Skip to content

[llvm-debuginfo-analyzer][NFC] Move some functionality to LVReader. #142740

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion llvm/include/llvm/DebugInfo/LogicalView/Core/LVReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class LVSplitContext final {

/// The logical reader owns of all the logical elements created during
/// the debug information parsing. For its creation it uses a specific
/// bump allocator for each type of logical element.
/// bump allocator for each type of logical element.
class LVReader {
LVBinaryType BinaryType;

Expand Down Expand Up @@ -122,7 +122,24 @@ class LVReader {

#undef LV_OBJECT_ALLOCATOR

// Scopes with ranges for current compile unit. It is used to find a line
// giving its exact or closest address. To support comdat functions, all
// addresses for the same section are recorded in the same map.
using LVSectionRanges = std::map<LVSectionIndex, std::unique_ptr<LVRange>>;
LVSectionRanges SectionRanges;

protected:
// Current elements during the processing of a DIE/MDNode.
LVElement *CurrentElement = nullptr;
LVScope *CurrentScope = nullptr;
LVSymbol *CurrentSymbol = nullptr;
LVType *CurrentType = nullptr;
LVLine *CurrentLine = nullptr;
LVOffset CurrentOffset = 0;

// Address ranges collected for current DIE/MDNode/AST Node.
std::vector<LVAddressRange> CurrentRanges;

LVScopeRoot *Root = nullptr;
std::string InputFilename;
std::string FileFormatName;
Expand All @@ -133,11 +150,18 @@ class LVReader {
// Only for ELF format. The CodeView is handled in a different way.
LVSectionIndex DotTextSectionIndex = UndefinedSectionIndex;

void addSectionRange(LVSectionIndex SectionIndex, LVScope *Scope);
void addSectionRange(LVSectionIndex SectionIndex, LVScope *Scope,
LVAddress LowerAddress, LVAddress UpperAddress);
LVRange *getSectionRanges(LVSectionIndex SectionIndex);

// Record Compilation Unit entry.
void addCompileUnitOffset(LVOffset Offset, LVScopeCompileUnit *CompileUnit) {
CompileUnits.emplace(Offset, CompileUnit);
}

LVElement *createElement(dwarf::Tag Tag);

// Create the Scope Root.
virtual Error createScopes() {
Root = createScopeRoot();
Expand Down
11 changes: 0 additions & 11 deletions llvm/include/llvm/DebugInfo/LogicalView/Readers/LVBinaryReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,6 @@ class LVBinaryReader : public LVReader {
SectionAddresses.emplace(Section.getAddress(), Section);
}

// Scopes with ranges for current compile unit. It is used to find a line
// giving its exact or closest address. To support comdat functions, all
// addresses for the same section are recorded in the same map.
using LVSectionRanges = std::map<LVSectionIndex, std::unique_ptr<LVRange>>;
LVSectionRanges SectionRanges;

// Image base and virtual address for Executable file.
uint64_t ImageBaseAddress = 0;
uint64_t VirtualAddress = 0;
Expand Down Expand Up @@ -179,11 +173,6 @@ class LVBinaryReader : public LVReader {
Expected<std::pair<LVSectionIndex, object::SectionRef>>
getSection(LVScope *Scope, LVAddress Address, LVSectionIndex SectionIndex);

void addSectionRange(LVSectionIndex SectionIndex, LVScope *Scope);
void addSectionRange(LVSectionIndex SectionIndex, LVScope *Scope,
LVAddress LowerAddress, LVAddress UpperAddress);
LVRange *getSectionRanges(LVSectionIndex SectionIndex);

void includeInlineeLines(LVSectionIndex SectionIndex, LVScope *Function);

Error createInstructions();
Expand Down
10 changes: 0 additions & 10 deletions llvm/include/llvm/DebugInfo/LogicalView/Readers/LVDWARFReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,13 @@ class LVDWARFReader final : public LVBinaryReader {
LVAddress CUBaseAddress = 0;
LVAddress CUHighAddress = 0;

// Current elements during the processing of a DIE.
LVElement *CurrentElement = nullptr;
LVScope *CurrentScope = nullptr;
LVSymbol *CurrentSymbol = nullptr;
LVType *CurrentType = nullptr;
LVOffset CurrentOffset = 0;
LVOffset CurrentEndOffset = 0;

// In DWARF v4, the files are 1-indexed.
// In DWARF v5, the files are 0-indexed.
// The DWARF reader expects the indexes as 1-indexed.
bool IncrementFileIndex = false;

// Address ranges collected for current DIE.
std::vector<LVAddressRange> CurrentRanges;

// Symbols with locations for current compile unit.
LVSymbols SymbolsWithLocations;

Expand Down Expand Up @@ -82,7 +73,6 @@ class LVDWARFReader final : public LVBinaryReader {

void mapRangeAddress(const object::ObjectFile &Obj) override;

LVElement *createElement(dwarf::Tag Tag);
void traverseDieAndChildren(DWARFDie &DIE, LVScope *Parent,
DWARFDie &SkeletonDie);
// Process the attributes for the given DIE.
Expand Down
247 changes: 247 additions & 0 deletions llvm/lib/DebugInfo/LogicalView/Core/LVReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,253 @@ StringRef LVReader::getFilename(LVObject *Object, size_t Index) const {
return CompileUnit ? CompileUnit->getFilename(Index) : StringRef();
}

void LVReader::addSectionRange(LVSectionIndex SectionIndex, LVScope *Scope) {
LVRange *ScopesWithRanges = getSectionRanges(SectionIndex);
ScopesWithRanges->addEntry(Scope);
}

void LVReader::addSectionRange(LVSectionIndex SectionIndex, LVScope *Scope,
LVAddress LowerAddress, LVAddress UpperAddress) {
LVRange *ScopesWithRanges = getSectionRanges(SectionIndex);
ScopesWithRanges->addEntry(Scope, LowerAddress, UpperAddress);
}

LVRange *LVReader::getSectionRanges(LVSectionIndex SectionIndex) {
// Check if we already have a mapping for this section index.
LVSectionRanges::iterator IterSection = SectionRanges.find(SectionIndex);
if (IterSection == SectionRanges.end())
IterSection =
SectionRanges.emplace(SectionIndex, std::make_unique<LVRange>()).first;
LVRange *Range = IterSection->second.get();
assert(Range && "Range is null.");
return Range;
}

LVElement *LVReader::createElement(dwarf::Tag Tag) {
CurrentScope = nullptr;
CurrentSymbol = nullptr;
CurrentType = nullptr;
CurrentRanges.clear();

LLVM_DEBUG(
{ dbgs() << "\n[createElement] " << dwarf::TagString(Tag) << "\n"; });

if (!options().getPrintSymbols()) {
switch (Tag) {
// As the command line options did not specify a request to print
// logical symbols (--print=symbols or --print=all or --print=elements),
// skip its creation.
case dwarf::DW_TAG_formal_parameter:
case dwarf::DW_TAG_unspecified_parameters:
case dwarf::DW_TAG_member:
case dwarf::DW_TAG_variable:
case dwarf::DW_TAG_inheritance:
case dwarf::DW_TAG_constant:
case dwarf::DW_TAG_call_site_parameter:
case dwarf::DW_TAG_GNU_call_site_parameter:
return nullptr;
default:
break;
}
}

switch (Tag) {
// Types.
case dwarf::DW_TAG_base_type:
CurrentType = createType();
CurrentType->setIsBase();
if (options().getAttributeBase())
CurrentType->setIncludeInPrint();
return CurrentType;
case dwarf::DW_TAG_const_type:
CurrentType = createType();
CurrentType->setIsConst();
CurrentType->setName("const");
return CurrentType;
case dwarf::DW_TAG_enumerator:
CurrentType = createTypeEnumerator();
return CurrentType;
case dwarf::DW_TAG_imported_declaration:
CurrentType = createTypeImport();
CurrentType->setIsImportDeclaration();
return CurrentType;
case dwarf::DW_TAG_imported_module:
CurrentType = createTypeImport();
CurrentType->setIsImportModule();
return CurrentType;
case dwarf::DW_TAG_pointer_type:
CurrentType = createType();
CurrentType->setIsPointer();
CurrentType->setName("*");
return CurrentType;
case dwarf::DW_TAG_ptr_to_member_type:
CurrentType = createType();
CurrentType->setIsPointerMember();
CurrentType->setName("*");
return CurrentType;
case dwarf::DW_TAG_reference_type:
CurrentType = createType();
CurrentType->setIsReference();
CurrentType->setName("&");
return CurrentType;
case dwarf::DW_TAG_restrict_type:
CurrentType = createType();
CurrentType->setIsRestrict();
CurrentType->setName("restrict");
return CurrentType;
case dwarf::DW_TAG_rvalue_reference_type:
CurrentType = createType();
CurrentType->setIsRvalueReference();
CurrentType->setName("&&");
return CurrentType;
case dwarf::DW_TAG_subrange_type:
CurrentType = createTypeSubrange();
return CurrentType;
case dwarf::DW_TAG_template_value_parameter:
CurrentType = createTypeParam();
CurrentType->setIsTemplateValueParam();
return CurrentType;
case dwarf::DW_TAG_template_type_parameter:
CurrentType = createTypeParam();
CurrentType->setIsTemplateTypeParam();
return CurrentType;
case dwarf::DW_TAG_GNU_template_template_param:
CurrentType = createTypeParam();
CurrentType->setIsTemplateTemplateParam();
return CurrentType;
case dwarf::DW_TAG_typedef:
CurrentType = createTypeDefinition();
return CurrentType;
case dwarf::DW_TAG_unspecified_type:
CurrentType = createType();
CurrentType->setIsUnspecified();
return CurrentType;
case dwarf::DW_TAG_volatile_type:
CurrentType = createType();
CurrentType->setIsVolatile();
CurrentType->setName("volatile");
return CurrentType;

// Symbols.
case dwarf::DW_TAG_formal_parameter:
CurrentSymbol = createSymbol();
CurrentSymbol->setIsParameter();
return CurrentSymbol;
case dwarf::DW_TAG_unspecified_parameters:
CurrentSymbol = createSymbol();
CurrentSymbol->setIsUnspecified();
CurrentSymbol->setName("...");
return CurrentSymbol;
case dwarf::DW_TAG_member:
CurrentSymbol = createSymbol();
CurrentSymbol->setIsMember();
return CurrentSymbol;
case dwarf::DW_TAG_variable:
CurrentSymbol = createSymbol();
CurrentSymbol->setIsVariable();
return CurrentSymbol;
case dwarf::DW_TAG_inheritance:
CurrentSymbol = createSymbol();
CurrentSymbol->setIsInheritance();
return CurrentSymbol;
case dwarf::DW_TAG_call_site_parameter:
case dwarf::DW_TAG_GNU_call_site_parameter:
CurrentSymbol = createSymbol();
CurrentSymbol->setIsCallSiteParameter();
return CurrentSymbol;
case dwarf::DW_TAG_constant:
CurrentSymbol = createSymbol();
CurrentSymbol->setIsConstant();
return CurrentSymbol;

// Scopes.
case dwarf::DW_TAG_catch_block:
CurrentScope = createScope();
CurrentScope->setIsCatchBlock();
return CurrentScope;
case dwarf::DW_TAG_lexical_block:
CurrentScope = createScope();
CurrentScope->setIsLexicalBlock();
return CurrentScope;
case dwarf::DW_TAG_try_block:
CurrentScope = createScope();
CurrentScope->setIsTryBlock();
return CurrentScope;
case dwarf::DW_TAG_compile_unit:
case dwarf::DW_TAG_skeleton_unit:
CurrentScope = createScopeCompileUnit();
CompileUnit = static_cast<LVScopeCompileUnit *>(CurrentScope);
return CurrentScope;
case dwarf::DW_TAG_inlined_subroutine:
CurrentScope = createScopeFunctionInlined();
return CurrentScope;
case dwarf::DW_TAG_namespace:
CurrentScope = createScopeNamespace();
return CurrentScope;
case dwarf::DW_TAG_template_alias:
CurrentScope = createScopeAlias();
return CurrentScope;
case dwarf::DW_TAG_array_type:
CurrentScope = createScopeArray();
return CurrentScope;
case dwarf::DW_TAG_call_site:
case dwarf::DW_TAG_GNU_call_site:
CurrentScope = createScopeFunction();
CurrentScope->setIsCallSite();
return CurrentScope;
case dwarf::DW_TAG_entry_point:
CurrentScope = createScopeFunction();
CurrentScope->setIsEntryPoint();
return CurrentScope;
case dwarf::DW_TAG_subprogram:
CurrentScope = createScopeFunction();
CurrentScope->setIsSubprogram();
return CurrentScope;
case dwarf::DW_TAG_subroutine_type:
CurrentScope = createScopeFunctionType();
return CurrentScope;
case dwarf::DW_TAG_label:
CurrentScope = createScopeFunction();
CurrentScope->setIsLabel();
return CurrentScope;
case dwarf::DW_TAG_class_type:
CurrentScope = createScopeAggregate();
CurrentScope->setIsClass();
return CurrentScope;
case dwarf::DW_TAG_structure_type:
CurrentScope = createScopeAggregate();
CurrentScope->setIsStructure();
return CurrentScope;
case dwarf::DW_TAG_union_type:
CurrentScope = createScopeAggregate();
CurrentScope->setIsUnion();
return CurrentScope;
case dwarf::DW_TAG_enumeration_type:
CurrentScope = createScopeEnumeration();
return CurrentScope;
case dwarf::DW_TAG_GNU_formal_parameter_pack:
CurrentScope = createScopeFormalPack();
return CurrentScope;
case dwarf::DW_TAG_GNU_template_parameter_pack:
CurrentScope = createScopeTemplatePack();
return CurrentScope;
case dwarf::DW_TAG_module:
CurrentScope = createScopeModule();
return CurrentScope;
default:
// Collect TAGs not implemented.
if (options().getInternalTag() && Tag)
CompileUnit->addDebugTag(Tag, CurrentOffset);
break;
}

LLVM_DEBUG({
dbgs() << "DWARF Tag not implemented: " << dwarf::TagString(Tag) << "\n";
});

return nullptr;
}

// The Reader is the module that creates the logical view using the debug
// information contained in the binary file specified in the command line.
// This is the main entry point for the Reader and performs the following
Expand Down
24 changes: 0 additions & 24 deletions llvm/lib/DebugInfo/LogicalView/Readers/LVBinaryReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,30 +367,6 @@ LVBinaryReader::getSection(LVScope *Scope, LVAddress Address,
return std::make_pair(Iter->first, Iter->second);
}

void LVBinaryReader::addSectionRange(LVSectionIndex SectionIndex,
LVScope *Scope) {
LVRange *ScopesWithRanges = getSectionRanges(SectionIndex);
ScopesWithRanges->addEntry(Scope);
}

void LVBinaryReader::addSectionRange(LVSectionIndex SectionIndex,
LVScope *Scope, LVAddress LowerAddress,
LVAddress UpperAddress) {
LVRange *ScopesWithRanges = getSectionRanges(SectionIndex);
ScopesWithRanges->addEntry(Scope, LowerAddress, UpperAddress);
}

LVRange *LVBinaryReader::getSectionRanges(LVSectionIndex SectionIndex) {
// Check if we already have a mapping for this section index.
LVSectionRanges::iterator IterSection = SectionRanges.find(SectionIndex);
if (IterSection == SectionRanges.end())
IterSection =
SectionRanges.emplace(SectionIndex, std::make_unique<LVRange>()).first;
LVRange *Range = IterSection->second.get();
assert(Range && "Range is null.");
return Range;
}

Error LVBinaryReader::createInstructions(LVScope *Scope,
LVSectionIndex SectionIndex,
const LVNameInfo &NameInfo) {
Expand Down
Loading
Loading