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 
10 
11 #include <cinttypes>
12 
13 #include <vector>
14 
15 #include "lldb/Core/Module.h"
16 #include "lldb/Core/Value.h"
17 #include "lldb/Core/dwarf.h"
19 #include "lldb/Utility/LLDBLog.h"
20 #include "lldb/Utility/Log.h"
22 #include "lldb/Utility/Scalar.h"
24 #include "lldb/Utility/VMRange.h"
25 
26 #include "lldb/Host/Host.h"
27 #include "lldb/Utility/Endian.h"
28 
29 #include "lldb/Symbol/Function.h"
30 
31 #include "lldb/Target/ABI.h"
33 #include "lldb/Target/Process.h"
35 #include "lldb/Target/StackFrame.h"
36 #include "lldb/Target/StackID.h"
37 #include "lldb/Target/Target.h"
38 #include "lldb/Target/Thread.h"
39 #include "llvm/DebugInfo/DWARF/DWARFDebugLoc.h"
40 #include "llvm/DebugInfo/DWARF/DWARFExpression.h"
41 
43 
44 using namespace lldb;
45 using namespace lldb_private;
46 using namespace lldb_private::dwarf;
47 
48 // DWARFExpression constructor
49 DWARFExpression::DWARFExpression() : m_data() {}
50 
51 DWARFExpression::DWARFExpression(const DataExtractor &data) : m_data(data) {}
52 
53 // Destructor
55 
56 bool DWARFExpression::IsValid() const { return m_data.GetByteSize() > 0; }
57 
58 void DWARFExpression::UpdateValue(uint64_t const_value,
59  lldb::offset_t const_value_byte_size,
60  uint8_t addr_byte_size) {
61  if (!const_value_byte_size)
62  return;
63 
65  DataBufferSP(new DataBufferHeap(&const_value, const_value_byte_size)));
67  m_data.SetAddressByteSize(addr_byte_size);
68 }
69 
71  ABI *abi) const {
72  llvm::DWARFExpression(m_data.GetAsLLVM(), m_data.GetAddressByteSize())
73  .print(s->AsRawOstream(), llvm::DIDumpOptions(),
74  abi ? &abi->GetMCRegisterInfo() : nullptr, nullptr);
75 }
76 
78 
80  m_reg_kind = reg_kind;
81 }
82 
83 
85  lldb::RegisterKind reg_kind,
86  uint32_t reg_num, Status *error_ptr,
87  Value &value) {
88  if (reg_ctx == nullptr) {
89  if (error_ptr)
90  error_ptr->SetErrorString("No register context in frame.\n");
91  } else {
92  uint32_t native_reg =
93  reg_ctx->ConvertRegisterKindToRegisterNumber(reg_kind, reg_num);
94  if (native_reg == LLDB_INVALID_REGNUM) {
95  if (error_ptr)
96  error_ptr->SetErrorStringWithFormat("Unable to convert register "
97  "kind=%u reg_num=%u to a native "
98  "register number.\n",
99  reg_kind, reg_num);
100  } else {
101  const RegisterInfo *reg_info =
102  reg_ctx->GetRegisterInfoAtIndex(native_reg);
103  RegisterValue reg_value;
104  if (reg_ctx->ReadRegister(reg_info, reg_value)) {
105  if (reg_value.GetScalarValue(value.GetScalar())) {
108  const_cast<RegisterInfo *>(reg_info));
109  if (error_ptr)
110  error_ptr->Clear();
111  return true;
112  } else {
113  // If we get this error, then we need to implement a value buffer in
114  // the dwarf expression evaluation function...
115  if (error_ptr)
116  error_ptr->SetErrorStringWithFormat(
117  "register %s can't be converted to a scalar value",
118  reg_info->name);
119  }
120  } else {
121  if (error_ptr)
122  error_ptr->SetErrorStringWithFormat("register %s is not available",
123  reg_info->name);
124  }
125  }
126  }
127  return false;
128 }
129 
130 /// Return the length in bytes of the set of operands for \p op. No guarantees
131 /// are made on the state of \p data after this call.
133  const lldb::offset_t data_offset,
134  const uint8_t op, const DWARFUnit *dwarf_cu) {
135  lldb::offset_t offset = data_offset;
136  switch (op) {
137  case DW_OP_addr:
138  case DW_OP_call_ref: // 0x9a 1 address sized offset of DIE (DWARF3)
139  return data.GetAddressByteSize();
140 
141  // Opcodes with no arguments
142  case DW_OP_deref: // 0x06
143  case DW_OP_dup: // 0x12
144  case DW_OP_drop: // 0x13
145  case DW_OP_over: // 0x14
146  case DW_OP_swap: // 0x16
147  case DW_OP_rot: // 0x17
148  case DW_OP_xderef: // 0x18
149  case DW_OP_abs: // 0x19
150  case DW_OP_and: // 0x1a
151  case DW_OP_div: // 0x1b
152  case DW_OP_minus: // 0x1c
153  case DW_OP_mod: // 0x1d
154  case DW_OP_mul: // 0x1e
155  case DW_OP_neg: // 0x1f
156  case DW_OP_not: // 0x20
157  case DW_OP_or: // 0x21
158  case DW_OP_plus: // 0x22
159  case DW_OP_shl: // 0x24
160  case DW_OP_shr: // 0x25
161  case DW_OP_shra: // 0x26
162  case DW_OP_xor: // 0x27
163  case DW_OP_eq: // 0x29
164  case DW_OP_ge: // 0x2a
165  case DW_OP_gt: // 0x2b
166  case DW_OP_le: // 0x2c
167  case DW_OP_lt: // 0x2d
168  case DW_OP_ne: // 0x2e
169  case DW_OP_lit0: // 0x30
170  case DW_OP_lit1: // 0x31
171  case DW_OP_lit2: // 0x32
172  case DW_OP_lit3: // 0x33
173  case DW_OP_lit4: // 0x34
174  case DW_OP_lit5: // 0x35
175  case DW_OP_lit6: // 0x36
176  case DW_OP_lit7: // 0x37
177  case DW_OP_lit8: // 0x38
178  case DW_OP_lit9: // 0x39
179  case DW_OP_lit10: // 0x3A
180  case DW_OP_lit11: // 0x3B
181  case DW_OP_lit12: // 0x3C
182  case DW_OP_lit13: // 0x3D
183  case DW_OP_lit14: // 0x3E
184  case DW_OP_lit15: // 0x3F
185  case DW_OP_lit16: // 0x40
186  case DW_OP_lit17: // 0x41
187  case DW_OP_lit18: // 0x42
188  case DW_OP_lit19: // 0x43
189  case DW_OP_lit20: // 0x44
190  case DW_OP_lit21: // 0x45
191  case DW_OP_lit22: // 0x46
192  case DW_OP_lit23: // 0x47
193  case DW_OP_lit24: // 0x48
194  case DW_OP_lit25: // 0x49
195  case DW_OP_lit26: // 0x4A
196  case DW_OP_lit27: // 0x4B
197  case DW_OP_lit28: // 0x4C
198  case DW_OP_lit29: // 0x4D
199  case DW_OP_lit30: // 0x4E
200  case DW_OP_lit31: // 0x4f
201  case DW_OP_reg0: // 0x50
202  case DW_OP_reg1: // 0x51
203  case DW_OP_reg2: // 0x52
204  case DW_OP_reg3: // 0x53
205  case DW_OP_reg4: // 0x54
206  case DW_OP_reg5: // 0x55
207  case DW_OP_reg6: // 0x56
208  case DW_OP_reg7: // 0x57
209  case DW_OP_reg8: // 0x58
210  case DW_OP_reg9: // 0x59
211  case DW_OP_reg10: // 0x5A
212  case DW_OP_reg11: // 0x5B
213  case DW_OP_reg12: // 0x5C
214  case DW_OP_reg13: // 0x5D
215  case DW_OP_reg14: // 0x5E
216  case DW_OP_reg15: // 0x5F
217  case DW_OP_reg16: // 0x60
218  case DW_OP_reg17: // 0x61
219  case DW_OP_reg18: // 0x62
220  case DW_OP_reg19: // 0x63
221  case DW_OP_reg20: // 0x64
222  case DW_OP_reg21: // 0x65
223  case DW_OP_reg22: // 0x66
224  case DW_OP_reg23: // 0x67
225  case DW_OP_reg24: // 0x68
226  case DW_OP_reg25: // 0x69
227  case DW_OP_reg26: // 0x6A
228  case DW_OP_reg27: // 0x6B
229  case DW_OP_reg28: // 0x6C
230  case DW_OP_reg29: // 0x6D
231  case DW_OP_reg30: // 0x6E
232  case DW_OP_reg31: // 0x6F
233  case DW_OP_nop: // 0x96
234  case DW_OP_push_object_address: // 0x97 DWARF3
235  case DW_OP_form_tls_address: // 0x9b DWARF3
236  case DW_OP_call_frame_cfa: // 0x9c DWARF3
237  case DW_OP_stack_value: // 0x9f DWARF4
238  case DW_OP_GNU_push_tls_address: // 0xe0 GNU extension
239  return 0;
240 
241  // Opcodes with a single 1 byte arguments
242  case DW_OP_const1u: // 0x08 1 1-byte constant
243  case DW_OP_const1s: // 0x09 1 1-byte constant
244  case DW_OP_pick: // 0x15 1 1-byte stack index
245  case DW_OP_deref_size: // 0x94 1 1-byte size of data retrieved
246  case DW_OP_xderef_size: // 0x95 1 1-byte size of data retrieved
247  return 1;
248 
249  // Opcodes with a single 2 byte arguments
250  case DW_OP_const2u: // 0x0a 1 2-byte constant
251  case DW_OP_const2s: // 0x0b 1 2-byte constant
252  case DW_OP_skip: // 0x2f 1 signed 2-byte constant
253  case DW_OP_bra: // 0x28 1 signed 2-byte constant
254  case DW_OP_call2: // 0x98 1 2-byte offset of DIE (DWARF3)
255  return 2;
256 
257  // Opcodes with a single 4 byte arguments
258  case DW_OP_const4u: // 0x0c 1 4-byte constant
259  case DW_OP_const4s: // 0x0d 1 4-byte constant
260  case DW_OP_call4: // 0x99 1 4-byte offset of DIE (DWARF3)
261  return 4;
262 
263  // Opcodes with a single 8 byte arguments
264  case DW_OP_const8u: // 0x0e 1 8-byte constant
265  case DW_OP_const8s: // 0x0f 1 8-byte constant
266  return 8;
267 
268  // All opcodes that have a single ULEB (signed or unsigned) argument
269  case DW_OP_addrx: // 0xa1 1 ULEB128 index
270  case DW_OP_constu: // 0x10 1 ULEB128 constant
271  case DW_OP_consts: // 0x11 1 SLEB128 constant
272  case DW_OP_plus_uconst: // 0x23 1 ULEB128 addend
273  case DW_OP_breg0: // 0x70 1 ULEB128 register
274  case DW_OP_breg1: // 0x71 1 ULEB128 register
275  case DW_OP_breg2: // 0x72 1 ULEB128 register
276  case DW_OP_breg3: // 0x73 1 ULEB128 register
277  case DW_OP_breg4: // 0x74 1 ULEB128 register
278  case DW_OP_breg5: // 0x75 1 ULEB128 register
279  case DW_OP_breg6: // 0x76 1 ULEB128 register
280  case DW_OP_breg7: // 0x77 1 ULEB128 register
281  case DW_OP_breg8: // 0x78 1 ULEB128 register
282  case DW_OP_breg9: // 0x79 1 ULEB128 register
283  case DW_OP_breg10: // 0x7a 1 ULEB128 register
284  case DW_OP_breg11: // 0x7b 1 ULEB128 register
285  case DW_OP_breg12: // 0x7c 1 ULEB128 register
286  case DW_OP_breg13: // 0x7d 1 ULEB128 register
287  case DW_OP_breg14: // 0x7e 1 ULEB128 register
288  case DW_OP_breg15: // 0x7f 1 ULEB128 register
289  case DW_OP_breg16: // 0x80 1 ULEB128 register
290  case DW_OP_breg17: // 0x81 1 ULEB128 register
291  case DW_OP_breg18: // 0x82 1 ULEB128 register
292  case DW_OP_breg19: // 0x83 1 ULEB128 register
293  case DW_OP_breg20: // 0x84 1 ULEB128 register
294  case DW_OP_breg21: // 0x85 1 ULEB128 register
295  case DW_OP_breg22: // 0x86 1 ULEB128 register
296  case DW_OP_breg23: // 0x87 1 ULEB128 register
297  case DW_OP_breg24: // 0x88 1 ULEB128 register
298  case DW_OP_breg25: // 0x89 1 ULEB128 register
299  case DW_OP_breg26: // 0x8a 1 ULEB128 register
300  case DW_OP_breg27: // 0x8b 1 ULEB128 register
301  case DW_OP_breg28: // 0x8c 1 ULEB128 register
302  case DW_OP_breg29: // 0x8d 1 ULEB128 register
303  case DW_OP_breg30: // 0x8e 1 ULEB128 register
304  case DW_OP_breg31: // 0x8f 1 ULEB128 register
305  case DW_OP_regx: // 0x90 1 ULEB128 register
306  case DW_OP_fbreg: // 0x91 1 SLEB128 offset
307  case DW_OP_piece: // 0x93 1 ULEB128 size of piece addressed
308  case DW_OP_GNU_addr_index: // 0xfb 1 ULEB128 index
309  case DW_OP_GNU_const_index: // 0xfc 1 ULEB128 index
310  data.Skip_LEB128(&offset);
311  return offset - data_offset;
312 
313  // All opcodes that have a 2 ULEB (signed or unsigned) arguments
314  case DW_OP_bregx: // 0x92 2 ULEB128 register followed by SLEB128 offset
315  case DW_OP_bit_piece: // 0x9d ULEB128 bit size, ULEB128 bit offset (DWARF3);
316  data.Skip_LEB128(&offset);
317  data.Skip_LEB128(&offset);
318  return offset - data_offset;
319 
320  case DW_OP_implicit_value: // 0x9e ULEB128 size followed by block of that size
321  // (DWARF4)
322  {
323  uint64_t block_len = data.Skip_LEB128(&offset);
324  offset += block_len;
325  return offset - data_offset;
326  }
327 
328  case DW_OP_GNU_entry_value:
329  case DW_OP_entry_value: // 0xa3 ULEB128 size + variable-length block
330  {
331  uint64_t subexpr_len = data.GetULEB128(&offset);
332  return (offset - data_offset) + subexpr_len;
333  }
334 
335  default:
336  if (!dwarf_cu) {
337  return LLDB_INVALID_OFFSET;
338  }
339  return dwarf_cu->GetSymbolFileDWARF().GetVendorDWARFOpcodeSize(
340  data, data_offset, op);
341  }
342 }
343 
345  uint32_t op_addr_idx,
346  bool &error) const {
347  error = false;
348  lldb::offset_t offset = 0;
349  uint32_t curr_op_addr_idx = 0;
350  while (m_data.ValidOffset(offset)) {
351  const uint8_t op = m_data.GetU8(&offset);
352 
353  if (op == DW_OP_addr) {
354  const lldb::addr_t op_file_addr = m_data.GetAddress(&offset);
355  if (curr_op_addr_idx == op_addr_idx)
356  return op_file_addr;
357  ++curr_op_addr_idx;
358  } else if (op == DW_OP_GNU_addr_index || op == DW_OP_addrx) {
359  uint64_t index = m_data.GetULEB128(&offset);
360  if (curr_op_addr_idx == op_addr_idx) {
361  if (!dwarf_cu) {
362  error = true;
363  break;
364  }
365 
366  return dwarf_cu->ReadAddressFromDebugAddrSection(index);
367  }
368  ++curr_op_addr_idx;
369  } else {
370  const offset_t op_arg_size =
371  GetOpcodeDataSize(m_data, offset, op, dwarf_cu);
372  if (op_arg_size == LLDB_INVALID_OFFSET) {
373  error = true;
374  break;
375  }
376  offset += op_arg_size;
377  }
378  }
379  return LLDB_INVALID_ADDRESS;
380 }
381 
383  lldb::addr_t file_addr) {
384  lldb::offset_t offset = 0;
385  while (m_data.ValidOffset(offset)) {
386  const uint8_t op = m_data.GetU8(&offset);
387 
388  if (op == DW_OP_addr) {
389  const uint32_t addr_byte_size = m_data.GetAddressByteSize();
390  // We have to make a copy of the data as we don't know if this data is
391  // from a read only memory mapped buffer, so we duplicate all of the data
392  // first, then modify it, and if all goes well, we then replace the data
393  // for this expression
394 
395  // Make en encoder that contains a copy of the location expression data
396  // so we can write the address into the buffer using the correct byte
397  // order.
398  DataEncoder encoder(m_data.GetDataStart(), m_data.GetByteSize(),
399  m_data.GetByteOrder(), addr_byte_size);
400 
401  // Replace the address in the new buffer
402  if (encoder.PutAddress(offset, file_addr) == UINT32_MAX)
403  return false;
404 
405  // All went well, so now we can reset the data using a shared pointer to
406  // the heap data so "m_data" will now correctly manage the heap data.
407  m_data.SetData(encoder.GetDataBuffer());
408  return true;
409  } else {
410  const offset_t op_arg_size =
411  GetOpcodeDataSize(m_data, offset, op, dwarf_cu);
412  if (op_arg_size == LLDB_INVALID_OFFSET)
413  break;
414  offset += op_arg_size;
415  }
416  }
417  return false;
418 }
419 
421  const DWARFUnit *dwarf_cu) const {
422  lldb::offset_t offset = 0;
423  while (m_data.ValidOffset(offset)) {
424  const uint8_t op = m_data.GetU8(&offset);
425 
426  if (op == DW_OP_form_tls_address || op == DW_OP_GNU_push_tls_address)
427  return true;
428  const offset_t op_arg_size =
429  GetOpcodeDataSize(m_data, offset, op, dwarf_cu);
430  if (op_arg_size == LLDB_INVALID_OFFSET)
431  return false;
432  offset += op_arg_size;
433  }
434  return false;
435 }
437  const DWARFUnit *dwarf_cu,
438  std::function<lldb::addr_t(lldb::addr_t file_addr)> const
439  &link_address_callback) {
440  const uint32_t addr_byte_size = m_data.GetAddressByteSize();
441  // We have to make a copy of the data as we don't know if this data is from a
442  // read only memory mapped buffer, so we duplicate all of the data first,
443  // then modify it, and if all goes well, we then replace the data for this
444  // expression.
445  // Make en encoder that contains a copy of the location expression data so we
446  // can write the address into the buffer using the correct byte order.
447  DataEncoder encoder(m_data.GetDataStart(), m_data.GetByteSize(),
448  m_data.GetByteOrder(), addr_byte_size);
449 
450  lldb::offset_t offset = 0;
451  lldb::offset_t const_offset = 0;
452  lldb::addr_t const_value = 0;
453  size_t const_byte_size = 0;
454  while (m_data.ValidOffset(offset)) {
455  const uint8_t op = m_data.GetU8(&offset);
456 
457  bool decoded_data = false;
458  switch (op) {
459  case DW_OP_const4u:
460  // Remember the const offset in case we later have a
461  // DW_OP_form_tls_address or DW_OP_GNU_push_tls_address
462  const_offset = offset;
463  const_value = m_data.GetU32(&offset);
464  decoded_data = true;
465  const_byte_size = 4;
466  break;
467 
468  case DW_OP_const8u:
469  // Remember the const offset in case we later have a
470  // DW_OP_form_tls_address or DW_OP_GNU_push_tls_address
471  const_offset = offset;
472  const_value = m_data.GetU64(&offset);
473  decoded_data = true;
474  const_byte_size = 8;
475  break;
476 
477  case DW_OP_form_tls_address:
478  case DW_OP_GNU_push_tls_address:
479  // DW_OP_form_tls_address and DW_OP_GNU_push_tls_address must be preceded
480  // by a file address on the stack. We assume that DW_OP_const4u or
481  // DW_OP_const8u is used for these values, and we check that the last
482  // opcode we got before either of these was DW_OP_const4u or
483  // DW_OP_const8u. If so, then we can link the value accordingly. For
484  // Darwin, the value in the DW_OP_const4u or DW_OP_const8u is the file
485  // address of a structure that contains a function pointer, the pthread
486  // key and the offset into the data pointed to by the pthread key. So we
487  // must link this address and also set the module of this expression to
488  // the new_module_sp so we can resolve the file address correctly
489  if (const_byte_size > 0) {
490  lldb::addr_t linked_file_addr = link_address_callback(const_value);
491  if (linked_file_addr == LLDB_INVALID_ADDRESS)
492  return false;
493  // Replace the address in the new buffer
494  if (encoder.PutUnsigned(const_offset, const_byte_size,
495  linked_file_addr) == UINT32_MAX)
496  return false;
497  }
498  break;
499 
500  default:
501  const_offset = 0;
502  const_value = 0;
503  const_byte_size = 0;
504  break;
505  }
506 
507  if (!decoded_data) {
508  const offset_t op_arg_size =
509  GetOpcodeDataSize(m_data, offset, op, dwarf_cu);
510  if (op_arg_size == LLDB_INVALID_OFFSET)
511  return false;
512  else
513  offset += op_arg_size;
514  }
515  }
516 
517  m_data.SetData(encoder.GetDataBuffer());
518  return true;
519 }
520 
521 static bool Evaluate_DW_OP_entry_value(std::vector<Value> &stack,
522  ExecutionContext *exe_ctx,
523  RegisterContext *reg_ctx,
524  const DataExtractor &opcodes,
525  lldb::offset_t &opcode_offset,
526  Status *error_ptr, Log *log) {
527  // DW_OP_entry_value(sub-expr) describes the location a variable had upon
528  // function entry: this variable location is presumed to be optimized out at
529  // the current PC value. The caller of the function may have call site
530  // information that describes an alternate location for the variable (e.g. a
531  // constant literal, or a spilled stack value) in the parent frame.
532  //
533  // Example (this is pseudo-code & pseudo-DWARF, but hopefully illustrative):
534  //
535  // void child(int &sink, int x) {
536  // ...
537  // /* "x" gets optimized out. */
538  //
539  // /* The location of "x" here is: DW_OP_entry_value($reg2). */
540  // ++sink;
541  // }
542  //
543  // void parent() {
544  // int sink;
545  //
546  // /*
547  // * The callsite information emitted here is:
548  // *
549  // * DW_TAG_call_site
550  // * DW_AT_return_pc ... (for "child(sink, 123);")
551  // * DW_TAG_call_site_parameter (for "sink")
552  // * DW_AT_location ($reg1)
553  // * DW_AT_call_value ($SP - 8)
554  // * DW_TAG_call_site_parameter (for "x")
555  // * DW_AT_location ($reg2)
556  // * DW_AT_call_value ($literal 123)
557  // *
558  // * DW_TAG_call_site
559  // * DW_AT_return_pc ... (for "child(sink, 456);")
560  // * ...
561  // */
562  // child(sink, 123);
563  // child(sink, 456);
564  // }
565  //
566  // When the program stops at "++sink" within `child`, the debugger determines
567  // the call site by analyzing the return address. Once the call site is found,
568  // the debugger determines which parameter is referenced by DW_OP_entry_value
569  // and evaluates the corresponding location for that parameter in `parent`.
570 
571  // 1. Find the function which pushed the current frame onto the stack.
572  if ((!exe_ctx || !exe_ctx->HasTargetScope()) || !reg_ctx) {
573  LLDB_LOG(log, "Evaluate_DW_OP_entry_value: no exe/reg context");
574  return false;
575  }
576 
577  StackFrame *current_frame = exe_ctx->GetFramePtr();
578  Thread *thread = exe_ctx->GetThreadPtr();
579  if (!current_frame || !thread) {
580  LLDB_LOG(log, "Evaluate_DW_OP_entry_value: no current frame/thread");
581  return false;
582  }
583 
584  Target &target = exe_ctx->GetTargetRef();
585  StackFrameSP parent_frame = nullptr;
586  addr_t return_pc = LLDB_INVALID_ADDRESS;
587  uint32_t current_frame_idx = current_frame->GetFrameIndex();
588  uint32_t num_frames = thread->GetStackFrameCount();
589  for (uint32_t parent_frame_idx = current_frame_idx + 1;
590  parent_frame_idx < num_frames; ++parent_frame_idx) {
591  parent_frame = thread->GetStackFrameAtIndex(parent_frame_idx);
592  // Require a valid sequence of frames.
593  if (!parent_frame)
594  break;
595 
596  // Record the first valid return address, even if this is an inlined frame,
597  // in order to look up the associated call edge in the first non-inlined
598  // parent frame.
599  if (return_pc == LLDB_INVALID_ADDRESS) {
600  return_pc = parent_frame->GetFrameCodeAddress().GetLoadAddress(&target);
601  LLDB_LOG(log,
602  "Evaluate_DW_OP_entry_value: immediate ancestor with pc = {0:x}",
603  return_pc);
604  }
605 
606  // If we've found an inlined frame, skip it (these have no call site
607  // parameters).
608  if (parent_frame->IsInlined())
609  continue;
610 
611  // We've found the first non-inlined parent frame.
612  break;
613  }
614  if (!parent_frame || !parent_frame->GetRegisterContext()) {
615  LLDB_LOG(log, "Evaluate_DW_OP_entry_value: no parent frame with reg ctx");
616  return false;
617  }
618 
619  Function *parent_func =
620  parent_frame->GetSymbolContext(eSymbolContextFunction).function;
621  if (!parent_func) {
622  LLDB_LOG(log, "Evaluate_DW_OP_entry_value: no parent function");
623  return false;
624  }
625 
626  // 2. Find the call edge in the parent function responsible for creating the
627  // current activation.
628  Function *current_func =
629  current_frame->GetSymbolContext(eSymbolContextFunction).function;
630  if (!current_func) {
631  LLDB_LOG(log, "Evaluate_DW_OP_entry_value: no current function");
632  return false;
633  }
634 
635  CallEdge *call_edge = nullptr;
636  ModuleList &modlist = target.GetImages();
637  ExecutionContext parent_exe_ctx = *exe_ctx;
638  parent_exe_ctx.SetFrameSP(parent_frame);
639  if (!parent_frame->IsArtificial()) {
640  // If the parent frame is not artificial, the current activation may be
641  // produced by an ambiguous tail call. In this case, refuse to proceed.
642  call_edge = parent_func->GetCallEdgeForReturnAddress(return_pc, target);
643  if (!call_edge) {
644  LLDB_LOG(log,
645  "Evaluate_DW_OP_entry_value: no call edge for retn-pc = {0:x} "
646  "in parent frame {1}",
647  return_pc, parent_func->GetName());
648  return false;
649  }
650  Function *callee_func = call_edge->GetCallee(modlist, parent_exe_ctx);
651  if (callee_func != current_func) {
652  LLDB_LOG(log, "Evaluate_DW_OP_entry_value: ambiguous call sequence, "
653  "can't find real parent frame");
654  return false;
655  }
656  } else {
657  // The StackFrameList solver machinery has deduced that an unambiguous tail
658  // call sequence that produced the current activation. The first edge in
659  // the parent that points to the current function must be valid.
660  for (auto &edge : parent_func->GetTailCallingEdges()) {
661  if (edge->GetCallee(modlist, parent_exe_ctx) == current_func) {
662  call_edge = edge.get();
663  break;
664  }
665  }
666  }
667  if (!call_edge) {
668  LLDB_LOG(log, "Evaluate_DW_OP_entry_value: no unambiguous edge from parent "
669  "to current function");
670  return false;
671  }
672 
673  // 3. Attempt to locate the DW_OP_entry_value expression in the set of
674  // available call site parameters. If found, evaluate the corresponding
675  // parameter in the context of the parent frame.
676  const uint32_t subexpr_len = opcodes.GetULEB128(&opcode_offset);
677  const void *subexpr_data = opcodes.GetData(&opcode_offset, subexpr_len);
678  if (!subexpr_data) {
679  LLDB_LOG(log, "Evaluate_DW_OP_entry_value: subexpr could not be read");
680  return false;
681  }
682 
683  const CallSiteParameter *matched_param = nullptr;
684  for (const CallSiteParameter &param : call_edge->GetCallSiteParameters()) {
685  DataExtractor param_subexpr_extractor;
686  if (!param.LocationInCallee.GetExpressionData(param_subexpr_extractor))
687  continue;
688  lldb::offset_t param_subexpr_offset = 0;
689  const void *param_subexpr_data =
690  param_subexpr_extractor.GetData(&param_subexpr_offset, subexpr_len);
691  if (!param_subexpr_data ||
692  param_subexpr_extractor.BytesLeft(param_subexpr_offset) != 0)
693  continue;
694 
695  // At this point, the DW_OP_entry_value sub-expression and the callee-side
696  // expression in the call site parameter are known to have the same length.
697  // Check whether they are equal.
698  //
699  // Note that an equality check is sufficient: the contents of the
700  // DW_OP_entry_value subexpression are only used to identify the right call
701  // site parameter in the parent, and do not require any special handling.
702  if (memcmp(subexpr_data, param_subexpr_data, subexpr_len) == 0) {
703  matched_param = &param;
704  break;
705  }
706  }
707  if (!matched_param) {
708  LLDB_LOG(log,
709  "Evaluate_DW_OP_entry_value: no matching call site param found");
710  return false;
711  }
712 
713  // TODO: Add support for DW_OP_push_object_address within a DW_OP_entry_value
714  // subexpresion whenever llvm does.
715  Value result;
716  const DWARFExpressionList &param_expr = matched_param->LocationInCaller;
717  if (!param_expr.Evaluate(&parent_exe_ctx,
718  parent_frame->GetRegisterContext().get(),
720  /*initial_value_ptr=*/nullptr,
721  /*object_address_ptr=*/nullptr, result, error_ptr)) {
722  LLDB_LOG(log,
723  "Evaluate_DW_OP_entry_value: call site param evaluation failed");
724  return false;
725  }
726 
727  stack.push_back(result);
728  return true;
729 }
730 
731 namespace {
732 /// The location description kinds described by the DWARF v5
733 /// specification. Composite locations are handled out-of-band and
734 /// thus aren't part of the enum.
735 enum LocationDescriptionKind {
736  Empty,
737  Memory,
738  Register,
739  Implicit
740  /* Composite*/
741 };
742 /// Adjust value's ValueType according to the kind of location description.
743 void UpdateValueTypeFromLocationDescription(Log *log, const DWARFUnit *dwarf_cu,
744  LocationDescriptionKind kind,
745  Value *value = nullptr) {
746  // Note that this function is conflating DWARF expressions with
747  // DWARF location descriptions. Perhaps it would be better to define
748  // a wrapper for DWARFExpression::Eval() that deals with DWARF
749  // location descriptions (which consist of one or more DWARF
750  // expressions). But doing this would mean we'd also need factor the
751  // handling of DW_OP_(bit_)piece out of this function.
752  if (dwarf_cu && dwarf_cu->GetVersion() >= 4) {
753  const char *log_msg = "DWARF location description kind: %s";
754  switch (kind) {
755  case Empty:
756  LLDB_LOGF(log, log_msg, "Empty");
757  break;
758  case Memory:
759  LLDB_LOGF(log, log_msg, "Memory");
760  if (value->GetValueType() == Value::ValueType::Scalar)
761  value->SetValueType(Value::ValueType::LoadAddress);
762  break;
763  case Register:
764  LLDB_LOGF(log, log_msg, "Register");
765  value->SetValueType(Value::ValueType::Scalar);
766  break;
767  case Implicit:
768  LLDB_LOGF(log, log_msg, "Implicit");
769  if (value->GetValueType() == Value::ValueType::LoadAddress)
770  value->SetValueType(Value::ValueType::Scalar);
771  break;
772  }
773  }
774 }
775 } // namespace
776 
777 /// Helper function to move common code used to resolve a file address and turn
778 /// into a load address.
779 ///
780 /// \param exe_ctx Pointer to the execution context
781 /// \param module_sp shared_ptr contains the module if we have one
782 /// \param error_ptr pointer to Status object if we have one
783 /// \param dw_op_type C-style string used to vary the error output
784 /// \param file_addr the file address we are trying to resolve and turn into a
785 /// load address
786 /// \param so_addr out parameter, will be set to load address or section offset
787 /// \param check_sectionoffset bool which determines if having a section offset
788 /// but not a load address is considerd a success
789 /// \returns llvm::Optional containing the load address if resolving and getting
790 /// the load address succeed or an empty Optinal otherwise. If
791 /// check_sectionoffset is true we consider LLDB_INVALID_ADDRESS a
792 /// success if so_addr.IsSectionOffset() is true.
793 static llvm::Optional<lldb::addr_t>
794 ResolveLoadAddress(ExecutionContext *exe_ctx, lldb::ModuleSP &module_sp,
795  Status *error_ptr, const char *dw_op_type,
796  lldb::addr_t file_addr, Address &so_addr,
797  bool check_sectionoffset = false) {
798  if (!module_sp) {
799  if (error_ptr)
800  error_ptr->SetErrorStringWithFormat(
801  "need module to resolve file address for %s", dw_op_type);
802  return {};
803  }
804 
805  if (!module_sp->ResolveFileAddress(file_addr, so_addr)) {
806  if (error_ptr)
807  error_ptr->SetErrorString("failed to resolve file address in module");
808  return {};
809  }
810 
811  addr_t load_addr = so_addr.GetLoadAddress(exe_ctx->GetTargetPtr());
812 
813  if (load_addr == LLDB_INVALID_ADDRESS &&
814  (check_sectionoffset && !so_addr.IsSectionOffset())) {
815  if (error_ptr)
816  error_ptr->SetErrorString("failed to resolve load address");
817  return {};
818  }
819 
820  return load_addr;
821 }
822 
823 /// Helper function to move common code used to load sized data from a uint8_t
824 /// buffer.
825 ///
826 /// \param addr_bytes uint8_t buffer containg raw data
827 /// \param size_addr_bytes how large is the underlying raw data
828 /// \param byte_order what is the byter order of the underlyig data
829 /// \param size How much of the underlying data we want to use
830 /// \return The underlying data converted into a Scalar
831 static Scalar DerefSizeExtractDataHelper(uint8_t *addr_bytes,
832  size_t size_addr_bytes,
833  ByteOrder byte_order, size_t size) {
834  DataExtractor addr_data(addr_bytes, size_addr_bytes, byte_order, size);
835 
836  lldb::offset_t addr_data_offset = 0;
837  if (size <= 8)
838  return addr_data.GetMaxU64(&addr_data_offset, size);
839  else
840  return addr_data.GetAddress(&addr_data_offset);
841 }
842 
844  ExecutionContext *exe_ctx, RegisterContext *reg_ctx,
845  lldb::ModuleSP module_sp, const DataExtractor &opcodes,
846  const DWARFUnit *dwarf_cu, const lldb::RegisterKind reg_kind,
847  const Value *initial_value_ptr, const Value *object_address_ptr,
848  Value &result, Status *error_ptr) {
849 
850  if (opcodes.GetByteSize() == 0) {
851  if (error_ptr)
852  error_ptr->SetErrorString(
853  "no location, value may have been optimized out");
854  return false;
855  }
856  std::vector<Value> stack;
857 
858  Process *process = nullptr;
859  StackFrame *frame = nullptr;
860  Target *target = nullptr;
861 
862  if (exe_ctx) {
863  process = exe_ctx->GetProcessPtr();
864  frame = exe_ctx->GetFramePtr();
865  target = exe_ctx->GetTargetPtr();
866  }
867  if (reg_ctx == nullptr && frame)
868  reg_ctx = frame->GetRegisterContext().get();
869 
870  if (initial_value_ptr)
871  stack.push_back(*initial_value_ptr);
872 
873  lldb::offset_t offset = 0;
874  Value tmp;
875  uint32_t reg_num;
876 
877  /// Insertion point for evaluating multi-piece expression.
878  uint64_t op_piece_offset = 0;
879  Value pieces; // Used for DW_OP_piece
880 
882  // A generic type is "an integral type that has the size of an address and an
883  // unspecified signedness". For now, just use the signedness of the operand.
884  // TODO: Implement a real typed stack, and store the genericness of the value
885  // there.
886  auto to_generic = [&](auto v) {
887  bool is_signed = std::is_signed<decltype(v)>::value;
888  return Scalar(llvm::APSInt(
889  llvm::APInt(8 * opcodes.GetAddressByteSize(), v, is_signed),
890  !is_signed));
891  };
892 
893  // The default kind is a memory location. This is updated by any
894  // operation that changes this, such as DW_OP_stack_value, and reset
895  // by composition operations like DW_OP_piece.
896  LocationDescriptionKind dwarf4_location_description_kind = Memory;
897 
898  while (opcodes.ValidOffset(offset)) {
899  const lldb::offset_t op_offset = offset;
900  const uint8_t op = opcodes.GetU8(&offset);
901 
902  if (log && log->GetVerbose()) {
903  size_t count = stack.size();
904  LLDB_LOGF(log, "Stack before operation has %" PRIu64 " values:",
905  (uint64_t)count);
906  for (size_t i = 0; i < count; ++i) {
907  StreamString new_value;
908  new_value.Printf("[%" PRIu64 "]", (uint64_t)i);
909  stack[i].Dump(&new_value);
910  LLDB_LOGF(log, " %s", new_value.GetData());
911  }
912  LLDB_LOGF(log, "0x%8.8" PRIx64 ": %s", op_offset,
913  DW_OP_value_to_name(op));
914  }
915 
916  switch (op) {
917  // The DW_OP_addr operation has a single operand that encodes a machine
918  // address and whose size is the size of an address on the target machine.
919  case DW_OP_addr:
920  stack.push_back(Scalar(opcodes.GetAddress(&offset)));
921  if (target &&
923  // wasm file sections aren't mapped into memory, therefore addresses can
924  // never point into a file section and are always LoadAddresses.
925  stack.back().SetValueType(Value::ValueType::LoadAddress);
926  } else {
927  stack.back().SetValueType(Value::ValueType::FileAddress);
928  // Convert the file address to a load address, so subsequent
929  // DWARF operators can operate on it.
930  if (target)
931  stack.back().ConvertToLoadAddress(module_sp.get(), target);
932  }
933  break;
934 
935  // The DW_OP_addr_sect_offset4 is used for any location expressions in
936  // shared libraries that have a location like:
937  // DW_OP_addr(0x1000)
938  // If this address resides in a shared library, then this virtual address
939  // won't make sense when it is evaluated in the context of a running
940  // process where shared libraries have been slid. To account for this, this
941  // new address type where we can store the section pointer and a 4 byte
942  // offset.
943  // case DW_OP_addr_sect_offset4:
944  // {
945  // result_type = eResultTypeFileAddress;
946  // lldb::Section *sect = (lldb::Section
947  // *)opcodes.GetMaxU64(&offset, sizeof(void *));
948  // lldb::addr_t sect_offset = opcodes.GetU32(&offset);
949  //
950  // Address so_addr (sect, sect_offset);
951  // lldb::addr_t load_addr = so_addr.GetLoadAddress();
952  // if (load_addr != LLDB_INVALID_ADDRESS)
953  // {
954  // // We successfully resolve a file address to a load
955  // // address.
956  // stack.push_back(load_addr);
957  // break;
958  // }
959  // else
960  // {
961  // // We were able
962  // if (error_ptr)
963  // error_ptr->SetErrorStringWithFormat ("Section %s in
964  // %s is not currently loaded.\n",
965  // sect->GetName().AsCString(),
966  // sect->GetModule()->GetFileSpec().GetFilename().AsCString());
967  // return false;
968  // }
969  // }
970  // break;
971 
972  // OPCODE: DW_OP_deref
973  // OPERANDS: none
974  // DESCRIPTION: Pops the top stack entry and treats it as an address.
975  // The value retrieved from that address is pushed. The size of the data
976  // retrieved from the dereferenced address is the size of an address on the
977  // target machine.
978  case DW_OP_deref: {
979  if (stack.empty()) {
980  if (error_ptr)
981  error_ptr->SetErrorString("Expression stack empty for DW_OP_deref.");
982  return false;
983  }
984  Value::ValueType value_type = stack.back().GetValueType();
985  switch (value_type) {
987  void *src = (void *)stack.back().GetScalar().ULongLong();
988  intptr_t ptr;
989  ::memcpy(&ptr, src, sizeof(void *));
990  stack.back().GetScalar() = ptr;
991  stack.back().ClearContext();
992  } break;
994  auto file_addr = stack.back().GetScalar().ULongLong(
996 
997  Address so_addr;
998  auto maybe_load_addr = ResolveLoadAddress(
999  exe_ctx, module_sp, error_ptr, "DW_OP_deref", file_addr, so_addr);
1000 
1001  if (!maybe_load_addr)
1002  return false;
1003 
1004  stack.back().GetScalar() = *maybe_load_addr;
1005  // Fall through to load address promotion code below.
1006  }
1007  [[fallthrough]];
1009  // Promote Scalar to LoadAddress and fall through.
1010  stack.back().SetValueType(Value::ValueType::LoadAddress);
1011  [[fallthrough]];
1013  if (exe_ctx) {
1014  if (process) {
1015  lldb::addr_t pointer_addr =
1016  stack.back().GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1017  Status error;
1018  lldb::addr_t pointer_value =
1019  process->ReadPointerFromMemory(pointer_addr, error);
1020  if (pointer_value != LLDB_INVALID_ADDRESS) {
1021  if (ABISP abi_sp = process->GetABI())
1022  pointer_value = abi_sp->FixCodeAddress(pointer_value);
1023  stack.back().GetScalar() = pointer_value;
1024  stack.back().ClearContext();
1025  } else {
1026  if (error_ptr)
1027  error_ptr->SetErrorStringWithFormat(
1028  "Failed to dereference pointer from 0x%" PRIx64
1029  " for DW_OP_deref: %s\n",
1030  pointer_addr, error.AsCString());
1031  return false;
1032  }
1033  } else {
1034  if (error_ptr)
1035  error_ptr->SetErrorString("NULL process for DW_OP_deref.\n");
1036  return false;
1037  }
1038  } else {
1039  if (error_ptr)
1040  error_ptr->SetErrorString(
1041  "NULL execution context for DW_OP_deref.\n");
1042  return false;
1043  }
1044  break;
1045 
1047  if (error_ptr)
1048  error_ptr->SetErrorString("Invalid value type for DW_OP_deref.\n");
1049  return false;
1050  }
1051 
1052  } break;
1053 
1054  // OPCODE: DW_OP_deref_size
1055  // OPERANDS: 1
1056  // 1 - uint8_t that specifies the size of the data to dereference.
1057  // DESCRIPTION: Behaves like the DW_OP_deref operation: it pops the top
1058  // stack entry and treats it as an address. The value retrieved from that
1059  // address is pushed. In the DW_OP_deref_size operation, however, the size
1060  // in bytes of the data retrieved from the dereferenced address is
1061  // specified by the single operand. This operand is a 1-byte unsigned
1062  // integral constant whose value may not be larger than the size of an
1063  // address on the target machine. The data retrieved is zero extended to
1064  // the size of an address on the target machine before being pushed on the
1065  // expression stack.
1066  case DW_OP_deref_size: {
1067  if (stack.empty()) {
1068  if (error_ptr)
1069  error_ptr->SetErrorString(
1070  "Expression stack empty for DW_OP_deref_size.");
1071  return false;
1072  }
1073  uint8_t size = opcodes.GetU8(&offset);
1074  Value::ValueType value_type = stack.back().GetValueType();
1075  switch (value_type) {
1077  void *src = (void *)stack.back().GetScalar().ULongLong();
1078  intptr_t ptr;
1079  ::memcpy(&ptr, src, sizeof(void *));
1080  // I can't decide whether the size operand should apply to the bytes in
1081  // their
1082  // lldb-host endianness or the target endianness.. I doubt this'll ever
1083  // come up but I'll opt for assuming big endian regardless.
1084  switch (size) {
1085  case 1:
1086  ptr = ptr & 0xff;
1087  break;
1088  case 2:
1089  ptr = ptr & 0xffff;
1090  break;
1091  case 3:
1092  ptr = ptr & 0xffffff;
1093  break;
1094  case 4:
1095  ptr = ptr & 0xffffffff;
1096  break;
1097  // the casts are added to work around the case where intptr_t is a 32
1098  // bit quantity;
1099  // presumably we won't hit the 5..7 cases if (void*) is 32-bits in this
1100  // program.
1101  case 5:
1102  ptr = (intptr_t)ptr & 0xffffffffffULL;
1103  break;
1104  case 6:
1105  ptr = (intptr_t)ptr & 0xffffffffffffULL;
1106  break;
1107  case 7:
1108  ptr = (intptr_t)ptr & 0xffffffffffffffULL;
1109  break;
1110  default:
1111  break;
1112  }
1113  stack.back().GetScalar() = ptr;
1114  stack.back().ClearContext();
1115  } break;
1117  auto file_addr =
1118  stack.back().GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1119  Address so_addr;
1120  auto maybe_load_addr =
1121  ResolveLoadAddress(exe_ctx, module_sp, error_ptr,
1122  "DW_OP_deref_size", file_addr, so_addr,
1123  /*check_sectionoffset=*/true);
1124 
1125  if (!maybe_load_addr)
1126  return false;
1127 
1128  addr_t load_addr = *maybe_load_addr;
1129 
1130  if (load_addr == LLDB_INVALID_ADDRESS && so_addr.IsSectionOffset()) {
1131  uint8_t addr_bytes[8];
1132  Status error;
1133 
1134  if (exe_ctx->GetTargetRef().ReadMemory(
1135  so_addr, &addr_bytes, size, error,
1136  /*force_live_memory=*/false) == size) {
1137  ObjectFile *objfile = module_sp->GetObjectFile();
1138 
1139  stack.back().GetScalar() = DerefSizeExtractDataHelper(
1140  addr_bytes, size, objfile->GetByteOrder(), size);
1141  stack.back().ClearContext();
1142  break;
1143  } else {
1144  if (error_ptr)
1145  error_ptr->SetErrorStringWithFormat(
1146  "Failed to dereference pointer for for DW_OP_deref_size: "
1147  "%s\n",
1148  error.AsCString());
1149  return false;
1150  }
1151  }
1152  stack.back().GetScalar() = load_addr;
1153  // Fall through to load address promotion code below.
1154  }
1155 
1156  [[fallthrough]];
1159  if (exe_ctx) {
1160  if (process) {
1161  lldb::addr_t pointer_addr =
1162  stack.back().GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1163  uint8_t addr_bytes[sizeof(lldb::addr_t)];
1164  Status error;
1165  if (process->ReadMemory(pointer_addr, &addr_bytes, size, error) ==
1166  size) {
1167 
1168  stack.back().GetScalar() =
1169  DerefSizeExtractDataHelper(addr_bytes, sizeof(addr_bytes),
1170  process->GetByteOrder(), size);
1171  stack.back().ClearContext();
1172  } else {
1173  if (error_ptr)
1174  error_ptr->SetErrorStringWithFormat(
1175  "Failed to dereference pointer from 0x%" PRIx64
1176  " for DW_OP_deref: %s\n",
1177  pointer_addr, error.AsCString());
1178  return false;
1179  }
1180  } else {
1181  if (error_ptr)
1182  error_ptr->SetErrorString("NULL process for DW_OP_deref_size.\n");
1183  return false;
1184  }
1185  } else {
1186  if (error_ptr)
1187  error_ptr->SetErrorString(
1188  "NULL execution context for DW_OP_deref_size.\n");
1189  return false;
1190  }
1191  break;
1192 
1194  if (error_ptr)
1195  error_ptr->SetErrorString("Invalid value for DW_OP_deref_size.\n");
1196  return false;
1197  }
1198 
1199  } break;
1200 
1201  // OPCODE: DW_OP_xderef_size
1202  // OPERANDS: 1
1203  // 1 - uint8_t that specifies the size of the data to dereference.
1204  // DESCRIPTION: Behaves like the DW_OP_xderef operation: the entry at
1205  // the top of the stack is treated as an address. The second stack entry is
1206  // treated as an "address space identifier" for those architectures that
1207  // support multiple address spaces. The top two stack elements are popped,
1208  // a data item is retrieved through an implementation-defined address
1209  // calculation and pushed as the new stack top. In the DW_OP_xderef_size
1210  // operation, however, the size in bytes of the data retrieved from the
1211  // dereferenced address is specified by the single operand. This operand is
1212  // a 1-byte unsigned integral constant whose value may not be larger than
1213  // the size of an address on the target machine. The data retrieved is zero
1214  // extended to the size of an address on the target machine before being
1215  // pushed on the expression stack.
1216  case DW_OP_xderef_size:
1217  if (error_ptr)
1218  error_ptr->SetErrorString("Unimplemented opcode: DW_OP_xderef_size.");
1219  return false;
1220  // OPCODE: DW_OP_xderef
1221  // OPERANDS: none
1222  // DESCRIPTION: Provides an extended dereference mechanism. The entry at
1223  // the top of the stack is treated as an address. The second stack entry is
1224  // treated as an "address space identifier" for those architectures that
1225  // support multiple address spaces. The top two stack elements are popped,
1226  // a data item is retrieved through an implementation-defined address
1227  // calculation and pushed as the new stack top. The size of the data
1228  // retrieved from the dereferenced address is the size of an address on the
1229  // target machine.
1230  case DW_OP_xderef:
1231  if (error_ptr)
1232  error_ptr->SetErrorString("Unimplemented opcode: DW_OP_xderef.");
1233  return false;
1234 
1235  // All DW_OP_constXXX opcodes have a single operand as noted below:
1236  //
1237  // Opcode Operand 1
1238  // DW_OP_const1u 1-byte unsigned integer constant
1239  // DW_OP_const1s 1-byte signed integer constant
1240  // DW_OP_const2u 2-byte unsigned integer constant
1241  // DW_OP_const2s 2-byte signed integer constant
1242  // DW_OP_const4u 4-byte unsigned integer constant
1243  // DW_OP_const4s 4-byte signed integer constant
1244  // DW_OP_const8u 8-byte unsigned integer constant
1245  // DW_OP_const8s 8-byte signed integer constant
1246  // DW_OP_constu unsigned LEB128 integer constant
1247  // DW_OP_consts signed LEB128 integer constant
1248  case DW_OP_const1u:
1249  stack.push_back(to_generic(opcodes.GetU8(&offset)));
1250  break;
1251  case DW_OP_const1s:
1252  stack.push_back(to_generic((int8_t)opcodes.GetU8(&offset)));
1253  break;
1254  case DW_OP_const2u:
1255  stack.push_back(to_generic(opcodes.GetU16(&offset)));
1256  break;
1257  case DW_OP_const2s:
1258  stack.push_back(to_generic((int16_t)opcodes.GetU16(&offset)));
1259  break;
1260  case DW_OP_const4u:
1261  stack.push_back(to_generic(opcodes.GetU32(&offset)));
1262  break;
1263  case DW_OP_const4s:
1264  stack.push_back(to_generic((int32_t)opcodes.GetU32(&offset)));
1265  break;
1266  case DW_OP_const8u:
1267  stack.push_back(to_generic(opcodes.GetU64(&offset)));
1268  break;
1269  case DW_OP_const8s:
1270  stack.push_back(to_generic((int64_t)opcodes.GetU64(&offset)));
1271  break;
1272  // These should also use to_generic, but we can't do that due to a
1273  // producer-side bug in llvm. See llvm.org/pr48087.
1274  case DW_OP_constu:
1275  stack.push_back(Scalar(opcodes.GetULEB128(&offset)));
1276  break;
1277  case DW_OP_consts:
1278  stack.push_back(Scalar(opcodes.GetSLEB128(&offset)));
1279  break;
1280 
1281  // OPCODE: DW_OP_dup
1282  // OPERANDS: none
1283  // DESCRIPTION: duplicates the value at the top of the stack
1284  case DW_OP_dup:
1285  if (stack.empty()) {
1286  if (error_ptr)
1287  error_ptr->SetErrorString("Expression stack empty for DW_OP_dup.");
1288  return false;
1289  } else
1290  stack.push_back(stack.back());
1291  break;
1292 
1293  // OPCODE: DW_OP_drop
1294  // OPERANDS: none
1295  // DESCRIPTION: pops the value at the top of the stack
1296  case DW_OP_drop:
1297  if (stack.empty()) {
1298  if (error_ptr)
1299  error_ptr->SetErrorString("Expression stack empty for DW_OP_drop.");
1300  return false;
1301  } else
1302  stack.pop_back();
1303  break;
1304 
1305  // OPCODE: DW_OP_over
1306  // OPERANDS: none
1307  // DESCRIPTION: Duplicates the entry currently second in the stack at
1308  // the top of the stack.
1309  case DW_OP_over:
1310  if (stack.size() < 2) {
1311  if (error_ptr)
1312  error_ptr->SetErrorString(
1313  "Expression stack needs at least 2 items for DW_OP_over.");
1314  return false;
1315  } else
1316  stack.push_back(stack[stack.size() - 2]);
1317  break;
1318 
1319  // OPCODE: DW_OP_pick
1320  // OPERANDS: uint8_t index into the current stack
1321  // DESCRIPTION: The stack entry with the specified index (0 through 255,
1322  // inclusive) is pushed on the stack
1323  case DW_OP_pick: {
1324  uint8_t pick_idx = opcodes.GetU8(&offset);
1325  if (pick_idx < stack.size())
1326  stack.push_back(stack[stack.size() - 1 - pick_idx]);
1327  else {
1328  if (error_ptr)
1329  error_ptr->SetErrorStringWithFormat(
1330  "Index %u out of range for DW_OP_pick.\n", pick_idx);
1331  return false;
1332  }
1333  } break;
1334 
1335  // OPCODE: DW_OP_swap
1336  // OPERANDS: none
1337  // DESCRIPTION: swaps the top two stack entries. The entry at the top
1338  // of the stack becomes the second stack entry, and the second entry
1339  // becomes the top of the stack
1340  case DW_OP_swap:
1341  if (stack.size() < 2) {
1342  if (error_ptr)
1343  error_ptr->SetErrorString(
1344  "Expression stack needs at least 2 items for DW_OP_swap.");
1345  return false;
1346  } else {
1347  tmp = stack.back();
1348  stack.back() = stack[stack.size() - 2];
1349  stack[stack.size() - 2] = tmp;
1350  }
1351  break;
1352 
1353  // OPCODE: DW_OP_rot
1354  // OPERANDS: none
1355  // DESCRIPTION: Rotates the first three stack entries. The entry at
1356  // the top of the stack becomes the third stack entry, the second entry
1357  // becomes the top of the stack, and the third entry becomes the second
1358  // entry.
1359  case DW_OP_rot:
1360  if (stack.size() < 3) {
1361  if (error_ptr)
1362  error_ptr->SetErrorString(
1363  "Expression stack needs at least 3 items for DW_OP_rot.");
1364  return false;
1365  } else {
1366  size_t last_idx = stack.size() - 1;
1367  Value old_top = stack[last_idx];
1368  stack[last_idx] = stack[last_idx - 1];
1369  stack[last_idx - 1] = stack[last_idx - 2];
1370  stack[last_idx - 2] = old_top;
1371  }
1372  break;
1373 
1374  // OPCODE: DW_OP_abs
1375  // OPERANDS: none
1376  // DESCRIPTION: pops the top stack entry, interprets it as a signed
1377  // value and pushes its absolute value. If the absolute value can not be
1378  // represented, the result is undefined.
1379  case DW_OP_abs:
1380  if (stack.empty()) {
1381  if (error_ptr)
1382  error_ptr->SetErrorString(
1383  "Expression stack needs at least 1 item for DW_OP_abs.");
1384  return false;
1385  } else if (!stack.back().ResolveValue(exe_ctx).AbsoluteValue()) {
1386  if (error_ptr)
1387  error_ptr->SetErrorString(
1388  "Failed to take the absolute value of the first stack item.");
1389  return false;
1390  }
1391  break;
1392 
1393  // OPCODE: DW_OP_and
1394  // OPERANDS: none
1395  // DESCRIPTION: pops the top two stack values, performs a bitwise and
1396  // operation on the two, and pushes the result.
1397  case DW_OP_and:
1398  if (stack.size() < 2) {
1399  if (error_ptr)
1400  error_ptr->SetErrorString(
1401  "Expression stack needs at least 2 items for DW_OP_and.");
1402  return false;
1403  } else {
1404  tmp = stack.back();
1405  stack.pop_back();
1406  stack.back().ResolveValue(exe_ctx) =
1407  stack.back().ResolveValue(exe_ctx) & tmp.ResolveValue(exe_ctx);
1408  }
1409  break;
1410 
1411  // OPCODE: DW_OP_div
1412  // OPERANDS: none
1413  // DESCRIPTION: pops the top two stack values, divides the former second
1414  // entry by the former top of the stack using signed division, and pushes
1415  // the result.
1416  case DW_OP_div:
1417  if (stack.size() < 2) {
1418  if (error_ptr)
1419  error_ptr->SetErrorString(
1420  "Expression stack needs at least 2 items for DW_OP_div.");
1421  return false;
1422  } else {
1423  tmp = stack.back();
1424  if (tmp.ResolveValue(exe_ctx).IsZero()) {
1425  if (error_ptr)
1426  error_ptr->SetErrorString("Divide by zero.");
1427  return false;
1428  } else {
1429  stack.pop_back();
1430  stack.back() =
1431  stack.back().ResolveValue(exe_ctx) / tmp.ResolveValue(exe_ctx);
1432  if (!stack.back().ResolveValue(exe_ctx).IsValid()) {
1433  if (error_ptr)
1434  error_ptr->SetErrorString("Divide failed.");
1435  return false;
1436  }
1437  }
1438  }
1439  break;
1440 
1441  // OPCODE: DW_OP_minus
1442  // OPERANDS: none
1443  // DESCRIPTION: pops the top two stack values, subtracts the former top
1444  // of the stack from the former second entry, and pushes the result.
1445  case DW_OP_minus:
1446  if (stack.size() < 2) {
1447  if (error_ptr)
1448  error_ptr->SetErrorString(
1449  "Expression stack needs at least 2 items for DW_OP_minus.");
1450  return false;
1451  } else {
1452  tmp = stack.back();
1453  stack.pop_back();
1454  stack.back().ResolveValue(exe_ctx) =
1455  stack.back().ResolveValue(exe_ctx) - tmp.ResolveValue(exe_ctx);
1456  }
1457  break;
1458 
1459  // OPCODE: DW_OP_mod
1460  // OPERANDS: none
1461  // DESCRIPTION: pops the top two stack values and pushes the result of
1462  // the calculation: former second stack entry modulo the former top of the
1463  // stack.
1464  case DW_OP_mod:
1465  if (stack.size() < 2) {
1466  if (error_ptr)
1467  error_ptr->SetErrorString(
1468  "Expression stack needs at least 2 items for DW_OP_mod.");
1469  return false;
1470  } else {
1471  tmp = stack.back();
1472  stack.pop_back();
1473  stack.back().ResolveValue(exe_ctx) =
1474  stack.back().ResolveValue(exe_ctx) % tmp.ResolveValue(exe_ctx);
1475  }
1476  break;
1477 
1478  // OPCODE: DW_OP_mul
1479  // OPERANDS: none
1480  // DESCRIPTION: pops the top two stack entries, multiplies them
1481  // together, and pushes the result.
1482  case DW_OP_mul:
1483  if (stack.size() < 2) {
1484  if (error_ptr)
1485  error_ptr->SetErrorString(
1486  "Expression stack needs at least 2 items for DW_OP_mul.");
1487  return false;
1488  } else {
1489  tmp = stack.back();
1490  stack.pop_back();
1491  stack.back().ResolveValue(exe_ctx) =
1492  stack.back().ResolveValue(exe_ctx) * tmp.ResolveValue(exe_ctx);
1493  }
1494  break;
1495 
1496  // OPCODE: DW_OP_neg
1497  // OPERANDS: none
1498  // DESCRIPTION: pops the top stack entry, and pushes its negation.
1499  case DW_OP_neg:
1500  if (stack.empty()) {
1501  if (error_ptr)
1502  error_ptr->SetErrorString(
1503  "Expression stack needs at least 1 item for DW_OP_neg.");
1504  return false;
1505  } else {
1506  if (!stack.back().ResolveValue(exe_ctx).UnaryNegate()) {
1507  if (error_ptr)
1508  error_ptr->SetErrorString("Unary negate failed.");
1509  return false;
1510  }
1511  }
1512  break;
1513 
1514  // OPCODE: DW_OP_not
1515  // OPERANDS: none
1516  // DESCRIPTION: pops the top stack entry, and pushes its bitwise
1517  // complement
1518  case DW_OP_not:
1519  if (stack.empty()) {
1520  if (error_ptr)
1521  error_ptr->SetErrorString(
1522  "Expression stack needs at least 1 item for DW_OP_not.");
1523  return false;
1524  } else {
1525  if (!stack.back().ResolveValue(exe_ctx).OnesComplement()) {
1526  if (error_ptr)
1527  error_ptr->SetErrorString("Logical NOT failed.");
1528  return false;
1529  }
1530  }
1531  break;
1532 
1533  // OPCODE: DW_OP_or
1534  // OPERANDS: none
1535  // DESCRIPTION: pops the top two stack entries, performs a bitwise or
1536  // operation on the two, and pushes the result.
1537  case DW_OP_or:
1538  if (stack.size() < 2) {
1539  if (error_ptr)
1540  error_ptr->SetErrorString(
1541  "Expression stack needs at least 2 items for DW_OP_or.");
1542  return false;
1543  } else {
1544  tmp = stack.back();
1545  stack.pop_back();
1546  stack.back().ResolveValue(exe_ctx) =
1547  stack.back().ResolveValue(exe_ctx) | tmp.ResolveValue(exe_ctx);
1548  }
1549  break;
1550 
1551  // OPCODE: DW_OP_plus
1552  // OPERANDS: none
1553  // DESCRIPTION: pops the top two stack entries, adds them together, and
1554  // pushes the result.
1555  case DW_OP_plus:
1556  if (stack.size() < 2) {
1557  if (error_ptr)
1558  error_ptr->SetErrorString(
1559  "Expression stack needs at least 2 items for DW_OP_plus.");
1560  return false;
1561  } else {
1562  tmp = stack.back();
1563  stack.pop_back();
1564  stack.back().GetScalar() += tmp.GetScalar();
1565  }
1566  break;
1567 
1568  // OPCODE: DW_OP_plus_uconst
1569  // OPERANDS: none
1570  // DESCRIPTION: pops the top stack entry, adds it to the unsigned LEB128
1571  // constant operand and pushes the result.
1572  case DW_OP_plus_uconst:
1573  if (stack.empty()) {
1574  if (error_ptr)
1575  error_ptr->SetErrorString(
1576  "Expression stack needs at least 1 item for DW_OP_plus_uconst.");
1577  return false;
1578  } else {
1579  const uint64_t uconst_value = opcodes.GetULEB128(&offset);
1580  // Implicit conversion from a UINT to a Scalar...
1581  stack.back().GetScalar() += uconst_value;
1582  if (!stack.back().GetScalar().IsValid()) {
1583  if (error_ptr)
1584  error_ptr->SetErrorString("DW_OP_plus_uconst failed.");
1585  return false;
1586  }
1587  }
1588  break;
1589 
1590  // OPCODE: DW_OP_shl
1591  // OPERANDS: none
1592  // DESCRIPTION: pops the top two stack entries, shifts the former
1593  // second entry left by the number of bits specified by the former top of
1594  // the stack, and pushes the result.
1595  case DW_OP_shl:
1596  if (stack.size() < 2) {
1597  if (error_ptr)
1598  error_ptr->SetErrorString(
1599  "Expression stack needs at least 2 items for DW_OP_shl.");
1600  return false;
1601  } else {
1602  tmp = stack.back();
1603  stack.pop_back();
1604  stack.back().ResolveValue(exe_ctx) <<= tmp.ResolveValue(exe_ctx);
1605  }
1606  break;
1607 
1608  // OPCODE: DW_OP_shr
1609  // OPERANDS: none
1610  // DESCRIPTION: pops the top two stack entries, shifts the former second
1611  // entry right logically (filling with zero bits) by the number of bits
1612  // specified by the former top of the stack, and pushes the result.
1613  case DW_OP_shr:
1614  if (stack.size() < 2) {
1615  if (error_ptr)
1616  error_ptr->SetErrorString(
1617  "Expression stack needs at least 2 items for DW_OP_shr.");
1618  return false;
1619  } else {
1620  tmp = stack.back();
1621  stack.pop_back();
1622  if (!stack.back().ResolveValue(exe_ctx).ShiftRightLogical(
1623  tmp.ResolveValue(exe_ctx))) {
1624  if (error_ptr)
1625  error_ptr->SetErrorString("DW_OP_shr failed.");
1626  return false;
1627  }
1628  }
1629  break;
1630 
1631  // OPCODE: DW_OP_shra
1632  // OPERANDS: none
1633  // DESCRIPTION: pops the top two stack entries, shifts the former second
1634  // entry right arithmetically (divide the magnitude by 2, keep the same
1635  // sign for the result) by the number of bits specified by the former top
1636  // of the stack, and pushes the result.
1637  case DW_OP_shra:
1638  if (stack.size() < 2) {
1639  if (error_ptr)
1640  error_ptr->SetErrorString(
1641  "Expression stack needs at least 2 items for DW_OP_shra.");
1642  return false;
1643  } else {
1644  tmp = stack.back();
1645  stack.pop_back();
1646  stack.back().ResolveValue(exe_ctx) >>= tmp.ResolveValue(exe_ctx);
1647  }
1648  break;
1649 
1650  // OPCODE: DW_OP_xor
1651  // OPERANDS: none
1652  // DESCRIPTION: pops the top two stack entries, performs the bitwise
1653  // exclusive-or operation on the two, and pushes the result.
1654  case DW_OP_xor:
1655  if (stack.size() < 2) {
1656  if (error_ptr)
1657  error_ptr->SetErrorString(
1658  "Expression stack needs at least 2 items for DW_OP_xor.");
1659  return false;
1660  } else {
1661  tmp = stack.back();
1662  stack.pop_back();
1663  stack.back().ResolveValue(exe_ctx) =
1664  stack.back().ResolveValue(exe_ctx) ^ tmp.ResolveValue(exe_ctx);
1665  }
1666  break;
1667 
1668  // OPCODE: DW_OP_skip
1669  // OPERANDS: int16_t
1670  // DESCRIPTION: An unconditional branch. Its single operand is a 2-byte
1671  // signed integer constant. The 2-byte constant is the number of bytes of
1672  // the DWARF expression to skip forward or backward from the current
1673  // operation, beginning after the 2-byte constant.
1674  case DW_OP_skip: {
1675  int16_t skip_offset = (int16_t)opcodes.GetU16(&offset);
1676  lldb::offset_t new_offset = offset + skip_offset;
1677  // New offset can point at the end of the data, in this case we should
1678  // terminate the DWARF expression evaluation (will happen in the loop
1679  // condition).
1680  if (new_offset <= opcodes.GetByteSize())
1681  offset = new_offset;
1682  else {
1683  if (error_ptr)
1684  error_ptr->SetErrorStringWithFormatv(
1685  "Invalid opcode offset in DW_OP_skip: {0}+({1}) > {2}", offset,
1686  skip_offset, opcodes.GetByteSize());
1687  return false;
1688  }
1689  } break;
1690 
1691  // OPCODE: DW_OP_bra
1692  // OPERANDS: int16_t
1693  // DESCRIPTION: A conditional branch. Its single operand is a 2-byte
1694  // signed integer constant. This operation pops the top of stack. If the
1695  // value popped is not the constant 0, the 2-byte constant operand is the
1696  // number of bytes of the DWARF expression to skip forward or backward from
1697  // the current operation, beginning after the 2-byte constant.
1698  case DW_OP_bra:
1699  if (stack.empty()) {
1700  if (error_ptr)
1701  error_ptr->SetErrorString(
1702  "Expression stack needs at least 1 item for DW_OP_bra.");
1703  return false;
1704  } else {
1705  tmp = stack.back();
1706  stack.pop_back();
1707  int16_t bra_offset = (int16_t)opcodes.GetU16(&offset);
1708  Scalar zero(0);
1709  if (tmp.ResolveValue(exe_ctx) != zero) {
1710  lldb::offset_t new_offset = offset + bra_offset;
1711  // New offset can point at the end of the data, in this case we should
1712  // terminate the DWARF expression evaluation (will happen in the loop
1713  // condition).
1714  if (new_offset <= opcodes.GetByteSize())
1715  offset = new_offset;
1716  else {
1717  if (error_ptr)
1718  error_ptr->SetErrorStringWithFormatv(
1719  "Invalid opcode offset in DW_OP_bra: {0}+({1}) > {2}", offset,
1720  bra_offset, opcodes.GetByteSize());
1721  return false;
1722  }
1723  }
1724  }
1725  break;
1726 
1727  // OPCODE: DW_OP_eq
1728  // OPERANDS: none
1729  // DESCRIPTION: pops the top two stack values, compares using the
1730  // equals (==) operator.
1731  // STACK RESULT: push the constant value 1 onto the stack if the result
1732  // of the operation is true or the constant value 0 if the result of the
1733  // operation is false.
1734  case DW_OP_eq:
1735  if (stack.size() < 2) {
1736  if (error_ptr)
1737  error_ptr->SetErrorString(
1738  "Expression stack needs at least 2 items for DW_OP_eq.");
1739  return false;
1740  } else {
1741  tmp = stack.back();
1742  stack.pop_back();
1743  stack.back().ResolveValue(exe_ctx) =
1744  stack.back().ResolveValue(exe_ctx) == tmp.ResolveValue(exe_ctx);
1745  }
1746  break;
1747 
1748  // OPCODE: DW_OP_ge
1749  // OPERANDS: none
1750  // DESCRIPTION: pops the top two stack values, compares using the
1751  // greater than or equal to (>=) operator.
1752  // STACK RESULT: push the constant value 1 onto the stack if the result
1753  // of the operation is true or the constant value 0 if the result of the
1754  // operation is false.
1755  case DW_OP_ge:
1756  if (stack.size() < 2) {
1757  if (error_ptr)
1758  error_ptr->SetErrorString(
1759  "Expression stack needs at least 2 items for DW_OP_ge.");
1760  return false;
1761  } else {
1762  tmp = stack.back();
1763  stack.pop_back();
1764  stack.back().ResolveValue(exe_ctx) =
1765  stack.back().ResolveValue(exe_ctx) >= tmp.ResolveValue(exe_ctx);
1766  }
1767  break;
1768 
1769  // OPCODE: DW_OP_gt
1770  // OPERANDS: none
1771  // DESCRIPTION: pops the top two stack values, compares using the
1772  // greater than (>) operator.
1773  // STACK RESULT: push the constant value 1 onto the stack if the result
1774  // of the operation is true or the constant value 0 if the result of the
1775  // operation is false.
1776  case DW_OP_gt:
1777  if (stack.size() < 2) {
1778  if (error_ptr)
1779  error_ptr->SetErrorString(
1780  "Expression stack needs at least 2 items for DW_OP_gt.");
1781  return false;
1782  } else {
1783  tmp = stack.back();
1784  stack.pop_back();
1785  stack.back().ResolveValue(exe_ctx) =
1786  stack.back().ResolveValue(exe_ctx) > tmp.ResolveValue(exe_ctx);
1787  }
1788  break;
1789 
1790  // OPCODE: DW_OP_le
1791  // OPERANDS: none
1792  // DESCRIPTION: pops the top two stack values, compares using the
1793  // less than or equal to (<=) operator.
1794  // STACK RESULT: push the constant value 1 onto the stack if the result
1795  // of the operation is true or the constant value 0 if the result of the
1796  // operation is false.
1797  case DW_OP_le:
1798  if (stack.size() < 2) {
1799  if (error_ptr)
1800  error_ptr->SetErrorString(
1801  "Expression stack needs at least 2 items for DW_OP_le.");
1802  return false;
1803  } else {
1804  tmp = stack.back();
1805  stack.pop_back();
1806  stack.back().ResolveValue(exe_ctx) =
1807  stack.back().ResolveValue(exe_ctx) <= tmp.ResolveValue(exe_ctx);
1808  }
1809  break;
1810 
1811  // OPCODE: DW_OP_lt
1812  // OPERANDS: none
1813  // DESCRIPTION: pops the top two stack values, compares using the
1814  // less than (<) operator.
1815  // STACK RESULT: push the constant value 1 onto the stack if the result
1816  // of the operation is true or the constant value 0 if the result of the
1817  // operation is false.
1818  case DW_OP_lt:
1819  if (stack.size() < 2) {
1820  if (error_ptr)
1821  error_ptr->SetErrorString(
1822  "Expression stack needs at least 2 items for DW_OP_lt.");
1823  return false;
1824  } else {
1825  tmp = stack.back();
1826  stack.pop_back();
1827  stack.back().ResolveValue(exe_ctx) =
1828  stack.back().ResolveValue(exe_ctx) < tmp.ResolveValue(exe_ctx);
1829  }
1830  break;
1831 
1832  // OPCODE: DW_OP_ne
1833  // OPERANDS: none
1834  // DESCRIPTION: pops the top two stack values, compares using the
1835  // not equal (!=) operator.
1836  // STACK RESULT: push the constant value 1 onto the stack if the result
1837  // of the operation is true or the constant value 0 if the result of the
1838  // operation is false.
1839  case DW_OP_ne:
1840  if (stack.size() < 2) {
1841  if (error_ptr)
1842  error_ptr->SetErrorString(
1843  "Expression stack needs at least 2 items for DW_OP_ne.");
1844  return false;
1845  } else {
1846  tmp = stack.back();
1847  stack.pop_back();
1848  stack.back().ResolveValue(exe_ctx) =
1849  stack.back().ResolveValue(exe_ctx) != tmp.ResolveValue(exe_ctx);
1850  }
1851  break;
1852 
1853  // OPCODE: DW_OP_litn
1854  // OPERANDS: none
1855  // DESCRIPTION: encode the unsigned literal values from 0 through 31.
1856  // STACK RESULT: push the unsigned literal constant value onto the top
1857  // of the stack.
1858  case DW_OP_lit0:
1859  case DW_OP_lit1:
1860  case DW_OP_lit2:
1861  case DW_OP_lit3:
1862  case DW_OP_lit4:
1863  case DW_OP_lit5:
1864  case DW_OP_lit6:
1865  case DW_OP_lit7:
1866  case DW_OP_lit8:
1867  case DW_OP_lit9:
1868  case DW_OP_lit10:
1869  case DW_OP_lit11:
1870  case DW_OP_lit12:
1871  case DW_OP_lit13:
1872  case DW_OP_lit14:
1873  case DW_OP_lit15:
1874  case DW_OP_lit16:
1875  case DW_OP_lit17:
1876  case DW_OP_lit18:
1877  case DW_OP_lit19:
1878  case DW_OP_lit20:
1879  case DW_OP_lit21:
1880  case DW_OP_lit22:
1881  case DW_OP_lit23:
1882  case DW_OP_lit24:
1883  case DW_OP_lit25:
1884  case DW_OP_lit26:
1885  case DW_OP_lit27:
1886  case DW_OP_lit28:
1887  case DW_OP_lit29:
1888  case DW_OP_lit30:
1889  case DW_OP_lit31:
1890  stack.push_back(to_generic(op - DW_OP_lit0));
1891  break;
1892 
1893  // OPCODE: DW_OP_regN
1894  // OPERANDS: none
1895  // DESCRIPTION: Push the value in register n on the top of the stack.
1896  case DW_OP_reg0:
1897  case DW_OP_reg1:
1898  case DW_OP_reg2:
1899  case DW_OP_reg3:
1900  case DW_OP_reg4:
1901  case DW_OP_reg5:
1902  case DW_OP_reg6:
1903  case DW_OP_reg7:
1904  case DW_OP_reg8:
1905  case DW_OP_reg9:
1906  case DW_OP_reg10:
1907  case DW_OP_reg11:
1908  case DW_OP_reg12:
1909  case DW_OP_reg13:
1910  case DW_OP_reg14:
1911  case DW_OP_reg15:
1912  case DW_OP_reg16:
1913  case DW_OP_reg17:
1914  case DW_OP_reg18:
1915  case DW_OP_reg19:
1916  case DW_OP_reg20:
1917  case DW_OP_reg21:
1918  case DW_OP_reg22:
1919  case DW_OP_reg23:
1920  case DW_OP_reg24:
1921  case DW_OP_reg25:
1922  case DW_OP_reg26:
1923  case DW_OP_reg27:
1924  case DW_OP_reg28:
1925  case DW_OP_reg29:
1926  case DW_OP_reg30:
1927  case DW_OP_reg31: {
1928  dwarf4_location_description_kind = Register;
1929  reg_num = op - DW_OP_reg0;
1930 
1931  if (ReadRegisterValueAsScalar(reg_ctx, reg_kind, reg_num, error_ptr, tmp))
1932  stack.push_back(tmp);
1933  else
1934  return false;
1935  } break;
1936  // OPCODE: DW_OP_regx
1937  // OPERANDS:
1938  // ULEB128 literal operand that encodes the register.
1939  // DESCRIPTION: Push the value in register on the top of the stack.
1940  case DW_OP_regx: {
1941  dwarf4_location_description_kind = Register;
1942  reg_num = opcodes.GetULEB128(&offset);
1943  if (ReadRegisterValueAsScalar(reg_ctx, reg_kind, reg_num, error_ptr, tmp))
1944  stack.push_back(tmp);
1945  else
1946  return false;
1947  } break;
1948 
1949  // OPCODE: DW_OP_bregN
1950  // OPERANDS:
1951  // SLEB128 offset from register N
1952  // DESCRIPTION: Value is in memory at the address specified by register
1953  // N plus an offset.
1954  case DW_OP_breg0:
1955  case DW_OP_breg1:
1956  case DW_OP_breg2:
1957  case DW_OP_breg3:
1958  case DW_OP_breg4:
1959  case DW_OP_breg5:
1960  case DW_OP_breg6:
1961  case DW_OP_breg7:
1962  case DW_OP_breg8:
1963  case DW_OP_breg9:
1964  case DW_OP_breg10:
1965  case DW_OP_breg11:
1966  case DW_OP_breg12:
1967  case DW_OP_breg13:
1968  case DW_OP_breg14:
1969  case DW_OP_breg15:
1970  case DW_OP_breg16:
1971  case DW_OP_breg17:
1972  case DW_OP_breg18:
1973  case DW_OP_breg19:
1974  case DW_OP_breg20:
1975  case DW_OP_breg21:
1976  case DW_OP_breg22:
1977  case DW_OP_breg23:
1978  case DW_OP_breg24:
1979  case DW_OP_breg25:
1980  case DW_OP_breg26:
1981  case DW_OP_breg27:
1982  case DW_OP_breg28:
1983  case DW_OP_breg29:
1984  case DW_OP_breg30:
1985  case DW_OP_breg31: {
1986  reg_num = op - DW_OP_breg0;
1987 
1988  if (ReadRegisterValueAsScalar(reg_ctx, reg_kind, reg_num, error_ptr,
1989  tmp)) {
1990  int64_t breg_offset = opcodes.GetSLEB128(&offset);
1991  tmp.ResolveValue(exe_ctx) += (uint64_t)breg_offset;
1992  tmp.ClearContext();
1993  stack.push_back(tmp);
1994  stack.back().SetValueType(Value::ValueType::LoadAddress);
1995  } else
1996  return false;
1997  } break;
1998  // OPCODE: DW_OP_bregx
1999  // OPERANDS: 2
2000  // ULEB128 literal operand that encodes the register.
2001  // SLEB128 offset from register N
2002  // DESCRIPTION: Value is in memory at the address specified by register
2003  // N plus an offset.
2004  case DW_OP_bregx: {
2005  reg_num = opcodes.GetULEB128(&offset);
2006 
2007  if (ReadRegisterValueAsScalar(reg_ctx, reg_kind, reg_num, error_ptr,
2008  tmp)) {
2009  int64_t breg_offset = opcodes.GetSLEB128(&offset);
2010  tmp.ResolveValue(exe_ctx) += (uint64_t)breg_offset;
2011  tmp.ClearContext();
2012  stack.push_back(tmp);
2013  stack.back().SetValueType(Value::ValueType::LoadAddress);
2014  } else
2015  return false;
2016  } break;
2017 
2018  case DW_OP_fbreg:
2019  if (exe_ctx) {
2020  if (frame) {
2021  Scalar value;
2022  if (frame->GetFrameBaseValue(value, error_ptr)) {
2023  int64_t fbreg_offset = opcodes.GetSLEB128(&offset);
2024  value += fbreg_offset;
2025  stack.push_back(value);
2026  stack.back().SetValueType(Value::ValueType::LoadAddress);
2027  } else
2028  return false;
2029  } else {
2030  if (error_ptr)
2031  error_ptr->SetErrorString(
2032  "Invalid stack frame in context for DW_OP_fbreg opcode.");
2033  return false;
2034  }
2035  } else {
2036  if (error_ptr)
2037  error_ptr->SetErrorString(
2038  "NULL execution context for DW_OP_fbreg.\n");
2039  return false;
2040  }
2041 
2042  break;
2043 
2044  // OPCODE: DW_OP_nop
2045  // OPERANDS: none
2046  // DESCRIPTION: A place holder. It has no effect on the location stack
2047  // or any of its values.
2048  case DW_OP_nop:
2049  break;
2050 
2051  // OPCODE: DW_OP_piece
2052  // OPERANDS: 1
2053  // ULEB128: byte size of the piece
2054  // DESCRIPTION: The operand describes the size in bytes of the piece of
2055  // the object referenced by the DWARF expression whose result is at the top
2056  // of the stack. If the piece is located in a register, but does not occupy
2057  // the entire register, the placement of the piece within that register is
2058  // defined by the ABI.
2059  //
2060  // Many compilers store a single variable in sets of registers, or store a
2061  // variable partially in memory and partially in registers. DW_OP_piece
2062  // provides a way of describing how large a part of a variable a particular
2063  // DWARF expression refers to.
2064  case DW_OP_piece: {
2065  LocationDescriptionKind piece_locdesc = dwarf4_location_description_kind;
2066  // Reset for the next piece.
2067  dwarf4_location_description_kind = Memory;
2068 
2069  const uint64_t piece_byte_size = opcodes.GetULEB128(&offset);
2070 
2071  if (piece_byte_size > 0) {
2072  Value curr_piece;
2073 
2074  if (stack.empty()) {
2075  UpdateValueTypeFromLocationDescription(
2076  log, dwarf_cu, LocationDescriptionKind::Empty);
2077  // In a multi-piece expression, this means that the current piece is
2078  // not available. Fill with zeros for now by resizing the data and
2079  // appending it
2080  curr_piece.ResizeData(piece_byte_size);
2081  // Note that "0" is not a correct value for the unknown bits.
2082  // It would be better to also return a mask of valid bits together
2083  // with the expression result, so the debugger can print missing
2084  // members as "<optimized out>" or something.
2085  ::memset(curr_piece.GetBuffer().GetBytes(), 0, piece_byte_size);
2086  pieces.AppendDataToHostBuffer(curr_piece);
2087  } else {
2088  Status error;
2089  // Extract the current piece into "curr_piece"
2090  Value curr_piece_source_value(stack.back());
2091  stack.pop_back();
2092  UpdateValueTypeFromLocationDescription(log, dwarf_cu, piece_locdesc,
2093  &curr_piece_source_value);
2094 
2095  const Value::ValueType curr_piece_source_value_type =
2096  curr_piece_source_value.GetValueType();
2097  switch (curr_piece_source_value_type) {
2099  return false;
2101  if (process) {
2102  if (curr_piece.ResizeData(piece_byte_size) == piece_byte_size) {
2103  lldb::addr_t load_addr =
2104  curr_piece_source_value.GetScalar().ULongLong(
2106  if (process->ReadMemory(
2107  load_addr, curr_piece.GetBuffer().GetBytes(),
2108  piece_byte_size, error) != piece_byte_size) {
2109  if (error_ptr)
2110  error_ptr->SetErrorStringWithFormat(
2111  "failed to read memory DW_OP_piece(%" PRIu64
2112  ") from 0x%" PRIx64,
2113  piece_byte_size, load_addr);
2114  return false;
2115  }
2116  } else {
2117  if (error_ptr)
2118  error_ptr->SetErrorStringWithFormat(
2119  "failed to resize the piece memory buffer for "
2120  "DW_OP_piece(%" PRIu64 ")",
2121  piece_byte_size);
2122  return false;
2123  }
2124  }
2125  break;
2126 
2129  if (error_ptr) {
2130  lldb::addr_t addr = curr_piece_source_value.GetScalar().ULongLong(
2132  error_ptr->SetErrorStringWithFormat(
2133  "failed to read memory DW_OP_piece(%" PRIu64
2134  ") from %s address 0x%" PRIx64,
2135  piece_byte_size, curr_piece_source_value.GetValueType() ==
2137  ? "file"
2138  : "host",
2139  addr);
2140  }
2141  return false;
2142 
2143  case Value::ValueType::Scalar: {
2144  uint32_t bit_size = piece_byte_size * 8;
2145  uint32_t bit_offset = 0;
2146  Scalar &scalar = curr_piece_source_value.GetScalar();
2147  if (!scalar.ExtractBitfield(
2148  bit_size, bit_offset)) {
2149  if (error_ptr)
2150  error_ptr->SetErrorStringWithFormat(
2151  "unable to extract %" PRIu64 " bytes from a %" PRIu64
2152  " byte scalar value.",
2153  piece_byte_size,
2154  (uint64_t)curr_piece_source_value.GetScalar()
2155  .GetByteSize());
2156  return false;
2157  }
2158  // Create curr_piece with bit_size. By default Scalar
2159  // grows to the nearest host integer type.
2160  llvm::APInt fail_value(1, 0, false);
2161  llvm::APInt ap_int = scalar.UInt128(fail_value);
2162  assert(ap_int.getBitWidth() >= bit_size);
2163  llvm::ArrayRef<uint64_t> buf{ap_int.getRawData(),
2164  ap_int.getNumWords()};
2165  curr_piece.GetScalar() = Scalar(llvm::APInt(bit_size, buf));
2166  } break;
2167  }
2168 
2169  // Check if this is the first piece?
2170  if (op_piece_offset == 0) {
2171  // This is the first piece, we should push it back onto the stack
2172  // so subsequent pieces will be able to access this piece and add
2173  // to it.
2174  if (pieces.AppendDataToHostBuffer(curr_piece) == 0) {
2175  if (error_ptr)
2176  error_ptr->SetErrorString("failed to append piece data");
2177  return false;
2178  }
2179  } else {
2180  // If this is the second or later piece there should be a value on
2181  // the stack.
2182  if (pieces.GetBuffer().GetByteSize() != op_piece_offset) {
2183  if (error_ptr)
2184  error_ptr->SetErrorStringWithFormat(
2185  "DW_OP_piece for offset %" PRIu64
2186  " but top of stack is of size %" PRIu64,
2187  op_piece_offset, pieces.GetBuffer().GetByteSize());
2188  return false;
2189  }
2190 
2191  if (pieces.AppendDataToHostBuffer(curr_piece) == 0) {
2192  if (error_ptr)
2193  error_ptr->SetErrorString("failed to append piece data");
2194  return false;
2195  }
2196  }
2197  }
2198  op_piece_offset += piece_byte_size;
2199  }
2200  } break;
2201 
2202  case DW_OP_bit_piece: // 0x9d ULEB128 bit size, ULEB128 bit offset (DWARF3);
2203  if (stack.size() < 1) {
2204  UpdateValueTypeFromLocationDescription(log, dwarf_cu,
2206  // Reset for the next piece.
2207  dwarf4_location_description_kind = Memory;
2208  if (error_ptr)
2209  error_ptr->SetErrorString(
2210  "Expression stack needs at least 1 item for DW_OP_bit_piece.");
2211  return false;
2212  } else {
2213  UpdateValueTypeFromLocationDescription(
2214  log, dwarf_cu, dwarf4_location_description_kind, &stack.back());
2215  // Reset for the next piece.
2216  dwarf4_location_description_kind = Memory;
2217  const uint64_t piece_bit_size = opcodes.GetULEB128(&offset);
2218  const uint64_t piece_bit_offset = opcodes.GetULEB128(&offset);
2219  switch (stack.back().GetValueType()) {
2221  return false;
2222  case Value::ValueType::Scalar: {
2223  if (!stack.back().GetScalar().ExtractBitfield(piece_bit_size,
2224  piece_bit_offset)) {
2225  if (error_ptr)
2226  error_ptr->SetErrorStringWithFormat(
2227  "unable to extract %" PRIu64 " bit value with %" PRIu64
2228  " bit offset from a %" PRIu64 " bit scalar value.",
2229  piece_bit_size, piece_bit_offset,
2230  (uint64_t)(stack.back().GetScalar().GetByteSize() * 8));
2231  return false;
2232  }
2233  } break;
2234 
2238  if (error_ptr) {
2239  error_ptr->SetErrorStringWithFormat(
2240  "unable to extract DW_OP_bit_piece(bit_size = %" PRIu64
2241  ", bit_offset = %" PRIu64 ") from an address value.",
2242  piece_bit_size, piece_bit_offset);
2243  }
2244  return false;
2245  }
2246  }
2247  break;
2248 
2249  // OPCODE: DW_OP_implicit_value
2250  // OPERANDS: 2
2251  // ULEB128 size of the value block in bytes
2252  // uint8_t* block bytes encoding value in target's memory
2253  // representation
2254  // DESCRIPTION: Value is immediately stored in block in the debug info with
2255  // the memory representation of the target.
2256  case DW_OP_implicit_value: {
2257  dwarf4_location_description_kind = Implicit;
2258 
2259  const uint32_t len = opcodes.GetULEB128(&offset);
2260  const void *data = opcodes.GetData(&offset, len);
2261 
2262  if (!data) {
2263  LLDB_LOG(log, "Evaluate_DW_OP_implicit_value: could not be read data");
2264  LLDB_ERRORF(error_ptr, "Could not evaluate %s.",
2265  DW_OP_value_to_name(op));
2266  return false;
2267  }
2268 
2269  Value result(data, len);
2270  stack.push_back(result);
2271  break;
2272  }
2273 
2274  case DW_OP_implicit_pointer: {
2275  dwarf4_location_description_kind = Implicit;
2276  LLDB_ERRORF(error_ptr, "Could not evaluate %s.", DW_OP_value_to_name(op));
2277  return false;
2278  }
2279 
2280  // OPCODE: DW_OP_push_object_address
2281  // OPERANDS: none
2282  // DESCRIPTION: Pushes the address of the object currently being
2283  // evaluated as part of evaluation of a user presented expression. This
2284  // object may correspond to an independent variable described by its own
2285  // DIE or it may be a component of an array, structure, or class whose
2286  // address has been dynamically determined by an earlier step during user
2287  // expression evaluation.
2288  case DW_OP_push_object_address:
2289  if (object_address_ptr)
2290  stack.push_back(*object_address_ptr);
2291  else {
2292  if (error_ptr)
2293  error_ptr->SetErrorString("DW_OP_push_object_address used without "
2294  "specifying an object address");
2295  return false;
2296  }
2297  break;
2298 
2299  // OPCODE: DW_OP_call2
2300  // OPERANDS:
2301  // uint16_t compile unit relative offset of a DIE
2302  // DESCRIPTION: Performs subroutine calls during evaluation
2303  // of a DWARF expression. The operand is the 2-byte unsigned offset of a
2304  // debugging information entry in the current compilation unit.
2305  //
2306  // Operand interpretation is exactly like that for DW_FORM_ref2.
2307  //
2308  // This operation transfers control of DWARF expression evaluation to the
2309  // DW_AT_location attribute of the referenced DIE. If there is no such
2310  // attribute, then there is no effect. Execution of the DWARF expression of
2311  // a DW_AT_location attribute may add to and/or remove from values on the
2312  // stack. Execution returns to the point following the call when the end of
2313  // the attribute is reached. Values on the stack at the time of the call
2314  // may be used as parameters by the called expression and values left on
2315  // the stack by the called expression may be used as return values by prior
2316  // agreement between the calling and called expressions.
2317  case DW_OP_call2:
2318  if (error_ptr)
2319  error_ptr->SetErrorString("Unimplemented opcode DW_OP_call2.");
2320  return false;
2321  // OPCODE: DW_OP_call4
2322  // OPERANDS: 1
2323  // uint32_t compile unit relative offset of a DIE
2324  // DESCRIPTION: Performs a subroutine call during evaluation of a DWARF
2325  // expression. For DW_OP_call4, the operand is a 4-byte unsigned offset of
2326  // a debugging information entry in the current compilation unit.
2327  //
2328  // Operand interpretation DW_OP_call4 is exactly like that for
2329  // DW_FORM_ref4.
2330  //
2331  // This operation transfers control of DWARF expression evaluation to the
2332  // DW_AT_location attribute of the referenced DIE. If there is no such
2333  // attribute, then there is no effect. Execution of the DWARF expression of
2334  // a DW_AT_location attribute may add to and/or remove from values on the
2335  // stack. Execution returns to the point following the call when the end of
2336  // the attribute is reached. Values on the stack at the time of the call
2337  // may be used as parameters by the called expression and values left on
2338  // the stack by the called expression may be used as return values by prior
2339  // agreement between the calling and called expressions.
2340  case DW_OP_call4:
2341  if (error_ptr)
2342  error_ptr->SetErrorString("Unimplemented opcode DW_OP_call4.");
2343  return false;
2344 
2345  // OPCODE: DW_OP_stack_value
2346  // OPERANDS: None
2347  // DESCRIPTION: Specifies that the object does not exist in memory but
2348  // rather is a constant value. The value from the top of the stack is the
2349  // value to be used. This is the actual object value and not the location.
2350  case DW_OP_stack_value:
2351  dwarf4_location_description_kind = Implicit;
2352  if (stack.empty()) {
2353  if (error_ptr)
2354  error_ptr->SetErrorString(
2355  "Expression stack needs at least 1 item for DW_OP_stack_value.");
2356  return false;
2357  }
2358  stack.back().SetValueType(Value::ValueType::Scalar);
2359  break;
2360 
2361  // OPCODE: DW_OP_convert
2362  // OPERANDS: 1
2363  // A ULEB128 that is either a DIE offset of a
2364  // DW_TAG_base_type or 0 for the generic (pointer-sized) type.
2365  //
2366  // DESCRIPTION: Pop the top stack element, convert it to a
2367  // different type, and push the result.
2368  case DW_OP_convert: {
2369  if (stack.size() < 1) {
2370  if (error_ptr)
2371  error_ptr->SetErrorString(
2372  "Expression stack needs at least 1 item for DW_OP_convert.");
2373  return false;
2374  }
2375  const uint64_t die_offset = opcodes.GetULEB128(&offset);
2376  uint64_t bit_size;
2377  bool sign;
2378  if (die_offset == 0) {
2379  // The generic type has the size of an address on the target
2380  // machine and an unspecified signedness. Scalar has no
2381  // "unspecified signedness", so we use unsigned types.
2382  if (!module_sp) {
2383  if (error_ptr)
2384  error_ptr->SetErrorString("No module");
2385  return false;
2386  }
2387  sign = false;
2388  bit_size = module_sp->GetArchitecture().GetAddressByteSize() * 8;
2389  if (!bit_size) {
2390  if (error_ptr)
2391  error_ptr->SetErrorString("unspecified architecture");
2392  return false;
2393  }
2394  } else {
2395  // Retrieve the type DIE that the value is being converted to. This
2396  // offset is compile unit relative so we need to fix it up.
2397  const uint64_t abs_die_offset = die_offset + dwarf_cu->GetOffset();
2398  // FIXME: the constness has annoying ripple effects.
2399  DWARFDIE die = const_cast<DWARFUnit *>(dwarf_cu)->GetDIE(abs_die_offset);
2400  if (!die) {
2401  if (error_ptr)
2402  error_ptr->SetErrorString("Cannot resolve DW_OP_convert type DIE");
2403  return false;
2404  }
2405  uint64_t encoding =
2406  die.GetAttributeValueAsUnsigned(DW_AT_encoding, DW_ATE_hi_user);
2407  bit_size = die.GetAttributeValueAsUnsigned(DW_AT_byte_size, 0) * 8;
2408  if (!bit_size)
2409  bit_size = die.GetAttributeValueAsUnsigned(DW_AT_bit_size, 0);
2410  if (!bit_size) {
2411  if (error_ptr)
2412  error_ptr->SetErrorString("Unsupported type size in DW_OP_convert");
2413  return false;
2414  }
2415  switch (encoding) {
2416  case DW_ATE_signed:
2417  case DW_ATE_signed_char:
2418  sign = true;
2419  break;
2420  case DW_ATE_unsigned:
2421  case DW_ATE_unsigned_char:
2422  sign = false;
2423  break;
2424  default:
2425  if (error_ptr)
2426  error_ptr->SetErrorString("Unsupported encoding in DW_OP_convert");
2427  return false;
2428  }
2429  }
2430  Scalar &top = stack.back().ResolveValue(exe_ctx);
2431  top.TruncOrExtendTo(bit_size, sign);
2432  break;
2433  }
2434 
2435  // OPCODE: DW_OP_call_frame_cfa
2436  // OPERANDS: None
2437  // DESCRIPTION: Specifies a DWARF expression that pushes the value of
2438  // the canonical frame address consistent with the call frame information
2439  // located in .debug_frame (or in the FDEs of the eh_frame section).
2440  case DW_OP_call_frame_cfa:
2441  if (frame) {
2442  // Note that we don't have to parse FDEs because this DWARF expression
2443  // is commonly evaluated with a valid stack frame.
2444  StackID id = frame->GetStackID();
2445  addr_t cfa = id.GetCallFrameAddress();
2446  if (cfa != LLDB_INVALID_ADDRESS) {
2447  stack.push_back(Scalar(cfa));
2448  stack.back().SetValueType(Value::ValueType::LoadAddress);
2449  } else if (error_ptr)
2450  error_ptr->SetErrorString("Stack frame does not include a canonical "
2451  "frame address for DW_OP_call_frame_cfa "
2452  "opcode.");
2453  } else {
2454  if (error_ptr)
2455  error_ptr->SetErrorString("Invalid stack frame in context for "
2456  "DW_OP_call_frame_cfa opcode.");
2457  return false;
2458  }
2459  break;
2460 
2461  // OPCODE: DW_OP_form_tls_address (or the old pre-DWARFv3 vendor extension
2462  // opcode, DW_OP_GNU_push_tls_address)
2463  // OPERANDS: none
2464  // DESCRIPTION: Pops a TLS offset from the stack, converts it to
2465  // an address in the current thread's thread-local storage block, and
2466  // pushes it on the stack.
2467  case DW_OP_form_tls_address:
2468  case DW_OP_GNU_push_tls_address: {
2469  if (stack.size() < 1) {
2470  if (error_ptr) {
2471  if (op == DW_OP_form_tls_address)
2472  error_ptr->SetErrorString(
2473  "DW_OP_form_tls_address needs an argument.");
2474  else
2475  error_ptr->SetErrorString(
2476  "DW_OP_GNU_push_tls_address needs an argument.");
2477  }
2478  return false;
2479  }
2480 
2481  if (!exe_ctx || !module_sp) {
2482  if (error_ptr)
2483  error_ptr->SetErrorString("No context to evaluate TLS within.");
2484  return false;
2485  }
2486 
2487  Thread *thread = exe_ctx->GetThreadPtr();
2488  if (!thread) {
2489  if (error_ptr)
2490  error_ptr->SetErrorString("No thread to evaluate TLS within.");
2491  return false;
2492  }
2493 
2494  // Lookup the TLS block address for this thread and module.
2495  const addr_t tls_file_addr =
2496  stack.back().GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
2497  const addr_t tls_load_addr =
2498  thread->GetThreadLocalData(module_sp, tls_file_addr);
2499 
2500  if (tls_load_addr == LLDB_INVALID_ADDRESS) {
2501  if (error_ptr)
2502  error_ptr->SetErrorString(
2503  "No TLS data currently exists for this thread.");
2504  return false;
2505  }
2506 
2507  stack.back().GetScalar() = tls_load_addr;
2508  stack.back().SetValueType(Value::ValueType::LoadAddress);
2509  } break;
2510 
2511  // OPCODE: DW_OP_addrx (DW_OP_GNU_addr_index is the legacy name.)
2512  // OPERANDS: 1
2513  // ULEB128: index to the .debug_addr section
2514  // DESCRIPTION: Pushes an address to the stack from the .debug_addr
2515  // section with the base address specified by the DW_AT_addr_base attribute
2516  // and the 0 based index is the ULEB128 encoded index.
2517  case DW_OP_addrx:
2518  case DW_OP_GNU_addr_index: {
2519  if (!dwarf_cu) {
2520  if (error_ptr)
2521  error_ptr->SetErrorString("DW_OP_GNU_addr_index found without a "
2522  "compile unit being specified");
2523  return false;
2524  }
2525  uint64_t index = opcodes.GetULEB128(&offset);
2526  lldb::addr_t value = dwarf_cu->ReadAddressFromDebugAddrSection(index);
2527  stack.push_back(Scalar(value));
2528  if (target &&
2530  // wasm file sections aren't mapped into memory, therefore addresses can
2531  // never point into a file section and are always LoadAddresses.
2532  stack.back().SetValueType(Value::ValueType::LoadAddress);
2533  } else {
2534  stack.back().SetValueType(Value::ValueType::FileAddress);
2535  }
2536  } break;
2537 
2538  // OPCODE: DW_OP_GNU_const_index
2539  // OPERANDS: 1
2540  // ULEB128: index to the .debug_addr section
2541  // DESCRIPTION: Pushes an constant with the size of a machine address to
2542  // the stack from the .debug_addr section with the base address specified
2543  // by the DW_AT_addr_base attribute and the 0 based index is the ULEB128
2544  // encoded index.
2545  case DW_OP_GNU_const_index: {
2546  if (!dwarf_cu) {
2547  if (error_ptr)
2548  error_ptr->SetErrorString("DW_OP_GNU_const_index found without a "
2549  "compile unit being specified");
2550  return false;
2551  }
2552  uint64_t index = opcodes.GetULEB128(&offset);
2553  lldb::addr_t value = dwarf_cu->ReadAddressFromDebugAddrSection(index);
2554  stack.push_back(Scalar(value));
2555  } break;
2556 
2557  case DW_OP_GNU_entry_value:
2558  case DW_OP_entry_value: {
2559  if (!Evaluate_DW_OP_entry_value(stack, exe_ctx, reg_ctx, opcodes, offset,
2560  error_ptr, log)) {
2561  LLDB_ERRORF(error_ptr, "Could not evaluate %s.",
2562  DW_OP_value_to_name(op));
2563  return false;
2564  }
2565  break;
2566  }
2567 
2568  default:
2569  if (dwarf_cu) {
2571  op, opcodes, offset, stack)) {
2572  break;
2573  }
2574  }
2575  if (error_ptr)
2576  error_ptr->SetErrorStringWithFormatv(
2577  "Unhandled opcode {0} in DWARFExpression", LocationAtom(op));
2578  return false;
2579  }
2580  }
2581 
2582  if (stack.empty()) {
2583  // Nothing on the stack, check if we created a piece value from DW_OP_piece
2584  // or DW_OP_bit_piece opcodes
2585  if (pieces.GetBuffer().GetByteSize()) {
2586  result = pieces;
2587  return true;
2588  }
2589  if (error_ptr)
2590  error_ptr->SetErrorString("Stack empty after evaluation.");
2591  return false;
2592  }
2593 
2594  UpdateValueTypeFromLocationDescription(
2595  log, dwarf_cu, dwarf4_location_description_kind, &stack.back());
2596 
2597  if (log && log->GetVerbose()) {
2598  size_t count = stack.size();
2599  LLDB_LOGF(log,
2600  "Stack after operation has %" PRIu64 " values:", (uint64_t)count);
2601  for (size_t i = 0; i < count; ++i) {
2602  StreamString new_value;
2603  new_value.Printf("[%" PRIu64 "]", (uint64_t)i);
2604  stack[i].Dump(&new_value);
2605  LLDB_LOGF(log, " %s", new_value.GetData());
2606  }
2607  }
2608  result = stack.back();
2609  return true; // Return true on success
2610 }
2611 
2613  const DWARFUnit *dwarf_cu, const DataExtractor &data,
2614  DWARFExpressionList *location_list) {
2615  location_list->Clear();
2616  std::unique_ptr<llvm::DWARFLocationTable> loctable_up =
2617  dwarf_cu->GetLocationTable(data);
2619  auto lookup_addr =
2620  [&](uint32_t index) -> llvm::Optional<llvm::object::SectionedAddress> {
2621  addr_t address = dwarf_cu->ReadAddressFromDebugAddrSection(index);
2622  if (address == LLDB_INVALID_ADDRESS)
2623  return llvm::None;
2624  return llvm::object::SectionedAddress{address};
2625  };
2626  auto process_list = [&](llvm::Expected<llvm::DWARFLocationExpression> loc) {
2627  if (!loc) {
2628  LLDB_LOG_ERROR(log, loc.takeError(), "{0}");
2629  return true;
2630  }
2631  auto buffer_sp =
2632  std::make_shared<DataBufferHeap>(loc->Expr.data(), loc->Expr.size());
2634  buffer_sp, data.GetByteOrder(), data.GetAddressByteSize()));
2635  location_list->AddExpression(loc->Range->LowPC, loc->Range->HighPC, expr);
2636  return true;
2637  };
2638  llvm::Error error = loctable_up->visitAbsoluteLocationList(
2639  0, llvm::object::SectionedAddress{dwarf_cu->GetBaseAddress()},
2640  lookup_addr, process_list);
2641  location_list->Sort();
2642  if (error) {
2643  LLDB_LOG_ERROR(log, std::move(error), "{0}");
2644  return false;
2645  }
2646  return true;
2647 }
2648 
2650  StackFrame &frame, const Instruction::Operand &operand) const {
2651  using namespace OperandMatchers;
2652 
2653  RegisterContextSP reg_ctx_sp = frame.GetRegisterContext();
2654  if (!reg_ctx_sp) {
2655  return false;
2656  }
2657 
2658  DataExtractor opcodes(m_data);
2659 
2660  lldb::offset_t op_offset = 0;
2661  uint8_t opcode = opcodes.GetU8(&op_offset);
2662 
2663  if (opcode == DW_OP_fbreg) {
2664  int64_t offset = opcodes.GetSLEB128(&op_offset);
2665 
2666  DWARFExpressionList *fb_expr = frame.GetFrameBaseExpression(nullptr);
2667  if (!fb_expr) {
2668  return false;
2669  }
2670 
2671  auto recurse = [&frame, fb_expr](const Instruction::Operand &child) {
2672  return fb_expr->MatchesOperand(frame, child);
2673  };
2674 
2675  if (!offset &&
2677  recurse)(operand)) {
2678  return true;
2679  }
2680 
2681  return MatchUnaryOp(
2684  MatchImmOp(offset), recurse))(operand);
2685  }
2686 
2687  bool dereference = false;
2688  const RegisterInfo *reg = nullptr;
2689  int64_t offset = 0;
2690 
2691  if (opcode >= DW_OP_reg0 && opcode <= DW_OP_reg31) {
2692  reg = reg_ctx_sp->GetRegisterInfo(m_reg_kind, opcode - DW_OP_reg0);
2693  } else if (opcode >= DW_OP_breg0 && opcode <= DW_OP_breg31) {
2694  offset = opcodes.GetSLEB128(&op_offset);
2695  reg = reg_ctx_sp->GetRegisterInfo(m_reg_kind, opcode - DW_OP_breg0);
2696  } else if (opcode == DW_OP_regx) {
2697  uint32_t reg_num = static_cast<uint32_t>(opcodes.GetULEB128(&op_offset));
2698  reg = reg_ctx_sp->GetRegisterInfo(m_reg_kind, reg_num);
2699  } else if (opcode == DW_OP_bregx) {
2700  uint32_t reg_num = static_cast<uint32_t>(opcodes.GetULEB128(&op_offset));
2701  offset = opcodes.GetSLEB128(&op_offset);
2702  reg = reg_ctx_sp->GetRegisterInfo(m_reg_kind, reg_num);
2703  } else {
2704  return false;
2705  }
2706 
2707  if (!reg) {
2708  return false;
2709  }
2710 
2711  if (dereference) {
2712  if (!offset &&
2714  MatchRegOp(*reg))(operand)) {
2715  return true;
2716  }
2717 
2718  return MatchUnaryOp(
2721  MatchRegOp(*reg),
2722  MatchImmOp(offset)))(operand);
2723  } else {
2724  return MatchRegOp(*reg)(operand);
2725  }
2726 }
lldb_private::Function::GetTailCallingEdges
llvm::ArrayRef< std::unique_ptr< CallEdge > > GetTailCallingEdges()
Get the outgoing tail-calling edges from this function.
Definition: Function.cpp:323
lldb_private::DataExtractor::GetULEB128
uint64_t GetULEB128(lldb::offset_t *offset_ptr) const
Extract a unsigned LEB128 value from *offset_ptr.
Definition: DataExtractor.cpp:842
lldb_private::Value::ValueType::Scalar
@ Scalar
A raw scalar value.
lldb_private::ExecutionContext
Definition: ExecutionContext.h:292
lldb_private::DWARFExpressionList::Clear
void Clear()
Definition: DWARFExpressionList.h:42
lldb_private::DataBufferHeap::GetByteSize
lldb::offset_t GetByteSize() const override
Definition: DataBufferHeap.cpp:43
lldb_private::Value::GetBuffer
DataBufferHeap & GetBuffer()
Definition: Value.h:120
Scalar.h
lldb_private::ExecutionContext::HasTargetScope
bool HasTargetScope() const
Returns true the ExecutionContext object contains a valid target.
Definition: ExecutionContext.cpp:379
lldb_private::DataExtractor::GetAddress
uint64_t GetAddress(lldb::offset_t *offset_ptr) const
Extract an address from *offset_ptr.
Definition: DataExtractor.cpp:649
lldb_private::DWARFExpressionList::Sort
void Sort()
Sort m_expressions.
Definition: DWARFExpressionList.h:55
lldb_private::Log::GetVerbose
bool GetVerbose() const
Definition: Log.cpp:301
lldb_private::CallSiteParameter::LocationInCaller
DWARFExpressionList LocationInCaller
Definition: Function.h:257
LLDB_INVALID_REGNUM
#define LLDB_INVALID_REGNUM
Definition: lldb-defines.h:79
lldb_private::ABI
Definition: ABI.h:27
lldb_private::Process::ReadMemory
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:1925
lldb_private::RegisterValue
Definition: RegisterValue.h:28
lldb_private::DWARFExpression::~DWARFExpression
virtual ~DWARFExpression()
Destructor.
lldb_private::Value
Definition: Value.h:38
lldb_private::Value::SetValueType
void SetValueType(ValueType value_type)
Definition: Value.h:89
lldb_private::ExecutionContext::GetProcessPtr
Process * GetProcessPtr() const
Returns a pointer to the process object.
Definition: ExecutionContext.cpp:206
lldb_private::DWARFExpression::m_data
DataExtractor m_data
A data extractor capable of reading opcode bytes.
Definition: DWARFExpression.h:160
lldb_private::DataExtractor::ValidOffset
bool ValidOffset(lldb::offset_t offset) const
Test the validity of offset.
Definition: DataExtractor.h:956
lldb_private::OperandMatchers::MatchOpType
std::function< bool(const Instruction::Operand &)> MatchOpType(Instruction::Operand::Type type)
Definition: Disassembler.h:280
Host.h
lldb_private::Value::ValueType::Invalid
@ Invalid
lldb_private::Value::ValueType::FileAddress
@ FileAddress
A file address value.
SymbolFileDWARF::GetVendorDWARFOpcodeSize
virtual lldb::offset_t GetVendorDWARFOpcodeSize(const lldb_private::DataExtractor &data, const lldb::offset_t data_offset, const uint8_t op) const
Definition: SymbolFileDWARF.h:334
lldb_private::Value::GetValueType
ValueType GetValueType() const
Definition: Value.cpp:106
LLDB_ERRORF
#define LLDB_ERRORF(status, fmt,...)
Definition: Status.h:204
lldb_private::ArchSpec::GetCore
Core GetCore() const
Definition: ArchSpec.h:442
ReadRegisterValueAsScalar
static bool ReadRegisterValueAsScalar(RegisterContext *reg_ctx, lldb::RegisterKind reg_kind, uint32_t reg_num, Status *error_ptr, Value &value)
Definition: DWARFExpression.cpp:84
lldb_private::DWARFExpressionList::MatchesOperand
bool MatchesOperand(StackFrame &frame, const Instruction::Operand &operand) const
Definition: DWARFExpressionList.cpp:115
lldb_private::RegisterContext::ReadRegister
virtual bool ReadRegister(const RegisterInfo *reg_info, RegisterValue &reg_value)=0
lldb_private::Scalar
Definition: Scalar.h:34
LLDB_LOGF
#define LLDB_LOGF(log,...)
Definition: Log.h:344
lldb_private::Process
Definition: Process.h:338
Module.h
lldb_private::ArchSpec::eCore_wasm32
@ eCore_wasm32
Definition: ArchSpec.h:223
lldb_private::RegisterContext::ConvertRegisterKindToRegisterNumber
virtual uint32_t ConvertRegisterKindToRegisterNumber(lldb::RegisterKind kind, uint32_t num)
Convert from a given register numbering scheme to the lldb register numbering scheme.
Definition: RegisterContext.cpp:268
lldb_private::StackFrame::GetFrameBaseExpression
DWARFExpressionList * GetFrameBaseExpression(Status *error_ptr)
Get the DWARFExpressionList corresponding to the Canonical Frame Address.
Definition: StackFrame.cpp:1132
lldb_private::ExecutionContext::GetFramePtr
StackFrame * GetFramePtr() const
Returns a pointer to the frame object.
Definition: ExecutionContext.h:408
lldb_private::DWARFExpression::ParseDWARFLocationList
static bool ParseDWARFLocationList(const DWARFUnit *dwarf_cu, const DataExtractor &data, DWARFExpressionList *loc_list)
Definition: DWARFExpression.cpp:2612
lldb_private::Scalar::UInt128
llvm::APInt UInt128(const llvm::APInt &fail_value) const
Definition: Scalar.cpp:350
lldb_private::Value::ValueType::LoadAddress
@ LoadAddress
A load address value.
lldb::offset_t
uint64_t offset_t
Definition: lldb-types.h:87
RegisterValue.h
lldb_private::Status::SetErrorStringWithFormatv
void SetErrorStringWithFormatv(const char *format, Args &&... args)
Definition: Status.h:173
StackFrame.h
lldb_private::Stream
Definition: Stream.h:28
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
lldb_private::RegisterContext::GetRegisterInfoAtIndex
virtual const RegisterInfo * GetRegisterInfoAtIndex(size_t reg)=0
lldb_private::Target
Definition: Target.h:469
lldb_private::DataExtractor::GetU64
uint64_t GetU64(lldb::offset_t *offset_ptr) const
Extract a uint64_t value from *offset_ptr.
Definition: DataExtractor.cpp:474
lldb_private::ExecutionContext::GetThreadPtr
Thread * GetThreadPtr() const
Returns a pointer to the thread object.
Definition: ExecutionContext.h:399
lldb_private::DataExtractor::SetData
lldb::offset_t SetData(const void *bytes, lldb::offset_t length, lldb::ByteOrder byte_order)
Set data with a buffer that is caller owned.
Definition: DataExtractor.cpp:223
ABI.h
lldb_private::DW_OP_value_to_name
const char * DW_OP_value_to_name(uint32_t val)
Definition: DWARFDefines.cpp:51
lldb_private::Target::GetImages
const ModuleList & GetImages() const
Get accessor for the images for this process.
Definition: Target.h:947
lldb_private::DWARFExpression::ContainsThreadLocalStorage
bool ContainsThreadLocalStorage(const DWARFUnit *dwarf_cu) const
Definition: DWARFExpression.cpp:420
Process.h
lldb_private::DWARFExpressionList::AddExpression
bool AddExpression(lldb::addr_t base, lldb::addr_t end, DWARFExpression expr)
Definition: DWARFExpressionList.cpp:33
DWARFDIE
Definition: DWARFDIE.h:16
Target.h
lldb_private::DataExtractor::SetByteOrder
void SetByteOrder(lldb::ByteOrder byte_order)
Set the byte_order value.
Definition: DataExtractor.h:931
lldb_private::Value::GetScalar
const Scalar & GetScalar() const
Definition: Value.h:112
lldb_private::DWARFExpression::LinkThreadLocalStorage
bool LinkThreadLocalStorage(const DWARFUnit *dwarf_cu, std::function< lldb::addr_t(lldb::addr_t file_addr)> const &link_address_callback)
Definition: DWARFExpression.cpp:436
lldb_private::DWARFExpression::m_reg_kind
lldb::RegisterKind m_reg_kind
One of the defines that starts with LLDB_REGKIND_.
Definition: DWARFExpression.h:163
lldb_private::Instruction::Operand::Type::Sum
@ Sum
lldb_private::StackID::GetCallFrameAddress
lldb::addr_t GetCallFrameAddress() const
Definition: StackID.h:33
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb_private::DataExtractor::GetSLEB128
int64_t GetSLEB128(lldb::offset_t *offset_ptr) const
Extract a signed LEB128 value from *offset_ptr.
Definition: DataExtractor.cpp:859
lldb_private::DWARFExpression::SetRegisterKind
void SetRegisterKind(lldb::RegisterKind reg_kind)
Set the call-frame-info style register kind.
Definition: DWARFExpression.cpp:79
lldb_private::Function
Definition: Function.h:409
lldb_private::ExecutionContext::GetRegisterContext
RegisterContext * GetRegisterContext() const
Definition: ExecutionContext.cpp:190
DWARFUnit
Definition: DWARFUnit.h:83
SymbolFileDWARF::ParseVendorDWARFOpcode
virtual bool ParseVendorDWARFOpcode(uint8_t op, const lldb_private::DataExtractor &opcodes, lldb::offset_t &offset, std::vector< lldb_private::Value > &stack) const
Definition: SymbolFileDWARF.h:341
lldb_private::OperandMatchers::MatchBinaryOp
std::function< bool(const Instruction::Operand &)> MatchBinaryOp(std::function< bool(const Instruction::Operand &)> base, std::function< bool(const Instruction::Operand &)> left, std::function< bool(const Instruction::Operand &)> right)
Definition: Disassembler.h:262
DWARFUnit::GetLocationTable
std::unique_ptr< llvm::DWARFLocationTable > GetLocationTable(const lldb_private::DataExtractor &data) const
Return the location table for parsing the given location list data.
Definition: DWARFUnit.cpp:507
lldb_private::DataExtractor::GetAddressByteSize
uint32_t GetAddressByteSize() const
Get the current address size.
Definition: DataExtractor.h:264
lldb_private::Function::GetName
ConstString GetName() const
Definition: Function.cpp:654
LLDB_INVALID_OFFSET
#define LLDB_INVALID_OFFSET
Definition: lldb-defines.h:85
lldb_private::DataExtractor
Definition: DataExtractor.h:48
lldb_private::ModuleList
Definition: ModuleList.h:82
lldb_private::Scalar::ULongLong
unsigned long long ULongLong(unsigned long long fail_value=0) const
Definition: Scalar.cpp:334
Log.h
lldb_private::process_gdb_remote::GDBRLog::Memory
@ Memory
lldb_private::DWARFExpression::Update_DW_OP_addr
bool Update_DW_OP_addr(const DWARFUnit *dwarf_cu, lldb::addr_t file_addr)
Definition: DWARFExpression.cpp:382
lldb_private::Thread
Definition: Thread.h:61
lldb_private::StreamString::GetData
const char * GetData() const
Definition: StreamString.h:43
lldb_private::DWARFExpression::DumpLocation
void DumpLocation(Stream *s, lldb::DescriptionLevel level, ABI *abi) const
Definition: DWARFExpression.cpp:70
lldb_private::Status::SetErrorStringWithFormat
int SetErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Set the current error string to a formatted error string.
Definition: Status.cpp:255
lldb_private::DataExtractor::GetAsLLVM
llvm::DataExtractor GetAsLLVM() const
Definition: DataExtractor.h:989
lldb_private::SymbolContext::function
Function * function
The Function for a given query.
Definition: SymbolContext.h:320
lldb_private::DataExtractor::SetAddressByteSize
void SetAddressByteSize(uint32_t addr_size)
Set the address byte size.
Definition: DataExtractor.h:845
StreamString.h
lldb_private::DWARFExpression
Definition: DWARFExpression.h:36
lldb_private::DWARFExpression::GetRegisterKind
lldb::RegisterKind GetRegisterKind() const
Return the call-frame-info style register kind.
Definition: DWARFExpression.cpp:77
lldb_private::DataExtractor::GetDataStart
const uint8_t * GetDataStart() const
Get the data start pointer.
Definition: DataExtractor.h:422
lldb_private::DataExtractor::GetByteOrder
lldb::ByteOrder GetByteOrder() const
Get the current byte order value.
Definition: DataExtractor.h:594
lldb_private::ObjectFile::GetByteOrder
virtual lldb::ByteOrder GetByteOrder() const =0
Gets whether endian swapping should occur when extracting data from this object file.
lldb_private::StreamString
Definition: StreamString.h:23
lldb_private::DataExtractor::GetU8
uint8_t GetU8(lldb::offset_t *offset_ptr) const
Extract a uint8_t value from *offset_ptr.
Definition: DataExtractor.cpp:316
StackID.h
DataEncoder.h
lldb_private::Thread::GetStackFrameCount
virtual uint32_t GetStackFrameCount()
Definition: Thread.h:395
lldb_private::CallEdge
Definition: Function.h:267
lldb_private::ABI::GetMCRegisterInfo
llvm::MCRegisterInfo & GetMCRegisterInfo()
Definition: ABI.h:143
lldb_private::Value::ValueType
ValueType
Type that describes Value::m_value.
Definition: Value.h:41
lldb_private::DWARFExpression::GetLocation_DW_OP_addr
lldb::addr_t GetLocation_DW_OP_addr(const DWARFUnit *dwarf_cu, uint32_t op_addr_idx, bool &error) const
If a location is not a location list, return true if the location contains a DW_OP_addr () opcode in ...
Definition: DWARFExpression.cpp:344
GetOpcodeDataSize
static offset_t GetOpcodeDataSize(const DataExtractor &data, const lldb::offset_t data_offset, const uint8_t op, const DWARFUnit *dwarf_cu)
Return the length in bytes of the set of operands for op.
Definition: DWARFExpression.cpp:132
lldb_private::OperandMatchers::MatchImmOp
std::function< bool(const Instruction::Operand &)> MatchImmOp(int64_t imm)
Definition: Disassembler.h:275
lldb_private::Scalar::GetByteSize
size_t GetByteSize() const
Definition: Scalar.cpp:131
lldb_private::Instruction::Operand
Definition: Disassembler.h:198
lldb_private::Scalar::ExtractBitfield
bool ExtractBitfield(uint32_t bit_size, uint32_t bit_offset)
Definition: Scalar.cpp:798
lldb_private::CallSiteParameter
Definition: Function.h:255
lldb_private::StackFrame::GetFrameBaseValue
bool GetFrameBaseValue(Scalar &value, Status *error_ptr)
Return the Canonical Frame Address (DWARF term) for this frame.
Definition: StackFrame.cpp:1086
lldb_private::DataExtractor::Skip_LEB128
uint32_t Skip_LEB128(lldb::offset_t *offset_ptr) const
Skip an LEB128 number at *offset_ptr.
Definition: DataExtractor.cpp:876
DWARFUnit.h
Thread.h
lldb_private::RegisterContext
Definition: RegisterContext.h:17
Empty
@ Empty
If the Mangled object has neither a mangled name or demangled name we can encode the object with one ...
Definition: Mangled.cpp:404
DWARFUnit::GetBaseAddress
dw_addr_t GetBaseAddress() const
Definition: DWARFUnit.h:159
lldb_private::DWARFExpression::UpdateValue
void UpdateValue(uint64_t const_value, lldb::offset_t const_value_byte_size, uint8_t addr_byte_size)
Definition: DWARFExpression.cpp:58
lldb_private::Function::GetCallEdgeForReturnAddress
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:330
lldb::RegisterKind
RegisterKind
Register numbering types.
Definition: lldb-enumerations.h:228
lldb_private::DWARFExpressionList::Evaluate
bool Evaluate(ExecutionContext *exe_ctx, RegisterContext *reg_ctx, lldb::addr_t func_load_addr, const Value *initial_value_ptr, const Value *object_address_ptr, Value &result, Status *error_ptr) const
Definition: DWARFExpressionList.cpp:201
DWARFUnit::GetOffset
dw_offset_t GetOffset() const
Definition: DWARFUnit.h:133
lldb_private::StackFrame::GetStackID
StackID & GetStackID()
Definition: StackFrame.cpp:145
lldb_private::Value::ClearContext
void ClearContext()
Definition: Value.h:91
lldb_private::Value::ResolveValue
Scalar & ResolveValue(ExecutionContext *exe_ctx)
Definition: Value.cpp:560
lldb_private::Instruction::Operand::Type::Dereference
@ Dereference
lldb_private::OperandMatchers::MatchRegOp
std::function< bool(const Instruction::Operand &)> MatchRegOp(const RegisterInfo &info)
Definition: Disassembler.h:271
lldb_private::DWARFExpression::MatchesOperand
bool MatchesOperand(StackFrame &frame, const Instruction::Operand &op) const
Definition: DWARFExpression.cpp:2649
lldb_private::DWARFExpression::DWARFExpression
DWARFExpression()
Definition: DWARFExpression.cpp:49
lldb_private::Target::GetArchitecture
const ArchSpec & GetArchitecture() const
Definition: Target.h:989
DWARFBaseDIE::GetAttributeValueAsUnsigned
uint64_t GetAttributeValueAsUnsigned(const dw_attr_t attr, uint64_t fail_value) const
Definition: DWARFBaseDIE.cpp:48
lldb_private::Status
Definition: Status.h:44
dwarf.h
lldb_private::Target::ReadMemory
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)
Definition: Target.cpp:1752
lldb_private::OperandMatchers::MatchUnaryOp
std::function< bool(const Instruction::Operand &)> MatchUnaryOp(std::function< bool(const Instruction::Operand &)> base, std::function< bool(const Instruction::Operand &)> child)
Definition: Disassembler.h:267
lldb_private::Scalar::IsZero
bool IsZero() const
Definition: Scalar.cpp:143
uint32_t
DWARFUnit::GetVersion
uint16_t GetVersion() const
Definition: DWARFUnit.h:154
lldb_private::Address
Definition: Address.h:59
lldb_private::DataExtractor::GetMaxU64
uint64_t GetMaxU64(lldb::offset_t *offset_ptr, size_t byte_size) const
Extract an unsigned integer of size byte_size from *offset_ptr.
Definition: DataExtractor.cpp:524
lldb_private::CallEdge::GetCallee
virtual Function * GetCallee(ModuleList &images, ExecutionContext &exe_ctx)=0
Get the callee's definition.
lldb_private::Value::ValueType::HostAddress
@ HostAddress
A host address value (for memory in the process that < A is using liblldb).
VMRange.h
ResolveLoadAddress
static llvm::Optional< lldb::addr_t > ResolveLoadAddress(ExecutionContext *exe_ctx, lldb::ModuleSP &module_sp, Status *error_ptr, 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.
Definition: DWARFExpression.cpp:794
lldb_private::DWARFExpression::Evaluate
static bool Evaluate(ExecutionContext *exe_ctx, RegisterContext *reg_ctx, lldb::ModuleSP module_sp, const DataExtractor &opcodes, const DWARFUnit *dwarf_cu, const lldb::RegisterKind reg_set, const Value *initial_value_ptr, const Value *object_address_ptr, Value &result, Status *error_ptr)
Evaluate a DWARF location expression in a particular context.
Definition: DWARFExpression.cpp:843
lldb_private::endian::InlHostByteOrder
lldb::ByteOrder InlHostByteOrder()
Definition: Endian.h:25
Evaluate_DW_OP_entry_value
static bool Evaluate_DW_OP_entry_value(std::vector< Value > &stack, ExecutionContext *exe_ctx, RegisterContext *reg_ctx, const DataExtractor &opcodes, lldb::offset_t &opcode_offset, Status *error_ptr, Log *log)
Definition: DWARFExpression.cpp:521
lldb_private::Status::SetErrorString
void SetErrorString(llvm::StringRef err_str)
Set the current error string to err_str.
Definition: Status.cpp:241
lldb_private::Address::GetLoadAddress
lldb::addr_t GetLoadAddress(Target *target) const
Get the load address.
Definition: Address.cpp:311
lldb_private::Stream::AsRawOstream
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
Definition: Stream.h:357
UINT32_MAX
#define UINT32_MAX
Definition: lldb-defines.h:19
lldb_private::DataExtractor::GetU32
uint32_t GetU32(lldb::offset_t *offset_ptr) const
Extract a uint32_t value from *offset_ptr.
Definition: DataExtractor.cpp:425
LLDB_INVALID_ADDRESS
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:74
LLDB_LOG
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition: Log.h:337
Function.h
lldb_private::Stream::Printf
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:107
lldb_private::Thread::GetThreadLocalData
virtual lldb::addr_t GetThreadLocalData(const lldb::ModuleSP module, lldb::addr_t tls_file_addr)
Retrieves the per-module TLS block for a thread.
Definition: Thread.cpp:1651
DWARFExpression.h
lldb_private::Value::ContextType::RegisterInfo
@ RegisterInfo
RegisterInfo * (can be a scalar or a vector register).
lldb_private::ExecutionContext::GetTargetRef
Target & GetTargetRef() const
Returns a reference to the target object.
Definition: ExecutionContext.cpp:224
lldb_private::DataExtractor::BytesLeft
lldb::offset_t BytesLeft(lldb::offset_t offset) const
Definition: DataExtractor.h:976
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::DataExtractor::GetU16
uint16_t GetU16(lldb::offset_t *offset_ptr) const
Extract a uint16_t value from *offset_ptr.
Definition: DataExtractor.cpp:347
DWARFUnit::ReadAddressFromDebugAddrSection
dw_addr_t ReadAddressFromDebugAddrSection(uint32_t index) const
Definition: DWARFUnit.cpp:595
lldb_private::Value::SetContext
void SetContext(ContextType context_type, void *p)
Definition: Value.h:96
lldb_private::Value::ResizeData
size_t ResizeData(size_t len)
Definition: Value.cpp:173
Error
llvm::Error Error
Definition: UdtRecordCompleter.cpp:34
lldb_private::CallEdge::GetCallSiteParameters
llvm::ArrayRef< CallSiteParameter > GetCallSiteParameters() const
Get the call site parameters available at this call edge.
Definition: Function.h:296
lldb_private::StackFrame::GetRegisterContext
lldb::RegisterContextSP GetRegisterContext()
Get the RegisterContext for this frame, if possible.
Definition: StackFrame.cpp:1143
DerefSizeExtractDataHelper
static Scalar DerefSizeExtractDataHelper(uint8_t *addr_bytes, size_t size_addr_bytes, ByteOrder byte_order, size_t size)
Helper function to move common code used to load sized data from a uint8_t buffer.
Definition: DWARFExpression.cpp:831
lldb_private::Address::IsSectionOffset
bool IsSectionOffset() const
Check if an address is section offset.
Definition: Address.h:332
lldb_private::Status::Clear
void Clear()
Clear the object state.
Definition: Status.cpp:167
lldb_private::StackID
Definition: StackID.h:17
lldb_private::Process::GetABI
const lldb::ABISP & GetABI()
Definition: Process.cpp:1486
lldb_private::Scalar::TruncOrExtendTo
void TruncOrExtendTo(uint16_t bits, bool sign)
Convert to an integer with bits and the given signedness.
Definition: Scalar.cpp:173
lldb_private::DataExtractor::GetData
const void * GetData(lldb::offset_t *offset_ptr, lldb::offset_t length) const
Extract length bytes from *offset_ptr.
Definition: DataExtractor.h:337
lldb_private::DWARFExpressionList
Definition: DWARFExpressionList.h:24
lldb_private::Process::GetByteOrder
lldb::ByteOrder GetByteOrder() const
Definition: Process.cpp:3362
lldb_private::Log
Definition: Log.h:115
lldb_private::StackFrame::GetFrameIndex
uint32_t GetFrameIndex() const
Query this frame to find what frame it is in this Thread's StackFrameList.
Definition: StackFrame.cpp:175
DWARFUnit::GetSymbolFileDWARF
SymbolFileDWARF & GetSymbolFileDWARF() const
Definition: DWARFUnit.h:199
lldb_private::Process::ReadPointerFromMemory
lldb::addr_t ReadPointerFromMemory(lldb::addr_t vm_addr, Status &error)
Definition: Process.cpp:2088
lldb_private::Thread::GetStackFrameAtIndex
virtual lldb::StackFrameSP GetStackFrameAtIndex(uint32_t idx)
Definition: Thread.h:399
lldb_private::ExecutionContext::SetFrameSP
void SetFrameSP(const lldb::StackFrameSP &frame_sp)
Set accessor to set only the frame shared pointer.
Definition: ExecutionContext.cpp:256
lldb_private::GetLog
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition: Log.h:309
lldb_private::DataExtractor::GetByteSize
uint64_t GetByteSize() const
Get the number of bytes contained in this object.
Definition: DataExtractor.h:270
lldb_private::StackFrame
Definition: StackFrame.h:40
lldb_private::DWARFExpression::IsValid
bool IsValid() const
Return true if the location expression contains data.
Definition: DWARFExpression.cpp:56
lldb_private::DataBufferHeap
Definition: DataBufferHeap.h:30
lldb_private::LLDBLog::Expressions
@ Expressions
lldb
Definition: SBAddress.h:15
Endian.h
RegisterContext.h
LLDB_LOG_ERROR
#define LLDB_LOG_ERROR(log, error,...)
Definition: Log.h:360
Value.h
lldb_private::StackFrame::GetSymbolContext
const SymbolContext & GetSymbolContext(lldb::SymbolContextItem resolve_scope)
Provide a SymbolContext for this StackFrame's current pc value.
Definition: StackFrame.cpp:300
LLDBLog.h
lldb_private::RegisterValue::GetScalarValue
bool GetScalarValue(Scalar &scalar) const
Definition: RegisterValue.cpp:126
lldb_private::dwarf
Definition: dwarf.h:19
lldb_private::ExecutionContext::GetTargetPtr
Target * GetTargetPtr() const
Returns a pointer to the target object.
Definition: ExecutionContext.cpp:198
lldb_private::ObjectFile
Definition: ObjectFile.h:60
lldb_private::Value::AppendDataToHostBuffer
size_t AppendDataToHostBuffer(const Value &rhs)
Definition: Value.cpp:135
ExecutionContext.h
lldb::DescriptionLevel
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
Definition: lldb-enumerations.h:208
lldb::ByteOrder
ByteOrder
Byte ordering definitions.
Definition: lldb-enumerations.h:139