@@ -34,6 +34,30 @@ namespace llvm {
34
34
35
35
namespace bolt {
36
36
37
+ struct AttrInfo {
38
+ DWARFFormValue V;
39
+ const DWARFAbbreviationDeclaration *AbbrevDecl;
40
+ uint64_t Offset;
41
+ uint32_t Size ; // Size of the attribute.
42
+ };
43
+
44
+ // / Finds attributes FormValue and Offset.
45
+ // /
46
+ // / \param DIE die to look up in.
47
+ // / \param AbbrevDecl abbrev declaration for the die.
48
+ // / \param Index an index in Abbrev declaration entry.
49
+ Optional<AttrInfo>
50
+ findAttributeInfo (const DWARFDie DIE,
51
+ const DWARFAbbreviationDeclaration *AbbrevDecl,
52
+ uint32_t Index);
53
+
54
+ // / Finds attributes FormValue and Offset.
55
+ // /
56
+ // / \param DIE die to look up in.
57
+ // / \param Attr the attribute to extract.
58
+ // / \return an optional AttrInfo with DWARFFormValue and Offset.
59
+ Optional<AttrInfo> findAttributeInfo (const DWARFDie DIE, dwarf::Attribute Attr);
60
+
37
61
// DWARF5 Header in order of encoding.
38
62
// Types represent encodnig sizes.
39
63
using UnitLengthType = uint32_t ;
@@ -447,23 +471,31 @@ class DebugStrWriter {
447
471
BinaryContext &BC;
448
472
};
449
473
474
+ class DebugInfoBinaryPatcher ;
475
+ class DebugAbbrevWriter ;
450
476
enum class LocWriterKind { DebugLocWriter, DebugLoclistWriter };
451
477
452
478
// / Serializes part of a .debug_loc DWARF section with LocationLists.
453
479
class SimpleBinaryPatcher ;
454
480
class DebugLocWriter {
481
+ protected:
482
+ DebugLocWriter (uint8_t DwarfVersion, LocWriterKind Kind)
483
+ : DwarfVersion(DwarfVersion), Kind(Kind) {
484
+ init ();
485
+ }
486
+
455
487
public:
456
- DebugLocWriter () = delete ;
457
- DebugLocWriter (BinaryContext *BC);
488
+ DebugLocWriter () { init (); };
458
489
virtual ~DebugLocWriter (){};
459
490
460
491
// / Writes out location lists and stores internal patches.
461
- virtual void addList (uint64_t AttrOffset, uint32_t LocListIndex,
462
- DebugLocationsVector &&LocList);
492
+ virtual void addList (AttrInfo &AttrVal, DebugLocationsVector &LocList,
493
+ DebugInfoBinaryPatcher &DebugInfoPatcher,
494
+ DebugAbbrevWriter &AbbrevWriter);
463
495
464
496
// / Writes out locations in to a local buffer, and adds Debug Info patches.
465
- virtual void finalize (uint64_t SectionOffset ,
466
- SimpleBinaryPatcher &DebugInfoPatcher );
497
+ virtual void finalize (DebugInfoBinaryPatcher &DebugInfoPatcher ,
498
+ DebugAbbrevWriter &AbbrevWriter );
467
499
468
500
// / Return internal buffer.
469
501
virtual std::unique_ptr<DebugBufferVector> getBuffer ();
@@ -485,13 +517,15 @@ class DebugLocWriter {
485
517
std::unique_ptr<raw_svector_ostream> LocStream;
486
518
// / Current offset in the section (updated as new entries are written).
487
519
// / Starts with 0 here since this only writes part of a full location lists
488
- // / section. In the final section, the first 16 bytes are reserved for an
489
- // / empty list.
490
- uint32_t SectionOffset{ 0 } ;
520
+ // / section. In the final section, for DWARF4, the first 16 bytes are reserved
521
+ // / for an empty list.
522
+ static uint32_t LocSectionOffset ;
491
523
uint8_t DwarfVersion{4 };
492
524
LocWriterKind Kind{LocWriterKind::DebugLocWriter};
493
525
494
526
private:
527
+ // / Inits all the related data structures.
528
+ void init ();
495
529
struct LocListDebugInfoPatchType {
496
530
uint64_t DebugInfoAttrOffset;
497
531
uint64_t LocListOffset;
@@ -501,36 +535,39 @@ class DebugLocWriter {
501
535
// / The list of debug info patches to be made once individual
502
536
// / location list writers have been filled
503
537
VectorLocListDebugInfoPatchType LocListDebugInfoPatches;
504
-
505
- using VectorEmptyLocListAttributes = std::vector<uint64_t >;
506
- // / Contains all the attributes pointing to empty location list.
507
- VectorEmptyLocListAttributes EmptyAttrLists;
508
538
};
509
539
510
540
class DebugLoclistWriter : public DebugLocWriter {
511
541
public:
512
542
~DebugLoclistWriter () {}
513
543
DebugLoclistWriter () = delete ;
514
- DebugLoclistWriter (BinaryContext *BC, DWARFUnit &Unit,
515
- uint32_t LocListsBaseAttrOffset, uint8_t DV, bool SD)
516
- : DebugLocWriter(BC), CU(Unit),
517
- LocListsBaseAttrOffset (LocListsBaseAttrOffset), IsSplitDwarf(SD) {
518
- Kind = LocWriterKind::DebugLoclistWriter;
519
- DwarfVersion = DV;
544
+ DebugLoclistWriter (DWARFUnit &Unit, uint8_t DV, bool SD)
545
+ : DebugLocWriter(DV, LocWriterKind::DebugLoclistWriter), CU(Unit),
546
+ IsSplitDwarf (SD) {
520
547
assert (DebugLoclistWriter::AddrWriter &&
521
548
" Please use SetAddressWriter to initialize "
522
549
" DebugAddrWriter before instantiation." );
550
+ if (DwarfVersion >= 5 ) {
551
+ LocBodyBuffer = std::make_unique<DebugBufferVector>();
552
+ LocBodyStream = std::make_unique<raw_svector_ostream>(*LocBodyBuffer);
553
+ } else {
554
+ // Writing out empty location list to which all references to empty
555
+ // location lists will point.
556
+ const char Zeroes[16 ] = {0 };
557
+ *LocStream << StringRef (Zeroes, 16 );
558
+ }
523
559
}
524
560
525
561
static void setAddressWriter (DebugAddrWriter *AddrW) { AddrWriter = AddrW; }
526
562
527
563
// / Stores location lists internally to be written out during finalize phase.
528
- virtual void addList (uint64_t AttrOffset, uint32_t LocListIndex,
529
- DebugLocationsVector &&LocList) override ;
564
+ virtual void addList (AttrInfo &AttrVal, DebugLocationsVector &LocList,
565
+ DebugInfoBinaryPatcher &DebugInfoPatcher,
566
+ DebugAbbrevWriter &AbbrevWriter) override ;
530
567
531
568
// / Writes out locations in to a local buffer and applies debug info patches.
532
- void finalize (uint64_t SectionOffset ,
533
- SimpleBinaryPatcher &DebugInfoPatcher ) override ;
569
+ void finalize (DebugInfoBinaryPatcher &DebugInfoPatcher ,
570
+ DebugAbbrevWriter &AbbrevWriter ) override ;
534
571
535
572
// / Returns CU ID.
536
573
// / For Skelton CU it is a CU Offset.
@@ -548,36 +585,21 @@ class DebugLoclistWriter : public DebugLocWriter {
548
585
bool isSplitDwarf () const { return IsSplitDwarf; }
549
586
550
587
constexpr static uint32_t InvalidIndex = UINT32_MAX;
551
- constexpr static uint32_t InvalidLocListsBaseAttrOffset = UINT32_MAX;
552
588
553
589
private:
554
590
// / Writes out locations in to a local buffer and applies debug info patches.
555
- void finalizeDWARFLegacy (uint64_t SectionOffset,
556
- SimpleBinaryPatcher &DebugInfoPatcher);
557
-
558
- // / Writes out locations in to a local buffer and applies debug info patches.
559
- void finalizeDWARF5 (uint64_t SectionOffset,
560
- SimpleBinaryPatcher &DebugInfoPatcher);
561
-
562
- struct LocPatch {
563
- uint64_t AttrOffset{0 };
564
- uint32_t Index;
565
- DebugLocationsVector LocList;
566
- };
567
- using LocPatchVec = SmallVector<LocPatch, 4 >;
568
- LocPatchVec Patches;
591
+ void finalizeDWARF5 (DebugInfoBinaryPatcher &DebugInfoPatcher,
592
+ DebugAbbrevWriter &AbbrevWriter);
569
593
570
- class Patch {
571
- public:
572
- Patch () = delete ;
573
- Patch (uint64_t O, uint64_t A) : Offset(O), Address(A) {}
574
- uint64_t Offset{0 };
575
- uint64_t Address{0 };
576
- };
577
594
static DebugAddrWriter *AddrWriter;
578
595
DWARFUnit &CU;
579
- uint32_t LocListsBaseAttrOffset{InvalidLocListsBaseAttrOffset};
580
596
bool IsSplitDwarf{false };
597
+ // Used for DWARF5 to store location lists before being finalized.
598
+ std::unique_ptr<DebugBufferVector> LocBodyBuffer;
599
+ std::unique_ptr<raw_svector_ostream> LocBodyStream;
600
+ std::vector<uint32_t > RelativeLocListOffsets;
601
+ uint32_t NumberOfEntries{0 };
602
+ static uint32_t LoclistBaseOffset;
581
603
};
582
604
583
605
enum class PatcherKind { SimpleBinaryPatcher, DebugInfoBinaryPatcher };
@@ -1156,18 +1178,6 @@ class DwarfLineTable {
1156
1178
// Returns DWARF Version for this line table.
1157
1179
uint16_t getDwarfVersion () const { return DwarfVersion; }
1158
1180
};
1159
-
1160
- struct AttrInfo {
1161
- DWARFFormValue V;
1162
- uint64_t Offset;
1163
- uint32_t Size ; // Size of the attribute.
1164
- };
1165
-
1166
- Optional<AttrInfo>
1167
- findAttributeInfo (const DWARFDie DIE,
1168
- const DWARFAbbreviationDeclaration *AbbrevDecl,
1169
- uint32_t Index);
1170
-
1171
1181
} // namespace bolt
1172
1182
} // namespace llvm
1173
1183
0 commit comments