DWARFExpression.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  1. //===-- DWARFExpression.cpp -----------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #include "llvm/DebugInfo/DWARF/DWARFExpression.h"
  9. #include "llvm/DebugInfo/DWARF/DWARFUnit.h"
  10. #include "llvm/Support/Format.h"
  11. #include <cassert>
  12. #include <cstdint>
  13. #include <vector>
  14. using namespace llvm;
  15. using namespace dwarf;
  16. namespace llvm {
  17. typedef std::vector<DWARFExpression::Operation::Description> DescVector;
  18. static DescVector getDescriptions() {
  19. DescVector Descriptions;
  20. typedef DWARFExpression::Operation Op;
  21. typedef Op::Description Desc;
  22. Descriptions.resize(0xff);
  23. Descriptions[DW_OP_addr] = Desc(Op::Dwarf2, Op::SizeAddr);
  24. Descriptions[DW_OP_deref] = Desc(Op::Dwarf2);
  25. Descriptions[DW_OP_const1u] = Desc(Op::Dwarf2, Op::Size1);
  26. Descriptions[DW_OP_const1s] = Desc(Op::Dwarf2, Op::SignedSize1);
  27. Descriptions[DW_OP_const2u] = Desc(Op::Dwarf2, Op::Size2);
  28. Descriptions[DW_OP_const2s] = Desc(Op::Dwarf2, Op::SignedSize2);
  29. Descriptions[DW_OP_const4u] = Desc(Op::Dwarf2, Op::Size4);
  30. Descriptions[DW_OP_const4s] = Desc(Op::Dwarf2, Op::SignedSize4);
  31. Descriptions[DW_OP_const8u] = Desc(Op::Dwarf2, Op::Size8);
  32. Descriptions[DW_OP_const8s] = Desc(Op::Dwarf2, Op::SignedSize8);
  33. Descriptions[DW_OP_constu] = Desc(Op::Dwarf2, Op::SizeLEB);
  34. Descriptions[DW_OP_consts] = Desc(Op::Dwarf2, Op::SignedSizeLEB);
  35. Descriptions[DW_OP_dup] = Desc(Op::Dwarf2);
  36. Descriptions[DW_OP_drop] = Desc(Op::Dwarf2);
  37. Descriptions[DW_OP_over] = Desc(Op::Dwarf2);
  38. Descriptions[DW_OP_pick] = Desc(Op::Dwarf2, Op::Size1);
  39. Descriptions[DW_OP_swap] = Desc(Op::Dwarf2);
  40. Descriptions[DW_OP_rot] = Desc(Op::Dwarf2);
  41. Descriptions[DW_OP_xderef] = Desc(Op::Dwarf2);
  42. Descriptions[DW_OP_abs] = Desc(Op::Dwarf2);
  43. Descriptions[DW_OP_and] = Desc(Op::Dwarf2);
  44. Descriptions[DW_OP_div] = Desc(Op::Dwarf2);
  45. Descriptions[DW_OP_minus] = Desc(Op::Dwarf2);
  46. Descriptions[DW_OP_mod] = Desc(Op::Dwarf2);
  47. Descriptions[DW_OP_mul] = Desc(Op::Dwarf2);
  48. Descriptions[DW_OP_neg] = Desc(Op::Dwarf2);
  49. Descriptions[DW_OP_not] = Desc(Op::Dwarf2);
  50. Descriptions[DW_OP_or] = Desc(Op::Dwarf2);
  51. Descriptions[DW_OP_plus] = Desc(Op::Dwarf2);
  52. Descriptions[DW_OP_plus_uconst] = Desc(Op::Dwarf2, Op::SizeLEB);
  53. Descriptions[DW_OP_shl] = Desc(Op::Dwarf2);
  54. Descriptions[DW_OP_shr] = Desc(Op::Dwarf2);
  55. Descriptions[DW_OP_shra] = Desc(Op::Dwarf2);
  56. Descriptions[DW_OP_xor] = Desc(Op::Dwarf2);
  57. Descriptions[DW_OP_skip] = Desc(Op::Dwarf2, Op::SignedSize2);
  58. Descriptions[DW_OP_bra] = Desc(Op::Dwarf2, Op::SignedSize2);
  59. Descriptions[DW_OP_eq] = Desc(Op::Dwarf2);
  60. Descriptions[DW_OP_ge] = Desc(Op::Dwarf2);
  61. Descriptions[DW_OP_gt] = Desc(Op::Dwarf2);
  62. Descriptions[DW_OP_le] = Desc(Op::Dwarf2);
  63. Descriptions[DW_OP_lt] = Desc(Op::Dwarf2);
  64. Descriptions[DW_OP_ne] = Desc(Op::Dwarf2);
  65. for (uint16_t LA = DW_OP_lit0; LA <= DW_OP_lit31; ++LA)
  66. Descriptions[LA] = Desc(Op::Dwarf2);
  67. for (uint16_t LA = DW_OP_reg0; LA <= DW_OP_reg31; ++LA)
  68. Descriptions[LA] = Desc(Op::Dwarf2);
  69. for (uint16_t LA = DW_OP_breg0; LA <= DW_OP_breg31; ++LA)
  70. Descriptions[LA] = Desc(Op::Dwarf2, Op::SignedSizeLEB);
  71. Descriptions[DW_OP_regx] = Desc(Op::Dwarf2, Op::SizeLEB);
  72. Descriptions[DW_OP_fbreg] = Desc(Op::Dwarf2, Op::SignedSizeLEB);
  73. Descriptions[DW_OP_bregx] = Desc(Op::Dwarf2, Op::SizeLEB, Op::SignedSizeLEB);
  74. Descriptions[DW_OP_piece] = Desc(Op::Dwarf2, Op::SizeLEB);
  75. Descriptions[DW_OP_deref_size] = Desc(Op::Dwarf2, Op::Size1);
  76. Descriptions[DW_OP_xderef_size] = Desc(Op::Dwarf2, Op::Size1);
  77. Descriptions[DW_OP_nop] = Desc(Op::Dwarf2);
  78. Descriptions[DW_OP_push_object_address] = Desc(Op::Dwarf3);
  79. Descriptions[DW_OP_call2] = Desc(Op::Dwarf3, Op::Size2);
  80. Descriptions[DW_OP_call4] = Desc(Op::Dwarf3, Op::Size4);
  81. Descriptions[DW_OP_call_ref] = Desc(Op::Dwarf3, Op::SizeRefAddr);
  82. Descriptions[DW_OP_form_tls_address] = Desc(Op::Dwarf3);
  83. Descriptions[DW_OP_call_frame_cfa] = Desc(Op::Dwarf3);
  84. Descriptions[DW_OP_bit_piece] = Desc(Op::Dwarf3, Op::SizeLEB, Op::SizeLEB);
  85. Descriptions[DW_OP_implicit_value] =
  86. Desc(Op::Dwarf3, Op::SizeLEB, Op::SizeBlock);
  87. Descriptions[DW_OP_stack_value] = Desc(Op::Dwarf3);
  88. Descriptions[DW_OP_WASM_location] =
  89. Desc(Op::Dwarf4, Op::SizeLEB, Op::WasmLocationArg);
  90. Descriptions[DW_OP_GNU_push_tls_address] = Desc(Op::Dwarf3);
  91. Descriptions[DW_OP_addrx] = Desc(Op::Dwarf4, Op::SizeLEB);
  92. Descriptions[DW_OP_GNU_addr_index] = Desc(Op::Dwarf4, Op::SizeLEB);
  93. Descriptions[DW_OP_GNU_const_index] = Desc(Op::Dwarf4, Op::SizeLEB);
  94. Descriptions[DW_OP_GNU_entry_value] = Desc(Op::Dwarf4, Op::SizeLEB);
  95. Descriptions[DW_OP_convert] = Desc(Op::Dwarf5, Op::BaseTypeRef);
  96. Descriptions[DW_OP_entry_value] = Desc(Op::Dwarf5, Op::SizeLEB);
  97. Descriptions[DW_OP_regval_type] =
  98. Desc(Op::Dwarf5, Op::SizeLEB, Op::BaseTypeRef);
  99. return Descriptions;
  100. }
  101. static DWARFExpression::Operation::Description getOpDesc(unsigned OpCode) {
  102. // FIXME: Make this constexpr once all compilers are smart enough to do it.
  103. static DescVector Descriptions = getDescriptions();
  104. // Handle possible corrupted or unsupported operation.
  105. if (OpCode >= Descriptions.size())
  106. return {};
  107. return Descriptions[OpCode];
  108. }
  109. bool DWARFExpression::Operation::extract(DataExtractor Data,
  110. uint8_t AddressSize, uint64_t Offset,
  111. std::optional<DwarfFormat> Format) {
  112. EndOffset = Offset;
  113. Opcode = Data.getU8(&Offset);
  114. Desc = getOpDesc(Opcode);
  115. if (Desc.Version == Operation::DwarfNA)
  116. return false;
  117. for (unsigned Operand = 0; Operand < 2; ++Operand) {
  118. unsigned Size = Desc.Op[Operand];
  119. unsigned Signed = Size & Operation::SignBit;
  120. if (Size == Operation::SizeNA)
  121. break;
  122. switch (Size & ~Operation::SignBit) {
  123. case Operation::Size1:
  124. Operands[Operand] = Data.getU8(&Offset);
  125. if (Signed)
  126. Operands[Operand] = (int8_t)Operands[Operand];
  127. break;
  128. case Operation::Size2:
  129. Operands[Operand] = Data.getU16(&Offset);
  130. if (Signed)
  131. Operands[Operand] = (int16_t)Operands[Operand];
  132. break;
  133. case Operation::Size4:
  134. Operands[Operand] = Data.getU32(&Offset);
  135. if (Signed)
  136. Operands[Operand] = (int32_t)Operands[Operand];
  137. break;
  138. case Operation::Size8:
  139. Operands[Operand] = Data.getU64(&Offset);
  140. break;
  141. case Operation::SizeAddr:
  142. Operands[Operand] = Data.getUnsigned(&Offset, AddressSize);
  143. break;
  144. case Operation::SizeRefAddr:
  145. if (!Format)
  146. return false;
  147. Operands[Operand] =
  148. Data.getUnsigned(&Offset, dwarf::getDwarfOffsetByteSize(*Format));
  149. break;
  150. case Operation::SizeLEB:
  151. if (Signed)
  152. Operands[Operand] = Data.getSLEB128(&Offset);
  153. else
  154. Operands[Operand] = Data.getULEB128(&Offset);
  155. break;
  156. case Operation::BaseTypeRef:
  157. Operands[Operand] = Data.getULEB128(&Offset);
  158. break;
  159. case Operation::WasmLocationArg:
  160. assert(Operand == 1);
  161. switch (Operands[0]) {
  162. case 0:
  163. case 1:
  164. case 2:
  165. case 4:
  166. Operands[Operand] = Data.getULEB128(&Offset);
  167. break;
  168. case 3: // global as uint32
  169. Operands[Operand] = Data.getU32(&Offset);
  170. break;
  171. default:
  172. return false; // Unknown Wasm location
  173. }
  174. break;
  175. case Operation::SizeBlock:
  176. // We need a size, so this cannot be the first operand
  177. if (Operand == 0)
  178. return false;
  179. // Store the offset of the block as the value.
  180. Operands[Operand] = Offset;
  181. Offset += Operands[Operand - 1];
  182. break;
  183. default:
  184. llvm_unreachable("Unknown DWARFExpression Op size");
  185. }
  186. OperandEndOffsets[Operand] = Offset;
  187. }
  188. EndOffset = Offset;
  189. return true;
  190. }
  191. static void prettyPrintBaseTypeRef(DWARFUnit *U, raw_ostream &OS,
  192. DIDumpOptions DumpOpts,
  193. const uint64_t Operands[2],
  194. unsigned Operand) {
  195. assert(Operand < 2 && "operand out of bounds");
  196. auto Die = U->getDIEForOffset(U->getOffset() + Operands[Operand]);
  197. if (Die && Die.getTag() == dwarf::DW_TAG_base_type) {
  198. OS << " (";
  199. if (DumpOpts.Verbose)
  200. OS << format("0x%08" PRIx64 " -> ", Operands[Operand]);
  201. OS << format("0x%08" PRIx64 ")", U->getOffset() + Operands[Operand]);
  202. if (auto Name = dwarf::toString(Die.find(dwarf::DW_AT_name)))
  203. OS << " \"" << *Name << "\"";
  204. } else {
  205. OS << format(" <invalid base_type ref: 0x%" PRIx64 ">",
  206. Operands[Operand]);
  207. }
  208. }
  209. bool DWARFExpression::prettyPrintRegisterOp(DWARFUnit *U, raw_ostream &OS,
  210. DIDumpOptions DumpOpts,
  211. uint8_t Opcode,
  212. const uint64_t Operands[2]) {
  213. if (!DumpOpts.GetNameForDWARFReg)
  214. return false;
  215. uint64_t DwarfRegNum;
  216. unsigned OpNum = 0;
  217. if (Opcode == DW_OP_bregx || Opcode == DW_OP_regx ||
  218. Opcode == DW_OP_regval_type)
  219. DwarfRegNum = Operands[OpNum++];
  220. else if (Opcode >= DW_OP_breg0 && Opcode < DW_OP_bregx)
  221. DwarfRegNum = Opcode - DW_OP_breg0;
  222. else
  223. DwarfRegNum = Opcode - DW_OP_reg0;
  224. auto RegName = DumpOpts.GetNameForDWARFReg(DwarfRegNum, DumpOpts.IsEH);
  225. if (!RegName.empty()) {
  226. if ((Opcode >= DW_OP_breg0 && Opcode <= DW_OP_breg31) ||
  227. Opcode == DW_OP_bregx)
  228. OS << ' ' << RegName << format("%+" PRId64, Operands[OpNum]);
  229. else
  230. OS << ' ' << RegName.data();
  231. if (Opcode == DW_OP_regval_type)
  232. prettyPrintBaseTypeRef(U, OS, DumpOpts, Operands, 1);
  233. return true;
  234. }
  235. return false;
  236. }
  237. bool DWARFExpression::Operation::print(raw_ostream &OS, DIDumpOptions DumpOpts,
  238. const DWARFExpression *Expr,
  239. DWARFUnit *U) const {
  240. if (Error) {
  241. OS << "<decoding error>";
  242. return false;
  243. }
  244. StringRef Name = OperationEncodingString(Opcode);
  245. assert(!Name.empty() && "DW_OP has no name!");
  246. OS << Name;
  247. if ((Opcode >= DW_OP_breg0 && Opcode <= DW_OP_breg31) ||
  248. (Opcode >= DW_OP_reg0 && Opcode <= DW_OP_reg31) ||
  249. Opcode == DW_OP_bregx || Opcode == DW_OP_regx ||
  250. Opcode == DW_OP_regval_type)
  251. if (prettyPrintRegisterOp(U, OS, DumpOpts, Opcode, Operands))
  252. return true;
  253. for (unsigned Operand = 0; Operand < 2; ++Operand) {
  254. unsigned Size = Desc.Op[Operand];
  255. unsigned Signed = Size & Operation::SignBit;
  256. if (Size == Operation::SizeNA)
  257. break;
  258. if (Size == Operation::BaseTypeRef && U) {
  259. // For DW_OP_convert the operand may be 0 to indicate that conversion to
  260. // the generic type should be done. The same holds for DW_OP_reinterpret,
  261. // which is currently not supported.
  262. if (Opcode == DW_OP_convert && Operands[Operand] == 0)
  263. OS << " 0x0";
  264. else
  265. prettyPrintBaseTypeRef(U, OS, DumpOpts, Operands, Operand);
  266. } else if (Size == Operation::WasmLocationArg) {
  267. assert(Operand == 1);
  268. switch (Operands[0]) {
  269. case 0:
  270. case 1:
  271. case 2:
  272. case 3: // global as uint32
  273. case 4:
  274. OS << format(" 0x%" PRIx64, Operands[Operand]);
  275. break;
  276. default: assert(false);
  277. }
  278. } else if (Size == Operation::SizeBlock) {
  279. uint64_t Offset = Operands[Operand];
  280. for (unsigned i = 0; i < Operands[Operand - 1]; ++i)
  281. OS << format(" 0x%02x", Expr->Data.getU8(&Offset));
  282. } else {
  283. if (Signed)
  284. OS << format(" %+" PRId64, (int64_t)Operands[Operand]);
  285. else if (Opcode != DW_OP_entry_value &&
  286. Opcode != DW_OP_GNU_entry_value)
  287. OS << format(" 0x%" PRIx64, Operands[Operand]);
  288. }
  289. }
  290. return true;
  291. }
  292. void DWARFExpression::print(raw_ostream &OS, DIDumpOptions DumpOpts,
  293. DWARFUnit *U, bool IsEH) const {
  294. uint32_t EntryValExprSize = 0;
  295. uint64_t EntryValStartOffset = 0;
  296. if (Data.getData().empty())
  297. OS << "<empty>";
  298. for (auto &Op : *this) {
  299. DumpOpts.IsEH = IsEH;
  300. if (!Op.print(OS, DumpOpts, this, U)) {
  301. uint64_t FailOffset = Op.getEndOffset();
  302. while (FailOffset < Data.getData().size())
  303. OS << format(" %02x", Data.getU8(&FailOffset));
  304. return;
  305. }
  306. if (Op.getCode() == DW_OP_entry_value ||
  307. Op.getCode() == DW_OP_GNU_entry_value) {
  308. OS << "(";
  309. EntryValExprSize = Op.getRawOperand(0);
  310. EntryValStartOffset = Op.getEndOffset();
  311. continue;
  312. }
  313. if (EntryValExprSize) {
  314. EntryValExprSize -= Op.getEndOffset() - EntryValStartOffset;
  315. if (EntryValExprSize == 0)
  316. OS << ")";
  317. }
  318. if (Op.getEndOffset() < Data.getData().size())
  319. OS << ", ";
  320. }
  321. }
  322. bool DWARFExpression::Operation::verify(const Operation &Op, DWARFUnit *U) {
  323. for (unsigned Operand = 0; Operand < 2; ++Operand) {
  324. unsigned Size = Op.Desc.Op[Operand];
  325. if (Size == Operation::SizeNA)
  326. break;
  327. if (Size == Operation::BaseTypeRef) {
  328. // For DW_OP_convert the operand may be 0 to indicate that conversion to
  329. // the generic type should be done, so don't look up a base type in that
  330. // case. The same holds for DW_OP_reinterpret, which is currently not
  331. // supported.
  332. if (Op.Opcode == DW_OP_convert && Op.Operands[Operand] == 0)
  333. continue;
  334. auto Die = U->getDIEForOffset(U->getOffset() + Op.Operands[Operand]);
  335. if (!Die || Die.getTag() != dwarf::DW_TAG_base_type)
  336. return false;
  337. }
  338. }
  339. return true;
  340. }
  341. bool DWARFExpression::verify(DWARFUnit *U) {
  342. for (auto &Op : *this)
  343. if (!Operation::verify(Op, U))
  344. return false;
  345. return true;
  346. }
  347. /// A user-facing string representation of a DWARF expression. This might be an
  348. /// Address expression, in which case it will be implicitly dereferenced, or a
  349. /// Value expression.
  350. struct PrintedExpr {
  351. enum ExprKind {
  352. Address,
  353. Value,
  354. };
  355. ExprKind Kind;
  356. SmallString<16> String;
  357. PrintedExpr(ExprKind K = Address) : Kind(K) {}
  358. };
  359. static bool printCompactDWARFExpr(
  360. raw_ostream &OS, DWARFExpression::iterator I,
  361. const DWARFExpression::iterator E,
  362. std::function<StringRef(uint64_t RegNum, bool IsEH)> GetNameForDWARFReg =
  363. nullptr) {
  364. SmallVector<PrintedExpr, 4> Stack;
  365. while (I != E) {
  366. const DWARFExpression::Operation &Op = *I;
  367. uint8_t Opcode = Op.getCode();
  368. switch (Opcode) {
  369. case dwarf::DW_OP_regx: {
  370. // DW_OP_regx: A register, with the register num given as an operand.
  371. // Printed as the plain register name.
  372. uint64_t DwarfRegNum = Op.getRawOperand(0);
  373. auto RegName = GetNameForDWARFReg(DwarfRegNum, false);
  374. if (RegName.empty())
  375. return false;
  376. raw_svector_ostream S(Stack.emplace_back(PrintedExpr::Value).String);
  377. S << RegName;
  378. break;
  379. }
  380. case dwarf::DW_OP_bregx: {
  381. int DwarfRegNum = Op.getRawOperand(0);
  382. int64_t Offset = Op.getRawOperand(1);
  383. auto RegName = GetNameForDWARFReg(DwarfRegNum, false);
  384. if (RegName.empty())
  385. return false;
  386. raw_svector_ostream S(Stack.emplace_back().String);
  387. S << RegName;
  388. if (Offset)
  389. S << format("%+" PRId64, Offset);
  390. break;
  391. }
  392. case dwarf::DW_OP_entry_value:
  393. case dwarf::DW_OP_GNU_entry_value: {
  394. // DW_OP_entry_value contains a sub-expression which must be rendered
  395. // separately.
  396. uint64_t SubExprLength = Op.getRawOperand(0);
  397. DWARFExpression::iterator SubExprEnd = I.skipBytes(SubExprLength);
  398. ++I;
  399. raw_svector_ostream S(Stack.emplace_back().String);
  400. S << "entry(";
  401. printCompactDWARFExpr(S, I, SubExprEnd, GetNameForDWARFReg);
  402. S << ")";
  403. I = SubExprEnd;
  404. continue;
  405. }
  406. case dwarf::DW_OP_stack_value: {
  407. // The top stack entry should be treated as the actual value of tne
  408. // variable, rather than the address of the variable in memory.
  409. assert(!Stack.empty());
  410. Stack.back().Kind = PrintedExpr::Value;
  411. break;
  412. }
  413. default:
  414. if (Opcode >= dwarf::DW_OP_reg0 && Opcode <= dwarf::DW_OP_reg31) {
  415. // DW_OP_reg<N>: A register, with the register num implied by the
  416. // opcode. Printed as the plain register name.
  417. uint64_t DwarfRegNum = Opcode - dwarf::DW_OP_reg0;
  418. auto RegName = GetNameForDWARFReg(DwarfRegNum, false);
  419. if (RegName.empty())
  420. return false;
  421. raw_svector_ostream S(Stack.emplace_back(PrintedExpr::Value).String);
  422. S << RegName;
  423. } else if (Opcode >= dwarf::DW_OP_breg0 &&
  424. Opcode <= dwarf::DW_OP_breg31) {
  425. int DwarfRegNum = Opcode - dwarf::DW_OP_breg0;
  426. int64_t Offset = Op.getRawOperand(0);
  427. auto RegName = GetNameForDWARFReg(DwarfRegNum, false);
  428. if (RegName.empty())
  429. return false;
  430. raw_svector_ostream S(Stack.emplace_back().String);
  431. S << RegName;
  432. if (Offset)
  433. S << format("%+" PRId64, Offset);
  434. } else {
  435. // If we hit an unknown operand, we don't know its effect on the stack,
  436. // so bail out on the whole expression.
  437. OS << "<unknown op " << dwarf::OperationEncodingString(Opcode) << " ("
  438. << (int)Opcode << ")>";
  439. return false;
  440. }
  441. break;
  442. }
  443. ++I;
  444. }
  445. assert(Stack.size() == 1 && "expected one value on stack");
  446. if (Stack.front().Kind == PrintedExpr::Address)
  447. OS << "[" << Stack.front().String << "]";
  448. else
  449. OS << Stack.front().String;
  450. return true;
  451. }
  452. bool DWARFExpression::printCompact(
  453. raw_ostream &OS,
  454. std::function<StringRef(uint64_t RegNum, bool IsEH)> GetNameForDWARFReg) {
  455. return printCompactDWARFExpr(OS, begin(), end(), GetNameForDWARFReg);
  456. }
  457. bool DWARFExpression::operator==(const DWARFExpression &RHS) const {
  458. if (AddressSize != RHS.AddressSize || Format != RHS.Format)
  459. return false;
  460. return Data.getData() == RHS.Data.getData();
  461. }
  462. } // namespace llvm