Recommit r345127 "[LLDB] - Add support for DW_RLE_base_address and DW_RLE_offset_pair entries (.debug_rnglists)"

With the fix: do not forget to hanlde the DW_RLE_start_end, which seems was
omited/forgotten/removed by mistake.

Original commit message:

The patch implements the support for DW_RLE_base_address and DW_RLE_offset_pair
.debug_rnglists entries

Differential revision: https://reviews.llvm.org/D53140
----
Added : /lldb/trunk/lit/Breakpoint/Inputs/debug_rnglist_offset_pair.yaml
Added : /lldb/trunk/lit/Breakpoint/debug_rnglist_offset_pair.test
Modified : /lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
Modified : /lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.cpp
Modified : /lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugRanges.h
Modified : /lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
Modified : /lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h

llvm-svn: 345251
This commit is contained in:
George Rimar 2018-10-25 10:25:45 +00:00
parent 9a24e1a7cd
commit 7e7f9c1008
7 changed files with 188 additions and 54 deletions

View File

@ -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:

View File

@ -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

View File

@ -456,20 +456,15 @@ bool DWARFDebugInfoEntry::GetDIENamesAndRanges(
break; break;
case DW_AT_ranges: { case DW_AT_ranges: {
const DWARFDebugRanges *debug_ranges = dwarf2Data->DebugRanges(); const DWARFDebugRangesBase *debug_ranges = dwarf2Data->DebugRanges();
if (debug_ranges) { if (debug_ranges)
debug_ranges->FindRanges(cu->GetRangesBase(), form_value.Unsigned(), ranges); debug_ranges->FindRanges(cu, form_value.Unsigned(), ranges);
// All DW_AT_ranges are relative to the base address of the compile else
// unit. We add the compile unit base address to make sure all the
// addresses are properly fixed up.
ranges.Slide(cu->GetBaseAddress());
} else {
cu->GetSymbolFileDWARF()->GetObjectFile()->GetModule()->ReportError( cu->GetSymbolFileDWARF()->GetObjectFile()->GetModule()->ReportError(
"{0x%8.8x}: DIE has DW_AT_ranges(0x%" PRIx64 "{0x%8.8x}: DIE has DW_AT_ranges(0x%" PRIx64
") attribute yet DWARF has no .debug_ranges, please file a bug " ") attribute yet DWARF has no .debug_ranges, please file a bug "
"and attach the file at the start of this error message", "and attach the file at the start of this error message",
m_offset, form_value.Unsigned()); m_offset, form_value.Unsigned());
}
} break; } break;
case DW_AT_name: case DW_AT_name:
@ -1065,10 +1060,8 @@ size_t DWARFDebugInfoEntry::GetAttributeAddressRanges(
dwarf2Data, cu, DW_AT_ranges, DW_INVALID_OFFSET, dwarf2Data, cu, DW_AT_ranges, DW_INVALID_OFFSET,
check_specification_or_abstract_origin); check_specification_or_abstract_origin);
if (debug_ranges_offset != DW_INVALID_OFFSET) { if (debug_ranges_offset != DW_INVALID_OFFSET) {
if (DWARFDebugRanges *debug_ranges = dwarf2Data->DebugRanges()) if (DWARFDebugRangesBase *debug_ranges = dwarf2Data->DebugRanges())
debug_ranges->FindRanges(cu->GetRangesBase(), debug_ranges_offset, debug_ranges->FindRanges(cu, debug_ranges_offset, ranges);
ranges);
ranges.Slide(cu->GetBaseAddress());
} else if (check_hi_lo_pc) { } else if (check_hi_lo_pc) {
dw_addr_t lo_pc = LLDB_INVALID_ADDRESS; dw_addr_t lo_pc = LLDB_INVALID_ADDRESS;
dw_addr_t hi_pc = LLDB_INVALID_ADDRESS; dw_addr_t hi_pc = LLDB_INVALID_ADDRESS;
@ -1723,12 +1716,9 @@ bool DWARFDebugInfoEntry::LookupAddress(const dw_addr_t address,
dwarf2Data, cu, DW_AT_ranges, DW_INVALID_OFFSET); dwarf2Data, cu, DW_AT_ranges, DW_INVALID_OFFSET);
if (debug_ranges_offset != DW_INVALID_OFFSET) { if (debug_ranges_offset != DW_INVALID_OFFSET) {
DWARFRangeList ranges; DWARFRangeList ranges;
DWARFDebugRanges *debug_ranges = dwarf2Data->DebugRanges(); DWARFDebugRangesBase *debug_ranges = dwarf2Data->DebugRanges();
debug_ranges->FindRanges(cu->GetRangesBase(), debug_ranges_offset, ranges); debug_ranges->FindRanges(cu, 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());
if (ranges.FindEntryThatContains(address)) { if (ranges.FindEntryThatContains(address)) {
found_address = true; found_address = true;
// puts("***MATCH***"); // puts("***MATCH***");

View File

@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "DWARFDebugRanges.h" #include "DWARFDebugRanges.h"
#include "DWARFUnit.h"
#include "SymbolFileDWARF.h" #include "SymbolFileDWARF.h"
#include "lldb/Utility/Stream.h" #include "lldb/Utility/Stream.h"
#include <assert.h> #include <assert.h>
@ -29,8 +30,6 @@ static dw_addr_t GetBaseAddressMarker(uint32_t addr_size) {
DWARFDebugRanges::DWARFDebugRanges() : m_range_map() {} DWARFDebugRanges::DWARFDebugRanges() : m_range_map() {}
DWARFDebugRanges::~DWARFDebugRanges() {}
void DWARFDebugRanges::Extract(SymbolFileDWARF *dwarf2Data) { void DWARFDebugRanges::Extract(SymbolFileDWARF *dwarf2Data) {
DWARFRangeList range_list; DWARFRangeList range_list;
lldb::offset_t offset = 0; lldb::offset_t offset = 0;
@ -112,23 +111,27 @@ void DWARFDebugRanges::Dump(Stream &s,
} }
} }
bool DWARFDebugRanges::FindRanges(dw_addr_t debug_ranges_base, bool DWARFDebugRanges::FindRanges(const DWARFUnit *cu,
dw_offset_t debug_ranges_offset, dw_offset_t debug_ranges_offset,
DWARFRangeList &range_list) const { 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); range_map_const_iterator pos = m_range_map.find(debug_ranges_address);
if (pos != m_range_map.end()) { if (pos != m_range_map.end()) {
range_list = pos->second; 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 true;
} }
return false; return false;
} }
bool DWARFDebugRngLists::ExtractRangeList(const DWARFDataExtractor &data, bool DWARFDebugRngLists::ExtractRangeList(
uint8_t addrSize, const DWARFDataExtractor &data, uint8_t addrSize,
lldb::offset_t *offset_ptr, lldb::offset_t *offset_ptr, std::vector<RngListEntry> &rangeList) {
DWARFRangeList &rangeList) { rangeList.clear();
rangeList.Clear();
bool error = false; bool error = false;
while (!error) { while (!error) {
@ -139,14 +142,27 @@ bool DWARFDebugRngLists::ExtractRangeList(const DWARFDataExtractor &data,
case DW_RLE_start_length: { case DW_RLE_start_length: {
dw_addr_t begin = data.GetMaxU64(offset_ptr, addrSize); dw_addr_t begin = data.GetMaxU64(offset_ptr, addrSize);
dw_addr_t len = data.GetULEB128(offset_ptr); dw_addr_t len = data.GetULEB128(offset_ptr);
rangeList.Append(DWARFRangeList::Entry(begin, len)); rangeList.push_back({DW_RLE_start_length, begin, len});
break; break;
} }
case DW_RLE_start_end: { case DW_RLE_start_end: {
dw_addr_t begin = data.GetMaxU64(offset_ptr, addrSize); dw_addr_t begin = data.GetMaxU64(offset_ptr, addrSize);
dw_addr_t end = 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});
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; break;
} }
@ -162,6 +178,38 @@ bool DWARFDebugRngLists::ExtractRangeList(const DWARFDataExtractor &data,
return false; 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_start_end:
range_list.Append(DWARFRangeList::Entry(E.value0, E.value1 - 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) { void DWARFDebugRngLists::Extract(SymbolFileDWARF *dwarf2Data) {
const DWARFDataExtractor &data = dwarf2Data->get_debug_rnglists_data(); const DWARFDataExtractor &data = dwarf2Data->get_debug_rnglists_data();
lldb::offset_t offset = 0; lldb::offset_t offset = 0;
@ -191,9 +239,8 @@ void DWARFDebugRngLists::Extract(SymbolFileDWARF *dwarf2Data) {
Offsets.push_back(data.GetPointer(&offset)); Offsets.push_back(data.GetPointer(&offset));
lldb::offset_t listOffset = offset; lldb::offset_t listOffset = offset;
DWARFRangeList rangeList; std::vector<RngListEntry> rangeList;
while (offset < end && ExtractRangeList(data, addrSize, &offset, rangeList)) { while (offset < end && ExtractRangeList(data, addrSize, &offset, rangeList)) {
rangeList.Sort();
m_range_map[listOffset] = rangeList; m_range_map[listOffset] = rangeList;
listOffset = offset; listOffset = offset;
} }

View File

@ -15,18 +15,26 @@
#include <map> #include <map>
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: public:
DWARFDebugRanges(); 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, static void Dump(lldb_private::Stream &s,
const lldb_private::DWARFDataExtractor &debug_ranges_data, const lldb_private::DWARFDataExtractor &debug_ranges_data,
lldb::offset_t *offset_ptr, dw_addr_t cu_base_addr); 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: protected:
bool Extract(SymbolFileDWARF *dwarf2Data, lldb::offset_t *offset_ptr, bool Extract(SymbolFileDWARF *dwarf2Data, lldb::offset_t *offset_ptr,
@ -39,16 +47,25 @@ protected:
}; };
// DWARF v5 .debug_rnglists section. // 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: public:
void Extract(SymbolFileDWARF *dwarf2Data) override; void Extract(SymbolFileDWARF *dwarf2Data) override;
bool FindRanges(const DWARFUnit *cu, dw_offset_t debug_ranges_offset,
DWARFRangeList &range_list) const override;
protected: protected:
bool ExtractRangeList(const lldb_private::DWARFDataExtractor &data, bool ExtractRangeList(const lldb_private::DWARFDataExtractor &data,
uint8_t addrSize, lldb::offset_t *offset_ptr, uint8_t addrSize, lldb::offset_t *offset_ptr,
DWARFRangeList &list); std::vector<RngListEntry> &list);
std::vector<uint64_t> Offsets; std::vector<uint64_t> Offsets;
std::map<dw_offset_t, std::vector<RngListEntry>> m_range_map;
}; };
#endif // SymbolFileDWARF_DWARFDebugRanges_h_ #endif // SymbolFileDWARF_DWARFDebugRanges_h_

View File

@ -769,7 +769,7 @@ SymbolFileDWARF::GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit) {
return NULL; return NULL;
} }
DWARFDebugRanges *SymbolFileDWARF::DebugRanges() { DWARFDebugRangesBase *SymbolFileDWARF::DebugRanges() {
if (m_ranges.get() == NULL) { if (m_ranges.get() == NULL) {
static Timer::Category func_cat(LLVM_PRETTY_FUNCTION); static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
Timer scoped_timer(func_cat, "%s this = %p", LLVM_PRETTY_FUNCTION, Timer scoped_timer(func_cat, "%s this = %p", LLVM_PRETTY_FUNCTION,
@ -786,7 +786,7 @@ DWARFDebugRanges *SymbolFileDWARF::DebugRanges() {
return m_ranges.get(); return m_ranges.get();
} }
const DWARFDebugRanges *SymbolFileDWARF::DebugRanges() const { const DWARFDebugRangesBase *SymbolFileDWARF::DebugRanges() const {
return m_ranges.get(); return m_ranges.get();
} }
@ -3379,15 +3379,10 @@ VariableSP SymbolFileDWARF::ParseVariableDIE(const SymbolContext &sc,
case DW_AT_start_scope: { case DW_AT_start_scope: {
if (form_value.Form() == DW_FORM_sec_offset) { if (form_value.Form() == DW_FORM_sec_offset) {
DWARFRangeList dwarf_scope_ranges; DWARFRangeList dwarf_scope_ranges;
const DWARFDebugRanges *debug_ranges = DebugRanges(); const DWARFDebugRangesBase *debug_ranges = DebugRanges();
debug_ranges->FindRanges(die.GetCU()->GetRangesBase(), debug_ranges->FindRanges(die.GetCU(),
form_value.Unsigned(), form_value.Unsigned(),
dwarf_scope_ranges); 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 { } else {
// TODO: Handle the case when DW_AT_start_scope have form // TODO: Handle the case when DW_AT_start_scope have form
// constant. The // constant. The

View File

@ -53,8 +53,7 @@ class DWARFDebugAranges;
class DWARFDebugInfo; class DWARFDebugInfo;
class DWARFDebugInfoEntry; class DWARFDebugInfoEntry;
class DWARFDebugLine; class DWARFDebugLine;
class DWARFDebugRanges; class DWARFDebugRangesBase;
class DWARFDebugRngLists;
class DWARFDeclContext; class DWARFDeclContext;
class DWARFDIECollection; class DWARFDIECollection;
class DWARFFormValue; class DWARFFormValue;
@ -266,9 +265,9 @@ public:
const DWARFDebugInfo *DebugInfo() const; const DWARFDebugInfo *DebugInfo() const;
DWARFDebugRanges *DebugRanges(); DWARFDebugRangesBase *DebugRanges();
const DWARFDebugRanges *DebugRanges() const; const DWARFDebugRangesBase *DebugRanges() const;
const lldb_private::DWARFDataExtractor &DebugLocData(); const lldb_private::DWARFDataExtractor &DebugLocData();
@ -512,7 +511,7 @@ protected:
typedef std::shared_ptr<std::set<DIERef>> DIERefSetSP; typedef std::shared_ptr<std::set<DIERef>> DIERefSetSP;
typedef std::unordered_map<std::string, DIERefSetSP> NameToOffsetMap; typedef std::unordered_map<std::string, DIERefSetSP> NameToOffsetMap;
NameToOffsetMap m_function_scope_qualified_name_map; NameToOffsetMap m_function_scope_qualified_name_map;
std::unique_ptr<DWARFDebugRanges> m_ranges; std::unique_ptr<DWARFDebugRangesBase> m_ranges;
UniqueDWARFASTTypeMap m_unique_ast_type_map; UniqueDWARFASTTypeMap m_unique_ast_type_map;
DIEToTypePtr m_die_to_type; DIEToTypePtr m_die_to_type;
DIEToVariableSP m_die_to_variable_sp; DIEToVariableSP m_die_to_variable_sp;