Index: lldb/trunk/lit/Breakpoint/Inputs/debug_rnglist_offset_pair.yaml =================================================================== --- lldb/trunk/lit/Breakpoint/Inputs/debug_rnglist_offset_pair.yaml +++ lldb/trunk/lit/Breakpoint/Inputs/debug_rnglist_offset_pair.yaml @@ -0,0 +1,53 @@ +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_EXEC + Machine: EM_X86_64 + Entry: 0x0000000000400440 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + Address: 0x0000000000400440 + AddressAlign: 0x0000000000000010 + Content: 31ED4989D15E4889E24883E4F0505449C7C0C005400048C7C15005400048C7C740054000E8B7FFFFFFF4660F1F44000055B820204000483D202040004889E57417B8000000004885C0740D5DBF20204000FFE00F1F4400005DC3660F1F440000BE20204000554881EE202040004889E548C1FE034889F048C1E83F4801C648D1FE7415B8000000004885C0740B5DBF20204000FFE00F1F005DC3660F1F440000803D391B0000007517554889E5E87EFFFFFFC605271B0000015DC30F1F440000F3C30F1F4000662E0F1F840000000000554889E55DEB89660F1F840000000000B9020000008B05F91A00000F1F44000021F883C1FF75F98905E71A0000C3669050BF01000000E8D5FFFFFF31C059C390415741564189FF415541544C8D25A618000055488D2DA6180000534989F64989D54C29E54883EC0848C1FD03E86FFEFFFF4885ED742031DB0F1F8400000000004C89EA4C89F64489FF41FF14DC4883C3014839EB75EA4883C4085B5D415C415D415E415FC390662E0F1F840000000000F3C3 + - Name: .debug_str_offsets + Type: SHT_PROGBITS + AddressAlign: 0x0000000000000001 + Content: 300000000500000000000000230000002C0000004F00000051000000550000005D0000006100000066000000680000006A000000 + - Name: .debug_str + Type: SHT_PROGBITS + Flags: [ SHF_MERGE, SHF_STRINGS ] + AddressAlign: 0x0000000000000001 + Content: 636C616E672076657273696F6E20382E302E3020287472756E6B203334343033352900746573742E637070002F686F6D652F756D622F74657374735F323031382F3130365F726E676C6973747332004300696E74005F5A33666F6F6900666F6F006D61696E00500049005700 + - Name: .debug_loc + Type: SHT_PROGBITS + AddressAlign: 0x0000000000000001 + Content: 05000000000000001000000000000000030011009F00000000000000000000000000000000 + - Name: .debug_abbrev + Type: SHT_PROGBITS + AddressAlign: 0x0000000000000001 + Content: 011101252513050325721710171B251101120674170000023400032549133F193A0B3B0B0218000003240003253E0B0B0B0000042E011101120640187A196E2503253A0B3B0B3F190000050500021803253A0B3B0B49130000060B01110112060000073400021703253A0B3B0B49130000080B015517000009340003253A0B3B0B491300000A2E011101120640187A1903253A0B3B0B49133F1900000B48007F137D0100000C0F004913000000 + - Name: .debug_info + Type: SHT_PROGBITS + AddressAlign: 0x0000000000000001 + Content: AC0000000500010800000000010004000108000000000000000220054000000000002F0000000C00000002033C000000010309032420400000000000030405040420054000000000001E0000000157050601040501550801043C0000000625054000000000001800000007000000000901063C000000080C000000090A0107AA0000000000000A40054000000000000F000000015707010E3C0000000B400000004B05400000000000000C3C00000000 + - Name: .debug_rnglists + Type: SHT_PROGBITS + AddressAlign: 0x0000000000000001 + Content: 18000000050008000000000005200540000000000004051204171D00 + - Name: .debug_macinfo + Type: SHT_PROGBITS + AddressAlign: 0x0000000000000001 + Content: '00' + - Name: .debug_line + Type: SHT_PROGBITS + AddressAlign: 0x0000000000000001 + Content: 7F000000050008004C000000010101FB0E0D00010101010000000100000101011F010000000003011F020F051E0223000000003D8C80E874CE6D5F1FC4A6544BE9D5B323000000003D8C80E874CE6D5F1FC4A6544BE9D5B300090220054000000000001605080A5B0515C60503063C0508063005016805004105030A21A00204000101 + - Name: .debug_line_str + Type: SHT_PROGBITS + Flags: [ SHF_MERGE, SHF_STRINGS ] + AddressAlign: 0x0000000000000001 + Content: 2F686F6D652F756D622F74657374735F323031382F3130365F726E676C697374733200746573742E63707000 +Symbols: Index: lldb/trunk/lit/Breakpoint/debug_rnglist_offset_pair.test =================================================================== --- lldb/trunk/lit/Breakpoint/debug_rnglist_offset_pair.test +++ lldb/trunk/lit/Breakpoint/debug_rnglist_offset_pair.test @@ -0,0 +1,33 @@ +# RUN: yaml2obj %p/Inputs/debug_rnglist_offset_pair.yaml > %ttest +# RUN: lldb-test breakpoints %ttest %s | FileCheck %s + +# The following code and invocation were used to produce asm file, +# which was manually edited to add DW_RLE_base_address entry. +# clang -S -g -gdwarf-5 -O1 test.cpp -o test.s +# Then it was compiled and converted to yaml. +# +# int C = 0; +# void foo(int P) +# { +# for (int I = 0; I < 2; ++I) { +# int *W = &C; +# *W &= P; +# } +# } +# +# int main () +# { +# foo (1); +# return 0; +# } +# +# clang and LLD versions were 8.0.0 (trunk 344035) +# +# Output file contains .debug_rnglists section with entries: +# DW_RLE_offset_pair and DW_RLE_base_address. + +b foo +# CHECK-LABEL: b foo +# CHECK: Address: {{.*}}`foo(int) + 5 at test.cpp:8:8 + + Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp =================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp @@ -456,20 +456,15 @@ break; case DW_AT_ranges: { - const DWARFDebugRanges *debug_ranges = dwarf2Data->DebugRanges(); - if (debug_ranges) { - debug_ranges->FindRanges(cu->GetRangesBase(), form_value.Unsigned(), ranges); - // All DW_AT_ranges are relative to the base address of the compile - // unit. We add the compile unit base address to make sure all the - // addresses are properly fixed up. - ranges.Slide(cu->GetBaseAddress()); - } else { + const DWARFDebugRangesBase *debug_ranges = dwarf2Data->DebugRanges(); + if (debug_ranges) + debug_ranges->FindRanges(cu, form_value.Unsigned(), ranges); + else cu->GetSymbolFileDWARF()->GetObjectFile()->GetModule()->ReportError( "{0x%8.8x}: DIE has DW_AT_ranges(0x%" PRIx64 ") attribute yet DWARF has no .debug_ranges, please file a bug " "and attach the file at the start of this error message", m_offset, form_value.Unsigned()); - } } break; case DW_AT_name: @@ -1065,10 +1060,8 @@ dwarf2Data, cu, DW_AT_ranges, DW_INVALID_OFFSET, check_specification_or_abstract_origin); if (debug_ranges_offset != DW_INVALID_OFFSET) { - if (DWARFDebugRanges *debug_ranges = dwarf2Data->DebugRanges()) - debug_ranges->FindRanges(cu->GetRangesBase(), debug_ranges_offset, - ranges); - ranges.Slide(cu->GetBaseAddress()); + if (DWARFDebugRangesBase *debug_ranges = dwarf2Data->DebugRanges()) + debug_ranges->FindRanges(cu, debug_ranges_offset, ranges); } else if (check_hi_lo_pc) { dw_addr_t lo_pc = LLDB_INVALID_ADDRESS; dw_addr_t hi_pc = LLDB_INVALID_ADDRESS; @@ -1723,12 +1716,9 @@ dwarf2Data, cu, DW_AT_ranges, DW_INVALID_OFFSET); if (debug_ranges_offset != DW_INVALID_OFFSET) { DWARFRangeList ranges; - DWARFDebugRanges *debug_ranges = dwarf2Data->DebugRanges(); - debug_ranges->FindRanges(cu->GetRangesBase(), debug_ranges_offset, ranges); - // All DW_AT_ranges are relative to the base address of the compile - // unit. We add the compile unit base address to make sure all the - // addresses are properly fixed up. - ranges.Slide(cu->GetBaseAddress()); + DWARFDebugRangesBase *debug_ranges = dwarf2Data->DebugRanges(); + debug_ranges->FindRanges(cu, debug_ranges_offset, ranges); + if (ranges.FindEntryThatContains(address)) { found_address = true; // puts("***MATCH***"); Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.h =================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.h +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.h @@ -15,18 +15,26 @@ #include -class DWARFDebugRanges { +class DWARFDebugRangesBase { +public: + virtual ~DWARFDebugRangesBase(){}; + + virtual void Extract(SymbolFileDWARF *dwarf2Data) = 0; + virtual bool FindRanges(const DWARFUnit *cu, dw_offset_t debug_ranges_offset, + DWARFRangeList &range_list) const = 0; +}; + +class DWARFDebugRanges final : public DWARFDebugRangesBase { public: DWARFDebugRanges(); - virtual ~DWARFDebugRanges(); - virtual void Extract(SymbolFileDWARF *dwarf2Data); + + virtual void Extract(SymbolFileDWARF *dwarf2Data) override; + virtual bool FindRanges(const DWARFUnit *cu, dw_offset_t debug_ranges_offset, + DWARFRangeList &range_list) const override; static void Dump(lldb_private::Stream &s, const lldb_private::DWARFDataExtractor &debug_ranges_data, lldb::offset_t *offset_ptr, dw_addr_t cu_base_addr); - bool FindRanges(dw_addr_t debug_ranges_base, - dw_offset_t debug_ranges_offset, - DWARFRangeList &range_list) const; protected: bool Extract(SymbolFileDWARF *dwarf2Data, lldb::offset_t *offset_ptr, @@ -39,16 +47,25 @@ }; // DWARF v5 .debug_rnglists section. -class DWARFDebugRngLists : public DWARFDebugRanges { +class DWARFDebugRngLists final : public DWARFDebugRangesBase { + struct RngListEntry { + uint8_t encoding; + uint64_t value0; + uint64_t value1; + }; + public: void Extract(SymbolFileDWARF *dwarf2Data) override; + bool FindRanges(const DWARFUnit *cu, dw_offset_t debug_ranges_offset, + DWARFRangeList &range_list) const override; protected: bool ExtractRangeList(const lldb_private::DWARFDataExtractor &data, uint8_t addrSize, lldb::offset_t *offset_ptr, - DWARFRangeList &list); + std::vector &list); std::vector Offsets; + std::map> m_range_map; }; #endif // SymbolFileDWARF_DWARFDebugRanges_h_ Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp =================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// #include "DWARFDebugRanges.h" +#include "DWARFUnit.h" #include "SymbolFileDWARF.h" #include "lldb/Utility/Stream.h" #include @@ -29,8 +30,6 @@ DWARFDebugRanges::DWARFDebugRanges() : m_range_map() {} -DWARFDebugRanges::~DWARFDebugRanges() {} - void DWARFDebugRanges::Extract(SymbolFileDWARF *dwarf2Data) { DWARFRangeList range_list; lldb::offset_t offset = 0; @@ -112,23 +111,27 @@ } } -bool DWARFDebugRanges::FindRanges(dw_addr_t debug_ranges_base, +bool DWARFDebugRanges::FindRanges(const DWARFUnit *cu, dw_offset_t debug_ranges_offset, DWARFRangeList &range_list) const { - dw_addr_t debug_ranges_address = debug_ranges_base + debug_ranges_offset; + dw_addr_t debug_ranges_address = cu->GetRangesBase() + debug_ranges_offset; range_map_const_iterator pos = m_range_map.find(debug_ranges_address); if (pos != m_range_map.end()) { range_list = pos->second; + + // All DW_AT_ranges are relative to the base address of the compile + // unit. We add the compile unit base address to make sure all the + // addresses are properly fixed up. + range_list.Slide(cu->GetBaseAddress()); return true; } return false; } -bool DWARFDebugRngLists::ExtractRangeList(const DWARFDataExtractor &data, - uint8_t addrSize, - lldb::offset_t *offset_ptr, - DWARFRangeList &rangeList) { - rangeList.Clear(); +bool DWARFDebugRngLists::ExtractRangeList( + const DWARFDataExtractor &data, uint8_t addrSize, + lldb::offset_t *offset_ptr, std::vector &rangeList) { + rangeList.clear(); bool error = false; while (!error) { @@ -139,14 +142,27 @@ case DW_RLE_start_length: { dw_addr_t begin = data.GetMaxU64(offset_ptr, addrSize); dw_addr_t len = data.GetULEB128(offset_ptr); - rangeList.Append(DWARFRangeList::Entry(begin, len)); + rangeList.push_back({DW_RLE_start_length, begin, len}); break; } case DW_RLE_start_end: { dw_addr_t begin = data.GetMaxU64(offset_ptr, addrSize); dw_addr_t end = data.GetMaxU64(offset_ptr, addrSize); - rangeList.Append(DWARFRangeList::Entry(begin, end - begin)); + rangeList.push_back({DW_RLE_start_end, begin, end - begin}); + break; + } + + case DW_RLE_base_address: { + dw_addr_t base = data.GetMaxU64(offset_ptr, addrSize); + rangeList.push_back({DW_RLE_base_address, base, 0}); + break; + } + + case DW_RLE_offset_pair: { + dw_addr_t begin = data.GetULEB128(offset_ptr); + dw_addr_t end = data.GetULEB128(offset_ptr); + rangeList.push_back({DW_RLE_offset_pair, begin, end}); break; } @@ -162,6 +178,35 @@ return false; } +bool DWARFDebugRngLists::FindRanges(const DWARFUnit *cu, + dw_offset_t debug_ranges_offset, + DWARFRangeList &range_list) const { + range_list.Clear(); + dw_addr_t debug_ranges_address = cu->GetRangesBase() + debug_ranges_offset; + auto pos = m_range_map.find(debug_ranges_address); + if (pos != m_range_map.end()) { + dw_addr_t BaseAddr = cu->GetBaseAddress(); + for (const RngListEntry &E : pos->second) { + switch (E.encoding) { + case DW_RLE_start_length: + range_list.Append(DWARFRangeList::Entry(E.value0, E.value1)); + break; + case DW_RLE_base_address: + BaseAddr = E.value0; + break; + case DW_RLE_offset_pair: + range_list.Append( + DWARFRangeList::Entry(BaseAddr + E.value0, E.value1 - E.value0)); + break; + default: + llvm_unreachable("unexpected encoding"); + } + } + return true; + } + return false; +} + void DWARFDebugRngLists::Extract(SymbolFileDWARF *dwarf2Data) { const DWARFDataExtractor &data = dwarf2Data->get_debug_rnglists_data(); lldb::offset_t offset = 0; @@ -191,9 +236,8 @@ Offsets.push_back(data.GetPointer(&offset)); lldb::offset_t listOffset = offset; - DWARFRangeList rangeList; + std::vector rangeList; while (offset < end && ExtractRangeList(data, addrSize, &offset, rangeList)) { - rangeList.Sort(); m_range_map[listOffset] = rangeList; listOffset = offset; } Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h =================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h @@ -53,8 +53,7 @@ class DWARFDebugInfo; class DWARFDebugInfoEntry; class DWARFDebugLine; -class DWARFDebugRanges; -class DWARFDebugRngLists; +class DWARFDebugRangesBase; class DWARFDeclContext; class DWARFDIECollection; class DWARFFormValue; @@ -266,9 +265,9 @@ const DWARFDebugInfo *DebugInfo() const; - DWARFDebugRanges *DebugRanges(); + DWARFDebugRangesBase *DebugRanges(); - const DWARFDebugRanges *DebugRanges() const; + const DWARFDebugRangesBase *DebugRanges() const; const lldb_private::DWARFDataExtractor &DebugLocData(); @@ -512,7 +511,7 @@ typedef std::shared_ptr> DIERefSetSP; typedef std::unordered_map NameToOffsetMap; NameToOffsetMap m_function_scope_qualified_name_map; - std::unique_ptr m_ranges; + std::unique_ptr m_ranges; UniqueDWARFASTTypeMap m_unique_ast_type_map; DIEToTypePtr m_die_to_type; DIEToVariableSP m_die_to_variable_sp; Index: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp =================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -769,7 +769,7 @@ return NULL; } -DWARFDebugRanges *SymbolFileDWARF::DebugRanges() { +DWARFDebugRangesBase *SymbolFileDWARF::DebugRanges() { if (m_ranges.get() == NULL) { static Timer::Category func_cat(LLVM_PRETTY_FUNCTION); Timer scoped_timer(func_cat, "%s this = %p", LLVM_PRETTY_FUNCTION, @@ -786,7 +786,7 @@ return m_ranges.get(); } -const DWARFDebugRanges *SymbolFileDWARF::DebugRanges() const { +const DWARFDebugRangesBase *SymbolFileDWARF::DebugRanges() const { return m_ranges.get(); } @@ -3379,15 +3379,10 @@ case DW_AT_start_scope: { if (form_value.Form() == DW_FORM_sec_offset) { DWARFRangeList dwarf_scope_ranges; - const DWARFDebugRanges *debug_ranges = DebugRanges(); - debug_ranges->FindRanges(die.GetCU()->GetRangesBase(), + const DWARFDebugRangesBase *debug_ranges = DebugRanges(); + debug_ranges->FindRanges(die.GetCU(), form_value.Unsigned(), dwarf_scope_ranges); - - // All DW_AT_start_scope are relative to the base address of the - // compile unit. We add the compile unit base address to make - // sure all the addresses are properly fixed up. - dwarf_scope_ranges.Slide(die.GetCU()->GetBaseAddress()); } else { // TODO: Handle the case when DW_AT_start_scope have form // constant. The