LLVM: lib/DebugInfo/DWARF/DWARFExpressionPrinter.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

14#include

15#include

16

17using namespace llvm;

18using namespace dwarf;

19

20namespace llvm {

21

24

28 unsigned Operand) {

29 assert(Operand < Operands.size() && "operand out of bounds");

30 if (!U) {

31 OS << format(" <base_type ref: 0x%" PRIx64 ">", Operands[Operand]);

32 return;

33 }

34 auto Die = U->getDIEForOffset(U->getOffset() + Operands[Operand]);

35 if (Die && Die.getTag() == dwarf::DW_TAG_base_type) {

36 OS << " (";

38 OS << format("0x%08" PRIx64 " -> ", Operands[Operand]);

39 OS << format("0x%08" PRIx64 ")", U->getOffset() + Operands[Operand]);

40 if (auto Name = dwarf::toString(Die.find(dwarf::DW_AT_name)))

41 OS << " \"" << *Name << "\"";

42 } else {

43 OS << format(" <invalid base_type ref: 0x%" PRIx64 ">", Operands[Operand]);

44 }

45}

46

50 if (Op->isError()) {

52 OS << "";

53 return false;

54 }

55

56 std::optional SubOpcode = Op->getSubCode();

57

58

59

60

61

63

64

65 if ((Op->getCode() >= DW_OP_breg0 && Op->getCode() <= DW_OP_breg31) ||

66 (Op->getCode() >= DW_OP_reg0 && Op->getCode() <= DW_OP_reg31) ||

67 Op->getCode() == DW_OP_bregx || Op->getCode() == DW_OP_regx ||

68 Op->getCode() == DW_OP_regval_type ||

69 SubOpcode == DW_OP_LLVM_call_frame_entry_reg ||

70 SubOpcode == DW_OP_LLVM_aspace_bregx) {

72 Op->getRawOperands()))

73 return true;

74

75 }

76

77

78 if (Op->getCode() == DW_OP_constu) {

80 return true;

81 }

82 if (Op->getCode() == DW_OP_consts) {

83 OS << (int64_t)Op->getRawOperand(0);

84 return true;

85 }

86 if (Op->getCode() >= DW_OP_lit0 && Op->getCode() <= DW_OP_lit31) {

87 OS << (unsigned)(Op->getCode() - DW_OP_lit0);

88 return true;

89 }

90 if (Op->getCode() == DW_OP_stack_value)

91 return true;

92

93 return true;

94 }

95

98 assert(!Name.empty() && "DW_OP has no name!");

99 OS << Name;

100

101 if (SubOpcode) {

103 assert(!SubName.empty() && "DW_OP SubOp has no name!");

104 OS << ' ' << SubName;

105 }

106 }

107

108 if ((Op->getCode() >= DW_OP_breg0 && Op->getCode() <= DW_OP_breg31) ||

109 (Op->getCode() >= DW_OP_reg0 && Op->getCode() <= DW_OP_reg31) ||

110 Op->getCode() == DW_OP_bregx || Op->getCode() == DW_OP_regx ||

111 Op->getCode() == DW_OP_regval_type ||

112 SubOpcode == DW_OP_LLVM_call_frame_entry_reg ||

113 SubOpcode == DW_OP_LLVM_aspace_bregx)

115 Op->getRawOperands()))

116 return true;

117

119 for (unsigned Operand = 0; Operand < Op->getDescription().Op.size();

120 ++Operand) {

121 unsigned Size = Op->getDescription().Op[Operand];

123

125 assert(Operand == 0 && "DW_OP SubOp must be the first operand");

126 assert(SubOpcode && "DW_OP SubOp description is inconsistent");

128

129

130

131 if (Op->getCode() == DW_OP_convert && Op->getRawOperand(Operand) == 0)

132 OS << " 0x0";

133 else

135 Operand);

137 assert(Operand == 1);

138 switch (Op->getRawOperand(0)) {

139 case 0:

140 case 1:

141 case 2:

142 case 3:

143 case 4:

144 OS << format(" 0x%" PRIx64, Op->getRawOperand(Operand));

145 break;

146 default:

148 }

151 for (unsigned i = 0; i < Op->getRawOperand(Operand - 1); ++i)

152 OS << format(" 0x%02x",

154 } else {

156 OS << format(" %+" PRId64, (int64_t)Op->getRawOperand(Operand));

157 else if (Op->getCode() != DW_OP_entry_value &&

158 Op->getCode() != DW_OP_GNU_entry_value)

159 OS << format(" 0x%" PRIx64, Op->getRawOperand(Operand));

160 }

161 }

162 }

163 return true;

164}

165

168 uint32_t EntryValExprSize = 0;

169 uint64_t EntryValStartOffset = 0;

170 if (E->getData().empty())

171 OS << "";

172

173 for (auto &Op : *E) {

174 DumpOpts.IsEH = IsEH;

176 uint64_t FailOffset = Op.getEndOffset();

177 while (FailOffset < E->getData().size())

178 OS << format(" %02x", static_cast<uint8_t>(E->getData()[FailOffset++]));

179 return;

180 }

182 if (Op.getCode() == DW_OP_entry_value ||

183 Op.getCode() == DW_OP_GNU_entry_value) {

184 OS << "(";

185 EntryValExprSize = Op.getRawOperand(0);

186 EntryValStartOffset = Op.getEndOffset();

187 continue;

188 }

189

190 if (EntryValExprSize) {

191 EntryValExprSize -= Op.getEndOffset() - EntryValStartOffset;

192 if (EntryValExprSize == 0)

193 OS << ")";

194 }

195

196 if (Op.getEndOffset() < E->getData().size())

197 OS << ", ";

198 }

199 }

200}

201

202

203

204

215

219 std::function<StringRef(uint64_t RegNum, bool IsEH)> GetNameForDWARFReg =

220 nullptr) {

222

224 std::optional SubOpcode) -> bool {

225

226

228 << (int)Opcode;

229 if (SubOpcode)

231 << " (" << *SubOpcode;

232 OS << ")>";

233 return false;

234 };

235

236 while (I != E) {

239 switch (Opcode) {

240 case dwarf::DW_OP_regx: {

241

242

243 uint64_t DwarfRegNum = Op.getRawOperand(0);

244 auto RegName = GetNameForDWARFReg(DwarfRegNum, false);

246 return false;

249 break;

250 }

251 case dwarf::DW_OP_bregx: {

252 int DwarfRegNum = Op.getRawOperand(0);

253 int64_t Offset = Op.getRawOperand(1);

254 auto RegName = GetNameForDWARFReg(DwarfRegNum, false);

256 return false;

261 break;

262 }

263 case dwarf::DW_OP_entry_value:

264 case dwarf::DW_OP_GNU_entry_value: {

265

266

267 uint64_t SubExprLength = Op.getRawOperand(0);

269 ++I;

271 S << "entry(";

273 S << ")";

274 I = SubExprEnd;

275 continue;

276 }

277 case dwarf::DW_OP_stack_value: {

278

279

280 assert(!Stack.empty());

282 break;

283 }

284 case dwarf::DW_OP_nop: {

285 break;

286 }

287 case dwarf::DW_OP_LLVM_user: {

288 std::optional SubOpcode = Op.getSubCode();

289 if (SubOpcode == dwarf::DW_OP_LLVM_nop)

290 break;

291 return UnknownOpcode(OS, Opcode, SubOpcode);

292 }

293 default:

294 if (Opcode >= dwarf::DW_OP_reg0 && Opcode <= dwarf::DW_OP_reg31) {

295

296

297 uint64_t DwarfRegNum = Opcode - dwarf::DW_OP_reg0;

298 auto RegName = GetNameForDWARFReg(DwarfRegNum, false);

300 return false;

303 } else if (Opcode >= dwarf::DW_OP_breg0 &&

304 Opcode <= dwarf::DW_OP_breg31) {

305 int DwarfRegNum = Opcode - dwarf::DW_OP_breg0;

306 int64_t Offset = Op.getRawOperand(0);

307 auto RegName = GetNameForDWARFReg(DwarfRegNum, false);

309 return false;

314 } else {

315 return UnknownOpcode(OS, Opcode, std::nullopt);

316 }

317 break;

318 }

319 ++I;

320 }

321

322 if (Stack.size() != 1) {

323 OS << "<stack of size " << Stack.size() << ", expected 1>";

324 return false;

325 }

326

328 OS << "[" << Stack.front().String << "]";

329 else

330 OS << Stack.front().String;

331

332 return true;

333}

334

340

345 return false;

346

348 unsigned OpNum = 0;

349

350 std::optional SubOpcode;

351 if (Opcode == DW_OP_LLVM_user)

352 SubOpcode = Operands[OpNum++];

353

354 if (Opcode == DW_OP_bregx || Opcode == DW_OP_regx ||

355 Opcode == DW_OP_regval_type || SubOpcode == DW_OP_LLVM_aspace_bregx ||

356 SubOpcode == DW_OP_LLVM_call_frame_entry_reg)

357 DwarfRegNum = Operands[OpNum++];

358 else if (Opcode >= DW_OP_breg0 && Opcode < DW_OP_bregx)

359 DwarfRegNum = Opcode - DW_OP_breg0;

360 else

361 DwarfRegNum = Opcode - DW_OP_reg0;

362

365 if ((Opcode >= DW_OP_breg0 && Opcode <= DW_OP_breg31) ||

366 Opcode == DW_OP_bregx || SubOpcode == DW_OP_LLVM_aspace_bregx)

367 OS << ' ' << RegName << format("%+" PRId64, Operands[OpNum]);

368 else

369 OS << ' ' << RegName.data();

370

371 if (Opcode == DW_OP_regval_type)

373 return true;

374 }

375

376 return false;

377}

378

379}

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)

Definition DWARFExpressionPrinter.cpp:47

LLVM_ABI void printDwarfExpression(const DWARFExpression *E, raw_ostream &OS, DIDumpOptions DumpOpts, DWARFUnit *U, bool IsEH=false)

Print a Dwarf expression/.

Definition DWARFExpressionPrinter.cpp:166

Op::Description Desc

Definition DWARFExpressionPrinter.cpp:23

static bool printCompactDWARFExpr(raw_ostream &OS, DWARFExpression::iterator I, const DWARFExpression::iterator E, std::function< StringRef(uint64_t RegNum, bool IsEH)> GetNameForDWARFReg=nullptr)

Definition DWARFExpressionPrinter.cpp:216

static void prettyPrintBaseTypeRef(DWARFUnit *U, raw_ostream &OS, DIDumpOptions DumpOpts, ArrayRef< uint64_t > Operands, unsigned Operand)

Definition DWARFExpressionPrinter.cpp:25

format_object< Ts... > format(const char *Fmt, const Ts &... Vals)

These are helper functions used to produce formatted output.

DWARFExpression::Operation Op

Definition DWARFExpressionPrinter.cpp:22

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.

Definition DWARFExpressionPrinter.cpp:341

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...

Definition DWARFExpressionPrinter.cpp:335

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.

ExprKind

Definition DWARFExpressionPrinter.cpp:206

@ Address

Definition DWARFExpressionPrinter.cpp:207

@ Value

Definition DWARFExpressionPrinter.cpp:208

PrintedExpr(ExprKind K=Address)

Definition DWARFExpressionPrinter.cpp:213

ExprKind Kind

Definition DWARFExpressionPrinter.cpp:210

SmallString< 16 > String

Definition DWARFExpressionPrinter.cpp:211