Skip to content

Commit 43ab881

Browse files
jalopezg-gitpeledins-zimperium
authored andcommitted
[llvm-debuginfo-analyzer] Add support for parsing DWARF DW_TAG_module
1 parent fc56a83 commit 43ab881

File tree

7 files changed

+62
-1
lines changed

7 files changed

+62
-1
lines changed

llvm/include/llvm/DebugInfo/LogicalView/Core/LVElement.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ enum class LVSubclassID : unsigned char {
4848
LV_SCOPE_NAMESPACE,
4949
LV_SCOPE_ROOT,
5050
LV_SCOPE_TEMPLATE_PACK,
51+
LV_SCOPE_MODULE,
5152
LV_SCOPE_LAST,
5253
LV_SYMBOL_FIRST,
5354
LV_SYMBOL,

llvm/include/llvm/DebugInfo/LogicalView/Core/LVReader.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ class LVReader {
107107
LV_OBJECT_ALLOCATOR(ScopeNamespace)
108108
LV_OBJECT_ALLOCATOR(ScopeRoot)
109109
LV_OBJECT_ALLOCATOR(ScopeTemplatePack)
110+
LV_OBJECT_ALLOCATOR(ScopeModule)
110111

111112
// Symbols allocator.
112113
LV_OBJECT_ALLOCATOR(Symbol)
@@ -213,6 +214,7 @@ class LVReader {
213214
LV_CREATE_OBJECT(ScopeNamespace)
214215
LV_CREATE_OBJECT(ScopeRoot)
215216
LV_CREATE_OBJECT(ScopeTemplatePack)
217+
LV_CREATE_OBJECT(ScopeModule)
216218

217219
// Symbols creation.
218220
LV_CREATE_OBJECT(Symbol)

llvm/include/llvm/DebugInfo/LogicalView/Core/LVScope.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ enum class LVScopeKind {
5757
IsTemplatePack,
5858
IsTryBlock,
5959
IsUnion,
60+
IsModule,
6061
LastEntry
6162
};
6263
using LVScopeKindSet = std::set<LVScopeKind>;
@@ -184,6 +185,7 @@ class LVScope : public LVElement {
184185
KIND(LVScopeKind, IsTemplatePack);
185186
KIND_1(LVScopeKind, IsTryBlock, IsBlock);
186187
KIND_1(LVScopeKind, IsUnion, IsAggregate);
188+
KIND_3(LVScopeKind, IsModule, CanHaveRanges, CanHaveLines, TransformName);
187189

188190
PROPERTY(Property, HasDiscriminator);
189191
PROPERTY(Property, CanHaveRanges);
@@ -838,6 +840,23 @@ class LVScopeTemplatePack final : public LVScope {
838840
void printExtra(raw_ostream &OS, bool Full = true) const override;
839841
};
840842

843+
// Class to represent a DWARF Module.
844+
class LVScopeModule final : public LVScope {
845+
public:
846+
LVScopeModule() : LVScope() {
847+
setIsModule();
848+
setIsLexicalBlock();
849+
}
850+
LVScopeModule(const LVScopeModule &) = delete;
851+
LVScopeModule &operator=(const LVScopeModule &) = delete;
852+
~LVScopeModule() = default;
853+
854+
// Returns true if current scope is logically equal to the given 'Scope'.
855+
bool equals(const LVScope *Scope) const override;
856+
857+
void printExtra(raw_ostream &OS, bool Full = true) const override;
858+
};
859+
841860
} // end namespace logicalview
842861
} // end namespace llvm
843862

llvm/lib/DebugInfo/LogicalView/Core/LVScope.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const char *const KindTemplateAlias = "TemplateAlias";
4040
const char *const KindTemplatePack = "TemplatePack";
4141
const char *const KindUndefined = "Undefined";
4242
const char *const KindUnion = "Union";
43+
const char *const KindModule = "Module";
4344
} // end anonymous namespace
4445

4546
//===----------------------------------------------------------------------===//
@@ -50,6 +51,8 @@ const char *LVScope::kind() const {
5051
const char *Kind = KindUndefined;
5152
if (getIsArray())
5253
Kind = KindArray;
54+
else if (getIsModule())
55+
Kind = KindModule;
5356
else if (getIsBlock())
5457
Kind = KindBlock;
5558
else if (getIsCallSite())
@@ -101,7 +104,8 @@ LVScopeDispatch LVScope::Dispatch = {
101104
{LVScopeKind::IsTemplateAlias, &LVScope::getIsTemplateAlias},
102105
{LVScopeKind::IsTemplatePack, &LVScope::getIsTemplatePack},
103106
{LVScopeKind::IsTryBlock, &LVScope::getIsTryBlock},
104-
{LVScopeKind::IsUnion, &LVScope::getIsUnion}};
107+
{LVScopeKind::IsUnion, &LVScope::getIsUnion},
108+
{LVScopeKind::IsModule, &LVScope::getIsModule}};
105109

106110
void LVScope::addToChildren(LVElement *Element) {
107111
if (!Children)
@@ -2116,3 +2120,15 @@ bool LVScopeTemplatePack::equals(const LVScope *Scope) const {
21162120
void LVScopeTemplatePack::printExtra(raw_ostream &OS, bool Full) const {
21172121
OS << formattedKind(kind()) << " " << formattedName(getName()) << "\n";
21182122
}
2123+
2124+
//===----------------------------------------------------------------------===//
2125+
// DWARF module (DW_TAG_module).
2126+
//===----------------------------------------------------------------------===//
2127+
bool LVScopeModule::equals(const LVScope *Scope) const {
2128+
// For lexical blocks, LVScope::equals() compares the parent scope.
2129+
return LVScope::equals(Scope) && (Scope->getName() == getName());
2130+
}
2131+
2132+
void LVScopeModule::printExtra(raw_ostream &OS, bool Full) const {
2133+
OS << formattedKind(kind()) << " " << formattedName(getName()) << "\n";
2134+
}

llvm/lib/DebugInfo/LogicalView/Readers/LVDWARFReader.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ LVElement *LVDWARFReader::createElement(dwarf::Tag Tag) {
233233
case dwarf::DW_TAG_GNU_template_parameter_pack:
234234
CurrentScope = createScopeTemplatePack();
235235
return CurrentScope;
236+
case dwarf::DW_TAG_module:
237+
CurrentScope = createScopeModule();
238+
return CurrentScope;
236239
default:
237240
// Collect TAGs not implemented.
238241
if (options().getInternalTag() && Tag)

llvm/unittests/DebugInfo/LogicalView/DWARFReaderTest.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const char *DwarfClang = "test-dwarf-clang.o";
3333
// Two compile units: one declares `extern int foo_printf(const char *, ...);`
3434
// and another one that defines the function.
3535
const char *DwarfClangUnspecParams = "test-dwarf-clang-unspec-params.elf";
36+
const char *DwarfClangModule = "test-dwarf-clang-module.o";
3637
const char *DwarfGcc = "test-dwarf-gcc.o";
3738

3839
// Helper function to get the first compile unit.
@@ -162,6 +163,22 @@ void checkUnspecifiedParameters(LVReader *Reader) {
162163
true);
163164
}
164165

166+
// Check the basic properties on parsed DW_TAG_module.
167+
void checkScopeModule(LVReader *Reader) {
168+
LVScopeRoot *Root = Reader->getScopesRoot();
169+
LVScopeCompileUnit *CompileUnit = getFirstCompileUnit(Root);
170+
171+
EXPECT_EQ(Root->getFileFormatName(), "Mach-O 64-bit x86-64");
172+
EXPECT_EQ(Root->getName(), DwarfClangModule);
173+
174+
ASSERT_NE(CompileUnit->getChildren(), nullptr);
175+
LVElement *FirstChild = *(CompileUnit->getChildren()->begin());
176+
EXPECT_EQ(FirstChild->getIsScope(), 1);
177+
LVScopeModule *Module = static_cast<LVScopeModule *>(FirstChild);
178+
EXPECT_EQ(Module->getIsModule(), 1);
179+
EXPECT_EQ(Module->getName(), "debugmodule");
180+
}
181+
165182
// Check the logical elements selection.
166183
void checkElementSelection(LVReader *Reader) {
167184
LVScopeRoot *Root = Reader->getScopesRoot();
@@ -312,6 +329,9 @@ void elementProperties(SmallString<128> &InputsDir) {
312329

313330
Reader = createReader(ReaderHandler, InputsDir, DwarfClangUnspecParams);
314331
checkUnspecifiedParameters(Reader.get());
332+
333+
Reader = createReader(ReaderHandler, InputsDir, DwarfClangModule);
334+
checkScopeModule(Reader.get());
315335
}
316336

317337
// Logical elements selection.
Binary file not shown.

0 commit comments

Comments
 (0)