14
14
#include " llvm/DebugInfo/DWARF/DWARFRelocMap.h"
15
15
#include " llvm/Support/Compiler.h"
16
16
#include " llvm/Support/DJB.h"
17
+ #include " llvm/Support/Errc.h"
17
18
#include " llvm/Support/Format.h"
18
19
#include " llvm/Support/FormatVariadic.h"
19
20
#include " llvm/Support/ScopedPrinter.h"
@@ -45,9 +46,9 @@ llvm::Error AppleAcceleratorTable::extract() {
45
46
uint32_t Offset = 0 ;
46
47
47
48
// Check that we can at least read the header.
48
- if (!AccelSection.isValidOffset (offsetof (Header, HeaderDataLength)+ 4 ))
49
- return make_error<StringError>( " Section too small: cannot read header. " ,
50
- inconvertibleErrorCode () );
49
+ if (!AccelSection.isValidOffset (offsetof (Header, HeaderDataLength) + 4 ))
50
+ return createStringError (errc::illegal_byte_sequence ,
51
+ " Section too small: cannot read header. " );
51
52
52
53
Hdr.Magic = AccelSection.getU32 (&Offset);
53
54
Hdr.Version = AccelSection.getU16 (&Offset);
@@ -62,9 +63,9 @@ llvm::Error AppleAcceleratorTable::extract() {
62
63
// equal to the size for an empty table and hence pointer after the section.
63
64
if (!AccelSection.isValidOffset (sizeof (Hdr) + Hdr.HeaderDataLength +
64
65
Hdr.BucketCount * 4 + Hdr.HashCount * 8 - 1 ))
65
- return make_error<StringError> (
66
- " Section too small: cannot read buckets and hashes. " ,
67
- inconvertibleErrorCode () );
66
+ return createStringError (
67
+ errc::illegal_byte_sequence ,
68
+ " Section too small: cannot read buckets and hashes. " );
68
69
69
70
HdrData.DIEOffsetBase = AccelSection.getU32 (&Offset);
70
71
uint32_t NumAtoms = AccelSection.getU32 (&Offset);
@@ -380,8 +381,8 @@ llvm::Error DWARFDebugNames::Header::extract(const DWARFDataExtractor &AS,
380
381
uint32_t *Offset) {
381
382
// Check that we can read the fixed-size part.
382
383
if (!AS.isValidOffset (*Offset + sizeof (HeaderPOD) - 1 ))
383
- return make_error<StringError>( " Section too small: cannot read header. " ,
384
- inconvertibleErrorCode () );
384
+ return createStringError (errc::illegal_byte_sequence ,
385
+ " Section too small: cannot read header. " );
385
386
386
387
UnitLength = AS.getU32 (Offset);
387
388
Version = AS.getU16 (Offset);
@@ -395,9 +396,9 @@ llvm::Error DWARFDebugNames::Header::extract(const DWARFDataExtractor &AS,
395
396
AugmentationStringSize = alignTo (AS.getU32 (Offset), 4 );
396
397
397
398
if (!AS.isValidOffsetForDataOfSize (*Offset, AugmentationStringSize))
398
- return make_error<StringError> (
399
- " Section too small: cannot read header augmentation. " ,
400
- inconvertibleErrorCode () );
399
+ return createStringError (
400
+ errc::illegal_byte_sequence ,
401
+ " Section too small: cannot read header augmentation. " );
401
402
AugmentationString.resize (AugmentationStringSize);
402
403
AS.getU8 (Offset, reinterpret_cast <uint8_t *>(AugmentationString.data ()),
403
404
AugmentationStringSize);
@@ -439,8 +440,8 @@ DWARFDebugNames::Abbrev DWARFDebugNames::AbbrevMapInfo::getTombstoneKey() {
439
440
Expected<DWARFDebugNames::AttributeEncoding>
440
441
DWARFDebugNames::NameIndex::extractAttributeEncoding (uint32_t *Offset) {
441
442
if (*Offset >= EntriesBase) {
442
- return make_error<StringError>( " Incorrectly terminated abbreviation table. " ,
443
- inconvertibleErrorCode () );
443
+ return createStringError (errc::illegal_byte_sequence ,
444
+ " Incorrectly terminated abbreviation table. " );
444
445
}
445
446
446
447
uint32_t Index = Section.AccelSection .getULEB128 (Offset);
@@ -465,8 +466,8 @@ DWARFDebugNames::NameIndex::extractAttributeEncodings(uint32_t *Offset) {
465
466
Expected<DWARFDebugNames::Abbrev>
466
467
DWARFDebugNames::NameIndex::extractAbbrev (uint32_t *Offset) {
467
468
if (*Offset >= EntriesBase) {
468
- return make_error<StringError>( " Incorrectly terminated abbreviation table. " ,
469
- inconvertibleErrorCode () );
469
+ return createStringError (errc::illegal_byte_sequence ,
470
+ " Incorrectly terminated abbreviation table. " );
470
471
}
471
472
472
473
uint32_t Code = Section.AccelSection .getULEB128 (Offset);
@@ -501,9 +502,8 @@ Error DWARFDebugNames::NameIndex::extract() {
501
502
Offset += Hdr.NameCount * 4 ;
502
503
503
504
if (!AS.isValidOffsetForDataOfSize (Offset, Hdr.AbbrevTableSize ))
504
- return make_error<StringError>(
505
- " Section too small: cannot read abbreviations." ,
506
- inconvertibleErrorCode ());
505
+ return createStringError (errc::illegal_byte_sequence,
506
+ " Section too small: cannot read abbreviations." );
507
507
508
508
EntriesBase = Offset + Hdr.AbbrevTableSize ;
509
509
@@ -514,10 +514,9 @@ Error DWARFDebugNames::NameIndex::extract() {
514
514
if (isSentinel (*AbbrevOr))
515
515
return Error::success ();
516
516
517
- if (!Abbrevs.insert (std::move (*AbbrevOr)).second ) {
518
- return make_error<StringError>(" Duplicate abbreviation code." ,
519
- inconvertibleErrorCode ());
520
- }
517
+ if (!Abbrevs.insert (std::move (*AbbrevOr)).second )
518
+ return createStringError (errc::invalid_argument,
519
+ " Duplicate abbreviation code." );
521
520
}
522
521
}
523
522
DWARFDebugNames::Entry::Entry (const NameIndex &NameIdx, const Abbrev &Abbr)
@@ -600,25 +599,24 @@ Expected<DWARFDebugNames::Entry>
600
599
DWARFDebugNames::NameIndex::getEntry (uint32_t *Offset) const {
601
600
const DWARFDataExtractor &AS = Section.AccelSection ;
602
601
if (!AS.isValidOffset (*Offset))
603
- return make_error<StringError>( " Incorrectly terminated entry list. " ,
604
- inconvertibleErrorCode () );
602
+ return createStringError (errc::illegal_byte_sequence ,
603
+ " Incorrectly terminated entry list. " );
605
604
606
605
uint32_t AbbrevCode = AS.getULEB128 (Offset);
607
606
if (AbbrevCode == 0 )
608
607
return make_error<SentinelError>();
609
608
610
609
const auto AbbrevIt = Abbrevs.find_as (AbbrevCode);
611
610
if (AbbrevIt == Abbrevs.end ())
612
- return make_error<StringError>(" Invalid abbreviation." ,
613
- inconvertibleErrorCode ());
611
+ return createStringError (errc::invalid_argument, " Invalid abbreviation." );
614
612
615
613
Entry E (*this , *AbbrevIt);
616
614
617
615
dwarf::FormParams FormParams = {Hdr.Version , 0 , dwarf::DwarfFormat::DWARF32};
618
616
for (auto &Value : E.Values ) {
619
617
if (!Value.extractValue (AS, Offset, FormParams))
620
- return make_error<StringError>( " Error extracting index attribute values. " ,
621
- inconvertibleErrorCode () );
618
+ return createStringError (errc::io_error ,
619
+ " Error extracting index attribute values. " );
622
620
}
623
621
return std::move (E);
624
622
}
0 commit comments