Skip to content

[LLDB] Unify DWARF section name matching #141344

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions lldb/include/lldb/Symbol/ObjectFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,13 @@ class ObjectFile : public std::enable_shared_from_this<ObjectFile>,
llvm::StringRef name,
lldb::SymbolType symbol_type_hint = lldb::eSymbolTypeUndefined);

/// Parses the section type from a section name for DWARF sections.
///
/// The \a name must be stripped of the default prefix (e.g. ".debug_" or
/// "__debug_"). If there's no matching section type, \a eSectionTypeOther
/// will be returned.
static lldb::SectionType GetDWARFSectionTypeFromName(llvm::StringRef name);

/// Loads this objfile to memory.
///
/// Loads the bits needed to create an executable image to the memory. It is
Expand Down
22 changes: 9 additions & 13 deletions lldb/source/Plugins/ObjectFile/COFF/ObjectFileCOFF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,19 +191,15 @@ void ObjectFileCOFF::CreateSections(lldb_private::SectionList &sections) {

auto SectionType = [](StringRef Name,
const coff_section *Section) -> lldb::SectionType {
lldb::SectionType type =
StringSwitch<lldb::SectionType>(Name)
// DWARF Debug Sections
.Case(".debug_abbrev", eSectionTypeDWARFDebugAbbrev)
.Case(".debug_info", eSectionTypeDWARFDebugInfo)
.Case(".debug_line", eSectionTypeDWARFDebugLine)
.Case(".debug_pubnames", eSectionTypeDWARFDebugPubNames)
.Case(".debug_pubtypes", eSectionTypeDWARFDebugPubTypes)
.Case(".debug_str", eSectionTypeDWARFDebugStr)
// CodeView Debug Sections: .debug$S, .debug$T
.StartsWith(".debug$", eSectionTypeDebug)
.Case("clangast", eSectionTypeOther)
.Default(eSectionTypeInvalid);
// DWARF Debug Sections
if (Name.consume_front(".debug_"))
return GetDWARFSectionTypeFromName(Name);

lldb::SectionType type = StringSwitch<lldb::SectionType>(Name)
// CodeView Debug Sections: .debug$S, .debug$T
.StartsWith(".debug$", eSectionTypeDebug)
.Case("clangast", eSectionTypeOther)
.Default(eSectionTypeInvalid);
if (type != eSectionTypeInvalid)
return type;

Expand Down
36 changes: 3 additions & 33 deletions lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1653,39 +1653,9 @@ lldb::user_id_t ObjectFileELF::GetSectionIndexByName(const char *name) {
}

static SectionType GetSectionTypeFromName(llvm::StringRef Name) {
if (Name.consume_front(".debug_")) {
return llvm::StringSwitch<SectionType>(Name)
.Case("abbrev", eSectionTypeDWARFDebugAbbrev)
.Case("abbrev.dwo", eSectionTypeDWARFDebugAbbrevDwo)
.Case("addr", eSectionTypeDWARFDebugAddr)
.Case("aranges", eSectionTypeDWARFDebugAranges)
.Case("cu_index", eSectionTypeDWARFDebugCuIndex)
.Case("frame", eSectionTypeDWARFDebugFrame)
.Case("info", eSectionTypeDWARFDebugInfo)
.Case("info.dwo", eSectionTypeDWARFDebugInfoDwo)
.Cases("line", "line.dwo", eSectionTypeDWARFDebugLine)
.Cases("line_str", "line_str.dwo", eSectionTypeDWARFDebugLineStr)
.Case("loc", eSectionTypeDWARFDebugLoc)
.Case("loc.dwo", eSectionTypeDWARFDebugLocDwo)
.Case("loclists", eSectionTypeDWARFDebugLocLists)
.Case("loclists.dwo", eSectionTypeDWARFDebugLocListsDwo)
.Case("macinfo", eSectionTypeDWARFDebugMacInfo)
.Cases("macro", "macro.dwo", eSectionTypeDWARFDebugMacro)
.Case("names", eSectionTypeDWARFDebugNames)
.Case("pubnames", eSectionTypeDWARFDebugPubNames)
.Case("pubtypes", eSectionTypeDWARFDebugPubTypes)
.Case("ranges", eSectionTypeDWARFDebugRanges)
.Case("rnglists", eSectionTypeDWARFDebugRngLists)
.Case("rnglists.dwo", eSectionTypeDWARFDebugRngListsDwo)
.Case("str", eSectionTypeDWARFDebugStr)
.Case("str.dwo", eSectionTypeDWARFDebugStrDwo)
.Case("str_offsets", eSectionTypeDWARFDebugStrOffsets)
.Case("str_offsets.dwo", eSectionTypeDWARFDebugStrOffsetsDwo)
.Case("tu_index", eSectionTypeDWARFDebugTuIndex)
.Case("types", eSectionTypeDWARFDebugTypes)
.Case("types.dwo", eSectionTypeDWARFDebugTypesDwo)
.Default(eSectionTypeOther);
}
if (Name.consume_front(".debug_"))
return ObjectFile::GetDWARFSectionTypeFromName(Name);

return llvm::StringSwitch<SectionType>(Name)
.Case(".ARM.exidx", eSectionTypeARMexidx)
.Case(".ARM.extab", eSectionTypeARMextab)
Expand Down
88 changes: 4 additions & 84 deletions lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1595,34 +1595,6 @@ static lldb::SectionType GetSectionType(uint32_t flags,
static ConstString g_sect_name_objc_classlist("__objc_classlist");
static ConstString g_sect_name_cfstring("__cfstring");

static ConstString g_sect_name_dwarf_debug_abbrev("__debug_abbrev");
static ConstString g_sect_name_dwarf_debug_abbrev_dwo("__debug_abbrev.dwo");
static ConstString g_sect_name_dwarf_debug_addr("__debug_addr");
static ConstString g_sect_name_dwarf_debug_aranges("__debug_aranges");
static ConstString g_sect_name_dwarf_debug_cu_index("__debug_cu_index");
static ConstString g_sect_name_dwarf_debug_frame("__debug_frame");
static ConstString g_sect_name_dwarf_debug_info("__debug_info");
static ConstString g_sect_name_dwarf_debug_info_dwo("__debug_info.dwo");
static ConstString g_sect_name_dwarf_debug_line("__debug_line");
static ConstString g_sect_name_dwarf_debug_line_dwo("__debug_line.dwo");
static ConstString g_sect_name_dwarf_debug_line_str("__debug_line_str");
static ConstString g_sect_name_dwarf_debug_loc("__debug_loc");
static ConstString g_sect_name_dwarf_debug_loclists("__debug_loclists");
static ConstString g_sect_name_dwarf_debug_loclists_dwo("__debug_loclists.dwo");
static ConstString g_sect_name_dwarf_debug_macinfo("__debug_macinfo");
static ConstString g_sect_name_dwarf_debug_macro("__debug_macro");
static ConstString g_sect_name_dwarf_debug_macro_dwo("__debug_macro.dwo");
static ConstString g_sect_name_dwarf_debug_names("__debug_names");
static ConstString g_sect_name_dwarf_debug_pubnames("__debug_pubnames");
static ConstString g_sect_name_dwarf_debug_pubtypes("__debug_pubtypes");
static ConstString g_sect_name_dwarf_debug_ranges("__debug_ranges");
static ConstString g_sect_name_dwarf_debug_rnglists("__debug_rnglists");
static ConstString g_sect_name_dwarf_debug_str("__debug_str");
static ConstString g_sect_name_dwarf_debug_str_dwo("__debug_str.dwo");
static ConstString g_sect_name_dwarf_debug_str_offs("__debug_str_offs");
static ConstString g_sect_name_dwarf_debug_str_offs_dwo("__debug_str_offs.dwo");
static ConstString g_sect_name_dwarf_debug_tu_index("__debug_tu_index");
static ConstString g_sect_name_dwarf_debug_types("__debug_types");
static ConstString g_sect_name_dwarf_apple_names("__apple_names");
static ConstString g_sect_name_dwarf_apple_types("__apple_types");
static ConstString g_sect_name_dwarf_apple_namespaces("__apple_namespac");
Expand All @@ -1637,62 +1609,10 @@ static lldb::SectionType GetSectionType(uint32_t flags,
static ConstString g_sect_name_lldb_formatters("__lldbformatters");
static ConstString g_sect_name_swift_ast("__swift_ast");

if (section_name == g_sect_name_dwarf_debug_abbrev)
return eSectionTypeDWARFDebugAbbrev;
if (section_name == g_sect_name_dwarf_debug_abbrev_dwo)
return eSectionTypeDWARFDebugAbbrevDwo;
if (section_name == g_sect_name_dwarf_debug_addr)
return eSectionTypeDWARFDebugAddr;
if (section_name == g_sect_name_dwarf_debug_aranges)
return eSectionTypeDWARFDebugAranges;
if (section_name == g_sect_name_dwarf_debug_cu_index)
return eSectionTypeDWARFDebugCuIndex;
if (section_name == g_sect_name_dwarf_debug_frame)
return eSectionTypeDWARFDebugFrame;
if (section_name == g_sect_name_dwarf_debug_info)
return eSectionTypeDWARFDebugInfo;
if (section_name == g_sect_name_dwarf_debug_info_dwo)
return eSectionTypeDWARFDebugInfoDwo;
if (section_name == g_sect_name_dwarf_debug_line)
return eSectionTypeDWARFDebugLine;
if (section_name == g_sect_name_dwarf_debug_line_dwo)
return eSectionTypeDWARFDebugLine; // Same as debug_line.
if (section_name == g_sect_name_dwarf_debug_line_str)
return eSectionTypeDWARFDebugLineStr;
if (section_name == g_sect_name_dwarf_debug_loc)
return eSectionTypeDWARFDebugLoc;
if (section_name == g_sect_name_dwarf_debug_loclists)
return eSectionTypeDWARFDebugLocLists;
if (section_name == g_sect_name_dwarf_debug_loclists_dwo)
return eSectionTypeDWARFDebugLocListsDwo;
if (section_name == g_sect_name_dwarf_debug_macinfo)
return eSectionTypeDWARFDebugMacInfo;
if (section_name == g_sect_name_dwarf_debug_macro)
return eSectionTypeDWARFDebugMacro;
if (section_name == g_sect_name_dwarf_debug_macro_dwo)
return eSectionTypeDWARFDebugMacInfo; // Same as debug_macro.
if (section_name == g_sect_name_dwarf_debug_names)
return eSectionTypeDWARFDebugNames;
if (section_name == g_sect_name_dwarf_debug_pubnames)
return eSectionTypeDWARFDebugPubNames;
if (section_name == g_sect_name_dwarf_debug_pubtypes)
return eSectionTypeDWARFDebugPubTypes;
if (section_name == g_sect_name_dwarf_debug_ranges)
return eSectionTypeDWARFDebugRanges;
if (section_name == g_sect_name_dwarf_debug_rnglists)
return eSectionTypeDWARFDebugRngLists;
if (section_name == g_sect_name_dwarf_debug_str)
return eSectionTypeDWARFDebugStr;
if (section_name == g_sect_name_dwarf_debug_str_dwo)
return eSectionTypeDWARFDebugStrDwo;
if (section_name == g_sect_name_dwarf_debug_str_offs)
return eSectionTypeDWARFDebugStrOffsets;
if (section_name == g_sect_name_dwarf_debug_str_offs_dwo)
return eSectionTypeDWARFDebugStrOffsetsDwo;
if (section_name == g_sect_name_dwarf_debug_tu_index)
return eSectionTypeDWARFDebugTuIndex;
if (section_name == g_sect_name_dwarf_debug_types)
return eSectionTypeDWARFDebugTypes;
llvm::StringRef stripped_name = section_name.GetStringRef();
if (stripped_name.consume_front("__debug_"))
return ObjectFile::GetDWARFSectionTypeFromName(stripped_name);

if (section_name == g_sect_name_dwarf_apple_names)
return eSectionTypeDWARFAppleNames;
if (section_name == g_sect_name_dwarf_apple_types)
Expand Down
17 changes: 3 additions & 14 deletions lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -977,25 +977,14 @@ SectionType ObjectFilePECOFF::GetSectionType(llvm::StringRef sect_name,
return eSectionTypeData;
}

if (sect_name.consume_front(".debug_"))
return GetDWARFSectionTypeFromName(sect_name);

SectionType section_type =
llvm::StringSwitch<SectionType>(sect_name)
.Case(".debug", eSectionTypeDebug)
.Case(".stabstr", eSectionTypeDataCString)
.Case(".reloc", eSectionTypeOther)
.Case(".debug_abbrev", eSectionTypeDWARFDebugAbbrev)
.Case(".debug_aranges", eSectionTypeDWARFDebugAranges)
.Case(".debug_frame", eSectionTypeDWARFDebugFrame)
.Case(".debug_info", eSectionTypeDWARFDebugInfo)
.Case(".debug_line", eSectionTypeDWARFDebugLine)
.Case(".debug_loc", eSectionTypeDWARFDebugLoc)
.Case(".debug_loclists", eSectionTypeDWARFDebugLocLists)
.Case(".debug_macinfo", eSectionTypeDWARFDebugMacInfo)
.Case(".debug_names", eSectionTypeDWARFDebugNames)
.Case(".debug_pubnames", eSectionTypeDWARFDebugPubNames)
.Case(".debug_pubtypes", eSectionTypeDWARFDebugPubTypes)
.Case(".debug_ranges", eSectionTypeDWARFDebugRanges)
.Case(".debug_str", eSectionTypeDWARFDebugStr)
.Case(".debug_types", eSectionTypeDWARFDebugTypes)
// .eh_frame can be truncated to 8 chars.
.Cases(".eh_frame", ".eh_fram", eSectionTypeEHFrame)
.Case(".gosymtab", eSectionTypeGoSymtab)
Expand Down
32 changes: 1 addition & 31 deletions lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,37 +252,7 @@ void ObjectFileWasm::ParseSymtab(Symtab &symtab) {}

static SectionType GetSectionTypeFromName(llvm::StringRef Name) {
if (Name.consume_front(".debug_") || Name.consume_front(".zdebug_")) {
return llvm::StringSwitch<SectionType>(Name)
.Case("abbrev", eSectionTypeDWARFDebugAbbrev)
.Case("abbrev.dwo", eSectionTypeDWARFDebugAbbrevDwo)
.Case("addr", eSectionTypeDWARFDebugAddr)
.Case("aranges", eSectionTypeDWARFDebugAranges)
.Case("cu_index", eSectionTypeDWARFDebugCuIndex)
.Case("frame", eSectionTypeDWARFDebugFrame)
.Case("info", eSectionTypeDWARFDebugInfo)
.Case("info.dwo", eSectionTypeDWARFDebugInfoDwo)
.Cases("line", "line.dwo", eSectionTypeDWARFDebugLine)
.Cases("line_str", "line_str.dwo", eSectionTypeDWARFDebugLineStr)
.Case("loc", eSectionTypeDWARFDebugLoc)
.Case("loc.dwo", eSectionTypeDWARFDebugLocDwo)
.Case("loclists", eSectionTypeDWARFDebugLocLists)
.Case("loclists.dwo", eSectionTypeDWARFDebugLocListsDwo)
.Case("macinfo", eSectionTypeDWARFDebugMacInfo)
.Cases("macro", "macro.dwo", eSectionTypeDWARFDebugMacro)
.Case("names", eSectionTypeDWARFDebugNames)
.Case("pubnames", eSectionTypeDWARFDebugPubNames)
.Case("pubtypes", eSectionTypeDWARFDebugPubTypes)
.Case("ranges", eSectionTypeDWARFDebugRanges)
.Case("rnglists", eSectionTypeDWARFDebugRngLists)
.Case("rnglists.dwo", eSectionTypeDWARFDebugRngListsDwo)
.Case("str", eSectionTypeDWARFDebugStr)
.Case("str.dwo", eSectionTypeDWARFDebugStrDwo)
.Case("str_offsets", eSectionTypeDWARFDebugStrOffsets)
.Case("str_offsets.dwo", eSectionTypeDWARFDebugStrOffsetsDwo)
.Case("tu_index", eSectionTypeDWARFDebugTuIndex)
.Case("types", eSectionTypeDWARFDebugTypes)
.Case("types.dwo", eSectionTypeDWARFDebugTypesDwo)
.Default(eSectionTypeOther);
return ObjectFile::GetDWARFSectionTypeFromName(Name);
}
return eSectionTypeOther;
}
Expand Down
35 changes: 35 additions & 0 deletions lldb/source/Symbol/ObjectFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,41 @@ ObjectFile::GetSymbolTypeFromName(llvm::StringRef name,
return symbol_type_hint;
}

lldb::SectionType
ObjectFile::GetDWARFSectionTypeFromName(llvm::StringRef name) {
return llvm::StringSwitch<SectionType>(name)
.Case("abbrev", eSectionTypeDWARFDebugAbbrev)
.Case("abbrev.dwo", eSectionTypeDWARFDebugAbbrevDwo)
.Case("addr", eSectionTypeDWARFDebugAddr)
.Case("aranges", eSectionTypeDWARFDebugAranges)
.Case("cu_index", eSectionTypeDWARFDebugCuIndex)
.Case("frame", eSectionTypeDWARFDebugFrame)
.Case("info", eSectionTypeDWARFDebugInfo)
.Case("info.dwo", eSectionTypeDWARFDebugInfoDwo)
.Cases("line", "line.dwo", eSectionTypeDWARFDebugLine)
.Cases("line_str", "line_str.dwo", eSectionTypeDWARFDebugLineStr)
.Case("loc", eSectionTypeDWARFDebugLoc)
.Case("loc.dwo", eSectionTypeDWARFDebugLocDwo)
.Case("loclists", eSectionTypeDWARFDebugLocLists)
.Case("loclists.dwo", eSectionTypeDWARFDebugLocListsDwo)
.Case("macinfo", eSectionTypeDWARFDebugMacInfo)
.Cases("macro", "macro.dwo", eSectionTypeDWARFDebugMacro)
.Case("names", eSectionTypeDWARFDebugNames)
.Case("pubnames", eSectionTypeDWARFDebugPubNames)
.Case("pubtypes", eSectionTypeDWARFDebugPubTypes)
.Case("ranges", eSectionTypeDWARFDebugRanges)
.Case("rnglists", eSectionTypeDWARFDebugRngLists)
.Case("rnglists.dwo", eSectionTypeDWARFDebugRngListsDwo)
.Case("str", eSectionTypeDWARFDebugStr)
.Case("str.dwo", eSectionTypeDWARFDebugStrDwo)
.Case("str_offsets", eSectionTypeDWARFDebugStrOffsets)
.Case("str_offsets.dwo", eSectionTypeDWARFDebugStrOffsetsDwo)
.Case("tu_index", eSectionTypeDWARFDebugTuIndex)
.Case("types", eSectionTypeDWARFDebugTypes)
.Case("types.dwo", eSectionTypeDWARFDebugTypesDwo)
.Default(eSectionTypeOther);
}

std::vector<ObjectFile::LoadableData>
ObjectFile::GetLoadableData(Target &target) {
std::vector<LoadableData> loadables;
Expand Down
Loading
Loading