30 assert(Operand < Operands.
size() &&
"operand out of bounds");
32 OS <<
formatv(
" <base_type ref: {0:x}>", Operands[Operand]);
35 auto Die = U->getDIEForOffset(U->getOffset() + Operands[Operand]);
36 if (Die && Die.getTag() == dwarf::DW_TAG_base_type) {
39 OS <<
formatv(
"{0:x8} -> ", Operands[Operand]);
40 OS <<
formatv(
"{0:x8})", U->getOffset() + Operands[Operand]);
42 OS <<
" \"" << *Name <<
"\"";
44 OS <<
formatv(
" <invalid base_type ref: {0:x}>", Operands[Operand]);
53 OS <<
"<decoding error>";
57 std::optional<unsigned> SubOpcode =
Op->getSubCode();
66 if ((
Op->getCode() >= DW_OP_breg0 &&
Op->getCode() <= DW_OP_breg31) ||
67 (
Op->getCode() >= DW_OP_reg0 &&
Op->getCode() <= DW_OP_reg31) ||
68 Op->getCode() == DW_OP_bregx ||
Op->getCode() == DW_OP_regx ||
69 Op->getCode() == DW_OP_regval_type ||
70 SubOpcode == DW_OP_LLVM_call_frame_entry_reg ||
71 SubOpcode == DW_OP_LLVM_aspace_bregx) {
73 Op->getRawOperands()))
79 if (
Op->getCode() == DW_OP_constu) {
83 if (
Op->getCode() == DW_OP_consts) {
84 OS << (int64_t)
Op->getRawOperand(0);
87 if (
Op->getCode() >= DW_OP_lit0 &&
Op->getCode() <= DW_OP_lit31) {
91 if (
Op->getCode() == DW_OP_stack_value)
99 assert(!Name.empty() &&
"DW_OP has no name!");
104 assert(!SubName.
empty() &&
"DW_OP SubOp has no name!");
105 OS <<
' ' << SubName;
109 if ((
Op->getCode() >= DW_OP_breg0 &&
Op->getCode() <= DW_OP_breg31) ||
110 (
Op->getCode() >= DW_OP_reg0 &&
Op->getCode() <= DW_OP_reg31) ||
111 Op->getCode() == DW_OP_bregx ||
Op->getCode() == DW_OP_regx ||
112 Op->getCode() == DW_OP_regval_type ||
113 SubOpcode == DW_OP_LLVM_call_frame_entry_reg ||
114 SubOpcode == DW_OP_LLVM_aspace_bregx)
116 Op->getRawOperands()))
120 for (
unsigned Operand = 0; Operand <
Op->getDescription().
Op.size();
122 unsigned Size =
Op->getDescription().Op[Operand];
126 assert(Operand == 0 &&
"DW_OP SubOp must be the first operand");
127 assert(SubOpcode &&
"DW_OP SubOp description is inconsistent");
132 if (
Op->getCode() == DW_OP_convert &&
Op->getRawOperand(Operand) == 0)
139 switch (
Op->getRawOperand(0)) {
145 OS <<
formatv(
" {0:x}",
Op->getRawOperand(Operand));
152 for (
unsigned i = 0; i <
Op->getRawOperand(Operand - 1); ++i)
157 OS <<
formatv(
" {0:+d}", (int64_t)
Op->getRawOperand(Operand));
158 else if (
Op->getCode() != DW_OP_entry_value &&
159 Op->getCode() != DW_OP_GNU_entry_value)
160 OS <<
formatv(
" {0:x}",
Op->getRawOperand(Operand));
171 if (E->getData().empty())
174 for (
auto &
Op : *E) {
175 DumpOpts.
IsEH = IsEH;
178 while (FailOffset < E->getData().
size())
180 static_cast<uint8_t>(E->getData()[FailOffset++]));
184 if (
Op.getCode() == DW_OP_entry_value ||
185 Op.getCode() == DW_OP_GNU_entry_value) {
187 EntryValExprSize =
Op.getRawOperand(0);
188 EntryValStartOffset =
Op.getEndOffset();
192 if (EntryValExprSize) {
193 EntryValExprSize -=
Op.getEndOffset() - EntryValStartOffset;
194 if (EntryValExprSize == 0)
198 if (
Op.getEndOffset() < E->getData().size())
226 std::optional<unsigned> SubOpcode) ->
bool {
233 <<
" (" << *SubOpcode;
242 case dwarf::DW_OP_regx: {
246 auto RegName = GetNameForDWARFReg(DwarfRegNum,
false);
253 case dwarf::DW_OP_bregx: {
254 int DwarfRegNum =
Op.getRawOperand(0);
255 int64_t
Offset =
Op.getRawOperand(1);
256 auto RegName = GetNameForDWARFReg(DwarfRegNum,
false);
265 case dwarf::DW_OP_entry_value:
266 case dwarf::DW_OP_GNU_entry_value: {
279 case dwarf::DW_OP_stack_value: {
286 case dwarf::DW_OP_nop: {
289 case dwarf::DW_OP_LLVM_user: {
290 std::optional<unsigned> SubOpcode =
Op.getSubCode();
291 if (SubOpcode == dwarf::DW_OP_LLVM_nop)
293 return UnknownOpcode(OS, Opcode, SubOpcode);
296 if (Opcode >= dwarf::DW_OP_reg0 && Opcode <= dwarf::DW_OP_reg31) {
299 uint64_t DwarfRegNum = Opcode - dwarf::DW_OP_reg0;
300 auto RegName = GetNameForDWARFReg(DwarfRegNum,
false);
305 }
else if (Opcode >= dwarf::DW_OP_breg0 &&
306 Opcode <= dwarf::DW_OP_breg31) {
307 int DwarfRegNum = Opcode - dwarf::DW_OP_breg0;
308 int64_t
Offset =
Op.getRawOperand(0);
309 auto RegName = GetNameForDWARFReg(DwarfRegNum,
false);
317 return UnknownOpcode(OS, Opcode, std::nullopt);
324 if (Stack.size() != 1) {
325 OS <<
"<stack of size " << Stack.size() <<
", expected 1>";
330 OS <<
"[" << Stack.front().String <<
"]";
332 OS << Stack.front().String;
352 std::optional<unsigned> SubOpcode;
353 if (Opcode == DW_OP_LLVM_user)
354 SubOpcode = Operands[OpNum++];
356 if (Opcode == DW_OP_bregx || Opcode == DW_OP_regx ||
357 Opcode == DW_OP_regval_type || SubOpcode == DW_OP_LLVM_aspace_bregx ||
358 SubOpcode == DW_OP_LLVM_call_frame_entry_reg)
359 DwarfRegNum = Operands[OpNum++];
360 else if (Opcode >= DW_OP_breg0 && Opcode < DW_OP_bregx)
361 DwarfRegNum = Opcode - DW_OP_breg0;
363 DwarfRegNum = Opcode - DW_OP_reg0;
367 if ((Opcode >= DW_OP_breg0 && Opcode <= DW_OP_breg31) ||
368 Opcode == DW_OP_bregx || SubOpcode == DW_OP_LLVM_aspace_bregx)
369 OS <<
' ' <<
RegName <<
formatv(
"{0:+d}", int64_t(Operands[OpNum]));
373 if (Opcode == DW_OP_regval_type)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the SmallString class.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
This class represents an Operation in the Expression.
@ SizeSubOpLEB
The operand is a ULEB128 encoded SubOpcode.
@ SizeBlock
Preceding operand contains block size.
An iterator to go through the expression operations.
StringRef getData() const
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
This class implements an extremely fast bulk output stream that can only output to a stream.
A raw_ostream that writes to an SmallVector or SmallString.
LLVM_ABI StringRef SubOperationEncodingString(unsigned OpEncoding, unsigned SubOpEncoding)
LLVM_ABI StringRef OperationEncodingString(unsigned Encoding)
Calculates the starting offsets for various sections within the .debug_names section.
std::optional< const char * > toString(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract a string value from it.
This is an optimization pass for GlobalISel generic memory operations.
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
static bool printOp(const DWARFExpression::Operation *Op, raw_ostream &OS, DIDumpOptions DumpOpts, const DWARFExpression *Expr, DWARFUnit *U)
LLVM_ABI void printDwarfExpression(const DWARFExpression *E, raw_ostream &OS, DIDumpOptions DumpOpts, DWARFUnit *U, bool IsEH=false)
Print a Dwarf expression/.
static bool printCompactDWARFExpr(raw_ostream &OS, DWARFExpression::iterator I, const DWARFExpression::iterator E, std::function< StringRef(uint64_t RegNum, bool IsEH)> GetNameForDWARFReg=nullptr)
static void prettyPrintBaseTypeRef(DWARFUnit *U, raw_ostream &OS, DIDumpOptions DumpOpts, ArrayRef< uint64_t > Operands, unsigned Operand)
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
DWARFExpression::Operation Op
LLVM_ABI bool prettyPrintRegisterOp(DWARFUnit *U, raw_ostream &OS, DIDumpOptions DumpOpts, uint8_t Opcode, ArrayRef< uint64_t > Operands)
Pretty print a register opcode and operands.
LLVM_ABI bool printDwarfExpressionCompact(const DWARFExpression *E, raw_ostream &OS, std::function< StringRef(uint64_t RegNum, bool IsEH)> GetNameForDWARFReg=nullptr)
Print the expression in a format intended to be compact and useful to a user, but not perfectly unamb...
Container for dump options that control which debug information will be dumped.
std::function< llvm::StringRef(uint64_t DwarfRegNum, bool IsEH)> GetNameForDWARFReg
Description of the encoding of one expression Op.
PrintedExpr(ExprKind K=Address)