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
20#include <optional>
21#include <vector>
22
23#include "lldb/Core/Module.h"
24#include "lldb/Core/Value.h"
27#include "lldb/Utility/Log.h"
29#include "lldb/Utility/Scalar.h"
31
32#include "lldb/Host/Host.h"
33#include "lldb/Utility/Endian.h"
34
36
37#include "lldb/Target/ABI.h"
39#include "lldb/Target/Process.h"
42#include "lldb/Target/StackID.h"
43#include "lldb/Target/Target.h"
44#include "lldb/Target/Thread.h"
45#include "llvm/DebugInfo/DWARF/DWARFExpressionPrinter.h"
46#include "llvm/DebugInfo/DWARF/LowLevel/DWARFExpression.h"
47#include "llvm/Support/ErrorExtras.h"
48
49using namespace lldb;
50using namespace lldb_private;
51using namespace lldb_private::plugin::dwarf;
52using namespace llvm::dwarf;
53
54namespace {
55/// The location description kinds described by the DWARF v5
56/// specification. Composite locations are handled out-of-band and
57/// thus aren't part of the enum.
58enum LocationDescriptionKind {
59 Empty,
60 Memory,
61 Register,
62 Implicit
63 /* Composite*/
64};
65
66/// Aggregates the inputs, derived pointers, and mutable evaluation state for
67/// a single DWARF expression evaluation. Passed by reference to every helper
68/// so they don't need to re-thread these individually.
69struct EvalContext {
70 ExecutionContext *exe_ctx;
71 RegisterContext *reg_ctx;
72 lldb::ModuleSP module_sp;
73 const DWARFExpression::Delegate *dwarf_cu;
74 lldb::RegisterKind reg_kind;
75 const Value *initial_value_ptr;
76 const Value *object_address_ptr;
77 Process *process = nullptr;
78 Target *target = nullptr;
79 StackFrame *frame = nullptr;
80
81 /// Mutable evaluation state.
82 /// @{
83 std::vector<Value> stack;
84 Value pieces;
85 uint64_t op_piece_offset = 0;
86 LocationDescriptionKind loc_desc_kind = Memory;
87 /// @}
88
89 EvalContext(ExecutionContext *exe_ctx, RegisterContext *reg_ctx,
90 lldb::ModuleSP module_sp,
91 const DWARFExpression::Delegate *dwarf_cu,
92 lldb::RegisterKind reg_kind, const Value *initial_value_ptr,
93 const Value *object_address_ptr)
94 : exe_ctx(exe_ctx), reg_ctx(reg_ctx), module_sp(std::move(module_sp)),
95 dwarf_cu(dwarf_cu), reg_kind(reg_kind),
96 initial_value_ptr(initial_value_ptr),
97 object_address_ptr(object_address_ptr) {
98 if (exe_ctx) {
99 process = exe_ctx->GetProcessPtr();
100 frame = exe_ctx->GetFramePtr();
101 target = exe_ctx->GetTargetPtr();
102 }
103 if (this->reg_ctx == nullptr && frame)
104 this->reg_ctx = frame->GetRegisterContext().get();
105 }
106};
107} // namespace
108
109// DWARFExpression constructor
111
113
114// Destructor
116
117bool DWARFExpression::IsValid() const { return m_data.GetByteSize() > 0; }
118
119void DWARFExpression::UpdateValue(uint64_t const_value,
120 lldb::offset_t const_value_byte_size,
121 uint8_t addr_byte_size) {
122 if (!const_value_byte_size)
123 return;
124
125 m_data.SetData(
126 DataBufferSP(new DataBufferHeap(&const_value, const_value_byte_size)));
127 m_data.SetByteOrder(endian::InlHostByteOrder());
128 m_data.SetAddressByteSize(addr_byte_size);
129}
130
132 ABI *abi,
133 llvm::DIDumpOptions options) const {
134 auto *MCRegInfo = abi ? &abi->GetMCRegisterInfo() : nullptr;
135 auto GetRegName = [&MCRegInfo](uint64_t DwarfRegNum,
136 bool IsEH) -> llvm::StringRef {
137 if (!MCRegInfo)
138 return {};
139 if (std::optional<unsigned> LLVMRegNum =
140 MCRegInfo->getLLVMRegNum(DwarfRegNum, IsEH))
141 if (const char *RegName = MCRegInfo->getName(*LLVMRegNum))
142 return llvm::StringRef(RegName);
143 return {};
144 };
145 options.GetNameForDWARFReg = GetRegName;
146 llvm::DWARFExpression E(m_data.GetAsLLVM(), m_data.GetAddressByteSize());
147 llvm::printDwarfExpression(&E, s->AsRawOstream(), options, nullptr);
148}
149
151
153 m_reg_kind = reg_kind;
154}
155
156llvm::Error
158 lldb::RegisterKind reg_kind,
159 uint32_t reg_num, Value &value) {
160 if (reg_ctx == nullptr)
161 return llvm::createStringError("no register context in frame");
162
163 const uint32_t native_reg =
164 reg_ctx->ConvertRegisterKindToRegisterNumber(reg_kind, reg_num);
165 if (native_reg == LLDB_INVALID_REGNUM)
166 return llvm::createStringError(
167 "unable to convert register kind=%u reg_num=%u to a native "
168 "register number",
169 reg_kind, reg_num);
170
171 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex(native_reg);
172 RegisterValue reg_value;
173 if (reg_ctx->ReadRegister(reg_info, reg_value)) {
174 if (reg_value.GetScalarValue(value.GetScalar())) {
177 const_cast<RegisterInfo *>(reg_info));
178 return llvm::Error::success();
179 }
180
181 // If we get this error, then we need to implement a value buffer in
182 // the dwarf expression evaluation function...
183 return llvm::createStringError(
184 "register %s can't be converted to a scalar value", reg_info->name);
185 }
186
187 return llvm::createStringError("register %s is not available",
188 reg_info->name);
189}
190
191/// Return the length in bytes of the set of operands for \p op. No guarantees
192/// are made on the state of \p data after this call.
193static lldb::offset_t
194GetOpcodeDataSize(const DataExtractor &data, const lldb::offset_t data_offset,
195 const LocationAtom op,
196 const DWARFExpression::Delegate *dwarf_cu) {
197 lldb::offset_t offset = data_offset;
198 switch (op) {
199 // Only used in LLVM metadata.
200 case DW_OP_LLVM_fragment:
201 case DW_OP_LLVM_convert:
202 case DW_OP_LLVM_tag_offset:
203 case DW_OP_LLVM_entry_value:
204 case DW_OP_LLVM_implicit_pointer:
205 case DW_OP_LLVM_arg:
206 case DW_OP_LLVM_extract_bits_sext:
207 case DW_OP_LLVM_extract_bits_zext:
208 break;
209 // Vendor extensions:
210 case DW_OP_HP_is_value:
211 case DW_OP_HP_fltconst4:
212 case DW_OP_HP_fltconst8:
213 case DW_OP_HP_mod_range:
214 case DW_OP_HP_unmod_range:
215 case DW_OP_HP_tls:
216 case DW_OP_INTEL_bit_piece:
217 case DW_OP_WASM_location:
218 case DW_OP_WASM_location_int:
219 case DW_OP_APPLE_uninit:
220 case DW_OP_PGI_omp_thread_num:
221 case DW_OP_hi_user:
222 case DW_OP_GNU_implicit_pointer:
223 break;
224
225 case DW_OP_addr:
226 case DW_OP_call_ref: // 0x9a 1 address sized offset of DIE (DWARF3)
227 return data.GetAddressByteSize();
228
229 // Opcodes with no arguments
230 case DW_OP_deref: // 0x06
231 case DW_OP_dup: // 0x12
232 case DW_OP_drop: // 0x13
233 case DW_OP_over: // 0x14
234 case DW_OP_swap: // 0x16
235 case DW_OP_rot: // 0x17
236 case DW_OP_xderef: // 0x18
237 case DW_OP_abs: // 0x19
238 case DW_OP_and: // 0x1a
239 case DW_OP_div: // 0x1b
240 case DW_OP_minus: // 0x1c
241 case DW_OP_mod: // 0x1d
242 case DW_OP_mul: // 0x1e
243 case DW_OP_neg: // 0x1f
244 case DW_OP_not: // 0x20
245 case DW_OP_or: // 0x21
246 case DW_OP_plus: // 0x22
247 case DW_OP_shl: // 0x24
248 case DW_OP_shr: // 0x25
249 case DW_OP_shra: // 0x26
250 case DW_OP_xor: // 0x27
251 case DW_OP_eq: // 0x29
252 case DW_OP_ge: // 0x2a
253 case DW_OP_gt: // 0x2b
254 case DW_OP_le: // 0x2c
255 case DW_OP_lt: // 0x2d
256 case DW_OP_ne: // 0x2e
257 case DW_OP_lit0: // 0x30
258 case DW_OP_lit1: // 0x31
259 case DW_OP_lit2: // 0x32
260 case DW_OP_lit3: // 0x33
261 case DW_OP_lit4: // 0x34
262 case DW_OP_lit5: // 0x35
263 case DW_OP_lit6: // 0x36
264 case DW_OP_lit7: // 0x37
265 case DW_OP_lit8: // 0x38
266 case DW_OP_lit9: // 0x39
267 case DW_OP_lit10: // 0x3A
268 case DW_OP_lit11: // 0x3B
269 case DW_OP_lit12: // 0x3C
270 case DW_OP_lit13: // 0x3D
271 case DW_OP_lit14: // 0x3E
272 case DW_OP_lit15: // 0x3F
273 case DW_OP_lit16: // 0x40
274 case DW_OP_lit17: // 0x41
275 case DW_OP_lit18: // 0x42
276 case DW_OP_lit19: // 0x43
277 case DW_OP_lit20: // 0x44
278 case DW_OP_lit21: // 0x45
279 case DW_OP_lit22: // 0x46
280 case DW_OP_lit23: // 0x47
281 case DW_OP_lit24: // 0x48
282 case DW_OP_lit25: // 0x49
283 case DW_OP_lit26: // 0x4A
284 case DW_OP_lit27: // 0x4B
285 case DW_OP_lit28: // 0x4C
286 case DW_OP_lit29: // 0x4D
287 case DW_OP_lit30: // 0x4E
288 case DW_OP_lit31: // 0x4f
289 case DW_OP_reg0: // 0x50
290 case DW_OP_reg1: // 0x51
291 case DW_OP_reg2: // 0x52
292 case DW_OP_reg3: // 0x53
293 case DW_OP_reg4: // 0x54
294 case DW_OP_reg5: // 0x55
295 case DW_OP_reg6: // 0x56
296 case DW_OP_reg7: // 0x57
297 case DW_OP_reg8: // 0x58
298 case DW_OP_reg9: // 0x59
299 case DW_OP_reg10: // 0x5A
300 case DW_OP_reg11: // 0x5B
301 case DW_OP_reg12: // 0x5C
302 case DW_OP_reg13: // 0x5D
303 case DW_OP_reg14: // 0x5E
304 case DW_OP_reg15: // 0x5F
305 case DW_OP_reg16: // 0x60
306 case DW_OP_reg17: // 0x61
307 case DW_OP_reg18: // 0x62
308 case DW_OP_reg19: // 0x63
309 case DW_OP_reg20: // 0x64
310 case DW_OP_reg21: // 0x65
311 case DW_OP_reg22: // 0x66
312 case DW_OP_reg23: // 0x67
313 case DW_OP_reg24: // 0x68
314 case DW_OP_reg25: // 0x69
315 case DW_OP_reg26: // 0x6A
316 case DW_OP_reg27: // 0x6B
317 case DW_OP_reg28: // 0x6C
318 case DW_OP_reg29: // 0x6D
319 case DW_OP_reg30: // 0x6E
320 case DW_OP_reg31: // 0x6F
321 case DW_OP_nop: // 0x96
322 case DW_OP_push_object_address: // 0x97 DWARF3
323 case DW_OP_form_tls_address: // 0x9b DWARF3
324 case DW_OP_call_frame_cfa: // 0x9c DWARF3
325 case DW_OP_stack_value: // 0x9f DWARF4
326 case DW_OP_GNU_push_tls_address: // 0xe0 GNU extension
327 return 0;
328
329 // Opcodes with a single 1 byte arguments
330 case DW_OP_const1u: // 0x08 1 1-byte constant
331 case DW_OP_const1s: // 0x09 1 1-byte constant
332 case DW_OP_pick: // 0x15 1 1-byte stack index
333 case DW_OP_deref_size: // 0x94 1 1-byte size of data retrieved
334 case DW_OP_xderef_size: // 0x95 1 1-byte size of data retrieved
335 case DW_OP_deref_type: // 0xa6 1 1-byte constant
336 return 1;
337
338 // Opcodes with a single 2 byte arguments
339 case DW_OP_const2u: // 0x0a 1 2-byte constant
340 case DW_OP_const2s: // 0x0b 1 2-byte constant
341 case DW_OP_skip: // 0x2f 1 signed 2-byte constant
342 case DW_OP_bra: // 0x28 1 signed 2-byte constant
343 case DW_OP_call2: // 0x98 1 2-byte offset of DIE (DWARF3)
344 return 2;
345
346 // Opcodes with a single 4 byte arguments
347 case DW_OP_const4u: // 0x0c 1 4-byte constant
348 case DW_OP_const4s: // 0x0d 1 4-byte constant
349 case DW_OP_call4: // 0x99 1 4-byte offset of DIE (DWARF3)
350 return 4;
351
352 // Opcodes with a single 8 byte arguments
353 case DW_OP_const8u: // 0x0e 1 8-byte constant
354 case DW_OP_const8s: // 0x0f 1 8-byte constant
355 return 8;
356
357 // All opcodes that have a single ULEB (signed or unsigned) argument
358 case DW_OP_constu: // 0x10 1 ULEB128 constant
359 case DW_OP_consts: // 0x11 1 SLEB128 constant
360 case DW_OP_plus_uconst: // 0x23 1 ULEB128 addend
361 case DW_OP_breg0: // 0x70 1 ULEB128 register
362 case DW_OP_breg1: // 0x71 1 ULEB128 register
363 case DW_OP_breg2: // 0x72 1 ULEB128 register
364 case DW_OP_breg3: // 0x73 1 ULEB128 register
365 case DW_OP_breg4: // 0x74 1 ULEB128 register
366 case DW_OP_breg5: // 0x75 1 ULEB128 register
367 case DW_OP_breg6: // 0x76 1 ULEB128 register
368 case DW_OP_breg7: // 0x77 1 ULEB128 register
369 case DW_OP_breg8: // 0x78 1 ULEB128 register
370 case DW_OP_breg9: // 0x79 1 ULEB128 register
371 case DW_OP_breg10: // 0x7a 1 ULEB128 register
372 case DW_OP_breg11: // 0x7b 1 ULEB128 register
373 case DW_OP_breg12: // 0x7c 1 ULEB128 register
374 case DW_OP_breg13: // 0x7d 1 ULEB128 register
375 case DW_OP_breg14: // 0x7e 1 ULEB128 register
376 case DW_OP_breg15: // 0x7f 1 ULEB128 register
377 case DW_OP_breg16: // 0x80 1 ULEB128 register
378 case DW_OP_breg17: // 0x81 1 ULEB128 register
379 case DW_OP_breg18: // 0x82 1 ULEB128 register
380 case DW_OP_breg19: // 0x83 1 ULEB128 register
381 case DW_OP_breg20: // 0x84 1 ULEB128 register
382 case DW_OP_breg21: // 0x85 1 ULEB128 register
383 case DW_OP_breg22: // 0x86 1 ULEB128 register
384 case DW_OP_breg23: // 0x87 1 ULEB128 register
385 case DW_OP_breg24: // 0x88 1 ULEB128 register
386 case DW_OP_breg25: // 0x89 1 ULEB128 register
387 case DW_OP_breg26: // 0x8a 1 ULEB128 register
388 case DW_OP_breg27: // 0x8b 1 ULEB128 register
389 case DW_OP_breg28: // 0x8c 1 ULEB128 register
390 case DW_OP_breg29: // 0x8d 1 ULEB128 register
391 case DW_OP_breg30: // 0x8e 1 ULEB128 register
392 case DW_OP_breg31: // 0x8f 1 ULEB128 register
393 case DW_OP_regx: // 0x90 1 ULEB128 register
394 case DW_OP_fbreg: // 0x91 1 SLEB128 offset
395 case DW_OP_piece: // 0x93 1 ULEB128 size of piece addressed
396 case DW_OP_convert: // 0xa8 1 ULEB128 offset
397 case DW_OP_reinterpret: // 0xa9 1 ULEB128 offset
398 case DW_OP_addrx: // 0xa1 1 ULEB128 index
399 case DW_OP_constx: // 0xa2 1 ULEB128 index
400 case DW_OP_xderef_type: // 0xa7 1 ULEB128 index
401 case DW_OP_GNU_addr_index: // 0xfb 1 ULEB128 index
402 case DW_OP_GNU_const_index: // 0xfc 1 ULEB128 index
403 data.Skip_LEB128(&offset);
404 return offset - data_offset;
405
406 // All opcodes that have a 2 ULEB (signed or unsigned) arguments
407 case DW_OP_bregx: // 0x92 2 ULEB128 register followed by SLEB128 offset
408 case DW_OP_bit_piece: // 0x9d ULEB128 bit size, ULEB128 bit offset (DWARF3);
409 case DW_OP_regval_type: // 0xa5 ULEB128 + ULEB128
410 data.Skip_LEB128(&offset);
411 data.Skip_LEB128(&offset);
412 return offset - data_offset;
413
414 case DW_OP_implicit_value: // 0x9e ULEB128 size followed by block of that size
415 // (DWARF4)
416 {
417 uint64_t block_len = data.Skip_LEB128(&offset);
418 offset += block_len;
419 return offset - data_offset;
420 }
421
422 case DW_OP_implicit_pointer: // 0xa0 4-byte (or 8-byte for DWARF 64) constant
423 // + LEB128
424 {
425 data.Skip_LEB128(&offset);
426 return (dwarf_cu ? dwarf_cu->GetAddressByteSize() : 4) + offset -
427 data_offset;
428 }
429
430 case DW_OP_GNU_entry_value:
431 case DW_OP_entry_value: // 0xa3 ULEB128 size + variable-length block
432 {
433 uint64_t subexpr_len = data.GetULEB128(&offset);
434 return (offset - data_offset) + subexpr_len;
435 }
436
437 case DW_OP_const_type: // 0xa4 ULEB128 + size + variable-length block
438 {
439 data.Skip_LEB128(&offset);
440 uint8_t length = data.GetU8(&offset);
441 return (offset - data_offset) + length;
442 }
443
444 case DW_OP_LLVM_user: // 0xe9: ULEB128 + variable length constant
445 {
446 uint64_t constants = data.GetULEB128(&offset);
447 return (offset - data_offset) + constants;
448 }
449 }
450
451 if (dwarf_cu)
452 return dwarf_cu->GetVendorDWARFOpcodeSize(data, data_offset, op);
453
454 return LLDB_INVALID_OFFSET;
455}
456
457static const char *DW_OP_value_to_name(uint32_t val) {
458 static char invalid[100];
459 llvm::StringRef llvmstr = llvm::dwarf::OperationEncodingString(val);
460 if (llvmstr.empty()) {
461 snprintf(invalid, sizeof(invalid), "Unknown DW_OP constant: 0x%x", val);
462 return invalid;
463 }
464 return llvmstr.data();
465}
466
467llvm::Expected<lldb::addr_t> DWARFExpression::GetLocation_DW_OP_addr(
468 const DWARFExpression::Delegate *dwarf_cu) const {
469 lldb::offset_t offset = 0;
470 while (m_data.ValidOffset(offset)) {
471 const LocationAtom op = static_cast<LocationAtom>(m_data.GetU8(&offset));
472
473 if (op == DW_OP_addr)
474 return m_data.GetAddress(&offset);
475
476 if (op == DW_OP_GNU_addr_index || op == DW_OP_addrx) {
477 const uint64_t index = m_data.GetULEB128(&offset);
478 if (dwarf_cu)
479 return dwarf_cu->ReadAddressFromDebugAddrSection(index);
480 return llvm::createStringError("cannot evaluate %s without a DWARF unit",
482 }
483
484 const lldb::offset_t op_arg_size =
485 GetOpcodeDataSize(m_data, offset, op, dwarf_cu);
486 if (op_arg_size == LLDB_INVALID_OFFSET)
487 return llvm::createStringError("cannot get opcode data size for %s",
489
490 offset += op_arg_size;
491 }
492
494}
495
497 const DWARFExpression::Delegate *dwarf_cu, lldb::addr_t file_addr) {
498 lldb::offset_t offset = 0;
499 while (m_data.ValidOffset(offset)) {
500 const LocationAtom op = static_cast<LocationAtom>(m_data.GetU8(&offset));
501
502 if (op == DW_OP_addr) {
503 const uint32_t addr_byte_size = m_data.GetAddressByteSize();
504 // We have to make a copy of the data as we don't know if this data is
505 // from a read only memory mapped buffer, so we duplicate all of the data
506 // first, then modify it, and if all goes well, we then replace the data
507 // for this expression
508
509 // Make en encoder that contains a copy of the location expression data
510 // so we can write the address into the buffer using the correct byte
511 // order.
512 DataEncoder encoder(m_data.GetDataStart(), m_data.GetByteSize(),
513 m_data.GetByteOrder(), addr_byte_size);
514
515 // Replace the address in the new buffer
516 if (encoder.PutAddress(offset, file_addr) == UINT32_MAX)
517 return false;
518
519 // All went well, so now we can reset the data using a shared pointer to
520 // the heap data so "m_data" will now correctly manage the heap data.
521 m_data.SetData(encoder.GetDataBuffer());
522 return true;
523 }
524 if (op == DW_OP_addrx) {
525 // Replace DW_OP_addrx with DW_OP_addr, since we can't modify the
526 // read-only debug_addr table.
527 // Subtract one to account for the opcode.
528 llvm::ArrayRef data_before_op = m_data.GetData().take_front(offset - 1);
529
530 // Read the addrx index to determine how many bytes it needs.
531 const lldb::offset_t old_offset = offset;
532 m_data.GetULEB128(&offset);
533 if (old_offset == offset)
534 return false;
535 llvm::ArrayRef data_after_op = m_data.GetData().drop_front(offset);
536
537 DataEncoder encoder(m_data.GetByteOrder(), m_data.GetAddressByteSize());
538 encoder.AppendData(data_before_op);
539 encoder.AppendU8(DW_OP_addr);
540 encoder.AppendAddress(file_addr);
541 encoder.AppendData(data_after_op);
542 m_data.SetData(encoder.GetDataBuffer());
543 return true;
544 }
545 const lldb::offset_t op_arg_size =
546 GetOpcodeDataSize(m_data, offset, op, dwarf_cu);
547 if (op_arg_size == LLDB_INVALID_OFFSET)
548 break;
549 offset += op_arg_size;
550 }
551 return false;
552}
553
555 const DWARFExpression::Delegate *dwarf_cu) const {
556 lldb::offset_t offset = 0;
557 while (m_data.ValidOffset(offset)) {
558 const LocationAtom op = static_cast<LocationAtom>(m_data.GetU8(&offset));
559
560 if (op == DW_OP_form_tls_address || op == DW_OP_GNU_push_tls_address)
561 return true;
562 const lldb::offset_t op_arg_size =
563 GetOpcodeDataSize(m_data, offset, op, dwarf_cu);
564 if (op_arg_size == LLDB_INVALID_OFFSET)
565 return false;
566 offset += op_arg_size;
567 }
568 return false;
569}
571 const DWARFExpression::Delegate *dwarf_cu,
572 std::function<lldb::addr_t(lldb::addr_t file_addr)> const
573 &link_address_callback) {
574 const uint32_t addr_byte_size = m_data.GetAddressByteSize();
575 // We have to make a copy of the data as we don't know if this data is from a
576 // read only memory mapped buffer, so we duplicate all of the data first,
577 // then modify it, and if all goes well, we then replace the data for this
578 // expression.
579 // Make en encoder that contains a copy of the location expression data so we
580 // can write the address into the buffer using the correct byte order.
581 DataEncoder encoder(m_data.GetDataStart(), m_data.GetByteSize(),
582 m_data.GetByteOrder(), addr_byte_size);
583
584 lldb::offset_t offset = 0;
585 lldb::offset_t const_offset = 0;
586 lldb::addr_t const_value = 0;
587 size_t const_byte_size = 0;
588 while (m_data.ValidOffset(offset)) {
589 const LocationAtom op = static_cast<LocationAtom>(m_data.GetU8(&offset));
590
591 bool decoded_data = false;
592 switch (op) {
593 case DW_OP_const4u:
594 // Remember the const offset in case we later have a
595 // DW_OP_form_tls_address or DW_OP_GNU_push_tls_address
596 const_offset = offset;
597 const_value = m_data.GetU32(&offset);
598 decoded_data = true;
599 const_byte_size = 4;
600 break;
601
602 case DW_OP_const8u:
603 // Remember the const offset in case we later have a
604 // DW_OP_form_tls_address or DW_OP_GNU_push_tls_address
605 const_offset = offset;
606 const_value = m_data.GetU64(&offset);
607 decoded_data = true;
608 const_byte_size = 8;
609 break;
610
611 case DW_OP_form_tls_address:
612 case DW_OP_GNU_push_tls_address:
613 // DW_OP_form_tls_address and DW_OP_GNU_push_tls_address must be preceded
614 // by a file address on the stack. We assume that DW_OP_const4u or
615 // DW_OP_const8u is used for these values, and we check that the last
616 // opcode we got before either of these was DW_OP_const4u or
617 // DW_OP_const8u. If so, then we can link the value accordingly. For
618 // Darwin, the value in the DW_OP_const4u or DW_OP_const8u is the file
619 // address of a structure that contains a function pointer, the pthread
620 // key and the offset into the data pointed to by the pthread key. So we
621 // must link this address and also set the module of this expression to
622 // the new_module_sp so we can resolve the file address correctly
623 if (const_byte_size > 0) {
624 lldb::addr_t linked_file_addr = link_address_callback(const_value);
625 if (linked_file_addr == LLDB_INVALID_ADDRESS)
626 return false;
627 // Replace the address in the new buffer
628 if (encoder.PutUnsigned(const_offset, const_byte_size,
629 linked_file_addr) == UINT32_MAX)
630 return false;
631 }
632 break;
633
634 default:
635 const_offset = 0;
636 const_value = 0;
637 const_byte_size = 0;
638 break;
639 }
640
641 if (!decoded_data) {
642 const lldb::offset_t op_arg_size =
643 GetOpcodeDataSize(m_data, offset, op, dwarf_cu);
644 if (op_arg_size == LLDB_INVALID_OFFSET)
645 return false;
646 else
647 offset += op_arg_size;
648 }
649 }
650
651 m_data.SetData(encoder.GetDataBuffer());
652 return true;
653}
654
655static llvm::Error Evaluate_DW_OP_entry_value(EvalContext &eval_ctx,
656 llvm::ArrayRef<uint8_t> subexpr) {
658 // DW_OP_entry_value(sub-expr) describes the location a variable had upon
659 // function entry: this variable location is presumed to be optimized out at
660 // the current PC value. The caller of the function may have call site
661 // information that describes an alternate location for the variable (e.g. a
662 // constant literal, or a spilled stack value) in the parent frame.
663 //
664 // Example (this is pseudo-code & pseudo-DWARF, but hopefully illustrative):
665 //
666 // void child(int &sink, int x) {
667 // ...
668 // /* "x" gets optimized out. */
669 //
670 // /* The location of "x" here is: DW_OP_entry_value($reg2). */
671 // ++sink;
672 // }
673 //
674 // void parent() {
675 // int sink;
676 //
677 // /*
678 // * The callsite information emitted here is:
679 // *
680 // * DW_TAG_call_site
681 // * DW_AT_return_pc ... (for "child(sink, 123);")
682 // * DW_TAG_call_site_parameter (for "sink")
683 // * DW_AT_location ($reg1)
684 // * DW_AT_call_value ($SP - 8)
685 // * DW_TAG_call_site_parameter (for "x")
686 // * DW_AT_location ($reg2)
687 // * DW_AT_call_value ($literal 123)
688 // *
689 // * DW_TAG_call_site
690 // * DW_AT_return_pc ... (for "child(sink, 456);")
691 // * ...
692 // */
693 // child(sink, 123);
694 // child(sink, 456);
695 // }
696 //
697 // When the program stops at "++sink" within `child`, the debugger determines
698 // the call site by analyzing the return address. Once the call site is found,
699 // the debugger determines which parameter is referenced by DW_OP_entry_value
700 // and evaluates the corresponding location for that parameter in `parent`.
701
702 // 1. Find the function which pushed the current frame onto the stack.
703 if ((!eval_ctx.exe_ctx || !eval_ctx.exe_ctx->HasTargetScope()) ||
704 !eval_ctx.reg_ctx) {
705 return llvm::createStringError("no exe/reg context");
706 }
707
708 StackFrame *current_frame = eval_ctx.exe_ctx->GetFramePtr();
709 Thread *thread = eval_ctx.exe_ctx->GetThreadPtr();
710 if (!current_frame || !thread)
711 return llvm::createStringError("no current frame/thread");
712
713 Target &target = eval_ctx.exe_ctx->GetTargetRef();
714 StackFrameSP parent_frame = nullptr;
715 addr_t return_pc = LLDB_INVALID_ADDRESS;
716 uint32_t current_frame_idx = current_frame->GetFrameIndex();
717
718 for (uint32_t parent_frame_idx = current_frame_idx + 1;; parent_frame_idx++) {
719 parent_frame = thread->GetStackFrameAtIndex(parent_frame_idx);
720 // If this is null, we're at the end of the stack.
721 if (!parent_frame)
722 break;
723
724 // Record the first valid return address, even if this is an inlined frame,
725 // in order to look up the associated call edge in the first non-inlined
726 // parent frame.
727 if (return_pc == LLDB_INVALID_ADDRESS) {
728 return_pc = parent_frame->GetFrameCodeAddress().GetLoadAddress(&target);
729 LLDB_LOG(log, "immediate ancestor with pc = {0:x}", return_pc);
730 }
731
732 // If we've found an inlined frame, skip it (these have no call site
733 // parameters).
734 if (parent_frame->IsInlined())
735 continue;
736
737 // We've found the first non-inlined parent frame.
738 break;
739 }
740 if (!parent_frame || !parent_frame->GetRegisterContext()) {
741 return llvm::createStringError("no parent frame with reg ctx");
742 }
743
744 Function *parent_func =
745 parent_frame->GetSymbolContext(eSymbolContextFunction).function;
746 if (!parent_func)
747 return llvm::createStringError("no parent function");
748
749 // 2. Find the call edge in the parent function responsible for creating the
750 // current activation.
751 Function *current_func =
752 current_frame->GetSymbolContext(eSymbolContextFunction).function;
753 if (!current_func)
754 return llvm::createStringError("no current function");
755
756 CallEdge *call_edge = nullptr;
757 ModuleList &modlist = target.GetImages();
758 ExecutionContext parent_exe_ctx = *eval_ctx.exe_ctx;
759 parent_exe_ctx.SetFrameSP(parent_frame);
760 if (!parent_frame->IsArtificial()) {
761 // If the parent frame is not artificial, the current activation may be
762 // produced by an ambiguous tail call. In this case, refuse to proceed.
763 call_edge = parent_func->GetCallEdgeForReturnAddress(return_pc, target);
764 if (!call_edge) {
765 return llvm::createStringErrorV(
766 "no call edge for retn-pc = {0:x} in parent frame {1}", return_pc,
767 parent_func->GetName());
768 }
769 Function *callee_func = call_edge->GetCallee(modlist, parent_exe_ctx);
770 if (callee_func != current_func) {
771 return llvm::createStringError(
772 "ambiguous call sequence, can't find real parent frame");
773 }
774 } else {
775 // The StackFrameList solver machinery has deduced that an unambiguous tail
776 // call sequence that produced the current activation. The first edge in
777 // the parent that points to the current function must be valid.
778 for (auto &edge : parent_func->GetTailCallingEdges()) {
779 if (edge->GetCallee(modlist, parent_exe_ctx) == current_func) {
780 call_edge = edge.get();
781 break;
782 }
783 }
784 }
785 if (!call_edge)
786 return llvm::createStringError("no unambiguous edge from parent "
787 "to current function");
788
789 // 3. Attempt to locate the DW_OP_entry_value expression in the set of
790 // available call site parameters. If found, evaluate the corresponding
791 // parameter in the context of the parent frame.
792 const CallSiteParameter *matched_param = nullptr;
793 for (const CallSiteParameter &param : call_edge->GetCallSiteParameters()) {
794 DataExtractor param_subexpr_extractor;
795 if (!param.LocationInCallee.GetExpressionData(param_subexpr_extractor))
796 continue;
797 lldb::offset_t param_subexpr_offset = 0;
798 const void *param_subexpr_data =
799 param_subexpr_extractor.GetData(&param_subexpr_offset, subexpr.size());
800 if (!param_subexpr_data ||
801 param_subexpr_extractor.BytesLeft(param_subexpr_offset) != 0)
802 continue;
803
804 // At this point, the DW_OP_entry_value sub-expression and the callee-side
805 // expression in the call site parameter are known to have the same length.
806 // Check whether they are equal.
807 //
808 // Note that an equality check is sufficient: the contents of the
809 // DW_OP_entry_value subexpression are only used to identify the right call
810 // site parameter in the parent, and do not require any special handling.
811 if (memcmp(subexpr.data(), param_subexpr_data, subexpr.size()) == 0) {
812 matched_param = &param;
813 break;
814 }
815 }
816 if (!matched_param)
817 return llvm::createStringError("no matching call site param found");
818
819 // TODO: Add support for DW_OP_push_object_address within a DW_OP_entry_value
820 // subexpresion whenever llvm does.
821 const DWARFExpressionList &param_expr = matched_param->LocationInCaller;
822
823 // Recurse through the public entry point so the call-site parameter is
824 // evaluated with a fresh EvalContext (separate stack and piece state).
825 llvm::Expected<Value> maybe_result = param_expr.Evaluate(
826 &parent_exe_ctx, parent_frame->GetRegisterContext().get(),
828 /*initial_value_ptr=*/nullptr,
829 /*object_address_ptr=*/nullptr);
830 if (!maybe_result) {
831 LLDB_LOG(log,
832 "Evaluate_DW_OP_entry_value: call site param evaluation failed");
833 return maybe_result.takeError();
834 }
835
836 eval_ctx.stack.push_back(*maybe_result);
837 return llvm::Error::success();
838}
839
840/// Adjust value's ValueType according to the kind of location description.
841static void UpdateValueTypeFromLocationDescription(EvalContext &eval_ctx,
842 LocationDescriptionKind kind,
843 Value *value = nullptr) {
844 // Note that this function is conflating DWARF expressions with
845 // DWARF location descriptions. Perhaps it would be better to define
846 // a wrapper for DWARFExpression::Eval() that deals with DWARF
847 // location descriptions (which consist of one or more DWARF
848 // expressions). But doing this would mean we'd also need factor the
849 // handling of DW_OP_(bit_)piece out of this function.
850 if (eval_ctx.dwarf_cu && eval_ctx.dwarf_cu->GetVersion() >= 4) {
852 const char *log_msg = "DWARF location description kind: %s";
853 switch (kind) {
854 case Empty:
855 LLDB_LOGF(log, log_msg, "Empty");
856 break;
857 case Memory:
858 LLDB_LOGF(log, log_msg, "Memory");
859 if (value->GetValueType() == Value::ValueType::Scalar)
860 value->SetValueType(Value::ValueType::LoadAddress);
861 break;
862 case Register:
863 LLDB_LOGF(log, log_msg, "Register");
864 value->SetValueType(Value::ValueType::Scalar);
865 break;
866 case Implicit:
867 LLDB_LOGF(log, log_msg, "Implicit");
868 if (value->GetValueType() == Value::ValueType::LoadAddress)
869 value->SetValueType(Value::ValueType::Scalar);
870 break;
871 }
872 }
873}
874
875/// Helper function to move common code used to resolve a file address and turn
876/// into a load address.
877///
878/// \param eval_ctx Evaluation context (provides exe_ctx and module_sp).
879/// \param dw_op_type C-style string used to vary the error output
880/// \param file_addr the file address we are trying to resolve and turn into a
881/// load address
882/// \param so_addr out parameter, will be set to load address or section offset
883/// \param check_sectionoffset bool which determines if having a section offset
884/// but not a load address is considerd a success
885/// \returns std::optional containing the load address if resolving and getting
886/// the load address succeed or an empty Optinal otherwise. If
887/// check_sectionoffset is true we consider LLDB_INVALID_ADDRESS a
888/// success if so_addr.IsSectionOffset() is true.
889static llvm::Expected<lldb::addr_t>
890ResolveLoadAddress(EvalContext &eval_ctx, const char *dw_op_type,
891 lldb::addr_t file_addr, Address &so_addr,
892 bool check_sectionoffset = false) {
893 if (!eval_ctx.module_sp)
894 return llvm::createStringError("need module to resolve file address for %s",
895 dw_op_type);
896
897 if (!eval_ctx.module_sp->ResolveFileAddress(file_addr, so_addr))
898 return llvm::createStringError("failed to resolve file address in module");
899
900 const addr_t load_addr = so_addr.GetLoadAddress(eval_ctx.target);
901
902 if (load_addr == LLDB_INVALID_ADDRESS &&
903 (check_sectionoffset && !so_addr.IsSectionOffset()))
904 return llvm::createStringError("failed to resolve load address");
905
906 return load_addr;
907}
908
909/// @brief Helper function to load sized data from a uint8_t buffer.
910///
911/// @param addr_bytes The buffer containing raw data.
912/// @param size_addr_bytes How large is the underlying raw data.
913/// @param byte_order What is the byte order of the underlying data.
914/// @param size How much of the underlying data we want to use.
915/// @return The underlying data converted into a Scalar.
916static Scalar DerefSizeExtractDataHelper(uint8_t *addr_bytes,
917 size_t size_addr_bytes,
918 ByteOrder byte_order, size_t size) {
919 DataExtractor addr_data(addr_bytes, size_addr_bytes, byte_order, size);
920
921 lldb::offset_t addr_data_offset = 0;
922 if (size <= 8)
923 return addr_data.GetMaxU64(&addr_data_offset, size);
924 return addr_data.GetAddress(&addr_data_offset);
925}
926
927static llvm::Error Evaluate_DW_OP_deref(EvalContext &eval_ctx,
928 LocationAtom opcode, unsigned size,
929 size_t size_addr_bytes) {
930 const char *op_name = DW_OP_value_to_name(opcode);
931 if (eval_ctx.stack.empty())
932 return llvm::createStringError("expression stack empty for %s", op_name);
933
934 if (size > 8)
935 return llvm::createStringError("Invalid address size for %s: %u", op_name,
936 size);
937
938 if (opcode == DW_OP_deref_size && size > size_addr_bytes)
939 return llvm::createStringError(
940 "DW_OP_deref_size size (%u) exceeds address size (%zu)", size,
941 size_addr_bytes);
942
943 // Deref a register or implicit location and truncate the value to `size`
944 // bytes. See the corresponding comment in DW_OP_deref for more details on
945 // why we deref these locations this way.
946 if (eval_ctx.loc_desc_kind == Register ||
947 eval_ctx.loc_desc_kind == Implicit) {
948 // Reset context to default values.
949 eval_ctx.loc_desc_kind = Memory;
950 eval_ctx.stack.back().ClearContext();
951
952 // Truncate the value on top of the stack to *size* bytes then
953 // extend to the size of an address (e.g. generic type).
954 Scalar scalar = eval_ctx.stack.back().GetScalar();
955 scalar.TruncOrExtendTo(size * 8, /*sign=*/false);
956 scalar.TruncOrExtendTo(size_addr_bytes * 8,
957 /*sign=*/false);
958 eval_ctx.stack.back().GetScalar() = scalar;
959 return llvm::Error::success();
960 }
961
962 Value::ValueType value_type = eval_ctx.stack.back().GetValueType();
963 switch (value_type) {
965 void *src = (void *)eval_ctx.stack.back().GetScalar().ULongLong();
966 intptr_t ptr;
967 ::memcpy(&ptr, src, sizeof(void *));
968 // I can't decide whether the size operand should apply to the bytes in
969 // their lldb-host endianness or the target endianness.. I doubt this'll
970 // ever come up but I'll opt for assuming big endian regardless.
971 switch (size) {
972 case 1:
973 ptr = ptr & 0xff;
974 break;
975 case 2:
976 ptr = ptr & 0xffff;
977 break;
978 case 3:
979 ptr = ptr & 0xffffff;
980 break;
981 case 4:
982 ptr = ptr & 0xffffffff;
983 break;
984 // The casts are added to work around the case where intptr_t is a 32-bit
985 // quantity. Presumably we won't hit the 5..7 cases if (void*) is 32-bits in
986 // this program.
987 case 5:
988 ptr = (intptr_t)ptr & 0xffffffffffULL;
989 break;
990 case 6:
991 ptr = (intptr_t)ptr & 0xffffffffffffULL;
992 break;
993 case 7:
994 ptr = (intptr_t)ptr & 0xffffffffffffffULL;
995 break;
996 default:
997 break;
998 }
999 eval_ctx.stack.back().GetScalar() = ptr;
1000 eval_ctx.stack.back().ClearContext();
1001 } break;
1003 auto file_addr =
1004 eval_ctx.stack.back().GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1005 Address so_addr;
1006 auto maybe_load_addr =
1007 ResolveLoadAddress(eval_ctx, op_name, file_addr, so_addr,
1008 /*check_sectionoffset=*/true);
1009
1010 if (!maybe_load_addr)
1011 return maybe_load_addr.takeError();
1012
1013 addr_t load_addr = *maybe_load_addr;
1014
1015 if (load_addr == LLDB_INVALID_ADDRESS && so_addr.IsSectionOffset()) {
1016 uint8_t addr_bytes[8];
1017 Status error;
1018
1019 if (!eval_ctx.target ||
1020 eval_ctx.target->ReadMemory(so_addr, &addr_bytes, size, error,
1021 /*force_live_memory=*/false) != size)
1022 return llvm::createStringError("failed to dereference pointer for %s: "
1023 "%s\n",
1024 op_name, error.AsCString());
1025
1026 ObjectFile *objfile = eval_ctx.module_sp->GetObjectFile();
1027
1028 eval_ctx.stack.back().GetScalar() = DerefSizeExtractDataHelper(
1029 addr_bytes, size, objfile->GetByteOrder(), size);
1030 eval_ctx.stack.back().ClearContext();
1031 break;
1032 }
1033 eval_ctx.stack.back().GetScalar() = load_addr;
1034 // Fall through to load address promotion code below.
1035 }
1036
1037 [[fallthrough]];
1039 // Promote Scalar to LoadAddress and fall through.
1040 eval_ctx.stack.back().SetValueType(Value::ValueType::LoadAddress);
1041 [[fallthrough]];
1043 if (!eval_ctx.exe_ctx)
1044 return llvm::createStringError("no execution context for %s", op_name);
1045 if (!eval_ctx.process)
1046 return llvm::createStringError("no process for %s", op_name);
1047
1048 lldb::addr_t pointer_addr =
1049 eval_ctx.stack.back().GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1050 uint8_t addr_bytes[sizeof(lldb::addr_t)];
1051 Status error;
1052
1053 if (eval_ctx.process->ReadMemory(pointer_addr, &addr_bytes, size, error) !=
1054 size)
1055 return llvm::createStringError(
1056 "failed to dereference pointer from 0x%" PRIx64 " for %s: %s\n",
1057 pointer_addr, op_name, error.AsCString());
1058
1059 eval_ctx.stack.back().GetScalar() = DerefSizeExtractDataHelper(
1060 addr_bytes, sizeof(addr_bytes), eval_ctx.process->GetByteOrder(), size);
1061 eval_ctx.stack.back().ClearContext();
1062 } break;
1063
1065 return llvm::createStringError("invalid value for %s", op_name);
1066 }
1067
1068 return llvm::Error::success();
1069}
1070
1071static llvm::Error Evaluate_DW_OP_piece(EvalContext &eval_ctx,
1072 uint64_t piece_byte_size) {
1073 LocationDescriptionKind piece_locdesc = eval_ctx.loc_desc_kind;
1074 // Reset for the next piece.
1075 eval_ctx.loc_desc_kind = Memory;
1076
1077 if (piece_byte_size == 0)
1078 return llvm::Error::success();
1079
1080 Value curr_piece;
1081
1082 if (eval_ctx.stack.empty()) {
1084 LocationDescriptionKind::Empty);
1085 // In a multi-piece expression, this means that the current piece is
1086 // not available. Fill with zeros for now by resizing the data and
1087 // appending it
1088 curr_piece.ResizeData(piece_byte_size);
1089 // Note that "0" is not a correct value for the unknown bits.
1090 // It would be better to also return a mask of valid bits together
1091 // with the expression result, so the debugger can print missing
1092 // members as "<optimized out>" or something.
1093 ::memset(curr_piece.GetBuffer().GetBytes(), 0, piece_byte_size);
1094 eval_ctx.pieces.AppendDataToHostBuffer(curr_piece);
1095 } else {
1096 Status error;
1097 // Extract the current piece into "curr_piece"
1098 Value curr_piece_source_value(eval_ctx.stack.back());
1099 eval_ctx.stack.pop_back();
1100 UpdateValueTypeFromLocationDescription(eval_ctx, piece_locdesc,
1101 &curr_piece_source_value);
1102
1103 const Value::ValueType curr_piece_source_value_type =
1104 curr_piece_source_value.GetValueType();
1105 Scalar &scalar = curr_piece_source_value.GetScalar();
1107 switch (curr_piece_source_value_type) {
1109 return llvm::createStringError("invalid value type");
1111 if (eval_ctx.target) {
1112 curr_piece_source_value.ConvertToLoadAddress(eval_ctx.module_sp.get(),
1113 eval_ctx.target);
1114 addr = scalar.ULongLong(LLDB_INVALID_ADDRESS);
1115 } else {
1116 return llvm::createStringError(
1117 "unable to convert file address 0x%" PRIx64 " to load address "
1118 "for DW_OP_piece(%" PRIu64 "): "
1119 "no target available",
1120 addr, piece_byte_size);
1121 }
1122 [[fallthrough]];
1124 if (eval_ctx.target) {
1125 if (curr_piece.ResizeData(piece_byte_size) == piece_byte_size) {
1126 if (eval_ctx.target->ReadMemory(
1127 Address(addr), curr_piece.GetBuffer().GetBytes(),
1128 piece_byte_size, error,
1129 /*force_live_memory=*/false) != piece_byte_size) {
1130 const char *addr_type =
1131 (curr_piece_source_value_type == Value::ValueType::LoadAddress)
1132 ? "load"
1133 : "file";
1134 return llvm::createStringError(
1135 "failed to read memory DW_OP_piece(%" PRIu64
1136 ") from %s address 0x%" PRIx64,
1137 piece_byte_size, addr_type, addr);
1138 }
1139 } else {
1140 return llvm::createStringError(
1141 "failed to resize the piece memory buffer for "
1142 "DW_OP_piece(%" PRIu64 ")",
1143 piece_byte_size);
1144 }
1145 }
1146 } break;
1148 return llvm::createStringError(
1149 "failed to read memory DW_OP_piece(%" PRIu64
1150 ") from host address 0x%" PRIx64,
1151 piece_byte_size, addr);
1152 } break;
1153
1155 uint32_t bit_size = piece_byte_size * 8;
1156 uint32_t bit_offset = 0;
1157 if (!scalar.ExtractBitfield(bit_size, bit_offset)) {
1158 return llvm::createStringError(
1159 "unable to extract %" PRIu64 " bytes from a %" PRIu64
1160 " byte scalar value.",
1161 piece_byte_size,
1162 (uint64_t)curr_piece_source_value.GetScalar().GetByteSize());
1163 }
1164
1165 // We have seen a case where we have expression like:
1166 // DW_OP_lit0, DW_OP_stack_value, DW_OP_piece 0x28
1167 // here we are assuming the compiler was trying to zero
1168 // extend the value that we should append to the buffer.
1169 scalar.TruncOrExtendTo(bit_size, /*sign=*/false);
1170 curr_piece.GetScalar() = scalar;
1171 } break;
1172 }
1173
1174 // Check if this is the first piece?
1175 if (eval_ctx.op_piece_offset == 0) {
1176 // This is the first piece, we should push it back onto the stack
1177 // so subsequent pieces will be able to access this piece and add
1178 // to it.
1179 if (eval_ctx.pieces.AppendDataToHostBuffer(curr_piece) == 0) {
1180 return llvm::createStringError("failed to append piece data");
1181 }
1182 } else {
1183 // If this is the second or later piece there should be a value on
1184 // the stack.
1185 if (eval_ctx.pieces.GetBuffer().GetByteSize() !=
1186 eval_ctx.op_piece_offset) {
1187 return llvm::createStringError(
1188 "DW_OP_piece for offset %" PRIu64
1189 " but top of stack is of size %" PRIu64,
1190 eval_ctx.op_piece_offset,
1191 eval_ctx.pieces.GetBuffer().GetByteSize());
1192 }
1193
1194 if (eval_ctx.pieces.AppendDataToHostBuffer(curr_piece) == 0)
1195 return llvm::createStringError("failed to append piece data");
1196 }
1197 }
1198 eval_ctx.op_piece_offset += piece_byte_size;
1199 return llvm::Error::success();
1200}
1201
1202static llvm::Error Evaluate_DW_OP_convert(EvalContext &eval_ctx,
1203 uint64_t relative_die_offset) {
1204 uint64_t bit_size;
1205 bool sign;
1206 if (relative_die_offset == 0) {
1207 // The generic type has the size of an address on the target
1208 // machine and an unspecified signedness. Scalar has no
1209 // "unspecified signedness", so we use unsigned types.
1210 if (!eval_ctx.module_sp)
1211 return llvm::createStringError("no module");
1212 sign = false;
1213 bit_size = eval_ctx.module_sp->GetArchitecture().GetAddressByteSize() * 8;
1214 if (!bit_size)
1215 return llvm::createStringError("unspecified architecture");
1216 } else {
1217 auto bit_size_sign_or_err =
1218 eval_ctx.dwarf_cu->GetDIEBitSizeAndSign(relative_die_offset);
1219 if (!bit_size_sign_or_err)
1220 return bit_size_sign_or_err.takeError();
1221 bit_size = bit_size_sign_or_err->first;
1222 sign = bit_size_sign_or_err->second;
1223 }
1224 eval_ctx.stack.back().GetScalar().TruncOrExtendTo(bit_size, sign);
1225 return llvm::Error::success();
1226}
1227
1228static llvm::Error Evaluate_DW_OP_form_tls_address(EvalContext &eval_ctx,
1229 LocationAtom opcode) {
1230 if (eval_ctx.stack.empty())
1231 return llvm::createStringError("%s needs an argument",
1232 opcode == DW_OP_form_tls_address
1233 ? "DW_OP_form_tls_address"
1234 : "DW_OP_GNU_push_tls_address");
1235
1236 if (!eval_ctx.exe_ctx || !eval_ctx.module_sp)
1237 return llvm::createStringError("no context to evaluate TLS within");
1238
1239 Thread *thread = eval_ctx.exe_ctx->GetThreadPtr();
1240 if (!thread)
1241 return llvm::createStringError("no thread to evaluate TLS within");
1242
1243 // Lookup the TLS block address for this thread and module.
1244 const addr_t tls_file_addr =
1245 eval_ctx.stack.back().GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1246 const addr_t tls_load_addr =
1247 thread->GetThreadLocalData(eval_ctx.module_sp, tls_file_addr);
1248
1249 if (tls_load_addr == LLDB_INVALID_ADDRESS)
1250 return llvm::createStringError(
1251 "no TLS data currently exists for this thread");
1252
1253 eval_ctx.stack.back().GetScalar() = tls_load_addr;
1254 eval_ctx.stack.back().SetValueType(Value::ValueType::LoadAddress);
1255 return llvm::Error::success();
1256}
1257
1258static llvm::Error Evaluate_DW_OP_fbreg(EvalContext &eval_ctx,
1259 int64_t fbreg_offset) {
1260 if (!eval_ctx.exe_ctx)
1261 return llvm::createStringError("NULL execution context for DW_OP_fbreg");
1262 if (!eval_ctx.frame)
1263 return llvm::createStringError(
1264 "invalid stack frame in context for DW_OP_fbreg opcode");
1265
1266 Scalar value;
1267 if (llvm::Error err = eval_ctx.frame->GetFrameBaseValue(value))
1268 return err;
1269 value += fbreg_offset;
1270 eval_ctx.stack.push_back(value);
1271 eval_ctx.stack.back().SetValueType(Value::ValueType::LoadAddress);
1272 return llvm::Error::success();
1273}
1274
1275static llvm::Error Evaluate_DW_OP_call_frame_cfa(EvalContext &eval_ctx) {
1276 if (!eval_ctx.frame)
1277 return llvm::createStringError(
1278 "invalid stack frame in context for DW_OP_call_frame_cfa opcode");
1279
1280 // Note that we don't have to parse FDEs because this DWARF expression
1281 // is commonly evaluated with a valid stack frame.
1282 StackID id = eval_ctx.frame->GetStackID();
1283 addr_t cfa = id.GetCallFrameAddressWithMetadata();
1284 if (cfa == LLDB_INVALID_ADDRESS)
1285 return llvm::createStringError("stack frame does not include a canonical "
1286 "frame address for DW_OP_call_frame_cfa "
1287 "opcode");
1288
1289 eval_ctx.stack.push_back(Scalar(cfa));
1290 eval_ctx.stack.back().SetValueType(Value::ValueType::LoadAddress);
1291 return llvm::Error::success();
1292}
1293
1294llvm::Expected<Value> DWARFExpression::Evaluate(
1295 ExecutionContext *exe_ctx, RegisterContext *reg_ctx,
1296 lldb::ModuleSP module_sp, const DataExtractor &opcodes,
1297 const DWARFExpression::Delegate *dwarf_cu,
1298 const lldb::RegisterKind reg_kind, const Value *initial_value_ptr,
1299 const Value *object_address_ptr) {
1300 uint32_t address_size = opcodes.GetAddressByteSize();
1301 llvm::DataExtractor expr_data = opcodes.GetAsLLVM();
1302 llvm::DWARFExpression expr(expr_data, address_size);
1303
1304 if (expr_data.size() == 0)
1305 return llvm::createStringError(
1306 "no location, value may have been optimized out");
1307
1308 EvalContext eval_ctx(exe_ctx, reg_ctx, std::move(module_sp), dwarf_cu,
1309 reg_kind, initial_value_ptr, object_address_ptr);
1310
1311 Stack &stack = eval_ctx.stack;
1312
1313 if (initial_value_ptr)
1314 stack.push_back(*initial_value_ptr);
1315
1316 Value tmp;
1317 uint32_t reg_num;
1318
1320 // A generic type is "an integral type that has the size of an address and an
1321 // unspecified signedness". For now, just use the signedness of the operand.
1322 // TODO: Implement a real typed stack, and store the genericness of the value
1323 // there.
1324 auto to_generic = [&](auto v) {
1325 // TODO: Avoid implicit trunc?
1326 // See https://github.com/llvm/llvm-project/issues/112510.
1327 bool is_signed = std::is_signed<decltype(v)>::value;
1328 return Scalar(llvm::APSInt(
1329 llvm::APInt(8 * address_size, v, is_signed, /*implicitTrunc=*/true),
1330 !is_signed));
1331 };
1332
1333 llvm::DWARFExpression::iterator op = expr.begin(), op_end = expr.end();
1334 while (op != op_end) {
1335 const uint64_t op_offset = op.getOffset();
1336 const LocationAtom opcode = static_cast<LocationAtom>(op->getCode());
1337
1338 if (log && log->GetVerbose()) {
1339 size_t count = stack.size();
1340 LLDB_LOGF(log, "Stack before operation has %" PRIu64 " values:",
1341 static_cast<uint64_t>(count));
1342 for (size_t i = 0; i < count; ++i) {
1343 StreamString new_value;
1344 new_value.Printf("[%" PRIu64 "]", static_cast<uint64_t>(i));
1345 stack[i].Dump(&new_value);
1346 LLDB_LOGF(log, " %s", new_value.GetData());
1347 }
1348 LLDB_LOGF(log, "0x%8.8" PRIx64 ": %s", op_offset,
1349 DW_OP_value_to_name(opcode));
1350 }
1351
1352 if (std::optional<unsigned> arity = OperationArity(opcode)) {
1353 if (stack.size() < *arity)
1354 return llvm::createStringError(
1355 "%s needs at least %d stack entries (stack has %d entries)",
1356 DW_OP_value_to_name(opcode), *arity, stack.size());
1357 }
1358
1359 switch (opcode) {
1360 case DW_OP_addr:
1361 stack.push_back(Scalar(op->getRawOperand(0)));
1362 if (eval_ctx.target && eval_ctx.target->GetArchitecture().GetCore() ==
1364 // wasm file sections aren't mapped into memory, therefore addresses can
1365 // never point into a file section and are always LoadAddresses.
1366 stack.back().SetValueType(Value::ValueType::LoadAddress);
1367 } else {
1368 stack.back().SetValueType(Value::ValueType::FileAddress);
1369 }
1370 break;
1371
1372 case DW_OP_deref: {
1373 size_t size = address_size;
1374 if (llvm::Error err = Evaluate_DW_OP_deref(eval_ctx, opcode, size, size))
1375 return err;
1376 } break;
1377
1378 case DW_OP_deref_size: {
1379 size_t size = op->getRawOperand(0);
1380 if (llvm::Error err =
1381 Evaluate_DW_OP_deref(eval_ctx, opcode, size, address_size))
1382 return err;
1383 } break;
1384
1385 case DW_OP_xderef_size:
1386 return llvm::createStringError("unimplemented opcode: DW_OP_xderef_size");
1387 case DW_OP_xderef:
1388 return llvm::createStringError("unimplemented opcode: DW_OP_xderef");
1389
1390 case DW_OP_const1u:
1391 stack.push_back(to_generic(op->getRawOperand(0)));
1392 break;
1393 case DW_OP_const1s:
1394 stack.push_back(to_generic(static_cast<int8_t>(op->getRawOperand(0))));
1395 break;
1396 case DW_OP_const2u:
1397 stack.push_back(to_generic(op->getRawOperand(0)));
1398 break;
1399 case DW_OP_const2s:
1400 stack.push_back(to_generic(static_cast<int16_t>(op->getRawOperand(0))));
1401 break;
1402 case DW_OP_const4u:
1403 stack.push_back(to_generic(op->getRawOperand(0)));
1404 break;
1405 case DW_OP_const4s:
1406 stack.push_back(to_generic(static_cast<int32_t>(op->getRawOperand(0))));
1407 break;
1408 case DW_OP_const8u:
1409 stack.push_back(to_generic(op->getRawOperand(0)));
1410 break;
1411 case DW_OP_const8s:
1412 stack.push_back(to_generic(static_cast<int64_t>(op->getRawOperand(0))));
1413 break;
1414 // These should also use to_generic, but we can't do that due to a
1415 // producer-side bug in llvm. See llvm.org/pr48087.
1416 case DW_OP_constu:
1417 stack.push_back(Scalar(op->getRawOperand(0)));
1418 break;
1419 case DW_OP_consts:
1420 stack.push_back(Scalar(static_cast<int64_t>(op->getRawOperand(0))));
1421 break;
1422
1423 case DW_OP_dup:
1424 if (stack.empty()) {
1425 return llvm::createStringError("expression stack empty for DW_OP_dup");
1426 } else
1427 stack.push_back(stack.back());
1428 break;
1429
1430 case DW_OP_drop:
1431 if (stack.empty()) {
1432 return llvm::createStringError("expression stack empty for DW_OP_drop");
1433 } else
1434 stack.pop_back();
1435 break;
1436
1437 case DW_OP_over:
1438 stack.push_back(stack[stack.size() - 2]);
1439 break;
1440
1441 case DW_OP_pick: {
1442 uint8_t pick_idx = op->getRawOperand(0);
1443 if (pick_idx < stack.size())
1444 stack.push_back(stack[stack.size() - 1 - pick_idx]);
1445 else {
1446 return llvm::createStringError(
1447 "Index %u out of range for DW_OP_pick.\n", pick_idx);
1448 }
1449 } break;
1450
1451 case DW_OP_swap:
1452 tmp = stack.back();
1453 stack.back() = stack[stack.size() - 2];
1454 stack[stack.size() - 2] = tmp;
1455 break;
1456
1457 case DW_OP_rot: {
1458 size_t last_idx = stack.size() - 1;
1459 Value old_top = stack[last_idx];
1460 stack[last_idx] = stack[last_idx - 1];
1461 stack[last_idx - 1] = stack[last_idx - 2];
1462 stack[last_idx - 2] = old_top;
1463 } break;
1464
1465 case DW_OP_abs:
1466 if (!stack.back().GetScalar().AbsoluteValue()) {
1467 return llvm::createStringError(
1468 "failed to take the absolute value of the first stack item");
1469 }
1470 break;
1471
1472 case DW_OP_and:
1473 tmp = stack.back();
1474 stack.pop_back();
1475 stack.back().GetScalar() = stack.back().GetScalar() & tmp.GetScalar();
1476 break;
1477
1478 case DW_OP_div: {
1479 tmp = stack.back();
1480 if (tmp.GetScalar().IsZero())
1481 return llvm::createStringError("divide by zero");
1482
1483 stack.pop_back();
1484 Scalar divisor, dividend;
1485 divisor = tmp.GetScalar();
1486 dividend = stack.back().GetScalar();
1487 divisor.MakeSigned();
1488 dividend.MakeSigned();
1489 stack.back() = dividend / divisor;
1490
1491 if (!stack.back().GetScalar().IsValid())
1492 return llvm::createStringError("divide failed");
1493 } break;
1494
1495 case DW_OP_minus:
1496 tmp = stack.back();
1497 stack.pop_back();
1498 stack.back().GetScalar() = stack.back().GetScalar() - tmp.GetScalar();
1499 break;
1500
1501 case DW_OP_mod:
1502 tmp = stack.back();
1503 stack.pop_back();
1504 stack.back().GetScalar() = stack.back().GetScalar() % tmp.GetScalar();
1505 break;
1506
1507 case DW_OP_mul:
1508 tmp = stack.back();
1509 stack.pop_back();
1510 stack.back().GetScalar() = stack.back().GetScalar() * tmp.GetScalar();
1511 break;
1512
1513 case DW_OP_neg:
1514 if (!stack.back().GetScalar().UnaryNegate())
1515 return llvm::createStringError("unary negate failed");
1516 break;
1517
1518 case DW_OP_not:
1519 if (!stack.back().GetScalar().OnesComplement())
1520 return llvm::createStringError("logical NOT failed");
1521 break;
1522
1523 case DW_OP_or:
1524 tmp = stack.back();
1525 stack.pop_back();
1526 stack.back().GetScalar() = stack.back().GetScalar() | tmp.GetScalar();
1527 break;
1528
1529 case DW_OP_plus:
1530 tmp = stack.back();
1531 stack.pop_back();
1532 stack.back().GetScalar() += tmp.GetScalar();
1533 break;
1534
1535 case DW_OP_plus_uconst: {
1536 const uint64_t uconst_value = op->getRawOperand(0);
1537 // Implicit conversion from a UINT to a Scalar...
1538 stack.back().GetScalar() += uconst_value;
1539 if (!stack.back().GetScalar().IsValid())
1540 return llvm::createStringError("DW_OP_plus_uconst failed");
1541 } break;
1542
1543 case DW_OP_shl:
1544 tmp = stack.back();
1545 stack.pop_back();
1546 stack.back().GetScalar() <<= tmp.GetScalar();
1547 break;
1548
1549 case DW_OP_shr:
1550 tmp = stack.back();
1551 stack.pop_back();
1552 if (!stack.back().GetScalar().ShiftRightLogical(tmp.GetScalar()))
1553 return llvm::createStringError("DW_OP_shr failed");
1554 break;
1555
1556 case DW_OP_shra:
1557 tmp = stack.back();
1558 stack.pop_back();
1559 stack.back().GetScalar() >>= tmp.GetScalar();
1560 break;
1561
1562 case DW_OP_xor:
1563 tmp = stack.back();
1564 stack.pop_back();
1565 stack.back().GetScalar() = stack.back().GetScalar() ^ tmp.GetScalar();
1566 break;
1567
1568 case DW_OP_skip: {
1569 int16_t skip_offset = static_cast<int16_t>(op->getRawOperand(0));
1570 lldb::offset_t new_offset = op->getEndOffset() + skip_offset;
1571 // New offset can point at the end of the data, in this case we should
1572 // terminate the DWARF expression evaluation (will happen in the loop
1573 // condition).
1574 if (new_offset <= expr_data.size()) {
1575 op = op.skipBytes(skip_offset);
1576 continue;
1577 }
1578 return llvm::createStringErrorV(
1579 "Invalid opcode offset in DW_OP_skip: {0}+({1}) > {2}",
1580 op->getEndOffset(), skip_offset, expr_data.size());
1581 }
1582
1583 case DW_OP_bra: {
1584 tmp = stack.back();
1585 stack.pop_back();
1586 int16_t bra_offset = static_cast<int16_t>(op->getRawOperand(0));
1587 Scalar zero(0);
1588 if (tmp.GetScalar() != zero) {
1589 lldb::offset_t new_offset = op->getEndOffset() + bra_offset;
1590 // New offset can point at the end of the data, in this case we should
1591 // terminate the DWARF expression evaluation (will happen in the loop
1592 // condition).
1593 if (new_offset <= expr_data.size()) {
1594 op = op.skipBytes(bra_offset);
1595 continue;
1596 }
1597 return llvm::createStringErrorV(
1598 "Invalid opcode offset in DW_OP_bra: {0}+({1}) > {2}",
1599 op->getEndOffset(), bra_offset, expr_data.size());
1600 }
1601 } break;
1602
1603 case DW_OP_eq:
1604 tmp = stack.back();
1605 stack.pop_back();
1606 stack.back().GetScalar() = stack.back().GetScalar() == tmp.GetScalar();
1607 break;
1608
1609 case DW_OP_ge:
1610 tmp = stack.back();
1611 stack.pop_back();
1612 stack.back().GetScalar() = stack.back().GetScalar() >= tmp.GetScalar();
1613 break;
1614
1615 case DW_OP_gt:
1616 tmp = stack.back();
1617 stack.pop_back();
1618 stack.back().GetScalar() = stack.back().GetScalar() > tmp.GetScalar();
1619 break;
1620
1621 case DW_OP_le:
1622 tmp = stack.back();
1623 stack.pop_back();
1624 stack.back().GetScalar() = stack.back().GetScalar() <= tmp.GetScalar();
1625 break;
1626
1627 case DW_OP_lt:
1628 tmp = stack.back();
1629 stack.pop_back();
1630 stack.back().GetScalar() = stack.back().GetScalar() < tmp.GetScalar();
1631 break;
1632
1633 case DW_OP_ne:
1634 tmp = stack.back();
1635 stack.pop_back();
1636 stack.back().GetScalar() = stack.back().GetScalar() != tmp.GetScalar();
1637 break;
1638
1639 case DW_OP_lit0:
1640 case DW_OP_lit1:
1641 case DW_OP_lit2:
1642 case DW_OP_lit3:
1643 case DW_OP_lit4:
1644 case DW_OP_lit5:
1645 case DW_OP_lit6:
1646 case DW_OP_lit7:
1647 case DW_OP_lit8:
1648 case DW_OP_lit9:
1649 case DW_OP_lit10:
1650 case DW_OP_lit11:
1651 case DW_OP_lit12:
1652 case DW_OP_lit13:
1653 case DW_OP_lit14:
1654 case DW_OP_lit15:
1655 case DW_OP_lit16:
1656 case DW_OP_lit17:
1657 case DW_OP_lit18:
1658 case DW_OP_lit19:
1659 case DW_OP_lit20:
1660 case DW_OP_lit21:
1661 case DW_OP_lit22:
1662 case DW_OP_lit23:
1663 case DW_OP_lit24:
1664 case DW_OP_lit25:
1665 case DW_OP_lit26:
1666 case DW_OP_lit27:
1667 case DW_OP_lit28:
1668 case DW_OP_lit29:
1669 case DW_OP_lit30:
1670 case DW_OP_lit31:
1671 stack.push_back(to_generic(opcode - DW_OP_lit0));
1672 break;
1673
1674 case DW_OP_reg0:
1675 case DW_OP_reg1:
1676 case DW_OP_reg2:
1677 case DW_OP_reg3:
1678 case DW_OP_reg4:
1679 case DW_OP_reg5:
1680 case DW_OP_reg6:
1681 case DW_OP_reg7:
1682 case DW_OP_reg8:
1683 case DW_OP_reg9:
1684 case DW_OP_reg10:
1685 case DW_OP_reg11:
1686 case DW_OP_reg12:
1687 case DW_OP_reg13:
1688 case DW_OP_reg14:
1689 case DW_OP_reg15:
1690 case DW_OP_reg16:
1691 case DW_OP_reg17:
1692 case DW_OP_reg18:
1693 case DW_OP_reg19:
1694 case DW_OP_reg20:
1695 case DW_OP_reg21:
1696 case DW_OP_reg22:
1697 case DW_OP_reg23:
1698 case DW_OP_reg24:
1699 case DW_OP_reg25:
1700 case DW_OP_reg26:
1701 case DW_OP_reg27:
1702 case DW_OP_reg28:
1703 case DW_OP_reg29:
1704 case DW_OP_reg30:
1705 case DW_OP_reg31: {
1706 eval_ctx.loc_desc_kind = Register;
1707 reg_num = opcode - DW_OP_reg0;
1708
1709 if (llvm::Error err = ReadRegisterValueAsScalar(
1710 eval_ctx.reg_ctx, eval_ctx.reg_kind, reg_num, tmp))
1711 return err;
1712 stack.push_back(tmp);
1713 } break;
1714 case DW_OP_regx: {
1715 eval_ctx.loc_desc_kind = Register;
1716 reg_num = op->getRawOperand(0);
1717 Status read_err;
1718 if (llvm::Error err = ReadRegisterValueAsScalar(
1719 eval_ctx.reg_ctx, eval_ctx.reg_kind, reg_num, tmp))
1720 return err;
1721 stack.push_back(tmp);
1722 } break;
1723
1724 case DW_OP_breg0:
1725 case DW_OP_breg1:
1726 case DW_OP_breg2:
1727 case DW_OP_breg3:
1728 case DW_OP_breg4:
1729 case DW_OP_breg5:
1730 case DW_OP_breg6:
1731 case DW_OP_breg7:
1732 case DW_OP_breg8:
1733 case DW_OP_breg9:
1734 case DW_OP_breg10:
1735 case DW_OP_breg11:
1736 case DW_OP_breg12:
1737 case DW_OP_breg13:
1738 case DW_OP_breg14:
1739 case DW_OP_breg15:
1740 case DW_OP_breg16:
1741 case DW_OP_breg17:
1742 case DW_OP_breg18:
1743 case DW_OP_breg19:
1744 case DW_OP_breg20:
1745 case DW_OP_breg21:
1746 case DW_OP_breg22:
1747 case DW_OP_breg23:
1748 case DW_OP_breg24:
1749 case DW_OP_breg25:
1750 case DW_OP_breg26:
1751 case DW_OP_breg27:
1752 case DW_OP_breg28:
1753 case DW_OP_breg29:
1754 case DW_OP_breg30:
1755 case DW_OP_breg31: {
1756 reg_num = opcode - DW_OP_breg0;
1757 if (llvm::Error err = ReadRegisterValueAsScalar(
1758 eval_ctx.reg_ctx, eval_ctx.reg_kind, reg_num, tmp))
1759 return err;
1760
1761 int64_t breg_offset = op->getRawOperand(0);
1762 tmp.GetScalar() += static_cast<uint64_t>(breg_offset);
1763 tmp.ClearContext();
1764 stack.push_back(tmp);
1765 stack.back().SetValueType(Value::ValueType::LoadAddress);
1766 } break;
1767 case DW_OP_bregx: {
1768 reg_num = op->getRawOperand(0);
1769 if (llvm::Error err = ReadRegisterValueAsScalar(
1770 eval_ctx.reg_ctx, eval_ctx.reg_kind, reg_num, tmp))
1771 return err;
1772
1773 int64_t breg_offset = op->getRawOperand(1);
1774 tmp.GetScalar() += static_cast<uint64_t>(breg_offset);
1775 tmp.ClearContext();
1776 stack.push_back(tmp);
1777 stack.back().SetValueType(Value::ValueType::LoadAddress);
1778 } break;
1779
1780 case DW_OP_fbreg:
1781 if (llvm::Error err =
1782 Evaluate_DW_OP_fbreg(eval_ctx, op->getRawOperand(0)))
1783 return err;
1784 break;
1785
1786 case DW_OP_nop:
1787 break;
1788
1789 case DW_OP_piece: {
1790 if (llvm::Error err =
1791 Evaluate_DW_OP_piece(eval_ctx, op->getRawOperand(0)))
1792 return err;
1793 } break;
1794
1795 case DW_OP_bit_piece:
1796 if (stack.size() < 1) {
1798 LocationDescriptionKind::Empty);
1799 // Reset for the next piece.
1800 eval_ctx.loc_desc_kind = Memory;
1801 return llvm::createStringError(
1802 "expression stack needs at least 1 item for DW_OP_bit_piece");
1803 } else {
1804 UpdateValueTypeFromLocationDescription(eval_ctx, eval_ctx.loc_desc_kind,
1805 &stack.back());
1806 // Reset for the next piece.
1807 eval_ctx.loc_desc_kind = Memory;
1808 const uint64_t piece_bit_size = op->getRawOperand(0);
1809 const uint64_t piece_bit_offset = op->getRawOperand(1);
1810 switch (stack.back().GetValueType()) {
1812 return llvm::createStringError(
1813 "unable to extract bit value from invalid value");
1815 if (!stack.back().GetScalar().ExtractBitfield(piece_bit_size,
1816 piece_bit_offset)) {
1817 return llvm::createStringError(
1818 "unable to extract %" PRIu64 " bit value with %" PRIu64
1819 " bit offset from a %" PRIu64 " bit scalar value.",
1820 piece_bit_size, piece_bit_offset,
1821 (uint64_t)(stack.back().GetScalar().GetByteSize() * 8));
1822 }
1823 } break;
1824
1828 return llvm::createStringError(
1829 "unable to extract DW_OP_bit_piece(bit_size = %" PRIu64
1830 ", bit_offset = %" PRIu64 ") from an address value.",
1831 piece_bit_size, piece_bit_offset);
1832 }
1833 }
1834 break;
1835
1836 case DW_OP_implicit_value: {
1837 eval_ctx.loc_desc_kind = Implicit;
1838
1839 // The second operand is a sequence of bytes of the length specified by
1840 // the first operand. LLVM represents it as an offset to that sequence.
1841 const uint64_t block_size = op->getRawOperand(0);
1842 uint64_t block_offset = op->getRawOperand(1);
1843
1844 llvm::Error error = llvm::Error::success();
1845 llvm::StringRef block_data =
1846 expr_data.getBytes(&block_offset, block_size, &error);
1847
1848 if (error)
1849 return error;
1850
1851 Value result(block_data.data(), block_data.size());
1852 stack.push_back(result);
1853 break;
1854 }
1855
1856 case DW_OP_implicit_pointer: {
1857 eval_ctx.loc_desc_kind = Implicit;
1858 return llvm::createStringError("could not evaluate %s",
1859 DW_OP_value_to_name(opcode));
1860 }
1861
1862 case DW_OP_push_object_address:
1863 if (eval_ctx.object_address_ptr)
1864 stack.push_back(*eval_ctx.object_address_ptr);
1865 else {
1866 return llvm::createStringError("DW_OP_push_object_address used without "
1867 "specifying an object address");
1868 }
1869 break;
1870
1871 case DW_OP_call2:
1872 return llvm::createStringError("unimplemented opcode DW_OP_call2");
1873 case DW_OP_call4:
1874 return llvm::createStringError("unimplemented opcode DW_OP_call4");
1875
1876 case DW_OP_stack_value:
1877 eval_ctx.loc_desc_kind = Implicit;
1878 stack.back().SetValueType(Value::ValueType::Scalar);
1879 break;
1880
1881 case DW_OP_convert:
1882 if (llvm::Error err =
1883 Evaluate_DW_OP_convert(eval_ctx, op->getRawOperand(0)))
1884 return err;
1885 break;
1886
1887 case DW_OP_call_frame_cfa:
1888 if (llvm::Error err = Evaluate_DW_OP_call_frame_cfa(eval_ctx))
1889 return err;
1890 break;
1891
1892 case DW_OP_form_tls_address:
1893 case DW_OP_GNU_push_tls_address:
1894 if (llvm::Error err = Evaluate_DW_OP_form_tls_address(eval_ctx, opcode))
1895 return err;
1896 break;
1897
1898 case DW_OP_addrx:
1899 case DW_OP_GNU_addr_index: {
1900 if (!eval_ctx.dwarf_cu)
1901 return llvm::createStringError("DW_OP_GNU_addr_index found without a "
1902 "compile unit being specified");
1903 uint64_t index = op->getRawOperand(0);
1904 lldb::addr_t value =
1905 eval_ctx.dwarf_cu->ReadAddressFromDebugAddrSection(index);
1906 stack.push_back(Scalar(value));
1907 if (eval_ctx.target && eval_ctx.target->GetArchitecture().GetCore() ==
1909 // wasm file sections aren't mapped into memory, therefore addresses can
1910 // never point into a file section and are always LoadAddresses.
1911 stack.back().SetValueType(Value::ValueType::LoadAddress);
1912 } else {
1913 stack.back().SetValueType(Value::ValueType::FileAddress);
1914 }
1915 } break;
1916
1917 case DW_OP_GNU_const_index: {
1918 if (!eval_ctx.dwarf_cu) {
1919 return llvm::createStringError("DW_OP_GNU_const_index found without a "
1920 "compile unit being specified");
1921 }
1922 uint64_t index = op->getRawOperand(0);
1923 lldb::addr_t value =
1924 eval_ctx.dwarf_cu->ReadAddressFromDebugAddrSection(index);
1925 stack.push_back(Scalar(value));
1926 } break;
1927
1928 case DW_OP_GNU_entry_value:
1929 case DW_OP_entry_value: {
1930 // Technically, DW_OP_entry_value has two operands, but LLVM represents
1931 // it as a single-operand operation (bug?). We can deal with this: the
1932 // second operand immediately follows the first, but have to be careful
1933 // when advancing the iterator, see the comment below.
1934 const uint64_t block_size = op->getRawOperand(0);
1935 uint64_t block_offset = op->getEndOffset();
1936
1937 llvm::Error error = llvm::Error::success();
1938 llvm::ArrayRef<uint8_t> block_data = llvm::arrayRefFromStringRef(
1939 expr_data.getBytes(&block_offset, block_size, &error));
1940
1941 if (error)
1942 return error;
1943
1944 if (llvm::Error err = Evaluate_DW_OP_entry_value(eval_ctx, block_data))
1945 return llvm::createStringError(
1946 "could not evaluate DW_OP_entry_value: %s",
1947 llvm::toString(std::move(err)).c_str());
1948
1949 // We can't use `operator++` here because the iterator currently points
1950 // to the second operand. See the comment above.
1951 op = op.skipBytes(block_size);
1952 continue;
1953 }
1954
1955 default:
1956 if (eval_ctx.dwarf_cu) {
1957 const uint64_t operands_offset = op_offset + 1;
1958 uint64_t offset = operands_offset; // Updated by the callee.
1959 if (eval_ctx.dwarf_cu->ParseVendorDWARFOpcode(
1960 opcode, expr_data, offset, eval_ctx.reg_ctx, eval_ctx.reg_kind,
1961 stack)) {
1962 // This is a little tricky. If LLVM knows about this vendor-specific
1963 // operation, `getEndOffset()` points past its last operand. If LLVM
1964 // knows nothing about this operation, `getEndOffset()` points to its
1965 // opcode. In both cases `offset` will point to the next operation,
1966 // but we can't use it directly because the only available mutating
1967 // method of `iterator` (not counting `operator++`) is `skipBytes()`.
1968 // So we calculate the offset and pass it to `skipBytes()`.
1969 assert(offset >= op->getEndOffset());
1970 uint64_t offset_to_next_op = offset - op->getEndOffset();
1971 op = op.skipBytes(offset_to_next_op);
1972 continue;
1973 }
1974 }
1975 return llvm::createStringErrorV("unhandled opcode {0} in DWARFExpression",
1976 opcode);
1977 }
1978 ++op;
1979 }
1980
1981 if (stack.empty()) {
1982 // Nothing on the stack, check if we created a piece value from DW_OP_piece
1983 // or DW_OP_bit_piece opcodes
1984 if (eval_ctx.pieces.GetBuffer().GetByteSize())
1985 return eval_ctx.pieces;
1986
1987 return llvm::createStringError("stack empty after evaluation");
1988 }
1989
1990 UpdateValueTypeFromLocationDescription(eval_ctx, eval_ctx.loc_desc_kind,
1991 &stack.back());
1992
1993 if (log && log->GetVerbose()) {
1994 size_t count = stack.size();
1995 LLDB_LOGF(log, "Stack after operation has %" PRIu64 " values:",
1996 static_cast<uint64_t>(count));
1997 for (size_t i = 0; i < count; ++i) {
1998 StreamString new_value;
1999 new_value.Printf("[%" PRIu64 "]", static_cast<uint64_t>(i));
2000 stack[i].Dump(&new_value);
2001 LLDB_LOGF(log, " %s", new_value.GetData());
2002 }
2003 }
2004 return stack.back();
2005}
2006
2008 StackFrame &frame, const Instruction::Operand &operand) const {
2009 using namespace OperandMatchers;
2010
2011 RegisterContextSP reg_ctx_sp = frame.GetRegisterContext();
2012 if (!reg_ctx_sp) {
2013 return false;
2014 }
2015
2016 DataExtractor opcodes(m_data);
2017
2018 lldb::offset_t op_offset = 0;
2019 uint8_t opcode = opcodes.GetU8(&op_offset);
2020
2021 if (opcode == DW_OP_fbreg) {
2022 int64_t offset = opcodes.GetSLEB128(&op_offset);
2023
2024 DWARFExpressionList *fb_expr = frame.GetFrameBaseExpression(nullptr);
2025 if (!fb_expr) {
2026 return false;
2027 }
2028
2029 auto recurse = [&frame, fb_expr](const Instruction::Operand &child) {
2030 return fb_expr->MatchesOperand(frame, child);
2031 };
2032
2033 if (!offset &&
2034 MatchUnaryOp(MatchOpType(Instruction::Operand::Type::Dereference),
2035 recurse)(operand)) {
2036 return true;
2037 }
2038
2039 return MatchUnaryOp(
2041 MatchBinaryOp(MatchOpType(Instruction::Operand::Type::Sum),
2042 MatchImmOp(offset), recurse))(operand);
2043 }
2044
2045 bool dereference = false;
2046 const RegisterInfo *reg = nullptr;
2047 int64_t offset = 0;
2048
2049 if (opcode >= DW_OP_reg0 && opcode <= DW_OP_reg31) {
2050 reg = reg_ctx_sp->GetRegisterInfo(m_reg_kind, opcode - DW_OP_reg0);
2051 } else if (opcode >= DW_OP_breg0 && opcode <= DW_OP_breg31) {
2052 offset = opcodes.GetSLEB128(&op_offset);
2053 reg = reg_ctx_sp->GetRegisterInfo(m_reg_kind, opcode - DW_OP_breg0);
2054 } else if (opcode == DW_OP_regx) {
2055 uint32_t reg_num = static_cast<uint32_t>(opcodes.GetULEB128(&op_offset));
2056 reg = reg_ctx_sp->GetRegisterInfo(m_reg_kind, reg_num);
2057 } else if (opcode == DW_OP_bregx) {
2058 uint32_t reg_num = static_cast<uint32_t>(opcodes.GetULEB128(&op_offset));
2059 offset = opcodes.GetSLEB128(&op_offset);
2060 reg = reg_ctx_sp->GetRegisterInfo(m_reg_kind, reg_num);
2061 } else {
2062 return false;
2063 }
2064
2065 if (!reg) {
2066 return false;
2067 }
2068
2069 if (dereference) {
2070 if (!offset &&
2071 MatchUnaryOp(MatchOpType(Instruction::Operand::Type::Dereference),
2072 MatchRegOp(*reg))(operand)) {
2073 return true;
2074 }
2075
2076 return MatchUnaryOp(
2078 MatchBinaryOp(MatchOpType(Instruction::Operand::Type::Sum),
2079 MatchRegOp(*reg), MatchImmOp(offset)))(operand);
2080 } else {
2081 return MatchRegOp(*reg)(operand);
2082 }
2083}
static llvm::raw_ostream & error(Stream &strm)
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 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 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)
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition Log.h:364
#define LLDB_LOGF(log,...)
Definition Log.h:378
@ Empty
If the Mangled object has neither a mangled name or demangled name we can encode the object with one ...
Definition Mangled.cpp:455
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:301
bool IsSectionOffset() const
Check if an address is section offset.
Definition Address.h:342
Core GetCore() const
Definition ArchSpec.h:451
Represent a call made within a Function.
Definition Function.h:268
virtual Function * GetCallee(ModuleList &images, ExecutionContext &exe_ctx)=0
Get the callee's definition.
llvm::ArrayRef< CallSiteParameter > GetCallSiteParameters() const
Get the call site parameters available at this call edge.
Definition Function.h:297
"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 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 llvm::Expected< std::pair< uint64_t, bool > > GetDIEBitSizeAndSign(uint64_t relative_die_offset) 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 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 a 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.
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:392
ConstString GetName() const
Definition Function.cpp:713
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:372
llvm::ArrayRef< std::unique_ptr< CallEdge > > GetTailCallingEdges()
Get the outgoing tail-calling edges from this function.
Definition Function.cpp:365
bool GetVerbose() const
Definition Log.cpp:300
A collection class for Module objects.
Definition ModuleList.h:125
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.
virtual size_t ReadMemory(lldb::addr_t vm_addr, void *buf, size_t size, Status &error)
Read of memory from a process.
Definition Process.cpp:2027
lldb::ByteOrder GetByteOrder() const
Definition Process.cpp:3897
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:162
bool IsZero() const
Definition Scalar.cpp:174
void TruncOrExtendTo(uint16_t bits, bool sign)
Convert to an integer with bits and the given signedness.
Definition Scalar.cpp:204
unsigned long long ULongLong(unsigned long long fail_value=0) const
Definition Scalar.cpp:365
bool ExtractBitfield(uint32_t bit_size, uint32_t bit_offset)
Definition Scalar.cpp:813
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
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:2062
const ModuleList & GetImages() const
Get accessor for the images for this process.
Definition Target.h:1240
const ArchSpec & GetArchitecture() const
Definition Target.h:1282
const Scalar & GetScalar() const
See comment on m_scalar to understand what GetScalar returns.
Definition Value.h:113
ValueType
Type that describes Value::m_value.
Definition Value.h:41
@ HostAddress
A host address value (for memory in the process that < A is using liblldb).
Definition Value.h:52
@ FileAddress
A file address value.
Definition Value.h:47
@ LoadAddress
A load address value.
Definition Value.h:49
@ Scalar
A raw scalar value.
Definition Value.h:45
void ClearContext()
Definition Value.h:91
size_t AppendDataToHostBuffer(const Value &rhs)
Definition Value.cpp:154
ValueType GetValueType() const
Definition Value.cpp:111
void SetContext(ContextType context_type, void *p)
Definition Value.h:96
DataBufferHeap & GetBuffer()
Definition Value.h:122
void SetValueType(ValueType value_type)
Definition Value.h:89
@ RegisterInfo
RegisterInfo * (can be a scalar or a vector register).
Definition Value.h:61
void ConvertToLoadAddress(Module *module, Target *target)
Convert this value's file address to a load address, if possible.
Definition Value.cpp:675
size_t ResizeData(size_t len)
Definition Value.cpp:192
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:327
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
uint64_t offset_t
Definition lldb-types.h:85
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:256
DWARFExpressionList LocationInCaller
Definition Function.h:258
Every register is described in detail including its name, alternate name (optional),...
const char * name
Name of this register, can't be NULL.