blob: f42cc7107a76bce7e599048a803035ea7c635a7d [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- DWARFExpression.cpp -------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "lldb/Expression/DWARFExpression.h"
11
12#include <vector>
13
Greg Claytona1b9a902011-11-13 04:15:56 +000014#include "lldb/Core/DataEncoder.h"
Chris Lattner24943d22010-06-08 16:52:24 +000015#include "lldb/Core/dwarf.h"
16#include "lldb/Core/Log.h"
Greg Clayton061b79d2011-05-09 20:18:18 +000017#include "lldb/Core/RegisterValue.h"
Chris Lattner24943d22010-06-08 16:52:24 +000018#include "lldb/Core/StreamString.h"
19#include "lldb/Core/Scalar.h"
20#include "lldb/Core/Value.h"
Greg Clayton178710c2010-09-14 02:20:48 +000021#include "lldb/Core/VMRange.h"
Chris Lattner24943d22010-06-08 16:52:24 +000022
23#include "lldb/Expression/ClangExpressionDeclMap.h"
24#include "lldb/Expression/ClangExpressionVariable.h"
25
Greg Claytoncd548032011-02-01 01:31:41 +000026#include "lldb/Host/Endian.h"
Jim Ingham8521b842011-12-01 03:01:30 +000027#include "lldb/Host/Host.h"
Chris Lattner24943d22010-06-08 16:52:24 +000028
29#include "lldb/lldb-private-log.h"
30
Greg Clayton1674b122010-07-21 22:12:05 +000031#include "lldb/Symbol/ClangASTType.h"
Chris Lattner24943d22010-06-08 16:52:24 +000032#include "lldb/Symbol/ClangASTContext.h"
33#include "lldb/Symbol/Type.h"
34
Greg Clayton5c3861d2011-09-02 01:15:17 +000035#include "lldb/Target/ABI.h"
Chris Lattner24943d22010-06-08 16:52:24 +000036#include "lldb/Target/ExecutionContext.h"
37#include "lldb/Target/Process.h"
38#include "lldb/Target/RegisterContext.h"
39#include "lldb/Target/StackFrame.h"
40
41using namespace lldb;
42using namespace lldb_private;
43
44const char *
45DW_OP_value_to_name (uint32_t val)
46{
47 static char invalid[100];
48 switch (val) {
49 case 0x03: return "DW_OP_addr";
50 case 0x06: return "DW_OP_deref";
51 case 0x08: return "DW_OP_const1u";
52 case 0x09: return "DW_OP_const1s";
53 case 0x0a: return "DW_OP_const2u";
54 case 0x0b: return "DW_OP_const2s";
55 case 0x0c: return "DW_OP_const4u";
56 case 0x0d: return "DW_OP_const4s";
57 case 0x0e: return "DW_OP_const8u";
58 case 0x0f: return "DW_OP_const8s";
59 case 0x10: return "DW_OP_constu";
60 case 0x11: return "DW_OP_consts";
61 case 0x12: return "DW_OP_dup";
62 case 0x13: return "DW_OP_drop";
63 case 0x14: return "DW_OP_over";
64 case 0x15: return "DW_OP_pick";
65 case 0x16: return "DW_OP_swap";
66 case 0x17: return "DW_OP_rot";
67 case 0x18: return "DW_OP_xderef";
68 case 0x19: return "DW_OP_abs";
69 case 0x1a: return "DW_OP_and";
70 case 0x1b: return "DW_OP_div";
71 case 0x1c: return "DW_OP_minus";
72 case 0x1d: return "DW_OP_mod";
73 case 0x1e: return "DW_OP_mul";
74 case 0x1f: return "DW_OP_neg";
75 case 0x20: return "DW_OP_not";
76 case 0x21: return "DW_OP_or";
77 case 0x22: return "DW_OP_plus";
78 case 0x23: return "DW_OP_plus_uconst";
79 case 0x24: return "DW_OP_shl";
80 case 0x25: return "DW_OP_shr";
81 case 0x26: return "DW_OP_shra";
82 case 0x27: return "DW_OP_xor";
83 case 0x2f: return "DW_OP_skip";
84 case 0x28: return "DW_OP_bra";
85 case 0x29: return "DW_OP_eq";
86 case 0x2a: return "DW_OP_ge";
87 case 0x2b: return "DW_OP_gt";
88 case 0x2c: return "DW_OP_le";
89 case 0x2d: return "DW_OP_lt";
90 case 0x2e: return "DW_OP_ne";
91 case 0x30: return "DW_OP_lit0";
92 case 0x31: return "DW_OP_lit1";
93 case 0x32: return "DW_OP_lit2";
94 case 0x33: return "DW_OP_lit3";
95 case 0x34: return "DW_OP_lit4";
96 case 0x35: return "DW_OP_lit5";
97 case 0x36: return "DW_OP_lit6";
98 case 0x37: return "DW_OP_lit7";
99 case 0x38: return "DW_OP_lit8";
100 case 0x39: return "DW_OP_lit9";
101 case 0x3a: return "DW_OP_lit10";
102 case 0x3b: return "DW_OP_lit11";
103 case 0x3c: return "DW_OP_lit12";
104 case 0x3d: return "DW_OP_lit13";
105 case 0x3e: return "DW_OP_lit14";
106 case 0x3f: return "DW_OP_lit15";
107 case 0x40: return "DW_OP_lit16";
108 case 0x41: return "DW_OP_lit17";
109 case 0x42: return "DW_OP_lit18";
110 case 0x43: return "DW_OP_lit19";
111 case 0x44: return "DW_OP_lit20";
112 case 0x45: return "DW_OP_lit21";
113 case 0x46: return "DW_OP_lit22";
114 case 0x47: return "DW_OP_lit23";
115 case 0x48: return "DW_OP_lit24";
116 case 0x49: return "DW_OP_lit25";
117 case 0x4a: return "DW_OP_lit26";
118 case 0x4b: return "DW_OP_lit27";
119 case 0x4c: return "DW_OP_lit28";
120 case 0x4d: return "DW_OP_lit29";
121 case 0x4e: return "DW_OP_lit30";
122 case 0x4f: return "DW_OP_lit31";
123 case 0x50: return "DW_OP_reg0";
124 case 0x51: return "DW_OP_reg1";
125 case 0x52: return "DW_OP_reg2";
126 case 0x53: return "DW_OP_reg3";
127 case 0x54: return "DW_OP_reg4";
128 case 0x55: return "DW_OP_reg5";
129 case 0x56: return "DW_OP_reg6";
130 case 0x57: return "DW_OP_reg7";
131 case 0x58: return "DW_OP_reg8";
132 case 0x59: return "DW_OP_reg9";
133 case 0x5a: return "DW_OP_reg10";
134 case 0x5b: return "DW_OP_reg11";
135 case 0x5c: return "DW_OP_reg12";
136 case 0x5d: return "DW_OP_reg13";
137 case 0x5e: return "DW_OP_reg14";
138 case 0x5f: return "DW_OP_reg15";
139 case 0x60: return "DW_OP_reg16";
140 case 0x61: return "DW_OP_reg17";
141 case 0x62: return "DW_OP_reg18";
142 case 0x63: return "DW_OP_reg19";
143 case 0x64: return "DW_OP_reg20";
144 case 0x65: return "DW_OP_reg21";
145 case 0x66: return "DW_OP_reg22";
146 case 0x67: return "DW_OP_reg23";
147 case 0x68: return "DW_OP_reg24";
148 case 0x69: return "DW_OP_reg25";
149 case 0x6a: return "DW_OP_reg26";
150 case 0x6b: return "DW_OP_reg27";
151 case 0x6c: return "DW_OP_reg28";
152 case 0x6d: return "DW_OP_reg29";
153 case 0x6e: return "DW_OP_reg30";
154 case 0x6f: return "DW_OP_reg31";
155 case 0x70: return "DW_OP_breg0";
156 case 0x71: return "DW_OP_breg1";
157 case 0x72: return "DW_OP_breg2";
158 case 0x73: return "DW_OP_breg3";
159 case 0x74: return "DW_OP_breg4";
160 case 0x75: return "DW_OP_breg5";
161 case 0x76: return "DW_OP_breg6";
162 case 0x77: return "DW_OP_breg7";
163 case 0x78: return "DW_OP_breg8";
164 case 0x79: return "DW_OP_breg9";
165 case 0x7a: return "DW_OP_breg10";
166 case 0x7b: return "DW_OP_breg11";
167 case 0x7c: return "DW_OP_breg12";
168 case 0x7d: return "DW_OP_breg13";
169 case 0x7e: return "DW_OP_breg14";
170 case 0x7f: return "DW_OP_breg15";
171 case 0x80: return "DW_OP_breg16";
172 case 0x81: return "DW_OP_breg17";
173 case 0x82: return "DW_OP_breg18";
174 case 0x83: return "DW_OP_breg19";
175 case 0x84: return "DW_OP_breg20";
176 case 0x85: return "DW_OP_breg21";
177 case 0x86: return "DW_OP_breg22";
178 case 0x87: return "DW_OP_breg23";
179 case 0x88: return "DW_OP_breg24";
180 case 0x89: return "DW_OP_breg25";
181 case 0x8a: return "DW_OP_breg26";
182 case 0x8b: return "DW_OP_breg27";
183 case 0x8c: return "DW_OP_breg28";
184 case 0x8d: return "DW_OP_breg29";
185 case 0x8e: return "DW_OP_breg30";
186 case 0x8f: return "DW_OP_breg31";
187 case 0x90: return "DW_OP_regx";
188 case 0x91: return "DW_OP_fbreg";
189 case 0x92: return "DW_OP_bregx";
190 case 0x93: return "DW_OP_piece";
191 case 0x94: return "DW_OP_deref_size";
192 case 0x95: return "DW_OP_xderef_size";
193 case 0x96: return "DW_OP_nop";
194 case 0x97: return "DW_OP_push_object_address";
195 case 0x98: return "DW_OP_call2";
196 case 0x99: return "DW_OP_call4";
197 case 0x9a: return "DW_OP_call_ref";
Greg Claytona1b9a902011-11-13 04:15:56 +0000198// case DW_OP_APPLE_array_ref: return "DW_OP_APPLE_array_ref";
199// case DW_OP_APPLE_extern: return "DW_OP_APPLE_extern";
Chris Lattner24943d22010-06-08 16:52:24 +0000200 case DW_OP_APPLE_uninit: return "DW_OP_APPLE_uninit";
Greg Claytona1b9a902011-11-13 04:15:56 +0000201// case DW_OP_APPLE_assign: return "DW_OP_APPLE_assign";
202// case DW_OP_APPLE_address_of: return "DW_OP_APPLE_address_of";
203// case DW_OP_APPLE_value_of: return "DW_OP_APPLE_value_of";
204// case DW_OP_APPLE_deref_type: return "DW_OP_APPLE_deref_type";
205// case DW_OP_APPLE_expr_local: return "DW_OP_APPLE_expr_local";
206// case DW_OP_APPLE_constf: return "DW_OP_APPLE_constf";
207// case DW_OP_APPLE_scalar_cast: return "DW_OP_APPLE_scalar_cast";
208// case DW_OP_APPLE_clang_cast: return "DW_OP_APPLE_clang_cast";
209// case DW_OP_APPLE_clear: return "DW_OP_APPLE_clear";
210// case DW_OP_APPLE_error: return "DW_OP_APPLE_error";
Chris Lattner24943d22010-06-08 16:52:24 +0000211 default:
212 snprintf (invalid, sizeof(invalid), "Unknown DW_OP constant: 0x%x", val);
213 return invalid;
214 }
215}
216
217
218//----------------------------------------------------------------------
219// DWARFExpression constructor
220//----------------------------------------------------------------------
221DWARFExpression::DWARFExpression() :
222 m_data(),
223 m_reg_kind (eRegisterKindDWARF),
Greg Claytonbdcb6ab2011-01-25 23:55:37 +0000224 m_loclist_slide (LLDB_INVALID_ADDRESS)
Chris Lattner24943d22010-06-08 16:52:24 +0000225{
226}
227
228DWARFExpression::DWARFExpression(const DWARFExpression& rhs) :
229 m_data(rhs.m_data),
230 m_reg_kind (rhs.m_reg_kind),
Greg Claytonbdcb6ab2011-01-25 23:55:37 +0000231 m_loclist_slide(rhs.m_loclist_slide)
Chris Lattner24943d22010-06-08 16:52:24 +0000232{
233}
234
235
Greg Clayton178710c2010-09-14 02:20:48 +0000236DWARFExpression::DWARFExpression(const DataExtractor& data, uint32_t data_offset, uint32_t data_length) :
Chris Lattner24943d22010-06-08 16:52:24 +0000237 m_data(data, data_offset, data_length),
238 m_reg_kind (eRegisterKindDWARF),
Greg Claytonbdcb6ab2011-01-25 23:55:37 +0000239 m_loclist_slide(LLDB_INVALID_ADDRESS)
Chris Lattner24943d22010-06-08 16:52:24 +0000240{
Chris Lattner24943d22010-06-08 16:52:24 +0000241}
242
243//----------------------------------------------------------------------
244// Destructor
245//----------------------------------------------------------------------
246DWARFExpression::~DWARFExpression()
247{
248}
249
250
251bool
252DWARFExpression::IsValid() const
253{
254 return m_data.GetByteSize() > 0;
255}
256
Chris Lattner24943d22010-06-08 16:52:24 +0000257void
Greg Clayton178710c2010-09-14 02:20:48 +0000258DWARFExpression::SetOpcodeData (const DataExtractor& data)
Chris Lattner24943d22010-06-08 16:52:24 +0000259{
260 m_data = data;
Chris Lattner24943d22010-06-08 16:52:24 +0000261}
262
263void
Greg Clayton4fa86fe2012-08-10 23:33:27 +0000264DWARFExpression::CopyOpcodeData (const DataExtractor& data, uint32_t data_offset, uint32_t data_length)
265{
266 const uint8_t *bytes = data.PeekData(data_offset, data_length);
267 m_data.SetData(DataBufferSP(new DataBufferHeap(bytes, data_length)));
268}
269
270void
Greg Clayton178710c2010-09-14 02:20:48 +0000271DWARFExpression::SetOpcodeData (const DataExtractor& data, uint32_t data_offset, uint32_t data_length)
Chris Lattner24943d22010-06-08 16:52:24 +0000272{
273 m_data.SetData(data, data_offset, data_length);
Chris Lattner24943d22010-06-08 16:52:24 +0000274}
275
276void
Greg Clayton5c3861d2011-09-02 01:15:17 +0000277DWARFExpression::DumpLocation (Stream *s, uint32_t offset, uint32_t length, lldb::DescriptionLevel level, ABI *abi) const
Chris Lattner24943d22010-06-08 16:52:24 +0000278{
279 if (!m_data.ValidOffsetForDataOfSize(offset, length))
280 return;
281 const uint32_t start_offset = offset;
282 const uint32_t end_offset = offset + length;
283 while (m_data.ValidOffset(offset) && offset < end_offset)
284 {
285 const uint32_t op_offset = offset;
286 const uint8_t op = m_data.GetU8(&offset);
287
288 switch (level)
289 {
Greg Clayton54e7afa2010-07-09 20:39:50 +0000290 default:
291 break;
292
Chris Lattner24943d22010-06-08 16:52:24 +0000293 case lldb::eDescriptionLevelBrief:
294 if (offset > start_offset)
295 s->PutChar(' ');
296 break;
297
298 case lldb::eDescriptionLevelFull:
299 case lldb::eDescriptionLevelVerbose:
300 if (offset > start_offset)
301 s->EOL();
302 s->Indent();
303 if (level == lldb::eDescriptionLevelFull)
304 break;
305 // Fall through for verbose and print offset and DW_OP prefix..
306 s->Printf("0x%8.8x: %s", op_offset, op >= DW_OP_APPLE_uninit ? "DW_OP_APPLE_" : "DW_OP_");
307 break;
308 }
309
310 switch (op)
311 {
Greg Clayton9b82f862011-07-11 05:12:02 +0000312 case DW_OP_addr: *s << "DW_OP_addr(" << m_data.GetAddress(&offset) << ") "; break; // 0x03 1 address
313 case DW_OP_deref: *s << "DW_OP_deref"; break; // 0x06
314 case DW_OP_const1u: s->Printf("DW_OP_const1u(0x%2.2x) ", m_data.GetU8(&offset)); break; // 0x08 1 1-byte constant
315 case DW_OP_const1s: s->Printf("DW_OP_const1s(0x%2.2x) ", m_data.GetU8(&offset)); break; // 0x09 1 1-byte constant
316 case DW_OP_const2u: s->Printf("DW_OP_const2u(0x%4.4x) ", m_data.GetU16(&offset)); break; // 0x0a 1 2-byte constant
317 case DW_OP_const2s: s->Printf("DW_OP_const2s(0x%4.4x) ", m_data.GetU16(&offset)); break; // 0x0b 1 2-byte constant
318 case DW_OP_const4u: s->Printf("DW_OP_const4u(0x%8.8x) ", m_data.GetU32(&offset)); break; // 0x0c 1 4-byte constant
319 case DW_OP_const4s: s->Printf("DW_OP_const4s(0x%8.8x) ", m_data.GetU32(&offset)); break; // 0x0d 1 4-byte constant
320 case DW_OP_const8u: s->Printf("DW_OP_const8u(0x%16.16llx) ", m_data.GetU64(&offset)); break; // 0x0e 1 8-byte constant
321 case DW_OP_const8s: s->Printf("DW_OP_const8s(0x%16.16llx) ", m_data.GetU64(&offset)); break; // 0x0f 1 8-byte constant
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000322 case DW_OP_constu: s->Printf("DW_OP_constu(0x%llx) ", m_data.GetULEB128(&offset)); break; // 0x10 1 ULEB128 constant
323 case DW_OP_consts: s->Printf("DW_OP_consts(0x%lld) ", m_data.GetSLEB128(&offset)); break; // 0x11 1 SLEB128 constant
Greg Clayton9b82f862011-07-11 05:12:02 +0000324 case DW_OP_dup: s->PutCString("DW_OP_dup"); break; // 0x12
325 case DW_OP_drop: s->PutCString("DW_OP_drop"); break; // 0x13
326 case DW_OP_over: s->PutCString("DW_OP_over"); break; // 0x14
327 case DW_OP_pick: s->Printf("DW_OP_pick(0x%2.2x) ", m_data.GetU8(&offset)); break; // 0x15 1 1-byte stack index
328 case DW_OP_swap: s->PutCString("DW_OP_swap"); break; // 0x16
329 case DW_OP_rot: s->PutCString("DW_OP_rot"); break; // 0x17
330 case DW_OP_xderef: s->PutCString("DW_OP_xderef"); break; // 0x18
331 case DW_OP_abs: s->PutCString("DW_OP_abs"); break; // 0x19
332 case DW_OP_and: s->PutCString("DW_OP_and"); break; // 0x1a
333 case DW_OP_div: s->PutCString("DW_OP_div"); break; // 0x1b
334 case DW_OP_minus: s->PutCString("DW_OP_minus"); break; // 0x1c
335 case DW_OP_mod: s->PutCString("DW_OP_mod"); break; // 0x1d
336 case DW_OP_mul: s->PutCString("DW_OP_mul"); break; // 0x1e
337 case DW_OP_neg: s->PutCString("DW_OP_neg"); break; // 0x1f
338 case DW_OP_not: s->PutCString("DW_OP_not"); break; // 0x20
339 case DW_OP_or: s->PutCString("DW_OP_or"); break; // 0x21
340 case DW_OP_plus: s->PutCString("DW_OP_plus"); break; // 0x22
Chris Lattner24943d22010-06-08 16:52:24 +0000341 case DW_OP_plus_uconst: // 0x23 1 ULEB128 addend
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000342 s->Printf("DW_OP_plus_uconst(0x%llx) ", m_data.GetULEB128(&offset));
Chris Lattner24943d22010-06-08 16:52:24 +0000343 break;
344
Greg Clayton9b82f862011-07-11 05:12:02 +0000345 case DW_OP_shl: s->PutCString("DW_OP_shl"); break; // 0x24
346 case DW_OP_shr: s->PutCString("DW_OP_shr"); break; // 0x25
347 case DW_OP_shra: s->PutCString("DW_OP_shra"); break; // 0x26
348 case DW_OP_xor: s->PutCString("DW_OP_xor"); break; // 0x27
349 case DW_OP_skip: s->Printf("DW_OP_skip(0x%4.4x)", m_data.GetU16(&offset)); break; // 0x2f 1 signed 2-byte constant
350 case DW_OP_bra: s->Printf("DW_OP_bra(0x%4.4x)", m_data.GetU16(&offset)); break; // 0x28 1 signed 2-byte constant
351 case DW_OP_eq: s->PutCString("DW_OP_eq"); break; // 0x29
352 case DW_OP_ge: s->PutCString("DW_OP_ge"); break; // 0x2a
353 case DW_OP_gt: s->PutCString("DW_OP_gt"); break; // 0x2b
354 case DW_OP_le: s->PutCString("DW_OP_le"); break; // 0x2c
355 case DW_OP_lt: s->PutCString("DW_OP_lt"); break; // 0x2d
356 case DW_OP_ne: s->PutCString("DW_OP_ne"); break; // 0x2e
Chris Lattner24943d22010-06-08 16:52:24 +0000357
358 case DW_OP_lit0: // 0x30
359 case DW_OP_lit1: // 0x31
360 case DW_OP_lit2: // 0x32
361 case DW_OP_lit3: // 0x33
362 case DW_OP_lit4: // 0x34
363 case DW_OP_lit5: // 0x35
364 case DW_OP_lit6: // 0x36
365 case DW_OP_lit7: // 0x37
366 case DW_OP_lit8: // 0x38
367 case DW_OP_lit9: // 0x39
368 case DW_OP_lit10: // 0x3A
369 case DW_OP_lit11: // 0x3B
370 case DW_OP_lit12: // 0x3C
371 case DW_OP_lit13: // 0x3D
372 case DW_OP_lit14: // 0x3E
373 case DW_OP_lit15: // 0x3F
374 case DW_OP_lit16: // 0x40
375 case DW_OP_lit17: // 0x41
376 case DW_OP_lit18: // 0x42
377 case DW_OP_lit19: // 0x43
378 case DW_OP_lit20: // 0x44
379 case DW_OP_lit21: // 0x45
380 case DW_OP_lit22: // 0x46
381 case DW_OP_lit23: // 0x47
382 case DW_OP_lit24: // 0x48
383 case DW_OP_lit25: // 0x49
384 case DW_OP_lit26: // 0x4A
385 case DW_OP_lit27: // 0x4B
386 case DW_OP_lit28: // 0x4C
387 case DW_OP_lit29: // 0x4D
388 case DW_OP_lit30: // 0x4E
Greg Clayton9b82f862011-07-11 05:12:02 +0000389 case DW_OP_lit31: s->Printf("DW_OP_lit%i", op - DW_OP_lit0); break; // 0x4f
Chris Lattner24943d22010-06-08 16:52:24 +0000390
391 case DW_OP_reg0: // 0x50
392 case DW_OP_reg1: // 0x51
393 case DW_OP_reg2: // 0x52
394 case DW_OP_reg3: // 0x53
395 case DW_OP_reg4: // 0x54
396 case DW_OP_reg5: // 0x55
397 case DW_OP_reg6: // 0x56
398 case DW_OP_reg7: // 0x57
399 case DW_OP_reg8: // 0x58
400 case DW_OP_reg9: // 0x59
401 case DW_OP_reg10: // 0x5A
402 case DW_OP_reg11: // 0x5B
403 case DW_OP_reg12: // 0x5C
404 case DW_OP_reg13: // 0x5D
405 case DW_OP_reg14: // 0x5E
406 case DW_OP_reg15: // 0x5F
407 case DW_OP_reg16: // 0x60
408 case DW_OP_reg17: // 0x61
409 case DW_OP_reg18: // 0x62
410 case DW_OP_reg19: // 0x63
411 case DW_OP_reg20: // 0x64
412 case DW_OP_reg21: // 0x65
413 case DW_OP_reg22: // 0x66
414 case DW_OP_reg23: // 0x67
415 case DW_OP_reg24: // 0x68
416 case DW_OP_reg25: // 0x69
417 case DW_OP_reg26: // 0x6A
418 case DW_OP_reg27: // 0x6B
419 case DW_OP_reg28: // 0x6C
420 case DW_OP_reg29: // 0x6D
421 case DW_OP_reg30: // 0x6E
Greg Clayton5c3861d2011-09-02 01:15:17 +0000422 case DW_OP_reg31: // 0x6F
423 {
424 uint32_t reg_num = op - DW_OP_reg0;
425 if (abi)
426 {
427 RegisterInfo reg_info;
428 if (abi->GetRegisterInfoByKind(m_reg_kind, reg_num, reg_info))
429 {
430 if (reg_info.name)
431 {
432 s->PutCString (reg_info.name);
433 break;
434 }
435 else if (reg_info.alt_name)
436 {
437 s->PutCString (reg_info.alt_name);
438 break;
439 }
440 }
441 }
442 s->Printf("DW_OP_reg%u", reg_num); break;
443 }
444 break;
Chris Lattner24943d22010-06-08 16:52:24 +0000445
446 case DW_OP_breg0:
447 case DW_OP_breg1:
448 case DW_OP_breg2:
449 case DW_OP_breg3:
450 case DW_OP_breg4:
451 case DW_OP_breg5:
452 case DW_OP_breg6:
453 case DW_OP_breg7:
454 case DW_OP_breg8:
455 case DW_OP_breg9:
456 case DW_OP_breg10:
457 case DW_OP_breg11:
458 case DW_OP_breg12:
459 case DW_OP_breg13:
460 case DW_OP_breg14:
461 case DW_OP_breg15:
462 case DW_OP_breg16:
463 case DW_OP_breg17:
464 case DW_OP_breg18:
465 case DW_OP_breg19:
466 case DW_OP_breg20:
467 case DW_OP_breg21:
468 case DW_OP_breg22:
469 case DW_OP_breg23:
470 case DW_OP_breg24:
471 case DW_OP_breg25:
472 case DW_OP_breg26:
473 case DW_OP_breg27:
474 case DW_OP_breg28:
475 case DW_OP_breg29:
476 case DW_OP_breg30:
Greg Clayton5c3861d2011-09-02 01:15:17 +0000477 case DW_OP_breg31:
478 {
479 uint32_t reg_num = op - DW_OP_breg0;
480 int64_t reg_offset = m_data.GetSLEB128(&offset);
481 if (abi)
482 {
483 RegisterInfo reg_info;
484 if (abi->GetRegisterInfoByKind(m_reg_kind, reg_num, reg_info))
485 {
486 if (reg_info.name)
487 {
488 s->Printf("[%s%+lli]", reg_info.name, reg_offset);
489 break;
490 }
491 else if (reg_info.alt_name)
492 {
493 s->Printf("[%s%+lli]", reg_info.alt_name, reg_offset);
494 break;
495 }
496 }
497 }
498 s->Printf("DW_OP_breg%i(0x%llx)", reg_num, reg_offset);
499 }
500 break;
Chris Lattner24943d22010-06-08 16:52:24 +0000501
502 case DW_OP_regx: // 0x90 1 ULEB128 register
Greg Clayton5c3861d2011-09-02 01:15:17 +0000503 {
504 uint64_t reg_num = m_data.GetULEB128(&offset);
505 if (abi)
506 {
507 RegisterInfo reg_info;
508 if (abi->GetRegisterInfoByKind(m_reg_kind, reg_num, reg_info))
509 {
510 if (reg_info.name)
511 {
512 s->PutCString (reg_info.name);
513 break;
514 }
515 else if (reg_info.alt_name)
516 {
517 s->PutCString (reg_info.alt_name);
518 break;
519 }
520 }
521 }
522 s->Printf("DW_OP_regx(%llu)", reg_num); break;
523 }
Chris Lattner24943d22010-06-08 16:52:24 +0000524 break;
525 case DW_OP_fbreg: // 0x91 1 SLEB128 offset
Greg Clayton5c3861d2011-09-02 01:15:17 +0000526 s->Printf("DW_OP_fbreg(%lli)",m_data.GetSLEB128(&offset));
Chris Lattner24943d22010-06-08 16:52:24 +0000527 break;
528 case DW_OP_bregx: // 0x92 2 ULEB128 register followed by SLEB128 offset
Greg Clayton5c3861d2011-09-02 01:15:17 +0000529 {
530 uint32_t reg_num = m_data.GetULEB128(&offset);
531 int64_t reg_offset = m_data.GetSLEB128(&offset);
532 if (abi)
533 {
534 RegisterInfo reg_info;
535 if (abi->GetRegisterInfoByKind(m_reg_kind, reg_num, reg_info))
536 {
537 if (reg_info.name)
538 {
539 s->Printf("[%s%+lli]", reg_info.name, reg_offset);
540 break;
541 }
542 else if (reg_info.alt_name)
543 {
544 s->Printf("[%s%+lli]", reg_info.alt_name, reg_offset);
545 break;
546 }
547 }
548 }
549 s->Printf("DW_OP_bregx(reg=%u,offset=%lli)", reg_num, reg_offset);
550 }
Chris Lattner24943d22010-06-08 16:52:24 +0000551 break;
552 case DW_OP_piece: // 0x93 1 ULEB128 size of piece addressed
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000553 s->Printf("DW_OP_piece(0x%llx)", m_data.GetULEB128(&offset));
Chris Lattner24943d22010-06-08 16:52:24 +0000554 break;
555 case DW_OP_deref_size: // 0x94 1 1-byte size of data retrieved
Greg Clayton9b82f862011-07-11 05:12:02 +0000556 s->Printf("DW_OP_deref_size(0x%2.2x)", m_data.GetU8(&offset));
Chris Lattner24943d22010-06-08 16:52:24 +0000557 break;
558 case DW_OP_xderef_size: // 0x95 1 1-byte size of data retrieved
Greg Clayton9b82f862011-07-11 05:12:02 +0000559 s->Printf("DW_OP_xderef_size(0x%2.2x)", m_data.GetU8(&offset));
Chris Lattner24943d22010-06-08 16:52:24 +0000560 break;
Greg Clayton9b82f862011-07-11 05:12:02 +0000561 case DW_OP_nop: s->PutCString("DW_OP_nop"); break; // 0x96
562 case DW_OP_push_object_address: s->PutCString("DW_OP_push_object_address"); break; // 0x97 DWARF3
Chris Lattner24943d22010-06-08 16:52:24 +0000563 case DW_OP_call2: // 0x98 DWARF3 1 2-byte offset of DIE
Greg Clayton9b82f862011-07-11 05:12:02 +0000564 s->Printf("DW_OP_call2(0x%4.4x)", m_data.GetU16(&offset));
Chris Lattner24943d22010-06-08 16:52:24 +0000565 break;
566 case DW_OP_call4: // 0x99 DWARF3 1 4-byte offset of DIE
Greg Clayton9b82f862011-07-11 05:12:02 +0000567 s->Printf("DW_OP_call4(0x%8.8x)", m_data.GetU32(&offset));
Chris Lattner24943d22010-06-08 16:52:24 +0000568 break;
569 case DW_OP_call_ref: // 0x9a DWARF3 1 4- or 8-byte offset of DIE
Greg Clayton9b82f862011-07-11 05:12:02 +0000570 s->Printf("DW_OP_call_ref(0x%8.8llx)", m_data.GetAddress(&offset));
Chris Lattner24943d22010-06-08 16:52:24 +0000571 break;
572// case DW_OP_form_tls_address: s << "form_tls_address"; break; // 0x9b DWARF3
573// case DW_OP_call_frame_cfa: s << "call_frame_cfa"; break; // 0x9c DWARF3
574// case DW_OP_bit_piece: // 0x9d DWARF3 2
Greg Clayton9b82f862011-07-11 05:12:02 +0000575// s->Printf("DW_OP_bit_piece(0x%x, 0x%x)", m_data.GetULEB128(&offset), m_data.GetULEB128(&offset));
Chris Lattner24943d22010-06-08 16:52:24 +0000576// break;
Greg Clayton9b82f862011-07-11 05:12:02 +0000577// case DW_OP_lo_user: s->PutCString("DW_OP_lo_user"); break; // 0xe0
578// case DW_OP_hi_user: s->PutCString("DW_OP_hi_user"); break; // 0xff
Greg Claytona1b9a902011-11-13 04:15:56 +0000579// case DW_OP_APPLE_extern:
580// s->Printf("DW_OP_APPLE_extern(%llu)", m_data.GetULEB128(&offset));
581// break;
582// case DW_OP_APPLE_array_ref:
583// s->PutCString("DW_OP_APPLE_array_ref");
584// break;
Chris Lattner24943d22010-06-08 16:52:24 +0000585 case DW_OP_APPLE_uninit:
Greg Clayton9b82f862011-07-11 05:12:02 +0000586 s->PutCString("DW_OP_APPLE_uninit"); // 0xF0
Chris Lattner24943d22010-06-08 16:52:24 +0000587 break;
Greg Claytona1b9a902011-11-13 04:15:56 +0000588// case DW_OP_APPLE_assign: // 0xF1 - pops value off and assigns it to second item on stack (2nd item must have assignable context)
589// s->PutCString("DW_OP_APPLE_assign");
590// break;
591// case DW_OP_APPLE_address_of: // 0xF2 - gets the address of the top stack item (top item must be a variable, or have value_type that is an address already)
592// s->PutCString("DW_OP_APPLE_address_of");
593// break;
594// case DW_OP_APPLE_value_of: // 0xF3 - pops the value off the stack and pushes the value of that object (top item must be a variable, or expression local)
595// s->PutCString("DW_OP_APPLE_value_of");
596// break;
597// case DW_OP_APPLE_deref_type: // 0xF4 - gets the address of the top stack item (top item must be a variable, or a clang type)
598// s->PutCString("DW_OP_APPLE_deref_type");
599// break;
600// case DW_OP_APPLE_expr_local: // 0xF5 - ULEB128 expression local index
601// s->Printf("DW_OP_APPLE_expr_local(%llu)", m_data.GetULEB128(&offset));
602// break;
603// case DW_OP_APPLE_constf: // 0xF6 - 1 byte float size, followed by constant float data
604// {
605// uint8_t float_length = m_data.GetU8(&offset);
606// s->Printf("DW_OP_APPLE_constf(<%u> ", float_length);
607// m_data.Dump(s, offset, eFormatHex, float_length, 1, UINT32_MAX, DW_INVALID_ADDRESS, 0, 0);
608// s->PutChar(')');
609// // Consume the float data
610// m_data.GetData(&offset, float_length);
611// }
612// break;
613// case DW_OP_APPLE_scalar_cast:
614// s->Printf("DW_OP_APPLE_scalar_cast(%s)", Scalar::GetValueTypeAsCString ((Scalar::Type)m_data.GetU8(&offset)));
615// break;
616// case DW_OP_APPLE_clang_cast:
617// {
618// clang::Type *clang_type = (clang::Type *)m_data.GetMaxU64(&offset, sizeof(void*));
619// s->Printf("DW_OP_APPLE_clang_cast(%p)", clang_type);
620// }
621// break;
622// case DW_OP_APPLE_clear:
623// s->PutCString("DW_OP_APPLE_clear");
624// break;
625// case DW_OP_APPLE_error: // 0xFF - Stops expression evaluation and returns an error (no args)
626// s->PutCString("DW_OP_APPLE_error");
627// break;
Chris Lattner24943d22010-06-08 16:52:24 +0000628 }
629 }
630}
631
632void
Greg Clayton178710c2010-09-14 02:20:48 +0000633DWARFExpression::SetLocationListSlide (addr_t slide)
Chris Lattner24943d22010-06-08 16:52:24 +0000634{
Greg Clayton178710c2010-09-14 02:20:48 +0000635 m_loclist_slide = slide;
Chris Lattner24943d22010-06-08 16:52:24 +0000636}
637
638int
639DWARFExpression::GetRegisterKind ()
640{
641 return m_reg_kind;
642}
643
644void
Greg Clayton5c3861d2011-09-02 01:15:17 +0000645DWARFExpression::SetRegisterKind (RegisterKind reg_kind)
Chris Lattner24943d22010-06-08 16:52:24 +0000646{
647 m_reg_kind = reg_kind;
648}
649
650bool
651DWARFExpression::IsLocationList() const
652{
Greg Clayton178710c2010-09-14 02:20:48 +0000653 return m_loclist_slide != LLDB_INVALID_ADDRESS;
Chris Lattner24943d22010-06-08 16:52:24 +0000654}
655
656void
Greg Clayton5c3861d2011-09-02 01:15:17 +0000657DWARFExpression::GetDescription (Stream *s, lldb::DescriptionLevel level, addr_t location_list_base_addr, ABI *abi) const
Chris Lattner24943d22010-06-08 16:52:24 +0000658{
659 if (IsLocationList())
660 {
661 // We have a location list
662 uint32_t offset = 0;
663 uint32_t count = 0;
Greg Clayton178710c2010-09-14 02:20:48 +0000664 addr_t curr_base_addr = location_list_base_addr;
Chris Lattner24943d22010-06-08 16:52:24 +0000665 while (m_data.ValidOffset(offset))
666 {
667 lldb::addr_t begin_addr_offset = m_data.GetAddress(&offset);
668 lldb::addr_t end_addr_offset = m_data.GetAddress(&offset);
669 if (begin_addr_offset < end_addr_offset)
670 {
671 if (count > 0)
672 s->PutCString(", ");
Greg Clayton178710c2010-09-14 02:20:48 +0000673 VMRange addr_range(curr_base_addr + begin_addr_offset, curr_base_addr + end_addr_offset);
674 addr_range.Dump(s, 0, 8);
Chris Lattner24943d22010-06-08 16:52:24 +0000675 s->PutChar('{');
676 uint32_t location_length = m_data.GetU16(&offset);
Greg Clayton5c3861d2011-09-02 01:15:17 +0000677 DumpLocation (s, offset, location_length, level, abi);
Chris Lattner24943d22010-06-08 16:52:24 +0000678 s->PutChar('}');
679 offset += location_length;
680 }
681 else if (begin_addr_offset == 0 && end_addr_offset == 0)
682 {
683 // The end of the location list is marked by both the start and end offset being zero
684 break;
685 }
686 else
687 {
Greg Claytonb3448432011-03-24 21:19:54 +0000688 if ((m_data.GetAddressByteSize() == 4 && (begin_addr_offset == UINT32_MAX)) ||
689 (m_data.GetAddressByteSize() == 8 && (begin_addr_offset == UINT64_MAX)))
Chris Lattner24943d22010-06-08 16:52:24 +0000690 {
Greg Clayton178710c2010-09-14 02:20:48 +0000691 curr_base_addr = end_addr_offset + location_list_base_addr;
Chris Lattner24943d22010-06-08 16:52:24 +0000692 // We have a new base address
693 if (count > 0)
694 s->PutCString(", ");
695 *s << "base_addr = " << end_addr_offset;
696 }
697 }
698
699 count++;
700 }
701 }
702 else
703 {
704 // We have a normal location that contains DW_OP location opcodes
Greg Clayton5c3861d2011-09-02 01:15:17 +0000705 DumpLocation (s, 0, m_data.GetByteSize(), level, abi);
Chris Lattner24943d22010-06-08 16:52:24 +0000706 }
707}
708
709static bool
710ReadRegisterValueAsScalar
711(
Greg Clayton061b79d2011-05-09 20:18:18 +0000712 RegisterContext *reg_ctx,
Chris Lattner24943d22010-06-08 16:52:24 +0000713 uint32_t reg_kind,
714 uint32_t reg_num,
715 Error *error_ptr,
716 Value &value
717)
718{
Greg Clayton061b79d2011-05-09 20:18:18 +0000719 if (reg_ctx == NULL)
Chris Lattner24943d22010-06-08 16:52:24 +0000720 {
Jason Molenda8e69de42010-11-20 01:28:30 +0000721 if (error_ptr)
722 error_ptr->SetErrorStringWithFormat("No register context in frame.\n");
Chris Lattner24943d22010-06-08 16:52:24 +0000723 }
724 else
725 {
Greg Clayton061b79d2011-05-09 20:18:18 +0000726 uint32_t native_reg = reg_ctx->ConvertRegisterKindToRegisterNumber(reg_kind, reg_num);
Jason Molenda8e69de42010-11-20 01:28:30 +0000727 if (native_reg == LLDB_INVALID_REGNUM)
728 {
729 if (error_ptr)
730 error_ptr->SetErrorStringWithFormat("Unable to convert register kind=%u reg_num=%u to a native register number.\n", reg_kind, reg_num);
731 }
732 else
733 {
Greg Clayton061b79d2011-05-09 20:18:18 +0000734 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex(native_reg);
735 RegisterValue reg_value;
736 if (reg_ctx->ReadRegister (reg_info, reg_value))
737 {
738 if (reg_value.GetScalarValue(value.GetScalar()))
739 {
740 value.SetValueType (Value::eValueTypeScalar);
Greg Clayton82f07462011-05-30 00:49:24 +0000741 value.SetContext (Value::eContextTypeRegisterInfo,
742 const_cast<RegisterInfo *>(reg_info));
Greg Clayton061b79d2011-05-09 20:18:18 +0000743 if (error_ptr)
744 error_ptr->Clear();
745 return true;
746 }
747 else
748 {
Greg Clayton82f07462011-05-30 00:49:24 +0000749 // If we get this error, then we need to implement a value
750 // buffer in the dwarf expression evaluation function...
Greg Clayton061b79d2011-05-09 20:18:18 +0000751 if (error_ptr)
Greg Clayton82f07462011-05-30 00:49:24 +0000752 error_ptr->SetErrorStringWithFormat ("register %s can't be converted to a scalar value",
753 reg_info->name);
Greg Clayton061b79d2011-05-09 20:18:18 +0000754 }
755 }
756 else
757 {
758 if (error_ptr)
Greg Clayton82f07462011-05-30 00:49:24 +0000759 error_ptr->SetErrorStringWithFormat("register %s is not available", reg_info->name);
Greg Clayton061b79d2011-05-09 20:18:18 +0000760 }
Jason Molenda8e69de42010-11-20 01:28:30 +0000761 }
Chris Lattner24943d22010-06-08 16:52:24 +0000762 }
763 return false;
764}
765
Greg Clayton178710c2010-09-14 02:20:48 +0000766//bool
767//DWARFExpression::LocationListContainsLoadAddress (Process* process, const Address &addr) const
768//{
769// return LocationListContainsLoadAddress(process, addr.GetLoadAddress(process));
770//}
771//
772//bool
773//DWARFExpression::LocationListContainsLoadAddress (Process* process, addr_t load_addr) const
774//{
775// if (load_addr == LLDB_INVALID_ADDRESS)
776// return false;
777//
778// if (IsLocationList())
779// {
780// uint32_t offset = 0;
781//
782// addr_t loc_list_base_addr = m_loclist_slide.GetLoadAddress(process);
783//
784// if (loc_list_base_addr == LLDB_INVALID_ADDRESS)
785// return false;
786//
787// while (m_data.ValidOffset(offset))
788// {
789// // We need to figure out what the value is for the location.
790// addr_t lo_pc = m_data.GetAddress(&offset);
791// addr_t hi_pc = m_data.GetAddress(&offset);
792// if (lo_pc == 0 && hi_pc == 0)
793// break;
794// else
795// {
796// lo_pc += loc_list_base_addr;
797// hi_pc += loc_list_base_addr;
798//
799// if (lo_pc <= load_addr && load_addr < hi_pc)
800// return true;
801//
802// offset += m_data.GetU16(&offset);
803// }
804// }
805// }
806// return false;
807//}
Greg Claytonb04e7a82010-08-24 21:05:24 +0000808
Greg Claytona1b9a902011-11-13 04:15:56 +0000809static uint32_t
810GetOpcodeDataSize (const DataExtractor &data, const uint32_t data_offset, const uint8_t op)
811{
812 uint32_t offset = data_offset;
813 switch (op)
814 {
815 case DW_OP_addr:
816 case DW_OP_call_ref: // 0x9a 1 address sized offset of DIE (DWARF3)
817 return data.GetAddressByteSize();
818
819 // Opcodes with no arguments
820 case DW_OP_deref: // 0x06
821 case DW_OP_dup: // 0x12
822 case DW_OP_drop: // 0x13
823 case DW_OP_over: // 0x14
824 case DW_OP_swap: // 0x16
825 case DW_OP_rot: // 0x17
826 case DW_OP_xderef: // 0x18
827 case DW_OP_abs: // 0x19
828 case DW_OP_and: // 0x1a
829 case DW_OP_div: // 0x1b
830 case DW_OP_minus: // 0x1c
831 case DW_OP_mod: // 0x1d
832 case DW_OP_mul: // 0x1e
833 case DW_OP_neg: // 0x1f
834 case DW_OP_not: // 0x20
835 case DW_OP_or: // 0x21
836 case DW_OP_plus: // 0x22
837 case DW_OP_shl: // 0x24
838 case DW_OP_shr: // 0x25
839 case DW_OP_shra: // 0x26
840 case DW_OP_xor: // 0x27
841 case DW_OP_eq: // 0x29
842 case DW_OP_ge: // 0x2a
843 case DW_OP_gt: // 0x2b
844 case DW_OP_le: // 0x2c
845 case DW_OP_lt: // 0x2d
846 case DW_OP_ne: // 0x2e
847 case DW_OP_lit0: // 0x30
848 case DW_OP_lit1: // 0x31
849 case DW_OP_lit2: // 0x32
850 case DW_OP_lit3: // 0x33
851 case DW_OP_lit4: // 0x34
852 case DW_OP_lit5: // 0x35
853 case DW_OP_lit6: // 0x36
854 case DW_OP_lit7: // 0x37
855 case DW_OP_lit8: // 0x38
856 case DW_OP_lit9: // 0x39
857 case DW_OP_lit10: // 0x3A
858 case DW_OP_lit11: // 0x3B
859 case DW_OP_lit12: // 0x3C
860 case DW_OP_lit13: // 0x3D
861 case DW_OP_lit14: // 0x3E
862 case DW_OP_lit15: // 0x3F
863 case DW_OP_lit16: // 0x40
864 case DW_OP_lit17: // 0x41
865 case DW_OP_lit18: // 0x42
866 case DW_OP_lit19: // 0x43
867 case DW_OP_lit20: // 0x44
868 case DW_OP_lit21: // 0x45
869 case DW_OP_lit22: // 0x46
870 case DW_OP_lit23: // 0x47
871 case DW_OP_lit24: // 0x48
872 case DW_OP_lit25: // 0x49
873 case DW_OP_lit26: // 0x4A
874 case DW_OP_lit27: // 0x4B
875 case DW_OP_lit28: // 0x4C
876 case DW_OP_lit29: // 0x4D
877 case DW_OP_lit30: // 0x4E
878 case DW_OP_lit31: // 0x4f
879 case DW_OP_reg0: // 0x50
880 case DW_OP_reg1: // 0x51
881 case DW_OP_reg2: // 0x52
882 case DW_OP_reg3: // 0x53
883 case DW_OP_reg4: // 0x54
884 case DW_OP_reg5: // 0x55
885 case DW_OP_reg6: // 0x56
886 case DW_OP_reg7: // 0x57
887 case DW_OP_reg8: // 0x58
888 case DW_OP_reg9: // 0x59
889 case DW_OP_reg10: // 0x5A
890 case DW_OP_reg11: // 0x5B
891 case DW_OP_reg12: // 0x5C
892 case DW_OP_reg13: // 0x5D
893 case DW_OP_reg14: // 0x5E
894 case DW_OP_reg15: // 0x5F
895 case DW_OP_reg16: // 0x60
896 case DW_OP_reg17: // 0x61
897 case DW_OP_reg18: // 0x62
898 case DW_OP_reg19: // 0x63
899 case DW_OP_reg20: // 0x64
900 case DW_OP_reg21: // 0x65
901 case DW_OP_reg22: // 0x66
902 case DW_OP_reg23: // 0x67
903 case DW_OP_reg24: // 0x68
904 case DW_OP_reg25: // 0x69
905 case DW_OP_reg26: // 0x6A
906 case DW_OP_reg27: // 0x6B
907 case DW_OP_reg28: // 0x6C
908 case DW_OP_reg29: // 0x6D
909 case DW_OP_reg30: // 0x6E
910 case DW_OP_reg31: // 0x6F
911 case DW_OP_nop: // 0x96
912 case DW_OP_push_object_address: // 0x97 DWARF3
913 case DW_OP_form_tls_address: // 0x9b DWARF3
914 case DW_OP_call_frame_cfa: // 0x9c DWARF3
Greg Claytonc6c37562011-12-01 04:06:15 +0000915 case DW_OP_stack_value: // 0x9f DWARF4
Greg Claytona1b9a902011-11-13 04:15:56 +0000916 return 0;
917
918 // Opcodes with a single 1 byte arguments
919 case DW_OP_const1u: // 0x08 1 1-byte constant
920 case DW_OP_const1s: // 0x09 1 1-byte constant
921 case DW_OP_pick: // 0x15 1 1-byte stack index
922 case DW_OP_deref_size: // 0x94 1 1-byte size of data retrieved
923 case DW_OP_xderef_size: // 0x95 1 1-byte size of data retrieved
924 return 1;
925
926 // Opcodes with a single 2 byte arguments
927 case DW_OP_const2u: // 0x0a 1 2-byte constant
928 case DW_OP_const2s: // 0x0b 1 2-byte constant
929 case DW_OP_skip: // 0x2f 1 signed 2-byte constant
930 case DW_OP_bra: // 0x28 1 signed 2-byte constant
931 case DW_OP_call2: // 0x98 1 2-byte offset of DIE (DWARF3)
932 return 2;
933
934 // Opcodes with a single 4 byte arguments
935 case DW_OP_const4u: // 0x0c 1 4-byte constant
936 case DW_OP_const4s: // 0x0d 1 4-byte constant
937 case DW_OP_call4: // 0x99 1 4-byte offset of DIE (DWARF3)
938 return 4;
939
940 // Opcodes with a single 8 byte arguments
941 case DW_OP_const8u: // 0x0e 1 8-byte constant
942 case DW_OP_const8s: // 0x0f 1 8-byte constant
943 return 8;
944
945 // All opcodes that have a single ULEB (signed or unsigned) argument
946 case DW_OP_constu: // 0x10 1 ULEB128 constant
947 case DW_OP_consts: // 0x11 1 SLEB128 constant
948 case DW_OP_plus_uconst: // 0x23 1 ULEB128 addend
949 case DW_OP_breg0: // 0x70 1 ULEB128 register
950 case DW_OP_breg1: // 0x71 1 ULEB128 register
951 case DW_OP_breg2: // 0x72 1 ULEB128 register
952 case DW_OP_breg3: // 0x73 1 ULEB128 register
953 case DW_OP_breg4: // 0x74 1 ULEB128 register
954 case DW_OP_breg5: // 0x75 1 ULEB128 register
955 case DW_OP_breg6: // 0x76 1 ULEB128 register
956 case DW_OP_breg7: // 0x77 1 ULEB128 register
957 case DW_OP_breg8: // 0x78 1 ULEB128 register
958 case DW_OP_breg9: // 0x79 1 ULEB128 register
959 case DW_OP_breg10: // 0x7a 1 ULEB128 register
960 case DW_OP_breg11: // 0x7b 1 ULEB128 register
961 case DW_OP_breg12: // 0x7c 1 ULEB128 register
962 case DW_OP_breg13: // 0x7d 1 ULEB128 register
963 case DW_OP_breg14: // 0x7e 1 ULEB128 register
964 case DW_OP_breg15: // 0x7f 1 ULEB128 register
965 case DW_OP_breg16: // 0x80 1 ULEB128 register
966 case DW_OP_breg17: // 0x81 1 ULEB128 register
967 case DW_OP_breg18: // 0x82 1 ULEB128 register
968 case DW_OP_breg19: // 0x83 1 ULEB128 register
969 case DW_OP_breg20: // 0x84 1 ULEB128 register
970 case DW_OP_breg21: // 0x85 1 ULEB128 register
971 case DW_OP_breg22: // 0x86 1 ULEB128 register
972 case DW_OP_breg23: // 0x87 1 ULEB128 register
973 case DW_OP_breg24: // 0x88 1 ULEB128 register
974 case DW_OP_breg25: // 0x89 1 ULEB128 register
975 case DW_OP_breg26: // 0x8a 1 ULEB128 register
976 case DW_OP_breg27: // 0x8b 1 ULEB128 register
977 case DW_OP_breg28: // 0x8c 1 ULEB128 register
978 case DW_OP_breg29: // 0x8d 1 ULEB128 register
979 case DW_OP_breg30: // 0x8e 1 ULEB128 register
980 case DW_OP_breg31: // 0x8f 1 ULEB128 register
981 case DW_OP_regx: // 0x90 1 ULEB128 register
982 case DW_OP_fbreg: // 0x91 1 SLEB128 offset
983 case DW_OP_piece: // 0x93 1 ULEB128 size of piece addressed
984 data.Skip_LEB128(&offset);
985 return offset - data_offset;
986
Greg Claytonc6c37562011-12-01 04:06:15 +0000987 // All opcodes that have a 2 ULEB (signed or unsigned) arguments
Greg Claytona1b9a902011-11-13 04:15:56 +0000988 case DW_OP_bregx: // 0x92 2 ULEB128 register followed by SLEB128 offset
989 case DW_OP_bit_piece: // 0x9d ULEB128 bit size, ULEB128 bit offset (DWARF3);
990 data.Skip_LEB128(&offset);
991 data.Skip_LEB128(&offset);
992 return offset - data_offset;
Greg Claytonc6c37562011-12-01 04:06:15 +0000993
994 case DW_OP_implicit_value: // 0x9e ULEB128 size followed by block of that size (DWARF4)
995 {
996 uint64_t block_len = data.Skip_LEB128(&offset);
997 offset += block_len;
998 return offset - data_offset;
999 }
1000
Greg Claytona1b9a902011-11-13 04:15:56 +00001001 default:
Greg Clayton2f28ece2012-01-04 22:56:43 +00001002 break;
Greg Claytona1b9a902011-11-13 04:15:56 +00001003 }
1004 return UINT32_MAX;
1005}
1006
1007bool
Greg Clayton2f28ece2012-01-04 22:56:43 +00001008DWARFExpression::LocationContains_DW_OP_addr (lldb::addr_t file_addr, bool &error) const
Greg Claytona1b9a902011-11-13 04:15:56 +00001009{
Greg Clayton2f28ece2012-01-04 22:56:43 +00001010 error = false;
Greg Claytona1b9a902011-11-13 04:15:56 +00001011 if (IsLocationList())
1012 return false;
1013 uint32_t offset = 0;
1014 while (m_data.ValidOffset(offset))
1015 {
1016 const uint8_t op = m_data.GetU8(&offset);
1017
1018 if (op == DW_OP_addr)
1019 {
1020 if (file_addr == LLDB_INVALID_ADDRESS)
1021 return true;
1022 addr_t op_file_addr = m_data.GetAddress(&offset);
1023 if (op_file_addr == file_addr)
1024 return true;
1025 }
1026 else
1027 {
1028 const uint32_t op_arg_size = GetOpcodeDataSize (m_data, offset, op);
1029 if (op_arg_size == UINT32_MAX)
Greg Clayton2f28ece2012-01-04 22:56:43 +00001030 {
1031 error = true;
Greg Claytona1b9a902011-11-13 04:15:56 +00001032 break;
Greg Clayton2f28ece2012-01-04 22:56:43 +00001033 }
Greg Claytona1b9a902011-11-13 04:15:56 +00001034 offset += op_arg_size;
1035 }
1036 }
1037 return false;
1038}
1039
1040bool
1041DWARFExpression::Update_DW_OP_addr (lldb::addr_t file_addr)
1042{
1043 if (IsLocationList())
1044 return false;
1045 uint32_t offset = 0;
1046 while (m_data.ValidOffset(offset))
1047 {
1048 const uint8_t op = m_data.GetU8(&offset);
1049
1050 if (op == DW_OP_addr)
1051 {
1052 const uint8_t addr_byte_size = m_data.GetAddressByteSize();
1053 // We have to make a copy of the data as we don't know if this
1054 // data is from a read only memory mapped buffer, so we duplicate
1055 // all of the data first, then modify it, and if all goes well,
1056 // we then replace the data for this expression
1057
1058 // So first we copy the data into a heap buffer
1059 std::auto_ptr<DataBufferHeap> head_data_ap (new DataBufferHeap (m_data.GetDataStart(),
1060 m_data.GetByteSize()));
1061
1062 // Make en encoder so we can write the address into the buffer using
1063 // the correct byte order (endianness)
1064 DataEncoder encoder (head_data_ap->GetBytes(),
1065 head_data_ap->GetByteSize(),
1066 m_data.GetByteOrder(),
1067 addr_byte_size);
1068
1069 // Replace the address in the new buffer
1070 if (encoder.PutMaxU64 (offset, addr_byte_size, file_addr) == UINT32_MAX)
1071 return false;
1072
1073 // All went well, so now we can reset the data using a shared
1074 // pointer to the heap data so "m_data" will now correctly
1075 // manage the heap data.
1076 m_data.SetData (DataBufferSP (head_data_ap.release()));
1077 return true;
1078 }
1079 else
1080 {
1081 const uint32_t op_arg_size = GetOpcodeDataSize (m_data, offset, op);
1082 if (op_arg_size == UINT32_MAX)
1083 break;
1084 offset += op_arg_size;
1085 }
1086 }
1087 return false;
1088}
1089
Greg Claytonb04e7a82010-08-24 21:05:24 +00001090bool
Greg Clayton178710c2010-09-14 02:20:48 +00001091DWARFExpression::LocationListContainsAddress (lldb::addr_t loclist_base_addr, lldb::addr_t addr) const
Greg Claytonb04e7a82010-08-24 21:05:24 +00001092{
Greg Clayton178710c2010-09-14 02:20:48 +00001093 if (addr == LLDB_INVALID_ADDRESS)
Greg Claytonb04e7a82010-08-24 21:05:24 +00001094 return false;
1095
Chris Lattner24943d22010-06-08 16:52:24 +00001096 if (IsLocationList())
1097 {
1098 uint32_t offset = 0;
Chris Lattner24943d22010-06-08 16:52:24 +00001099
Greg Clayton178710c2010-09-14 02:20:48 +00001100 if (loclist_base_addr == LLDB_INVALID_ADDRESS)
Chris Lattner24943d22010-06-08 16:52:24 +00001101 return false;
1102
1103 while (m_data.ValidOffset(offset))
1104 {
1105 // We need to figure out what the value is for the location.
1106 addr_t lo_pc = m_data.GetAddress(&offset);
1107 addr_t hi_pc = m_data.GetAddress(&offset);
1108 if (lo_pc == 0 && hi_pc == 0)
1109 break;
1110 else
1111 {
Greg Clayton178710c2010-09-14 02:20:48 +00001112 lo_pc += loclist_base_addr - m_loclist_slide;
1113 hi_pc += loclist_base_addr - m_loclist_slide;
Chris Lattner24943d22010-06-08 16:52:24 +00001114
Greg Clayton178710c2010-09-14 02:20:48 +00001115 if (lo_pc <= addr && addr < hi_pc)
Chris Lattner24943d22010-06-08 16:52:24 +00001116 return true;
1117
1118 offset += m_data.GetU16(&offset);
1119 }
1120 }
1121 }
1122 return false;
1123}
Greg Claytonb04e7a82010-08-24 21:05:24 +00001124
Chris Lattner24943d22010-06-08 16:52:24 +00001125bool
Greg Clayton9b82f862011-07-11 05:12:02 +00001126DWARFExpression::GetLocation (addr_t base_addr, addr_t pc, uint32_t &offset, uint32_t &length)
1127{
1128 offset = 0;
1129 if (!IsLocationList())
1130 {
1131 length = m_data.GetByteSize();
1132 return true;
1133 }
1134
1135 if (base_addr != LLDB_INVALID_ADDRESS && pc != LLDB_INVALID_ADDRESS)
1136 {
1137 addr_t curr_base_addr = base_addr;
1138
1139 while (m_data.ValidOffset(offset))
1140 {
1141 // We need to figure out what the value is for the location.
1142 addr_t lo_pc = m_data.GetAddress(&offset);
1143 addr_t hi_pc = m_data.GetAddress(&offset);
1144 if (lo_pc == 0 && hi_pc == 0)
1145 {
1146 break;
1147 }
1148 else
1149 {
1150 lo_pc += curr_base_addr - m_loclist_slide;
1151 hi_pc += curr_base_addr - m_loclist_slide;
1152
1153 length = m_data.GetU16(&offset);
1154
1155 if (length > 0 && lo_pc <= pc && pc < hi_pc)
1156 return true;
1157
1158 offset += length;
1159 }
1160 }
1161 }
1162 offset = UINT32_MAX;
1163 length = 0;
1164 return false;
1165}
1166
1167bool
1168DWARFExpression::DumpLocationForAddress (Stream *s,
1169 lldb::DescriptionLevel level,
1170 addr_t base_addr,
Greg Clayton5c3861d2011-09-02 01:15:17 +00001171 addr_t address,
1172 ABI *abi)
Greg Clayton9b82f862011-07-11 05:12:02 +00001173{
1174 uint32_t offset = 0;
1175 uint32_t length = 0;
1176
1177 if (GetLocation (base_addr, address, offset, length))
1178 {
1179 if (length > 0)
1180 {
Greg Clayton5c3861d2011-09-02 01:15:17 +00001181 DumpLocation(s, offset, length, level, abi);
Greg Clayton9b82f862011-07-11 05:12:02 +00001182 return true;
1183 }
1184 }
1185 return false;
1186}
1187
1188bool
Chris Lattner24943d22010-06-08 16:52:24 +00001189DWARFExpression::Evaluate
1190(
1191 ExecutionContextScope *exe_scope,
1192 clang::ASTContext *ast_context,
Greg Claytonbdcb6ab2011-01-25 23:55:37 +00001193 ClangExpressionVariableList *expr_locals,
1194 ClangExpressionDeclMap *decl_map,
Greg Clayton178710c2010-09-14 02:20:48 +00001195 lldb::addr_t loclist_base_load_addr,
Chris Lattner24943d22010-06-08 16:52:24 +00001196 const Value* initial_value_ptr,
1197 Value& result,
1198 Error *error_ptr
1199) const
1200{
1201 ExecutionContext exe_ctx (exe_scope);
Greg Claytonbdcb6ab2011-01-25 23:55:37 +00001202 return Evaluate(&exe_ctx, ast_context, expr_locals, decl_map, NULL, loclist_base_load_addr, initial_value_ptr, result, error_ptr);
Chris Lattner24943d22010-06-08 16:52:24 +00001203}
1204
1205bool
1206DWARFExpression::Evaluate
1207(
1208 ExecutionContext *exe_ctx,
1209 clang::ASTContext *ast_context,
Greg Claytonbdcb6ab2011-01-25 23:55:37 +00001210 ClangExpressionVariableList *expr_locals,
1211 ClangExpressionDeclMap *decl_map,
Jason Molenda8e69de42010-11-20 01:28:30 +00001212 RegisterContext *reg_ctx,
Greg Clayton178710c2010-09-14 02:20:48 +00001213 lldb::addr_t loclist_base_load_addr,
Chris Lattner24943d22010-06-08 16:52:24 +00001214 const Value* initial_value_ptr,
1215 Value& result,
1216 Error *error_ptr
1217) const
1218{
1219 if (IsLocationList())
1220 {
1221 uint32_t offset = 0;
Jason Molenda8e69de42010-11-20 01:28:30 +00001222 addr_t pc;
Greg Clayton567e7f32011-09-22 04:58:26 +00001223 StackFrame *frame = NULL;
Jason Molenda8e69de42010-11-20 01:28:30 +00001224 if (reg_ctx)
1225 pc = reg_ctx->GetPC();
1226 else
Greg Clayton567e7f32011-09-22 04:58:26 +00001227 {
1228 frame = exe_ctx->GetFramePtr();
Sean Callanan86106812012-03-10 03:03:46 +00001229 if (!frame)
1230 return false;
1231 RegisterContextSP reg_ctx_sp = frame->GetRegisterContext();
1232 if (!reg_ctx_sp)
1233 return false;
1234 pc = reg_ctx_sp->GetPC();
Greg Clayton567e7f32011-09-22 04:58:26 +00001235 }
Chris Lattner24943d22010-06-08 16:52:24 +00001236
Greg Clayton178710c2010-09-14 02:20:48 +00001237 if (loclist_base_load_addr != LLDB_INVALID_ADDRESS)
Chris Lattner24943d22010-06-08 16:52:24 +00001238 {
Greg Clayton178710c2010-09-14 02:20:48 +00001239 if (pc == LLDB_INVALID_ADDRESS)
Chris Lattner24943d22010-06-08 16:52:24 +00001240 {
Greg Clayton178710c2010-09-14 02:20:48 +00001241 if (error_ptr)
1242 error_ptr->SetErrorString("Invalid PC in frame.");
1243 return false;
Chris Lattner24943d22010-06-08 16:52:24 +00001244 }
Greg Clayton178710c2010-09-14 02:20:48 +00001245
1246 addr_t curr_loclist_base_load_addr = loclist_base_load_addr;
1247
1248 while (m_data.ValidOffset(offset))
Chris Lattner24943d22010-06-08 16:52:24 +00001249 {
Greg Clayton178710c2010-09-14 02:20:48 +00001250 // We need to figure out what the value is for the location.
1251 addr_t lo_pc = m_data.GetAddress(&offset);
1252 addr_t hi_pc = m_data.GetAddress(&offset);
1253 if (lo_pc == 0 && hi_pc == 0)
Chris Lattner24943d22010-06-08 16:52:24 +00001254 {
Greg Clayton178710c2010-09-14 02:20:48 +00001255 break;
Chris Lattner24943d22010-06-08 16:52:24 +00001256 }
Greg Clayton178710c2010-09-14 02:20:48 +00001257 else
1258 {
1259 lo_pc += curr_loclist_base_load_addr - m_loclist_slide;
1260 hi_pc += curr_loclist_base_load_addr - m_loclist_slide;
1261
1262 uint16_t length = m_data.GetU16(&offset);
1263
1264 if (length > 0 && lo_pc <= pc && pc < hi_pc)
1265 {
Greg Claytonbdcb6ab2011-01-25 23:55:37 +00001266 return DWARFExpression::Evaluate (exe_ctx, ast_context, expr_locals, decl_map, reg_ctx, m_data, offset, length, m_reg_kind, initial_value_ptr, result, error_ptr);
Greg Clayton178710c2010-09-14 02:20:48 +00001267 }
1268 offset += length;
1269 }
Chris Lattner24943d22010-06-08 16:52:24 +00001270 }
1271 }
1272 if (error_ptr)
Greg Clayton82f07462011-05-30 00:49:24 +00001273 error_ptr->SetErrorString ("variable not available");
Chris Lattner24943d22010-06-08 16:52:24 +00001274 return false;
1275 }
1276
1277 // Not a location list, just a single expression.
Greg Claytonbdcb6ab2011-01-25 23:55:37 +00001278 return DWARFExpression::Evaluate (exe_ctx, ast_context, expr_locals, decl_map, reg_ctx, m_data, 0, m_data.GetByteSize(), m_reg_kind, initial_value_ptr, result, error_ptr);
Chris Lattner24943d22010-06-08 16:52:24 +00001279}
1280
1281
1282
1283bool
1284DWARFExpression::Evaluate
1285(
1286 ExecutionContext *exe_ctx,
1287 clang::ASTContext *ast_context,
Chris Lattner24943d22010-06-08 16:52:24 +00001288 ClangExpressionVariableList *expr_locals,
1289 ClangExpressionDeclMap *decl_map,
Jason Molenda8e69de42010-11-20 01:28:30 +00001290 RegisterContext *reg_ctx,
Greg Claytonbdcb6ab2011-01-25 23:55:37 +00001291 const DataExtractor& opcodes,
Chris Lattner24943d22010-06-08 16:52:24 +00001292 const uint32_t opcodes_offset,
1293 const uint32_t opcodes_length,
1294 const uint32_t reg_kind,
1295 const Value* initial_value_ptr,
1296 Value& result,
1297 Error *error_ptr
1298)
1299{
1300 std::vector<Value> stack;
1301
Greg Clayton567e7f32011-09-22 04:58:26 +00001302 Process *process = NULL;
1303 StackFrame *frame = NULL;
1304
1305 if (exe_ctx)
1306 {
1307 process = exe_ctx->GetProcessPtr();
1308 frame = exe_ctx->GetFramePtr();
1309 }
1310 if (reg_ctx == NULL && frame)
1311 reg_ctx = frame->GetRegisterContext().get();
Jason Molenda8e69de42010-11-20 01:28:30 +00001312
Chris Lattner24943d22010-06-08 16:52:24 +00001313 if (initial_value_ptr)
1314 stack.push_back(*initial_value_ptr);
1315
1316 uint32_t offset = opcodes_offset;
1317 const uint32_t end_offset = opcodes_offset + opcodes_length;
1318 Value tmp;
1319 uint32_t reg_num;
1320
1321 // Make sure all of the data is available in opcodes.
1322 if (!opcodes.ValidOffsetForDataOfSize(opcodes_offset, opcodes_length))
1323 {
1324 if (error_ptr)
1325 error_ptr->SetErrorString ("Invalid offset and/or length for opcodes buffer.");
1326 return false;
1327 }
Greg Claytone005f2c2010-11-06 01:53:30 +00001328 LogSP log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
Chris Lattner24943d22010-06-08 16:52:24 +00001329
1330
1331 while (opcodes.ValidOffset(offset) && offset < end_offset)
1332 {
1333 const uint32_t op_offset = offset;
1334 const uint8_t op = opcodes.GetU8(&offset);
1335
Sean Callanan67bbb112011-10-14 20:34:21 +00001336 if (log && log->GetVerbose())
Chris Lattner24943d22010-06-08 16:52:24 +00001337 {
Chris Lattner24943d22010-06-08 16:52:24 +00001338 size_t count = stack.size();
Jason Molenda7e5fa7f2011-09-20 21:44:10 +00001339 log->Printf("Stack before operation has %lu values:", count);
Chris Lattner24943d22010-06-08 16:52:24 +00001340 for (size_t i=0; i<count; ++i)
1341 {
1342 StreamString new_value;
1343 new_value.Printf("[%zu]", i);
1344 stack[i].Dump(&new_value);
Sean Callanan6184dfe2010-06-23 00:47:48 +00001345 log->Printf(" %s", new_value.GetData());
Chris Lattner24943d22010-06-08 16:52:24 +00001346 }
1347 log->Printf("0x%8.8x: %s", op_offset, DW_OP_value_to_name(op));
1348 }
1349 switch (op)
1350 {
1351 //----------------------------------------------------------------------
1352 // The DW_OP_addr operation has a single operand that encodes a machine
1353 // address and whose size is the size of an address on the target machine.
1354 //----------------------------------------------------------------------
1355 case DW_OP_addr:
Greg Clayton801417e2011-07-07 01:59:51 +00001356 stack.push_back(Scalar(opcodes.GetAddress(&offset)));
Chris Lattner24943d22010-06-08 16:52:24 +00001357 stack.back().SetValueType (Value::eValueTypeFileAddress);
1358 break;
1359
1360 //----------------------------------------------------------------------
1361 // The DW_OP_addr_sect_offset4 is used for any location expressions in
1362 // shared libraries that have a location like:
1363 // DW_OP_addr(0x1000)
1364 // If this address resides in a shared library, then this virtual
1365 // address won't make sense when it is evaluated in the context of a
1366 // running process where shared libraries have been slid. To account for
1367 // this, this new address type where we can store the section pointer
1368 // and a 4 byte offset.
1369 //----------------------------------------------------------------------
1370// case DW_OP_addr_sect_offset4:
1371// {
1372// result_type = eResultTypeFileAddress;
1373// lldb::Section *sect = (lldb::Section *)opcodes.GetMaxU64(&offset, sizeof(void *));
1374// lldb::addr_t sect_offset = opcodes.GetU32(&offset);
1375//
1376// Address so_addr (sect, sect_offset);
1377// lldb::addr_t load_addr = so_addr.GetLoadAddress();
1378// if (load_addr != LLDB_INVALID_ADDRESS)
1379// {
1380// // We successfully resolve a file address to a load
1381// // address.
1382// stack.push_back(load_addr);
1383// break;
1384// }
1385// else
1386// {
1387// // We were able
1388// if (error_ptr)
1389// error_ptr->SetErrorStringWithFormat ("Section %s in %s is not currently loaded.\n", sect->GetName().AsCString(), sect->GetModule()->GetFileSpec().GetFilename().AsCString());
1390// return false;
1391// }
1392// }
1393// break;
1394
1395 //----------------------------------------------------------------------
1396 // OPCODE: DW_OP_deref
1397 // OPERANDS: none
1398 // DESCRIPTION: Pops the top stack entry and treats it as an address.
1399 // The value retrieved from that address is pushed. The size of the
1400 // data retrieved from the dereferenced address is the size of an
1401 // address on the target machine.
1402 //----------------------------------------------------------------------
1403 case DW_OP_deref:
1404 {
1405 Value::ValueType value_type = stack.back().GetValueType();
1406 switch (value_type)
1407 {
1408 case Value::eValueTypeHostAddress:
1409 {
1410 void *src = (void *)stack.back().GetScalar().ULongLong();
1411 intptr_t ptr;
1412 ::memcpy (&ptr, src, sizeof(void *));
1413 stack.back().GetScalar() = ptr;
1414 stack.back().ClearContext();
1415 }
1416 break;
1417 case Value::eValueTypeLoadAddress:
1418 if (exe_ctx)
1419 {
Greg Clayton567e7f32011-09-22 04:58:26 +00001420 if (process)
Chris Lattner24943d22010-06-08 16:52:24 +00001421 {
1422 lldb::addr_t pointer_addr = stack.back().GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1423 uint8_t addr_bytes[sizeof(lldb::addr_t)];
Greg Clayton567e7f32011-09-22 04:58:26 +00001424 uint32_t addr_size = process->GetAddressByteSize();
Chris Lattner24943d22010-06-08 16:52:24 +00001425 Error error;
Greg Clayton567e7f32011-09-22 04:58:26 +00001426 if (process->ReadMemory(pointer_addr, &addr_bytes, addr_size, error) == addr_size)
Chris Lattner24943d22010-06-08 16:52:24 +00001427 {
Greg Clayton567e7f32011-09-22 04:58:26 +00001428 DataExtractor addr_data(addr_bytes, sizeof(addr_bytes), process->GetByteOrder(), addr_size);
Chris Lattner24943d22010-06-08 16:52:24 +00001429 uint32_t addr_data_offset = 0;
1430 stack.back().GetScalar() = addr_data.GetPointer(&addr_data_offset);
1431 stack.back().ClearContext();
1432 }
1433 else
1434 {
1435 if (error_ptr)
1436 error_ptr->SetErrorStringWithFormat ("Failed to dereference pointer from 0x%llx for DW_OP_deref: %s\n",
1437 pointer_addr,
1438 error.AsCString());
1439 return false;
1440 }
1441 }
1442 else
1443 {
1444 if (error_ptr)
1445 error_ptr->SetErrorStringWithFormat ("NULL process for DW_OP_deref.\n");
1446 return false;
1447 }
1448 }
1449 else
1450 {
1451 if (error_ptr)
1452 error_ptr->SetErrorStringWithFormat ("NULL execution context for DW_OP_deref.\n");
1453 return false;
1454 }
1455 break;
1456
1457 default:
1458 break;
1459 }
1460
1461 }
1462 break;
1463
1464 //----------------------------------------------------------------------
1465 // OPCODE: DW_OP_deref_size
1466 // OPERANDS: 1
1467 // 1 - uint8_t that specifies the size of the data to dereference.
1468 // DESCRIPTION: Behaves like the DW_OP_deref operation: it pops the top
1469 // stack entry and treats it as an address. The value retrieved from that
1470 // address is pushed. In the DW_OP_deref_size operation, however, the
1471 // size in bytes of the data retrieved from the dereferenced address is
1472 // specified by the single operand. This operand is a 1-byte unsigned
1473 // integral constant whose value may not be larger than the size of an
1474 // address on the target machine. The data retrieved is zero extended
1475 // to the size of an address on the target machine before being pushed
1476 // on the expression stack.
1477 //----------------------------------------------------------------------
1478 case DW_OP_deref_size:
Jason Molenda8e69de42010-11-20 01:28:30 +00001479 {
1480 uint8_t size = opcodes.GetU8(&offset);
1481 Value::ValueType value_type = stack.back().GetValueType();
1482 switch (value_type)
1483 {
1484 case Value::eValueTypeHostAddress:
1485 {
1486 void *src = (void *)stack.back().GetScalar().ULongLong();
1487 intptr_t ptr;
1488 ::memcpy (&ptr, src, sizeof(void *));
1489 // I can't decide whether the size operand should apply to the bytes in their
1490 // lldb-host endianness or the target endianness.. I doubt this'll ever come up
1491 // but I'll opt for assuming big endian regardless.
1492 switch (size)
1493 {
1494 case 1: ptr = ptr & 0xff; break;
1495 case 2: ptr = ptr & 0xffff; break;
1496 case 3: ptr = ptr & 0xffffff; break;
1497 case 4: ptr = ptr & 0xffffffff; break;
Jason Molendaa99bcaa2010-11-29 21:38:58 +00001498 // the casts are added to work around the case where intptr_t is a 32 bit quantity;
1499 // presumably we won't hit the 5..7 cases if (void*) is 32-bits in this program.
1500 case 5: ptr = (intptr_t) ptr & 0xffffffffffULL; break;
1501 case 6: ptr = (intptr_t) ptr & 0xffffffffffffULL; break;
1502 case 7: ptr = (intptr_t) ptr & 0xffffffffffffffULL; break;
Jason Molenda8e69de42010-11-20 01:28:30 +00001503 default: break;
1504 }
1505 stack.back().GetScalar() = ptr;
1506 stack.back().ClearContext();
1507 }
1508 break;
1509 case Value::eValueTypeLoadAddress:
1510 if (exe_ctx)
1511 {
Greg Clayton567e7f32011-09-22 04:58:26 +00001512 if (process)
Jason Molenda8e69de42010-11-20 01:28:30 +00001513 {
1514 lldb::addr_t pointer_addr = stack.back().GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1515 uint8_t addr_bytes[sizeof(lldb::addr_t)];
1516 Error error;
Greg Clayton567e7f32011-09-22 04:58:26 +00001517 if (process->ReadMemory(pointer_addr, &addr_bytes, size, error) == size)
Jason Molenda8e69de42010-11-20 01:28:30 +00001518 {
Greg Clayton567e7f32011-09-22 04:58:26 +00001519 DataExtractor addr_data(addr_bytes, sizeof(addr_bytes), process->GetByteOrder(), size);
Jason Molenda8e69de42010-11-20 01:28:30 +00001520 uint32_t addr_data_offset = 0;
1521 switch (size)
1522 {
1523 case 1: stack.back().GetScalar() = addr_data.GetU8(&addr_data_offset); break;
1524 case 2: stack.back().GetScalar() = addr_data.GetU16(&addr_data_offset); break;
1525 case 4: stack.back().GetScalar() = addr_data.GetU32(&addr_data_offset); break;
1526 case 8: stack.back().GetScalar() = addr_data.GetU64(&addr_data_offset); break;
1527 default: stack.back().GetScalar() = addr_data.GetPointer(&addr_data_offset);
1528 }
1529 stack.back().ClearContext();
1530 }
1531 else
1532 {
1533 if (error_ptr)
1534 error_ptr->SetErrorStringWithFormat ("Failed to dereference pointer from 0x%llx for DW_OP_deref: %s\n",
1535 pointer_addr,
1536 error.AsCString());
1537 return false;
1538 }
1539 }
1540 else
1541 {
1542 if (error_ptr)
1543 error_ptr->SetErrorStringWithFormat ("NULL process for DW_OP_deref.\n");
1544 return false;
1545 }
1546 }
1547 else
1548 {
1549 if (error_ptr)
1550 error_ptr->SetErrorStringWithFormat ("NULL execution context for DW_OP_deref.\n");
1551 return false;
1552 }
1553 break;
1554
1555 default:
1556 break;
1557 }
1558
1559 }
1560 break;
Chris Lattner24943d22010-06-08 16:52:24 +00001561
1562 //----------------------------------------------------------------------
1563 // OPCODE: DW_OP_xderef_size
1564 // OPERANDS: 1
1565 // 1 - uint8_t that specifies the size of the data to dereference.
1566 // DESCRIPTION: Behaves like the DW_OP_xderef operation: the entry at
1567 // the top of the stack is treated as an address. The second stack
Greg Clayton33ed1702010-08-24 00:45:41 +00001568 // entry is treated as an "address space identifier" for those
Chris Lattner24943d22010-06-08 16:52:24 +00001569 // architectures that support multiple address spaces. The top two
1570 // stack elements are popped, a data item is retrieved through an
1571 // implementation-defined address calculation and pushed as the new
1572 // stack top. In the DW_OP_xderef_size operation, however, the size in
1573 // bytes of the data retrieved from the dereferenced address is
1574 // specified by the single operand. This operand is a 1-byte unsigned
1575 // integral constant whose value may not be larger than the size of an
1576 // address on the target machine. The data retrieved is zero extended
1577 // to the size of an address on the target machine before being pushed
1578 // on the expression stack.
1579 //----------------------------------------------------------------------
1580 case DW_OP_xderef_size:
1581 if (error_ptr)
1582 error_ptr->SetErrorString("Unimplemented opcode: DW_OP_xderef_size.");
1583 return false;
1584 //----------------------------------------------------------------------
1585 // OPCODE: DW_OP_xderef
1586 // OPERANDS: none
1587 // DESCRIPTION: Provides an extended dereference mechanism. The entry at
1588 // the top of the stack is treated as an address. The second stack entry
1589 // is treated as an "address space identifier" for those architectures
1590 // that support multiple address spaces. The top two stack elements are
1591 // popped, a data item is retrieved through an implementation-defined
1592 // address calculation and pushed as the new stack top. The size of the
1593 // data retrieved from the dereferenced address is the size of an address
1594 // on the target machine.
1595 //----------------------------------------------------------------------
1596 case DW_OP_xderef:
1597 if (error_ptr)
1598 error_ptr->SetErrorString("Unimplemented opcode: DW_OP_xderef.");
1599 return false;
1600
1601 //----------------------------------------------------------------------
1602 // All DW_OP_constXXX opcodes have a single operand as noted below:
1603 //
1604 // Opcode Operand 1
1605 // --------------- ----------------------------------------------------
1606 // DW_OP_const1u 1-byte unsigned integer constant
1607 // DW_OP_const1s 1-byte signed integer constant
1608 // DW_OP_const2u 2-byte unsigned integer constant
1609 // DW_OP_const2s 2-byte signed integer constant
1610 // DW_OP_const4u 4-byte unsigned integer constant
1611 // DW_OP_const4s 4-byte signed integer constant
1612 // DW_OP_const8u 8-byte unsigned integer constant
1613 // DW_OP_const8s 8-byte signed integer constant
1614 // DW_OP_constu unsigned LEB128 integer constant
1615 // DW_OP_consts signed LEB128 integer constant
1616 //----------------------------------------------------------------------
Greg Clayton801417e2011-07-07 01:59:51 +00001617 case DW_OP_const1u : stack.push_back(Scalar(( uint8_t)opcodes.GetU8 (&offset))); break;
1618 case DW_OP_const1s : stack.push_back(Scalar(( int8_t)opcodes.GetU8 (&offset))); break;
1619 case DW_OP_const2u : stack.push_back(Scalar((uint16_t)opcodes.GetU16 (&offset))); break;
1620 case DW_OP_const2s : stack.push_back(Scalar(( int16_t)opcodes.GetU16 (&offset))); break;
1621 case DW_OP_const4u : stack.push_back(Scalar((uint32_t)opcodes.GetU32 (&offset))); break;
1622 case DW_OP_const4s : stack.push_back(Scalar(( int32_t)opcodes.GetU32 (&offset))); break;
1623 case DW_OP_const8u : stack.push_back(Scalar((uint64_t)opcodes.GetU64 (&offset))); break;
1624 case DW_OP_const8s : stack.push_back(Scalar(( int64_t)opcodes.GetU64 (&offset))); break;
1625 case DW_OP_constu : stack.push_back(Scalar(opcodes.GetULEB128 (&offset))); break;
1626 case DW_OP_consts : stack.push_back(Scalar(opcodes.GetSLEB128 (&offset))); break;
Chris Lattner24943d22010-06-08 16:52:24 +00001627
1628 //----------------------------------------------------------------------
1629 // OPCODE: DW_OP_dup
1630 // OPERANDS: none
1631 // DESCRIPTION: duplicates the value at the top of the stack
1632 //----------------------------------------------------------------------
1633 case DW_OP_dup:
1634 if (stack.empty())
1635 {
1636 if (error_ptr)
1637 error_ptr->SetErrorString("Expression stack empty for DW_OP_dup.");
1638 return false;
1639 }
1640 else
1641 stack.push_back(stack.back());
1642 break;
1643
1644 //----------------------------------------------------------------------
1645 // OPCODE: DW_OP_drop
1646 // OPERANDS: none
1647 // DESCRIPTION: pops the value at the top of the stack
1648 //----------------------------------------------------------------------
1649 case DW_OP_drop:
1650 if (stack.empty())
1651 {
1652 if (error_ptr)
1653 error_ptr->SetErrorString("Expression stack empty for DW_OP_drop.");
1654 return false;
1655 }
1656 else
1657 stack.pop_back();
1658 break;
1659
1660 //----------------------------------------------------------------------
1661 // OPCODE: DW_OP_over
1662 // OPERANDS: none
1663 // DESCRIPTION: Duplicates the entry currently second in the stack at
1664 // the top of the stack.
1665 //----------------------------------------------------------------------
1666 case DW_OP_over:
1667 if (stack.size() < 2)
1668 {
1669 if (error_ptr)
1670 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_over.");
1671 return false;
1672 }
1673 else
1674 stack.push_back(stack[stack.size() - 2]);
1675 break;
1676
1677
1678 //----------------------------------------------------------------------
1679 // OPCODE: DW_OP_pick
1680 // OPERANDS: uint8_t index into the current stack
1681 // DESCRIPTION: The stack entry with the specified index (0 through 255,
1682 // inclusive) is pushed on the stack
1683 //----------------------------------------------------------------------
1684 case DW_OP_pick:
1685 {
1686 uint8_t pick_idx = opcodes.GetU8(&offset);
1687 if (pick_idx < stack.size())
1688 stack.push_back(stack[pick_idx]);
1689 else
1690 {
1691 if (error_ptr)
1692 error_ptr->SetErrorStringWithFormat("Index %u out of range for DW_OP_pick.\n", pick_idx);
1693 return false;
1694 }
1695 }
1696 break;
1697
1698 //----------------------------------------------------------------------
1699 // OPCODE: DW_OP_swap
1700 // OPERANDS: none
1701 // DESCRIPTION: swaps the top two stack entries. The entry at the top
1702 // of the stack becomes the second stack entry, and the second entry
1703 // becomes the top of the stack
1704 //----------------------------------------------------------------------
1705 case DW_OP_swap:
1706 if (stack.size() < 2)
1707 {
1708 if (error_ptr)
1709 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_swap.");
1710 return false;
1711 }
1712 else
1713 {
1714 tmp = stack.back();
1715 stack.back() = stack[stack.size() - 2];
1716 stack[stack.size() - 2] = tmp;
1717 }
1718 break;
1719
1720 //----------------------------------------------------------------------
1721 // OPCODE: DW_OP_rot
1722 // OPERANDS: none
1723 // DESCRIPTION: Rotates the first three stack entries. The entry at
1724 // the top of the stack becomes the third stack entry, the second
1725 // entry becomes the top of the stack, and the third entry becomes
1726 // the second entry.
1727 //----------------------------------------------------------------------
1728 case DW_OP_rot:
1729 if (stack.size() < 3)
1730 {
1731 if (error_ptr)
1732 error_ptr->SetErrorString("Expression stack needs at least 3 items for DW_OP_rot.");
1733 return false;
1734 }
1735 else
1736 {
1737 size_t last_idx = stack.size() - 1;
1738 Value old_top = stack[last_idx];
1739 stack[last_idx] = stack[last_idx - 1];
1740 stack[last_idx - 1] = stack[last_idx - 2];
1741 stack[last_idx - 2] = old_top;
1742 }
1743 break;
1744
1745 //----------------------------------------------------------------------
1746 // OPCODE: DW_OP_abs
1747 // OPERANDS: none
1748 // DESCRIPTION: pops the top stack entry, interprets it as a signed
1749 // value and pushes its absolute value. If the absolute value can not be
1750 // represented, the result is undefined.
1751 //----------------------------------------------------------------------
1752 case DW_OP_abs:
1753 if (stack.empty())
1754 {
1755 if (error_ptr)
1756 error_ptr->SetErrorString("Expression stack needs at least 1 item for DW_OP_abs.");
1757 return false;
1758 }
1759 else if (stack.back().ResolveValue(exe_ctx, ast_context).AbsoluteValue() == false)
1760 {
1761 if (error_ptr)
1762 error_ptr->SetErrorString("Failed to take the absolute value of the first stack item.");
1763 return false;
1764 }
1765 break;
1766
1767 //----------------------------------------------------------------------
1768 // OPCODE: DW_OP_and
1769 // OPERANDS: none
1770 // DESCRIPTION: pops the top two stack values, performs a bitwise and
1771 // operation on the two, and pushes the result.
1772 //----------------------------------------------------------------------
1773 case DW_OP_and:
1774 if (stack.size() < 2)
1775 {
1776 if (error_ptr)
1777 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_and.");
1778 return false;
1779 }
1780 else
1781 {
1782 tmp = stack.back();
1783 stack.pop_back();
1784 stack.back().ResolveValue(exe_ctx, ast_context) = stack.back().ResolveValue(exe_ctx, ast_context) & tmp.ResolveValue(exe_ctx, ast_context);
1785 }
1786 break;
1787
1788 //----------------------------------------------------------------------
1789 // OPCODE: DW_OP_div
1790 // OPERANDS: none
1791 // DESCRIPTION: pops the top two stack values, divides the former second
1792 // entry by the former top of the stack using signed division, and
1793 // pushes the result.
1794 //----------------------------------------------------------------------
1795 case DW_OP_div:
1796 if (stack.size() < 2)
1797 {
1798 if (error_ptr)
1799 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_div.");
1800 return false;
1801 }
1802 else
1803 {
1804 tmp = stack.back();
1805 if (tmp.ResolveValue(exe_ctx, ast_context).IsZero())
1806 {
1807 if (error_ptr)
1808 error_ptr->SetErrorString("Divide by zero.");
1809 return false;
1810 }
1811 else
1812 {
1813 stack.pop_back();
1814 stack.back() = stack.back().ResolveValue(exe_ctx, ast_context) / tmp.ResolveValue(exe_ctx, ast_context);
1815 if (!stack.back().ResolveValue(exe_ctx, ast_context).IsValid())
1816 {
1817 if (error_ptr)
1818 error_ptr->SetErrorString("Divide failed.");
1819 return false;
1820 }
1821 }
1822 }
1823 break;
1824
1825 //----------------------------------------------------------------------
1826 // OPCODE: DW_OP_minus
1827 // OPERANDS: none
1828 // DESCRIPTION: pops the top two stack values, subtracts the former top
1829 // of the stack from the former second entry, and pushes the result.
1830 //----------------------------------------------------------------------
1831 case DW_OP_minus:
1832 if (stack.size() < 2)
1833 {
1834 if (error_ptr)
1835 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_minus.");
1836 return false;
1837 }
1838 else
1839 {
1840 tmp = stack.back();
1841 stack.pop_back();
1842 stack.back().ResolveValue(exe_ctx, ast_context) = stack.back().ResolveValue(exe_ctx, ast_context) - tmp.ResolveValue(exe_ctx, ast_context);
1843 }
1844 break;
1845
1846 //----------------------------------------------------------------------
1847 // OPCODE: DW_OP_mod
1848 // OPERANDS: none
1849 // DESCRIPTION: pops the top two stack values and pushes the result of
1850 // the calculation: former second stack entry modulo the former top of
1851 // the stack.
1852 //----------------------------------------------------------------------
1853 case DW_OP_mod:
1854 if (stack.size() < 2)
1855 {
1856 if (error_ptr)
1857 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_mod.");
1858 return false;
1859 }
1860 else
1861 {
1862 tmp = stack.back();
1863 stack.pop_back();
1864 stack.back().ResolveValue(exe_ctx, ast_context) = stack.back().ResolveValue(exe_ctx, ast_context) % tmp.ResolveValue(exe_ctx, ast_context);
1865 }
1866 break;
1867
1868
1869 //----------------------------------------------------------------------
1870 // OPCODE: DW_OP_mul
1871 // OPERANDS: none
1872 // DESCRIPTION: pops the top two stack entries, multiplies them
1873 // together, and pushes the result.
1874 //----------------------------------------------------------------------
1875 case DW_OP_mul:
1876 if (stack.size() < 2)
1877 {
1878 if (error_ptr)
1879 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_mul.");
1880 return false;
1881 }
1882 else
1883 {
1884 tmp = stack.back();
1885 stack.pop_back();
1886 stack.back().ResolveValue(exe_ctx, ast_context) = stack.back().ResolveValue(exe_ctx, ast_context) * tmp.ResolveValue(exe_ctx, ast_context);
1887 }
1888 break;
1889
1890 //----------------------------------------------------------------------
1891 // OPCODE: DW_OP_neg
1892 // OPERANDS: none
1893 // DESCRIPTION: pops the top stack entry, and pushes its negation.
1894 //----------------------------------------------------------------------
1895 case DW_OP_neg:
1896 if (stack.empty())
1897 {
1898 if (error_ptr)
1899 error_ptr->SetErrorString("Expression stack needs at least 1 item for DW_OP_neg.");
1900 return false;
1901 }
1902 else
1903 {
1904 if (stack.back().ResolveValue(exe_ctx, ast_context).UnaryNegate() == false)
1905 {
1906 if (error_ptr)
1907 error_ptr->SetErrorString("Unary negate failed.");
1908 return false;
1909 }
1910 }
1911 break;
1912
1913 //----------------------------------------------------------------------
1914 // OPCODE: DW_OP_not
1915 // OPERANDS: none
1916 // DESCRIPTION: pops the top stack entry, and pushes its bitwise
1917 // complement
1918 //----------------------------------------------------------------------
1919 case DW_OP_not:
1920 if (stack.empty())
1921 {
1922 if (error_ptr)
1923 error_ptr->SetErrorString("Expression stack needs at least 1 item for DW_OP_not.");
1924 return false;
1925 }
1926 else
1927 {
1928 if (stack.back().ResolveValue(exe_ctx, ast_context).OnesComplement() == false)
1929 {
1930 if (error_ptr)
1931 error_ptr->SetErrorString("Logical NOT failed.");
1932 return false;
1933 }
1934 }
1935 break;
1936
1937 //----------------------------------------------------------------------
1938 // OPCODE: DW_OP_or
1939 // OPERANDS: none
1940 // DESCRIPTION: pops the top two stack entries, performs a bitwise or
1941 // operation on the two, and pushes the result.
1942 //----------------------------------------------------------------------
1943 case DW_OP_or:
1944 if (stack.size() < 2)
1945 {
1946 if (error_ptr)
1947 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_or.");
1948 return false;
1949 }
1950 else
1951 {
1952 tmp = stack.back();
1953 stack.pop_back();
1954 stack.back().ResolveValue(exe_ctx, ast_context) = stack.back().ResolveValue(exe_ctx, ast_context) | tmp.ResolveValue(exe_ctx, ast_context);
1955 }
1956 break;
1957
1958 //----------------------------------------------------------------------
1959 // OPCODE: DW_OP_plus
1960 // OPERANDS: none
1961 // DESCRIPTION: pops the top two stack entries, adds them together, and
1962 // pushes the result.
1963 //----------------------------------------------------------------------
1964 case DW_OP_plus:
1965 if (stack.size() < 2)
1966 {
1967 if (error_ptr)
1968 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_plus.");
1969 return false;
1970 }
1971 else
1972 {
1973 tmp = stack.back();
1974 stack.pop_back();
1975 stack.back().ResolveValue(exe_ctx, ast_context) = stack.back().ResolveValue(exe_ctx, ast_context) + tmp.ResolveValue(exe_ctx, ast_context);
1976 }
1977 break;
1978
1979 //----------------------------------------------------------------------
1980 // OPCODE: DW_OP_plus_uconst
1981 // OPERANDS: none
1982 // DESCRIPTION: pops the top stack entry, adds it to the unsigned LEB128
1983 // constant operand and pushes the result.
1984 //----------------------------------------------------------------------
1985 case DW_OP_plus_uconst:
1986 if (stack.empty())
1987 {
1988 if (error_ptr)
1989 error_ptr->SetErrorString("Expression stack needs at least 1 item for DW_OP_plus_uconst.");
1990 return false;
1991 }
1992 else
1993 {
1994 uint32_t uconst_value = opcodes.GetULEB128(&offset);
1995 // Implicit conversion from a UINT to a Scalar...
1996 stack.back().ResolveValue(exe_ctx, ast_context) += uconst_value;
1997 if (!stack.back().ResolveValue(exe_ctx, ast_context).IsValid())
1998 {
1999 if (error_ptr)
2000 error_ptr->SetErrorString("DW_OP_plus_uconst failed.");
2001 return false;
2002 }
2003 }
2004 break;
2005
2006 //----------------------------------------------------------------------
2007 // OPCODE: DW_OP_shl
2008 // OPERANDS: none
2009 // DESCRIPTION: pops the top two stack entries, shifts the former
2010 // second entry left by the number of bits specified by the former top
2011 // of the stack, and pushes the result.
2012 //----------------------------------------------------------------------
2013 case DW_OP_shl:
2014 if (stack.size() < 2)
2015 {
2016 if (error_ptr)
2017 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_shl.");
2018 return false;
2019 }
2020 else
2021 {
2022 tmp = stack.back();
2023 stack.pop_back();
2024 stack.back().ResolveValue(exe_ctx, ast_context) <<= tmp.ResolveValue(exe_ctx, ast_context);
2025 }
2026 break;
2027
2028 //----------------------------------------------------------------------
2029 // OPCODE: DW_OP_shr
2030 // OPERANDS: none
2031 // DESCRIPTION: pops the top two stack entries, shifts the former second
2032 // entry right logically (filling with zero bits) by the number of bits
2033 // specified by the former top of the stack, and pushes the result.
2034 //----------------------------------------------------------------------
2035 case DW_OP_shr:
2036 if (stack.size() < 2)
2037 {
2038 if (error_ptr)
2039 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_shr.");
2040 return false;
2041 }
2042 else
2043 {
2044 tmp = stack.back();
2045 stack.pop_back();
2046 if (stack.back().ResolveValue(exe_ctx, ast_context).ShiftRightLogical(tmp.ResolveValue(exe_ctx, ast_context)) == false)
2047 {
2048 if (error_ptr)
2049 error_ptr->SetErrorString("DW_OP_shr failed.");
2050 return false;
2051 }
2052 }
2053 break;
2054
2055 //----------------------------------------------------------------------
2056 // OPCODE: DW_OP_shra
2057 // OPERANDS: none
2058 // DESCRIPTION: pops the top two stack entries, shifts the former second
2059 // entry right arithmetically (divide the magnitude by 2, keep the same
2060 // sign for the result) by the number of bits specified by the former
2061 // top of the stack, and pushes the result.
2062 //----------------------------------------------------------------------
2063 case DW_OP_shra:
2064 if (stack.size() < 2)
2065 {
2066 if (error_ptr)
2067 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_shra.");
2068 return false;
2069 }
2070 else
2071 {
2072 tmp = stack.back();
2073 stack.pop_back();
2074 stack.back().ResolveValue(exe_ctx, ast_context) >>= tmp.ResolveValue(exe_ctx, ast_context);
2075 }
2076 break;
2077
2078 //----------------------------------------------------------------------
2079 // OPCODE: DW_OP_xor
2080 // OPERANDS: none
2081 // DESCRIPTION: pops the top two stack entries, performs the bitwise
2082 // exclusive-or operation on the two, and pushes the result.
2083 //----------------------------------------------------------------------
2084 case DW_OP_xor:
2085 if (stack.size() < 2)
2086 {
2087 if (error_ptr)
2088 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_xor.");
2089 return false;
2090 }
2091 else
2092 {
2093 tmp = stack.back();
2094 stack.pop_back();
2095 stack.back().ResolveValue(exe_ctx, ast_context) = stack.back().ResolveValue(exe_ctx, ast_context) ^ tmp.ResolveValue(exe_ctx, ast_context);
2096 }
2097 break;
2098
2099
2100 //----------------------------------------------------------------------
2101 // OPCODE: DW_OP_skip
2102 // OPERANDS: int16_t
2103 // DESCRIPTION: An unconditional branch. Its single operand is a 2-byte
2104 // signed integer constant. The 2-byte constant is the number of bytes
2105 // of the DWARF expression to skip forward or backward from the current
2106 // operation, beginning after the 2-byte constant.
2107 //----------------------------------------------------------------------
2108 case DW_OP_skip:
2109 {
2110 int16_t skip_offset = (int16_t)opcodes.GetU16(&offset);
2111 uint32_t new_offset = offset + skip_offset;
2112 if (new_offset >= opcodes_offset && new_offset < end_offset)
2113 offset = new_offset;
2114 else
2115 {
2116 if (error_ptr)
2117 error_ptr->SetErrorString("Invalid opcode offset in DW_OP_skip.");
2118 return false;
2119 }
2120 }
2121 break;
2122
2123 //----------------------------------------------------------------------
2124 // OPCODE: DW_OP_bra
2125 // OPERANDS: int16_t
2126 // DESCRIPTION: A conditional branch. Its single operand is a 2-byte
2127 // signed integer constant. This operation pops the top of stack. If
2128 // the value popped is not the constant 0, the 2-byte constant operand
2129 // is the number of bytes of the DWARF expression to skip forward or
2130 // backward from the current operation, beginning after the 2-byte
2131 // constant.
2132 //----------------------------------------------------------------------
2133 case DW_OP_bra:
2134 {
2135 tmp = stack.back();
2136 stack.pop_back();
2137 int16_t bra_offset = (int16_t)opcodes.GetU16(&offset);
2138 Scalar zero(0);
2139 if (tmp.ResolveValue(exe_ctx, ast_context) != zero)
2140 {
2141 uint32_t new_offset = offset + bra_offset;
2142 if (new_offset >= opcodes_offset && new_offset < end_offset)
2143 offset = new_offset;
2144 else
2145 {
2146 if (error_ptr)
2147 error_ptr->SetErrorString("Invalid opcode offset in DW_OP_bra.");
2148 return false;
2149 }
2150 }
2151 }
2152 break;
2153
2154 //----------------------------------------------------------------------
2155 // OPCODE: DW_OP_eq
2156 // OPERANDS: none
2157 // DESCRIPTION: pops the top two stack values, compares using the
2158 // equals (==) operator.
2159 // STACK RESULT: push the constant value 1 onto the stack if the result
2160 // of the operation is true or the constant value 0 if the result of the
2161 // operation is false.
2162 //----------------------------------------------------------------------
2163 case DW_OP_eq:
2164 if (stack.size() < 2)
2165 {
2166 if (error_ptr)
2167 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_eq.");
2168 return false;
2169 }
2170 else
2171 {
2172 tmp = stack.back();
2173 stack.pop_back();
2174 stack.back().ResolveValue(exe_ctx, ast_context) = stack.back().ResolveValue(exe_ctx, ast_context) == tmp.ResolveValue(exe_ctx, ast_context);
2175 }
2176 break;
2177
2178 //----------------------------------------------------------------------
2179 // OPCODE: DW_OP_ge
2180 // OPERANDS: none
2181 // DESCRIPTION: pops the top two stack values, compares using the
2182 // greater than or equal to (>=) operator.
2183 // STACK RESULT: push the constant value 1 onto the stack if the result
2184 // of the operation is true or the constant value 0 if the result of the
2185 // operation is false.
2186 //----------------------------------------------------------------------
2187 case DW_OP_ge:
2188 if (stack.size() < 2)
2189 {
2190 if (error_ptr)
2191 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_ge.");
2192 return false;
2193 }
2194 else
2195 {
2196 tmp = stack.back();
2197 stack.pop_back();
2198 stack.back().ResolveValue(exe_ctx, ast_context) = stack.back().ResolveValue(exe_ctx, ast_context) >= tmp.ResolveValue(exe_ctx, ast_context);
2199 }
2200 break;
2201
2202 //----------------------------------------------------------------------
2203 // OPCODE: DW_OP_gt
2204 // OPERANDS: none
2205 // DESCRIPTION: pops the top two stack values, compares using the
2206 // greater than (>) operator.
2207 // STACK RESULT: push the constant value 1 onto the stack if the result
2208 // of the operation is true or the constant value 0 if the result of the
2209 // operation is false.
2210 //----------------------------------------------------------------------
2211 case DW_OP_gt:
2212 if (stack.size() < 2)
2213 {
2214 if (error_ptr)
2215 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_gt.");
2216 return false;
2217 }
2218 else
2219 {
2220 tmp = stack.back();
2221 stack.pop_back();
2222 stack.back().ResolveValue(exe_ctx, ast_context) = stack.back().ResolveValue(exe_ctx, ast_context) > tmp.ResolveValue(exe_ctx, ast_context);
2223 }
2224 break;
2225
2226 //----------------------------------------------------------------------
2227 // OPCODE: DW_OP_le
2228 // OPERANDS: none
2229 // DESCRIPTION: pops the top two stack values, compares using the
2230 // less than or equal to (<=) operator.
2231 // STACK RESULT: push the constant value 1 onto the stack if the result
2232 // of the operation is true or the constant value 0 if the result of the
2233 // operation is false.
2234 //----------------------------------------------------------------------
2235 case DW_OP_le:
2236 if (stack.size() < 2)
2237 {
2238 if (error_ptr)
2239 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_le.");
2240 return false;
2241 }
2242 else
2243 {
2244 tmp = stack.back();
2245 stack.pop_back();
2246 stack.back().ResolveValue(exe_ctx, ast_context) = stack.back().ResolveValue(exe_ctx, ast_context) <= tmp.ResolveValue(exe_ctx, ast_context);
2247 }
2248 break;
2249
2250 //----------------------------------------------------------------------
2251 // OPCODE: DW_OP_lt
2252 // OPERANDS: none
2253 // DESCRIPTION: pops the top two stack values, compares using the
2254 // less than (<) operator.
2255 // STACK RESULT: push the constant value 1 onto the stack if the result
2256 // of the operation is true or the constant value 0 if the result of the
2257 // operation is false.
2258 //----------------------------------------------------------------------
2259 case DW_OP_lt:
2260 if (stack.size() < 2)
2261 {
2262 if (error_ptr)
2263 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_lt.");
2264 return false;
2265 }
2266 else
2267 {
2268 tmp = stack.back();
2269 stack.pop_back();
2270 stack.back().ResolveValue(exe_ctx, ast_context) = stack.back().ResolveValue(exe_ctx, ast_context) < tmp.ResolveValue(exe_ctx, ast_context);
2271 }
2272 break;
2273
2274 //----------------------------------------------------------------------
2275 // OPCODE: DW_OP_ne
2276 // OPERANDS: none
2277 // DESCRIPTION: pops the top two stack values, compares using the
2278 // not equal (!=) operator.
2279 // STACK RESULT: push the constant value 1 onto the stack if the result
2280 // of the operation is true or the constant value 0 if the result of the
2281 // operation is false.
2282 //----------------------------------------------------------------------
2283 case DW_OP_ne:
2284 if (stack.size() < 2)
2285 {
2286 if (error_ptr)
2287 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_ne.");
2288 return false;
2289 }
2290 else
2291 {
2292 tmp = stack.back();
2293 stack.pop_back();
2294 stack.back().ResolveValue(exe_ctx, ast_context) = stack.back().ResolveValue(exe_ctx, ast_context) != tmp.ResolveValue(exe_ctx, ast_context);
2295 }
2296 break;
2297
2298 //----------------------------------------------------------------------
2299 // OPCODE: DW_OP_litn
2300 // OPERANDS: none
2301 // DESCRIPTION: encode the unsigned literal values from 0 through 31.
2302 // STACK RESULT: push the unsigned literal constant value onto the top
2303 // of the stack.
2304 //----------------------------------------------------------------------
2305 case DW_OP_lit0:
2306 case DW_OP_lit1:
2307 case DW_OP_lit2:
2308 case DW_OP_lit3:
2309 case DW_OP_lit4:
2310 case DW_OP_lit5:
2311 case DW_OP_lit6:
2312 case DW_OP_lit7:
2313 case DW_OP_lit8:
2314 case DW_OP_lit9:
2315 case DW_OP_lit10:
2316 case DW_OP_lit11:
2317 case DW_OP_lit12:
2318 case DW_OP_lit13:
2319 case DW_OP_lit14:
2320 case DW_OP_lit15:
2321 case DW_OP_lit16:
2322 case DW_OP_lit17:
2323 case DW_OP_lit18:
2324 case DW_OP_lit19:
2325 case DW_OP_lit20:
2326 case DW_OP_lit21:
2327 case DW_OP_lit22:
2328 case DW_OP_lit23:
2329 case DW_OP_lit24:
2330 case DW_OP_lit25:
2331 case DW_OP_lit26:
2332 case DW_OP_lit27:
2333 case DW_OP_lit28:
2334 case DW_OP_lit29:
2335 case DW_OP_lit30:
2336 case DW_OP_lit31:
Greg Clayton801417e2011-07-07 01:59:51 +00002337 stack.push_back(Scalar(op - DW_OP_lit0));
Chris Lattner24943d22010-06-08 16:52:24 +00002338 break;
2339
2340 //----------------------------------------------------------------------
2341 // OPCODE: DW_OP_regN
2342 // OPERANDS: none
2343 // DESCRIPTION: Push the value in register n on the top of the stack.
2344 //----------------------------------------------------------------------
2345 case DW_OP_reg0:
2346 case DW_OP_reg1:
2347 case DW_OP_reg2:
2348 case DW_OP_reg3:
2349 case DW_OP_reg4:
2350 case DW_OP_reg5:
2351 case DW_OP_reg6:
2352 case DW_OP_reg7:
2353 case DW_OP_reg8:
2354 case DW_OP_reg9:
2355 case DW_OP_reg10:
2356 case DW_OP_reg11:
2357 case DW_OP_reg12:
2358 case DW_OP_reg13:
2359 case DW_OP_reg14:
2360 case DW_OP_reg15:
2361 case DW_OP_reg16:
2362 case DW_OP_reg17:
2363 case DW_OP_reg18:
2364 case DW_OP_reg19:
2365 case DW_OP_reg20:
2366 case DW_OP_reg21:
2367 case DW_OP_reg22:
2368 case DW_OP_reg23:
2369 case DW_OP_reg24:
2370 case DW_OP_reg25:
2371 case DW_OP_reg26:
2372 case DW_OP_reg27:
2373 case DW_OP_reg28:
2374 case DW_OP_reg29:
2375 case DW_OP_reg30:
2376 case DW_OP_reg31:
2377 {
2378 reg_num = op - DW_OP_reg0;
2379
Jason Molenda8e69de42010-11-20 01:28:30 +00002380 if (ReadRegisterValueAsScalar (reg_ctx, reg_kind, reg_num, error_ptr, tmp))
Chris Lattner24943d22010-06-08 16:52:24 +00002381 stack.push_back(tmp);
2382 else
2383 return false;
2384 }
2385 break;
2386 //----------------------------------------------------------------------
2387 // OPCODE: DW_OP_regx
2388 // OPERANDS:
2389 // ULEB128 literal operand that encodes the register.
2390 // DESCRIPTION: Push the value in register on the top of the stack.
2391 //----------------------------------------------------------------------
2392 case DW_OP_regx:
2393 {
2394 reg_num = opcodes.GetULEB128(&offset);
Jason Molenda8e69de42010-11-20 01:28:30 +00002395 if (ReadRegisterValueAsScalar (reg_ctx, reg_kind, reg_num, error_ptr, tmp))
Chris Lattner24943d22010-06-08 16:52:24 +00002396 stack.push_back(tmp);
2397 else
2398 return false;
2399 }
2400 break;
2401
2402 //----------------------------------------------------------------------
2403 // OPCODE: DW_OP_bregN
2404 // OPERANDS:
2405 // SLEB128 offset from register N
2406 // DESCRIPTION: Value is in memory at the address specified by register
2407 // N plus an offset.
2408 //----------------------------------------------------------------------
2409 case DW_OP_breg0:
2410 case DW_OP_breg1:
2411 case DW_OP_breg2:
2412 case DW_OP_breg3:
2413 case DW_OP_breg4:
2414 case DW_OP_breg5:
2415 case DW_OP_breg6:
2416 case DW_OP_breg7:
2417 case DW_OP_breg8:
2418 case DW_OP_breg9:
2419 case DW_OP_breg10:
2420 case DW_OP_breg11:
2421 case DW_OP_breg12:
2422 case DW_OP_breg13:
2423 case DW_OP_breg14:
2424 case DW_OP_breg15:
2425 case DW_OP_breg16:
2426 case DW_OP_breg17:
2427 case DW_OP_breg18:
2428 case DW_OP_breg19:
2429 case DW_OP_breg20:
2430 case DW_OP_breg21:
2431 case DW_OP_breg22:
2432 case DW_OP_breg23:
2433 case DW_OP_breg24:
2434 case DW_OP_breg25:
2435 case DW_OP_breg26:
2436 case DW_OP_breg27:
2437 case DW_OP_breg28:
2438 case DW_OP_breg29:
2439 case DW_OP_breg30:
2440 case DW_OP_breg31:
2441 {
2442 reg_num = op - DW_OP_breg0;
2443
Jason Molenda8e69de42010-11-20 01:28:30 +00002444 if (ReadRegisterValueAsScalar (reg_ctx, reg_kind, reg_num, error_ptr, tmp))
Chris Lattner24943d22010-06-08 16:52:24 +00002445 {
2446 int64_t breg_offset = opcodes.GetSLEB128(&offset);
2447 tmp.ResolveValue(exe_ctx, ast_context) += (uint64_t)breg_offset;
Sean Callanan6fc5c712012-01-06 18:24:47 +00002448 tmp.ClearContext();
Chris Lattner24943d22010-06-08 16:52:24 +00002449 stack.push_back(tmp);
2450 stack.back().SetValueType (Value::eValueTypeLoadAddress);
2451 }
2452 else
2453 return false;
2454 }
2455 break;
2456 //----------------------------------------------------------------------
2457 // OPCODE: DW_OP_bregx
2458 // OPERANDS: 2
2459 // ULEB128 literal operand that encodes the register.
2460 // SLEB128 offset from register N
2461 // DESCRIPTION: Value is in memory at the address specified by register
2462 // N plus an offset.
2463 //----------------------------------------------------------------------
2464 case DW_OP_bregx:
2465 {
2466 reg_num = opcodes.GetULEB128(&offset);
2467
Jason Molenda8e69de42010-11-20 01:28:30 +00002468 if (ReadRegisterValueAsScalar (reg_ctx, reg_kind, reg_num, error_ptr, tmp))
Chris Lattner24943d22010-06-08 16:52:24 +00002469 {
2470 int64_t breg_offset = opcodes.GetSLEB128(&offset);
2471 tmp.ResolveValue(exe_ctx, ast_context) += (uint64_t)breg_offset;
Sean Callanan6fc5c712012-01-06 18:24:47 +00002472 tmp.ClearContext();
Chris Lattner24943d22010-06-08 16:52:24 +00002473 stack.push_back(tmp);
2474 stack.back().SetValueType (Value::eValueTypeLoadAddress);
2475 }
2476 else
2477 return false;
2478 }
2479 break;
2480
2481 case DW_OP_fbreg:
Greg Clayton567e7f32011-09-22 04:58:26 +00002482 if (exe_ctx)
Chris Lattner24943d22010-06-08 16:52:24 +00002483 {
Greg Clayton567e7f32011-09-22 04:58:26 +00002484 if (frame)
Chris Lattner24943d22010-06-08 16:52:24 +00002485 {
Greg Clayton567e7f32011-09-22 04:58:26 +00002486 Scalar value;
2487 if (frame->GetFrameBaseValue(value, error_ptr))
2488 {
2489 int64_t fbreg_offset = opcodes.GetSLEB128(&offset);
2490 value += fbreg_offset;
2491 stack.push_back(value);
2492 stack.back().SetValueType (Value::eValueTypeLoadAddress);
2493 }
2494 else
2495 return false;
Chris Lattner24943d22010-06-08 16:52:24 +00002496 }
2497 else
Greg Clayton567e7f32011-09-22 04:58:26 +00002498 {
2499 if (error_ptr)
2500 error_ptr->SetErrorString ("Invalid stack frame in context for DW_OP_fbreg opcode.");
Chris Lattner24943d22010-06-08 16:52:24 +00002501 return false;
Greg Clayton567e7f32011-09-22 04:58:26 +00002502 }
Chris Lattner24943d22010-06-08 16:52:24 +00002503 }
2504 else
2505 {
2506 if (error_ptr)
Greg Clayton567e7f32011-09-22 04:58:26 +00002507 error_ptr->SetErrorStringWithFormat ("NULL execution context for DW_OP_fbreg.\n");
Chris Lattner24943d22010-06-08 16:52:24 +00002508 return false;
2509 }
Greg Clayton567e7f32011-09-22 04:58:26 +00002510
Chris Lattner24943d22010-06-08 16:52:24 +00002511 break;
2512
2513 //----------------------------------------------------------------------
2514 // OPCODE: DW_OP_nop
2515 // OPERANDS: none
2516 // DESCRIPTION: A place holder. It has no effect on the location stack
2517 // or any of its values.
2518 //----------------------------------------------------------------------
2519 case DW_OP_nop:
2520 break;
2521
2522 //----------------------------------------------------------------------
2523 // OPCODE: DW_OP_piece
2524 // OPERANDS: 1
2525 // ULEB128: byte size of the piece
2526 // DESCRIPTION: The operand describes the size in bytes of the piece of
2527 // the object referenced by the DWARF expression whose result is at the
2528 // top of the stack. If the piece is located in a register, but does not
2529 // occupy the entire register, the placement of the piece within that
2530 // register is defined by the ABI.
2531 //
2532 // Many compilers store a single variable in sets of registers, or store
2533 // a variable partially in memory and partially in registers.
2534 // DW_OP_piece provides a way of describing how large a part of a
2535 // variable a particular DWARF expression refers to.
2536 //----------------------------------------------------------------------
2537 case DW_OP_piece:
2538 if (error_ptr)
2539 error_ptr->SetErrorString ("Unimplemented opcode DW_OP_piece.");
2540 return false;
2541
2542 //----------------------------------------------------------------------
2543 // OPCODE: DW_OP_push_object_address
2544 // OPERANDS: none
2545 // DESCRIPTION: Pushes the address of the object currently being
2546 // evaluated as part of evaluation of a user presented expression.
2547 // This object may correspond to an independent variable described by
2548 // its own DIE or it may be a component of an array, structure, or class
2549 // whose address has been dynamically determined by an earlier step
2550 // during user expression evaluation.
2551 //----------------------------------------------------------------------
2552 case DW_OP_push_object_address:
2553 if (error_ptr)
2554 error_ptr->SetErrorString ("Unimplemented opcode DW_OP_push_object_address.");
2555 return false;
2556
2557 //----------------------------------------------------------------------
2558 // OPCODE: DW_OP_call2
2559 // OPERANDS:
2560 // uint16_t compile unit relative offset of a DIE
2561 // DESCRIPTION: Performs subroutine calls during evaluation
2562 // of a DWARF expression. The operand is the 2-byte unsigned offset
2563 // of a debugging information entry in the current compilation unit.
2564 //
2565 // Operand interpretation is exactly like that for DW_FORM_ref2.
2566 //
2567 // This operation transfers control of DWARF expression evaluation
2568 // to the DW_AT_location attribute of the referenced DIE. If there is
2569 // no such attribute, then there is no effect. Execution of the DWARF
2570 // expression of a DW_AT_location attribute may add to and/or remove from
2571 // values on the stack. Execution returns to the point following the call
2572 // when the end of the attribute is reached. Values on the stack at the
2573 // time of the call may be used as parameters by the called expression
2574 // and values left on the stack by the called expression may be used as
2575 // return values by prior agreement between the calling and called
2576 // expressions.
2577 //----------------------------------------------------------------------
2578 case DW_OP_call2:
2579 if (error_ptr)
2580 error_ptr->SetErrorString ("Unimplemented opcode DW_OP_call2.");
2581 return false;
2582 //----------------------------------------------------------------------
2583 // OPCODE: DW_OP_call4
2584 // OPERANDS: 1
2585 // uint32_t compile unit relative offset of a DIE
2586 // DESCRIPTION: Performs a subroutine call during evaluation of a DWARF
2587 // expression. For DW_OP_call4, the operand is a 4-byte unsigned offset
2588 // of a debugging information entry in the current compilation unit.
2589 //
2590 // Operand interpretation DW_OP_call4 is exactly like that for
2591 // DW_FORM_ref4.
2592 //
2593 // This operation transfers control of DWARF expression evaluation
2594 // to the DW_AT_location attribute of the referenced DIE. If there is
2595 // no such attribute, then there is no effect. Execution of the DWARF
2596 // expression of a DW_AT_location attribute may add to and/or remove from
2597 // values on the stack. Execution returns to the point following the call
2598 // when the end of the attribute is reached. Values on the stack at the
2599 // time of the call may be used as parameters by the called expression
2600 // and values left on the stack by the called expression may be used as
2601 // return values by prior agreement between the calling and called
2602 // expressions.
2603 //----------------------------------------------------------------------
2604 case DW_OP_call4:
2605 if (error_ptr)
2606 error_ptr->SetErrorString ("Unimplemented opcode DW_OP_call4.");
2607 return false;
2608
Greg Claytona1b9a902011-11-13 04:15:56 +00002609#if 0
Chris Lattner24943d22010-06-08 16:52:24 +00002610 //----------------------------------------------------------------------
2611 // OPCODE: DW_OP_call_ref
2612 // OPERANDS:
2613 // uint32_t absolute DIE offset for 32-bit DWARF or a uint64_t
2614 // absolute DIE offset for 64 bit DWARF.
2615 // DESCRIPTION: Performs a subroutine call during evaluation of a DWARF
2616 // expression. Takes a single operand. In the 32-bit DWARF format, the
2617 // operand is a 4-byte unsigned value; in the 64-bit DWARF format, it
2618 // is an 8-byte unsigned value. The operand is used as the offset of a
2619 // debugging information entry in a .debug_info section which may be
2620 // contained in a shared object for executable other than that
2621 // containing the operator. For references from one shared object or
2622 // executable to another, the relocation must be performed by the
2623 // consumer.
2624 //
2625 // Operand interpretation of DW_OP_call_ref is exactly like that for
2626 // DW_FORM_ref_addr.
2627 //
2628 // This operation transfers control of DWARF expression evaluation
2629 // to the DW_AT_location attribute of the referenced DIE. If there is
2630 // no such attribute, then there is no effect. Execution of the DWARF
2631 // expression of a DW_AT_location attribute may add to and/or remove from
2632 // values on the stack. Execution returns to the point following the call
2633 // when the end of the attribute is reached. Values on the stack at the
2634 // time of the call may be used as parameters by the called expression
2635 // and values left on the stack by the called expression may be used as
2636 // return values by prior agreement between the calling and called
2637 // expressions.
2638 //----------------------------------------------------------------------
2639 case DW_OP_call_ref:
2640 if (error_ptr)
2641 error_ptr->SetErrorString ("Unimplemented opcode DW_OP_call_ref.");
2642 return false;
2643
Greg Claytona1b9a902011-11-13 04:15:56 +00002644 //----------------------------------------------------------------------
2645 // OPCODE: DW_OP_APPLE_array_ref
2646 // OPERANDS: none
2647 // DESCRIPTION: Pops a value off the stack and uses it as the array
2648 // index. Pops a second value off the stack and uses it as the array
2649 // itself. Pushes a value onto the stack representing the element of
2650 // the array specified by the index.
2651 //----------------------------------------------------------------------
2652 case DW_OP_APPLE_array_ref:
Chris Lattner24943d22010-06-08 16:52:24 +00002653 {
2654 if (stack.size() < 2)
2655 {
2656 if (error_ptr)
2657 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_APPLE_array_ref.");
2658 return false;
2659 }
2660
2661 Value index_val = stack.back();
2662 stack.pop_back();
2663 Value array_val = stack.back();
2664 stack.pop_back();
2665
2666 Scalar &index_scalar = index_val.ResolveValue(exe_ctx, ast_context);
Greg Clayton381f9682011-04-01 18:14:08 +00002667 int64_t index = index_scalar.SLongLong(LLONG_MAX);
Chris Lattner24943d22010-06-08 16:52:24 +00002668
Greg Clayton381f9682011-04-01 18:14:08 +00002669 if (index == LLONG_MAX)
Chris Lattner24943d22010-06-08 16:52:24 +00002670 {
2671 if (error_ptr)
2672 error_ptr->SetErrorString("Invalid array index.");
2673 return false;
2674 }
Greg Claytona1b9a902011-11-13 04:15:56 +00002675
Greg Clayton6916e352010-11-13 03:52:47 +00002676 if (array_val.GetContextType() != Value::eContextTypeClangType)
Chris Lattner24943d22010-06-08 16:52:24 +00002677 {
2678 if (error_ptr)
2679 error_ptr->SetErrorString("Arrays without Clang types are unhandled at this time.");
2680 return false;
2681 }
2682
2683 if (array_val.GetValueType() != Value::eValueTypeLoadAddress &&
2684 array_val.GetValueType() != Value::eValueTypeHostAddress)
2685 {
2686 if (error_ptr)
2687 error_ptr->SetErrorString("Array must be stored in memory.");
2688 return false;
2689 }
2690
Greg Clayton462d4142010-09-29 01:12:09 +00002691 void *array_type = array_val.GetClangType();
Chris Lattner24943d22010-06-08 16:52:24 +00002692
2693 void *member_type;
2694 uint64_t size = 0;
2695
2696 if ((!ClangASTContext::IsPointerType(array_type, &member_type)) &&
2697 (!ClangASTContext::IsArrayType(array_type, &member_type, &size)))
2698 {
2699 if (error_ptr)
2700 error_ptr->SetErrorString("Array reference from something that is neither a pointer nor an array.");
2701 return false;
2702 }
2703
2704 if (size && (index >= size || index < 0))
2705 {
2706 if (error_ptr)
2707 error_ptr->SetErrorStringWithFormat("Out of bounds array access. %lld is not in [0, %llu]", index, size);
2708 return false;
2709 }
2710
Greg Clayton960d6a42010-08-03 00:35:52 +00002711 uint64_t member_bit_size = ClangASTType::GetClangTypeBitWidth(ast_context, member_type);
2712 uint64_t member_bit_align = ClangASTType::GetTypeBitAlign(ast_context, member_type);
Chris Lattner24943d22010-06-08 16:52:24 +00002713 uint64_t member_bit_incr = ((member_bit_size + member_bit_align - 1) / member_bit_align) * member_bit_align;
2714 if (member_bit_incr % 8)
2715 {
2716 if (error_ptr)
Jason Molenda95b7b432011-09-20 00:26:08 +00002717 error_ptr->SetErrorStringWithFormat("Array increment is not byte aligned");
Chris Lattner24943d22010-06-08 16:52:24 +00002718 return false;
2719 }
2720 int64_t member_offset = (int64_t)(member_bit_incr / 8) * index;
2721
2722 Value member;
2723
Greg Clayton6916e352010-11-13 03:52:47 +00002724 member.SetContext(Value::eContextTypeClangType, member_type);
Chris Lattner24943d22010-06-08 16:52:24 +00002725 member.SetValueType(array_val.GetValueType());
2726
2727 addr_t array_base = (addr_t)array_val.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
2728 addr_t member_loc = array_base + member_offset;
2729 member.GetScalar() = (uint64_t)member_loc;
2730
2731 stack.push_back(member);
2732 }
Greg Claytona1b9a902011-11-13 04:15:56 +00002733 break;
Chris Lattner24943d22010-06-08 16:52:24 +00002734
2735 //----------------------------------------------------------------------
2736 // OPCODE: DW_OP_APPLE_uninit
2737 // OPERANDS: none
2738 // DESCRIPTION: Lets us know that the value is currently not initialized
2739 //----------------------------------------------------------------------
2740 case DW_OP_APPLE_uninit:
2741 //return eResultTypeErrorUninitialized;
2742 break; // Ignore this as we have seen cases where this value is incorrectly added
2743
2744 //----------------------------------------------------------------------
2745 // OPCODE: DW_OP_APPLE_assign
2746 // OPERANDS: none
2747 // DESCRIPTION: Pops a value off of the stack and assigns it to the next
2748 // item on the stack which must be something assignable (inferior
2749 // Variable, inferior Type with address, inferior register, or
2750 // expression local variable.
2751 //----------------------------------------------------------------------
2752 case DW_OP_APPLE_assign:
2753 if (stack.size() < 2)
2754 {
2755 if (error_ptr)
2756 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_APPLE_assign.");
2757 return false;
2758 }
2759 else
2760 {
2761 tmp = stack.back();
2762 stack.pop_back();
2763 Value::ContextType context_type = stack.back().GetContextType();
Greg Claytoncd548032011-02-01 01:31:41 +00002764 StreamString new_value(Stream::eBinary, 4, lldb::endian::InlHostByteOrder());
Chris Lattner24943d22010-06-08 16:52:24 +00002765 switch (context_type)
2766 {
Greg Clayton6916e352010-11-13 03:52:47 +00002767 case Value::eContextTypeClangType:
Chris Lattner24943d22010-06-08 16:52:24 +00002768 {
Greg Clayton462d4142010-09-29 01:12:09 +00002769 void *clang_type = stack.back().GetClangType();
Chris Lattner24943d22010-06-08 16:52:24 +00002770
2771 if (ClangASTContext::IsAggregateType (clang_type))
2772 {
2773 Value::ValueType source_value_type = tmp.GetValueType();
2774 Value::ValueType target_value_type = stack.back().GetValueType();
2775
2776 addr_t source_addr = (addr_t)tmp.GetScalar().ULongLong();
2777 addr_t target_addr = (addr_t)stack.back().GetScalar().ULongLong();
2778
Greg Clayton960d6a42010-08-03 00:35:52 +00002779 size_t byte_size = (ClangASTType::GetClangTypeBitWidth(ast_context, clang_type) + 7) / 8;
Chris Lattner24943d22010-06-08 16:52:24 +00002780
2781 switch (source_value_type)
2782 {
Greg Clayton4fdf7602011-03-20 04:57:14 +00002783 case Value::eValueTypeScalar:
2784 case Value::eValueTypeFileAddress:
2785 break;
2786
Chris Lattner24943d22010-06-08 16:52:24 +00002787 case Value::eValueTypeLoadAddress:
2788 switch (target_value_type)
2789 {
2790 case Value::eValueTypeLoadAddress:
2791 {
2792 DataBufferHeap data;
2793 data.SetByteSize(byte_size);
2794
2795 Error error;
Greg Clayton567e7f32011-09-22 04:58:26 +00002796 if (process->ReadMemory (source_addr, data.GetBytes(), byte_size, error) != byte_size)
Chris Lattner24943d22010-06-08 16:52:24 +00002797 {
2798 if (error_ptr)
2799 error_ptr->SetErrorStringWithFormat ("Couldn't read a composite type from the target: %s", error.AsCString());
2800 return false;
2801 }
2802
Greg Clayton567e7f32011-09-22 04:58:26 +00002803 if (process->WriteMemory (target_addr, data.GetBytes(), byte_size, error) != byte_size)
Chris Lattner24943d22010-06-08 16:52:24 +00002804 {
2805 if (error_ptr)
2806 error_ptr->SetErrorStringWithFormat ("Couldn't write a composite type to the target: %s", error.AsCString());
2807 return false;
2808 }
2809 }
2810 break;
2811 case Value::eValueTypeHostAddress:
Greg Clayton567e7f32011-09-22 04:58:26 +00002812 if (process->GetByteOrder() != lldb::endian::InlHostByteOrder())
Chris Lattner24943d22010-06-08 16:52:24 +00002813 {
2814 if (error_ptr)
2815 error_ptr->SetErrorStringWithFormat ("Copy of composite types between incompatible byte orders is unimplemented");
2816 return false;
2817 }
2818 else
2819 {
2820 Error error;
Greg Clayton567e7f32011-09-22 04:58:26 +00002821 if (process->ReadMemory (source_addr, (uint8_t*)target_addr, byte_size, error) != byte_size)
Chris Lattner24943d22010-06-08 16:52:24 +00002822 {
2823 if (error_ptr)
2824 error_ptr->SetErrorStringWithFormat ("Couldn't read a composite type from the target: %s", error.AsCString());
2825 return false;
2826 }
2827 }
2828 break;
2829 default:
2830 return false;
2831 }
2832 break;
2833 case Value::eValueTypeHostAddress:
2834 switch (target_value_type)
2835 {
2836 case Value::eValueTypeLoadAddress:
Greg Clayton567e7f32011-09-22 04:58:26 +00002837 if (process->GetByteOrder() != lldb::endian::InlHostByteOrder())
Chris Lattner24943d22010-06-08 16:52:24 +00002838 {
2839 if (error_ptr)
2840 error_ptr->SetErrorStringWithFormat ("Copy of composite types between incompatible byte orders is unimplemented");
2841 return false;
2842 }
2843 else
2844 {
2845 Error error;
Greg Clayton567e7f32011-09-22 04:58:26 +00002846 if (process->WriteMemory (target_addr, (uint8_t*)source_addr, byte_size, error) != byte_size)
Chris Lattner24943d22010-06-08 16:52:24 +00002847 {
2848 if (error_ptr)
2849 error_ptr->SetErrorStringWithFormat ("Couldn't write a composite type to the target: %s", error.AsCString());
2850 return false;
2851 }
2852 }
2853 case Value::eValueTypeHostAddress:
2854 memcpy ((uint8_t*)target_addr, (uint8_t*)source_addr, byte_size);
2855 break;
2856 default:
2857 return false;
2858 }
2859 }
2860 }
2861 else
2862 {
Greg Clayton1674b122010-07-21 22:12:05 +00002863 if (!ClangASTType::SetValueFromScalar (ast_context,
2864 clang_type,
2865 tmp.ResolveValue(exe_ctx, ast_context),
2866 new_value))
Chris Lattner24943d22010-06-08 16:52:24 +00002867 {
2868 if (error_ptr)
2869 error_ptr->SetErrorStringWithFormat ("Couldn't extract a value from an integral type.\n");
2870 return false;
2871 }
2872
2873 Value::ValueType value_type = stack.back().GetValueType();
2874
2875 switch (value_type)
2876 {
2877 case Value::eValueTypeLoadAddress:
2878 case Value::eValueTypeHostAddress:
2879 {
Greg Claytonb3448432011-03-24 21:19:54 +00002880 AddressType address_type = (value_type == Value::eValueTypeLoadAddress ? eAddressTypeLoad : eAddressTypeHost);
Chris Lattner24943d22010-06-08 16:52:24 +00002881 lldb::addr_t addr = stack.back().GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton1674b122010-07-21 22:12:05 +00002882 if (!ClangASTType::WriteToMemory (ast_context,
2883 clang_type,
2884 exe_ctx,
2885 addr,
2886 address_type,
2887 new_value))
Chris Lattner24943d22010-06-08 16:52:24 +00002888 {
2889 if (error_ptr)
2890 error_ptr->SetErrorStringWithFormat ("Failed to write value to memory at 0x%llx.\n", addr);
2891 return false;
2892 }
2893 }
2894 break;
2895
2896 default:
2897 break;
2898 }
2899 }
2900 }
2901 break;
2902
2903 default:
2904 if (error_ptr)
2905 error_ptr->SetErrorString ("Assign failed.");
2906 return false;
2907 }
2908 }
2909 break;
2910
2911 //----------------------------------------------------------------------
2912 // OPCODE: DW_OP_APPLE_address_of
2913 // OPERANDS: none
2914 // DESCRIPTION: Pops a value off of the stack and pushed its address.
2915 // The top item on the stack must be a variable, or already be a memory
2916 // location.
2917 //----------------------------------------------------------------------
2918 case DW_OP_APPLE_address_of:
2919 if (stack.empty())
2920 {
2921 if (error_ptr)
2922 error_ptr->SetErrorString("Expression stack needs at least 1 item for DW_OP_APPLE_address_of.");
2923 return false;
2924 }
2925 else
2926 {
2927 Value::ValueType value_type = stack.back().GetValueType();
2928 switch (value_type)
2929 {
2930 default:
2931 case Value::eValueTypeScalar: // raw scalar value
2932 if (error_ptr)
2933 error_ptr->SetErrorString("Top stack item isn't a memory based object.");
2934 return false;
2935
2936 case Value::eValueTypeLoadAddress: // load address value
2937 case Value::eValueTypeFileAddress: // file address value
2938 case Value::eValueTypeHostAddress: // host address value (for memory in the process that is using liblldb)
2939 // Taking the address of an object reduces it to the address
2940 // of the value and removes any extra context it had.
2941 //stack.back().SetValueType(Value::eValueTypeScalar);
2942 stack.back().ClearContext();
2943 break;
2944 }
2945 }
2946 break;
2947
2948 //----------------------------------------------------------------------
2949 // OPCODE: DW_OP_APPLE_value_of
2950 // OPERANDS: none
2951 // DESCRIPTION: Pops a value off of the stack and pushed its value.
2952 // The top item on the stack must be a variable, expression variable.
2953 //----------------------------------------------------------------------
2954 case DW_OP_APPLE_value_of:
2955 if (stack.empty())
2956 {
2957 if (error_ptr)
2958 error_ptr->SetErrorString("Expression stack needs at least 1 items for DW_OP_APPLE_value_of.");
2959 return false;
2960 }
2961 else if (!stack.back().ValueOf(exe_ctx, ast_context))
2962 {
2963 if (error_ptr)
2964 error_ptr->SetErrorString ("Top stack item isn't a valid candidate for DW_OP_APPLE_value_of.");
2965 return false;
2966 }
2967 break;
2968
2969 //----------------------------------------------------------------------
2970 // OPCODE: DW_OP_APPLE_deref_type
2971 // OPERANDS: none
2972 // DESCRIPTION: gets the value pointed to by the top stack item
2973 //----------------------------------------------------------------------
2974 case DW_OP_APPLE_deref_type:
2975 {
2976 if (stack.empty())
2977 {
2978 if (error_ptr)
2979 error_ptr->SetErrorString("Expression stack needs at least 1 items for DW_OP_APPLE_deref_type.");
2980 return false;
2981 }
2982
2983 tmp = stack.back();
2984 stack.pop_back();
2985
Greg Clayton6916e352010-11-13 03:52:47 +00002986 if (tmp.GetContextType() != Value::eContextTypeClangType)
Chris Lattner24943d22010-06-08 16:52:24 +00002987 {
2988 if (error_ptr)
2989 error_ptr->SetErrorString("Item at top of expression stack must have a Clang type");
2990 return false;
2991 }
2992
Greg Clayton462d4142010-09-29 01:12:09 +00002993 void *ptr_type = tmp.GetClangType();
Chris Lattner24943d22010-06-08 16:52:24 +00002994 void *target_type;
2995
2996 if (!ClangASTContext::IsPointerType(ptr_type, &target_type))
2997 {
2998 if (error_ptr)
2999 error_ptr->SetErrorString("Dereferencing a non-pointer type");
3000 return false;
3001 }
3002
3003 // TODO do we want all pointers to be dereferenced as load addresses?
3004 Value::ValueType value_type = tmp.GetValueType();
3005
3006 tmp.ResolveValue(exe_ctx, ast_context);
3007
3008 tmp.SetValueType(value_type);
Greg Clayton6916e352010-11-13 03:52:47 +00003009 tmp.SetContext(Value::eContextTypeClangType, target_type);
Chris Lattner24943d22010-06-08 16:52:24 +00003010
3011 stack.push_back(tmp);
3012 }
3013 break;
3014
3015 //----------------------------------------------------------------------
3016 // OPCODE: DW_OP_APPLE_expr_local
3017 // OPERANDS: ULEB128
3018 // DESCRIPTION: pushes the expression local variable index onto the
3019 // stack and set the appropriate context so we know the stack item is
3020 // an expression local variable index.
3021 //----------------------------------------------------------------------
3022 case DW_OP_APPLE_expr_local:
3023 {
Sean Callanana6223432010-08-20 01:02:30 +00003024 /*
Chris Lattner24943d22010-06-08 16:52:24 +00003025 uint32_t idx = opcodes.GetULEB128(&offset);
3026 if (expr_locals == NULL)
3027 {
3028 if (error_ptr)
3029 error_ptr->SetErrorStringWithFormat ("DW_OP_APPLE_expr_local(%u) opcode encountered with no local variable list.\n", idx);
3030 return false;
3031 }
3032 Value *expr_local_variable = expr_locals->GetVariableAtIndex(idx);
3033 if (expr_local_variable == NULL)
3034 {
3035 if (error_ptr)
3036 error_ptr->SetErrorStringWithFormat ("DW_OP_APPLE_expr_local(%u) with invalid index %u.\n", idx, idx);
3037 return false;
3038 }
Greg Clayton801417e2011-07-07 01:59:51 +00003039 // The proxy code has been removed. If it is ever re-added, please
3040 // use shared pointers or return by value to avoid possible memory
3041 // leak (there is no leak here, but in general, no returning pointers
3042 // that must be manually freed please.
Chris Lattner24943d22010-06-08 16:52:24 +00003043 Value *proxy = expr_local_variable->CreateProxy();
3044 stack.push_back(*proxy);
3045 delete proxy;
Greg Clayton6916e352010-11-13 03:52:47 +00003046 //stack.back().SetContext (Value::eContextTypeClangType, expr_local_variable->GetClangType());
Sean Callanana6223432010-08-20 01:02:30 +00003047 */
Chris Lattner24943d22010-06-08 16:52:24 +00003048 }
3049 break;
3050
3051 //----------------------------------------------------------------------
3052 // OPCODE: DW_OP_APPLE_extern
3053 // OPERANDS: ULEB128
3054 // DESCRIPTION: pushes a proxy for the extern object index onto the
3055 // stack.
3056 //----------------------------------------------------------------------
3057 case DW_OP_APPLE_extern:
3058 {
Sean Callanan8c127202010-08-23 23:09:38 +00003059 /*
Chris Lattner24943d22010-06-08 16:52:24 +00003060 uint32_t idx = opcodes.GetULEB128(&offset);
3061 if (!decl_map)
3062 {
3063 if (error_ptr)
3064 error_ptr->SetErrorStringWithFormat ("DW_OP_APPLE_extern(%u) opcode encountered with no decl map.\n", idx);
3065 return false;
3066 }
3067 Value *extern_var = decl_map->GetValueForIndex(idx);
3068 if (!extern_var)
3069 {
3070 if (error_ptr)
3071 error_ptr->SetErrorStringWithFormat ("DW_OP_APPLE_extern(%u) with invalid index %u.\n", idx, idx);
3072 return false;
3073 }
Greg Clayton801417e2011-07-07 01:59:51 +00003074 // The proxy code has been removed. If it is ever re-added, please
3075 // use shared pointers or return by value to avoid possible memory
3076 // leak (there is no leak here, but in general, no returning pointers
3077 // that must be manually freed please.
Chris Lattner24943d22010-06-08 16:52:24 +00003078 Value *proxy = extern_var->CreateProxy();
3079 stack.push_back(*proxy);
3080 delete proxy;
Sean Callanan8c127202010-08-23 23:09:38 +00003081 */
Chris Lattner24943d22010-06-08 16:52:24 +00003082 }
3083 break;
3084
3085 case DW_OP_APPLE_scalar_cast:
3086 if (stack.empty())
3087 {
3088 if (error_ptr)
3089 error_ptr->SetErrorString("Expression stack needs at least 1 item for DW_OP_APPLE_scalar_cast.");
3090 return false;
3091 }
3092 else
3093 {
3094 // Simple scalar cast
3095 if (!stack.back().ResolveValue(exe_ctx, ast_context).Cast((Scalar::Type)opcodes.GetU8(&offset)))
3096 {
3097 if (error_ptr)
3098 error_ptr->SetErrorString("Cast failed.");
3099 return false;
3100 }
3101 }
3102 break;
3103
3104
3105 case DW_OP_APPLE_clang_cast:
3106 if (stack.empty())
3107 {
3108 if (error_ptr)
3109 error_ptr->SetErrorString("Expression stack needs at least 1 item for DW_OP_APPLE_clang_cast.");
3110 return false;
3111 }
3112 else
3113 {
3114 void *clang_type = (void *)opcodes.GetMaxU64(&offset, sizeof(void*));
Greg Clayton6916e352010-11-13 03:52:47 +00003115 stack.back().SetContext (Value::eContextTypeClangType, clang_type);
Chris Lattner24943d22010-06-08 16:52:24 +00003116 }
3117 break;
3118 //----------------------------------------------------------------------
3119 // OPCODE: DW_OP_APPLE_constf
3120 // OPERANDS: 1 byte float length, followed by that many bytes containing
3121 // the constant float data.
3122 // DESCRIPTION: Push a float value onto the expression stack.
3123 //----------------------------------------------------------------------
3124 case DW_OP_APPLE_constf: // 0xF6 - 1 byte float size, followed by constant float data
3125 {
3126 uint8_t float_length = opcodes.GetU8(&offset);
3127 if (sizeof(float) == float_length)
3128 tmp.ResolveValue(exe_ctx, ast_context) = opcodes.GetFloat (&offset);
3129 else if (sizeof(double) == float_length)
3130 tmp.ResolveValue(exe_ctx, ast_context) = opcodes.GetDouble (&offset);
3131 else if (sizeof(long double) == float_length)
3132 tmp.ResolveValue(exe_ctx, ast_context) = opcodes.GetLongDouble (&offset);
3133 else
3134 {
3135 StreamString new_value;
3136 opcodes.Dump(&new_value, offset, eFormatBytes, 1, float_length, UINT32_MAX, DW_INVALID_ADDRESS, 0, 0);
3137
3138 if (error_ptr)
3139 error_ptr->SetErrorStringWithFormat ("DW_OP_APPLE_constf(<%u> %s) unsupported float size.\n", float_length, new_value.GetData());
3140 return false;
3141 }
3142 tmp.SetValueType(Value::eValueTypeScalar);
3143 tmp.ClearContext();
3144 stack.push_back(tmp);
3145 }
3146 break;
3147 //----------------------------------------------------------------------
3148 // OPCODE: DW_OP_APPLE_clear
3149 // OPERANDS: none
3150 // DESCRIPTION: Clears the expression stack.
3151 //----------------------------------------------------------------------
3152 case DW_OP_APPLE_clear:
3153 stack.clear();
3154 break;
3155
3156 //----------------------------------------------------------------------
3157 // OPCODE: DW_OP_APPLE_error
3158 // OPERANDS: none
3159 // DESCRIPTION: Pops a value off of the stack and pushed its value.
3160 // The top item on the stack must be a variable, expression variable.
3161 //----------------------------------------------------------------------
3162 case DW_OP_APPLE_error: // 0xFF - Stops expression evaluation and returns an error (no args)
3163 if (error_ptr)
3164 error_ptr->SetErrorString ("Generic error.");
3165 return false;
Greg Claytona1b9a902011-11-13 04:15:56 +00003166#endif // #if 0
3167
Chris Lattner24943d22010-06-08 16:52:24 +00003168 }
3169 }
3170
3171 if (stack.empty())
3172 {
3173 if (error_ptr)
3174 error_ptr->SetErrorString ("Stack empty after evaluation.");
3175 return false;
3176 }
Sean Callanan67bbb112011-10-14 20:34:21 +00003177 else if (log && log->GetVerbose())
Chris Lattner24943d22010-06-08 16:52:24 +00003178 {
Chris Lattner24943d22010-06-08 16:52:24 +00003179 size_t count = stack.size();
Jason Molenda7e5fa7f2011-09-20 21:44:10 +00003180 log->Printf("Stack after operation has %lu values:", count);
Chris Lattner24943d22010-06-08 16:52:24 +00003181 for (size_t i=0; i<count; ++i)
3182 {
3183 StreamString new_value;
3184 new_value.Printf("[%zu]", i);
3185 stack[i].Dump(&new_value);
Sean Callanan6184dfe2010-06-23 00:47:48 +00003186 log->Printf(" %s", new_value.GetData());
Chris Lattner24943d22010-06-08 16:52:24 +00003187 }
3188 }
3189
3190 result = stack.back();
3191 return true; // Return true on success
3192}
3193