Skip to content

Commit 411497c

Browse files
committed
llvm-dwarfdump: Support multiple debug_loclists contributions
Also fixing the incorrect "offset" field being computed/printed for each location list. llvm-svn: 374232
1 parent 745e57c commit 411497c

File tree

7 files changed

+66
-19
lines changed

7 files changed

+66
-19
lines changed

llvm/include/llvm/DebugInfo/DWARF/DWARFDebugLoc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class DWARFDebugLoclists {
9999
bool IsLittleEndian;
100100

101101
public:
102-
void parse(DataExtractor data, unsigned Version);
102+
void parse(DataExtractor data, uint64_t Offset, uint64_t EndOffset, uint16_t Version);
103103
void dump(raw_ostream &OS, uint64_t BaseAddr, const MCRegisterInfo *RegInfo,
104104
Optional<uint64_t> Offset) const;
105105

llvm/lib/DebugInfo/DWARF/DWARFContext.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -290,20 +290,24 @@ static void dumpLoclistsSection(raw_ostream &OS, DIDumpOptions DumpOpts,
290290
const MCRegisterInfo *MRI,
291291
Optional<uint64_t> DumpOffset) {
292292
uint64_t Offset = 0;
293-
DWARFDebugLoclists Loclists;
294293

295-
DWARFListTableHeader Header(".debug_loclists", "locations");
296-
if (Error E = Header.extract(Data, &Offset)) {
297-
WithColor::error() << toString(std::move(E)) << '\n';
298-
return;
299-
}
294+
while (Data.isValidOffset(Offset)) {
295+
DWARFListTableHeader Header(".debug_loclists", "locations");
296+
if (Error E = Header.extract(Data, &Offset)) {
297+
WithColor::error() << toString(std::move(E)) << '\n';
298+
return;
299+
}
300300

301-
Header.dump(OS, DumpOpts);
302-
DataExtractor LocData(Data.getData().drop_front(Offset),
303-
Data.isLittleEndian(), Header.getAddrSize());
301+
Header.dump(OS, DumpOpts);
302+
DataExtractor LocData(Data.getData(),
303+
Data.isLittleEndian(), Header.getAddrSize());
304304

305-
Loclists.parse(LocData, Header.getVersion());
306-
Loclists.dump(OS, 0, MRI, DumpOffset);
305+
DWARFDebugLoclists Loclists;
306+
uint64_t EndOffset = Header.length() + Header.getHeaderOffset();
307+
Loclists.parse(LocData, Offset, EndOffset, Header.getVersion());
308+
Loclists.dump(OS, 0, MRI, DumpOffset);
309+
Offset = EndOffset;
310+
}
307311
}
308312

309313
void DWARFContext::dump(
@@ -733,7 +737,7 @@ const DWARFDebugLoclists *DWARFContext::getDebugLocDWO() {
733737
// Use version 4. DWO does not support the DWARF v5 .debug_loclists yet and
734738
// that means we are parsing the new style .debug_loc (pre-standatized version
735739
// of the .debug_loclists).
736-
LocDWO->parse(LocData, 4 /* Version */);
740+
LocDWO->parse(LocData, 0, LocData.getData().size(), 4 /* Version */);
737741
return LocDWO.get();
738742
}
739743

llvm/lib/DebugInfo/DWARF/DWARFDebugLoc.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,11 @@ DWARFDebugLoclists::parseOneLocationList(const DataExtractor &Data,
187187
return LL;
188188
}
189189

190-
void DWARFDebugLoclists::parse(DataExtractor data, unsigned Version) {
190+
void DWARFDebugLoclists::parse(DataExtractor data, uint64_t Offset, uint64_t EndOffset, uint16_t Version) {
191191
IsLittleEndian = data.isLittleEndian();
192192
AddressSize = data.getAddressSize();
193193

194-
uint64_t Offset = 0;
195-
while (Offset < data.getData().size()) {
194+
while (Offset < EndOffset) {
196195
if (auto LL = parseOneLocationList(data, &Offset, Version))
197196
Locations.push_back(std::move(*LL));
198197
else {

llvm/test/CodeGen/X86/debug-loclists.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
; CHECK: .debug_loclists contents:
1414
; CHECK-NEXT: 0x00000000: locations list header: length = 0x00000015, version = 0x0005, addr_size = 0x08, seg_size = 0x00, offset_entry_count = 0x00000000
15-
; CHECK-NEXT: 0x00000000:
15+
; CHECK-NEXT: 0x0000000c:
1616
; CHECK-NEXT: [0x0000000000000000, 0x0000000000000004): DW_OP_breg5 RDI+0
1717
; CHECK-NEXT: [0x0000000000000004, 0x0000000000000012): DW_OP_breg3 RBX+0
1818

llvm/test/DebugInfo/X86/dwarfdump-debug-loclists.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
# CHECK: .debug_loclists contents:
1212
# CHECK-NEXT: 0x00000000: locations list header: length = 0x0000002c, version = 0x0005, addr_size = 0x08, seg_size = 0x00, offset_entry_count = 0x00000000
13-
# CHECK-NEXT: 0x00000000:
13+
# CHECK-NEXT: 0x0000000c:
1414
# CHECK-NEXT: [0x0000000000000000, 0x0000000000000010): DW_OP_breg5 RDI+0
1515
# CHECK-NEXT: [0x0000000000000530, 0x0000000000000540): DW_OP_breg6 RBP-8, DW_OP_deref
1616
# CHECK-NEXT: [0x0000000000000700, 0x0000000000000710): DW_OP_breg5 RDI+0
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# RUN: llvm-mc %s -filetype obj -triple x86_64-pc-linux -o %t.o
2+
# RUN: llvm-dwarfdump -v %t.o | FileCheck %s
3+
4+
# Test dumping of multiple separate debug_loclist contributions
5+
# CHECK: .debug_loclists contents:
6+
# CHECK: 0x00000000: locations list header:
7+
# CHECK: 0x0000000c:
8+
# CHECK: [0x0000000000000001, 0x0000000000000002): DW_OP_consts +7, DW_OP_stack_value
9+
# CHECK: 0x00000014: locations list header:
10+
# CHECK: [0x0000000000000005, 0x0000000000000007): DW_OP_consts +12, DW_OP_stack_value
11+
12+
.section .debug_loclists,"",@progbits
13+
.long .Ldebug_loclist_table_end0-.Ldebug_loclist_table_start0 # Length
14+
.Ldebug_loclist_table_start0:
15+
.short 5 # Version
16+
.byte 8 # Address size
17+
.byte 0 # Segment selector size
18+
.long 0 # Offset entry count
19+
20+
.byte 4 # DW_LLE_offset_pair
21+
.uleb128 1 # starting offset
22+
.uleb128 2 # ending offset
23+
.byte 3 # Loc expr size
24+
.byte 17 # DW_OP_consts
25+
.byte 7 # 7
26+
.byte 159 # DW_OP_stack_value
27+
.byte 0 # DW_LLE_end_of_list
28+
.Ldebug_loclist_table_end0:
29+
.long .Ldebug_loclist_table_end1-.Ldebug_loclist_table_start1 # Length
30+
.Ldebug_loclist_table_start1:
31+
.short 5 # Version
32+
.byte 8 # Address size
33+
.byte 0 # Segment selector size
34+
.long 0 # Offset entry count
35+
36+
.byte 4 # DW_LLE_offset_pair
37+
.uleb128 5 # starting offset
38+
.uleb128 7 # ending offset
39+
.byte 3 # Loc expr size
40+
.byte 17 # DW_OP_consts
41+
.byte 12 # 12
42+
.byte 159 # DW_OP_stack_value
43+
.byte 0 # DW_LLE_end_of_list
44+
.Ldebug_loclist_table_end1:

llvm/test/tools/llvm-dwarfdump/X86/debug_loclists_startx_length.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
# CHECK: .debug_loclists contents:
99
# CHECK-NEXT: 0x00000000: locations list header: length = 0x0000000e, version = 0x0005, addr_size = 0x08, seg_size = 0x00, offset_entry_count = 0x00000000
10-
# CHECK-NEXT: 0x00000000:
10+
# CHECK-NEXT: 0x0000000c:
1111
# CHECK-NEXT: Addr idx 1 (w/ length 16): DW_OP_reg5 RDI
1212

1313
.section .debug_loclists,"",@progbits

0 commit comments

Comments
 (0)