LLDB mainline
DWARFExpression.cpp
Go to the documentation of this file.
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//
9// The DWARF expression opcodes evaluated in this file are defined by the DWARF
10// Debugging Information Format specification, available at:
11//
12// https://dwarfstd.org/
13//
14//===----------------------------------------------------------------------===//
15
17
18#include <cinttypes>
19#include <limits>
20
21#include <optional>
22#include <vector>
23
24#include "lldb/Core/Module.h"
25#include "lldb/Core/Value.h"
28#include "lldb/Utility/Log.h"
30#include "lldb/Utility/Scalar.h"
32
33#include "lldb/Host/Host.h"
34#include "lldb/Utility/Endian.h"
35
37
38#include "lldb/Target/ABI.h"
41#include "lldb/Target/Process.h"
44#include "lldb/Target/StackID.h"
45#include "lldb/Target/Target.h"
46#include "lldb/Target/Thread.h"
47#include "llvm/DebugInfo/DWARF/DWARFExpressionUnit.h"
48#include "llvm/DebugInfo/DWARF/LowLevel/DWARFExpression.h"
49#include "llvm/Support/ErrorExtras.h"
50
51using namespace lldb;
52using namespace lldb_private;
53using namespace lldb_private::plugin::dwarf;
54using namespace llvm::dwarf;
55
56namespace {
57/// The location description kinds described by the DWARF v5
58/// specification. Composite locations are handled out-of-band and
59/// thus aren't part of the enum.
60enum LocationDescriptionKind {
61 Empty,
62 Memory,
63 Register,
64 Implicit
65 /* Composite*/
66};
67
68/// Aggregates the inputs, derived pointers, and mutable evaluation state for
69/// a single DWARF expression evaluation. Passed by reference to every helper
70/// so they don't need to re-thread these individually.
71struct EvalContext {
72 ExecutionContext *exe_ctx;
73 RegisterContext *reg_ctx;
74 lldb::ModuleSP module_sp;
75 const DWARFExpression::Delegate *dwarf_cu;
76 lldb::RegisterKind reg_kind;
77 lldb::ByteOrder byte_order;
78 const Value *initial_value_ptr;
79 const Value *object_address_ptr;
80 Process *process = nullptr;
81 Target *target = nullptr;
82 StackFrame *frame = nullptr;
83
84 /// Mutable evaluation state.
85 /// @{
86 std::vector<Value> stack;
87 Value pieces;
88 uint64_t op_piece_bit_offset = 0;
89 LocationDescriptionKind loc_desc_kind = Memory;
90 /// @}
91
92 EvalContext(ExecutionContext *exe_ctx, RegisterContext *reg_ctx,
93 lldb::ModuleSP module_sp,
94 const DWARFExpression::Delegate *dwarf_cu,
95 lldb::RegisterKind reg_kind, lldb::ByteOrder byte_order,
96 const Value *initial_value_ptr, const Value *object_address_ptr)
97 : exe_ctx(exe_ctx), reg_ctx(reg_ctx), module_sp(std::move(module_sp)),
98 dwarf_cu(dwarf_cu), reg_kind(reg_kind), byte_order(byte_order),
99 initial_value_ptr(initial_value_ptr),
100 object_address_ptr(object_address_ptr) {
101 if (exe_ctx) {
102 process = exe_ctx->GetProcessPtr();
103 frame = exe_ctx->GetFramePtr();
104 target = exe_ctx->GetTargetPtr();
105 }
106 if (this->reg_ctx == nullptr && frame)
107 this->reg_ctx = frame->GetRegisterContext().get();
108 }
109};
110} // namespace
111
112// DWARFExpression constructor
114
116
117// Destructor
119
120bool DWARFExpression::IsValid() const { return m_data.GetByteSize() > 0; }
121
122void DWARFExpression::UpdateValue(uint64_t const_value,
123 lldb::offset_t const_value_byte_size,
124 uint8_t addr_byte_size) {
125 if (!const_value_byte_size)
126 return;
127
128 m_data.SetData(
129 DataBufferSP(new DataBufferHeap(&const_value, const_value_byte_size)));
130 m_data.SetByteOrder(endian::InlHostByteOrder());
131 m_data.SetAddressByteSize(addr_byte_size);
132}
133
135 ABI *abi,
136 llvm::DIDumpOptions options) const {
137 auto *MCRegInfo = abi ? &abi->GetMCRegisterInfo() : nullptr;
138 auto GetRegName = [&MCRegInfo](uint64_t DwarfRegNum,
139 bool IsEH) -> llvm::StringRef {
140 if (!MCRegInfo)
141 return {};
142 if (std::optional<unsigned> LLVMRegNum =
143 MCRegInfo->getLLVMRegNum(DwarfRegNum, IsEH))
144 if (const char *RegName = MCRegInfo->getName(*LLVMRegNum))
145 return llvm::StringRef(RegName);
146 return {};
147 };
148 options.GetNameForDWARFReg = GetRegName;
149 llvm::DWARFExpression E(m_data.GetAsLLVM(), m_data.GetAddressByteSize());
150 llvm::printDwarfExpression(&E, s->AsRawOstream(), options);
151}
152
154
156 m_reg_kind = reg_kind;
157}
158
159llvm::Error
161 lldb::RegisterKind reg_kind,
162 uint32_t reg_num, Value &value) {
163 if (reg_ctx == nullptr)
164 return llvm::createStringError("no register context in frame");
165
166 const uint32_t native_reg =
167 reg_ctx->ConvertRegisterKindToRegisterNumber(reg_kind, reg_num);
168 if (native_reg == LLDB_INVALID_REGNUM)
169 return llvm::createStringError(
170 "unable to convert register kind=%u reg_num=%u to a native "
171 "register number",
172 reg_kind, reg_num);
173
174 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex(native_reg);
175 RegisterValue reg_value;
176 if (reg_ctx->ReadRegister(reg_info, reg_value)) {
177 if (reg_value.GetScalarValue(value.GetScalar())) {
180 const_cast<RegisterInfo *>(reg_info));
181 return llvm::Error::success();
182 }
183
184 // If we get this error, then we need to implement a value buffer in
185 // the dwarf expression evaluation function...
186 return llvm::createStringError(
187 "register %s can't be converted to a scalar value", reg_info->name);
188 }
189
190 return llvm::createStringError("register %s is not available",
191 reg_info->name);
192}
193
194/// Return the length in bytes of the set of operands for \p op. No guarantees
195/// are made on the state of \p data after this call.
196static lldb::offset_t
197GetOpcodeDataSize(const DataExtractor &data, const lldb::offset_t data_offset,
198 const LocationAtom op,
199 const DWARFExpression::Delegate *dwarf_cu) {
200 lldb::offset_t offset = data_offset;
201 switch (op) {
202 // Only used in LLVM metadata.
203 case DW_OP_LLVM_fragment:
204 case DW_OP_LLVM_convert:
205 case DW_OP_LLVM_tag_offset:
206 case DW_OP_LLVM_entry_value:
207 case DW_OP_LLVM_implicit_pointer:
208 case DW_OP_LLVM_arg:
209 case DW_OP_LLVM_extract_bits_sext:
210 case DW_OP_LLVM_extract_bits_zext:
211 break;
212 // Vendor extensions:
213 case DW_OP_HP_is_value:
214 case DW_OP_HP_fltconst4:
215 case DW_OP_HP_fltconst8:
216 case DW_OP_HP_mod_range:
217 case DW_OP_HP_unmod_range:
218 case DW_OP_HP_tls:
219 case DW_OP_INTEL_bit_piece:
220 case DW_OP_WASM_location:
221 case DW_OP_WASM_location_int:
222 case DW_OP_APPLE_uninit:
223 case DW_OP_PGI_omp_thread_num:
224 case DW_OP_hi_user:
225 case DW_OP_GNU_implicit_pointer:
226 break;
227
228 case DW_OP_addr:
229 case DW_OP_call_ref: // 0x9a 1 address sized offset of DIE (DWARF3)
230 return data.GetAddressByteSize();
231
232 // Opcodes with no arguments
233 case DW_OP_deref: // 0x06
234 case DW_OP_dup: // 0x12
235 case DW_OP_drop: // 0x13
236 case DW_OP_over: // 0x14
237 case DW_OP_swap: // 0x16
238 case DW_OP_rot: // 0x17
239 case DW_OP_xderef: // 0x18
240 case DW_OP_abs: // 0x19
241 case DW_OP_and: // 0x1a
242 case DW_OP_div: // 0x1b
243 case DW_OP_minus: // 0x1c
244 case DW_OP_mod: // 0x1d
245 case DW_OP_mul: // 0x1e
246 case DW_OP_neg: // 0x1f
247 case DW_OP_not: // 0x20
248 case DW_OP_or: // 0x21
249 case DW_OP_plus: // 0x22
250 case DW_OP_shl: // 0x24
251 case DW_OP_shr: // 0x25
252 case DW_OP_shra: // 0x26
253 case DW_OP_xor: // 0x27
254 case DW_OP_eq: // 0x29
255 case DW_OP_ge: // 0x2a
256 case DW_OP_gt: // 0x2b
257 case DW_OP_le: // 0x2c
258 case DW_OP_lt: // 0x2d
259 case DW_OP_ne: // 0x2e
260 case DW_OP_lit0: // 0x30
261 case DW_OP_lit1: // 0x31
262 case DW_OP_lit2: // 0x32
263 case DW_OP_lit3: // 0x33
264 case DW_OP_lit4: // 0x34
265 case DW_OP_lit5: // 0x35
266 case DW_OP_lit6: // 0x36
267 case DW_OP_lit7: // 0x37
268 case DW_OP_lit8: // 0x38
269 case DW_OP_lit9: // 0x39
270 case DW_OP_lit10: // 0x3A
271 case DW_OP_lit11: // 0x3B
272 case DW_OP_lit12: // 0x3C
273 case DW_OP_lit13: // 0x3D
274 case DW_OP_lit14: // 0x3E
275 case DW_OP_lit15: // 0x3F
276 case DW_OP_lit16: // 0x40
277 case DW_OP_lit17: // 0x41
278 case DW_OP_lit18: // 0x42
279 case DW_OP_lit19: // 0x43
280 case DW_OP_lit20: // 0x44
281 case DW_OP_lit21: // 0x45
282 case DW_OP_lit22: // 0x46
283 case DW_OP_lit23: // 0x47
284 case DW_OP_lit24: // 0x48
285 case DW_OP_lit25: // 0x49
286 case DW_OP_lit26: // 0x4A
287 case DW_OP_lit27: // 0x4B
288 case DW_OP_lit28: // 0x4C
289 case DW_OP_lit29: // 0x4D
290 case DW_OP_lit30: // 0x4E
291 case DW_OP_lit31: // 0x4f
292 case DW_OP_reg0: // 0x50
293 case DW_OP_reg1: // 0x51
294 case DW_OP_reg2: // 0x52
295 case DW_OP_reg3: // 0x53
296 case DW_OP_reg4: // 0x54
297 case DW_OP_reg5: // 0x55
298 case DW_OP_reg6: // 0x56
299 case DW_OP_reg7: // 0x57
300 case DW_OP_reg8: // 0x58
301 case DW_OP_reg9: // 0x59
302 case DW_OP_reg10: // 0x5A
303 case DW_OP_reg11: // 0x5B
304 case DW_OP_reg12: // 0x5C
305 case DW_OP_reg13: // 0x5D
306 case DW_OP_reg14: // 0x5E
307 case DW_OP_reg15: // 0x5F
308 case DW_OP_reg16: // 0x60
309 case DW_OP_reg17: // 0x61
310 case DW_OP_reg18: // 0x62
311 case DW_OP_reg19: // 0x63
312 case DW_OP_reg20: // 0x64
313 case DW_OP_reg21: // 0x65
314 case DW_OP_reg22: // 0x66
315 case DW_OP_reg23: // 0x67
316 case DW_OP_reg24: // 0x68
317 case DW_OP_reg25: // 0x69
318 case DW_OP_reg26: // 0x6A
319 case DW_OP_reg27: // 0x6B
320 case DW_OP_reg28: // 0x6C
321 case DW_OP_reg29: // 0x6D
322 case DW_OP_reg30: // 0x6E
323 case DW_OP_reg31: // 0x6F
324 case DW_OP_nop: // 0x96
325 case DW_OP_push_object_address: // 0x97 DWARF3
326 case DW_OP_form_tls_address: // 0x9b DWARF3
327 case DW_OP_call_frame_cfa: // 0x9c DWARF3
328 case DW_OP_stack_value: // 0x9f DWARF4
329 case DW_OP_GNU_push_tls_address: // 0xe0 GNU extension
330 return 0;
331
332 // Opcodes with a single 1 byte arguments
333 case DW_OP_const1u: // 0x08 1 1-byte constant
334 case DW_OP_const1s: // 0x09 1 1-byte constant
335 case DW_OP_pick: // 0x15 1 1-byte stack index
336 case DW_OP_deref_size: // 0x94 1 1-byte size of data retrieved
337 case DW_OP_xderef_size: // 0x95 1 1-byte size of data retrieved
338 case DW_OP_deref_type: // 0xa6 1 1-byte constant
339 return 1;
340
341 // Opcodes with a single 2 byte arguments
342 case DW_OP_const2u: // 0x0a 1 2-byte constant
343 case DW_OP_const2s: // 0x0b 1 2-byte constant
344 case DW_OP_skip: // 0x2f 1 signed 2-byte constant
345 case DW_OP_bra: // 0x28 1 signed 2-byte constant
346 case DW_OP_call2: // 0x98 1 2-byte offset of DIE (DWARF3)
347 return 2;
348
349 // Opcodes with a single 4 byte arguments
350 case DW_OP_const4u: // 0x0c 1 4-byte constant
351 case DW_OP_const4s: // 0x0d 1 4-byte constant
352 case DW_OP_call4: // 0x99 1 4-byte offset of DIE (DWARF3)
353 return 4;
354
355 // Opcodes with a single 8 byte arguments
356 case DW_OP_const8u: // 0x0e 1 8-byte constant
357 case DW_OP_const8s: // 0x0f 1 8-byte constant
358 return 8;
359
360 // All opcodes that have a single ULEB (signed or unsigned) argument
361 case DW_OP_constu: // 0x10 1 ULEB128 constant
362 case DW_OP_consts: // 0x11 1 SLEB128 constant
363 case DW_OP_plus_uconst: // 0x23 1 ULEB128 addend
364 case DW_OP_breg0: // 0x70 1 ULEB128 register
365 case DW_OP_breg1: // 0x71 1 ULEB128 register
366 case DW_OP_breg2: // 0x72 1 ULEB128 register
367 case DW_OP_breg3: // 0x73 1 ULEB128 register
368 case DW_OP_breg4: // 0x74 1 ULEB128 register
369 case DW_OP_breg5: // 0x75 1 ULEB128 register
370 case DW_OP_breg6: // 0x76 1 ULEB128 register
371 case DW_OP_breg7: // 0x77 1 ULEB128 register
372 case DW_OP_breg8: // 0x78 1 ULEB128 register
373 case DW_OP_breg9: // 0x79 1 ULEB128 register
374 case DW_OP_breg10: // 0x7a 1 ULEB128 register
375 case DW_OP_breg11: // 0x7b 1 ULEB128 register
376 case DW_OP_breg12: // 0x7c 1 ULEB128 register
377 case DW_OP_breg13: // 0x7d 1 ULEB128 register
378 case DW_OP_breg14: // 0x7e 1 ULEB128 register
379 case DW_OP_breg15: // 0x7f 1 ULEB128 register
380 case DW_OP_breg16: // 0x80 1 ULEB128 register
381 case DW_OP_breg17: // 0x81 1 ULEB128 register
382 case DW_OP_breg18: // 0x82 1 ULEB128 register
383 case DW_OP_breg19: // 0x83 1 ULEB128 register
384 case DW_OP_breg20: // 0x84 1 ULEB128 register
385 case DW_OP_breg21: // 0x85 1 ULEB128 register
386 case DW_OP_breg22: // 0x86 1 ULEB128 register
387 case DW_OP_breg23: // 0x87 1 ULEB128 register
388 case DW_OP_breg24: // 0x88 1 ULEB128 register
389 case DW_OP_breg25: // 0x89 1 ULEB128 register
390 case DW_OP_breg26: // 0x8a 1 ULEB128 register
391 case DW_OP_breg27: // 0x8b 1 ULEB128 register
392 case DW_OP_breg28: // 0x8c 1 ULEB128 register
393 case DW_OP_breg29: // 0x8d 1 ULEB128 register
394 case DW_OP_breg30: // 0x8e 1 ULEB128 register
395 case DW_OP_breg31: // 0x8f 1 ULEB128 register
396 case DW_OP_regx: // 0x90 1 ULEB128 register
397 case DW_OP_fbreg: // 0x91 1 SLEB128 offset
398 case DW_OP_piece: // 0x93 1 ULEB128 size of piece addressed
399 case DW_OP_convert: // 0xa8 1 ULEB128 offset
400 case DW_OP_reinterpret: // 0xa9 1 ULEB128 offset
401 case DW_OP_addrx: // 0xa1 1 ULEB128 index
402 case DW_OP_constx: // 0xa2 1 ULEB128 index
403 case DW_OP_xderef_type: // 0xa7 1 ULEB128 index
404 case DW_OP_GNU_addr_index: // 0xfb 1 ULEB128 index
405 case DW_OP_GNU_const_index: // 0xfc 1 ULEB128 index
406 data.Skip_LEB128(&offset);
407 return offset - data_offset;
408
409 // All opcodes that have a 2 ULEB (signed or unsigned) arguments
410 case DW_OP_bregx: // 0x92 2 ULEB128 register followed by SLEB128 offset
411 case DW_OP_bit_piece: // 0x9d ULEB128 bit size, ULEB128 bit offset (DWARF3);
412 case DW_OP_regval_type: // 0xa5 ULEB128 + ULEB128
413 data.Skip_LEB128(&offset);
414 data.Skip_LEB128(&offset);
415 return offset - data_offset;
416
417 case DW_OP_implicit_value: // 0x9e ULEB128 size followed by block of that size
418 // (DWARF4)
419 {
420 uint64_t block_len = data.GetULEB128(&offset);
421 offset += block_len;
422 return offset - data_offset;
423 }
424
425 case DW_OP_implicit_pointer: // 0xa0 4-byte (or 8-byte for DWARF 64) constant
426 // + LEB128
427 {
428 data.Skip_LEB128(&offset);
429 return (dwarf_cu ? dwarf_cu->GetAddressByteSize() : 4) + offset -
430 data_offset;
431 }
432
433 case DW_OP_GNU_entry_value:
434 case DW_OP_entry_value: // 0xa3 ULEB128 size + variable-length block
435 {
436 uint64_t subexpr_len = data.GetULEB128(&offset);
437 return (offset - data_offset) + subexpr_len;
438 }
439
440 case DW_OP_const_type: // 0xa4 ULEB128 + size + variable-length block
441 {
442 data.Skip_LEB128(&offset);
443 uint8_t length = data.GetU8(&offset);
444 return (offset - data_offset) + length;
445 }
446
447 case DW_OP_LLVM_user: // 0xe9: ULEB128 + variable length constant
448 {
449 uint64_t constants = data.GetULEB128(&offset);
450 return (offset - data_offset) + constants;
451 }
452 }
453
454 if (dwarf_cu)
455 return dwarf_cu->GetVendorDWARFOpcodeSize(data, data_offset, op);
456
457 return LLDB_INVALID_OFFSET;
458}
459
460static const char *DW_OP_value_to_name(uint32_t val) {
461 static char invalid[100];
462 llvm::StringRef llvmstr = llvm::dwarf::OperationEncodingString(val);
463 if (llvmstr.empty()) {
464 snprintf(invalid, sizeof(invalid), "Unknown DW_OP constant: 0x%x", val);
465 return invalid;
466 }
467 return llvmstr.data();
468}
469
470llvm::Expected<lldb::addr_t> DWARFExpression::GetLocation_DW_OP_addr(
471 const DWARFExpression::Delegate *dwarf_cu) const {
472 lldb::offset_t offset = 0;
473 while (m_data.ValidOffset(offset)) {
474 const LocationAtom op = static_cast<LocationAtom>(m_data.GetU8(&offset));
475
476 if (op == DW_OP_addr)
477 return m_data.GetAddress(&offset);
478
479 if (op == DW_OP_GNU_addr_index || op == DW_OP_addrx) {
480 const uint64_t index = m_data.GetULEB128(&offset);
481 if (dwarf_cu)
482 return dwarf_cu->ReadAddressFromDebugAddrSection(index);
483 return llvm::createStringError("cannot evaluate %s without a DWARF unit",
485 }
486
487 const lldb::offset_t op_arg_size =
488 GetOpcodeDataSize(m_data, offset, op, dwarf_cu);
489 if (op_arg_size == LLDB_INVALID_OFFSET)
490 return llvm::createStringError("cannot get opcode data size for %s",
492
493 offset += op_arg_size;
494 }
495
497}
498
500 const DWARFExpression::Delegate *dwarf_cu, lldb::addr_t file_addr) {
501 lldb::offset_t offset = 0;
502 while (m_data.ValidOffset(offset)) {
503 const LocationAtom op = static_cast<LocationAtom>(m_data.GetU8(&offset));
504
505 if (op == DW_OP_addr) {
506 const uint32_t addr_byte_size = m_data.GetAddressByteSize();
507 // We have to make a copy of the data as we don't know if this data is
508 // from a read only memory mapped buffer, so we duplicate all of the data
509 // first, then modify it, and if all goes well, we then replace the data
510 // for this expression
511
512 // Make en encoder that contains a copy of the location expression data
513 // so we can write the address into the buffer using the correct byte
514 // order.
515 DataEncoder encoder(m_data.GetDataStart(), m_data.GetByteSize(),
516 m_data.GetByteOrder(), addr_byte_size);
517
518 // Replace the address in the new buffer
519 if (encoder.PutAddress(offset, file_addr) == UINT32_MAX)
520 return false;
521
522 // All went well, so now we can reset the data using a shared pointer to
523 // the heap data so "m_data" will now correctly manage the heap data.
524 m_data.SetData(encoder.GetDataBuffer());
525 return true;
526 }
527 if (op == DW_OP_addrx) {
528 // Replace DW_OP_addrx with DW_OP_addr, since we can't modify the
529 // read-only debug_addr table.
530 // Subtract one to account for the opcode.
531 llvm::ArrayRef data_before_op = m_data.GetData().take_front(offset - 1);
532
533 // Read the addrx index to determine how many bytes it needs.
534 const lldb::offset_t old_offset = offset;
535 m_data.GetULEB128(&offset);
536 if (old_offset == offset)
537 return false;
538 llvm::ArrayRef data_after_op = m_data.GetData().drop_front(offset);
539
540 DataEncoder encoder(m_data.GetByteOrder(), m_data.GetAddressByteSize());
541 encoder.AppendData(data_before_op);
542 encoder.AppendU8(DW_OP_addr);
543 encoder.AppendAddress(file_addr);
544 encoder.AppendData(data_after_op);
545 m_data.SetData(encoder.GetDataBuffer());
546 return true;
547 }
548 const lldb::offset_t op_arg_size =
549 GetOpcodeDataSize(m_data, offset, op, dwarf_cu);
550 if (op_arg_size == LLDB_INVALID_OFFSET)
551 break;
552 offset += op_arg_size;
553 }
554 return false;
555}
556
558 const DWARFExpression::Delegate *dwarf_cu) const {
559 lldb::offset_t offset = 0;
560 while (m_data.ValidOffset(offset)) {
561 const LocationAtom op = static_cast<LocationAtom>(m_data.GetU8(&offset));
562
563 if (op == DW_OP_form_tls_address || op == DW_OP_GNU_push_tls_address)
564 return true;
565 const lldb::offset_t op_arg_size =
566 GetOpcodeDataSize(m_data, offset, op, dwarf_cu);
567 if (op_arg_size == LLDB_INVALID_OFFSET)
568 return false;
569 offset += op_arg_size;
570 }
571 return false;
572}
573
575 const DWARFExpression::Delegate *dwarf_cu) const {
576 lldb::offset_t offset = 0;
577 while (m_data.ValidOffset(offset)) {
578 const LocationAtom op = static_cast<LocationAtom>(m_data.GetU8(&offset));
579
580 switch (op) {
581 // Implicit locations have no storage in the inferior. Composite locations
582 // might, but we conservatively treat them as non-writable because LLDB
583 // does not write their pieces back.
584 case DW_OP_stack_value:
585 case DW_OP_implicit_value:
586 case DW_OP_implicit_pointer:
587 case DW_OP_piece:
588 case DW_OP_bit_piece:
589 return true;
590 default:
591 break;
592 }
593
594 const lldb::offset_t op_arg_size =
595 GetOpcodeDataSize(m_data, offset, op, dwarf_cu);
596 if (op_arg_size == LLDB_INVALID_OFFSET)
597 return false;
598 offset += op_arg_size;
599 }
600 return false;
601}
602
604 const DWARFExpression::Delegate *dwarf_cu,
605 std::function<lldb::addr_t(lldb::addr_t file_addr)> const
606 &link_address_callback) {
607 const uint32_t addr_byte_size = m_data.GetAddressByteSize();
608 // We have to make a copy of the data as we don't know if this data is from a
609 // read only memory mapped buffer, so we duplicate all of the data first,
610 // then modify it, and if all goes well, we then replace the data for this
611 // expression.
612 // Make en encoder that contains a copy of the location expression data so we
613 // can write the address into the buffer using the correct byte order.
614 DataEncoder encoder(m_data.GetDataStart(), m_data.GetByteSize(),
615 m_data.GetByteOrder(), addr_byte_size);
616
617 lldb::offset_t offset = 0;
618 lldb::offset_t const_offset = 0;
619 lldb::addr_t const_value = 0;
620 size_t const_byte_size = 0;
621 while (m_data.ValidOffset(offset)) {
622 const LocationAtom op = static_cast<LocationAtom>(m_data.GetU8(&offset));
623
624 bool decoded_data = false;
625 switch (op) {
626 case DW_OP_const4u:
627 // Remember the const offset in case we later have a
628 // DW_OP_form_tls_address or DW_OP_GNU_push_tls_address
629 const_offset = offset;
630 const_value = m_data.GetU32(&offset);
631 decoded_data = true;
632 const_byte_size = 4;
633 break;
634
635 case DW_OP_const8u:
636 // Remember the const offset in case we later have a
637 // DW_OP_form_tls_address or DW_OP_GNU_push_tls_address
638 const_offset = offset;
639 const_value = m_data.GetU64(&offset);
640 decoded_data = true;
641 const_byte_size = 8;
642 break;
643
644 case DW_OP_form_tls_address:
645 case DW_OP_GNU_push_tls_address:
646 // DW_OP_form_tls_address and DW_OP_GNU_push_tls_address must be preceded
647 // by a file address on the stack. We assume that DW_OP_const4u or
648 // DW_OP_const8u is used for these values, and we check that the last
649 // opcode we got before either of these was DW_OP_const4u or
650 // DW_OP_const8u. If so, then we can link the value accordingly. For
651 // Darwin, the value in the DW_OP_const4u or DW_OP_const8u is the file
652 // address of a structure that contains a function pointer, the pthread
653 // key and the offset into the data pointed to by the pthread key. So we
654 // must link this address and also set the module of this expression to
655 // the new_module_sp so we can resolve the file address correctly
656 if (const_byte_size > 0) {
657 lldb::addr_t linked_file_addr = link_address_callback(const_value);
658 if (linked_file_addr == LLDB_INVALID_ADDRESS)
659 return false;
660 // Replace the address in the new buffer
661 if (encoder.PutUnsigned(const_offset, const_byte_size,
662 linked_file_addr) == UINT32_MAX)
663 return false;
664 }
665 break;
666
667 default:
668 const_offset = 0;
669 const_value = 0;
670 const_byte_size = 0;
671 break;
672 }
673
674 if (!decoded_data) {
675 const lldb::offset_t op_arg_size =
676 GetOpcodeDataSize(m_data, offset, op, dwarf_cu);
677 if (op_arg_size == LLDB_INVALID_OFFSET)
678 return false;
679 else
680 offset += op_arg_size;
681 }
682 }
683
684 m_data.SetData(encoder.GetDataBuffer());
685 return true;
686}
687
688/// Asks the language runtime of the current function to evaluate
689/// DW_OP_entry_value(\p entry_value), possibly together with some of the
690/// \p following operations, which it consumes.
691static std::optional<Value>
693 llvm::ArrayRef<uint8_t> entry_value,
694 llvm::ArrayRef<uint8_t> &following) {
695 if (!eval_ctx.frame || !eval_ctx.process)
696 return std::nullopt;
697 Function *function =
698 eval_ctx.frame->GetSymbolContext(eSymbolContextFunction).function;
699 if (!function)
700 return std::nullopt;
701 LanguageRuntime *runtime =
702 eval_ctx.process->GetLanguageRuntime(function->GetLanguage());
703 if (!runtime)
704 return std::nullopt;
705
706 llvm::ArrayRef<uint8_t> rest = following;
707 std::optional<Value> value =
708 runtime->EvaluateEntryValue(*eval_ctx.frame, entry_value, rest);
709 // The runtime may only consume operations from the front.
710 if (!value || rest.end() != following.end() || rest.size() > following.size())
711 return std::nullopt;
712 following = rest;
713 return value;
714}
715
716static llvm::Error Evaluate_DW_OP_entry_value(EvalContext &eval_ctx,
717 llvm::ArrayRef<uint8_t> subexpr) {
719 // DW_OP_entry_value(sub-expr) describes the location a variable had upon
720 // function entry: this variable location is presumed to be optimized out at
721 // the current PC value. The caller of the function may have call site
722 // information that describes an alternate location for the variable (e.g. a
723 // constant literal, or a spilled stack value) in the parent frame.
724 //
725 // Example (this is pseudo-code & pseudo-DWARF, but hopefully illustrative):
726 //
727 // void child(int &sink, int x) {
728 // ...
729 // /* "x" gets optimized out. */
730 //
731 // /* The location of "x" here is: DW_OP_entry_value($reg2). */
732 // ++sink;
733 // }
734 //
735 // void parent() {
736 // int sink;
737 //
738 // /*
739 // * The callsite information emitted here is:
740 // *
741 // * DW_TAG_call_site
742 // * DW_AT_return_pc ... (for "child(sink, 123);")
743 // * DW_TAG_call_site_parameter (for "sink")
744 // * DW_AT_location ($reg1)
745 // * DW_AT_call_value ($SP - 8)
746 // * DW_TAG_call_site_parameter (for "x")
747 // * DW_AT_location ($reg2)
748 // * DW_AT_call_value ($literal 123)
749 // *
750 // * DW_TAG_call_site
751 // * DW_AT_return_pc ... (for "child(sink, 456);")
752 // * ...
753 // */
754 // child(sink, 123);
755 // child(sink, 456);
756 // }
757 //
758 // When the program stops at "++sink" within `child`, the debugger determines
759 // the call site by analyzing the return address. Once the call site is found,
760 // the debugger determines which parameter is referenced by DW_OP_entry_value
761 // and evaluates the corresponding location for that parameter in `parent`.
762
763 // 1. Find the function which pushed the current frame onto the stack.
764 if ((!eval_ctx.exe_ctx || !eval_ctx.exe_ctx->HasTargetScope()) ||
765 !eval_ctx.reg_ctx) {
766 return llvm::createStringError("no exe/reg context");
767 }
768
769 StackFrame *current_frame = eval_ctx.exe_ctx->GetFramePtr();
770 Thread *thread = eval_ctx.exe_ctx->GetThreadPtr();
771 if (!current_frame || !thread)
772 return llvm::createStringError("no current frame/thread");
773
774 Target &target = eval_ctx.exe_ctx->GetTargetRef();
775 StackFrameSP parent_frame = nullptr;
776 addr_t return_pc = LLDB_INVALID_ADDRESS;
777 uint32_t current_frame_idx = current_frame->GetFrameIndex();
778
779 for (uint32_t parent_frame_idx = current_frame_idx + 1;; parent_frame_idx++) {
780 parent_frame = thread->GetStackFrameAtIndex(parent_frame_idx);
781 // If this is null, we're at the end of the stack.
782 if (!parent_frame)
783 break;
784
785 // Record the first valid return address, even if this is an inlined frame,
786 // in order to look up the associated call edge in the first non-inlined
787 // parent frame.
788 if (return_pc == LLDB_INVALID_ADDRESS) {
789 return_pc = parent_frame->GetFrameCodeAddress().GetLoadAddress(&target);
790 LLDB_LOG(log, "immediate ancestor with pc = {0:x}", return_pc);
791 }
792
793 // If we've found an inlined frame, skip it (these have no call site
794 // parameters).
795 if (parent_frame->IsInlined())
796 continue;
797
798 // We've found the first non-inlined parent frame.
799 break;
800 }
801 if (!parent_frame || !parent_frame->GetRegisterContext()) {
802 return llvm::createStringError("no parent frame with reg ctx");
803 }
804
805 Function *parent_func =
806 parent_frame->GetSymbolContext(eSymbolContextFunction).function;
807 if (!parent_func)
808 return llvm::createStringError("no parent function");
809
810 // 2. Find the call edge in the parent function responsible for creating the
811 // current activation.
812 Function *current_func =
813 current_frame->GetSymbolContext(eSymbolContextFunction).function;
814 if (!current_func)
815 return llvm::createStringError("no current function");
816
817 CallEdge *call_edge = nullptr;
818 ModuleList &modlist = target.GetImages();
819 ExecutionContext parent_exe_ctx = *eval_ctx.exe_ctx;
820 parent_exe_ctx.SetFrameSP(parent_frame);
821 if (!parent_frame->IsArtificial()) {
822 // If the parent frame is not artificial, the current activation may be
823 // produced by an ambiguous tail call. In this case, refuse to proceed.
824 call_edge = parent_func->GetCallEdgeForReturnAddress(return_pc, target);
825 if (!call_edge) {
826 return llvm::createStringErrorV(
827 "no call edge for retn-pc = {0:x} in parent frame {1}", return_pc,
828 parent_func->GetName());
829 }
830 SymbolContext callee = call_edge->GetCallee(modlist, parent_exe_ctx);
831 if (callee.function != current_func) {
832 return llvm::createStringError(
833 "ambiguous call sequence, can't find real parent frame");
834 }
835 } else {
836 // The StackFrameList solver machinery has deduced that an unambiguous tail
837 // call sequence that produced the current activation. The first edge in
838 // the parent that points to the current function must be valid.
839 for (auto &edge : parent_func->GetTailCallingEdges()) {
840 if (edge->GetCallee(modlist, parent_exe_ctx).function == current_func) {
841 call_edge = edge.get();
842 break;
843 }
844 }
845 }
846 if (!call_edge)
847 return llvm::createStringError("no unambiguous edge from parent "
848 "to current function");
849
850 // 3. Attempt to locate the DW_OP_entry_value expression in the set of
851 // available call site parameters. If found, evaluate the corresponding
852 // parameter in the context of the parent frame.
853 const CallSiteParameter *matched_param = nullptr;
854 for (const CallSiteParameter &param : call_edge->GetCallSiteParameters()) {
855 DataExtractor param_subexpr_extractor;
856 if (!param.LocationInCallee.GetExpressionData(param_subexpr_extractor))
857 continue;
858 lldb::offset_t param_subexpr_offset = 0;
859 const void *param_subexpr_data =
860 param_subexpr_extractor.GetData(&param_subexpr_offset, subexpr.size());
861 if (!param_subexpr_data ||
862 param_subexpr_extractor.BytesLeft(param_subexpr_offset) != 0)
863 continue;
864
865 // At this point, the DW_OP_entry_value sub-expression and the callee-side
866 // expression in the call site parameter are known to have the same length.
867 // Check whether they are equal.
868 //
869 // Note that an equality check is sufficient: the contents of the
870 // DW_OP_entry_value subexpression are only used to identify the right call
871 // site parameter in the parent, and do not require any special handling.
872 if (memcmp(subexpr.data(), param_subexpr_data, subexpr.size()) == 0) {
873 matched_param = &param;
874 break;
875 }
876 }
877 if (!matched_param)
878 return llvm::createStringError("no matching call site param found");
879
880 // TODO: Add support for DW_OP_push_object_address within a DW_OP_entry_value
881 // subexpresion whenever llvm does.
882 const DWARFExpressionList &param_expr = matched_param->LocationInCaller;
883
884 // Recurse through the public entry point so the call-site parameter is
885 // evaluated with a fresh EvalContext (separate stack and piece state).
886 llvm::Expected<Value> maybe_result = param_expr.Evaluate(
887 &parent_exe_ctx, parent_frame->GetRegisterContext().get(),
889 /*initial_value_ptr=*/nullptr,
890 /*object_address_ptr=*/nullptr);
891 if (!maybe_result) {
892 LLDB_LOG(log,
893 "Evaluate_DW_OP_entry_value: call site param evaluation failed");
894 return maybe_result.takeError();
895 }
896
897 eval_ctx.stack.push_back(*maybe_result);
898 return llvm::Error::success();
899}
900
901/// Adjust value's ValueType according to the kind of location description.
902static void UpdateValueTypeFromLocationDescription(EvalContext &eval_ctx,
903 LocationDescriptionKind kind,
904 Value *value = nullptr) {
905 // Note that this function is conflating DWARF expressions with
906 // DWARF location descriptions. Perhaps it would be better to define
907 // a wrapper for DWARFExpression::Eval() that deals with DWARF
908 // location descriptions (which consist of one or more DWARF
909 // expressions). But doing this would mean we'd also need factor the
910 // handling of DW_OP_(bit_)piece out of this function.
911 if (eval_ctx.dwarf_cu && eval_ctx.dwarf_cu->GetVersion() >= 4) {
913 const char *log_msg = "DWARF location description kind: %s";
914 switch (kind) {
915 case Empty:
916 LLDB_LOGF(log, log_msg, "Empty");
917 break;
918 case Memory:
919 LLDB_LOGF(log, log_msg, "Memory");
920 if (value->GetValueType() == Value::ValueType::Scalar)
921 value->SetValueType(Value::ValueType::LoadAddress);
922 break;
923 case Register:
924 LLDB_LOGF(log, log_msg, "Register");
925 value->SetValueType(Value::ValueType::Scalar);
926 break;
927 case Implicit:
928 LLDB_LOGF(log, log_msg, "Implicit");
929 if (value->GetValueType() == Value::ValueType::LoadAddress)
930 value->SetValueType(Value::ValueType::Scalar);
931 break;
932 }
933 }
934}
935
936/// Helper function to move common code used to resolve a file address and turn
937/// into a load address.
938///
939/// \param eval_ctx Evaluation context (provides exe_ctx and module_sp).
940/// \param dw_op_type C-style string used to vary the error output
941/// \param file_addr the file address we are trying to resolve and turn into a
942/// load address
943/// \param so_addr out parameter, will be set to load address or section offset
944/// \param check_sectionoffset bool which determines if having a section offset
945/// but not a load address is considerd a success
946/// \returns std::optional containing the load address if resolving and getting
947/// the load address succeed or an empty Optinal otherwise. If
948/// check_sectionoffset is true we consider LLDB_INVALID_ADDRESS a
949/// success if so_addr.IsSectionOffset() is true.
950static llvm::Expected<lldb::addr_t>
951ResolveLoadAddress(EvalContext &eval_ctx, const char *dw_op_type,
952 lldb::addr_t file_addr, Address &so_addr,
953 bool check_sectionoffset = false) {
954 if (!eval_ctx.module_sp)
955 return llvm::createStringError("need module to resolve file address for %s",
956 dw_op_type);
957
958 if (!eval_ctx.module_sp->ResolveFileAddress(file_addr, so_addr))
959 return llvm::createStringError("failed to resolve file address in module");
960
961 const addr_t load_addr = so_addr.GetLoadAddress(eval_ctx.target);
962
963 if (load_addr == LLDB_INVALID_ADDRESS &&
964 (check_sectionoffset && !so_addr.IsSectionOffset()))
965 return llvm::createStringError("failed to resolve load address");
966
967 return load_addr;
968}
969
970/// @brief Helper function to load sized data from a uint8_t buffer.
971///
972/// @param addr_bytes The buffer containing raw data.
973/// @param size_addr_bytes How large is the underlying raw data.
974/// @param byte_order What is the byte order of the underlying data.
975/// @param size How much of the underlying data we want to use.
976/// @return The underlying data converted into a Scalar.
977static Scalar DerefSizeExtractDataHelper(uint8_t *addr_bytes,
978 size_t size_addr_bytes,
979 ByteOrder byte_order, size_t size) {
980 DataExtractor addr_data(addr_bytes, size_addr_bytes, byte_order, size);
981
982 lldb::offset_t addr_data_offset = 0;
983 if (size <= 8)
984 return addr_data.GetMaxU64(&addr_data_offset, size);
985 return addr_data.GetAddress(&addr_data_offset);
986}
987
988static llvm::Error Evaluate_DW_OP_deref(EvalContext &eval_ctx,
989 LocationAtom opcode, unsigned size,
990 size_t size_addr_bytes) {
991 const char *op_name = DW_OP_value_to_name(opcode);
992 if (eval_ctx.stack.empty())
993 return llvm::createStringError("expression stack empty for %s", op_name);
994
995 if (size == 0 || size > 8)
996 return llvm::createStringError("Invalid address size for %s: %u", op_name,
997 size);
998
999 if (opcode == DW_OP_deref_size && size > size_addr_bytes)
1000 return llvm::createStringError(
1001 "DW_OP_deref_size size (%u) exceeds address size (%zu)", size,
1002 size_addr_bytes);
1003
1004 // Deref a register or implicit location and truncate the value to `size`
1005 // bytes. See the corresponding comment in DW_OP_deref for more details on
1006 // why we deref these locations this way.
1007 if (eval_ctx.loc_desc_kind == Register ||
1008 eval_ctx.loc_desc_kind == Implicit) {
1009 // Reset context to default values.
1010 eval_ctx.loc_desc_kind = Memory;
1011 eval_ctx.stack.back().ClearContext();
1012
1013 // Truncate the value on top of the stack to *size* bytes then
1014 // extend to the size of an address (e.g. generic type).
1015 Scalar scalar = eval_ctx.stack.back().GetScalar();
1016 scalar.TruncOrExtendTo(size * 8, /*sign=*/false);
1017 scalar.TruncOrExtendTo(size_addr_bytes * 8,
1018 /*sign=*/false);
1019 eval_ctx.stack.back().GetScalar() = scalar;
1020 return llvm::Error::success();
1021 }
1022
1023 Value::ValueType value_type = eval_ctx.stack.back().GetValueType();
1024 switch (value_type) {
1026 void *src = (void *)eval_ctx.stack.back().GetScalar().ULongLong();
1027 intptr_t ptr;
1028 ::memcpy(&ptr, src, sizeof(void *));
1029 // I can't decide whether the size operand should apply to the bytes in
1030 // their lldb-host endianness or the target endianness.. I doubt this'll
1031 // ever come up but I'll opt for assuming big endian regardless.
1032 switch (size) {
1033 case 1:
1034 ptr = ptr & 0xff;
1035 break;
1036 case 2:
1037 ptr = ptr & 0xffff;
1038 break;
1039 case 3:
1040 ptr = ptr & 0xffffff;
1041 break;
1042 case 4:
1043 ptr = ptr & 0xffffffff;
1044 break;
1045 // The casts are added to work around the case where intptr_t is a 32-bit
1046 // quantity. Presumably we won't hit the 5..7 cases if (void*) is 32-bits in
1047 // this program.
1048 case 5:
1049 ptr = (intptr_t)ptr & 0xffffffffffULL;
1050 break;
1051 case 6:
1052 ptr = (intptr_t)ptr & 0xffffffffffffULL;
1053 break;
1054 case 7:
1055 ptr = (intptr_t)ptr & 0xffffffffffffffULL;
1056 break;
1057 default:
1058 break;
1059 }
1060 eval_ctx.stack.back().GetScalar() = ptr;
1061 eval_ctx.stack.back().ClearContext();
1062 } break;
1064 auto file_addr =
1065 eval_ctx.stack.back().GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1066 Address so_addr;
1067 auto maybe_load_addr =
1068 ResolveLoadAddress(eval_ctx, op_name, file_addr, so_addr,
1069 /*check_sectionoffset=*/true);
1070
1071 if (!maybe_load_addr)
1072 return maybe_load_addr.takeError();
1073
1074 addr_t load_addr = *maybe_load_addr;
1075
1076 if (load_addr == LLDB_INVALID_ADDRESS && so_addr.IsSectionOffset()) {
1077 uint8_t addr_bytes[8];
1078 Status error;
1079
1080 if (!eval_ctx.target ||
1081 eval_ctx.target->ReadMemory(so_addr, &addr_bytes, size, error,
1082 /*force_live_memory=*/false) != size)
1083 return llvm::createStringError("failed to dereference pointer for %s: "
1084 "%s\n",
1085 op_name, error.AsCString());
1086
1087 ObjectFile *objfile = eval_ctx.module_sp->GetObjectFile();
1088
1089 eval_ctx.stack.back().GetScalar() = DerefSizeExtractDataHelper(
1090 addr_bytes, size, objfile->GetByteOrder(), size);
1091 eval_ctx.stack.back().ClearContext();
1092 break;
1093 }
1094 eval_ctx.stack.back().GetScalar() = load_addr;
1095 // Fall through to load address promotion code below.
1096 }
1097
1098 [[fallthrough]];
1100 // Promote Scalar to LoadAddress and fall through.
1101 eval_ctx.stack.back().SetValueType(Value::ValueType::LoadAddress);
1102 [[fallthrough]];
1104 if (!eval_ctx.exe_ctx)
1105 return llvm::createStringError("no execution context for %s", op_name);
1106 if (!eval_ctx.process)
1107 return llvm::createStringError("no process for %s", op_name);
1108
1109 lldb::addr_t pointer_addr =
1110 eval_ctx.stack.back().GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1111 uint8_t addr_bytes[sizeof(lldb::addr_t)];
1112 Status error;
1113
1114 if (eval_ctx.process->ReadMemory(pointer_addr, &addr_bytes, size, error) !=
1115 size)
1116 return llvm::createStringError(
1117 "failed to dereference pointer from 0x%" PRIx64 " for %s: %s\n",
1118 pointer_addr, op_name, error.AsCString());
1119
1120 eval_ctx.stack.back().GetScalar() = DerefSizeExtractDataHelper(
1121 addr_bytes, sizeof(addr_bytes), eval_ctx.process->GetByteOrder(), size);
1122 eval_ctx.stack.back().ClearContext();
1123 } break;
1124
1126 return llvm::createStringError("invalid value for %s", op_name);
1127 }
1128
1129 // Both operations push a generic, address-sized result. The truncation to
1130 // `size` bytes is unnecessary here because the branches above already limit
1131 // the value to `size` bytes; it is only done for consistency with the
1132 // Register/Implicit path above.
1133 eval_ctx.stack.back().GetScalar().TruncOrExtendTo(size * 8, /*sign=*/false);
1134 eval_ctx.stack.back().GetScalar().TruncOrExtendTo(size_addr_bytes * 8,
1135 /*sign=*/false);
1136 return llvm::Error::success();
1137}
1138
1139static std::optional<uint64_t> BitsToBytes(uint64_t bit_size) {
1140 if (bit_size > std::numeric_limits<uint64_t>::max() - 7)
1141 return std::nullopt;
1142 return (bit_size + 7) / 8;
1143}
1144
1145static uint8_t GetBitMask(uint64_t bit_offset, lldb::ByteOrder byte_order) {
1146 uint8_t bit_in_byte = bit_offset % 8;
1147 if (byte_order == lldb::eByteOrderBig)
1148 bit_in_byte = 7 - bit_in_byte;
1149 return static_cast<uint8_t>(1u << bit_in_byte);
1150}
1151
1152/// Appends an eagerly materialized piece at the next composite bit offset.
1153static llvm::Error AppendPieceToComposite(EvalContext &eval_ctx,
1154 const Value &piece,
1155 uint64_t piece_bit_size) {
1156 if (piece_bit_size == 0)
1157 return llvm::Error::success();
1158
1159 if (eval_ctx.byte_order != lldb::eByteOrderLittle &&
1160 eval_ctx.byte_order != lldb::eByteOrderBig)
1161 return llvm::createStringError(
1162 "unsupported byte order for composite DWARF piece");
1163
1164 if (eval_ctx.op_piece_bit_offset >
1165 std::numeric_limits<uint64_t>::max() - piece_bit_size)
1166 return llvm::createStringError("composite DWARF piece size overflow");
1167 const uint64_t next_bit_offset =
1168 eval_ctx.op_piece_bit_offset + piece_bit_size;
1169
1170 std::optional<uint64_t> current_byte_size =
1171 BitsToBytes(eval_ctx.op_piece_bit_offset);
1172 std::optional<uint64_t> next_byte_size = BitsToBytes(next_bit_offset);
1173 if (!current_byte_size || !next_byte_size ||
1174 *next_byte_size > std::numeric_limits<size_t>::max())
1175 return llvm::createStringError("composite DWARF piece size overflow");
1176 if (eval_ctx.pieces.GetBuffer().GetByteSize() != *current_byte_size)
1177 return llvm::createStringError(
1178 "composite DWARF piece buffer size does not match its bit offset");
1179
1180 const uint8_t *source_data = nullptr;
1181 uint64_t source_byte_size = 0;
1182 uint64_t source_bit_offset = 0;
1183 std::vector<uint8_t> scalar_data;
1184
1185 switch (piece.GetValueType()) {
1187 if (piece_bit_size > std::numeric_limits<uint16_t>::max())
1188 return llvm::createStringError("scalar DWARF piece is too large");
1189 std::optional<uint64_t> scalar_byte_size = BitsToBytes(piece_bit_size);
1190 if (!scalar_byte_size ||
1191 *scalar_byte_size > std::numeric_limits<size_t>::max())
1192 return llvm::createStringError("scalar DWARF piece is too large");
1193
1194 scalar_data.resize(static_cast<size_t>(*scalar_byte_size));
1195 Status error;
1196 if (piece.GetScalar().GetAsMemoryData(
1197 scalar_data.data(), scalar_data.size(), eval_ctx.byte_order,
1198 error) != scalar_data.size())
1199 return llvm::createStringError("failed to serialize scalar DWARF piece");
1200
1201 source_data = scalar_data.data();
1202 source_byte_size = scalar_data.size();
1203 // A partial-byte scalar occupies the least significant bits of its first
1204 // byte, which follow the leading padding bits in big-endian order.
1205 if (eval_ctx.byte_order == lldb::eByteOrderBig && piece_bit_size % 8)
1206 source_bit_offset = 8 - piece_bit_size % 8;
1207 break;
1208 }
1210 source_data = piece.GetBuffer().GetBytes();
1211 source_byte_size = piece.GetBuffer().GetByteSize();
1212 break;
1216 return llvm::createStringError(
1217 "unsupported value type for composite DWARF piece");
1218 }
1219
1220 if (source_bit_offset >
1221 std::numeric_limits<uint64_t>::max() - piece_bit_size ||
1222 source_byte_size > std::numeric_limits<uint64_t>::max() / 8 ||
1223 source_bit_offset + piece_bit_size > source_byte_size * 8)
1224 return llvm::createStringError("DWARF piece exceeds its source buffer");
1225
1226 if (eval_ctx.pieces.ResizeData(static_cast<size_t>(*next_byte_size)) !=
1227 *next_byte_size)
1228 return llvm::createStringError(
1229 "failed to resize composite DWARF piece buffer");
1230
1231 uint8_t *destination_data = eval_ctx.pieces.GetBuffer().GetBytes();
1232 if (eval_ctx.op_piece_bit_offset % 8 == 0 && source_bit_offset % 8 == 0 &&
1233 piece_bit_size % 8 == 0) {
1234 ::memcpy(destination_data + eval_ctx.op_piece_bit_offset / 8,
1235 source_data + source_bit_offset / 8, piece_bit_size / 8);
1236 } else {
1237 for (uint64_t i = 0; i < piece_bit_size; ++i) {
1238 const uint64_t source_offset = source_bit_offset + i;
1239 const uint64_t destination_offset = eval_ctx.op_piece_bit_offset + i;
1240 const bool bit = source_data[source_offset / 8] &
1241 GetBitMask(source_offset, eval_ctx.byte_order);
1242 uint8_t &destination_byte = destination_data[destination_offset / 8];
1243 const uint8_t destination_mask =
1244 GetBitMask(destination_offset, eval_ctx.byte_order);
1245 if (bit)
1246 destination_byte |= destination_mask;
1247 else
1248 destination_byte &= static_cast<uint8_t>(~destination_mask);
1249 }
1250 }
1251
1252 eval_ctx.op_piece_bit_offset = next_bit_offset;
1253 return llvm::Error::success();
1254}
1255
1256static llvm::Error Evaluate_DW_OP_piece(EvalContext &eval_ctx,
1257 uint64_t piece_byte_size) {
1258 LocationDescriptionKind piece_locdesc = eval_ctx.loc_desc_kind;
1259 // Reset for the next piece.
1260 eval_ctx.loc_desc_kind = Memory;
1261
1262 if (piece_byte_size == 0) {
1263 // A zero-sized piece contributes no data, but it still consumes its source
1264 // location description.
1265 if (!eval_ctx.stack.empty())
1266 eval_ctx.stack.pop_back();
1267 return llvm::Error::success();
1268 }
1269
1270 if (piece_byte_size > std::numeric_limits<uint64_t>::max() / 8 ||
1271 piece_byte_size > std::numeric_limits<size_t>::max())
1272 return llvm::createStringError("DW_OP_piece size overflow");
1273 const uint64_t piece_bit_size = piece_byte_size * 8;
1274
1275 Value curr_piece;
1276
1277 if (eval_ctx.stack.empty()) {
1279 LocationDescriptionKind::Empty);
1280 // In a multi-piece expression, this means that the current piece is
1281 // not available. Fill with zeros for now by resizing the data.
1282 curr_piece.ResizeData(piece_byte_size);
1283 // Note that "0" is not a correct value for the unknown bits.
1284 // It would be better to also return a mask of valid bits together
1285 // with the expression result, so the debugger can print missing
1286 // members as "<optimized out>" or something.
1287 ::memset(curr_piece.GetBuffer().GetBytes(), 0, piece_byte_size);
1288 } else {
1289 Status error;
1290 // Extract the current piece into "curr_piece"
1291 Value curr_piece_source_value(eval_ctx.stack.back());
1292 eval_ctx.stack.pop_back();
1293 UpdateValueTypeFromLocationDescription(eval_ctx, piece_locdesc,
1294 &curr_piece_source_value);
1295
1296 const Value::ValueType curr_piece_source_value_type =
1297 curr_piece_source_value.GetValueType();
1298 Scalar &scalar = curr_piece_source_value.GetScalar();
1300 switch (curr_piece_source_value_type) {
1302 return llvm::createStringError("invalid value type");
1304 if (eval_ctx.target) {
1305 curr_piece_source_value.ConvertToLoadAddress(eval_ctx.module_sp.get(),
1306 eval_ctx.target);
1307 addr = scalar.ULongLong(LLDB_INVALID_ADDRESS);
1308 } else {
1309 return llvm::createStringError(
1310 "unable to convert file address 0x%" PRIx64 " to load address "
1311 "for DW_OP_piece(%" PRIu64 "): "
1312 "no target available",
1313 addr, piece_byte_size);
1314 }
1315 [[fallthrough]];
1317 if (eval_ctx.target) {
1318 if (curr_piece.ResizeData(piece_byte_size) == piece_byte_size) {
1319 if (eval_ctx.target->ReadMemory(
1320 Address(addr), curr_piece.GetBuffer().GetBytes(),
1321 piece_byte_size, error,
1322 /*force_live_memory=*/false) != piece_byte_size) {
1323 const char *addr_type =
1324 (curr_piece_source_value_type == Value::ValueType::LoadAddress)
1325 ? "load"
1326 : "file";
1327 return llvm::createStringError(
1328 "failed to read memory DW_OP_piece(%" PRIu64
1329 ") from %s address 0x%" PRIx64,
1330 piece_byte_size, addr_type, addr);
1331 }
1332 } else {
1333 return llvm::createStringError(
1334 "failed to resize the piece memory buffer for "
1335 "DW_OP_piece(%" PRIu64 ")",
1336 piece_byte_size);
1337 }
1338 }
1339 } break;
1341 // DW_OP_implicit_value uses a host-address Value to own its bytes. For
1342 // a full-width piece, the address is only an implementation detail and
1343 // the backing bytes are the value of the piece.
1344 if (piece_locdesc == Implicit &&
1345 curr_piece_source_value.GetBuffer().GetByteSize() ==
1346 piece_byte_size) {
1347 curr_piece = curr_piece_source_value;
1348 break;
1349 }
1350 return llvm::createStringError(
1351 "failed to read memory DW_OP_piece(%" PRIu64
1352 ") from host address 0x%" PRIx64,
1353 piece_byte_size, addr);
1354 } break;
1355
1357 if (piece_bit_size > std::numeric_limits<uint16_t>::max())
1358 return llvm::createStringError("scalar DW_OP_piece is too large");
1359 const uint32_t bit_size = static_cast<uint32_t>(piece_bit_size);
1360 uint32_t bit_offset = 0;
1361 if (!scalar.ExtractBitfield(bit_size, bit_offset)) {
1362 return llvm::createStringError(
1363 "unable to extract %" PRIu64 " bytes from a %" PRIu64
1364 " byte scalar value.",
1365 piece_byte_size,
1366 (uint64_t)curr_piece_source_value.GetScalar().GetByteSize());
1367 }
1368
1369 // We have seen a case where we have expression like:
1370 // DW_OP_lit0, DW_OP_stack_value, DW_OP_piece 0x28
1371 // here we are assuming the compiler was trying to zero
1372 // extend the value that we should append to the buffer.
1373 scalar.TruncOrExtendTo(bit_size, /*sign=*/false);
1374 curr_piece.GetScalar() = scalar;
1375 } break;
1376 }
1377 }
1378 return AppendPieceToComposite(eval_ctx, curr_piece, piece_bit_size);
1379}
1380
1381static llvm::Error Evaluate_DW_OP_convert(EvalContext &eval_ctx,
1382 uint64_t relative_die_offset) {
1383 uint64_t bit_size;
1384 llvm::dwarf::TypeKind encoding;
1385 if (relative_die_offset == 0) {
1386 // The generic type has the size of an address on the target
1387 // machine and an unspecified signedness. Scalar has no
1388 // "unspecified signedness", so we use unsigned types.
1389 if (!eval_ctx.module_sp)
1390 return llvm::createStringError("no module");
1391 encoding = llvm::dwarf::DW_ATE_unsigned;
1392 bit_size = eval_ctx.module_sp->GetArchitecture().GetAddressByteSize() * 8;
1393 if (!bit_size)
1394 return llvm::createStringError("unspecified architecture");
1395 } else {
1396 if (!eval_ctx.dwarf_cu)
1397 return llvm::createStringError(
1398 "DW_OP_convert with a DIE offset requires a DWARF unit");
1399 auto bit_size_encoding_or_err =
1400 eval_ctx.dwarf_cu->GetDIEBitSizeAndEncoding(relative_die_offset);
1401 if (!bit_size_encoding_or_err)
1402 return bit_size_encoding_or_err.takeError();
1403 bit_size = bit_size_encoding_or_err->first;
1404 encoding = bit_size_encoding_or_err->second;
1405 }
1406
1407 Scalar &scalar = eval_ctx.stack.back().GetScalar();
1408 if (encoding == llvm::dwarf::DW_ATE_float) {
1409 const llvm::fltSemantics *semantics;
1410 switch (bit_size) {
1411 case 32:
1412 semantics = &llvm::APFloat::IEEEsingle();
1413 break;
1414 case 64:
1415 semantics = &llvm::APFloat::IEEEdouble();
1416 break;
1417 case 80:
1418 semantics = &llvm::APFloat::x87DoubleExtended();
1419 break;
1420 default:
1421 return llvm::createStringError("unsupported floating-point type size");
1422 }
1423
1424 if (scalar.GetType() == Scalar::e_float) {
1425 llvm::APFloat value = scalar.GetAPFloat();
1426 bool loses_info;
1427 value.convert(*semantics, llvm::APFloat::rmNearestTiesToEven,
1428 &loses_info);
1429 scalar = Scalar(std::move(value));
1430 } else if (!scalar.FloatPromote(*semantics)) {
1431 return llvm::createStringError("cannot convert value to floating point");
1432 }
1433 return llvm::Error::success();
1434 }
1435
1436 const bool sign = encoding == llvm::dwarf::DW_ATE_signed ||
1437 encoding == llvm::dwarf::DW_ATE_signed_char;
1438 if (scalar.GetType() == Scalar::e_float) {
1439 if (bit_size > std::numeric_limits<uint16_t>::max())
1440 return llvm::createStringError("unsupported integer type size: %" PRIu64,
1441 bit_size);
1442
1443 llvm::APSInt value(static_cast<unsigned>(bit_size),
1444 /*isUnsigned=*/!sign);
1445 bool is_exact;
1446 llvm::APFloat::opStatus status = scalar.GetAPFloat().convertToInteger(
1447 value, llvm::APFloat::rmTowardZero, &is_exact);
1448 if (status & llvm::APFloat::opInvalidOp)
1449 return llvm::createStringError(
1450 "cannot convert floating-point value to integer");
1451 scalar = Scalar(std::move(value));
1452 } else {
1453 scalar.TruncOrExtendTo(bit_size, sign);
1454 }
1455 return llvm::Error::success();
1456}
1457
1458static llvm::Error Evaluate_DW_OP_form_tls_address(EvalContext &eval_ctx,
1459 LocationAtom opcode) {
1460 if (eval_ctx.stack.empty())
1461 return llvm::createStringError("%s needs an argument",
1462 opcode == DW_OP_form_tls_address
1463 ? "DW_OP_form_tls_address"
1464 : "DW_OP_GNU_push_tls_address");
1465
1466 if (!eval_ctx.exe_ctx || !eval_ctx.module_sp)
1467 return llvm::createStringError("no context to evaluate TLS within");
1468
1469 Thread *thread = eval_ctx.exe_ctx->GetThreadPtr();
1470 if (!thread)
1471 return llvm::createStringError("no thread to evaluate TLS within");
1472
1473 // Lookup the TLS block address for this thread and module.
1474 const addr_t tls_file_addr =
1475 eval_ctx.stack.back().GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1476 const addr_t tls_load_addr =
1477 thread->GetThreadLocalData(eval_ctx.module_sp, tls_file_addr);
1478
1479 if (tls_load_addr == LLDB_INVALID_ADDRESS)
1480 return llvm::createStringError(
1481 "no TLS data currently exists for this thread");
1482
1483 eval_ctx.stack.back().GetScalar() = tls_load_addr;
1484 eval_ctx.stack.back().SetValueType(Value::ValueType::LoadAddress);
1485 return llvm::Error::success();
1486}
1487
1488static llvm::Error Evaluate_DW_OP_fbreg(EvalContext &eval_ctx,
1489 int64_t fbreg_offset) {
1490 if (!eval_ctx.exe_ctx)
1491 return llvm::createStringError("NULL execution context for DW_OP_fbreg");
1492 if (!eval_ctx.frame)
1493 return llvm::createStringError(
1494 "invalid stack frame in context for DW_OP_fbreg opcode");
1495
1496 Scalar value;
1497 if (llvm::Error err = eval_ctx.frame->GetFrameBaseValue(value))
1498 return err;
1499 value += fbreg_offset;
1500 eval_ctx.stack.push_back(value);
1501 eval_ctx.stack.back().SetValueType(Value::ValueType::LoadAddress);
1502 return llvm::Error::success();
1503}
1504
1505static llvm::Error Evaluate_DW_OP_call_frame_cfa(EvalContext &eval_ctx) {
1506 if (!eval_ctx.frame)
1507 return llvm::createStringError(
1508 "invalid stack frame in context for DW_OP_call_frame_cfa opcode");
1509
1510 // Note that we don't have to parse FDEs because this DWARF expression
1511 // is commonly evaluated with a valid stack frame.
1512 StackID id = eval_ctx.frame->GetStackID();
1513 addr_t cfa = id.GetCallFrameAddressWithMetadata();
1514 // Fail for tail call frames too: they borrow the CFA of the frame that
1515 // reused their stack, so locations computed from it point into that frame.
1516 if (cfa == LLDB_INVALID_ADDRESS || id.GetTailCallDepth())
1517 return llvm::createStringError("stack frame does not include a canonical "
1518 "frame address for DW_OP_call_frame_cfa "
1519 "opcode");
1520
1521 eval_ctx.stack.push_back(Scalar(cfa));
1522 eval_ctx.stack.back().SetValueType(Value::ValueType::LoadAddress);
1523 return llvm::Error::success();
1524}
1525
1526static llvm::Error CheckScalarOperandsHaveSameType(const Scalar &lhs,
1527 const Scalar &rhs,
1528 LocationAtom opcode,
1529 size_t address_size) {
1530 auto mismatch = [&](const char *what) {
1531 return llvm::createStringError("%s requires operands to have the same %s",
1532 DW_OP_value_to_name(opcode), what);
1533 };
1534
1535 // Scalar does not preserve the original DWARF DIE, but it does carry the
1536 // pieces of base-type information used by the evaluator: kind, size, and
1537 // integer signedness.
1538 if (lhs.GetType() != rhs.GetType())
1539 return mismatch("type");
1540
1541 // Only integer scalars have signedness. Non-integer operands (e.g. floats)
1542 // have no further scalar type information to compare once kind and size
1543 // match.
1544 if (lhs.GetType() != Scalar::e_int) {
1545 if (lhs.GetByteSize() != rhs.GetByteSize())
1546 return mismatch("size");
1547 return llvm::Error::success();
1548 }
1549
1550 // DWARF generic values are address-sized integers with unspecified
1551 // signedness. LLDB does not explicitly preserve genericness on the
1552 // expression stack, so treat integers at least as wide as the generic type
1553 // as potentially generic and compatible with one another, regardless of
1554 // exact width or signedness. This keeps common expressions working: e.g.
1555 // DW_OP_breg produces a register-sized value while DW_OP_const* produces an
1556 // address-sized one, yet both are meant to be generic. DW_OP_constu and
1557 // DW_OP_consts also do not always use to_generic due to
1558 // https://github.com/llvm/llvm-project/issues/47431. A precise fix would
1559 // require tracking genericness directly, which is a larger type-system
1560 // change.
1561 if (address_size != 0 && lhs.GetByteSize() >= address_size &&
1562 rhs.GetByteSize() >= address_size)
1563 return llvm::Error::success();
1564
1565 // For non-generic integer operands, size and signedness are part of the
1566 // base-type information preserved by Scalar, so require them to match.
1567 if (lhs.GetByteSize() != rhs.GetByteSize())
1568 return mismatch("size");
1569 if (lhs.IsSigned() != rhs.IsSigned())
1570 return mismatch("signedness");
1571
1572 return llvm::Error::success();
1573}
1574
1575// Scalar does not preserve DWARF's generic type identifier. Since generic
1576// values are address-sized integers, use the scalar kind and width as an
1577// approximation.
1579 size_t address_size) {
1580 return address_size != 0 && operand.GetType() == Scalar::e_int &&
1581 operand.GetByteSize() == address_size;
1582}
1583
1584llvm::Expected<Value> DWARFExpression::Evaluate(
1585 ExecutionContext *exe_ctx, RegisterContext *reg_ctx,
1586 lldb::ModuleSP module_sp, const DataExtractor &opcodes,
1587 const DWARFExpression::Delegate *dwarf_cu,
1588 const lldb::RegisterKind reg_kind, const Value *initial_value_ptr,
1589 const Value *object_address_ptr) {
1590 uint32_t address_size = opcodes.GetAddressByteSize();
1591 llvm::DataExtractor expr_data = opcodes.GetAsLLVM();
1592 llvm::DWARFExpression expr(expr_data, address_size);
1593
1594 if (expr_data.size() == 0)
1595 return llvm::createStringError(
1596 "no location, value may have been optimized out");
1597
1598 EvalContext eval_ctx(exe_ctx, reg_ctx, std::move(module_sp), dwarf_cu,
1599 reg_kind, opcodes.GetByteOrder(), initial_value_ptr,
1600 object_address_ptr);
1601
1602 Stack &stack = eval_ctx.stack;
1603
1604 if (initial_value_ptr)
1605 stack.push_back(*initial_value_ptr);
1606
1607 Value tmp;
1608 uint32_t reg_num;
1609
1611 // A generic type is "an integral type that has the size of an address and an
1612 // unspecified signedness". For now, just use the signedness of the operand.
1613 // TODO: Implement a real typed stack, and store the genericness of the value
1614 // there.
1615 auto to_generic = [&](auto v) {
1616 // TODO: Avoid implicit trunc?
1617 // See https://github.com/llvm/llvm-project/issues/112510.
1618 bool is_signed = std::is_signed<decltype(v)>::value;
1619 return Scalar(llvm::APSInt(
1620 llvm::APInt(8 * address_size, v, is_signed, /*implicitTrunc=*/true),
1621 !is_signed));
1622 };
1623
1624 llvm::DWARFExpression::iterator op = expr.begin(), op_end = expr.end();
1625 while (op != op_end) {
1626 const uint64_t op_offset = op.getOffset();
1627 const LocationAtom opcode = static_cast<LocationAtom>(op->getCode());
1628
1629 if (log && log->GetVerbose()) {
1630 size_t count = stack.size();
1631 LLDB_LOGF(log, "Stack before operation has %" PRIu64 " values:",
1632 static_cast<uint64_t>(count));
1633 for (size_t i = 0; i < count; ++i) {
1634 StreamString new_value;
1635 new_value.Printf("[%" PRIu64 "]", static_cast<uint64_t>(i));
1636 stack[i].Dump(&new_value);
1637 LLDB_LOGF(log, " %s", new_value.GetData());
1638 }
1639 LLDB_LOGF(log, "0x%8.8" PRIx64 ": %s", op_offset,
1640 DW_OP_value_to_name(opcode));
1641 }
1642
1643 if (std::optional<unsigned> arity = OperationArity(opcode)) {
1644 if (stack.size() < *arity)
1645 return llvm::createStringError(
1646 "%s needs at least %d stack entries (stack has %d entries)",
1647 DW_OP_value_to_name(opcode), *arity, stack.size());
1648 }
1649
1650 switch (opcode) {
1651 case DW_OP_addr:
1652 stack.push_back(to_generic(op->getRawOperand(0)));
1653 stack.back().SetValueType(Value::ValueType::FileAddress);
1654 break;
1655
1656 case DW_OP_deref: {
1657 size_t size = address_size;
1658 if (llvm::Error err = Evaluate_DW_OP_deref(eval_ctx, opcode, size, size))
1659 return err;
1660 } break;
1661
1662 case DW_OP_deref_size: {
1663 size_t size = op->getRawOperand(0);
1664 if (llvm::Error err =
1665 Evaluate_DW_OP_deref(eval_ctx, opcode, size, address_size))
1666 return err;
1667 } break;
1668
1669 case DW_OP_const1u:
1670 stack.push_back(to_generic(op->getRawOperand(0)));
1671 break;
1672 case DW_OP_const1s:
1673 stack.push_back(to_generic(static_cast<int8_t>(op->getRawOperand(0))));
1674 break;
1675 case DW_OP_const2u:
1676 stack.push_back(to_generic(op->getRawOperand(0)));
1677 break;
1678 case DW_OP_const2s:
1679 stack.push_back(to_generic(static_cast<int16_t>(op->getRawOperand(0))));
1680 break;
1681 case DW_OP_const4u:
1682 stack.push_back(to_generic(op->getRawOperand(0)));
1683 break;
1684 case DW_OP_const4s:
1685 stack.push_back(to_generic(static_cast<int32_t>(op->getRawOperand(0))));
1686 break;
1687 case DW_OP_const8u:
1688 stack.push_back(to_generic(op->getRawOperand(0)));
1689 break;
1690 case DW_OP_const8s:
1691 stack.push_back(to_generic(static_cast<int64_t>(op->getRawOperand(0))));
1692 break;
1693 case DW_OP_constu:
1694 stack.push_back(to_generic(op->getRawOperand(0)));
1695 break;
1696 case DW_OP_consts:
1697 stack.push_back(to_generic(static_cast<int64_t>(op->getRawOperand(0))));
1698 break;
1699
1700 case DW_OP_dup:
1701 if (stack.empty()) {
1702 return llvm::createStringError("expression stack empty for DW_OP_dup");
1703 } else
1704 stack.push_back(stack.back());
1705 break;
1706
1707 case DW_OP_drop:
1708 if (stack.empty()) {
1709 return llvm::createStringError("expression stack empty for DW_OP_drop");
1710 } else
1711 stack.pop_back();
1712 break;
1713
1714 case DW_OP_over:
1715 stack.push_back(stack[stack.size() - 2]);
1716 break;
1717
1718 case DW_OP_pick: {
1719 uint8_t pick_idx = op->getRawOperand(0);
1720 if (pick_idx < stack.size())
1721 stack.push_back(stack[stack.size() - 1 - pick_idx]);
1722 else {
1723 return llvm::createStringError(
1724 "Index %u out of range for DW_OP_pick.\n", pick_idx);
1725 }
1726 } break;
1727
1728 case DW_OP_swap:
1729 tmp = stack.back();
1730 stack.back() = stack[stack.size() - 2];
1731 stack[stack.size() - 2] = tmp;
1732 break;
1733
1734 case DW_OP_rot: {
1735 size_t last_idx = stack.size() - 1;
1736 Value old_top = stack[last_idx];
1737 stack[last_idx] = stack[last_idx - 1];
1738 stack[last_idx - 1] = stack[last_idx - 2];
1739 stack[last_idx - 2] = old_top;
1740 } break;
1741
1742 case DW_OP_abs:
1743 if (!stack.back().GetScalar().AbsoluteValue()) {
1744 return llvm::createStringError(
1745 "failed to take the absolute value of the first stack item");
1746 }
1747 break;
1748
1749 case DW_OP_and:
1750 if (llvm::Error err = CheckScalarOperandsHaveSameType(
1751 stack[stack.size() - 2].GetScalar(), stack.back().GetScalar(),
1752 opcode, address_size))
1753 return err;
1754 tmp = stack.back();
1755 stack.pop_back();
1756 stack.back().GetScalar() = stack.back().GetScalar() & tmp.GetScalar();
1757 break;
1758
1759 case DW_OP_div: {
1760 if (llvm::Error err = CheckScalarOperandsHaveSameType(
1761 stack[stack.size() - 2].GetScalar(), stack.back().GetScalar(),
1762 opcode, address_size))
1763 return err;
1764 tmp = stack.back();
1765 if (tmp.GetScalar().IsZero())
1766 return llvm::createStringError("divide by zero");
1767
1768 stack.pop_back();
1769 Scalar divisor, dividend;
1770 divisor = tmp.GetScalar();
1771 dividend = stack.back().GetScalar();
1772 divisor.MakeSigned();
1773 dividend.MakeSigned();
1774 stack.back() = dividend / divisor;
1775
1776 if (!stack.back().GetScalar().IsValid())
1777 return llvm::createStringError("divide failed");
1778 } break;
1779
1780 case DW_OP_minus:
1781 if (llvm::Error err = CheckScalarOperandsHaveSameType(
1782 stack[stack.size() - 2].GetScalar(), stack.back().GetScalar(),
1783 opcode, address_size))
1784 return err;
1785 tmp = stack.back();
1786 stack.pop_back();
1787 stack.back().GetScalar() = stack.back().GetScalar() - tmp.GetScalar();
1788 break;
1789
1790 case DW_OP_mod:
1791 if (llvm::Error err = CheckScalarOperandsHaveSameType(
1792 stack[stack.size() - 2].GetScalar(), stack.back().GetScalar(),
1793 opcode, address_size))
1794 return err;
1795 tmp = stack.back();
1796 stack.pop_back();
1797 if (IsPotentiallyGenericIntegerOperand(tmp.GetScalar(), address_size) &&
1798 IsPotentiallyGenericIntegerOperand(stack.back().GetScalar(),
1799 address_size)) {
1800 tmp.GetScalar().MakeUnsigned();
1801 stack.back().GetScalar().MakeUnsigned();
1802 }
1803 stack.back().GetScalar() = stack.back().GetScalar() % tmp.GetScalar();
1804 break;
1805
1806 case DW_OP_mul:
1807 if (llvm::Error err = CheckScalarOperandsHaveSameType(
1808 stack[stack.size() - 2].GetScalar(), stack.back().GetScalar(),
1809 opcode, address_size))
1810 return err;
1811 tmp = stack.back();
1812 stack.pop_back();
1813 stack.back().GetScalar() = stack.back().GetScalar() * tmp.GetScalar();
1814 break;
1815
1816 case DW_OP_neg:
1817 if (!stack.back().GetScalar().UnaryNegate())
1818 return llvm::createStringError("unary negate failed");
1819 break;
1820
1821 case DW_OP_not:
1822 if (!stack.back().GetScalar().OnesComplement())
1823 return llvm::createStringError("logical NOT failed");
1824 break;
1825
1826 case DW_OP_or:
1827 if (llvm::Error err = CheckScalarOperandsHaveSameType(
1828 stack[stack.size() - 2].GetScalar(), stack.back().GetScalar(),
1829 opcode, address_size))
1830 return err;
1831 tmp = stack.back();
1832 stack.pop_back();
1833 stack.back().GetScalar() = stack.back().GetScalar() | tmp.GetScalar();
1834 break;
1835
1836 case DW_OP_plus:
1837 if (llvm::Error err = CheckScalarOperandsHaveSameType(
1838 stack[stack.size() - 2].GetScalar(), stack.back().GetScalar(),
1839 opcode, address_size))
1840 return err;
1841 tmp = stack.back();
1842 stack.pop_back();
1843 stack.back().GetScalar() += tmp.GetScalar();
1844 break;
1845
1846 case DW_OP_plus_uconst: {
1847 const uint64_t uconst_value = op->getRawOperand(0);
1848 Scalar &operand = stack.back().GetScalar();
1849 Scalar addend(uconst_value);
1850 // The addend is interpreted as the same type as the popped operand
1851 // (DWARF v5, 2.5.1.4). Give it the operand's exact integer type so
1852 // the addition keeps the operand's width and wraparound semantics
1853 // instead of promoting to a 64-bit unsigned value.
1854 if (operand.GetType() == Scalar::e_int)
1855 addend.TruncOrExtendTo(operand.GetAPSInt().getBitWidth(),
1856 operand.GetAPSInt().isSigned());
1857 operand += addend;
1858 if (!operand.IsValid())
1859 return llvm::createStringError("DW_OP_plus_uconst failed");
1860 } break;
1861
1862 case DW_OP_shl:
1863 if (llvm::Error err = CheckScalarOperandsHaveSameType(
1864 stack[stack.size() - 2].GetScalar(), stack.back().GetScalar(),
1865 opcode, address_size))
1866 return err;
1867 tmp = stack.back();
1868 stack.pop_back();
1869 stack.back().GetScalar() <<= tmp.GetScalar();
1870 break;
1871
1872 case DW_OP_shr:
1873 if (llvm::Error err = CheckScalarOperandsHaveSameType(
1874 stack[stack.size() - 2].GetScalar(), stack.back().GetScalar(),
1875 opcode, address_size))
1876 return err;
1877 tmp = stack.back();
1878 stack.pop_back();
1879 if (!stack.back().GetScalar().ShiftRightLogical(tmp.GetScalar()))
1880 return llvm::createStringError("DW_OP_shr failed");
1881 break;
1882
1883 case DW_OP_shra:
1884 if (llvm::Error err = CheckScalarOperandsHaveSameType(
1885 stack[stack.size() - 2].GetScalar(), stack.back().GetScalar(),
1886 opcode, address_size))
1887 return err;
1888 tmp = stack.back();
1889 stack.pop_back();
1890 stack.back().GetScalar() >>= tmp.GetScalar();
1891 break;
1892
1893 case DW_OP_xor:
1894 if (llvm::Error err = CheckScalarOperandsHaveSameType(
1895 stack[stack.size() - 2].GetScalar(), stack.back().GetScalar(),
1896 opcode, address_size))
1897 return err;
1898 tmp = stack.back();
1899 stack.pop_back();
1900 stack.back().GetScalar() = stack.back().GetScalar() ^ tmp.GetScalar();
1901 break;
1902
1903 case DW_OP_skip: {
1904 int16_t skip_offset = static_cast<int16_t>(op->getRawOperand(0));
1905 lldb::offset_t new_offset = op->getEndOffset() + skip_offset;
1906 // New offset can point at the end of the data, in this case we should
1907 // terminate the DWARF expression evaluation (will happen in the loop
1908 // condition).
1909 if (new_offset <= expr_data.size()) {
1910 op = op.skipBytes(skip_offset);
1911 continue;
1912 }
1913 return llvm::createStringErrorV(
1914 "Invalid opcode offset in DW_OP_skip: {0}+({1}) > {2}",
1915 op->getEndOffset(), skip_offset, expr_data.size());
1916 }
1917
1918 case DW_OP_bra: {
1919 tmp = stack.back();
1920 stack.pop_back();
1921 int16_t bra_offset = static_cast<int16_t>(op->getRawOperand(0));
1922 Scalar zero(0);
1923 if (tmp.GetScalar() != zero) {
1924 lldb::offset_t new_offset = op->getEndOffset() + bra_offset;
1925 // New offset can point at the end of the data, in this case we should
1926 // terminate the DWARF expression evaluation (will happen in the loop
1927 // condition).
1928 if (new_offset <= expr_data.size()) {
1929 op = op.skipBytes(bra_offset);
1930 continue;
1931 }
1932 return llvm::createStringErrorV(
1933 "Invalid opcode offset in DW_OP_bra: {0}+({1}) > {2}",
1934 op->getEndOffset(), bra_offset, expr_data.size());
1935 }
1936 } break;
1937
1938 case DW_OP_eq:
1939 if (llvm::Error err = CheckScalarOperandsHaveSameType(
1940 stack[stack.size() - 2].GetScalar(), stack.back().GetScalar(),
1941 opcode, address_size))
1942 return err;
1943 tmp = stack.back();
1944 stack.pop_back();
1945 stack.back().GetScalar() =
1946 to_generic(stack.back().GetScalar() == tmp.GetScalar());
1947 break;
1948
1949 case DW_OP_ge:
1950 if (llvm::Error err = CheckScalarOperandsHaveSameType(
1951 stack[stack.size() - 2].GetScalar(), stack.back().GetScalar(),
1952 opcode, address_size))
1953 return err;
1954 tmp = stack.back();
1955 stack.pop_back();
1956 if (IsPotentiallyGenericIntegerOperand(tmp.GetScalar(), address_size) &&
1957 IsPotentiallyGenericIntegerOperand(stack.back().GetScalar(),
1958 address_size)) {
1959 tmp.GetScalar().MakeSigned();
1960 stack.back().GetScalar().MakeSigned();
1961 }
1962 stack.back().GetScalar() =
1963 to_generic(stack.back().GetScalar() >= tmp.GetScalar());
1964 break;
1965
1966 case DW_OP_gt:
1967 if (llvm::Error err = CheckScalarOperandsHaveSameType(
1968 stack[stack.size() - 2].GetScalar(), stack.back().GetScalar(),
1969 opcode, address_size))
1970 return err;
1971 tmp = stack.back();
1972 stack.pop_back();
1973 if (IsPotentiallyGenericIntegerOperand(tmp.GetScalar(), address_size) &&
1974 IsPotentiallyGenericIntegerOperand(stack.back().GetScalar(),
1975 address_size)) {
1976 tmp.GetScalar().MakeSigned();
1977 stack.back().GetScalar().MakeSigned();
1978 }
1979 stack.back().GetScalar() =
1980 to_generic(stack.back().GetScalar() > tmp.GetScalar());
1981 break;
1982
1983 case DW_OP_le:
1984 if (llvm::Error err = CheckScalarOperandsHaveSameType(
1985 stack[stack.size() - 2].GetScalar(), stack.back().GetScalar(),
1986 opcode, address_size))
1987 return err;
1988 tmp = stack.back();
1989 stack.pop_back();
1990 if (IsPotentiallyGenericIntegerOperand(tmp.GetScalar(), address_size) &&
1991 IsPotentiallyGenericIntegerOperand(stack.back().GetScalar(),
1992 address_size)) {
1993 tmp.GetScalar().MakeSigned();
1994 stack.back().GetScalar().MakeSigned();
1995 }
1996 stack.back().GetScalar() =
1997 to_generic(stack.back().GetScalar() <= tmp.GetScalar());
1998 break;
1999
2000 case DW_OP_lt:
2001 if (llvm::Error err = CheckScalarOperandsHaveSameType(
2002 stack[stack.size() - 2].GetScalar(), stack.back().GetScalar(),
2003 opcode, address_size))
2004 return err;
2005 tmp = stack.back();
2006 stack.pop_back();
2007 if (IsPotentiallyGenericIntegerOperand(tmp.GetScalar(), address_size) &&
2008 IsPotentiallyGenericIntegerOperand(stack.back().GetScalar(),
2009 address_size)) {
2010 tmp.GetScalar().MakeSigned();
2011 stack.back().GetScalar().MakeSigned();
2012 }
2013 stack.back().GetScalar() =
2014 to_generic(stack.back().GetScalar() < tmp.GetScalar());
2015 break;
2016
2017 case DW_OP_ne:
2018 if (llvm::Error err = CheckScalarOperandsHaveSameType(
2019 stack[stack.size() - 2].GetScalar(), stack.back().GetScalar(),
2020 opcode, address_size))
2021 return err;
2022 tmp = stack.back();
2023 stack.pop_back();
2024 stack.back().GetScalar() =
2025 to_generic(stack.back().GetScalar() != tmp.GetScalar());
2026 break;
2027
2028 case DW_OP_lit0:
2029 case DW_OP_lit1:
2030 case DW_OP_lit2:
2031 case DW_OP_lit3:
2032 case DW_OP_lit4:
2033 case DW_OP_lit5:
2034 case DW_OP_lit6:
2035 case DW_OP_lit7:
2036 case DW_OP_lit8:
2037 case DW_OP_lit9:
2038 case DW_OP_lit10:
2039 case DW_OP_lit11:
2040 case DW_OP_lit12:
2041 case DW_OP_lit13:
2042 case DW_OP_lit14:
2043 case DW_OP_lit15:
2044 case DW_OP_lit16:
2045 case DW_OP_lit17:
2046 case DW_OP_lit18:
2047 case DW_OP_lit19:
2048 case DW_OP_lit20:
2049 case DW_OP_lit21:
2050 case DW_OP_lit22:
2051 case DW_OP_lit23:
2052 case DW_OP_lit24:
2053 case DW_OP_lit25:
2054 case DW_OP_lit26:
2055 case DW_OP_lit27:
2056 case DW_OP_lit28:
2057 case DW_OP_lit29:
2058 case DW_OP_lit30:
2059 case DW_OP_lit31:
2060 stack.push_back(to_generic(opcode - DW_OP_lit0));
2061 break;
2062
2063 case DW_OP_reg0:
2064 case DW_OP_reg1:
2065 case DW_OP_reg2:
2066 case DW_OP_reg3:
2067 case DW_OP_reg4:
2068 case DW_OP_reg5:
2069 case DW_OP_reg6:
2070 case DW_OP_reg7:
2071 case DW_OP_reg8:
2072 case DW_OP_reg9:
2073 case DW_OP_reg10:
2074 case DW_OP_reg11:
2075 case DW_OP_reg12:
2076 case DW_OP_reg13:
2077 case DW_OP_reg14:
2078 case DW_OP_reg15:
2079 case DW_OP_reg16:
2080 case DW_OP_reg17:
2081 case DW_OP_reg18:
2082 case DW_OP_reg19:
2083 case DW_OP_reg20:
2084 case DW_OP_reg21:
2085 case DW_OP_reg22:
2086 case DW_OP_reg23:
2087 case DW_OP_reg24:
2088 case DW_OP_reg25:
2089 case DW_OP_reg26:
2090 case DW_OP_reg27:
2091 case DW_OP_reg28:
2092 case DW_OP_reg29:
2093 case DW_OP_reg30:
2094 case DW_OP_reg31: {
2095 eval_ctx.loc_desc_kind = Register;
2096 reg_num = opcode - DW_OP_reg0;
2097
2098 if (llvm::Error err = ReadRegisterValueAsScalar(
2099 eval_ctx.reg_ctx, eval_ctx.reg_kind, reg_num, tmp))
2100 return err;
2101 stack.push_back(tmp);
2102 } break;
2103 case DW_OP_regx: {
2104 eval_ctx.loc_desc_kind = Register;
2105 reg_num = op->getRawOperand(0);
2106 Status read_err;
2107 if (llvm::Error err = ReadRegisterValueAsScalar(
2108 eval_ctx.reg_ctx, eval_ctx.reg_kind, reg_num, tmp))
2109 return err;
2110 stack.push_back(tmp);
2111 } break;
2112
2113 case DW_OP_breg0:
2114 case DW_OP_breg1:
2115 case DW_OP_breg2:
2116 case DW_OP_breg3:
2117 case DW_OP_breg4:
2118 case DW_OP_breg5:
2119 case DW_OP_breg6:
2120 case DW_OP_breg7:
2121 case DW_OP_breg8:
2122 case DW_OP_breg9:
2123 case DW_OP_breg10:
2124 case DW_OP_breg11:
2125 case DW_OP_breg12:
2126 case DW_OP_breg13:
2127 case DW_OP_breg14:
2128 case DW_OP_breg15:
2129 case DW_OP_breg16:
2130 case DW_OP_breg17:
2131 case DW_OP_breg18:
2132 case DW_OP_breg19:
2133 case DW_OP_breg20:
2134 case DW_OP_breg21:
2135 case DW_OP_breg22:
2136 case DW_OP_breg23:
2137 case DW_OP_breg24:
2138 case DW_OP_breg25:
2139 case DW_OP_breg26:
2140 case DW_OP_breg27:
2141 case DW_OP_breg28:
2142 case DW_OP_breg29:
2143 case DW_OP_breg30:
2144 case DW_OP_breg31: {
2145 reg_num = opcode - DW_OP_breg0;
2146 if (llvm::Error err = ReadRegisterValueAsScalar(
2147 eval_ctx.reg_ctx, eval_ctx.reg_kind, reg_num, tmp))
2148 return err;
2149
2150 int64_t breg_offset = op->getRawOperand(0);
2151 tmp.GetScalar() = to_generic(tmp.GetScalar().ULongLong());
2152 tmp.GetScalar() += to_generic(breg_offset);
2153 tmp.ClearContext();
2154 stack.push_back(tmp);
2155 stack.back().SetValueType(Value::ValueType::LoadAddress);
2156 } break;
2157 case DW_OP_bregx: {
2158 reg_num = op->getRawOperand(0);
2159 if (llvm::Error err = ReadRegisterValueAsScalar(
2160 eval_ctx.reg_ctx, eval_ctx.reg_kind, reg_num, tmp))
2161 return err;
2162
2163 int64_t breg_offset = op->getRawOperand(1);
2164 tmp.GetScalar() = to_generic(tmp.GetScalar().ULongLong());
2165 tmp.GetScalar() += to_generic(breg_offset);
2166 tmp.ClearContext();
2167 stack.push_back(tmp);
2168 stack.back().SetValueType(Value::ValueType::LoadAddress);
2169 } break;
2170
2171 case DW_OP_fbreg:
2172 if (llvm::Error err =
2173 Evaluate_DW_OP_fbreg(eval_ctx, op->getRawOperand(0)))
2174 return err;
2175 stack.back().GetScalar() =
2176 to_generic(stack.back().GetScalar().ULongLong());
2177 break;
2178
2179 case DW_OP_nop:
2180 break;
2181
2182 case DW_OP_piece: {
2183 if (llvm::Error err =
2184 Evaluate_DW_OP_piece(eval_ctx, op->getRawOperand(0)))
2185 return err;
2186 } break;
2187
2188 case DW_OP_bit_piece:
2189 if (stack.size() < 1) {
2191 LocationDescriptionKind::Empty);
2192 // Reset for the next piece.
2193 eval_ctx.loc_desc_kind = Memory;
2194 return llvm::createStringError(
2195 "expression stack needs at least 1 item for DW_OP_bit_piece");
2196 } else {
2197 const LocationDescriptionKind piece_locdesc = eval_ctx.loc_desc_kind;
2198 UpdateValueTypeFromLocationDescription(eval_ctx, piece_locdesc,
2199 &stack.back());
2200 // Reset for the next piece.
2201 eval_ctx.loc_desc_kind = Memory;
2202 const uint64_t piece_bit_size = op->getRawOperand(0);
2203 const uint64_t piece_bit_offset = op->getRawOperand(1);
2204 if (piece_bit_size == 0) {
2205 // Each piece's location expression is evaluated independently.
2206 stack.clear();
2207 break;
2208 }
2209 switch (stack.back().GetValueType()) {
2211 return llvm::createStringError(
2212 "unable to extract bit value from invalid value");
2214 if (piece_bit_size > std::numeric_limits<uint16_t>::max())
2215 return llvm::createStringError(
2216 "scalar DW_OP_bit_piece is too large");
2217
2218 Value curr_piece(stack.back());
2219 Scalar &scalar = curr_piece.GetScalar();
2220 if (scalar.GetType() != Scalar::e_int)
2221 return llvm::createStringError(
2222 "unable to extract %" PRIu64 " bit value with %" PRIu64
2223 " bit offset from a non-integer scalar value.",
2224 piece_bit_size, piece_bit_offset);
2225 const uint64_t scalar_bit_size = scalar.GetAPSInt().getBitWidth();
2226 if (piece_bit_offset >= scalar_bit_size) {
2227 scalar = Scalar(llvm::APInt(static_cast<unsigned>(piece_bit_size),
2228 /*val=*/0));
2229 } else if (!scalar.ExtractBitfield(
2230 static_cast<uint32_t>(piece_bit_size),
2231 static_cast<uint32_t>(piece_bit_offset))) {
2232 return llvm::createStringError(
2233 "unable to extract %" PRIu64 " bit value with %" PRIu64
2234 " bit offset from a %" PRIu64 " bit scalar value.",
2235 piece_bit_size, piece_bit_offset, scalar_bit_size);
2236 }
2237 scalar.TruncOrExtendTo(static_cast<uint16_t>(piece_bit_size),
2238 /*sign=*/false);
2239 // Each piece's location expression is evaluated independently.
2240 stack.clear();
2241 if (llvm::Error err =
2242 AppendPieceToComposite(eval_ctx, curr_piece, piece_bit_size))
2243 return err;
2244 } break;
2245
2248 return llvm::createStringError(
2249 "unable to extract DW_OP_bit_piece(bit_size = %" PRIu64
2250 ", bit_offset = %" PRIu64 ") from an address value.",
2251 piece_bit_size, piece_bit_offset);
2252
2254 // As above, a full-width DW_OP_implicit_value piece refers to the
2255 // backing bytes, not the address of that backing storage.
2256 if (piece_locdesc == Implicit && piece_bit_offset == 0 &&
2257 piece_bit_size % 8 == 0 &&
2258 stack.back().GetBuffer().GetByteSize() == piece_bit_size / 8)
2259 break;
2260 return llvm::createStringError(
2261 "unable to extract DW_OP_bit_piece(bit_size = %" PRIu64
2262 ", bit_offset = %" PRIu64 ") from an address value.",
2263 piece_bit_size, piece_bit_offset);
2264 }
2265 }
2266 break;
2267
2268 case DW_OP_implicit_value: {
2269 eval_ctx.loc_desc_kind = Implicit;
2270
2271 // The second operand is a sequence of bytes of the length specified by
2272 // the first operand. LLVM represents it as an offset to that sequence.
2273 const uint64_t block_size = op->getRawOperand(0);
2274 uint64_t block_offset = op->getRawOperand(1);
2275
2276 llvm::Error error = llvm::Error::success();
2277 llvm::StringRef block_data =
2278 expr_data.getBytes(&block_offset, block_size, &error);
2279
2280 if (error)
2281 return error;
2282
2283 Value result(block_data.data(), block_data.size());
2284 stack.push_back(result);
2285 break;
2286 }
2287
2288 case DW_OP_implicit_pointer: {
2289 eval_ctx.loc_desc_kind = Implicit;
2290 return llvm::createStringError("could not evaluate %s",
2291 DW_OP_value_to_name(opcode));
2292 }
2293
2294 case DW_OP_push_object_address:
2295 if (eval_ctx.object_address_ptr)
2296 stack.push_back(*eval_ctx.object_address_ptr);
2297 else {
2298 return llvm::createStringError("DW_OP_push_object_address used without "
2299 "specifying an object address");
2300 }
2301 break;
2302
2303 case DW_OP_stack_value:
2304 eval_ctx.loc_desc_kind = Implicit;
2305 stack.back().SetValueType(Value::ValueType::Scalar);
2306 break;
2307
2308 case DW_OP_convert:
2309 if (llvm::Error err =
2310 Evaluate_DW_OP_convert(eval_ctx, op->getRawOperand(0)))
2311 return err;
2312 break;
2313
2314 case DW_OP_call_frame_cfa:
2315 if (llvm::Error err = Evaluate_DW_OP_call_frame_cfa(eval_ctx))
2316 return err;
2317 stack.back().GetScalar() =
2318 to_generic(stack.back().GetScalar().ULongLong());
2319 break;
2320
2321 case DW_OP_form_tls_address:
2322 case DW_OP_GNU_push_tls_address:
2323 if (llvm::Error err = Evaluate_DW_OP_form_tls_address(eval_ctx, opcode))
2324 return err;
2325 break;
2326
2327 case DW_OP_addrx:
2328 case DW_OP_GNU_addr_index: {
2329 if (!eval_ctx.dwarf_cu)
2330 return llvm::createStringError("DW_OP_GNU_addr_index found without a "
2331 "compile unit being specified");
2332 uint64_t index = op->getRawOperand(0);
2333 lldb::addr_t value =
2334 eval_ctx.dwarf_cu->ReadAddressFromDebugAddrSection(index);
2335 stack.push_back(to_generic(value));
2336 stack.back().SetValueType(Value::ValueType::FileAddress);
2337 } break;
2338
2339 case DW_OP_GNU_const_index: {
2340 if (!eval_ctx.dwarf_cu) {
2341 return llvm::createStringError("DW_OP_GNU_const_index found without a "
2342 "compile unit being specified");
2343 }
2344 uint64_t index = op->getRawOperand(0);
2345 lldb::addr_t value =
2346 eval_ctx.dwarf_cu->ReadAddressFromDebugAddrSection(index);
2347 stack.push_back(to_generic(value));
2348 } break;
2349
2350 case DW_OP_GNU_entry_value:
2351 case DW_OP_entry_value: {
2352 // Technically, DW_OP_entry_value has two operands, but LLVM represents
2353 // it as a single-operand operation (bug?). We can deal with this: the
2354 // second operand immediately follows the first, but have to be careful
2355 // when advancing the iterator, see the comment below.
2356 const uint64_t block_size = op->getRawOperand(0);
2357 uint64_t block_offset = op->getEndOffset();
2358
2359 llvm::Error error = llvm::Error::success();
2360 llvm::ArrayRef<uint8_t> block_data = llvm::arrayRefFromStringRef(
2361 expr_data.getBytes(&block_offset, block_size, &error));
2362
2363 if (error)
2364 return error;
2365
2366 // A language runtime may know the entry value without call site
2367 // information.
2368 llvm::ArrayRef<uint8_t> following = llvm::arrayRefFromStringRef(
2369 expr_data.getData().drop_front(block_offset));
2370 const size_t following_size = following.size();
2371 if (std::optional<Value> value = EvaluateEntryValueInLanguageRuntime(
2372 eval_ctx, block_data, following)) {
2373 stack.push_back(*value);
2374 op = op.skipBytes(block_size + following_size - following.size());
2375 continue;
2376 }
2377
2378 if (llvm::Error err = Evaluate_DW_OP_entry_value(eval_ctx, block_data))
2379 return llvm::createStringError(
2380 "could not evaluate DW_OP_entry_value: %s",
2381 llvm::toString(std::move(err)).c_str());
2382
2383 // We can't use `operator++` here because the iterator currently points
2384 // to the second operand. See the comment above.
2385 op = op.skipBytes(block_size);
2386 continue;
2387 }
2388
2389 // These opcodes are decoded but not evaluated here.
2390 case DW_OP_xderef:
2391 case DW_OP_xderef_size:
2392 case DW_OP_call2:
2393 case DW_OP_call4:
2394 case DW_OP_call_ref:
2395 case DW_OP_constx:
2396 case DW_OP_const_type:
2397 case DW_OP_regval_type:
2398 case DW_OP_deref_type:
2399 case DW_OP_xderef_type:
2400 case DW_OP_reinterpret:
2401 case DW_OP_GNU_implicit_pointer:
2402 return llvm::createStringError("unimplemented opcode %s",
2403 DW_OP_value_to_name(opcode));
2404
2405 case DW_OP_LLVM_user:
2406 if (op->getSubCode() == DW_OP_LLVM_piece_end) {
2407 if (op->getEndOffset() != expr_data.size())
2408 return llvm::createStringError(
2409 "DW_OP_LLVM_piece_end is only supported at the end of an "
2410 "expression");
2411
2412 // LLDB already constructs one composite in `pieces`, so a terminal
2413 // DW_OP_LLVM_piece_end is a no-op. TODO: Support multiple composites
2414 // and DW_OP_piece_end once LLVM implements DWARF 6 locations on the
2415 // stack.
2416 // Extension:
2417 // https://llvm.org/docs/AMDGPUDwarfExtensionsForHeterogeneousDebugging.html
2418 // Standard: https://dwarfstd.org/issues/230524.1-orig.html
2419 break;
2420 }
2421 [[fallthrough]];
2422
2423 default:
2424 if (eval_ctx.dwarf_cu) {
2425 const uint64_t operands_offset = op_offset + 1;
2426 uint64_t offset = operands_offset; // Updated by the callee.
2427 if (eval_ctx.dwarf_cu->ParseVendorDWARFOpcode(
2428 opcode, expr_data, offset, eval_ctx.reg_ctx, eval_ctx.reg_kind,
2429 stack)) {
2430 // This is a little tricky. If LLVM knows about this vendor-specific
2431 // operation, `getEndOffset()` points past its last operand. If LLVM
2432 // knows nothing about this operation, `getEndOffset()` points to its
2433 // opcode. In both cases `offset` will point to the next operation,
2434 // but we can't use it directly because the only available mutating
2435 // method of `iterator` (not counting `operator++`) is `skipBytes()`.
2436 // So we calculate the offset and pass it to `skipBytes()`.
2437 assert(offset >= op->getEndOffset());
2438 uint64_t offset_to_next_op = offset - op->getEndOffset();
2439 op = op.skipBytes(offset_to_next_op);
2440 continue;
2441 }
2442 }
2443 return llvm::createStringErrorV("unhandled opcode {0} in DWARFExpression",
2444 opcode);
2445 }
2446 ++op;
2447 }
2448
2449 if (stack.empty()) {
2450 // Nothing on the stack, check if we created a piece value from DW_OP_piece
2451 // or DW_OP_bit_piece opcodes
2452 if (eval_ctx.pieces.GetBuffer().GetByteSize())
2453 return eval_ctx.pieces;
2454
2455 return llvm::createStringError("stack empty after evaluation");
2456 }
2457
2458 UpdateValueTypeFromLocationDescription(eval_ctx, eval_ctx.loc_desc_kind,
2459 &stack.back());
2460
2461 if (log && log->GetVerbose()) {
2462 size_t count = stack.size();
2463 LLDB_LOGF(log, "Stack after operation has %" PRIu64 " values:",
2464 static_cast<uint64_t>(count));
2465 for (size_t i = 0; i < count; ++i) {
2466 StreamString new_value;
2467 new_value.Printf("[%" PRIu64 "]", static_cast<uint64_t>(i));
2468 stack[i].Dump(&new_value);
2469 LLDB_LOGF(log, " %s", new_value.GetData());
2470 }
2471 }
2472 return stack.back();
2473}
2474
2476 StackFrame &frame, const Instruction::Operand &operand) const {
2477 using namespace OperandMatchers;
2478
2479 RegisterContextSP reg_ctx_sp = frame.GetRegisterContext();
2480 if (!reg_ctx_sp) {
2481 return false;
2482 }
2483
2484 DataExtractor opcodes(m_data);
2485
2486 lldb::offset_t op_offset = 0;
2487 uint8_t opcode = opcodes.GetU8(&op_offset);
2488
2489 if (opcode == DW_OP_fbreg) {
2490 int64_t offset = opcodes.GetSLEB128(&op_offset);
2491
2492 DWARFExpressionList *fb_expr = frame.GetFrameBaseExpression(nullptr);
2493 if (!fb_expr) {
2494 return false;
2495 }
2496
2497 auto recurse = [&frame, fb_expr](const Instruction::Operand &child) {
2498 return fb_expr->MatchesOperand(frame, child);
2499 };
2500
2501 if (!offset &&
2502 MatchUnaryOp(MatchOpType(Instruction::Operand::Type::Dereference),
2503 recurse)(operand)) {
2504 return true;
2505 }
2506
2507 return MatchUnaryOp(
2509 MatchBinaryOp(MatchOpType(Instruction::Operand::Type::Sum),
2510 MatchImmOp(offset), recurse))(operand);
2511 }
2512
2513 bool dereference = false;
2514 const RegisterInfo *reg = nullptr;
2515 int64_t offset = 0;
2516
2517 if (opcode >= DW_OP_reg0 && opcode <= DW_OP_reg31) {
2518 reg = reg_ctx_sp->GetRegisterInfo(m_reg_kind, opcode - DW_OP_reg0);
2519 } else if (opcode >= DW_OP_breg0 && opcode <= DW_OP_breg31) {
2520 offset = opcodes.GetSLEB128(&op_offset);
2521 reg = reg_ctx_sp->GetRegisterInfo(m_reg_kind, opcode - DW_OP_breg0);
2522 } else if (opcode == DW_OP_regx) {
2523 uint32_t reg_num = static_cast<uint32_t>(opcodes.GetULEB128(&op_offset));
2524 reg = reg_ctx_sp->GetRegisterInfo(m_reg_kind, reg_num);
2525 } else if (opcode == DW_OP_bregx) {
2526 uint32_t reg_num = static_cast<uint32_t>(opcodes.GetULEB128(&op_offset));
2527 offset = opcodes.GetSLEB128(&op_offset);
2528 reg = reg_ctx_sp->GetRegisterInfo(m_reg_kind, reg_num);
2529 } else {
2530 return false;
2531 }
2532
2533 if (!reg) {
2534 return false;
2535 }
2536
2537 if (dereference) {
2538 if (!offset &&
2539 MatchUnaryOp(MatchOpType(Instruction::Operand::Type::Dereference),
2540 MatchRegOp(*reg))(operand)) {
2541 return true;
2542 }
2543
2544 return MatchUnaryOp(
2546 MatchBinaryOp(MatchOpType(Instruction::Operand::Type::Sum),
2547 MatchRegOp(*reg), MatchImmOp(offset)))(operand);
2548 } else {
2549 return MatchRegOp(*reg)(operand);
2550 }
2551}
static llvm::raw_ostream & error(Stream &strm)
static std::optional< Value > EvaluateEntryValueInLanguageRuntime(EvalContext &eval_ctx, llvm::ArrayRef< uint8_t > entry_value, llvm::ArrayRef< uint8_t > &following)
Asks the language runtime of the current function to evaluate DW_OP_entry_value(entry_value),...
static llvm::Error Evaluate_DW_OP_entry_value(EvalContext &eval_ctx, llvm::ArrayRef< uint8_t > subexpr)
static llvm::Error Evaluate_DW_OP_convert(EvalContext &eval_ctx, uint64_t relative_die_offset)
static llvm::Error CheckScalarOperandsHaveSameType(const Scalar &lhs, const Scalar &rhs, LocationAtom opcode, size_t address_size)
static llvm::Error AppendPieceToComposite(EvalContext &eval_ctx, const Value &piece, uint64_t piece_bit_size)
Appends an eagerly materialized piece at the next composite bit offset.
static llvm::Error Evaluate_DW_OP_piece(EvalContext &eval_ctx, uint64_t piece_byte_size)
static llvm::Error Evaluate_DW_OP_fbreg(EvalContext &eval_ctx, int64_t fbreg_offset)
static std::optional< uint64_t > BitsToBytes(uint64_t bit_size)
static uint8_t GetBitMask(uint64_t bit_offset, lldb::ByteOrder byte_order)
static const char * DW_OP_value_to_name(uint32_t val)
static llvm::Error Evaluate_DW_OP_form_tls_address(EvalContext &eval_ctx, LocationAtom opcode)
static llvm::Expected< lldb::addr_t > ResolveLoadAddress(EvalContext &eval_ctx, const char *dw_op_type, lldb::addr_t file_addr, Address &so_addr, bool check_sectionoffset=false)
Helper function to move common code used to resolve a file address and turn into a load address.
static lldb::offset_t GetOpcodeDataSize(const DataExtractor &data, const lldb::offset_t data_offset, const LocationAtom op, const DWARFExpression::Delegate *dwarf_cu)
Return the length in bytes of the set of operands for op.
static llvm::Error Evaluate_DW_OP_call_frame_cfa(EvalContext &eval_ctx)
static Scalar DerefSizeExtractDataHelper(uint8_t *addr_bytes, size_t size_addr_bytes, ByteOrder byte_order, size_t size)
Helper function to load sized data from a uint8_t buffer.
static void UpdateValueTypeFromLocationDescription(EvalContext &eval_ctx, LocationDescriptionKind kind, Value *value=nullptr)
Adjust value's ValueType according to the kind of location description.
static llvm::Error Evaluate_DW_OP_deref(EvalContext &eval_ctx, LocationAtom opcode, unsigned size, size_t size_addr_bytes)
static bool IsPotentiallyGenericIntegerOperand(const Scalar &operand, size_t address_size)
#define bit
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition Log.h:375
#define LLDB_LOGF(log,...)
Definition Log.h:389
@ Empty
If the Mangled object has neither a mangled name or demangled name we can encode the object with one ...
Definition Mangled.cpp:384
llvm::MCRegisterInfo & GetMCRegisterInfo()
Definition ABI.h:144
A section + offset based address class.
Definition Address.h:62
lldb::addr_t GetLoadAddress(Target *target) const
Get the load address.
Definition Address.cpp:303
bool IsSectionOffset() const
Check if an address is section offset.
Definition Address.h:342
Represent a call made within a Function.
Definition Function.h:254
virtual SymbolContext GetCallee(ModuleList &images, ExecutionContext &exe_ctx)=0
Get the callee's definition, resolved against images.
llvm::ArrayRef< CallSiteParameter > GetCallSiteParameters() const
Get the call site parameters available at this call edge.
Definition Function.h:288
"lldb/Expression/DWARFExpressionList.h" Encapsulates a range map from file address range to a single ...
bool MatchesOperand(StackFrame &frame, const Instruction::Operand &operand) const
llvm::Expected< Value > Evaluate(ExecutionContext *exe_ctx, RegisterContext *reg_ctx, lldb::addr_t func_load_addr, const Value *initial_value_ptr, const Value *object_address_ptr) const
virtual llvm::Expected< std::pair< uint64_t, llvm::dwarf::TypeKind > > GetDIEBitSizeAndEncoding(uint64_t relative_die_offset) const =0
virtual uint16_t GetVersion() const =0
virtual lldb::offset_t GetVendorDWARFOpcodeSize(const DataExtractor &data, const lldb::offset_t data_offset, const uint8_t op) const =0
virtual dw_addr_t ReadAddressFromDebugAddrSection(uint32_t index) const =0
virtual bool ParseVendorDWARFOpcode(uint8_t op, const llvm::DataExtractor &opcodes, lldb::offset_t &offset, RegisterContext *reg_ctx, lldb::RegisterKind reg_kind, Stack &stack) const =0
virtual uint8_t GetAddressByteSize() const =0
DataExtractor m_data
A data extractor capable of reading opcode bytes.
llvm::Expected< lldb::addr_t > GetLocation_DW_OP_addr(const Delegate *dwarf_cu) const
Return the address specified by the first DW_OP_{addr, addrx, GNU_addr_index} in the operation stream...
void UpdateValue(uint64_t const_value, lldb::offset_t const_value_byte_size, uint8_t addr_byte_size)
static llvm::Expected< Value > Evaluate(ExecutionContext *exe_ctx, RegisterContext *reg_ctx, lldb::ModuleSP module_sp, const DataExtractor &opcodes, const Delegate *dwarf_cu, const lldb::RegisterKind reg_set, const Value *initial_value_ptr, const Value *object_address_ptr)
Evaluate a DWARF location expression in a particular context.
bool ContainsThreadLocalStorage(const Delegate *dwarf_cu) const
bool LinkThreadLocalStorage(const Delegate *dwarf_cu, std::function< lldb::addr_t(lldb::addr_t file_addr)> const &link_address_callback)
lldb::RegisterKind m_reg_kind
One of the defines that starts with LLDB_REGKIND_.
bool IsImplicit(const Delegate *dwarf_cu) const
Return true if this expression produces a DWARF implicit or composite location description that LLDB ...
bool Update_DW_OP_addr(const Delegate *dwarf_cu, lldb::addr_t file_addr)
void SetRegisterKind(lldb::RegisterKind reg_kind)
Set the call-frame-info style register kind.
static llvm::Error ReadRegisterValueAsScalar(RegisterContext *reg_ctx, lldb::RegisterKind reg_kind, uint32_t reg_num, Value &value)
bool MatchesOperand(StackFrame &frame, const Instruction::Operand &op) const
void DumpLocation(Stream *s, lldb::DescriptionLevel level, ABI *abi, llvm::DIDumpOptions options={}) const
lldb::RegisterKind GetRegisterKind() const
Return the call-frame-info style register kind.
bool IsValid() const
Return true if the location expression contains data.
A subclass of DataBuffer that stores a data buffer on the heap.
lldb::offset_t GetByteSize() const override
Get the number of bytes in the data buffer.
An binary data encoding class.
Definition DataEncoder.h:42
std::shared_ptr< lldb_private::DataBufferHeap > GetDataBuffer()
Get a shared copy of the heap based memory buffer owned by this object.
uint32_t PutUnsigned(uint32_t offset, uint32_t byte_size, uint64_t value)
Encode an unsigned integer of size byte_size to offset.
uint32_t PutAddress(uint32_t offset, lldb::addr_t addr)
Encode an address in the existing buffer at offset bytes into the buffer.
void AppendAddress(lldb::addr_t addr)
Append an address sized integer to the end of the owned data.
void AppendU8(uint8_t value)
Append a unsigned integer to the end of the owned data.
void AppendData(llvm::StringRef data)
Append bytes to the end of the owned data.
An data extractor class.
uint64_t GetULEB128(lldb::offset_t *offset_ptr) const
Extract a unsigned LEB128 value from *offset_ptr.
virtual const void * GetData(lldb::offset_t *offset_ptr, lldb::offset_t length) const
Extract length bytes from *offset_ptr.
virtual lldb::offset_t BytesLeft(lldb::offset_t offset) const
llvm::DataExtractor GetAsLLVM() const
uint32_t Skip_LEB128(lldb::offset_t *offset_ptr) const
Skip an LEB128 number at *offset_ptr.
uint64_t GetAddress(lldb::offset_t *offset_ptr) const
Extract an address from *offset_ptr.
uint32_t GetAddressByteSize() const
Get the current address size.
uint64_t GetMaxU64(lldb::offset_t *offset_ptr, size_t byte_size) const
Extract an unsigned integer of size byte_size from *offset_ptr.
int64_t GetSLEB128(lldb::offset_t *offset_ptr) const
Extract a signed LEB128 value from *offset_ptr.
lldb::ByteOrder GetByteOrder() const
Get the current byte order value.
uint8_t GetU8(lldb::offset_t *offset_ptr) const
Extract a uint8_t value from *offset_ptr.
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
void SetFrameSP(const lldb::StackFrameSP &frame_sp)
Set accessor to set only the frame shared pointer.
StackFrame * GetFramePtr() const
Returns a pointer to the frame object.
bool HasTargetScope() const
Returns true the ExecutionContext object contains a valid target.
Target & GetTargetRef() const
Returns a reference to the target object.
Thread * GetThreadPtr() const
Returns a pointer to the thread object.
A class that describes a function.
Definition Function.h:386
ConstString GetName() const
Definition Function.cpp:724
CallEdge * GetCallEdgeForReturnAddress(lldb::addr_t return_pc, Target &target)
Get the outgoing call edge from this function which has the given return address return_pc,...
Definition Function.cpp:386
llvm::ArrayRef< std::unique_ptr< CallEdge > > GetTailCallingEdges()
Get the outgoing tail-calling edges from this function.
Definition Function.cpp:379
lldb::LanguageType GetLanguage() const
Definition Function.cpp:713
virtual std::optional< Value > EvaluateEntryValue(StackFrame &frame, llvm::ArrayRef< uint8_t > entry_value, llvm::ArrayRef< uint8_t > &following)
This allows a language runtime to evaluate DW_OP_entry_value(entry_value) in frame without call site ...
bool GetVerbose() const
Definition Log.cpp:329
A collection class for Module objects.
Definition ModuleList.h:127
A plug-in interface definition class for object file parsers.
Definition ObjectFile.h:46
virtual lldb::ByteOrder GetByteOrder() const =0
Gets whether endian swapping should occur when extracting data from this object file.
size_t ReadMemory(const ProcessAddress &process_addr, void *buf, size_t size, Status &error)
Read of memory from a process.
Definition Process.cpp:2114
lldb::ByteOrder GetByteOrder() const
Definition Process.cpp:3969
LanguageRuntime * GetLanguageRuntime(lldb::LanguageType language)
Definition Process.cpp:1555
virtual uint32_t ConvertRegisterKindToRegisterNumber(lldb::RegisterKind kind, uint32_t num)
Convert from a given register numbering scheme to the lldb register numbering scheme.
virtual const RegisterInfo * GetRegisterInfoAtIndex(size_t reg)=0
virtual bool ReadRegister(const RegisterInfo *reg_info, RegisterValue &reg_value)=0
bool GetScalarValue(Scalar &scalar) const
size_t GetByteSize() const
Definition Scalar.cpp:163
bool IsZero() const
Definition Scalar.cpp:175
void TruncOrExtendTo(uint16_t bits, bool sign)
Convert to an integer with bits and the given signedness.
Definition Scalar.cpp:205
unsigned long long ULongLong(unsigned long long fail_value=0) const
Definition Scalar.cpp:366
Scalar::Type GetType() const
Definition Scalar.h:153
llvm::APFloat GetAPFloat() const
Definition Scalar.h:190
bool IsSigned() const
Definition Scalar.cpp:261
size_t GetAsMemoryData(void *dst, size_t dst_len, lldb::ByteOrder dst_byte_order, Status &error) const
Definition Scalar.cpp:791
bool FloatPromote(const llvm::fltSemantics &semantics)
Definition Scalar.cpp:225
bool ExtractBitfield(uint32_t bit_size, uint32_t bit_offset)
Definition Scalar.cpp:816
bool IsValid() const
Definition Scalar.h:111
llvm::APSInt GetAPSInt() const
Definition Scalar.h:188
This base class provides an interface to stack frames.
Definition StackFrame.h:44
virtual DWARFExpressionList * GetFrameBaseExpression(Status *error_ptr)
Get the DWARFExpressionList corresponding to the Canonical Frame Address.
virtual llvm::Error GetFrameBaseValue(Scalar &value)
Return the Canonical Frame Address (DWARF term) for this frame.
virtual lldb::RegisterContextSP GetRegisterContext()
Get the RegisterContext for this frame, if possible.
virtual StackID & GetStackID()
virtual const SymbolContext & GetSymbolContext(lldb::SymbolContextItem resolve_scope)
Provide a SymbolContext for this StackFrame's current pc value.
virtual uint32_t GetFrameIndex() const
Query this frame to find what frame it is in this Thread's StackFrameList.
An error handling class.
Definition Status.h:118
const char * GetData() const
A stream class that can stream formatted output to a file.
Definition Stream.h:28
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
Definition Stream.h:405
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition Stream.cpp:134
Defines a symbol context baton that can be handed other debug core functions.
Function * function
The Function for a given query.
virtual size_t ReadMemory(const Address &addr, void *dst, size_t dst_len, Status &error, bool force_live_memory=false, lldb::addr_t *load_addr_ptr=nullptr, bool *did_read_live_memory=nullptr)
Definition Target.cpp:2134
const ModuleList & GetImages() const
Get accessor for the images for this process.
Definition Target.h:1283
const Scalar & GetScalar() const
See comment on m_scalar to understand what GetScalar returns.
Definition Value.h:114
ValueType
Type that describes Value::m_value.
Definition Value.h:42
@ HostAddress
A host address value (for memory in the process that < A is using liblldb).
Definition Value.h:53
@ FileAddress
A file address value.
Definition Value.h:48
@ LoadAddress
A load address value.
Definition Value.h:50
@ Scalar
A raw scalar value.
Definition Value.h:46
void ClearContext()
Definition Value.h:92
ValueType GetValueType() const
Definition Value.cpp:112
void SetContext(ContextType context_type, void *p)
Definition Value.h:97
DataBufferHeap & GetBuffer()
Definition Value.h:123
void SetValueType(ValueType value_type)
Definition Value.h:90
@ RegisterInfo
RegisterInfo * (can be a scalar or a vector register).
Definition Value.h:62
void ConvertToLoadAddress(Module *module, Target *target)
Convert this value's file address to a load address, if possible.
Definition Value.cpp:680
size_t ResizeData(size_t len)
Definition Value.cpp:193
uint8_t * GetBytes()
Get a pointer to the data.
Definition DataBuffer.h:108
#define LLDB_INVALID_ADDRESS
#define LLDB_INVALID_OFFSET
#define UINT32_MAX
#define LLDB_INVALID_REGNUM
lldb::ByteOrder InlHostByteOrder()
Definition Endian.h:25
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition Log.h:338
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
uint64_t offset_t
Definition lldb-types.h:86
ByteOrder
Byte ordering definitions.
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
uint64_t addr_t
Definition lldb-types.h:80
std::shared_ptr< lldb_private::RegisterContext > RegisterContextSP
std::shared_ptr< lldb_private::Module > ModuleSP
RegisterKind
Register numbering types.
Represent the locations of a parameter at a call site, both in the caller and in the callee.
Definition Function.h:242
DWARFExpressionList LocationInCaller
Definition Function.h:244
Every register is described in detail including its name, alternate name (optional),...
const char * name
Name of this register, can't be NULL.