@@ -139,19 +139,19 @@ void DWARFDebugLoc::parse(const DWARFDataExtractor &data) {
139
139
}
140
140
}
141
141
142
- Expected<DWARFDebugLoclists::LocationList>
143
- DWARFDebugLoclists::parseOneLocationList (const DWARFDataExtractor &Data,
144
- uint64_t *Offset, unsigned Version) {
145
- LocationList LL;
146
- LL.Offset = *Offset;
147
- DataExtractor::Cursor C (*Offset);
142
+ Error DWARFDebugLoclists::visitLocationList (
143
+ const DWARFDataExtractor &Data, uint64_t *Offset, uint16_t Version,
144
+ llvm::function_ref<bool (const Entry &)> F) {
148
145
149
- // dwarf::DW_LLE_end_of_list_entry is 0 and indicates the end of the list.
150
- while (auto Kind = Data.getU8 (C)) {
146
+ DataExtractor::Cursor C (*Offset);
147
+ bool Continue = true ;
148
+ while (Continue) {
151
149
Entry E;
152
- E.Kind = Kind;
153
- E.Offset = C.tell () - 1 ;
154
- switch (Kind) {
150
+ E.Offset = C.tell ();
151
+ E.Kind = Data.getU8 (C);
152
+ switch (E.Kind ) {
153
+ case dwarf::DW_LLE_end_of_list:
154
+ break ;
155
155
case dwarf::DW_LLE_base_addressx:
156
156
E.Value0 = Data.getULEB128 (C);
157
157
break ;
@@ -164,64 +164,69 @@ DWARFDebugLoclists::parseOneLocationList(const DWARFDataExtractor &Data,
164
164
else
165
165
E.Value1 = Data.getULEB128 (C);
166
166
break ;
167
- case dwarf::DW_LLE_start_length:
168
- E.Value0 = Data.getRelocatedAddress (C);
169
- E.Value1 = Data.getULEB128 (C);
170
- break ;
171
167
case dwarf::DW_LLE_offset_pair:
172
168
E.Value0 = Data.getULEB128 (C);
173
169
E.Value1 = Data.getULEB128 (C);
174
170
break ;
175
171
case dwarf::DW_LLE_base_address:
176
172
E.Value0 = Data.getRelocatedAddress (C);
177
173
break ;
174
+ case dwarf::DW_LLE_start_length:
175
+ E.Value0 = Data.getRelocatedAddress (C);
176
+ E.Value1 = Data.getULEB128 (C);
177
+ break ;
178
+ case dwarf::DW_LLE_startx_endx:
179
+ case dwarf::DW_LLE_default_location:
180
+ case dwarf::DW_LLE_start_end:
178
181
default :
179
182
cantFail (C.takeError ());
180
183
return createStringError (errc::illegal_byte_sequence,
181
- " LLE of kind %x not supported" , (int )Kind);
184
+ " LLE of kind %x not supported" , (int )E. Kind );
182
185
}
183
186
184
- if (Kind != dwarf::DW_LLE_base_address &&
185
- Kind != dwarf::DW_LLE_base_addressx) {
187
+ if (E.Kind != dwarf::DW_LLE_base_address &&
188
+ E.Kind != dwarf::DW_LLE_base_addressx &&
189
+ E.Kind != dwarf::DW_LLE_end_of_list) {
186
190
unsigned Bytes = Version >= 5 ? Data.getULEB128 (C) : Data.getU16 (C);
187
191
// A single ___location description describing the ___location of the object...
188
192
Data.getU8 (C, E.Loc , Bytes);
189
193
}
190
194
191
- LL.Entries .push_back (std::move (E));
195
+ if (!C)
196
+ return C.takeError ();
197
+ Continue = F (E) && E.Kind != dwarf::DW_LLE_end_of_list;
192
198
}
193
- if (Error Err = C.takeError ())
194
- return std::move (Err);
195
- Entry E;
196
- E.Kind = dwarf::DW_LLE_end_of_list;
197
- E.Offset = C.tell () - 1 ;
198
- LL.Entries .push_back (E);
199
199
*Offset = C.tell ();
200
- return LL ;
200
+ return Error::success () ;
201
201
}
202
202
203
- void DWARFDebugLoclists::parse (const DWARFDataExtractor &data, uint64_t Offset ,
204
- uint64_t EndOffset , uint16_t Version) {
205
- IsLittleEndian = data. isLittleEndian ();
206
- AddressSize = data. getAddressSize ();
207
-
208
- while (Offset < EndOffset ) {
209
- if ( auto LL = parseOneLocationList (data, &Offset, Version))
210
- Locations. push_back ( std::move (*LL));
211
- else {
212
- logAllUnhandledErrors (LL. takeError (), WithColor::error ());
213
- return ;
214
- }
203
+ bool DWARFDebugLoclists::dumpLocationList (const DWARFDataExtractor &Data ,
204
+ uint64_t *Offset , uint16_t Version,
205
+ raw_ostream &OS, uint64_t BaseAddr,
206
+ const MCRegisterInfo *MRI,
207
+ DWARFUnit *U, DIDumpOptions DumpOpts,
208
+ unsigned Indent ) {
209
+ size_t MaxEncodingStringLength = 0 ;
210
+ if (DumpOpts. Verbose ) {
211
+ # define HANDLE_DW_LLE ( ID, NAME ) \
212
+ MaxEncodingStringLength = std::max (MaxEncodingStringLength, \
213
+ dwarf::LocListEncodingString (ID). size ()) ;
214
+ # include " llvm/BinaryFormat/Dwarf.def "
215
215
}
216
- }
217
216
218
- DWARFDebugLoclists::LocationList const *
219
- DWARFDebugLoclists::getLocationListAtOffset (uint64_t Offset) const {
220
- auto It = partition_point (
221
- Locations, [=](const LocationList &L) { return L.Offset < Offset; });
222
- if (It != Locations.end () && It->Offset == Offset)
223
- return &(*It);
224
- return nullptr ;
217
+ OS << format (" 0x%8.8" PRIx64 " : " , *Offset);
218
+ Error E = visitLocationList (Data, Offset, Version, [&](const Entry &E) {
219
+ E.dump (OS, BaseAddr, Data.isLittleEndian (), Data.getAddressSize (), MRI, U,
220
+ DumpOpts, Indent, MaxEncodingStringLength);
221
+ return true ;
222
+ });
223
+ if (E) {
224
+ OS << " \n " ;
225
+ OS.indent (Indent);
226
+ OS << " error: " << toString (std::move (E));
227
+ return false ;
228
+ }
229
+ return true ;
225
230
}
226
231
227
232
void DWARFDebugLoclists::Entry::dump (raw_ostream &OS, uint64_t &BaseAddr,
@@ -297,44 +302,25 @@ void DWARFDebugLoclists::Entry::dump(raw_ostream &OS, uint64_t &BaseAddr,
297
302
298
303
dumpExpression (OS, Loc, IsLittleEndian, AddressSize, MRI, U);
299
304
}
300
- void DWARFDebugLoclists::LocationList::dump (raw_ostream &OS, uint64_t BaseAddr,
301
- bool IsLittleEndian,
302
- unsigned AddressSize,
303
- const MCRegisterInfo *MRI,
304
- DWARFUnit *U,
305
- DIDumpOptions DumpOpts,
306
- unsigned Indent) const {
307
- size_t MaxEncodingStringLength = 0 ;
308
- if (DumpOpts.Verbose )
309
- for (const auto &Entry : Entries)
310
- MaxEncodingStringLength =
311
- std::max (MaxEncodingStringLength,
312
- dwarf::LocListEncodingString (Entry.Kind ).size ());
313
-
314
- for (const Entry &E : Entries)
315
- E.dump (OS, BaseAddr, IsLittleEndian, AddressSize, MRI, U, DumpOpts, Indent,
316
- MaxEncodingStringLength);
317
- }
318
-
319
- void DWARFDebugLoclists::dump (raw_ostream &OS, uint64_t BaseAddr,
320
- const MCRegisterInfo *MRI, DIDumpOptions DumpOpts,
321
- Optional<uint64_t > Offset) const {
322
- auto DumpLocationList = [&](const LocationList &L) {
323
- OS << format (" 0x%8.8" PRIx64 " : " , L.Offset );
324
- L.dump (OS, BaseAddr, IsLittleEndian, AddressSize, MRI, nullptr , DumpOpts,
325
- /* Indent=*/ 12 );
326
- OS << " \n " ;
327
- };
328
305
329
- if (Offset) {
330
- if (auto *L = getLocationListAtOffset (*Offset))
331
- DumpLocationList (*L);
306
+ void DWARFDebugLoclists::dumpRange (const DWARFDataExtractor &Data,
307
+ uint64_t StartOffset, uint64_t Size,
308
+ uint16_t Version, raw_ostream &OS,
309
+ uint64_t BaseAddr, const MCRegisterInfo *MRI,
310
+ DIDumpOptions DumpOpts) {
311
+ if (!Data.isValidOffsetForDataOfSize (StartOffset, Size)) {
312
+ OS << " Invalid dump range\n " ;
332
313
return ;
333
314
}
334
-
335
- for (const LocationList &L : Locations) {
336
- DumpLocationList (L);
337
- if (&L != &Locations.back ())
338
- OS << ' \n ' ;
315
+ uint64_t Offset = StartOffset;
316
+ StringRef Separator;
317
+ bool CanContinue = true ;
318
+ while (CanContinue && Offset < StartOffset + Size) {
319
+ OS << Separator;
320
+ Separator = " \n " ;
321
+
322
+ CanContinue = dumpLocationList (Data, &Offset, Version, OS, BaseAddr, MRI,
323
+ nullptr , DumpOpts, /* Indent=*/ 12 );
324
+ OS << ' \n ' ;
339
325
}
340
326
}
0 commit comments