Skip to content

Commit c6670fa

Browse files
authored
[LLDB] Unify DWARF section name matching (#141344)
Different object file formats support DWARF sections (COFF, ELF, MachO, PE/COFF, WASM). COFF and PE/COFF only matched a subset. This caused some GCC executables produced on MinGW to have issue later on when debugging. One example is that `.debug_rnglists` was not matched, which caused range-extraction to fail when printing a backtrace. This unifies the parsing of section names in `ObjectFile::GetDWARFSectionTypeFromName`, so all file formats can use the same naming convention. Since the prefixes are different, `GetDWARFSectionTypeFromName` only matches the suffixes (i.e. `.debug_` needs to be stripped before). I added two tests to ensure the sections are correctly identified on Windows executables.
1 parent 62c9b0c commit c6670fa

File tree

9 files changed

+364
-175
lines changed

9 files changed

+364
-175
lines changed

lldb/include/lldb/Symbol/ObjectFile.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,13 @@ class ObjectFile : public std::enable_shared_from_this<ObjectFile>,
709709
llvm::StringRef name,
710710
lldb::SymbolType symbol_type_hint = lldb::eSymbolTypeUndefined);
711711

712+
/// Parses the section type from a section name for DWARF sections.
713+
///
714+
/// The \a name must be stripped of the default prefix (e.g. ".debug_" or
715+
/// "__debug_"). If there's no matching section type, \a eSectionTypeOther
716+
/// will be returned.
717+
static lldb::SectionType GetDWARFSectionTypeFromName(llvm::StringRef name);
718+
712719
/// Loads this objfile to memory.
713720
///
714721
/// Loads the bits needed to create an executable image to the memory. It is

lldb/source/Plugins/ObjectFile/COFF/ObjectFileCOFF.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -191,19 +191,15 @@ void ObjectFileCOFF::CreateSections(lldb_private::SectionList &sections) {
191191

192192
auto SectionType = [](StringRef Name,
193193
const coff_section *Section) -> lldb::SectionType {
194-
lldb::SectionType type =
195-
StringSwitch<lldb::SectionType>(Name)
196-
// DWARF Debug Sections
197-
.Case(".debug_abbrev", eSectionTypeDWARFDebugAbbrev)
198-
.Case(".debug_info", eSectionTypeDWARFDebugInfo)
199-
.Case(".debug_line", eSectionTypeDWARFDebugLine)
200-
.Case(".debug_pubnames", eSectionTypeDWARFDebugPubNames)
201-
.Case(".debug_pubtypes", eSectionTypeDWARFDebugPubTypes)
202-
.Case(".debug_str", eSectionTypeDWARFDebugStr)
203-
// CodeView Debug Sections: .debug$S, .debug$T
204-
.StartsWith(".debug$", eSectionTypeDebug)
205-
.Case("clangast", eSectionTypeOther)
206-
.Default(eSectionTypeInvalid);
194+
// DWARF Debug Sections
195+
if (Name.consume_front(".debug_"))
196+
return GetDWARFSectionTypeFromName(Name);
197+
198+
lldb::SectionType type = StringSwitch<lldb::SectionType>(Name)
199+
// CodeView Debug Sections: .debug$S, .debug$T
200+
.StartsWith(".debug$", eSectionTypeDebug)
201+
.Case("clangast", eSectionTypeOther)
202+
.Default(eSectionTypeInvalid);
207203
if (type != eSectionTypeInvalid)
208204
return type;
209205

lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,39 +1653,9 @@ lldb::user_id_t ObjectFileELF::GetSectionIndexByName(const char *name) {
16531653
}
16541654

16551655
static SectionType GetSectionTypeFromName(llvm::StringRef Name) {
1656-
if (Name.consume_front(".debug_")) {
1657-
return llvm::StringSwitch<SectionType>(Name)
1658-
.Case("abbrev", eSectionTypeDWARFDebugAbbrev)
1659-
.Case("abbrev.dwo", eSectionTypeDWARFDebugAbbrevDwo)
1660-
.Case("addr", eSectionTypeDWARFDebugAddr)
1661-
.Case("aranges", eSectionTypeDWARFDebugAranges)
1662-
.Case("cu_index", eSectionTypeDWARFDebugCuIndex)
1663-
.Case("frame", eSectionTypeDWARFDebugFrame)
1664-
.Case("info", eSectionTypeDWARFDebugInfo)
1665-
.Case("info.dwo", eSectionTypeDWARFDebugInfoDwo)
1666-
.Cases("line", "line.dwo", eSectionTypeDWARFDebugLine)
1667-
.Cases("line_str", "line_str.dwo", eSectionTypeDWARFDebugLineStr)
1668-
.Case("loc", eSectionTypeDWARFDebugLoc)
1669-
.Case("loc.dwo", eSectionTypeDWARFDebugLocDwo)
1670-
.Case("loclists", eSectionTypeDWARFDebugLocLists)
1671-
.Case("loclists.dwo", eSectionTypeDWARFDebugLocListsDwo)
1672-
.Case("macinfo", eSectionTypeDWARFDebugMacInfo)
1673-
.Cases("macro", "macro.dwo", eSectionTypeDWARFDebugMacro)
1674-
.Case("names", eSectionTypeDWARFDebugNames)
1675-
.Case("pubnames", eSectionTypeDWARFDebugPubNames)
1676-
.Case("pubtypes", eSectionTypeDWARFDebugPubTypes)
1677-
.Case("ranges", eSectionTypeDWARFDebugRanges)
1678-
.Case("rnglists", eSectionTypeDWARFDebugRngLists)
1679-
.Case("rnglists.dwo", eSectionTypeDWARFDebugRngListsDwo)
1680-
.Case("str", eSectionTypeDWARFDebugStr)
1681-
.Case("str.dwo", eSectionTypeDWARFDebugStrDwo)
1682-
.Case("str_offsets", eSectionTypeDWARFDebugStrOffsets)
1683-
.Case("str_offsets.dwo", eSectionTypeDWARFDebugStrOffsetsDwo)
1684-
.Case("tu_index", eSectionTypeDWARFDebugTuIndex)
1685-
.Case("types", eSectionTypeDWARFDebugTypes)
1686-
.Case("types.dwo", eSectionTypeDWARFDebugTypesDwo)
1687-
.Default(eSectionTypeOther);
1688-
}
1656+
if (Name.consume_front(".debug_"))
1657+
return ObjectFile::GetDWARFSectionTypeFromName(Name);
1658+
16891659
return llvm::StringSwitch<SectionType>(Name)
16901660
.Case(".ARM.exidx", eSectionTypeARMexidx)
16911661
.Case(".ARM.extab", eSectionTypeARMextab)

lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp

Lines changed: 4 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,34 +1595,6 @@ static lldb::SectionType GetSectionType(uint32_t flags,
15951595
static ConstString g_sect_name_objc_classlist("__objc_classlist");
15961596
static ConstString g_sect_name_cfstring("__cfstring");
15971597

1598-
static ConstString g_sect_name_dwarf_debug_abbrev("__debug_abbrev");
1599-
static ConstString g_sect_name_dwarf_debug_abbrev_dwo("__debug_abbrev.dwo");
1600-
static ConstString g_sect_name_dwarf_debug_addr("__debug_addr");
1601-
static ConstString g_sect_name_dwarf_debug_aranges("__debug_aranges");
1602-
static ConstString g_sect_name_dwarf_debug_cu_index("__debug_cu_index");
1603-
static ConstString g_sect_name_dwarf_debug_frame("__debug_frame");
1604-
static ConstString g_sect_name_dwarf_debug_info("__debug_info");
1605-
static ConstString g_sect_name_dwarf_debug_info_dwo("__debug_info.dwo");
1606-
static ConstString g_sect_name_dwarf_debug_line("__debug_line");
1607-
static ConstString g_sect_name_dwarf_debug_line_dwo("__debug_line.dwo");
1608-
static ConstString g_sect_name_dwarf_debug_line_str("__debug_line_str");
1609-
static ConstString g_sect_name_dwarf_debug_loc("__debug_loc");
1610-
static ConstString g_sect_name_dwarf_debug_loclists("__debug_loclists");
1611-
static ConstString g_sect_name_dwarf_debug_loclists_dwo("__debug_loclists.dwo");
1612-
static ConstString g_sect_name_dwarf_debug_macinfo("__debug_macinfo");
1613-
static ConstString g_sect_name_dwarf_debug_macro("__debug_macro");
1614-
static ConstString g_sect_name_dwarf_debug_macro_dwo("__debug_macro.dwo");
1615-
static ConstString g_sect_name_dwarf_debug_names("__debug_names");
1616-
static ConstString g_sect_name_dwarf_debug_pubnames("__debug_pubnames");
1617-
static ConstString g_sect_name_dwarf_debug_pubtypes("__debug_pubtypes");
1618-
static ConstString g_sect_name_dwarf_debug_ranges("__debug_ranges");
1619-
static ConstString g_sect_name_dwarf_debug_rnglists("__debug_rnglists");
1620-
static ConstString g_sect_name_dwarf_debug_str("__debug_str");
1621-
static ConstString g_sect_name_dwarf_debug_str_dwo("__debug_str.dwo");
1622-
static ConstString g_sect_name_dwarf_debug_str_offs("__debug_str_offs");
1623-
static ConstString g_sect_name_dwarf_debug_str_offs_dwo("__debug_str_offs.dwo");
1624-
static ConstString g_sect_name_dwarf_debug_tu_index("__debug_tu_index");
1625-
static ConstString g_sect_name_dwarf_debug_types("__debug_types");
16261598
static ConstString g_sect_name_dwarf_apple_names("__apple_names");
16271599
static ConstString g_sect_name_dwarf_apple_types("__apple_types");
16281600
static ConstString g_sect_name_dwarf_apple_namespaces("__apple_namespac");
@@ -1637,62 +1609,10 @@ static lldb::SectionType GetSectionType(uint32_t flags,
16371609
static ConstString g_sect_name_lldb_formatters("__lldbformatters");
16381610
static ConstString g_sect_name_swift_ast("__swift_ast");
16391611

1640-
if (section_name == g_sect_name_dwarf_debug_abbrev)
1641-
return eSectionTypeDWARFDebugAbbrev;
1642-
if (section_name == g_sect_name_dwarf_debug_abbrev_dwo)
1643-
return eSectionTypeDWARFDebugAbbrevDwo;
1644-
if (section_name == g_sect_name_dwarf_debug_addr)
1645-
return eSectionTypeDWARFDebugAddr;
1646-
if (section_name == g_sect_name_dwarf_debug_aranges)
1647-
return eSectionTypeDWARFDebugAranges;
1648-
if (section_name == g_sect_name_dwarf_debug_cu_index)
1649-
return eSectionTypeDWARFDebugCuIndex;
1650-
if (section_name == g_sect_name_dwarf_debug_frame)
1651-
return eSectionTypeDWARFDebugFrame;
1652-
if (section_name == g_sect_name_dwarf_debug_info)
1653-
return eSectionTypeDWARFDebugInfo;
1654-
if (section_name == g_sect_name_dwarf_debug_info_dwo)
1655-
return eSectionTypeDWARFDebugInfoDwo;
1656-
if (section_name == g_sect_name_dwarf_debug_line)
1657-
return eSectionTypeDWARFDebugLine;
1658-
if (section_name == g_sect_name_dwarf_debug_line_dwo)
1659-
return eSectionTypeDWARFDebugLine; // Same as debug_line.
1660-
if (section_name == g_sect_name_dwarf_debug_line_str)
1661-
return eSectionTypeDWARFDebugLineStr;
1662-
if (section_name == g_sect_name_dwarf_debug_loc)
1663-
return eSectionTypeDWARFDebugLoc;
1664-
if (section_name == g_sect_name_dwarf_debug_loclists)
1665-
return eSectionTypeDWARFDebugLocLists;
1666-
if (section_name == g_sect_name_dwarf_debug_loclists_dwo)
1667-
return eSectionTypeDWARFDebugLocListsDwo;
1668-
if (section_name == g_sect_name_dwarf_debug_macinfo)
1669-
return eSectionTypeDWARFDebugMacInfo;
1670-
if (section_name == g_sect_name_dwarf_debug_macro)
1671-
return eSectionTypeDWARFDebugMacro;
1672-
if (section_name == g_sect_name_dwarf_debug_macro_dwo)
1673-
return eSectionTypeDWARFDebugMacInfo; // Same as debug_macro.
1674-
if (section_name == g_sect_name_dwarf_debug_names)
1675-
return eSectionTypeDWARFDebugNames;
1676-
if (section_name == g_sect_name_dwarf_debug_pubnames)
1677-
return eSectionTypeDWARFDebugPubNames;
1678-
if (section_name == g_sect_name_dwarf_debug_pubtypes)
1679-
return eSectionTypeDWARFDebugPubTypes;
1680-
if (section_name == g_sect_name_dwarf_debug_ranges)
1681-
return eSectionTypeDWARFDebugRanges;
1682-
if (section_name == g_sect_name_dwarf_debug_rnglists)
1683-
return eSectionTypeDWARFDebugRngLists;
1684-
if (section_name == g_sect_name_dwarf_debug_str)
1685-
return eSectionTypeDWARFDebugStr;
1686-
if (section_name == g_sect_name_dwarf_debug_str_dwo)
1687-
return eSectionTypeDWARFDebugStrDwo;
1688-
if (section_name == g_sect_name_dwarf_debug_str_offs)
1689-
return eSectionTypeDWARFDebugStrOffsets;
1690-
if (section_name == g_sect_name_dwarf_debug_str_offs_dwo)
1691-
return eSectionTypeDWARFDebugStrOffsetsDwo;
1692-
if (section_name == g_sect_name_dwarf_debug_tu_index)
1693-
return eSectionTypeDWARFDebugTuIndex;
1694-
if (section_name == g_sect_name_dwarf_debug_types)
1695-
return eSectionTypeDWARFDebugTypes;
1612+
llvm::StringRef stripped_name = section_name.GetStringRef();
1613+
if (stripped_name.consume_front("__debug_"))
1614+
return ObjectFile::GetDWARFSectionTypeFromName(stripped_name);
1615+
16961616
if (section_name == g_sect_name_dwarf_apple_names)
16971617
return eSectionTypeDWARFAppleNames;
16981618
if (section_name == g_sect_name_dwarf_apple_types)

lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -976,25 +976,14 @@ SectionType ObjectFilePECOFF::GetSectionType(llvm::StringRef sect_name,
976976
return eSectionTypeData;
977977
}
978978

979+
if (sect_name.consume_front(".debug_"))
980+
return GetDWARFSectionTypeFromName(sect_name);
981+
979982
SectionType section_type =
980983
llvm::StringSwitch<SectionType>(sect_name)
981984
.Case(".debug", eSectionTypeDebug)
982985
.Case(".stabstr", eSectionTypeDataCString)
983986
.Case(".reloc", eSectionTypeOther)
984-
.Case(".debug_abbrev", eSectionTypeDWARFDebugAbbrev)
985-
.Case(".debug_aranges", eSectionTypeDWARFDebugAranges)
986-
.Case(".debug_frame", eSectionTypeDWARFDebugFrame)
987-
.Case(".debug_info", eSectionTypeDWARFDebugInfo)
988-
.Case(".debug_line", eSectionTypeDWARFDebugLine)
989-
.Case(".debug_loc", eSectionTypeDWARFDebugLoc)
990-
.Case(".debug_loclists", eSectionTypeDWARFDebugLocLists)
991-
.Case(".debug_macinfo", eSectionTypeDWARFDebugMacInfo)
992-
.Case(".debug_names", eSectionTypeDWARFDebugNames)
993-
.Case(".debug_pubnames", eSectionTypeDWARFDebugPubNames)
994-
.Case(".debug_pubtypes", eSectionTypeDWARFDebugPubTypes)
995-
.Case(".debug_ranges", eSectionTypeDWARFDebugRanges)
996-
.Case(".debug_str", eSectionTypeDWARFDebugStr)
997-
.Case(".debug_types", eSectionTypeDWARFDebugTypes)
998987
// .eh_frame can be truncated to 8 chars.
999988
.Cases(".eh_frame", ".eh_fram", eSectionTypeEHFrame)
1000989
.Case(".gosymtab", eSectionTypeGoSymtab)

lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.cpp

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -252,37 +252,7 @@ void ObjectFileWasm::ParseSymtab(Symtab &symtab) {}
252252

253253
static SectionType GetSectionTypeFromName(llvm::StringRef Name) {
254254
if (Name.consume_front(".debug_") || Name.consume_front(".zdebug_")) {
255-
return llvm::StringSwitch<SectionType>(Name)
256-
.Case("abbrev", eSectionTypeDWARFDebugAbbrev)
257-
.Case("abbrev.dwo", eSectionTypeDWARFDebugAbbrevDwo)
258-
.Case("addr", eSectionTypeDWARFDebugAddr)
259-
.Case("aranges", eSectionTypeDWARFDebugAranges)
260-
.Case("cu_index", eSectionTypeDWARFDebugCuIndex)
261-
.Case("frame", eSectionTypeDWARFDebugFrame)
262-
.Case("info", eSectionTypeDWARFDebugInfo)
263-
.Case("info.dwo", eSectionTypeDWARFDebugInfoDwo)
264-
.Cases("line", "line.dwo", eSectionTypeDWARFDebugLine)
265-
.Cases("line_str", "line_str.dwo", eSectionTypeDWARFDebugLineStr)
266-
.Case("loc", eSectionTypeDWARFDebugLoc)
267-
.Case("loc.dwo", eSectionTypeDWARFDebugLocDwo)
268-
.Case("loclists", eSectionTypeDWARFDebugLocLists)
269-
.Case("loclists.dwo", eSectionTypeDWARFDebugLocListsDwo)
270-
.Case("macinfo", eSectionTypeDWARFDebugMacInfo)
271-
.Cases("macro", "macro.dwo", eSectionTypeDWARFDebugMacro)
272-
.Case("names", eSectionTypeDWARFDebugNames)
273-
.Case("pubnames", eSectionTypeDWARFDebugPubNames)
274-
.Case("pubtypes", eSectionTypeDWARFDebugPubTypes)
275-
.Case("ranges", eSectionTypeDWARFDebugRanges)
276-
.Case("rnglists", eSectionTypeDWARFDebugRngLists)
277-
.Case("rnglists.dwo", eSectionTypeDWARFDebugRngListsDwo)
278-
.Case("str", eSectionTypeDWARFDebugStr)
279-
.Case("str.dwo", eSectionTypeDWARFDebugStrDwo)
280-
.Case("str_offsets", eSectionTypeDWARFDebugStrOffsets)
281-
.Case("str_offsets.dwo", eSectionTypeDWARFDebugStrOffsetsDwo)
282-
.Case("tu_index", eSectionTypeDWARFDebugTuIndex)
283-
.Case("types", eSectionTypeDWARFDebugTypes)
284-
.Case("types.dwo", eSectionTypeDWARFDebugTypesDwo)
285-
.Default(eSectionTypeOther);
255+
return ObjectFile::GetDWARFSectionTypeFromName(Name);
286256
}
287257
return eSectionTypeOther;
288258
}

lldb/source/Symbol/ObjectFile.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,41 @@ ObjectFile::GetSymbolTypeFromName(llvm::StringRef name,
635635
return symbol_type_hint;
636636
}
637637

638+
lldb::SectionType
639+
ObjectFile::GetDWARFSectionTypeFromName(llvm::StringRef name) {
640+
return llvm::StringSwitch<SectionType>(name)
641+
.Case("abbrev", eSectionTypeDWARFDebugAbbrev)
642+
.Case("abbrev.dwo", eSectionTypeDWARFDebugAbbrevDwo)
643+
.Case("addr", eSectionTypeDWARFDebugAddr)
644+
.Case("aranges", eSectionTypeDWARFDebugAranges)
645+
.Case("cu_index", eSectionTypeDWARFDebugCuIndex)
646+
.Case("frame", eSectionTypeDWARFDebugFrame)
647+
.Case("info", eSectionTypeDWARFDebugInfo)
648+
.Case("info.dwo", eSectionTypeDWARFDebugInfoDwo)
649+
.Cases("line", "line.dwo", eSectionTypeDWARFDebugLine)
650+
.Cases("line_str", "line_str.dwo", eSectionTypeDWARFDebugLineStr)
651+
.Case("loc", eSectionTypeDWARFDebugLoc)
652+
.Case("loc.dwo", eSectionTypeDWARFDebugLocDwo)
653+
.Case("loclists", eSectionTypeDWARFDebugLocLists)
654+
.Case("loclists.dwo", eSectionTypeDWARFDebugLocListsDwo)
655+
.Case("macinfo", eSectionTypeDWARFDebugMacInfo)
656+
.Cases("macro", "macro.dwo", eSectionTypeDWARFDebugMacro)
657+
.Case("names", eSectionTypeDWARFDebugNames)
658+
.Case("pubnames", eSectionTypeDWARFDebugPubNames)
659+
.Case("pubtypes", eSectionTypeDWARFDebugPubTypes)
660+
.Case("ranges", eSectionTypeDWARFDebugRanges)
661+
.Case("rnglists", eSectionTypeDWARFDebugRngLists)
662+
.Case("rnglists.dwo", eSectionTypeDWARFDebugRngListsDwo)
663+
.Case("str", eSectionTypeDWARFDebugStr)
664+
.Case("str.dwo", eSectionTypeDWARFDebugStrDwo)
665+
.Case("str_offsets", eSectionTypeDWARFDebugStrOffsets)
666+
.Case("str_offsets.dwo", eSectionTypeDWARFDebugStrOffsetsDwo)
667+
.Case("tu_index", eSectionTypeDWARFDebugTuIndex)
668+
.Case("types", eSectionTypeDWARFDebugTypes)
669+
.Case("types.dwo", eSectionTypeDWARFDebugTypesDwo)
670+
.Default(eSectionTypeOther);
671+
}
672+
638673
std::vector<ObjectFile::LoadableData>
639674
ObjectFile::GetLoadableData(Target &target) {
640675
std::vector<LoadableData> loadables;

0 commit comments

Comments
 (0)