38 uint64_t DwarfRegNumBE =
40 const char *
Data =
reinterpret_cast<const char *
>(&DwarfRegNumBE);
41 const char *Begin = std::find_if(
Data,
Data +
sizeof(DwarfRegNumBE),
42 [](
char c) {
return c !=
'\0'; });
51 for (
size_t I = 1;
I < Tmp.size(); ++
I)
64 uint64_t DwarfRegNum,
bool IsEH,
65 const std::function<
StringRef(uint64_t,
bool)> &GetNameForDWARFReg) {
66 if (GetNameForDWARFReg) {
67 StringRef R = GetNameForDWARFReg(DwarfRegNum, IsEH);
73 return Decoded.
str().
str();
82 OS <<
"<decoding error>";
86 std::optional<unsigned> SubOpcode =
Op->getSubCode();
95 if ((
Op->getCode() >= DW_OP_breg0 &&
Op->getCode() <= DW_OP_breg31) ||
96 (
Op->getCode() >= DW_OP_reg0 &&
Op->getCode() <= DW_OP_reg31) ||
97 Op->getCode() == DW_OP_bregx ||
Op->getCode() == DW_OP_regx ||
98 Op->getCode() == DW_OP_regval_type ||
99 SubOpcode == DW_OP_LLVM_call_frame_entry_reg ||
100 SubOpcode == DW_OP_LLVM_aspace_bregx) {
102 Op->getCode(),
Op->getRawOperands()))
108 if (
Op->getCode() == DW_OP_constu) {
109 OS << (uint64_t)
Op->getRawOperand(0);
112 if (
Op->getCode() == DW_OP_consts) {
113 OS << (int64_t)
Op->getRawOperand(0);
116 if (
Op->getCode() >= DW_OP_lit0 &&
Op->getCode() <= DW_OP_lit31) {
120 if (
Op->getCode() == DW_OP_stack_value)
128 assert(!Name.empty() &&
"DW_OP has no name!");
133 assert(!SubName.
empty() &&
"DW_OP SubOp has no name!");
134 OS <<
' ' << SubName;
138 if ((
Op->getCode() >= DW_OP_breg0 &&
Op->getCode() <= DW_OP_breg31) ||
139 (
Op->getCode() >= DW_OP_reg0 &&
Op->getCode() <= DW_OP_reg31) ||
140 Op->getCode() == DW_OP_bregx ||
Op->getCode() == DW_OP_regx ||
141 Op->getCode() == DW_OP_regval_type ||
142 SubOpcode == DW_OP_LLVM_call_frame_entry_reg ||
143 SubOpcode == DW_OP_LLVM_aspace_bregx)
145 Op->getCode(),
Op->getRawOperands()))
149 for (
unsigned Operand = 0; Operand <
Op->getDescription().
Op.size();
151 unsigned Size =
Op->getDescription().Op[Operand];
155 assert(Operand == 0 &&
"DW_OP SubOp must be the first operand");
156 assert(SubOpcode &&
"DW_OP SubOp description is inconsistent");
162 if (
Op->getCode() == DW_OP_convert &&
Op->getRawOperand(Operand) == 0)
165 PrintBaseTypeRef(OS, DumpOpts,
Op->getRawOperands(), Operand);
168 switch (
Op->getRawOperand(0)) {
174 OS <<
formatv(
" {0:x}",
Op->getRawOperand(Operand));
180 uint64_t
Offset =
Op->getRawOperand(Operand);
181 for (
unsigned i = 0; i <
Op->getRawOperand(Operand - 1); ++i)
186 OS <<
formatv(
" {0:+d}", (int64_t)
Op->getRawOperand(Operand));
187 else if (
Op->getCode() != DW_OP_entry_value &&
188 Op->getCode() != DW_OP_GNU_entry_value)
189 OS <<
formatv(
" {0:x}",
Op->getRawOperand(Operand));
201 uint64_t EntryValStartOffset = 0;
202 if (E->getData().empty())
205 for (
auto &
Op : *E) {
206 DumpOpts.
IsEH = IsEH;
207 if (!
printOp(&
Op, OS, DumpOpts, E, PrintBaseTypeRef) &&
209 uint64_t FailOffset =
Op.getEndOffset();
210 while (FailOffset < E->getData().
size())
212 static_cast<uint8_t>(E->getData()[FailOffset++]));
216 if (
Op.getCode() == DW_OP_entry_value ||
217 Op.getCode() == DW_OP_GNU_entry_value) {
219 EntryValExprSize =
Op.getRawOperand(0);
220 EntryValStartOffset =
Op.getEndOffset();
224 if (EntryValExprSize) {
225 EntryValExprSize -=
Op.getEndOffset() - EntryValStartOffset;
226 if (EntryValExprSize == 0)
230 if (
Op.getEndOffset() < E->getData().size())
253 std::function<
StringRef(uint64_t RegNum,
bool IsEH)> GetNameForDWARFReg =
258 std::optional<unsigned> SubOpcode) ->
bool {
265 <<
" (" << *SubOpcode;
273 auto UnknownRegister = [](
raw_ostream &OS, uint64_t DwarfRegNum) ->
bool {
274 OS <<
"<unknown register " << DwarfRegNum <<
">";
282 case dwarf::DW_OP_regx: {
285 const uint64_t DwarfRegNum =
Op.getRawOperand(0);
289 return UnknownRegister(OS, DwarfRegNum);
294 case dwarf::DW_OP_bregx: {
295 const uint64_t DwarfRegNum =
Op.getRawOperand(0);
296 const uint64_t
Offset =
Op.getRawOperand(1);
300 return UnknownRegister(OS, DwarfRegNum);
307 case dwarf::DW_OP_entry_value:
308 case dwarf::DW_OP_GNU_entry_value: {
311 uint64_t SubExprLength =
Op.getRawOperand(0);
320 GetNameForDWARFReg)) {
321 OS << SubExprOS.
str();
326 S <<
"entry(" << SubExprOS.
str() <<
")";
330 case dwarf::DW_OP_stack_value: {
337 case dwarf::DW_OP_nop: {
340 case dwarf::DW_OP_LLVM_user: {
341 std::optional<unsigned> SubOpcode =
Op.getSubCode();
342 if (SubOpcode == dwarf::DW_OP_LLVM_nop)
344 return UnknownOpcode(OS, Opcode, SubOpcode);
347 if (Opcode >= dwarf::DW_OP_reg0 && Opcode <= dwarf::DW_OP_reg31) {
350 uint64_t DwarfRegNum = Opcode - dwarf::DW_OP_reg0;
354 return UnknownRegister(OS, DwarfRegNum);
357 }
else if (Opcode >= dwarf::DW_OP_breg0 &&
358 Opcode <= dwarf::DW_OP_breg31) {
359 int DwarfRegNum = Opcode - dwarf::DW_OP_breg0;
360 int64_t
Offset =
Op.getRawOperand(0);
364 return UnknownRegister(OS, DwarfRegNum);
370 return UnknownOpcode(OS, Opcode, std::nullopt);
377 if (Stack.size() != 1) {
378 OS <<
"<stack of size " << Stack.size() <<
", expected 1>";
383 OS <<
"[" << Stack.front().String <<
"]";
385 OS << Stack.front().String;
397 std::function<
StringRef(uint64_t RegNum,
bool IsEH)> GetNameForDWARFReg) {
405 uint64_t DwarfRegNum;
408 std::optional<unsigned> SubOpcode;
409 if (Opcode == DW_OP_LLVM_user)
412 const bool RegNumFromOperand =
413 Opcode == DW_OP_bregx || Opcode == DW_OP_regx ||
414 Opcode == DW_OP_regval_type || SubOpcode == DW_OP_LLVM_aspace_bregx ||
415 SubOpcode == DW_OP_LLVM_call_frame_entry_reg;
417 if (RegNumFromOperand)
419 else if (Opcode >= DW_OP_breg0 && Opcode < DW_OP_bregx)
420 DwarfRegNum = Opcode - DW_OP_breg0;
422 DwarfRegNum = Opcode - DW_OP_reg0;
428 if ((Opcode >= DW_OP_breg0 && Opcode <= DW_OP_breg31) ||
429 Opcode == DW_OP_bregx || SubOpcode == DW_OP_LLVM_aspace_bregx)
434 if (Opcode == DW_OP_regval_type) {
435 if (PrintBaseTypeRef)
436 PrintBaseTypeRef(OS, DumpOpts,
Operands, 1);
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)
bool prettyPrintRegisterOp(BaseTypeRefPrinter PrintBaseTypeRef, raw_ostream &OS, DIDumpOptions DumpOpts, uint8_t Opcode, ArrayRef< uint64_t > Operands)
function_ref< void(raw_ostream &OS, DIDumpOptions DumpOpts, ArrayRef< uint64_t > Operands, unsigned Operand)> BaseTypeRefPrinter
Prints the base type DIE that operand Operand of Operands refers to.
void printDwarfExpression(const DWARFExpression *E, raw_ostream &OS, DIDumpOptions DumpOpts, BaseTypeRefPrinter PrintBaseTypeRef, bool IsEH)
Calculates the starting offsets for various sections within the .debug_names section.
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.
LLVM_ABI void printDwarfExpression(const DWARFExpression *E, raw_ostream &OS, DIDumpOptions DumpOpts, bool IsEH=false)
Print a Dwarf expression.
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, detail::BaseTypeRefPrinter PrintBaseTypeRef)
static bool printCompactDWARFExpr(raw_ostream &OS, DWARFExpression::iterator I, const DWARFExpression::iterator E, std::function< StringRef(uint64_t RegNum, bool IsEH)> GetNameForDWARFReg=nullptr)
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 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
PrintedExpr(ExprKind K=Address)