@@ -510,7 +510,7 @@ DWARFDebugNames::Abbrev DWARFDebugNames::AbbrevMapInfo::getTombstoneKey() {
510
510
511
511
Expected<DWARFDebugNames::AttributeEncoding>
512
512
DWARFDebugNames::NameIndex::extractAttributeEncoding (uint64_t *Offset) {
513
- if (*Offset >= EntriesBase) {
513
+ if (*Offset >= Offsets. EntriesBase ) {
514
514
return createStringError (errc::illegal_byte_sequence,
515
515
" Incorrectly terminated abbreviation table." );
516
516
}
@@ -536,7 +536,7 @@ DWARFDebugNames::NameIndex::extractAttributeEncodings(uint64_t *Offset) {
536
536
537
537
Expected<DWARFDebugNames::Abbrev>
538
538
DWARFDebugNames::NameIndex::extractAbbrev (uint64_t *Offset) {
539
- if (*Offset >= EntriesBase) {
539
+ if (*Offset >= Offsets. EntriesBase ) {
540
540
return createStringError (errc::illegal_byte_sequence,
541
541
" Incorrectly terminated abbreviation table." );
542
542
}
@@ -552,32 +552,50 @@ DWARFDebugNames::NameIndex::extractAbbrev(uint64_t *Offset) {
552
552
return Abbrev (Code, dwarf::Tag (Tag), AbbrevOffset, std::move (*AttrEncOr));
553
553
}
554
554
555
+ void llvm::findDebugNamesOffsets (
556
+ DWARFDebugNames::DWARFDebugNamesOffsets &Offsets, uint64_t HdrSize,
557
+ dwarf::DwarfFormat Format, const DWARFDebugNames::Header &Hdr) {
558
+ uint32_t DwarfSize = (Format == llvm::dwarf::DwarfFormat::DWARF64) ? 8 : 4 ;
559
+ uint64_t Offset = HdrSize;
560
+ Offsets.CUsBase = Offset;
561
+ Offset += Hdr.CompUnitCount * DwarfSize;
562
+ Offset += Hdr.LocalTypeUnitCount * DwarfSize;
563
+ Offset += Hdr.ForeignTypeUnitCount * 8 ;
564
+
565
+ Offsets.BucketsBase = Offset;
566
+ Offset += Hdr.BucketCount * 4 ;
567
+
568
+ Offsets.HashesBase = Offset;
569
+ if (Hdr.BucketCount > 0 )
570
+ Offset += Hdr.NameCount * 4 ;
571
+
572
+ Offsets.StringOffsetsBase = Offset;
573
+ Offset += Hdr.NameCount * DwarfSize;
574
+
575
+ Offsets.EntryOffsetsBase = Offset;
576
+ Offset += Hdr.NameCount * DwarfSize;
577
+
578
+ Offset += Hdr.AbbrevTableSize ;
579
+ Offsets.EntriesBase = Offset;
580
+ }
581
+
555
582
Error DWARFDebugNames::NameIndex::extract () {
556
583
const DWARFDataExtractor &AS = Section.AccelSection ;
557
- uint64_t Offset = Base;
558
- if (Error E = Hdr.extract (AS, &Offset ))
584
+ uint64_t hdrSize = Base;
585
+ if (Error E = Hdr.extract (AS, &hdrSize ))
559
586
return E;
560
587
561
588
const unsigned SectionOffsetSize = dwarf::getDwarfOffsetByteSize (Hdr.Format );
562
- CUsBase = Offset;
563
- Offset += Hdr.CompUnitCount * SectionOffsetSize;
564
- Offset += Hdr.LocalTypeUnitCount * SectionOffsetSize;
565
- Offset += Hdr.ForeignTypeUnitCount * 8 ;
566
- BucketsBase = Offset;
567
- Offset += Hdr.BucketCount * 4 ;
568
- HashesBase = Offset;
569
- if (Hdr.BucketCount > 0 )
570
- Offset += Hdr.NameCount * 4 ;
571
- StringOffsetsBase = Offset;
572
- Offset += Hdr.NameCount * SectionOffsetSize;
573
- EntryOffsetsBase = Offset;
574
- Offset += Hdr.NameCount * SectionOffsetSize;
589
+ findDebugNamesOffsets (Offsets, hdrSize, Hdr.Format , Hdr);
590
+
591
+ uint64_t Offset =
592
+ Offsets.EntryOffsetsBase + (Hdr.NameCount * SectionOffsetSize);
575
593
576
594
if (!AS.isValidOffsetForDataOfSize (Offset, Hdr.AbbrevTableSize ))
577
595
return createStringError (errc::illegal_byte_sequence,
578
596
" Section too small: cannot read abbreviations." );
579
597
580
- EntriesBase = Offset + Hdr.AbbrevTableSize ;
598
+ Offsets. EntriesBase = Offset + Hdr.AbbrevTableSize ;
581
599
582
600
for (;;) {
583
601
auto AbbrevOr = extractAbbrev (&Offset);
@@ -679,7 +697,7 @@ void DWARFDebugNames::Entry::dumpParentIdx(
679
697
return ;
680
698
}
681
699
682
- auto AbsoluteOffset = NameIdx->EntriesBase + FormValue.getRawUValue ();
700
+ auto AbsoluteOffset = NameIdx->Offsets . EntriesBase + FormValue.getRawUValue ();
683
701
W.getOStream () << " Entry @ 0x" + Twine::utohexstr (AbsoluteOffset);
684
702
}
685
703
@@ -708,22 +726,23 @@ std::error_code DWARFDebugNames::SentinelError::convertToErrorCode() const {
708
726
uint64_t DWARFDebugNames::NameIndex::getCUOffset (uint32_t CU) const {
709
727
assert (CU < Hdr.CompUnitCount );
710
728
const unsigned SectionOffsetSize = dwarf::getDwarfOffsetByteSize (Hdr.Format );
711
- uint64_t Offset = CUsBase + SectionOffsetSize * CU;
729
+ uint64_t Offset = Offsets. CUsBase + SectionOffsetSize * CU;
712
730
return Section.AccelSection .getRelocatedValue (SectionOffsetSize, &Offset);
713
731
}
714
732
715
733
uint64_t DWARFDebugNames::NameIndex::getLocalTUOffset (uint32_t TU) const {
716
734
assert (TU < Hdr.LocalTypeUnitCount );
717
735
const unsigned SectionOffsetSize = dwarf::getDwarfOffsetByteSize (Hdr.Format );
718
- uint64_t Offset = CUsBase + SectionOffsetSize * (Hdr.CompUnitCount + TU);
736
+ uint64_t Offset =
737
+ Offsets.CUsBase + SectionOffsetSize * (Hdr.CompUnitCount + TU);
719
738
return Section.AccelSection .getRelocatedValue (SectionOffsetSize, &Offset);
720
739
}
721
740
722
741
uint64_t DWARFDebugNames::NameIndex::getForeignTUSignature (uint32_t TU) const {
723
742
assert (TU < Hdr.ForeignTypeUnitCount );
724
743
const unsigned SectionOffsetSize = dwarf::getDwarfOffsetByteSize (Hdr.Format );
725
744
uint64_t Offset =
726
- CUsBase +
745
+ Offsets. CUsBase +
727
746
SectionOffsetSize * (Hdr.CompUnitCount + Hdr.LocalTypeUnitCount ) + 8 * TU;
728
747
return Section.AccelSection .getU64 (&Offset);
729
748
}
@@ -759,28 +778,28 @@ DWARFDebugNames::NameIndex::getNameTableEntry(uint32_t Index) const {
759
778
assert (0 < Index && Index <= Hdr.NameCount );
760
779
const unsigned SectionOffsetSize = dwarf::getDwarfOffsetByteSize (Hdr.Format );
761
780
uint64_t StringOffsetOffset =
762
- StringOffsetsBase + SectionOffsetSize * (Index - 1 );
781
+ Offsets. StringOffsetsBase + SectionOffsetSize * (Index - 1 );
763
782
uint64_t EntryOffsetOffset =
764
- EntryOffsetsBase + SectionOffsetSize * (Index - 1 );
783
+ Offsets. EntryOffsetsBase + SectionOffsetSize * (Index - 1 );
765
784
const DWARFDataExtractor &AS = Section.AccelSection ;
766
785
767
786
uint64_t StringOffset =
768
787
AS.getRelocatedValue (SectionOffsetSize, &StringOffsetOffset);
769
788
uint64_t EntryOffset = AS.getUnsigned (&EntryOffsetOffset, SectionOffsetSize);
770
- EntryOffset += EntriesBase;
789
+ EntryOffset += Offsets. EntriesBase ;
771
790
return {Section.StringSection , Index, StringOffset, EntryOffset};
772
791
}
773
792
774
793
uint32_t
775
794
DWARFDebugNames::NameIndex::getBucketArrayEntry (uint32_t Bucket) const {
776
795
assert (Bucket < Hdr.BucketCount );
777
- uint64_t BucketOffset = BucketsBase + 4 * Bucket;
796
+ uint64_t BucketOffset = Offsets. BucketsBase + 4 * Bucket;
778
797
return Section.AccelSection .getU32 (&BucketOffset);
779
798
}
780
799
781
800
uint32_t DWARFDebugNames::NameIndex::getHashArrayEntry (uint32_t Index) const {
782
801
assert (0 < Index && Index <= Hdr.NameCount );
783
- uint64_t HashOffset = HashesBase + 4 * (Index - 1 );
802
+ uint64_t HashOffset = Offsets. HashesBase + 4 * (Index - 1 );
784
803
return Section.AccelSection .getU32 (&HashOffset);
785
804
}
786
805
0 commit comments