17#include "llvm/Config/llvm-config.h"
28#define DEBUG_TYPE "dwarfdebug"
40 ID.AddInteger(
unsigned(
Form));
41 if (
Form == dwarf::DW_FORM_implicit_const)
52 ID.AddInteger(
unsigned(
Tag));
53 ID.AddInteger(
unsigned(Children));
56 for (
unsigned i = 0,
N = Data.size(); i <
N; ++i)
70 for (
unsigned i = 0,
N = Data.size(); i <
N; ++i) {
93 if (AttrData.
getForm() == dwarf::DW_FORM_implicit_const)
104 O <<
"Abbreviation @"
105 <<
format(
"0x%lx", (
long)(intptr_t)
this)
112 for (
unsigned i = 0,
N = Data.size(); i <
N; ++i) {
118 if (Data[i].getForm() == dwarf::DW_FORM_implicit_const)
119 O <<
" " << Data[i].getValue();
125#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
137 Abbrev->~DIEAbbrev();
148 AbbreviationsSet.FindNodeOrInsertPos(
ID, InsertPos)) {
155 Abbreviations.push_back(New);
156 New->setNumber(Abbreviations.size());
160 AbbreviationsSet.InsertNode(New, InsertPos);
165 if (!Abbreviations.empty()) {
177 return Owner.dyn_cast<
DIE*>();
183 if (V.getForm() == dwarf::DW_FORM_implicit_const)
185 V.getDIEInteger().getValue());
193 assert(Unit &&
"DIE must be owned by a DIEUnit to get its absolute offset");
194 return Unit->getDebugSectionOffset() +
getOffset();
200 if (p->getTag() == dwarf::DW_TAG_compile_unit ||
201 p->getTag() == dwarf::DW_TAG_skeleton_unit ||
202 p->getTag() == dwarf::DW_TAG_type_unit)
212 return UnitDie->Owner.dyn_cast<
DIEUnit*>();
219 for (
const auto &V :
values())
228 O <<
Type <<
": Size: " <<
Size <<
"\n";
231 const std::string Indent(IndentCount,
' ');
232 for (
const auto &V : Values.
values()) {
234 O <<
"Blk[" <<
I++ <<
"]";
243 const std::string Indent(IndentCount,
' ');
244 O << Indent <<
"Die: " <<
format(
"0x%lx", (
long)(intptr_t)
this)
245 <<
", Offset: " << Offset <<
", Size: " << Size <<
"\n";
251 for (
const auto &V :
values()) {
260 for (
const auto &Child :
children())
261 Child.print(O, IndentCount + 4);
266#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
286 for (
const auto &V :
values())
296 Child.computeOffsetsAndAbbrevs(
FormParams, AbbrevSet, CUOffset);
299 CUOffset +=
sizeof(int8_t);
314 assert((UnitTag == dwarf::DW_TAG_compile_unit ||
315 UnitTag == dwarf::DW_TAG_skeleton_unit ||
316 UnitTag == dwarf::DW_TAG_type_unit ||
317 UnitTag == dwarf::DW_TAG_partial_unit) &&
318 "expected a unit TAG");
325#define HANDLE_DIEVALUE(T) \
327 getDIE##T().emitValue(AP, Form); \
329#include "llvm/CodeGen/DIEValue.def"
337#define HANDLE_DIEVALUE(T) \
339 return getDIE##T().sizeOf(FormParams, Form);
340#include "llvm/CodeGen/DIEValue.def"
350#define HANDLE_DIEVALUE(T) \
352 getDIE##T().print(O); \
354#include "llvm/CodeGen/DIEValue.def"
358#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
372 case dwarf::DW_FORM_implicit_const:
373 case dwarf::DW_FORM_flag_present:
376 Asm->OutStreamer->addBlankLine();
378 case dwarf::DW_FORM_flag:
379 case dwarf::DW_FORM_ref1:
380 case dwarf::DW_FORM_data1:
381 case dwarf::DW_FORM_strx1:
382 case dwarf::DW_FORM_addrx1:
383 case dwarf::DW_FORM_ref2:
384 case dwarf::DW_FORM_data2:
385 case dwarf::DW_FORM_strx2:
386 case dwarf::DW_FORM_addrx2:
387 case dwarf::DW_FORM_strx3:
388 case dwarf::DW_FORM_addrx3:
389 case dwarf::DW_FORM_strp:
390 case dwarf::DW_FORM_ref4:
391 case dwarf::DW_FORM_data4:
392 case dwarf::DW_FORM_ref_sup4:
393 case dwarf::DW_FORM_strx4:
394 case dwarf::DW_FORM_addrx4:
395 case dwarf::DW_FORM_ref8:
396 case dwarf::DW_FORM_ref_sig8:
397 case dwarf::DW_FORM_data8:
398 case dwarf::DW_FORM_ref_sup8:
399 case dwarf::DW_FORM_GNU_ref_alt:
400 case dwarf::DW_FORM_GNU_strp_alt:
401 case dwarf::DW_FORM_line_strp:
402 case dwarf::DW_FORM_sec_offset:
403 case dwarf::DW_FORM_strp_sup:
404 case dwarf::DW_FORM_addr:
405 case dwarf::DW_FORM_ref_addr:
406 Asm->OutStreamer->emitIntValue(Integer,
409 case dwarf::DW_FORM_GNU_str_index:
410 case dwarf::DW_FORM_GNU_addr_index:
411 case dwarf::DW_FORM_ref_udata:
412 case dwarf::DW_FORM_strx:
413 case dwarf::DW_FORM_addrx:
414 case dwarf::DW_FORM_rnglistx:
415 case dwarf::DW_FORM_udata:
416 Asm->emitULEB128(Integer);
418 case dwarf::DW_FORM_sdata:
419 Asm->emitSLEB128(Integer);
429 if (std::optional<uint8_t> FixedSize =
434 case dwarf::DW_FORM_GNU_str_index:
435 case dwarf::DW_FORM_GNU_addr_index:
436 case dwarf::DW_FORM_ref_udata:
437 case dwarf::DW_FORM_strx:
438 case dwarf::DW_FORM_addrx:
439 case dwarf::DW_FORM_rnglistx:
440 case dwarf::DW_FORM_udata:
442 case dwarf::DW_FORM_sdata:
450 O <<
"Int: " << (int64_t)Integer <<
" 0x";
451 O.write_hex(Integer);
469 case dwarf::DW_FORM_data4:
471 case dwarf::DW_FORM_data8:
473 case dwarf::DW_FORM_sec_offset:
490 bool IsSectionRelative =
Form != dwarf::DW_FORM_addr;
500 case dwarf::DW_FORM_data4:
502 case dwarf::DW_FORM_data8:
504 case dwarf::DW_FORM_sec_offset:
505 case dwarf::DW_FORM_strp:
507 case dwarf::DW_FORM_addr:
523 assert(
Offset < (1ULL << (ULEB128PadSize * 7)) &&
"Offset wont fit");
528 return ULEB128PadSize;
550 case dwarf::DW_FORM_data4:
552 case dwarf::DW_FORM_data8:
554 case dwarf::DW_FORM_sec_offset:
575 case dwarf::DW_FORM_GNU_str_index:
576 case dwarf::DW_FORM_strx:
577 case dwarf::DW_FORM_strx1:
578 case dwarf::DW_FORM_strx2:
579 case dwarf::DW_FORM_strx3:
580 case dwarf::DW_FORM_strx4:
583 case dwarf::DW_FORM_strp:
600 case dwarf::DW_FORM_GNU_str_index:
601 case dwarf::DW_FORM_strx:
602 case dwarf::DW_FORM_strx1:
603 case dwarf::DW_FORM_strx2:
604 case dwarf::DW_FORM_strx3:
605 case dwarf::DW_FORM_strx4:
607 case dwarf::DW_FORM_strp:
625 if (
Form == dwarf::DW_FORM_string) {
640 O <<
"InlineString: " << S;
652 case dwarf::DW_FORM_ref1:
653 case dwarf::DW_FORM_ref2:
654 case dwarf::DW_FORM_ref4:
655 case dwarf::DW_FORM_ref8:
660 case dwarf::DW_FORM_ref_udata:
664 case dwarf::DW_FORM_ref_addr: {
685 case dwarf::DW_FORM_ref1:
687 case dwarf::DW_FORM_ref2:
689 case dwarf::DW_FORM_ref4:
691 case dwarf::DW_FORM_ref8:
693 case dwarf::DW_FORM_ref_udata:
695 case dwarf::DW_FORM_ref_addr:
705 O <<
format(
"Die: 0x%lx", (
long)(intptr_t)&Entry);
714 for (
const auto &V :
values())
726 case dwarf::DW_FORM_block1: Asm->emitInt8(Size);
break;
727 case dwarf::DW_FORM_block2: Asm->emitInt16(Size);
break;
728 case dwarf::DW_FORM_block4: Asm->emitInt32(Size);
break;
729 case dwarf::DW_FORM_block:
730 case dwarf::DW_FORM_exprloc:
731 Asm->emitULEB128(Size);
735 for (
const auto &V :
values())
743 case dwarf::DW_FORM_block1:
return Size +
sizeof(int8_t);
744 case dwarf::DW_FORM_block2:
return Size +
sizeof(int16_t);
745 case dwarf::DW_FORM_block4:
return Size +
sizeof(int32_t);
746 case dwarf::DW_FORM_block:
747 case dwarf::DW_FORM_exprloc:
764 for (
const auto &V :
values())
776 case dwarf::DW_FORM_block1: Asm->emitInt8(Size);
break;
777 case dwarf::DW_FORM_block2: Asm->emitInt16(Size);
break;
778 case dwarf::DW_FORM_block4: Asm->emitInt32(Size);
break;
779 case dwarf::DW_FORM_exprloc:
780 case dwarf::DW_FORM_block:
781 Asm->emitULEB128(Size);
783 case dwarf::DW_FORM_string:
break;
784 case dwarf::DW_FORM_data16:
break;
787 for (
const auto &V :
values())
795 case dwarf::DW_FORM_block1:
return Size +
sizeof(int8_t);
796 case dwarf::DW_FORM_block2:
return Size +
sizeof(int16_t);
797 case dwarf::DW_FORM_block4:
return Size +
sizeof(int32_t);
798 case dwarf::DW_FORM_exprloc:
800 case dwarf::DW_FORM_data16:
return 16;
817 case dwarf::DW_FORM_loclistx:
819 case dwarf::DW_FORM_data4:
821 "DW_FORM_data4 is not suitable to emit a pointer to a location list "
822 "in the 64-bit DWARF format");
824 case dwarf::DW_FORM_data8:
826 "DW_FORM_data8 is not suitable to emit a pointer to a location list "
827 "in the 32-bit DWARF format");
829 case dwarf::DW_FORM_sec_offset:
839 if (
Form == dwarf::DW_FORM_loclistx) {
864 Addr.
emitValue(AP, dwarf::DW_FORM_addrx);
865 Offset.
emitValue(AP, dwarf::DW_FORM_data4);
#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)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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
Dwarf abbreviation data, describes one attribute of a Dwarf abbreviation.
dwarf::Form getForm() const
dwarf::Attribute getAttribute() const
Accessors.
void Profile(FoldingSetNodeID &ID) const
Used to gather unique data for the abbreviation folding set.
Helps unique DIEAbbrev objects and assigns abbreviation numbers.
void Emit(const AsmPrinter *AP, MCSection *Section) const
Print all abbreviations using the specified asm printer.
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.
void print(raw_ostream &O) const
void AddImplicitConstAttribute(dwarf::Attribute Attribute, int64_t Value)
Adds attribute with DW_FORM_implicit_const value.
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.
void Profile(FoldingSetNodeID &ID) const
Used to gather unique data for the abbreviation folding set.
void print(raw_ostream &O) const
unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const
void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit label value.
void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit base type reference.
void print(raw_ostream &O) const
unsigned sizeOf(const dwarf::FormParams &, dwarf::Form) const
sizeOf - Determine size of the base type reference in bytes.
unsigned sizeOf(const dwarf::FormParams &, dwarf::Form Form) const
sizeOf - Determine size of block data in bytes.
void print(raw_ostream &O) const
void emitValue(const AsmPrinter *Asm, dwarf::Form Form) const
EmitValue - Emit block data.
unsigned computeSize(const dwarf::FormParams &FormParams) const
Calculate the size of the location expression.
void print(raw_ostream &O) const
unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const
SizeOf - Determine size of delta value in bytes.
void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit delta value.
void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit debug information entry offset.
void print(raw_ostream &O) const
unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const
void print(raw_ostream &O) const
void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit expression value.
unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const
SizeOf - Determine size of expression value in bytes.
void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
void print(raw_ostream &O) const
unsigned sizeOf(const dwarf::FormParams &, dwarf::Form) const
unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const
sizeOf - Determine size of integer value in bytes.
void print(raw_ostream &O) const
void emitValue(const AsmPrinter *Asm, dwarf::Form Form) const
EmitValue - Emit integer of appropriate size.
void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit label value.
void print(raw_ostream &O) const
unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const
sizeOf - Determine size of label value in bytes.
void print(raw_ostream &O) const
unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const
void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit label value.
void print(raw_ostream &O) const
unsigned sizeOf(const dwarf::FormParams &, dwarf::Form Form) const
sizeOf - Determine size of location data in bytes.
void emitValue(const AsmPrinter *Asm, dwarf::Form Form) const
EmitValue - Emit location data.
unsigned computeSize(const dwarf::FormParams &FormParams) const
Calculate the size of the location expression.
void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit string value.
void print(raw_ostream &O) const
unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const
sizeOf - Determine size of delta value in bytes.
Represents a compile or type unit.
virtual const MCSymbol * getCrossSectionRelativeBaseAddress() const
DIEUnit(dwarf::Tag UnitTag)
void print(raw_ostream &O) const
void emitValue(const AsmPrinter *AP) const
Emit value via the Dwarf writer.
unsigned sizeOf(const dwarf::FormParams &FormParams) const
Return the size of a value in bytes.
A structured debug information entry.
DIEValue findAttribute(dwarf::Attribute Attribute) const
Find a value in the DIE with the attribute given.
void print(raw_ostream &O, unsigned IndentCount=0) const
unsigned getAbbrevNumber() const
DIEAbbrev generateAbbrev() const
Generate the abbreviation for this DIE.
unsigned computeOffsetsAndAbbrevs(const dwarf::FormParams &FormParams, DIEAbbrevSet &AbbrevSet, unsigned CUOffset)
Compute the offset of this DIE and all its children.
DIEUnit * getUnit() const
Climb up the parent chain to get the compile unit or type unit that this DIE belongs to.
const DIE * getUnitDie() const
Climb up the parent chain to get the compile unit or type 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)
uint64_t getDebugSectionOffset() const
Get the absolute offset within the .debug_info or .debug_types section for this DIE.
dwarf::Tag getTag() 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 the split dwarf proposal support.
unsigned getIndex() const
StringRef getString() const
uint64_t getOffset() const
MCSymbol * getSymbol() const
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
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 ...
StringRef getName() const
getName - Get the symbol name.
StringRef - Represent a constant reference to a string, i.e.
constexpr size_t size() const
size - Get the string size.
const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM Value Representation.
This class implements an extremely fast bulk output stream that can only output to a stream.
StringRef AttributeString(unsigned Attribute)
StringRef FormEncodingString(unsigned Encoding)
StringRef ChildrenString(unsigned Children)
StringRef TagString(unsigned Tag)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
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...
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.
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.
unsigned getULEB128Size(uint64_t Value)
Utility function to get the size of the ULEB128-encoded value.
unsigned getSLEB128Size(int64_t Value)
Utility function to get the size of the SLEB128-encoded value.