[Lldb-commits] [lldb] 8131cb6 - [lldb/DWARF] Add support for location lists in package files
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Wed Feb 19 05:38:12 PST 2020
Author: Pavel Labath
Date: 2020-02-19T14:33:58+01:00
New Revision: 8131cb6e18931e4cb642a1dfaa7c219c38656442
URL: https://github.com/llvm/llvm-project/commit/8131cb6e18931e4cb642a1dfaa7c219c38656442
DIFF: https://github.com/llvm/llvm-project/commit/8131cb6e18931e4cb642a1dfaa7c219c38656442.diff
LOG: [lldb/DWARF] Add support for location lists in package files
The only thing needed was to account for the offset from the
debug_cu_index section when searching for the location list.
This patch also fixes a bug in the Module::ParseAllDebugSymbols
function, which meant that we would only parse the variables of the
first compile unit in the module. This function is only used from
lldb-test, so this does not fix any real issue, besides preventing me
from writing a test for this patch.
Added:
Modified:
lldb/source/Core/Module.cpp
lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h
lldb/test/Shell/SymbolFile/DWARF/dwp.s
Removed:
################################################################################
diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp
index e61b875c3399..e917980791c2 100644
--- a/lldb/source/Core/Module.cpp
+++ b/lldb/source/Core/Module.cpp
@@ -364,11 +364,11 @@ void Module::ParseAllDebugSymbols() {
if (num_comp_units == 0)
return;
- SymbolContext sc;
- sc.module_sp = shared_from_this();
SymbolFile *symbols = GetSymbolFile();
for (size_t cu_idx = 0; cu_idx < num_comp_units; cu_idx++) {
+ SymbolContext sc;
+ sc.module_sp = shared_from_this();
sc.comp_unit = symbols->GetCompileUnitAtIndex(cu_idx).get();
if (!sc.comp_unit)
continue;
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
index 6ff3601ab049..0198a10645c2 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
@@ -474,10 +474,17 @@ DWARFUnit::GetLocationTable(const DataExtractor &data) const {
return std::make_unique<llvm::DWARFDebugLoc>(llvm_data);
}
-const DWARFDataExtractor &DWARFUnit::GetLocationData() const {
+DWARFDataExtractor DWARFUnit::GetLocationData() const {
DWARFContext &Ctx = GetSymbolFileDWARF().GetDWARFContext();
- return GetVersion() >= 5 ? Ctx.getOrLoadLocListsData()
- : Ctx.getOrLoadLocData();
+ const DWARFDataExtractor &data =
+ GetVersion() >= 5 ? Ctx.getOrLoadLocListsData() : Ctx.getOrLoadLocData();
+ if (const llvm::DWARFUnitIndex::Entry *entry = m_header.GetIndexEntry()) {
+ if (const auto *contribution = entry->getOffset(llvm::DW_SECT_LOC))
+ return DWARFDataExtractor(data, contribution->Offset,
+ contribution->Length);
+ return DWARFDataExtractor();
+ }
+ return data;
}
void DWARFUnit::SetRangesBase(dw_addr_t ranges_base) {
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h
index f15086d9504d..938a49453e37 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h
@@ -255,7 +255,7 @@ class DWARFUnit : public lldb_private::UserID {
std::unique_ptr<llvm::DWARFLocationTable>
GetLocationTable(const lldb_private::DataExtractor &data) const;
- const lldb_private::DWARFDataExtractor &GetLocationData() const;
+ lldb_private::DWARFDataExtractor GetLocationData() const;
protected:
DWARFUnit(SymbolFileDWARF &dwarf, lldb::user_id_t uid,
diff --git a/lldb/test/Shell/SymbolFile/DWARF/dwp.s b/lldb/test/Shell/SymbolFile/DWARF/dwp.s
index 23fcde872947..730609412c36 100644
--- a/lldb/test/Shell/SymbolFile/DWARF/dwp.s
+++ b/lldb/test/Shell/SymbolFile/DWARF/dwp.s
@@ -2,23 +2,49 @@
# RUN: llvm-mc --filetype=obj --triple x86_64-pc-linux %s -o %t --defsym MAIN=0
# RUN: llvm-mc --filetype=obj --triple x86_64-pc-linux %s -o %t.dwp --defsym DWP=0
-# RUN: %lldb %t -o "target variable A" -b | FileCheck %s
+# RUN: %lldb %t -o "target variable A" -o "image lookup -v -n F1" -b | FileCheck %s
# RUN: lldb-test symbols %t | FileCheck %s --check-prefix=SYMBOLS
+# CHECK-LABEL: target variable A
# CHECK: (INT0) A = 0
# CHECK: (INT1) A = 1
# CHECK: (INT2) A = 2
# CHECK: (INT3) A = 3
+# CHECK-LABEL: image lookup -v -n F1
+# CHECK: CompileUnit: id = {0x00000001}, file = "1.c", language = "unknown"
+# CHECK: Function: {{.*}}, name = "F1", range = [0x0000000000000001-0x0000000000000002)
+# CHECK: Variable: {{.*}}, name = "x", type = "int", location = DW_OP_reg1 RDX
+
# SYMBOLS: Compile units:
# SYMBOLS-NEXT: CompileUnit{0x00000000}, language = "unknown", file = '0.c'
# SYMBOLS-NEXT: Variable{{.*}}, name = "A", {{.*}}, location = DW_OP_GNU_addr_index 0x0
+# SYMBOLS-NEXT: Function{{.*}}, demangled = F0
+# SYMBOLS-NEXT: Block{{.*}}, ranges = [0x00000000-0x00000001)
+# SYMBOLS-NEXT: Variable{{.*}}, name = "x", {{.*}}, location =
+# SYMBOLS-NEXT: DW_LLE_startx_length (0x0000000000000001, 0x0000000000000001): DW_OP_reg0 RAX
+# SYMBOLS-EMPTY:
# SYMBOLS-NEXT: CompileUnit{0x00000001}, language = "unknown", file = '1.c'
-# SYMBOLS-NEXT: Variable{{.*}}, name = "A", {{.*}}, location = DW_OP_GNU_addr_index 0x1
-# SYMBOLS-NEXT: CompileUnit{0x00000002}, language = "unknown", file = '2.c'
# SYMBOLS-NEXT: Variable{{.*}}, name = "A", {{.*}}, location = DW_OP_GNU_addr_index 0x2
+# SYMBOLS-NEXT: Function{{.*}}, demangled = F1
+# SYMBOLS-NEXT: Block{{.*}}, ranges = [0x00000001-0x00000002)
+# SYMBOLS-NEXT: Variable{{.*}}, name = "x", {{.*}}, location =
+# SYMBOLS-NEXT: DW_LLE_startx_length (0x0000000000000003, 0x0000000000000001): DW_OP_reg1 RDX
+# SYMBOLS-EMPTY:
+# SYMBOLS-NEXT: CompileUnit{0x00000002}, language = "unknown", file = '2.c'
+# SYMBOLS-NEXT: Variable{{.*}}, name = "A", {{.*}}, location = DW_OP_GNU_addr_index 0x4
+# SYMBOLS-NEXT: Function{{.*}}, demangled = F2
+# SYMBOLS-NEXT: Block{{.*}}, ranges = [0x00000002-0x00000003)
+# SYMBOLS-NEXT: Variable{{.*}}, name = "x", {{.*}}, location =
+# SYMBOLS-NEXT: DW_LLE_startx_length (0x0000000000000005, 0x0000000000000001): DW_OP_reg2 RCX
+# SYMBOLS-EMPTY:
# SYMBOLS-NEXT: CompileUnit{0x00000003}, language = "unknown", file = '3.c'
-# SYMBOLS-NEXT: Variable{{.*}}, name = "A", {{.*}}, location = DW_OP_GNU_addr_index 0x3
+# SYMBOLS-NEXT: Variable{{.*}}, name = "A", {{.*}}, location = DW_OP_GNU_addr_index 0x6
+# SYMBOLS-NEXT: Function{{.*}}, demangled = F3
+# SYMBOLS-NEXT: Block{{.*}}, ranges = [0x00000003-0x00000004)
+# SYMBOLS-NEXT: Variable{{.*}}, name = "x", {{.*}}, location =
+# SYMBOLS-NEXT: DW_LLE_startx_length (0x0000000000000007, 0x0000000000000001): DW_OP_reg3 RBX
+# SYMBOLS-EMPTY:
# SYMBOLS-NEXT: CompileUnit{0x00000004}, language = "unknown", file = ''
# SYMBOLS-EMPTY:
@@ -32,6 +58,8 @@
.byte 7 # DW_FORM_data8
.ascii "\263B" # DW_AT_GNU_addr_base
.byte 23 # DW_FORM_sec_offset
+ .byte 85 # DW_AT_ranges
+ .byte 23 # DW_FORM_sec_offset
.byte 0 # EOM(1)
.byte 0 # EOM(2)
.byte 0 # EOM(3)
@@ -42,6 +70,10 @@
A\I:
.long \I
+ .text
+F\I:
+ nop
+
.section .debug_info,"", at progbits
.Lcu_begin\I:
.long .Ldebug_info_end\I-.Ldebug_info_start\I # Length of Unit
@@ -53,10 +85,19 @@ A\I:
.asciz "A.dwo" # DW_AT_GNU_dwo_name
.quad \I # DW_AT_GNU_dwo_id
.long .debug_addr # DW_AT_GNU_addr_base
+ .long .Lranges\I # DW_AT_ranges
.Ldebug_info_end\I:
.section .debug_addr,"", at progbits
.quad A\I
+ .quad F\I
+
+ .section .debug_ranges,"", at progbits
+.Lranges\I:
+ .quad F\I
+ .quad F\I+1
+ .quad 0
+ .quad 0
.endr
.endif
@@ -73,6 +114,16 @@ A\I:
.long .Lstr\I-.debug_str.dwo
.Lstr_offsets_end\I:
+ .section .debug_loc.dwo,"e", at progbits
+.Lloc\I:
+ .byte 3 # DW_LLE_startx_length
+ .uleb128 \I*2+1
+ .long 1
+ .short 1 # Expression size
+ .byte 80+\I # super-register DW_OP_reg0+\I
+ .byte 0 # DW_LLE_end_of_list
+.Lloc_end\I:
+
.section .debug_abbrev.dwo,"e", at progbits
.Labbrev\I:
.byte \I*10+1 # Abbreviation Code
@@ -115,6 +166,28 @@ A\I:
.byte 19 # DW_FORM_ref4
.byte 0 # EOM(1)
.byte 0 # EOM(2)
+ .byte \I*10+5 # Abbreviation Code
+ .byte 46 # DW_TAG_subprogram
+ .byte 1 # DW_CHILDREN_yes
+ .byte 17 # DW_AT_low_pc
+ .uleb128 0x1f01 # DW_FORM_GNU_addr_index
+ .byte 18 # DW_AT_high_pc
+ .byte 11 # DW_FORM_data1
+ .byte 3 # DW_AT_name
+ .byte 8 # DW_FORM_string
+ .byte 0 # EOM(1)
+ .byte 0 # EOM(2)
+ .byte \I*10+6 # Abbreviation Code
+ .byte 5 # DW_TAG_formal_parameter
+ .byte 0 # DW_CHILDREN_no
+ .byte 2 # DW_AT_location
+ .byte 23 # DW_FORM_sec_offset
+ .byte 3 # DW_AT_name
+ .byte 8 # DW_FORM_string
+ .byte 73 # DW_AT_type
+ .byte 19 # DW_FORM_ref4
+ .byte 0 # EOM(1)
+ .byte 0 # EOM(2)
.byte 0 # EOM(3)
.Labbrev_end\I:
@@ -133,7 +206,7 @@ A\I:
.long .Ltypedef\I-.Lcu_begin\I# DW_AT_type
.byte 2 # DW_AT_location
.byte 0xfb # DW_OP_GNU_addr_index
- .byte \I
+ .byte \I*2
.Ltypedef\I:
.byte \I*10+4 # Abbrev DW_TAG_typedef
.byte 0 # DW_AT_name
@@ -143,6 +216,18 @@ A\I:
.asciz "int" # DW_AT_name
.byte 5 # DW_AT_encoding
.byte 4 # DW_AT_byte_size
+
+ .byte \I*10+5 # Abbrev DW_TAG_subprogram
+ .uleb128 \I*2+1 # DW_AT_low_pc
+ .byte 1 # DW_AT_high_pc
+ .byte 'F', '0'+\I, 0 # DW_AT_name
+
+ .byte \I*10+6 # Abbrev DW_TAG_formal_parameter
+ .long 0 # DW_AT_location
+ .asciz "x" # DW_AT_name
+ .long .Ltype\I-.Lcu_begin\I # DW_AT_type
+
+ .byte 0 # End Of Children Mark
.byte 0 # End Of Children Mark
.Ldebug_info_end\I:
.endr
@@ -150,7 +235,7 @@ A\I:
.section .debug_cu_index,"e", at progbits
.short 2 # DWARF version number
.short 0 # Reserved
- .long 3 # Section count
+ .long 4 # Section count
.long 4 # Unit count
.long 8 # Slot count
@@ -159,16 +244,19 @@ A\I:
.long 1 # DW_SECT_INFO
.long 3 # DW_SECT_ABBREV
+ .long 5 # DW_SECT_LOC
.long 6 # DW_SECT_STR_OFFSETS
.irpc I,0123
.long .Lcu_begin\I-.debug_info.dwo
.long .Labbrev\I-.debug_abbrev.dwo
+ .long .Lloc\I-.debug_loc.dwo
.long .Lstr_offsets\I-.debug_str_offsets.dwo
.endr
.irpc I,0123
.long .Ldebug_info_end\I-.Lcu_begin\I
.long .Labbrev_end\I-.Labbrev\I
+ .long .Lloc_end\I-.Lloc\I
.long .Lstr_offsets_end\I-.Lstr_offsets\I
.endr
More information about the lldb-commits
mailing list