Skip to content

Commit ec671f3

Browse files
committed
[lldb] Support .debug_rnglists.dwo sections in dwp file
This patch considers the CU index entry when reading the .debug_rnglists.dwo section. Reviewed By: jankratochvil Differential Revision: https://reviews.llvm.org/D107456
1 parent 98d0f8f commit ec671f3

File tree

3 files changed

+210
-5
lines changed

3 files changed

+210
-5
lines changed

lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,24 @@ DWARFDataExtractor DWARFUnit::GetLocationData() const {
513513
return data;
514514
}
515515

516+
DWARFDataExtractor DWARFUnit::GetRnglistData() const {
517+
DWARFContext &Ctx = GetSymbolFileDWARF().GetDWARFContext();
518+
const DWARFDataExtractor &data = Ctx.getOrLoadRngListsData();
519+
if (const llvm::DWARFUnitIndex::Entry *entry = m_header.GetIndexEntry()) {
520+
if (const auto *contribution =
521+
entry->getContribution(llvm::DW_SECT_RNGLISTS))
522+
return DWARFDataExtractor(data, contribution->Offset,
523+
contribution->Length);
524+
GetSymbolFileDWARF().GetObjectFile()->GetModule()->ReportError(
525+
"Failed to find range list contribution for CU with signature "
526+
"0x%" PRIx64,
527+
entry->getSignature());
528+
529+
return DWARFDataExtractor();
530+
}
531+
return data;
532+
}
533+
516534
void DWARFUnit::SetRangesBase(dw_addr_t ranges_base) {
517535
lldbassert(!m_rnglist_table_done);
518536

@@ -525,8 +543,7 @@ DWARFUnit::GetRnglistTable() {
525543
m_rnglist_table_done = true;
526544
if (auto table_or_error =
527545
ParseListTableHeader<llvm::DWARFDebugRnglistTable>(
528-
m_dwarf.GetDWARFContext().getOrLoadRngListsData().GetAsLLVM(),
529-
m_ranges_base, DWARF32))
546+
GetRnglistData().GetAsLLVM(), m_ranges_base, DWARF32))
530547
m_rnglist_table = std::move(table_or_error.get());
531548
else
532549
GetSymbolFileDWARF().GetObjectFile()->GetModule()->ReportError(
@@ -547,7 +564,7 @@ llvm::Expected<uint64_t> DWARFUnit::GetRnglistOffset(uint32_t Index) {
547564
"DW_AT_rnglists_base for CU at 0x%8.8x",
548565
GetOffset());
549566
if (llvm::Optional<uint64_t> off = GetRnglistTable()->getOffsetEntry(
550-
m_dwarf.GetDWARFContext().getOrLoadRngListsData().GetAsLLVM(), Index))
567+
GetRnglistData().GetAsLLVM(), Index))
551568
return *off + m_ranges_base;
552569
return llvm::createStringError(
553570
errc::invalid_argument,
@@ -1001,8 +1018,7 @@ DWARFUnit::FindRnglistFromOffset(dw_offset_t offset) {
10011018
return llvm::createStringError(errc::invalid_argument,
10021019
"missing or invalid range list table");
10031020

1004-
llvm::DWARFDataExtractor data =
1005-
m_dwarf.GetDWARFContext().getOrLoadRngListsData().GetAsLLVM();
1021+
llvm::DWARFDataExtractor data = GetRnglistData().GetAsLLVM();
10061022

10071023
// As DW_AT_rnglists_base may be missing we need to call setAddressSize.
10081024
data.setAddressSize(m_header.GetAddressByteSize());

lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ class DWARFUnit : public lldb_private::UserID {
286286

287287
const llvm::Optional<llvm::DWARFDebugRnglistTable> &GetRnglistTable();
288288

289+
lldb_private::DWARFDataExtractor GetRnglistData() const;
290+
289291
SymbolFileDWARF &m_dwarf;
290292
std::shared_ptr<DWARFUnit> m_dwo;
291293
DWARFUnitHeader m_header;
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
## This tests if .debug_rnglists.dwo are correctly read if they are part
2+
## of a dwp file.
3+
4+
# RUN: llvm-mc -triple=x86_64-pc-linux -filetype=obj %s --defsym MAIN=0 > %t
5+
# RUN: llvm-mc -triple=x86_64-pc-linux -filetype=obj %s > %t.dwp
6+
# RUN: %lldb %t -o "image lookup -v -s lookup_rnglists" -o exit | FileCheck %s
7+
8+
# CHECK-LABEL: image lookup -v -s lookup_rnglists
9+
# CHECK: Function: id = {{.*}}, name = "rnglists", range = [0x0000000000000000-0x0000000000000003)
10+
# CHECK: Blocks: id = {{.*}}, range = [0x00000000-0x00000003)
11+
# CHECK-NEXT: id = {{.*}}, range = [0x00000001-0x00000002)
12+
13+
.text
14+
rnglists:
15+
nop
16+
.Lblock1_begin:
17+
lookup_rnglists:
18+
nop
19+
.Lblock1_end:
20+
nop
21+
.Lrnglists_end:
22+
23+
## The main file.
24+
.ifdef MAIN
25+
.section .debug_abbrev,"",@progbits
26+
.byte 1 # Abbreviation Code
27+
.byte 17 # DW_TAG_compile_unit
28+
.byte 0 # DW_CHILDREN_no
29+
.byte 0x76 # DW_AT_dwo_name
30+
.byte 8 # DW_FORM_string
31+
.byte 115 # DW_AT_addr_base
32+
.byte 23 # DW_FORM_sec_offset
33+
.byte 85 # DW_AT_ranges
34+
.byte 35 # DW_FORM_rnglistx
35+
.byte 116 # DW_AT_rnglists_base
36+
.byte 23 # DW_FORM_sec_offset
37+
.byte 0 # EOM(1)
38+
.byte 0 # EOM(2)
39+
.byte 0 # EOM(3)
40+
41+
.section .debug_info,"",@progbits
42+
.Lcu_begin0:
43+
.long .Ldebug_info_end0-.Ldebug_info_start0 # Length of Unit
44+
.Ldebug_info_start0:
45+
.short 5 # DWARF version number
46+
.byte 4 # DWARF Unit Type
47+
.byte 8 # Address Size (in bytes)
48+
.long .debug_abbrev # Offset Into Abbrev. Section
49+
.quad 1026699901672188186 # DWO id
50+
.byte 1 # Abbrev [1] DW_TAG_compile_unit
51+
.asciz "debug_rnglists-dwp.s.tmp.dwo" # DW_AT_dwo_name
52+
.long .Laddr_table_base0 # DW_AT_addr_base
53+
.byte 0 # DW_AT_ranges
54+
.long .Lskel_rnglists_table_base # DW_AT_rnglists_base
55+
.Ldebug_info_end0:
56+
57+
.section .debug_addr,"",@progbits
58+
.long .Ldebug_addr_end0-.Ldebug_addr_start0 # Length of contribution
59+
.Ldebug_addr_start0:
60+
.short 5 # DWARF version number
61+
.byte 8 # Address size
62+
.byte 0 # Segment selector size
63+
.Laddr_table_base0:
64+
.quad rnglists
65+
.quad .Lblock1_begin
66+
.Ldebug_addr_end0:
67+
68+
.section .debug_rnglists,"",@progbits
69+
.long .Lskel_rnglist_table_end-.Lskel_rnglist_table_start # Length
70+
.Lskel_rnglist_table_start:
71+
.short 5 # Version
72+
.byte 8 # Address size
73+
.byte 0 # Segment selector size
74+
.long 1 # Offset entry count
75+
.Lskel_rnglists_table_base:
76+
.long .Lskel_ranges0-.Lskel_rnglists_table_base
77+
.Lskel_ranges0:
78+
.byte 7 # DW_RLE_start_length
79+
.quad rnglists
80+
.uleb128 .Lrnglists_end-rnglists
81+
.byte 0 # DW_RLE_end_of_list
82+
.Lskel_rnglist_table_end:
83+
.else
84+
## DWP file starts here.
85+
.section .debug_abbrev.dwo,"e",@progbits
86+
.LAbbrevBegin:
87+
.byte 1 # Abbreviation Code
88+
.byte 17 # DW_TAG_compile_unit
89+
.byte 1 # DW_CHILDREN_yes
90+
.byte 37 # DW_AT_producer
91+
.byte 8 # DW_FORM_string
92+
.byte 0 # EOM(1)
93+
.byte 0 # EOM(2)
94+
.byte 2 # Abbreviation Code
95+
.byte 46 # DW_TAG_subprogram
96+
.byte 1 # DW_CHILDREN_yes
97+
.byte 17 # DW_AT_low_pc
98+
.byte 27 # DW_FORM_addrx
99+
.byte 18 # DW_AT_high_pc
100+
.byte 6 # DW_FORM_data4
101+
.byte 3 # DW_AT_name
102+
.byte 8 # DW_FORM_string
103+
.byte 0 # EOM(1)
104+
.byte 0 # EOM(2)
105+
.byte 5 # Abbreviation Code
106+
.byte 11 # DW_TAG_lexical_block
107+
.byte 0 # DW_CHILDREN_no
108+
.byte 85 # DW_AT_ranges
109+
.byte 35 # DW_FORM_rnglistx
110+
.byte 0 # EOM(1)
111+
.byte 0 # EOM(2)
112+
.byte 0 # EOM(3)
113+
.LAbbrevEnd:
114+
.section .debug_info.dwo,"e",@progbits
115+
.LCUBegin:
116+
.long .Ldebug_info_end1-.Ldebug_info_start1 # Length of Unit
117+
.Ldebug_info_start1:
118+
.short 5 # DWARF version number
119+
.byte 5 # DWARF Unit Type
120+
.byte 8 # Address Size (in bytes)
121+
.long 0 # Offset Into Abbrev. Section
122+
.quad 1026699901672188186 # DWO id
123+
.byte 1 # Abbrev [1] DW_TAG_compile_unit
124+
.asciz "Hand-written DWARF" # DW_AT_producer
125+
.byte 2 # Abbrev [2] DW_TAG_subprogram
126+
.byte 0 # DW_AT_low_pc
127+
.long .Lrnglists_end-rnglists # DW_AT_high_pc
128+
.asciz "rnglists" # DW_AT_name
129+
.byte 5 # Abbrev [5] DW_TAG_lexical_block
130+
.byte 0 # DW_AT_ranges
131+
.byte 0 # End Of Children Mark
132+
.byte 0 # End Of Children Mark
133+
.Ldebug_info_end1:
134+
.LCUEnd:
135+
.section .debug_rnglists.dwo,"e",@progbits
136+
## Fake rnglists to check if the cu index is taken into account
137+
.long .Lfake_rnglist_end-.Lfake_rnglist_start # Length
138+
.Lfake_rnglist_start:
139+
.short 5 # Version
140+
.byte 8 # Address size
141+
.byte 0 # Segment selector size
142+
.long 0 # Offset entry count
143+
.byte 0 # DW_RLE_end_of_list
144+
.Lfake_rnglist_end:
145+
.LRLBegin:
146+
.long .Ldwo_rnglist_table_end-.Ldwo_rnglist_table_start # Length
147+
.Ldwo_rnglist_table_start:
148+
.short 5 # Version
149+
.byte 8 # Address size
150+
.byte 0 # Segment selector size
151+
.long 1 # Offset entry count
152+
.Ldwo_rnglists_table_base:
153+
.long .Ldwo_ranges-.Ldwo_rnglists_table_base
154+
.Ldwo_ranges:
155+
.byte 3 # DW_RLE_startx_length
156+
.uleb128 1
157+
.uleb128 .Lblock1_end-.Lblock1_begin
158+
.byte 0 # DW_RLE_end_of_list
159+
.Ldwo_rnglist_table_end:
160+
.LRLEnd:
161+
.section .debug_cu_index, "", @progbits
162+
## Header:
163+
.short 5 # Version
164+
.short 0 # Padding
165+
.long 3 # Section count
166+
.long 1 # Unit count
167+
.long 2 # Slot count
168+
## Hash Table of Signatures:
169+
.quad 1026699901672188186
170+
.quad 0
171+
## Parallel Table of Indexes:
172+
.long 1
173+
.long 0
174+
## Table of Section Offsets:
175+
## Row 0:
176+
.long 1 # DW_SECT_INFO
177+
.long 3 # DW_SECT_ABBREV
178+
.long 8 # DW_SECT_RNGLISTS
179+
## Row 1:
180+
.long 0 # Offset in .debug_info.dwo
181+
.long 0 # Offset in .debug_abbrev.dwo
182+
.long .LRLBegin-.debug_rnglists.dwo # Offset in .debug_rnglists.dwo
183+
## Table of Section Sizes:
184+
.long .LCUEnd-.LCUBegin # Size in .debug_info.dwo
185+
.long .LAbbrevEnd-.LAbbrevBegin # Size in .debug_abbrev.dwo
186+
.long .LRLEnd-.LRLBegin # Size in .debug_rnglists.dwo
187+
.endif

0 commit comments

Comments
 (0)