-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[llvm-debuginfo-analyzer] Add support for parsing DWARF / CodeView SourceLanguage #137223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -415,6 +415,9 @@ class LVScopeCompileUnit final : public LVScope { | |
// Toolchain producer. | ||
size_t ProducerIndex = 0; | ||
|
||
// Source language. | ||
LVSourceLanguage SourceLanguage{}; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May be just: |
||
// Compilation directory name. | ||
size_t CompilationDirectoryIndex = 0; | ||
|
||
|
@@ -548,6 +551,9 @@ class LVScopeCompileUnit final : public LVScope { | |
ProducerIndex = getStringPool().getIndex(ProducerName); | ||
} | ||
|
||
LVSourceLanguage getSourceLanguage() const override { return SourceLanguage; } | ||
void setSourceLanguage(LVSourceLanguage SL) override { SourceLanguage = SL; } | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Get/Set the language string from/into the |
||
void setCPUType(codeview::CPUType Type) { CompilationCPUType = Type; } | ||
codeview::CPUType getCPUType() { return CompilationCPUType; } | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
//===----------------------------------------------------------------------===// | ||
|
||
#include "llvm/DebugInfo/LogicalView/Core/LVElement.h" | ||
#include "llvm/DebugInfo/CodeView/EnumTables.h" | ||
#include "llvm/DebugInfo/LogicalView/Core/LVReader.h" | ||
#include "llvm/DebugInfo/LogicalView/Core/LVScope.h" | ||
#include "llvm/DebugInfo/LogicalView/Core/LVType.h" | ||
|
@@ -19,6 +20,23 @@ using namespace llvm; | |
using namespace llvm::codeview; | ||
using namespace llvm::logicalview; | ||
|
||
StringRef LVSourceLanguage::getName() const { | ||
if (!isValid()) | ||
return {}; | ||
switch (Language.index()) { | ||
case 1: // DWARF | ||
return llvm::dwarf::LanguageString( | ||
std::get<llvm::dwarf::SourceLanguage>(Language)); | ||
case 2: // CodeView | ||
{ | ||
static auto LangNames = llvm::codeview::getSourceLanguageNames(); | ||
return LangNames[std::get<llvm::codeview::SourceLanguage>(Language)].Name; | ||
} | ||
default: | ||
llvm_unreachable("Unsupported language"); | ||
} | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This logic can be used to store the |
||
#define DEBUG_TYPE "Element" | ||
|
||
LVElementDispatch LVElement::Dispatch = { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be explore the use of
StringPool
to store theLanguage
string.Basically, the
setSourceLanguage
function to use the logic fromStringRef LVSourceLanguage::getName()
to get the string and store it in theStringPool
. And to get back the string in 'getSourceLanguage' query theStringPool
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds promising, and a bit simpler, given the existing infrastructure.
However, in the current state of this PR, we could write a
switch
statement on the returned value ofgetSourceLanguage.getAs<...>()
; this particular use case would become a bit harder to support if using strings as the underlying representation.Initially, I thought this could be supported by exposing the
LanguageIndex
data member (suggested below), but this is not reliable, as it depends on the interning order.We could still go for
StringPool
+LanguageIndex
at the cost of having to do string comparisons somewhere else (I would prefer to avoid this).Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about this a bit and came to the conclusion that we could, either
std::variant<Ts...>
, perhaps with some additional improvement.LVSourceLanguage
essentially anenum
which contains enumerators for every language supported by any of the readers. We could use the most-significant bits to store the format that defines such language (e.g. DWARF, CodeView, etc.). This may be simple, as we can do something similar toThen, the SourceLanguage becomes just a
uint32_t
. Essentially, this tries to represent the same as above, but without usingstd::variant<Ts...>
, and possibly being more space-efficient.StringPool
, as you suggested. Then, it may be a bit uncomfortable fordebuginfologicalview
library users to do something conditionally on the source language of a compile unit.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, I tend to like (2) more, so if you also agree, I could switch to this option for the next revision.