41 const char *
Data =
reinterpret_cast<const char *
>(&DwarfRegNumBE);
42 const char *Begin = std::find_if(
Data,
Data +
sizeof(DwarfRegNumBE),
43 [](
char c) {
return c !=
'\0'; });
52 for (
size_t I = 1;
I < Tmp.size(); ++
I)
67 if (GetNameForDWARFReg) {
68 StringRef R = GetNameForDWARFReg(DwarfRegNum, IsEH);
74 return Decoded.
str().
str();
87 auto Die = U->getDIEForOffset(U->getOffset() +
Operands[Operand]);
88 if (Die && Die.getTag() == dwarf::DW_TAG_base_type) {
94 OS <<
" \"" << *Name <<
"\"";
105 OS <<
"<decoding error>";
109 std::optional<unsigned> SubOpcode =
Op->getSubCode();
118 if ((
Op->getCode() >= DW_OP_breg0 &&
Op->getCode() <= DW_OP_breg31) ||
119 (
Op->getCode() >= DW_OP_reg0 &&
Op->getCode() <= DW_OP_reg31) ||
120 Op->getCode() == DW_OP_bregx ||
Op->getCode() == DW_OP_regx ||
121 Op->getCode() == DW_OP_regval_type ||
122 SubOpcode == DW_OP_LLVM_call_frame_entry_reg ||
123 SubOpcode == DW_OP_LLVM_aspace_bregx) {
125 Op->getRawOperands()))
131 if (
Op->getCode() == DW_OP_constu) {
135 if (
Op->getCode() == DW_OP_consts) {
136 OS << (int64_t)
Op->getRawOperand(0);
139 if (
Op->getCode() >= DW_OP_lit0 &&
Op->getCode() <= DW_OP_lit31) {
143 if (
Op->getCode() == DW_OP_stack_value)
151 assert(!Name.empty() &&
"DW_OP has no name!");
156 assert(!SubName.
empty() &&
"DW_OP SubOp has no name!");
157 OS <<
' ' << SubName;
161 if ((
Op->getCode() >= DW_OP_breg0 &&
Op->getCode() <= DW_OP_breg31) ||
162 (
Op->getCode() >= DW_OP_reg0 &&
Op->getCode() <= DW_OP_reg31) ||
163 Op->getCode() == DW_OP_bregx ||
Op->getCode() == DW_OP_regx ||
164 Op->getCode() == DW_OP_regval_type ||
165 SubOpcode == DW_OP_LLVM_call_frame_entry_reg ||
166 SubOpcode == DW_OP_LLVM_aspace_bregx)
168 Op->getRawOperands()))
172 for (
unsigned Operand = 0; Operand <
Op->getDescription().
Op.size();
174 unsigned Size =
Op->getDescription().Op[Operand];
178 assert(Operand == 0 &&
"DW_OP SubOp must be the first operand");
179 assert(SubOpcode &&
"DW_OP SubOp description is inconsistent");
184 if (
Op->getCode() == DW_OP_convert &&
Op->getRawOperand(Operand) == 0)
191 switch (
Op->getRawOperand(0)) {
197 OS <<
formatv(
" {0:x}",
Op->getRawOperand(Operand));
204 for (
unsigned i = 0; i <
Op->getRawOperand(Operand - 1); ++i)
209 OS <<
formatv(
" {0:+d}", (int64_t)
Op->getRawOperand(Operand));
210 else if (
Op->getCode() != DW_OP_entry_value &&
211 Op->getCode() != DW_OP_GNU_entry_value)
212 OS <<
formatv(
" {0:x}",
Op->getRawOperand(Operand));
223 if (E->getData().empty())
226 for (
auto &
Op : *E) {
227 DumpOpts.
IsEH = IsEH;
230 while (FailOffset < E->getData().
size())
232 static_cast<uint8_t>(E->getData()[FailOffset++]));
236 if (
Op.getCode() == DW_OP_entry_value ||
237 Op.getCode() == DW_OP_GNU_entry_value) {
239 EntryValExprSize =
Op.getRawOperand(0);
240 EntryValStartOffset =
Op.getEndOffset();
244 if (EntryValExprSize) {
245 EntryValExprSize -=
Op.getEndOffset() - EntryValStartOffset;
246 if (EntryValExprSize == 0)
250 if (
Op.getEndOffset() < E->getData().size())
278 std::optional<unsigned> SubOpcode) ->
bool {
285 <<
" (" << *SubOpcode;
294 OS <<
"<unknown register " << DwarfRegNum <<
">";
302 case dwarf::DW_OP_regx: {
305 const uint64_t DwarfRegNum =
Op.getRawOperand(0);
309 return UnknownRegister(OS, DwarfRegNum);
314 case dwarf::DW_OP_bregx: {
315 const uint64_t DwarfRegNum =
Op.getRawOperand(0);
320 return UnknownRegister(OS, DwarfRegNum);
327 case dwarf::DW_OP_entry_value:
328 case dwarf::DW_OP_GNU_entry_value: {
340 GetNameForDWARFReg)) {
341 OS << SubExprOS.
str();
346 S <<
"entry(" << SubExprOS.
str() <<
")";
350 case dwarf::DW_OP_stack_value: {
357 case dwarf::DW_OP_nop: {
360 case dwarf::DW_OP_LLVM_user: {
361 std::optional<unsigned> SubOpcode =
Op.getSubCode();
362 if (SubOpcode == dwarf::DW_OP_LLVM_nop)
364 return UnknownOpcode(OS, Opcode, SubOpcode);
367 if (Opcode >= dwarf::DW_OP_reg0 && Opcode <= dwarf::DW_OP_reg31) {
370 uint64_t DwarfRegNum = Opcode - dwarf::DW_OP_reg0;
374 return UnknownRegister(OS, DwarfRegNum);
377 }
else if (Opcode >= dwarf::DW_OP_breg0 &&
378 Opcode <= dwarf::DW_OP_breg31) {
379 int DwarfRegNum = Opcode - dwarf::DW_OP_breg0;
380 int64_t
Offset =
Op.getRawOperand(0);
384 return UnknownRegister(OS, DwarfRegNum);
390 return UnknownOpcode(OS, Opcode, std::nullopt);
397 if (Stack.size() != 1) {
398 OS <<
"<stack of size " << Stack.size() <<
", expected 1>";
403 OS <<
"[" << Stack.front().String <<
"]";
405 OS << Stack.front().String;
422 std::optional<unsigned> SubOpcode;
423 if (Opcode == DW_OP_LLVM_user)
426 const bool RegNumFromOperand =
427 Opcode == DW_OP_bregx || Opcode == DW_OP_regx ||
428 Opcode == DW_OP_regval_type || SubOpcode == DW_OP_LLVM_aspace_bregx ||
429 SubOpcode == DW_OP_LLVM_call_frame_entry_reg;
431 if (RegNumFromOperand)
433 else if (Opcode >= DW_OP_breg0 && Opcode < DW_OP_bregx)
434 DwarfRegNum = Opcode - DW_OP_breg0;
436 DwarfRegNum = Opcode - DW_OP_reg0;
442 if ((Opcode >= DW_OP_breg0 && Opcode <= DW_OP_breg31) ||
443 Opcode == DW_OP_bregx || SubOpcode == DW_OP_LLVM_aspace_bregx)
448 if (Opcode == DW_OP_regval_type)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the SmallString class.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
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...
StringRef str() const
Explicit conversion to StringRef.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
std::string str() const
Get the contents as an std::string.
constexpr bool empty() const
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.
StringRef str() const
Return a StringRef for the vector contents.
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.
value_type byte_swap(value_type value, endianness endian)
Swap the bytes of value to match the given endianness.
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)
static bool decodeVirtualRegisterName(uint64_t DwarfRegNum, SmallString< 8 > &Out)
Some backends (e.g.
bool isAlnum(char C)
Checks whether character C is either a decimal digit or an uppercase or lowercase letter as classifie...
static std::string resolveRegName(uint64_t DwarfRegNum, bool IsEH, const std::function< StringRef(uint64_t, bool)> &GetNameForDWARFReg)
Resolves a DWARF register number to a display name: first via GetNameForDWARFReg (MC register names),...
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)