@@ -233,16 +233,17 @@ bool mccasformats::v1::doesntDedup(dwarf::Form Form, dwarf::Attribute Attr) {
233
233
return llvm::is_contained (it->second , Attr);
234
234
}
235
235
236
- uint64_t
237
- mccasformats::v1::convertFourByteFormDataToULEB ( ArrayRef<char > FormData,
238
- DataWriter &Writer ) {
236
+ uint64_t mccasformats::v1::convertFourByteFormDataToULEB (
237
+ ArrayRef<char > FormData, DataWriter &Writer, bool IsLittleEndian ,
238
+ uint8_t AddressSize ) {
239
239
assert (FormData.size () == 4 );
240
- auto Reader =
241
- BinaryStreamReader (toStringRef (FormData), support::endianness::little);
240
+ StringRef FormDataStringRef = StringRef (FormData.begin (), FormData.size ());
241
+ DataExtractor Extractor (FormDataStringRef, IsLittleEndian, AddressSize);
242
+ DataExtractor::Cursor Cursor (0 );
242
243
243
- uint32_t IntegerData;
244
- if (auto Err = Reader. readInteger (IntegerData) )
245
- handleAllErrors (std::move (Err )); // this should never fail
244
+ uint32_t IntegerData = Extractor. getU32 (Cursor) ;
245
+ if (!Cursor )
246
+ handleAllErrors (Cursor. takeError ( )); // this should never fail
246
247
Writer.writeULEB128 (IntegerData);
247
248
return getULEB128Size (IntegerData);
248
249
}
@@ -271,39 +272,41 @@ void AbbrevEntryWriter::writeAbbrevEntry(DWARFDie DIE) {
271
272
}
272
273
273
274
Expected<dwarf::Tag> AbbrevEntryReader::readTag () {
274
- uint64_t TagAsInt;
275
- if (auto E = DataStream. readULEB128 (TagAsInt) )
276
- return std::move (E );
275
+ uint64_t TagAsInt = Extractor. getULEB128 (Cursor) ;
276
+ if (!Cursor )
277
+ return Cursor. takeError ( );
277
278
return static_cast <dwarf::Tag>(TagAsInt);
278
279
}
279
280
280
281
Expected<bool > AbbrevEntryReader::readHasChildren () {
281
- char HasChildren;
282
- if (auto E = DataStream. readInteger (HasChildren) )
283
- return std::move (E );
282
+ char HasChildren = Extractor. getU8 (Cursor) ;
283
+ if (!Cursor )
284
+ return Cursor. takeError ( );
284
285
return HasChildren;
285
286
}
286
287
287
288
Expected<dwarf::Attribute> AbbrevEntryReader::readAttr () {
288
- if (DataStream. bytesRemaining () == 0 )
289
+ if (Extractor. eof (Cursor) )
289
290
return static_cast <dwarf::Attribute>(getEndOfAttributesMarker ());
290
- uint64_t AttrAsInt;
291
- if (auto E = DataStream. readULEB128 (AttrAsInt) )
292
- return std::move (E );
291
+ uint64_t AttrAsInt = Extractor. getULEB128 (Cursor) ;
292
+ if (!Cursor )
293
+ return Cursor. takeError ( );
293
294
return static_cast <dwarf::Attribute>(AttrAsInt);
294
295
}
295
296
296
- static Expected<int64_t > handleImplicitConst (BinaryStreamReader &Reader) {
297
- int64_t ImplicitVal;
298
- if (auto E = Reader.readSLEB128 (ImplicitVal))
299
- return std::move (E);
297
+ static Expected<int64_t > handleImplicitConst (DataExtractor &Extractor,
298
+ DataExtractor::Cursor &Cursor) {
299
+ int64_t ImplicitVal = Extractor.getSLEB128 (Cursor);
300
+
301
+ if (!Cursor)
302
+ return Cursor.takeError ();
300
303
return ImplicitVal;
301
304
}
302
305
303
306
Expected<dwarf::Form> AbbrevEntryReader::readForm () {
304
- uint64_t FormAsInt;
305
- if (auto E = DataStream. readULEB128 (FormAsInt) )
306
- return std::move (E );
307
+ uint64_t FormAsInt = Extractor. getULEB128 (Cursor) ;
308
+ if (!Cursor )
309
+ return Cursor. takeError ( );
307
310
auto Form = static_cast <dwarf::Form>(FormAsInt);
308
311
309
312
// Dwarf 5: Section 7.4:
@@ -314,45 +317,45 @@ Expected<dwarf::Form> AbbrevEntryReader::readForm() {
314
317
315
318
// Advance reader to beyond the implicit_const value, to read Forms correctly.
316
319
if (Form == dwarf::Form::DW_FORM_implicit_const) {
317
- auto ImplicitVal = handleImplicitConst (DataStream );
320
+ auto ImplicitVal = handleImplicitConst (Extractor, Cursor );
318
321
if (!ImplicitVal)
319
322
return ImplicitVal.takeError ();
320
323
}
321
324
return Form;
322
325
}
323
326
324
- uint64_t
325
- mccasformats::v1::reconstructAbbrevSection (raw_ostream &OS,
326
- ArrayRef<StringRef> AbbrevEntries,
327
- uint64_t &MaxDIEAbbrevCount) {
327
+ uint64_t mccasformats::v1::reconstructAbbrevSection (
328
+ raw_ostream &OS, ArrayRef<StringRef> AbbrevEntries,
329
+ uint64_t &MaxDIEAbbrevCount, bool IsLittleEndian, uint8_t AddressSize) {
328
330
uint64_t WrittenSize = 0 ;
329
331
for (auto EntryData : AbbrevEntries) {
330
332
// Dwarf 5: Section 7.5.3:
331
333
// Each declaration begins with an unsigned LEB128 number representing the
332
334
// abbreviation code itself. [...] The abbreviation code 0 is reserved for
333
335
// null debugging information entries.
334
336
WrittenSize += encodeULEB128 (MaxDIEAbbrevCount, OS);
335
- BinaryStreamReader Reader (EntryData, support::endianness::little);
337
+ DataExtractor Extractor (EntryData, IsLittleEndian, AddressSize);
338
+ DataExtractor::Cursor Cursor (0 );
336
339
// [uleb(Tag), has_children]
337
- uint64_t TagAsInt;
338
- uint8_t HasChildren;
339
- if ( auto Err = Reader. readULEB128 (TagAsInt))
340
- handleAllErrors ( std::move (Err) );
341
- if (auto Err = Reader. readInteger (HasChildren) )
342
- handleAllErrors (std::move (Err ));
340
+ uint64_t TagAsInt = Extractor. getULEB128 (Cursor) ;
341
+ if (!Cursor)
342
+ handleAllErrors (Cursor. takeError ());
343
+ uint8_t HasChildren = Extractor. getU8 (Cursor );
344
+ if (!Cursor )
345
+ handleAllErrors (Cursor. takeError ( ));
343
346
WrittenSize += encodeULEB128 (TagAsInt, OS);
344
347
OS << HasChildren;
345
348
WrittenSize += 1 ;
346
349
assert (HasChildren == 0 || HasChildren == 1 );
347
350
348
351
// [uleb(Attr), uleb(Form)]*
349
- while (!Reader. empty ( )) {
350
- uint64_t AttrAsInt;
351
- uint64_t FormAsInt;
352
- if ( auto Err = Reader. readULEB128 (AttrAsInt))
353
- handleAllErrors ( std::move (Err) );
354
- if (auto Err = Reader. readULEB128 (FormAsInt) )
355
- handleAllErrors (std::move (Err ));
352
+ while (!Extractor. eof (Cursor )) {
353
+ uint64_t AttrAsInt = Extractor. getULEB128 (Cursor) ;
354
+ if (!Cursor)
355
+ handleAllErrors (Cursor. takeError ());
356
+ uint64_t FormAsInt = Extractor. getULEB128 (Cursor );
357
+ if (!Cursor )
358
+ handleAllErrors (Cursor. takeError ( ));
356
359
357
360
WrittenSize += encodeULEB128 (AttrAsInt, OS);
358
361
@@ -370,7 +373,7 @@ mccasformats::v1::reconstructAbbrevSection(raw_ostream &OS,
370
373
// This number is used as the value of the attribute with the
371
374
// aformentioned form and nothing is stored in the .debug_info section.
372
375
if (Form == dwarf::Form::DW_FORM_implicit_const) {
373
- auto ImplicitVal = handleImplicitConst (Reader );
376
+ auto ImplicitVal = handleImplicitConst (Extractor, Cursor );
374
377
if (!ImplicitVal)
375
378
handleAllErrors (ImplicitVal.takeError ());
376
379
WrittenSize += encodeSLEB128 (*ImplicitVal, OS);
0 commit comments