DwarfExpression.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. //===- llvm/CodeGen/DwarfExpression.cpp - Dwarf Debug Framework -----------===//
  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. //
  9. // This file contains support for writing dwarf debug info into asm files.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #include "DwarfExpression.h"
  13. #include "DwarfCompileUnit.h"
  14. #include "llvm/ADT/APInt.h"
  15. #include "llvm/ADT/SmallBitVector.h"
  16. #include "llvm/BinaryFormat/Dwarf.h"
  17. #include "llvm/CodeGen/Register.h"
  18. #include "llvm/CodeGen/TargetRegisterInfo.h"
  19. #include "llvm/IR/DebugInfoMetadata.h"
  20. #include "llvm/Support/ErrorHandling.h"
  21. #include <algorithm>
  22. #include <cassert>
  23. #include <cstdint>
  24. using namespace llvm;
  25. void DwarfExpression::emitConstu(uint64_t Value) {
  26. if (Value < 32)
  27. emitOp(dwarf::DW_OP_lit0 + Value);
  28. else if (Value == std::numeric_limits<uint64_t>::max()) {
  29. // Only do this for 64-bit values as the DWARF expression stack uses
  30. // target-address-size values.
  31. emitOp(dwarf::DW_OP_lit0);
  32. emitOp(dwarf::DW_OP_not);
  33. } else {
  34. emitOp(dwarf::DW_OP_constu);
  35. emitUnsigned(Value);
  36. }
  37. }
  38. void DwarfExpression::addReg(int DwarfReg, const char *Comment) {
  39. assert(DwarfReg >= 0 && "invalid negative dwarf register number");
  40. assert((isUnknownLocation() || isRegisterLocation()) &&
  41. "location description already locked down");
  42. LocationKind = Register;
  43. if (DwarfReg < 32) {
  44. emitOp(dwarf::DW_OP_reg0 + DwarfReg, Comment);
  45. } else {
  46. emitOp(dwarf::DW_OP_regx, Comment);
  47. emitUnsigned(DwarfReg);
  48. }
  49. }
  50. void DwarfExpression::addBReg(int DwarfReg, int Offset) {
  51. assert(DwarfReg >= 0 && "invalid negative dwarf register number");
  52. assert(!isRegisterLocation() && "location description already locked down");
  53. if (DwarfReg < 32) {
  54. emitOp(dwarf::DW_OP_breg0 + DwarfReg);
  55. } else {
  56. emitOp(dwarf::DW_OP_bregx);
  57. emitUnsigned(DwarfReg);
  58. }
  59. emitSigned(Offset);
  60. }
  61. void DwarfExpression::addFBReg(int Offset) {
  62. emitOp(dwarf::DW_OP_fbreg);
  63. emitSigned(Offset);
  64. }
  65. void DwarfExpression::addOpPiece(unsigned SizeInBits, unsigned OffsetInBits) {
  66. if (!SizeInBits)
  67. return;
  68. const unsigned SizeOfByte = 8;
  69. if (OffsetInBits > 0 || SizeInBits % SizeOfByte) {
  70. emitOp(dwarf::DW_OP_bit_piece);
  71. emitUnsigned(SizeInBits);
  72. emitUnsigned(OffsetInBits);
  73. } else {
  74. emitOp(dwarf::DW_OP_piece);
  75. unsigned ByteSize = SizeInBits / SizeOfByte;
  76. emitUnsigned(ByteSize);
  77. }
  78. this->OffsetInBits += SizeInBits;
  79. }
  80. void DwarfExpression::addShr(unsigned ShiftBy) {
  81. emitConstu(ShiftBy);
  82. emitOp(dwarf::DW_OP_shr);
  83. }
  84. void DwarfExpression::addAnd(unsigned Mask) {
  85. emitConstu(Mask);
  86. emitOp(dwarf::DW_OP_and);
  87. }
  88. bool DwarfExpression::addMachineReg(const TargetRegisterInfo &TRI,
  89. unsigned MachineReg, unsigned MaxSize) {
  90. if (!llvm::Register::isPhysicalRegister(MachineReg)) {
  91. if (isFrameRegister(TRI, MachineReg)) {
  92. DwarfRegs.push_back({-1, 0, nullptr});
  93. return true;
  94. }
  95. return false;
  96. }
  97. int Reg = TRI.getDwarfRegNum(MachineReg, false);
  98. // If this is a valid register number, emit it.
  99. if (Reg >= 0) {
  100. DwarfRegs.push_back({Reg, 0, nullptr});
  101. return true;
  102. }
  103. // Walk up the super-register chain until we find a valid number.
  104. // For example, EAX on x86_64 is a 32-bit fragment of RAX with offset 0.
  105. for (MCSuperRegIterator SR(MachineReg, &TRI); SR.isValid(); ++SR) {
  106. Reg = TRI.getDwarfRegNum(*SR, false);
  107. if (Reg >= 0) {
  108. unsigned Idx = TRI.getSubRegIndex(*SR, MachineReg);
  109. unsigned Size = TRI.getSubRegIdxSize(Idx);
  110. unsigned RegOffset = TRI.getSubRegIdxOffset(Idx);
  111. DwarfRegs.push_back({Reg, 0, "super-register"});
  112. // Use a DW_OP_bit_piece to describe the sub-register.
  113. setSubRegisterPiece(Size, RegOffset);
  114. return true;
  115. }
  116. }
  117. // Otherwise, attempt to find a covering set of sub-register numbers.
  118. // For example, Q0 on ARM is a composition of D0+D1.
  119. unsigned CurPos = 0;
  120. // The size of the register in bits.
  121. const TargetRegisterClass *RC = TRI.getMinimalPhysRegClass(MachineReg);
  122. unsigned RegSize = TRI.getRegSizeInBits(*RC);
  123. // Keep track of the bits in the register we already emitted, so we
  124. // can avoid emitting redundant aliasing subregs. Because this is
  125. // just doing a greedy scan of all subregisters, it is possible that
  126. // this doesn't find a combination of subregisters that fully cover
  127. // the register (even though one may exist).
  128. SmallBitVector Coverage(RegSize, false);
  129. for (MCSubRegIterator SR(MachineReg, &TRI); SR.isValid(); ++SR) {
  130. unsigned Idx = TRI.getSubRegIndex(MachineReg, *SR);
  131. unsigned Size = TRI.getSubRegIdxSize(Idx);
  132. unsigned Offset = TRI.getSubRegIdxOffset(Idx);
  133. Reg = TRI.getDwarfRegNum(*SR, false);
  134. if (Reg < 0)
  135. continue;
  136. // Intersection between the bits we already emitted and the bits
  137. // covered by this subregister.
  138. SmallBitVector CurSubReg(RegSize, false);
  139. CurSubReg.set(Offset, Offset + Size);
  140. // If this sub-register has a DWARF number and we haven't covered
  141. // its range, emit a DWARF piece for it.
  142. if (CurSubReg.test(Coverage)) {
  143. // Emit a piece for any gap in the coverage.
  144. if (Offset > CurPos)
  145. DwarfRegs.push_back({-1, Offset - CurPos, "no DWARF register encoding"});
  146. DwarfRegs.push_back(
  147. {Reg, std::min<unsigned>(Size, MaxSize - Offset), "sub-register"});
  148. if (Offset >= MaxSize)
  149. break;
  150. // Mark it as emitted.
  151. Coverage.set(Offset, Offset + Size);
  152. CurPos = Offset + Size;
  153. }
  154. }
  155. // Failed to find any DWARF encoding.
  156. if (CurPos == 0)
  157. return false;
  158. // Found a partial or complete DWARF encoding.
  159. if (CurPos < RegSize)
  160. DwarfRegs.push_back({-1, RegSize - CurPos, "no DWARF register encoding"});
  161. return true;
  162. }
  163. void DwarfExpression::addStackValue() {
  164. if (DwarfVersion >= 4)
  165. emitOp(dwarf::DW_OP_stack_value);
  166. }
  167. void DwarfExpression::addSignedConstant(int64_t Value) {
  168. assert(isImplicitLocation() || isUnknownLocation());
  169. LocationKind = Implicit;
  170. emitOp(dwarf::DW_OP_consts);
  171. emitSigned(Value);
  172. }
  173. void DwarfExpression::addUnsignedConstant(uint64_t Value) {
  174. assert(isImplicitLocation() || isUnknownLocation());
  175. LocationKind = Implicit;
  176. emitConstu(Value);
  177. }
  178. void DwarfExpression::addUnsignedConstant(const APInt &Value) {
  179. assert(isImplicitLocation() || isUnknownLocation());
  180. LocationKind = Implicit;
  181. unsigned Size = Value.getBitWidth();
  182. const uint64_t *Data = Value.getRawData();
  183. // Chop it up into 64-bit pieces, because that's the maximum that
  184. // addUnsignedConstant takes.
  185. unsigned Offset = 0;
  186. while (Offset < Size) {
  187. addUnsignedConstant(*Data++);
  188. if (Offset == 0 && Size <= 64)
  189. break;
  190. addStackValue();
  191. addOpPiece(std::min(Size - Offset, 64u), Offset);
  192. Offset += 64;
  193. }
  194. }
  195. bool DwarfExpression::addMachineRegExpression(const TargetRegisterInfo &TRI,
  196. DIExpressionCursor &ExprCursor,
  197. unsigned MachineReg,
  198. unsigned FragmentOffsetInBits) {
  199. auto Fragment = ExprCursor.getFragmentInfo();
  200. if (!addMachineReg(TRI, MachineReg, Fragment ? Fragment->SizeInBits : ~1U)) {
  201. LocationKind = Unknown;
  202. return false;
  203. }
  204. bool HasComplexExpression = false;
  205. auto Op = ExprCursor.peek();
  206. if (Op && Op->getOp() != dwarf::DW_OP_LLVM_fragment)
  207. HasComplexExpression = true;
  208. // If the register can only be described by a complex expression (i.e.,
  209. // multiple subregisters) it doesn't safely compose with another complex
  210. // expression. For example, it is not possible to apply a DW_OP_deref
  211. // operation to multiple DW_OP_pieces.
  212. if (HasComplexExpression && DwarfRegs.size() > 1) {
  213. DwarfRegs.clear();
  214. LocationKind = Unknown;
  215. return false;
  216. }
  217. // Handle simple register locations. If we are supposed to emit
  218. // a call site parameter expression and if that expression is just a register
  219. // location, emit it with addBReg and offset 0, because we should emit a DWARF
  220. // expression representing a value, rather than a location.
  221. if (!isMemoryLocation() && !HasComplexExpression && (!isParameterValue() ||
  222. isEntryValue())) {
  223. for (auto &Reg : DwarfRegs) {
  224. if (Reg.DwarfRegNo >= 0)
  225. addReg(Reg.DwarfRegNo, Reg.Comment);
  226. addOpPiece(Reg.Size);
  227. }
  228. if (isEntryValue() && !isParameterValue() && DwarfVersion >= 4)
  229. emitOp(dwarf::DW_OP_stack_value);
  230. DwarfRegs.clear();
  231. return true;
  232. }
  233. // Don't emit locations that cannot be expressed without DW_OP_stack_value.
  234. if (DwarfVersion < 4)
  235. if (any_of(ExprCursor, [](DIExpression::ExprOperand Op) -> bool {
  236. return Op.getOp() == dwarf::DW_OP_stack_value;
  237. })) {
  238. DwarfRegs.clear();
  239. LocationKind = Unknown;
  240. return false;
  241. }
  242. assert(DwarfRegs.size() == 1);
  243. auto Reg = DwarfRegs[0];
  244. bool FBReg = isFrameRegister(TRI, MachineReg);
  245. int SignedOffset = 0;
  246. assert(Reg.Size == 0 && "subregister has same size as superregister");
  247. // Pattern-match combinations for which more efficient representations exist.
  248. // [Reg, DW_OP_plus_uconst, Offset] --> [DW_OP_breg, Offset].
  249. if (Op && (Op->getOp() == dwarf::DW_OP_plus_uconst)) {
  250. uint64_t Offset = Op->getArg(0);
  251. uint64_t IntMax = static_cast<uint64_t>(std::numeric_limits<int>::max());
  252. if (Offset <= IntMax) {
  253. SignedOffset = Offset;
  254. ExprCursor.take();
  255. }
  256. }
  257. // [Reg, DW_OP_constu, Offset, DW_OP_plus] --> [DW_OP_breg, Offset]
  258. // [Reg, DW_OP_constu, Offset, DW_OP_minus] --> [DW_OP_breg,-Offset]
  259. // If Reg is a subregister we need to mask it out before subtracting.
  260. if (Op && Op->getOp() == dwarf::DW_OP_constu) {
  261. uint64_t Offset = Op->getArg(0);
  262. uint64_t IntMax = static_cast<uint64_t>(std::numeric_limits<int>::max());
  263. auto N = ExprCursor.peekNext();
  264. if (N && N->getOp() == dwarf::DW_OP_plus && Offset <= IntMax) {
  265. SignedOffset = Offset;
  266. ExprCursor.consume(2);
  267. } else if (N && N->getOp() == dwarf::DW_OP_minus &&
  268. !SubRegisterSizeInBits && Offset <= IntMax + 1) {
  269. SignedOffset = -static_cast<int64_t>(Offset);
  270. ExprCursor.consume(2);
  271. }
  272. }
  273. if (FBReg)
  274. addFBReg(SignedOffset);
  275. else
  276. addBReg(Reg.DwarfRegNo, SignedOffset);
  277. DwarfRegs.clear();
  278. return true;
  279. }
  280. void DwarfExpression::addEntryValueExpression(DIExpressionCursor &ExprCursor) {
  281. auto Op = ExprCursor.take();
  282. assert(Op && Op->getOp() == dwarf::DW_OP_entry_value);
  283. assert(!isMemoryLocation() &&
  284. "We don't support entry values of memory locations yet");
  285. emitOp(CU.getDwarf5OrGNULocationAtom(dwarf::DW_OP_entry_value));
  286. emitUnsigned(Op->getArg(0));
  287. }
  288. /// Assuming a well-formed expression, match "DW_OP_deref* DW_OP_LLVM_fragment?".
  289. static bool isMemoryLocation(DIExpressionCursor ExprCursor) {
  290. while (ExprCursor) {
  291. auto Op = ExprCursor.take();
  292. switch (Op->getOp()) {
  293. case dwarf::DW_OP_deref:
  294. case dwarf::DW_OP_LLVM_fragment:
  295. break;
  296. default:
  297. return false;
  298. }
  299. }
  300. return true;
  301. }
  302. void DwarfExpression::addExpression(DIExpressionCursor &&ExprCursor,
  303. unsigned FragmentOffsetInBits) {
  304. // If we need to mask out a subregister, do it now, unless the next
  305. // operation would emit an OpPiece anyway.
  306. auto N = ExprCursor.peek();
  307. if (SubRegisterSizeInBits && N && (N->getOp() != dwarf::DW_OP_LLVM_fragment))
  308. maskSubRegister();
  309. Optional<DIExpression::ExprOperand> PrevConvertOp = None;
  310. while (ExprCursor) {
  311. auto Op = ExprCursor.take();
  312. uint64_t OpNum = Op->getOp();
  313. if (OpNum >= dwarf::DW_OP_reg0 && OpNum <= dwarf::DW_OP_reg31) {
  314. emitOp(OpNum);
  315. continue;
  316. } else if (OpNum >= dwarf::DW_OP_breg0 && OpNum <= dwarf::DW_OP_breg31) {
  317. addBReg(OpNum - dwarf::DW_OP_breg0, Op->getArg(0));
  318. continue;
  319. }
  320. switch (OpNum) {
  321. case dwarf::DW_OP_LLVM_fragment: {
  322. unsigned SizeInBits = Op->getArg(1);
  323. unsigned FragmentOffset = Op->getArg(0);
  324. // The fragment offset must have already been adjusted by emitting an
  325. // empty DW_OP_piece / DW_OP_bit_piece before we emitted the base
  326. // location.
  327. assert(OffsetInBits >= FragmentOffset && "fragment offset not added?");
  328. // If addMachineReg already emitted DW_OP_piece operations to represent
  329. // a super-register by splicing together sub-registers, subtract the size
  330. // of the pieces that was already emitted.
  331. SizeInBits -= OffsetInBits - FragmentOffset;
  332. // If addMachineReg requested a DW_OP_bit_piece to stencil out a
  333. // sub-register that is smaller than the current fragment's size, use it.
  334. if (SubRegisterSizeInBits)
  335. SizeInBits = std::min<unsigned>(SizeInBits, SubRegisterSizeInBits);
  336. // Emit a DW_OP_stack_value for implicit location descriptions.
  337. if (isImplicitLocation())
  338. addStackValue();
  339. // Emit the DW_OP_piece.
  340. addOpPiece(SizeInBits, SubRegisterOffsetInBits);
  341. setSubRegisterPiece(0, 0);
  342. // Reset the location description kind.
  343. LocationKind = Unknown;
  344. return;
  345. }
  346. case dwarf::DW_OP_plus_uconst:
  347. assert(!isRegisterLocation());
  348. emitOp(dwarf::DW_OP_plus_uconst);
  349. emitUnsigned(Op->getArg(0));
  350. break;
  351. case dwarf::DW_OP_plus:
  352. case dwarf::DW_OP_minus:
  353. case dwarf::DW_OP_mul:
  354. case dwarf::DW_OP_div:
  355. case dwarf::DW_OP_mod:
  356. case dwarf::DW_OP_or:
  357. case dwarf::DW_OP_and:
  358. case dwarf::DW_OP_xor:
  359. case dwarf::DW_OP_shl:
  360. case dwarf::DW_OP_shr:
  361. case dwarf::DW_OP_shra:
  362. case dwarf::DW_OP_lit0:
  363. case dwarf::DW_OP_not:
  364. case dwarf::DW_OP_dup:
  365. emitOp(OpNum);
  366. break;
  367. case dwarf::DW_OP_deref:
  368. assert(!isRegisterLocation());
  369. if (!isMemoryLocation() && ::isMemoryLocation(ExprCursor))
  370. // Turning this into a memory location description makes the deref
  371. // implicit.
  372. LocationKind = Memory;
  373. else
  374. emitOp(dwarf::DW_OP_deref);
  375. break;
  376. case dwarf::DW_OP_constu:
  377. assert(!isRegisterLocation());
  378. emitConstu(Op->getArg(0));
  379. break;
  380. case dwarf::DW_OP_LLVM_convert: {
  381. unsigned BitSize = Op->getArg(0);
  382. dwarf::TypeKind Encoding = static_cast<dwarf::TypeKind>(Op->getArg(1));
  383. if (DwarfVersion >= 5) {
  384. emitOp(dwarf::DW_OP_convert);
  385. // Reuse the base_type if we already have one in this CU otherwise we
  386. // create a new one.
  387. unsigned I = 0, E = CU.ExprRefedBaseTypes.size();
  388. for (; I != E; ++I)
  389. if (CU.ExprRefedBaseTypes[I].BitSize == BitSize &&
  390. CU.ExprRefedBaseTypes[I].Encoding == Encoding)
  391. break;
  392. if (I == E)
  393. CU.ExprRefedBaseTypes.emplace_back(BitSize, Encoding);
  394. // If targeting a location-list; simply emit the index into the raw
  395. // byte stream as ULEB128, DwarfDebug::emitDebugLocEntry has been
  396. // fitted with means to extract it later.
  397. // If targeting a inlined DW_AT_location; insert a DIEBaseTypeRef
  398. // (containing the index and a resolve mechanism during emit) into the
  399. // DIE value list.
  400. emitBaseTypeRef(I);
  401. } else {
  402. if (PrevConvertOp && PrevConvertOp->getArg(0) < BitSize) {
  403. if (Encoding == dwarf::DW_ATE_signed)
  404. emitLegacySExt(PrevConvertOp->getArg(0));
  405. else if (Encoding == dwarf::DW_ATE_unsigned)
  406. emitLegacyZExt(PrevConvertOp->getArg(0));
  407. PrevConvertOp = None;
  408. } else {
  409. PrevConvertOp = Op;
  410. }
  411. }
  412. break;
  413. }
  414. case dwarf::DW_OP_stack_value:
  415. LocationKind = Implicit;
  416. break;
  417. case dwarf::DW_OP_swap:
  418. assert(!isRegisterLocation());
  419. emitOp(dwarf::DW_OP_swap);
  420. break;
  421. case dwarf::DW_OP_xderef:
  422. assert(!isRegisterLocation());
  423. emitOp(dwarf::DW_OP_xderef);
  424. break;
  425. case dwarf::DW_OP_deref_size:
  426. emitOp(dwarf::DW_OP_deref_size);
  427. emitData1(Op->getArg(0));
  428. break;
  429. case dwarf::DW_OP_LLVM_tag_offset:
  430. TagOffset = Op->getArg(0);
  431. break;
  432. case dwarf::DW_OP_regx:
  433. emitOp(dwarf::DW_OP_regx);
  434. emitUnsigned(Op->getArg(0));
  435. break;
  436. case dwarf::DW_OP_bregx:
  437. emitOp(dwarf::DW_OP_bregx);
  438. emitUnsigned(Op->getArg(0));
  439. emitSigned(Op->getArg(1));
  440. break;
  441. default:
  442. llvm_unreachable("unhandled opcode found in expression");
  443. }
  444. }
  445. if (isImplicitLocation() && !isParameterValue())
  446. // Turn this into an implicit location description.
  447. addStackValue();
  448. }
  449. /// add masking operations to stencil out a subregister.
  450. void DwarfExpression::maskSubRegister() {
  451. assert(SubRegisterSizeInBits && "no subregister was registered");
  452. if (SubRegisterOffsetInBits > 0)
  453. addShr(SubRegisterOffsetInBits);
  454. uint64_t Mask = (1ULL << (uint64_t)SubRegisterSizeInBits) - 1ULL;
  455. addAnd(Mask);
  456. }
  457. void DwarfExpression::finalize() {
  458. assert(DwarfRegs.size() == 0 && "dwarf registers not emitted");
  459. // Emit any outstanding DW_OP_piece operations to mask out subregisters.
  460. if (SubRegisterSizeInBits == 0)
  461. return;
  462. // Don't emit a DW_OP_piece for a subregister at offset 0.
  463. if (SubRegisterOffsetInBits == 0)
  464. return;
  465. addOpPiece(SubRegisterSizeInBits, SubRegisterOffsetInBits);
  466. }
  467. void DwarfExpression::addFragmentOffset(const DIExpression *Expr) {
  468. if (!Expr || !Expr->isFragment())
  469. return;
  470. uint64_t FragmentOffset = Expr->getFragmentInfo()->OffsetInBits;
  471. assert(FragmentOffset >= OffsetInBits &&
  472. "overlapping or duplicate fragments");
  473. if (FragmentOffset > OffsetInBits)
  474. addOpPiece(FragmentOffset - OffsetInBits);
  475. OffsetInBits = FragmentOffset;
  476. }
  477. void DwarfExpression::emitLegacySExt(unsigned FromBits) {
  478. // (((X >> (FromBits - 1)) * (~0)) << FromBits) | X
  479. emitOp(dwarf::DW_OP_dup);
  480. emitOp(dwarf::DW_OP_constu);
  481. emitUnsigned(FromBits - 1);
  482. emitOp(dwarf::DW_OP_shr);
  483. emitOp(dwarf::DW_OP_lit0);
  484. emitOp(dwarf::DW_OP_not);
  485. emitOp(dwarf::DW_OP_mul);
  486. emitOp(dwarf::DW_OP_constu);
  487. emitUnsigned(FromBits);
  488. emitOp(dwarf::DW_OP_shl);
  489. emitOp(dwarf::DW_OP_or);
  490. }
  491. void DwarfExpression::emitLegacyZExt(unsigned FromBits) {
  492. // (X & (1 << FromBits - 1))
  493. emitOp(dwarf::DW_OP_constu);
  494. emitUnsigned((1ULL << FromBits) - 1);
  495. emitOp(dwarf::DW_OP_and);
  496. }