17#include "llvm/Config/llvm-config.h"
28#define DEBUG_TYPE "dwarfdebug"
39 ID.AddInteger(
unsigned(Attribute));
40 ID.AddInteger(
unsigned(Form));
41 if (Form == dwarf::DW_FORM_implicit_const)
52 ID.AddInteger(
unsigned(Tag));
53 ID.AddInteger(
unsigned(Children));
91 if (AttrData.getForm() == dwarf::DW_FORM_implicit_const)
102 O <<
"Abbreviation @"
103 <<
format(
"0x%lx", (
long)(intptr_t)
this)
114 if (
D.getForm() == dwarf::DW_FORM_implicit_const)
115 O <<
" " <<
D.getValue();
121#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
133 Abbrev->~DIEAbbrev();
143 if (
DIEAbbrev *Existing = AbbreviationsSet.lookup(ID, Token)) {
150 Abbreviations.push_back(New);
151 New->setNumber(Abbreviations.size());
155 AbbreviationsSet.insert(New, Token);
160 if (!Abbreviations.empty()) {
176 if (V.getForm() == dwarf::DW_FORM_implicit_const)
178 V.getDIEInteger().getValue());
186 assert(Unit &&
"DIE must be owned by a DIEUnit to get its absolute offset");
187 return Unit->getDebugSectionOffset() +
getOffset();
191 for (
const DIE *
P =
this;
P;
P =
P->getParent())
199 return Unit ? &Unit->getUnitDie() :
nullptr;
205 for (
const auto &V :
values())
214 O <<
Type <<
": Size: " <<
Size <<
"\n";
217 const std::string Indent(IndentCount,
' ');
218 for (
const auto &V :
Values.values()) {
220 O <<
"Blk[" <<
I++ <<
"]";
229 const std::string Indent(IndentCount,
' ');
230 O << Indent <<
"Die: " <<
format(
"0x%lx", (
long)(intptr_t)
this)
231 <<
", Offset: " << Offset <<
", Size: " << Size <<
"\n";
237 for (
const auto &V :
values()) {
246 for (
const auto &Child :
children())
247 Child.print(O, IndentCount + 4);
252#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
272 for (
const auto &V :
values())
273 CUOffset += V.sizeOf(FormParams);
282 Child.computeOffsetsAndAbbrevs(FormParams, AbbrevSet, CUOffset);
285 CUOffset +=
sizeof(int8_t);
307#define HANDLE_DIEVALUE(T) \
309 getDIE##T().emitValue(AP, Form); \
311#include "llvm/CodeGen/DIEValue.def"
319#define HANDLE_DIEVALUE(T) \
321 return getDIE##T().sizeOf(FormParams, Form);
322#include "llvm/CodeGen/DIEValue.def"
332#define HANDLE_DIEVALUE(T) \
334 getDIE##T().print(O); \
336#include "llvm/CodeGen/DIEValue.def"
340#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
354 case dwarf::DW_FORM_implicit_const:
355 case dwarf::DW_FORM_flag_present:
358 Asm->OutStreamer->addBlankLine();
360 case dwarf::DW_FORM_flag:
361 case dwarf::DW_FORM_ref1:
362 case dwarf::DW_FORM_data1:
363 case dwarf::DW_FORM_strx1:
364 case dwarf::DW_FORM_addrx1:
365 case dwarf::DW_FORM_ref2:
366 case dwarf::DW_FORM_data2:
367 case dwarf::DW_FORM_strx2:
368 case dwarf::DW_FORM_addrx2:
369 case dwarf::DW_FORM_strx3:
370 case dwarf::DW_FORM_addrx3:
371 case dwarf::DW_FORM_strp:
372 case dwarf::DW_FORM_ref4:
373 case dwarf::DW_FORM_data4:
374 case dwarf::DW_FORM_ref_sup4:
375 case dwarf::DW_FORM_strx4:
376 case dwarf::DW_FORM_addrx4:
377 case dwarf::DW_FORM_ref8:
378 case dwarf::DW_FORM_ref_sig8:
379 case dwarf::DW_FORM_data8:
380 case dwarf::DW_FORM_ref_sup8:
381 case dwarf::DW_FORM_GNU_ref_alt:
382 case dwarf::DW_FORM_GNU_strp_alt:
383 case dwarf::DW_FORM_line_strp:
384 case dwarf::DW_FORM_sec_offset:
385 case dwarf::DW_FORM_strp_sup:
386 case dwarf::DW_FORM_addr:
387 case dwarf::DW_FORM_ref_addr:
388 Asm->OutStreamer->emitIntValue(Integer,
389 sizeOf(Asm->getDwarfFormParams(), Form));
391 case dwarf::DW_FORM_GNU_str_index:
392 case dwarf::DW_FORM_GNU_addr_index:
393 case dwarf::DW_FORM_ref_udata:
394 case dwarf::DW_FORM_strx:
395 case dwarf::DW_FORM_addrx:
396 case dwarf::DW_FORM_rnglistx:
397 case dwarf::DW_FORM_udata:
398 Asm->emitULEB128(Integer);
400 case dwarf::DW_FORM_sdata:
401 Asm->emitSLEB128(Integer);
411 if (std::optional<uint8_t> FixedSize =
416 case dwarf::DW_FORM_GNU_str_index:
417 case dwarf::DW_FORM_GNU_addr_index:
418 case dwarf::DW_FORM_ref_udata:
419 case dwarf::DW_FORM_strx:
420 case dwarf::DW_FORM_addrx:
421 case dwarf::DW_FORM_rnglistx:
422 case dwarf::DW_FORM_udata:
424 case dwarf::DW_FORM_sdata:
432 O <<
"Int: " << (int64_t)Integer <<
" 0x";
433 O.write_hex(Integer);
451 case dwarf::DW_FORM_data4:
453 case dwarf::DW_FORM_data8:
455 case dwarf::DW_FORM_sec_offset:
476 bool IsSectionRelative = Form != dwarf::DW_FORM_addr;
486 case dwarf::DW_FORM_data4:
488 case dwarf::DW_FORM_data8:
490 case dwarf::DW_FORM_sec_offset:
491 case dwarf::DW_FORM_strp:
493 case dwarf::DW_FORM_addr:
508 uint64_t
Offset =
CU->ExprRefedBaseTypes[Index].Die->getOffset();
509 assert(
Offset < (1ULL << (ULEB128PadSize * 7)) &&
"Offset wont fit");
514 return ULEB128PadSize;
536 case dwarf::DW_FORM_data4:
538 case dwarf::DW_FORM_data8:
540 case dwarf::DW_FORM_sec_offset:
549 O <<
"Del: " << LabelHi->getName() <<
"-" << LabelLo->getName();
561 case dwarf::DW_FORM_GNU_str_index:
562 case dwarf::DW_FORM_strx:
563 case dwarf::DW_FORM_strx1:
564 case dwarf::DW_FORM_strx2:
565 case dwarf::DW_FORM_strx3:
566 case dwarf::DW_FORM_strx4:
569 case dwarf::DW_FORM_strp:
586 case dwarf::DW_FORM_GNU_str_index:
587 case dwarf::DW_FORM_strx:
588 case dwarf::DW_FORM_strx1:
589 case dwarf::DW_FORM_strx2:
590 case dwarf::DW_FORM_strx3:
591 case dwarf::DW_FORM_strx4:
593 case dwarf::DW_FORM_strp:
604 O <<
"String: " << S.getString();
611 if (Form == dwarf::DW_FORM_string) {
626 O <<
"InlineString: " << S;
638 case dwarf::DW_FORM_ref1:
639 case dwarf::DW_FORM_ref2:
640 case dwarf::DW_FORM_ref4:
641 case dwarf::DW_FORM_ref8:
646 case dwarf::DW_FORM_ref_udata:
650 case dwarf::DW_FORM_ref_addr: {
652 uint64_t Addr = Entry->getDebugSectionOffset();
654 Entry->getUnit()->getCrossSectionRelativeBaseAddress()) {
671 case dwarf::DW_FORM_ref1:
673 case dwarf::DW_FORM_ref2:
675 case dwarf::DW_FORM_ref4:
677 case dwarf::DW_FORM_ref8:
679 case dwarf::DW_FORM_ref_udata:
681 case dwarf::DW_FORM_ref_addr:
691 O <<
format(
"Die: 0x%lx", (
long)(intptr_t)&Entry);
700 for (
const auto &V :
values())
701 Size += V.sizeOf(FormParams);
712 case dwarf::DW_FORM_block1: Asm->emitInt8(Size);
break;
713 case dwarf::DW_FORM_block2: Asm->emitInt16(Size);
break;
714 case dwarf::DW_FORM_block4: Asm->emitInt32(Size);
break;
715 case dwarf::DW_FORM_block:
716 case dwarf::DW_FORM_exprloc:
717 Asm->emitULEB128(Size);
721 for (
const auto &V :
values())
729 case dwarf::DW_FORM_block1:
return Size +
sizeof(int8_t);
730 case dwarf::DW_FORM_block2:
return Size +
sizeof(int16_t);
731 case dwarf::DW_FORM_block4:
return Size +
sizeof(int32_t);
732 case dwarf::DW_FORM_block:
733 case dwarf::DW_FORM_exprloc:
750 for (
const auto &V :
values())
751 Size += V.sizeOf(FormParams);
762 case dwarf::DW_FORM_block1: Asm->emitInt8(Size);
break;
763 case dwarf::DW_FORM_block2: Asm->emitInt16(Size);
break;
764 case dwarf::DW_FORM_block4: Asm->emitInt32(Size);
break;
765 case dwarf::DW_FORM_exprloc:
766 case dwarf::DW_FORM_block:
767 Asm->emitULEB128(Size);
769 case dwarf::DW_FORM_string:
break;
770 case dwarf::DW_FORM_data16:
break;
773 for (
const auto &V :
values())
781 case dwarf::DW_FORM_block1:
return Size +
sizeof(int8_t);
782 case dwarf::DW_FORM_block2:
return Size +
sizeof(int16_t);
783 case dwarf::DW_FORM_block4:
return Size +
sizeof(int32_t);
784 case dwarf::DW_FORM_exprloc:
786 case dwarf::DW_FORM_data16:
return 16;
803 case dwarf::DW_FORM_loclistx:
805 case dwarf::DW_FORM_data4:
807 "DW_FORM_data4 is not suitable to emit a pointer to a location list "
808 "in the 64-bit DWARF format");
810 case dwarf::DW_FORM_data8:
812 "DW_FORM_data8 is not suitable to emit a pointer to a location list "
813 "in the 32-bit DWARF format");
815 case dwarf::DW_FORM_sec_offset:
825 if (Form == dwarf::DW_FORM_loclistx) {
843 return Addr.sizeOf(FormParams, dwarf::DW_FORM_addrx) +
844 Offset.sizeOf(FormParams, dwarf::DW_FORM_data4);
850 Addr.emitValue(AP, dwarf::DW_FORM_addrx);
851 Offset.emitValue(AP, dwarf::DW_FORM_data4);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
static LLVM_DUMP_METHOD void printValues(raw_ostream &O, const DIEValueList &Values, StringRef Type, unsigned Size, unsigned IndentCount)
This class is intended to be used as a driving class for all asm writers.
void emitULEB128(uint64_t Value, const char *Desc=nullptr, unsigned PadTo=0) const
Emit the specified unsigned leb128 value.
void emitDwarfSymbolReference(const MCSymbol *Label, bool ForceOffset=false) const
Emit a reference to a symbol for use in dwarf.
virtual void emitDebugValue(const MCExpr *Value, unsigned Size) const
Emit the directive and value for debug thread local expression.
DwarfDebug * getDwarfDebug()
void emitLabelPlusOffset(const MCSymbol *Label, uint64_t Offset, unsigned Size, bool IsSectionRelative=false) const
Emit something like ".long Label+Offset" where the size in bytes of the directive is specified by Siz...
void emitLabelDifference(const MCSymbol *Hi, const MCSymbol *Lo, unsigned Size) const
Emit something like ".long Hi-Lo" where the size in bytes of the directive is specified by Size and H...
void emitInt8(int Value) const
Emit a byte directive and value.
void emitDwarfAbbrevs(const T &Abbrevs) const
Emit Dwarf abbreviation table.
void emitSLEB128(int64_t Value, const char *Desc=nullptr) const
Emit the specified signed leb128 value.
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
void emitLabelReference(const MCSymbol *Label, unsigned Size, bool IsSectionRelative=false) const
Emit something like ".long Label" where the size in bytes of the directive is specified by Size and L...
uint16_t getDwarfVersion() const
dwarf::FormParams getDwarfFormParams() const
Returns information about the byte size of DW_FORM values.
bool doesDwarfUseRelocationsAcrossSections() const
Functions, function parameters, and return types can have attributes to indicate how they should be t...
Dwarf abbreviation data, describes one attribute of a Dwarf abbreviation.
LLVM_ABI void Profile(FoldingSetNodeID &ID) const
Used to gather unique data for the abbreviation folding set.
Helps unique DIEAbbrev objects and assigns abbreviation numbers.
LLVM_ABI void Emit(const AsmPrinter *AP, MCSection *Section) const
Print all abbreviations using the specified asm printer.
LLVM_ABI DIEAbbrev & uniqueAbbreviation(DIE &Die)
Generate the abbreviation declaration for a DIE and return a pointer to the generated abbreviation.
Dwarf abbreviation, describes the organization of a debug information object.
LLVM_ABI void print(raw_ostream &O) const
void AddImplicitConstAttribute(dwarf::Attribute Attribute, int64_t Value)
Adds attribute with DW_FORM_implicit_const value.
LLVM_ABI void Emit(const AsmPrinter *AP) const
Print the abbreviation using the specified asm printer.
void AddAttribute(dwarf::Attribute Attribute, dwarf::Form Form)
Adds another set of attribute information to the abbreviation.
LLVM_ABI void dump() const
LLVM_ABI void Profile(FoldingSetNodeID &ID) const
Used to gather unique data for the abbreviation folding set.
LLVM_ABI void print(raw_ostream &O) const
LLVM_ABI unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const
LLVM_ABI void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit label value.
LLVM_ABI void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit base type reference.
LLVM_ABI void print(raw_ostream &O) const
LLVM_ABI unsigned sizeOf(const dwarf::FormParams &, dwarf::Form) const
sizeOf - Determine size of the base type reference in bytes.
LLVM_ABI unsigned sizeOf(const dwarf::FormParams &, dwarf::Form Form) const
sizeOf - Determine size of block data in bytes.
LLVM_ABI void print(raw_ostream &O) const
LLVM_ABI void emitValue(const AsmPrinter *Asm, dwarf::Form Form) const
EmitValue - Emit block data.
LLVM_ABI unsigned computeSize(const dwarf::FormParams &FormParams) const
Calculate the size of the location expression.
LLVM_ABI void print(raw_ostream &O) const
LLVM_ABI unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const
SizeOf - Determine size of delta value in bytes.
LLVM_ABI void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit delta value.
LLVM_ABI void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit debug information entry offset.
LLVM_ABI void print(raw_ostream &O) const
LLVM_ABI unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const
LLVM_ABI void print(raw_ostream &O) const
LLVM_ABI void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit expression value.
LLVM_ABI unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const
SizeOf - Determine size of expression value in bytes.
LLVM_ABI void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
LLVM_ABI void print(raw_ostream &O) const
LLVM_ABI unsigned sizeOf(const dwarf::FormParams &, dwarf::Form) const
LLVM_ABI unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const
sizeOf - Determine size of integer value in bytes.
LLVM_ABI void print(raw_ostream &O) const
LLVM_ABI void emitValue(const AsmPrinter *Asm, dwarf::Form Form) const
EmitValue - Emit integer of appropriate size.
LLVM_ABI void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit label value.
LLVM_ABI void print(raw_ostream &O) const
LLVM_ABI unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const
sizeOf - Determine size of label value in bytes.
LLVM_ABI void print(raw_ostream &O) const
LLVM_ABI unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const
LLVM_ABI void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit label value.
LLVM_ABI void print(raw_ostream &O) const
LLVM_ABI unsigned sizeOf(const dwarf::FormParams &, dwarf::Form Form) const
sizeOf - Determine size of location data in bytes.
LLVM_ABI void emitValue(const AsmPrinter *Asm, dwarf::Form Form) const
EmitValue - Emit location data.
LLVM_ABI unsigned computeSize(const dwarf::FormParams &FormParams) const
Calculate the size of the location expression.
LLVM_ABI void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit string value.
LLVM_ABI void print(raw_ostream &O) const
LLVM_ABI unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const
sizeOf - Determine size of delta value in bytes.
LLVM_ABI DIEUnit(dwarf::Tag UnitTag)
LLVM_ABI void print(raw_ostream &O) const
LLVM_ABI void emitValue(const AsmPrinter *AP) const
Emit value via the Dwarf writer.
LLVM_ABI unsigned sizeOf(const dwarf::FormParams &FormParams) const
Return the size of a value in bytes.
LLVM_ABI void dump() const
A structured debug information entry.
LLVM_ABI DIEValue findAttribute(dwarf::Attribute Attribute) const
Find a value in the DIE with the attribute given.
LLVM_ABI void print(raw_ostream &O, unsigned IndentCount=0) const
unsigned getAbbrevNumber() const
LLVM_ABI DIEAbbrev generateAbbrev() const
Generate the abbreviation for this DIE.
LLVM_ABI unsigned computeOffsetsAndAbbrevs(const dwarf::FormParams &FormParams, DIEAbbrevSet &AbbrevSet, unsigned CUOffset)
Compute the offset of this DIE and all its children.
LLVM_ABI DIEUnit * getUnit() const
Climb up the parent chain to get the unit that this DIE belongs to.
LLVM_ABI const DIE * getUnitDie() const
Climb up the parent chain to get the unit DIE that this DIE belongs to.
void setAbbrevNumber(unsigned I)
Set the abbreviation number for this DIE.
unsigned getOffset() const
Get the compile/type unit relative offset of this DIE.
void setOffset(unsigned O)
LLVM_ABI uint64_t getDebugSectionOffset() const
Get the absolute offset within the .debug_info or .debug_types section for this DIE.
dwarf::Tag getTag() const
LLVM_ABI void dump() const
LLVM_ABI DIE * getParent() const
const List & getList(size_t LI) const
Collects and handles dwarf debug information.
const DebugLocStream & getDebugLocs() const
Returns the entries for the .debug_loc section.
bool useSplitDwarf() const
Returns whether or not to change the current debug info for split DWARF.
Insertion token: a failed lookup fills it in, the matching insert consumes it.
This class is used to gather all the unique data bits of a node.
This class is intended to be used as a base class for asm properties and features specific to the tar...
void printExpr(raw_ostream &, const MCExpr &) const
Instances of this class represent a uniqued identifier for a section in the current translation unit.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Represent a constant reference to a string, i.e.
The instances of the Type class are immutable: once they are created, they are never changed.
This class implements an extremely fast bulk output stream that can only output to a stream.
LLVM_ABI StringRef AttributeString(unsigned Attribute)
LLVM_ABI StringRef FormEncodingString(unsigned Encoding)
LLVM_ABI StringRef ChildrenString(unsigned Children)
LLVM_ABI StringRef TagString(unsigned Tag)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
bool isUnitType(uint8_t UnitType)
LLVM_ABI bool isValidFormForVersion(Form F, unsigned Version, bool ExtensionsOk=true)
Tells whether the specified form is defined in the specified version, or is an extension if extension...
LLVM_ABI std::optional< uint8_t > getFixedFormByteSize(dwarf::Form Form, FormParams Params)
Get the fixed byte size for a given form.
This is an optimization pass for GlobalISel generic memory operations.
RelativeUniformCounterPtr Values
auto dyn_cast_if_present(const Y &Val)
dyn_cast_if_present<X> - Functionally identical to dyn_cast, except that a null (or none in the case ...
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
LLVM_ABI unsigned getULEB128Size(uint64_t Value)
Utility function to get the size of the ULEB128-encoded value.
LLVM_ABI unsigned getSLEB128Size(int64_t Value)
Utility function to get the size of the SLEB128-encoded value.