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();
86 auto Die = U->getDIEForOffset(U->getOffset() +
Operands[Operand]);
87 if (Die && Die.getTag() == dwarf::DW_TAG_base_type) {
93 OS <<
" \"" << *Name <<
"\"";
104 OS <<
"<decoding error>";
108 std::optional<unsigned> SubOpcode =
Op->getSubCode();
117 if ((
Op->getCode() >= DW_OP_breg0 &&
Op->getCode() <= DW_OP_breg31) ||
118 (
Op->getCode() >= DW_OP_reg0 &&
Op->getCode() <= DW_OP_reg31) ||
119 Op->getCode() == DW_OP_bregx ||
Op->getCode() == DW_OP_regx ||
120 Op->getCode() == DW_OP_regval_type ||
121 SubOpcode == DW_OP_LLVM_call_frame_entry_reg ||
122 SubOpcode == DW_OP_LLVM_aspace_bregx) {
124 Op->getRawOperands()))
130 if (
Op->getCode() == DW_OP_constu) {
131 OS << (uint64_t)
Op->getRawOperand(0);
134 if (
Op->getCode() == DW_OP_consts) {
135 OS << (int64_t)
Op->getRawOperand(0);
138 if (
Op->getCode() >= DW_OP_lit0 &&
Op->getCode() <= DW_OP_lit31) {
142 if (
Op->getCode() == DW_OP_stack_value)
150 assert(!Name.empty() &&
"DW_OP has no name!");
155 assert(!SubName.
empty() &&
"DW_OP SubOp has no name!");
156 OS <<
' ' << SubName;
160 if ((
Op->getCode() >= DW_OP_breg0 &&
Op->getCode() <= DW_OP_breg31) ||
161 (
Op->getCode() >= DW_OP_reg0 &&
Op->getCode() <= DW_OP_reg31) ||
162 Op->getCode() == DW_OP_bregx ||
Op->getCode() == DW_OP_regx ||
163 Op->getCode() == DW_OP_regval_type ||
164 SubOpcode == DW_OP_LLVM_call_frame_entry_reg ||
165 SubOpcode == DW_OP_LLVM_aspace_bregx)
167 Op->getRawOperands()))
171 for (
unsigned Operand = 0; Operand <
Op->getDescription().
Op.size();
173 unsigned Size =
Op->getDescription().Op[Operand];
177 assert(Operand == 0 &&
"DW_OP SubOp must be the first operand");
178 assert(SubOpcode &&
"DW_OP SubOp description is inconsistent");
183 if (
Op->getCode() == DW_OP_convert &&
Op->getRawOperand(Operand) == 0)
190 switch (
Op->getRawOperand(0)) {
196 OS <<
formatv(
" {0:x}",
Op->getRawOperand(Operand));
202 uint64_t
Offset =
Op->getRawOperand(Operand);
203 for (
unsigned i = 0; i <
Op->getRawOperand(Operand - 1); ++i)
208 OS <<
formatv(
" {0:+d}", (int64_t)
Op->getRawOperand(Operand));
209 else if (
Op->getCode() != DW_OP_entry_value &&
210 Op->getCode() != DW_OP_GNU_entry_value)
211 OS <<
formatv(
" {0:x}",
Op->getRawOperand(Operand));
221 uint64_t EntryValStartOffset = 0;
222 if (E->getData().empty())
225 for (
auto &
Op : *E) {
226 DumpOpts.
IsEH = IsEH;
228 uint64_t FailOffset =
Op.getEndOffset();
229 while (FailOffset < E->getData().
size())
231 static_cast<uint8_t>(E->getData()[FailOffset++]));
235 if (
Op.getCode() == DW_OP_entry_value ||
236 Op.getCode() == DW_OP_GNU_entry_value) {
238 EntryValExprSize =
Op.getRawOperand(0);
239 EntryValStartOffset =
Op.getEndOffset();
243 if (EntryValExprSize) {
244 EntryValExprSize -=
Op.getEndOffset() - EntryValStartOffset;
245 if (EntryValExprSize == 0)
249 if (
Op.getEndOffset() < E->getData().size())
272 std::function<
StringRef(uint64_t RegNum,
bool IsEH)> GetNameForDWARFReg =
277 std::optional<unsigned> SubOpcode) ->
bool {
284 <<
" (" << *SubOpcode;
292 auto UnknownRegister = [](
raw_ostream &OS, uint64_t DwarfRegNum) ->
bool {
293 OS <<
"<unknown register " << DwarfRegNum <<
">";
301 case dwarf::DW_OP_regx: {
304 const uint64_t DwarfRegNum =
Op.getRawOperand(0);
308 return UnknownRegister(OS, DwarfRegNum);
313 case dwarf::DW_OP_bregx: {
314 const uint64_t DwarfRegNum =
Op.getRawOperand(0);
315 const uint64_t
Offset =
Op.getRawOperand(1);
319 return UnknownRegister(OS, DwarfRegNum);
326 case dwarf::DW_OP_entry_value:
327 case dwarf::DW_OP_GNU_entry_value: {
330 uint64_t SubExprLength =
Op.getRawOperand(0);
339 GetNameForDWARFReg)) {
340 OS << SubExprOS.
str();
345 S <<
"entry(" << SubExprOS.
str() <<
")";
349 case dwarf::DW_OP_stack_value: {
356 case dwarf::DW_OP_nop: {
359 case dwarf::DW_OP_LLVM_user: {
360 std::optional<unsigned> SubOpcode =
Op.getSubCode();
361 if (SubOpcode == dwarf::DW_OP_LLVM_nop)
363 return UnknownOpcode(OS, Opcode, SubOpcode);
366 if (Opcode >= dwarf::DW_OP_reg0 && Opcode <= dwarf::DW_OP_reg31) {
369 uint64_t DwarfRegNum = Opcode - dwarf::DW_OP_reg0;
373 return UnknownRegister(OS, DwarfRegNum);
376 }
else if (Opcode >= dwarf::DW_OP_breg0 &&
377 Opcode <= dwarf::DW_OP_breg31) {
378 int DwarfRegNum = Opcode - dwarf::DW_OP_breg0;
379 int64_t
Offset =
Op.getRawOperand(0);
383 return UnknownRegister(OS, DwarfRegNum);
389 return UnknownOpcode(OS, Opcode, std::nullopt);
396 if (Stack.size() != 1) {
397 OS <<
"<stack of size " << Stack.size() <<
", expected 1>";
402 OS <<
"[" << Stack.front().String <<
"]";
404 OS << Stack.front().String;
411 std::function<
StringRef(uint64_t RegNum,
bool IsEH)> GetNameForDWARFReg) {
418 uint64_t DwarfRegNum;
421 std::optional<unsigned> SubOpcode;
422 if (Opcode == DW_OP_LLVM_user)
425 const bool RegNumFromOperand =
426 Opcode == DW_OP_bregx || Opcode == DW_OP_regx ||
427 Opcode == DW_OP_regval_type || SubOpcode == DW_OP_LLVM_aspace_bregx ||
428 SubOpcode == DW_OP_LLVM_call_frame_entry_reg;
430 if (RegNumFromOperand)
432 else if (Opcode >= DW_OP_breg0 && Opcode < DW_OP_bregx)
433 DwarfRegNum = Opcode - DW_OP_breg0;
435 DwarfRegNum = Opcode - DW_OP_reg0;
441 if ((Opcode >= DW_OP_breg0 && Opcode <= DW_OP_breg31) ||
442 Opcode == DW_OP_bregx || SubOpcode == DW_OP_LLVM_aspace_bregx)
447 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)