blob: 1ff6e8e138b4f585d7977b7c4b9959c5ef2c598f [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 Clayton178710c2010-09-14 02:20:48 +0000264DWARFExpression::SetOpcodeData (const DataExtractor& data, uint32_t data_offset, uint32_t data_length)
Chris Lattner24943d22010-06-08 16:52:24 +0000265{
266 m_data.SetData(data, data_offset, data_length);
Chris Lattner24943d22010-06-08 16:52:24 +0000267}
268
269void
Greg Clayton5c3861d2011-09-02 01:15:17 +0000270DWARFExpression::DumpLocation (Stream *s, uint32_t offset, uint32_t length, lldb::DescriptionLevel level, ABI *abi) const
Chris Lattner24943d22010-06-08 16:52:24 +0000271{
272 if (!m_data.ValidOffsetForDataOfSize(offset, length))
273 return;
274 const uint32_t start_offset = offset;
275 const uint32_t end_offset = offset + length;
276 while (m_data.ValidOffset(offset) && offset < end_offset)
277 {
278 const uint32_t op_offset = offset;
279 const uint8_t op = m_data.GetU8(&offset);
280
281 switch (level)
282 {
Greg Clayton54e7afa2010-07-09 20:39:50 +0000283 default:
284 break;
285
Chris Lattner24943d22010-06-08 16:52:24 +0000286 case lldb::eDescriptionLevelBrief:
287 if (offset > start_offset)
288 s->PutChar(' ');
289 break;
290
291 case lldb::eDescriptionLevelFull:
292 case lldb::eDescriptionLevelVerbose:
293 if (offset > start_offset)
294 s->EOL();
295 s->Indent();
296 if (level == lldb::eDescriptionLevelFull)
297 break;
298 // Fall through for verbose and print offset and DW_OP prefix..
299 s->Printf("0x%8.8x: %s", op_offset, op >= DW_OP_APPLE_uninit ? "DW_OP_APPLE_" : "DW_OP_");
300 break;
301 }
302
303 switch (op)
304 {
Greg Clayton9b82f862011-07-11 05:12:02 +0000305 case DW_OP_addr: *s << "DW_OP_addr(" << m_data.GetAddress(&offset) << ") "; break; // 0x03 1 address
306 case DW_OP_deref: *s << "DW_OP_deref"; break; // 0x06
307 case DW_OP_const1u: s->Printf("DW_OP_const1u(0x%2.2x) ", m_data.GetU8(&offset)); break; // 0x08 1 1-byte constant
308 case DW_OP_const1s: s->Printf("DW_OP_const1s(0x%2.2x) ", m_data.GetU8(&offset)); break; // 0x09 1 1-byte constant
309 case DW_OP_const2u: s->Printf("DW_OP_const2u(0x%4.4x) ", m_data.GetU16(&offset)); break; // 0x0a 1 2-byte constant
310 case DW_OP_const2s: s->Printf("DW_OP_const2s(0x%4.4x) ", m_data.GetU16(&offset)); break; // 0x0b 1 2-byte constant
311 case DW_OP_const4u: s->Printf("DW_OP_const4u(0x%8.8x) ", m_data.GetU32(&offset)); break; // 0x0c 1 4-byte constant
312 case DW_OP_const4s: s->Printf("DW_OP_const4s(0x%8.8x) ", m_data.GetU32(&offset)); break; // 0x0d 1 4-byte constant
313 case DW_OP_const8u: s->Printf("DW_OP_const8u(0x%16.16llx) ", m_data.GetU64(&offset)); break; // 0x0e 1 8-byte constant
314 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 +0000315 case DW_OP_constu: s->Printf("DW_OP_constu(0x%llx) ", m_data.GetULEB128(&offset)); break; // 0x10 1 ULEB128 constant
316 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 +0000317 case DW_OP_dup: s->PutCString("DW_OP_dup"); break; // 0x12
318 case DW_OP_drop: s->PutCString("DW_OP_drop"); break; // 0x13
319 case DW_OP_over: s->PutCString("DW_OP_over"); break; // 0x14
320 case DW_OP_pick: s->Printf("DW_OP_pick(0x%2.2x) ", m_data.GetU8(&offset)); break; // 0x15 1 1-byte stack index
321 case DW_OP_swap: s->PutCString("DW_OP_swap"); break; // 0x16
322 case DW_OP_rot: s->PutCString("DW_OP_rot"); break; // 0x17
323 case DW_OP_xderef: s->PutCString("DW_OP_xderef"); break; // 0x18
324 case DW_OP_abs: s->PutCString("DW_OP_abs"); break; // 0x19
325 case DW_OP_and: s->PutCString("DW_OP_and"); break; // 0x1a
326 case DW_OP_div: s->PutCString("DW_OP_div"); break; // 0x1b
327 case DW_OP_minus: s->PutCString("DW_OP_minus"); break; // 0x1c
328 case DW_OP_mod: s->PutCString("DW_OP_mod"); break; // 0x1d
329 case DW_OP_mul: s->PutCString("DW_OP_mul"); break; // 0x1e
330 case DW_OP_neg: s->PutCString("DW_OP_neg"); break; // 0x1f
331 case DW_OP_not: s->PutCString("DW_OP_not"); break; // 0x20
332 case DW_OP_or: s->PutCString("DW_OP_or"); break; // 0x21
333 case DW_OP_plus: s->PutCString("DW_OP_plus"); break; // 0x22
Chris Lattner24943d22010-06-08 16:52:24 +0000334 case DW_OP_plus_uconst: // 0x23 1 ULEB128 addend
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000335 s->Printf("DW_OP_plus_uconst(0x%llx) ", m_data.GetULEB128(&offset));
Chris Lattner24943d22010-06-08 16:52:24 +0000336 break;
337
Greg Clayton9b82f862011-07-11 05:12:02 +0000338 case DW_OP_shl: s->PutCString("DW_OP_shl"); break; // 0x24
339 case DW_OP_shr: s->PutCString("DW_OP_shr"); break; // 0x25
340 case DW_OP_shra: s->PutCString("DW_OP_shra"); break; // 0x26
341 case DW_OP_xor: s->PutCString("DW_OP_xor"); break; // 0x27
342 case DW_OP_skip: s->Printf("DW_OP_skip(0x%4.4x)", m_data.GetU16(&offset)); break; // 0x2f 1 signed 2-byte constant
343 case DW_OP_bra: s->Printf("DW_OP_bra(0x%4.4x)", m_data.GetU16(&offset)); break; // 0x28 1 signed 2-byte constant
344 case DW_OP_eq: s->PutCString("DW_OP_eq"); break; // 0x29
345 case DW_OP_ge: s->PutCString("DW_OP_ge"); break; // 0x2a
346 case DW_OP_gt: s->PutCString("DW_OP_gt"); break; // 0x2b
347 case DW_OP_le: s->PutCString("DW_OP_le"); break; // 0x2c
348 case DW_OP_lt: s->PutCString("DW_OP_lt"); break; // 0x2d
349 case DW_OP_ne: s->PutCString("DW_OP_ne"); break; // 0x2e
Chris Lattner24943d22010-06-08 16:52:24 +0000350
351 case DW_OP_lit0: // 0x30
352 case DW_OP_lit1: // 0x31
353 case DW_OP_lit2: // 0x32
354 case DW_OP_lit3: // 0x33
355 case DW_OP_lit4: // 0x34
356 case DW_OP_lit5: // 0x35
357 case DW_OP_lit6: // 0x36
358 case DW_OP_lit7: // 0x37
359 case DW_OP_lit8: // 0x38
360 case DW_OP_lit9: // 0x39
361 case DW_OP_lit10: // 0x3A
362 case DW_OP_lit11: // 0x3B
363 case DW_OP_lit12: // 0x3C
364 case DW_OP_lit13: // 0x3D
365 case DW_OP_lit14: // 0x3E
366 case DW_OP_lit15: // 0x3F
367 case DW_OP_lit16: // 0x40
368 case DW_OP_lit17: // 0x41
369 case DW_OP_lit18: // 0x42
370 case DW_OP_lit19: // 0x43
371 case DW_OP_lit20: // 0x44
372 case DW_OP_lit21: // 0x45
373 case DW_OP_lit22: // 0x46
374 case DW_OP_lit23: // 0x47
375 case DW_OP_lit24: // 0x48
376 case DW_OP_lit25: // 0x49
377 case DW_OP_lit26: // 0x4A
378 case DW_OP_lit27: // 0x4B
379 case DW_OP_lit28: // 0x4C
380 case DW_OP_lit29: // 0x4D
381 case DW_OP_lit30: // 0x4E
Greg Clayton9b82f862011-07-11 05:12:02 +0000382 case DW_OP_lit31: s->Printf("DW_OP_lit%i", op - DW_OP_lit0); break; // 0x4f
Chris Lattner24943d22010-06-08 16:52:24 +0000383
384 case DW_OP_reg0: // 0x50
385 case DW_OP_reg1: // 0x51
386 case DW_OP_reg2: // 0x52
387 case DW_OP_reg3: // 0x53
388 case DW_OP_reg4: // 0x54
389 case DW_OP_reg5: // 0x55
390 case DW_OP_reg6: // 0x56
391 case DW_OP_reg7: // 0x57
392 case DW_OP_reg8: // 0x58
393 case DW_OP_reg9: // 0x59
394 case DW_OP_reg10: // 0x5A
395 case DW_OP_reg11: // 0x5B
396 case DW_OP_reg12: // 0x5C
397 case DW_OP_reg13: // 0x5D
398 case DW_OP_reg14: // 0x5E
399 case DW_OP_reg15: // 0x5F
400 case DW_OP_reg16: // 0x60
401 case DW_OP_reg17: // 0x61
402 case DW_OP_reg18: // 0x62
403 case DW_OP_reg19: // 0x63
404 case DW_OP_reg20: // 0x64
405 case DW_OP_reg21: // 0x65
406 case DW_OP_reg22: // 0x66
407 case DW_OP_reg23: // 0x67
408 case DW_OP_reg24: // 0x68
409 case DW_OP_reg25: // 0x69
410 case DW_OP_reg26: // 0x6A
411 case DW_OP_reg27: // 0x6B
412 case DW_OP_reg28: // 0x6C
413 case DW_OP_reg29: // 0x6D
414 case DW_OP_reg30: // 0x6E
Greg Clayton5c3861d2011-09-02 01:15:17 +0000415 case DW_OP_reg31: // 0x6F
416 {
417 uint32_t reg_num = op - DW_OP_reg0;
418 if (abi)
419 {
420 RegisterInfo reg_info;
421 if (abi->GetRegisterInfoByKind(m_reg_kind, reg_num, reg_info))
422 {
423 if (reg_info.name)
424 {
425 s->PutCString (reg_info.name);
426 break;
427 }
428 else if (reg_info.alt_name)
429 {
430 s->PutCString (reg_info.alt_name);
431 break;
432 }
433 }
434 }
435 s->Printf("DW_OP_reg%u", reg_num); break;
436 }
437 break;
Chris Lattner24943d22010-06-08 16:52:24 +0000438
439 case DW_OP_breg0:
440 case DW_OP_breg1:
441 case DW_OP_breg2:
442 case DW_OP_breg3:
443 case DW_OP_breg4:
444 case DW_OP_breg5:
445 case DW_OP_breg6:
446 case DW_OP_breg7:
447 case DW_OP_breg8:
448 case DW_OP_breg9:
449 case DW_OP_breg10:
450 case DW_OP_breg11:
451 case DW_OP_breg12:
452 case DW_OP_breg13:
453 case DW_OP_breg14:
454 case DW_OP_breg15:
455 case DW_OP_breg16:
456 case DW_OP_breg17:
457 case DW_OP_breg18:
458 case DW_OP_breg19:
459 case DW_OP_breg20:
460 case DW_OP_breg21:
461 case DW_OP_breg22:
462 case DW_OP_breg23:
463 case DW_OP_breg24:
464 case DW_OP_breg25:
465 case DW_OP_breg26:
466 case DW_OP_breg27:
467 case DW_OP_breg28:
468 case DW_OP_breg29:
469 case DW_OP_breg30:
Greg Clayton5c3861d2011-09-02 01:15:17 +0000470 case DW_OP_breg31:
471 {
472 uint32_t reg_num = op - DW_OP_breg0;
473 int64_t reg_offset = m_data.GetSLEB128(&offset);
474 if (abi)
475 {
476 RegisterInfo reg_info;
477 if (abi->GetRegisterInfoByKind(m_reg_kind, reg_num, reg_info))
478 {
479 if (reg_info.name)
480 {
481 s->Printf("[%s%+lli]", reg_info.name, reg_offset);
482 break;
483 }
484 else if (reg_info.alt_name)
485 {
486 s->Printf("[%s%+lli]", reg_info.alt_name, reg_offset);
487 break;
488 }
489 }
490 }
491 s->Printf("DW_OP_breg%i(0x%llx)", reg_num, reg_offset);
492 }
493 break;
Chris Lattner24943d22010-06-08 16:52:24 +0000494
495 case DW_OP_regx: // 0x90 1 ULEB128 register
Greg Clayton5c3861d2011-09-02 01:15:17 +0000496 {
497 uint64_t reg_num = m_data.GetULEB128(&offset);
498 if (abi)
499 {
500 RegisterInfo reg_info;
501 if (abi->GetRegisterInfoByKind(m_reg_kind, reg_num, reg_info))
502 {
503 if (reg_info.name)
504 {
505 s->PutCString (reg_info.name);
506 break;
507 }
508 else if (reg_info.alt_name)
509 {
510 s->PutCString (reg_info.alt_name);
511 break;
512 }
513 }
514 }
515 s->Printf("DW_OP_regx(%llu)", reg_num); break;
516 }
Chris Lattner24943d22010-06-08 16:52:24 +0000517 break;
518 case DW_OP_fbreg: // 0x91 1 SLEB128 offset
Greg Clayton5c3861d2011-09-02 01:15:17 +0000519 s->Printf("DW_OP_fbreg(%lli)",m_data.GetSLEB128(&offset));
Chris Lattner24943d22010-06-08 16:52:24 +0000520 break;
521 case DW_OP_bregx: // 0x92 2 ULEB128 register followed by SLEB128 offset
Greg Clayton5c3861d2011-09-02 01:15:17 +0000522 {
523 uint32_t reg_num = m_data.GetULEB128(&offset);
524 int64_t reg_offset = m_data.GetSLEB128(&offset);
525 if (abi)
526 {
527 RegisterInfo reg_info;
528 if (abi->GetRegisterInfoByKind(m_reg_kind, reg_num, reg_info))
529 {
530 if (reg_info.name)
531 {
532 s->Printf("[%s%+lli]", reg_info.name, reg_offset);
533 break;
534 }
535 else if (reg_info.alt_name)
536 {
537 s->Printf("[%s%+lli]", reg_info.alt_name, reg_offset);
538 break;
539 }
540 }
541 }
542 s->Printf("DW_OP_bregx(reg=%u,offset=%lli)", reg_num, reg_offset);
543 }
Chris Lattner24943d22010-06-08 16:52:24 +0000544 break;
545 case DW_OP_piece: // 0x93 1 ULEB128 size of piece addressed
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000546 s->Printf("DW_OP_piece(0x%llx)", m_data.GetULEB128(&offset));
Chris Lattner24943d22010-06-08 16:52:24 +0000547 break;
548 case DW_OP_deref_size: // 0x94 1 1-byte size of data retrieved
Greg Clayton9b82f862011-07-11 05:12:02 +0000549 s->Printf("DW_OP_deref_size(0x%2.2x)", m_data.GetU8(&offset));
Chris Lattner24943d22010-06-08 16:52:24 +0000550 break;
551 case DW_OP_xderef_size: // 0x95 1 1-byte size of data retrieved
Greg Clayton9b82f862011-07-11 05:12:02 +0000552 s->Printf("DW_OP_xderef_size(0x%2.2x)", m_data.GetU8(&offset));
Chris Lattner24943d22010-06-08 16:52:24 +0000553 break;
Greg Clayton9b82f862011-07-11 05:12:02 +0000554 case DW_OP_nop: s->PutCString("DW_OP_nop"); break; // 0x96
555 case DW_OP_push_object_address: s->PutCString("DW_OP_push_object_address"); break; // 0x97 DWARF3
Chris Lattner24943d22010-06-08 16:52:24 +0000556 case DW_OP_call2: // 0x98 DWARF3 1 2-byte offset of DIE
Greg Clayton9b82f862011-07-11 05:12:02 +0000557 s->Printf("DW_OP_call2(0x%4.4x)", m_data.GetU16(&offset));
Chris Lattner24943d22010-06-08 16:52:24 +0000558 break;
559 case DW_OP_call4: // 0x99 DWARF3 1 4-byte offset of DIE
Greg Clayton9b82f862011-07-11 05:12:02 +0000560 s->Printf("DW_OP_call4(0x%8.8x)", m_data.GetU32(&offset));
Chris Lattner24943d22010-06-08 16:52:24 +0000561 break;
562 case DW_OP_call_ref: // 0x9a DWARF3 1 4- or 8-byte offset of DIE
Greg Clayton9b82f862011-07-11 05:12:02 +0000563 s->Printf("DW_OP_call_ref(0x%8.8llx)", m_data.GetAddress(&offset));
Chris Lattner24943d22010-06-08 16:52:24 +0000564 break;
565// case DW_OP_form_tls_address: s << "form_tls_address"; break; // 0x9b DWARF3
566// case DW_OP_call_frame_cfa: s << "call_frame_cfa"; break; // 0x9c DWARF3
567// case DW_OP_bit_piece: // 0x9d DWARF3 2
Greg Clayton9b82f862011-07-11 05:12:02 +0000568// 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 +0000569// break;
Greg Clayton9b82f862011-07-11 05:12:02 +0000570// case DW_OP_lo_user: s->PutCString("DW_OP_lo_user"); break; // 0xe0
571// case DW_OP_hi_user: s->PutCString("DW_OP_hi_user"); break; // 0xff
Greg Claytona1b9a902011-11-13 04:15:56 +0000572// case DW_OP_APPLE_extern:
573// s->Printf("DW_OP_APPLE_extern(%llu)", m_data.GetULEB128(&offset));
574// break;
575// case DW_OP_APPLE_array_ref:
576// s->PutCString("DW_OP_APPLE_array_ref");
577// break;
Chris Lattner24943d22010-06-08 16:52:24 +0000578 case DW_OP_APPLE_uninit:
Greg Clayton9b82f862011-07-11 05:12:02 +0000579 s->PutCString("DW_OP_APPLE_uninit"); // 0xF0
Chris Lattner24943d22010-06-08 16:52:24 +0000580 break;
Greg Claytona1b9a902011-11-13 04:15:56 +0000581// case DW_OP_APPLE_assign: // 0xF1 - pops value off and assigns it to second item on stack (2nd item must have assignable context)
582// s->PutCString("DW_OP_APPLE_assign");
583// break;
584// 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)
585// s->PutCString("DW_OP_APPLE_address_of");
586// break;
587// 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)
588// s->PutCString("DW_OP_APPLE_value_of");
589// break;
590// 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)
591// s->PutCString("DW_OP_APPLE_deref_type");
592// break;
593// case DW_OP_APPLE_expr_local: // 0xF5 - ULEB128 expression local index
594// s->Printf("DW_OP_APPLE_expr_local(%llu)", m_data.GetULEB128(&offset));
595// break;
596// case DW_OP_APPLE_constf: // 0xF6 - 1 byte float size, followed by constant float data
597// {
598// uint8_t float_length = m_data.GetU8(&offset);
599// s->Printf("DW_OP_APPLE_constf(<%u> ", float_length);
600// m_data.Dump(s, offset, eFormatHex, float_length, 1, UINT32_MAX, DW_INVALID_ADDRESS, 0, 0);
601// s->PutChar(')');
602// // Consume the float data
603// m_data.GetData(&offset, float_length);
604// }
605// break;
606// case DW_OP_APPLE_scalar_cast:
607// s->Printf("DW_OP_APPLE_scalar_cast(%s)", Scalar::GetValueTypeAsCString ((Scalar::Type)m_data.GetU8(&offset)));
608// break;
609// case DW_OP_APPLE_clang_cast:
610// {
611// clang::Type *clang_type = (clang::Type *)m_data.GetMaxU64(&offset, sizeof(void*));
612// s->Printf("DW_OP_APPLE_clang_cast(%p)", clang_type);
613// }
614// break;
615// case DW_OP_APPLE_clear:
616// s->PutCString("DW_OP_APPLE_clear");
617// break;
618// case DW_OP_APPLE_error: // 0xFF - Stops expression evaluation and returns an error (no args)
619// s->PutCString("DW_OP_APPLE_error");
620// break;
Chris Lattner24943d22010-06-08 16:52:24 +0000621 }
622 }
623}
624
625void
Greg Clayton178710c2010-09-14 02:20:48 +0000626DWARFExpression::SetLocationListSlide (addr_t slide)
Chris Lattner24943d22010-06-08 16:52:24 +0000627{
Greg Clayton178710c2010-09-14 02:20:48 +0000628 m_loclist_slide = slide;
Chris Lattner24943d22010-06-08 16:52:24 +0000629}
630
631int
632DWARFExpression::GetRegisterKind ()
633{
634 return m_reg_kind;
635}
636
637void
Greg Clayton5c3861d2011-09-02 01:15:17 +0000638DWARFExpression::SetRegisterKind (RegisterKind reg_kind)
Chris Lattner24943d22010-06-08 16:52:24 +0000639{
640 m_reg_kind = reg_kind;
641}
642
643bool
644DWARFExpression::IsLocationList() const
645{
Greg Clayton178710c2010-09-14 02:20:48 +0000646 return m_loclist_slide != LLDB_INVALID_ADDRESS;
Chris Lattner24943d22010-06-08 16:52:24 +0000647}
648
649void
Greg Clayton5c3861d2011-09-02 01:15:17 +0000650DWARFExpression::GetDescription (Stream *s, lldb::DescriptionLevel level, addr_t location_list_base_addr, ABI *abi) const
Chris Lattner24943d22010-06-08 16:52:24 +0000651{
652 if (IsLocationList())
653 {
654 // We have a location list
655 uint32_t offset = 0;
656 uint32_t count = 0;
Greg Clayton178710c2010-09-14 02:20:48 +0000657 addr_t curr_base_addr = location_list_base_addr;
Chris Lattner24943d22010-06-08 16:52:24 +0000658 while (m_data.ValidOffset(offset))
659 {
660 lldb::addr_t begin_addr_offset = m_data.GetAddress(&offset);
661 lldb::addr_t end_addr_offset = m_data.GetAddress(&offset);
662 if (begin_addr_offset < end_addr_offset)
663 {
664 if (count > 0)
665 s->PutCString(", ");
Greg Clayton178710c2010-09-14 02:20:48 +0000666 VMRange addr_range(curr_base_addr + begin_addr_offset, curr_base_addr + end_addr_offset);
667 addr_range.Dump(s, 0, 8);
Chris Lattner24943d22010-06-08 16:52:24 +0000668 s->PutChar('{');
669 uint32_t location_length = m_data.GetU16(&offset);
Greg Clayton5c3861d2011-09-02 01:15:17 +0000670 DumpLocation (s, offset, location_length, level, abi);
Chris Lattner24943d22010-06-08 16:52:24 +0000671 s->PutChar('}');
672 offset += location_length;
673 }
674 else if (begin_addr_offset == 0 && end_addr_offset == 0)
675 {
676 // The end of the location list is marked by both the start and end offset being zero
677 break;
678 }
679 else
680 {
Greg Claytonb3448432011-03-24 21:19:54 +0000681 if ((m_data.GetAddressByteSize() == 4 && (begin_addr_offset == UINT32_MAX)) ||
682 (m_data.GetAddressByteSize() == 8 && (begin_addr_offset == UINT64_MAX)))
Chris Lattner24943d22010-06-08 16:52:24 +0000683 {
Greg Clayton178710c2010-09-14 02:20:48 +0000684 curr_base_addr = end_addr_offset + location_list_base_addr;
Chris Lattner24943d22010-06-08 16:52:24 +0000685 // We have a new base address
686 if (count > 0)
687 s->PutCString(", ");
688 *s << "base_addr = " << end_addr_offset;
689 }
690 }
691
692 count++;
693 }
694 }
695 else
696 {
697 // We have a normal location that contains DW_OP location opcodes
Greg Clayton5c3861d2011-09-02 01:15:17 +0000698 DumpLocation (s, 0, m_data.GetByteSize(), level, abi);
Chris Lattner24943d22010-06-08 16:52:24 +0000699 }
700}
701
702static bool
703ReadRegisterValueAsScalar
704(
Greg Clayton061b79d2011-05-09 20:18:18 +0000705 RegisterContext *reg_ctx,
Chris Lattner24943d22010-06-08 16:52:24 +0000706 uint32_t reg_kind,
707 uint32_t reg_num,
708 Error *error_ptr,
709 Value &value
710)
711{
Greg Clayton061b79d2011-05-09 20:18:18 +0000712 if (reg_ctx == NULL)
Chris Lattner24943d22010-06-08 16:52:24 +0000713 {
Jason Molenda8e69de42010-11-20 01:28:30 +0000714 if (error_ptr)
715 error_ptr->SetErrorStringWithFormat("No register context in frame.\n");
Chris Lattner24943d22010-06-08 16:52:24 +0000716 }
717 else
718 {
Greg Clayton061b79d2011-05-09 20:18:18 +0000719 uint32_t native_reg = reg_ctx->ConvertRegisterKindToRegisterNumber(reg_kind, reg_num);
Jason Molenda8e69de42010-11-20 01:28:30 +0000720 if (native_reg == LLDB_INVALID_REGNUM)
721 {
722 if (error_ptr)
723 error_ptr->SetErrorStringWithFormat("Unable to convert register kind=%u reg_num=%u to a native register number.\n", reg_kind, reg_num);
724 }
725 else
726 {
Greg Clayton061b79d2011-05-09 20:18:18 +0000727 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex(native_reg);
728 RegisterValue reg_value;
729 if (reg_ctx->ReadRegister (reg_info, reg_value))
730 {
731 if (reg_value.GetScalarValue(value.GetScalar()))
732 {
733 value.SetValueType (Value::eValueTypeScalar);
Greg Clayton82f07462011-05-30 00:49:24 +0000734 value.SetContext (Value::eContextTypeRegisterInfo,
735 const_cast<RegisterInfo *>(reg_info));
Greg Clayton061b79d2011-05-09 20:18:18 +0000736 if (error_ptr)
737 error_ptr->Clear();
738 return true;
739 }
740 else
741 {
Greg Clayton82f07462011-05-30 00:49:24 +0000742 // If we get this error, then we need to implement a value
743 // buffer in the dwarf expression evaluation function...
Greg Clayton061b79d2011-05-09 20:18:18 +0000744 if (error_ptr)
Greg Clayton82f07462011-05-30 00:49:24 +0000745 error_ptr->SetErrorStringWithFormat ("register %s can't be converted to a scalar value",
746 reg_info->name);
Greg Clayton061b79d2011-05-09 20:18:18 +0000747 }
748 }
749 else
750 {
751 if (error_ptr)
Greg Clayton82f07462011-05-30 00:49:24 +0000752 error_ptr->SetErrorStringWithFormat("register %s is not available", reg_info->name);
Greg Clayton061b79d2011-05-09 20:18:18 +0000753 }
Jason Molenda8e69de42010-11-20 01:28:30 +0000754 }
Chris Lattner24943d22010-06-08 16:52:24 +0000755 }
756 return false;
757}
758
Greg Clayton178710c2010-09-14 02:20:48 +0000759//bool
760//DWARFExpression::LocationListContainsLoadAddress (Process* process, const Address &addr) const
761//{
762// return LocationListContainsLoadAddress(process, addr.GetLoadAddress(process));
763//}
764//
765//bool
766//DWARFExpression::LocationListContainsLoadAddress (Process* process, addr_t load_addr) const
767//{
768// if (load_addr == LLDB_INVALID_ADDRESS)
769// return false;
770//
771// if (IsLocationList())
772// {
773// uint32_t offset = 0;
774//
775// addr_t loc_list_base_addr = m_loclist_slide.GetLoadAddress(process);
776//
777// if (loc_list_base_addr == LLDB_INVALID_ADDRESS)
778// return false;
779//
780// while (m_data.ValidOffset(offset))
781// {
782// // We need to figure out what the value is for the location.
783// addr_t lo_pc = m_data.GetAddress(&offset);
784// addr_t hi_pc = m_data.GetAddress(&offset);
785// if (lo_pc == 0 && hi_pc == 0)
786// break;
787// else
788// {
789// lo_pc += loc_list_base_addr;
790// hi_pc += loc_list_base_addr;
791//
792// if (lo_pc <= load_addr && load_addr < hi_pc)
793// return true;
794//
795// offset += m_data.GetU16(&offset);
796// }
797// }
798// }
799// return false;
800//}
Greg Claytonb04e7a82010-08-24 21:05:24 +0000801
Greg Claytona1b9a902011-11-13 04:15:56 +0000802static uint32_t
803GetOpcodeDataSize (const DataExtractor &data, const uint32_t data_offset, const uint8_t op)
804{
805 uint32_t offset = data_offset;
806 switch (op)
807 {
808 case DW_OP_addr:
809 case DW_OP_call_ref: // 0x9a 1 address sized offset of DIE (DWARF3)
810 return data.GetAddressByteSize();
811
812 // Opcodes with no arguments
813 case DW_OP_deref: // 0x06
814 case DW_OP_dup: // 0x12
815 case DW_OP_drop: // 0x13
816 case DW_OP_over: // 0x14
817 case DW_OP_swap: // 0x16
818 case DW_OP_rot: // 0x17
819 case DW_OP_xderef: // 0x18
820 case DW_OP_abs: // 0x19
821 case DW_OP_and: // 0x1a
822 case DW_OP_div: // 0x1b
823 case DW_OP_minus: // 0x1c
824 case DW_OP_mod: // 0x1d
825 case DW_OP_mul: // 0x1e
826 case DW_OP_neg: // 0x1f
827 case DW_OP_not: // 0x20
828 case DW_OP_or: // 0x21
829 case DW_OP_plus: // 0x22
830 case DW_OP_shl: // 0x24
831 case DW_OP_shr: // 0x25
832 case DW_OP_shra: // 0x26
833 case DW_OP_xor: // 0x27
834 case DW_OP_eq: // 0x29
835 case DW_OP_ge: // 0x2a
836 case DW_OP_gt: // 0x2b
837 case DW_OP_le: // 0x2c
838 case DW_OP_lt: // 0x2d
839 case DW_OP_ne: // 0x2e
840 case DW_OP_lit0: // 0x30
841 case DW_OP_lit1: // 0x31
842 case DW_OP_lit2: // 0x32
843 case DW_OP_lit3: // 0x33
844 case DW_OP_lit4: // 0x34
845 case DW_OP_lit5: // 0x35
846 case DW_OP_lit6: // 0x36
847 case DW_OP_lit7: // 0x37
848 case DW_OP_lit8: // 0x38
849 case DW_OP_lit9: // 0x39
850 case DW_OP_lit10: // 0x3A
851 case DW_OP_lit11: // 0x3B
852 case DW_OP_lit12: // 0x3C
853 case DW_OP_lit13: // 0x3D
854 case DW_OP_lit14: // 0x3E
855 case DW_OP_lit15: // 0x3F
856 case DW_OP_lit16: // 0x40
857 case DW_OP_lit17: // 0x41
858 case DW_OP_lit18: // 0x42
859 case DW_OP_lit19: // 0x43
860 case DW_OP_lit20: // 0x44
861 case DW_OP_lit21: // 0x45
862 case DW_OP_lit22: // 0x46
863 case DW_OP_lit23: // 0x47
864 case DW_OP_lit24: // 0x48
865 case DW_OP_lit25: // 0x49
866 case DW_OP_lit26: // 0x4A
867 case DW_OP_lit27: // 0x4B
868 case DW_OP_lit28: // 0x4C
869 case DW_OP_lit29: // 0x4D
870 case DW_OP_lit30: // 0x4E
871 case DW_OP_lit31: // 0x4f
872 case DW_OP_reg0: // 0x50
873 case DW_OP_reg1: // 0x51
874 case DW_OP_reg2: // 0x52
875 case DW_OP_reg3: // 0x53
876 case DW_OP_reg4: // 0x54
877 case DW_OP_reg5: // 0x55
878 case DW_OP_reg6: // 0x56
879 case DW_OP_reg7: // 0x57
880 case DW_OP_reg8: // 0x58
881 case DW_OP_reg9: // 0x59
882 case DW_OP_reg10: // 0x5A
883 case DW_OP_reg11: // 0x5B
884 case DW_OP_reg12: // 0x5C
885 case DW_OP_reg13: // 0x5D
886 case DW_OP_reg14: // 0x5E
887 case DW_OP_reg15: // 0x5F
888 case DW_OP_reg16: // 0x60
889 case DW_OP_reg17: // 0x61
890 case DW_OP_reg18: // 0x62
891 case DW_OP_reg19: // 0x63
892 case DW_OP_reg20: // 0x64
893 case DW_OP_reg21: // 0x65
894 case DW_OP_reg22: // 0x66
895 case DW_OP_reg23: // 0x67
896 case DW_OP_reg24: // 0x68
897 case DW_OP_reg25: // 0x69
898 case DW_OP_reg26: // 0x6A
899 case DW_OP_reg27: // 0x6B
900 case DW_OP_reg28: // 0x6C
901 case DW_OP_reg29: // 0x6D
902 case DW_OP_reg30: // 0x6E
903 case DW_OP_reg31: // 0x6F
904 case DW_OP_nop: // 0x96
905 case DW_OP_push_object_address: // 0x97 DWARF3
906 case DW_OP_form_tls_address: // 0x9b DWARF3
907 case DW_OP_call_frame_cfa: // 0x9c DWARF3
Greg Claytonc6c37562011-12-01 04:06:15 +0000908 case DW_OP_stack_value: // 0x9f DWARF4
Greg Claytona1b9a902011-11-13 04:15:56 +0000909 return 0;
910
911 // Opcodes with a single 1 byte arguments
912 case DW_OP_const1u: // 0x08 1 1-byte constant
913 case DW_OP_const1s: // 0x09 1 1-byte constant
914 case DW_OP_pick: // 0x15 1 1-byte stack index
915 case DW_OP_deref_size: // 0x94 1 1-byte size of data retrieved
916 case DW_OP_xderef_size: // 0x95 1 1-byte size of data retrieved
917 return 1;
918
919 // Opcodes with a single 2 byte arguments
920 case DW_OP_const2u: // 0x0a 1 2-byte constant
921 case DW_OP_const2s: // 0x0b 1 2-byte constant
922 case DW_OP_skip: // 0x2f 1 signed 2-byte constant
923 case DW_OP_bra: // 0x28 1 signed 2-byte constant
924 case DW_OP_call2: // 0x98 1 2-byte offset of DIE (DWARF3)
925 return 2;
926
927 // Opcodes with a single 4 byte arguments
928 case DW_OP_const4u: // 0x0c 1 4-byte constant
929 case DW_OP_const4s: // 0x0d 1 4-byte constant
930 case DW_OP_call4: // 0x99 1 4-byte offset of DIE (DWARF3)
931 return 4;
932
933 // Opcodes with a single 8 byte arguments
934 case DW_OP_const8u: // 0x0e 1 8-byte constant
935 case DW_OP_const8s: // 0x0f 1 8-byte constant
936 return 8;
937
938 // All opcodes that have a single ULEB (signed or unsigned) argument
939 case DW_OP_constu: // 0x10 1 ULEB128 constant
940 case DW_OP_consts: // 0x11 1 SLEB128 constant
941 case DW_OP_plus_uconst: // 0x23 1 ULEB128 addend
942 case DW_OP_breg0: // 0x70 1 ULEB128 register
943 case DW_OP_breg1: // 0x71 1 ULEB128 register
944 case DW_OP_breg2: // 0x72 1 ULEB128 register
945 case DW_OP_breg3: // 0x73 1 ULEB128 register
946 case DW_OP_breg4: // 0x74 1 ULEB128 register
947 case DW_OP_breg5: // 0x75 1 ULEB128 register
948 case DW_OP_breg6: // 0x76 1 ULEB128 register
949 case DW_OP_breg7: // 0x77 1 ULEB128 register
950 case DW_OP_breg8: // 0x78 1 ULEB128 register
951 case DW_OP_breg9: // 0x79 1 ULEB128 register
952 case DW_OP_breg10: // 0x7a 1 ULEB128 register
953 case DW_OP_breg11: // 0x7b 1 ULEB128 register
954 case DW_OP_breg12: // 0x7c 1 ULEB128 register
955 case DW_OP_breg13: // 0x7d 1 ULEB128 register
956 case DW_OP_breg14: // 0x7e 1 ULEB128 register
957 case DW_OP_breg15: // 0x7f 1 ULEB128 register
958 case DW_OP_breg16: // 0x80 1 ULEB128 register
959 case DW_OP_breg17: // 0x81 1 ULEB128 register
960 case DW_OP_breg18: // 0x82 1 ULEB128 register
961 case DW_OP_breg19: // 0x83 1 ULEB128 register
962 case DW_OP_breg20: // 0x84 1 ULEB128 register
963 case DW_OP_breg21: // 0x85 1 ULEB128 register
964 case DW_OP_breg22: // 0x86 1 ULEB128 register
965 case DW_OP_breg23: // 0x87 1 ULEB128 register
966 case DW_OP_breg24: // 0x88 1 ULEB128 register
967 case DW_OP_breg25: // 0x89 1 ULEB128 register
968 case DW_OP_breg26: // 0x8a 1 ULEB128 register
969 case DW_OP_breg27: // 0x8b 1 ULEB128 register
970 case DW_OP_breg28: // 0x8c 1 ULEB128 register
971 case DW_OP_breg29: // 0x8d 1 ULEB128 register
972 case DW_OP_breg30: // 0x8e 1 ULEB128 register
973 case DW_OP_breg31: // 0x8f 1 ULEB128 register
974 case DW_OP_regx: // 0x90 1 ULEB128 register
975 case DW_OP_fbreg: // 0x91 1 SLEB128 offset
976 case DW_OP_piece: // 0x93 1 ULEB128 size of piece addressed
977 data.Skip_LEB128(&offset);
978 return offset - data_offset;
979
Greg Claytonc6c37562011-12-01 04:06:15 +0000980 // All opcodes that have a 2 ULEB (signed or unsigned) arguments
Greg Claytona1b9a902011-11-13 04:15:56 +0000981 case DW_OP_bregx: // 0x92 2 ULEB128 register followed by SLEB128 offset
982 case DW_OP_bit_piece: // 0x9d ULEB128 bit size, ULEB128 bit offset (DWARF3);
983 data.Skip_LEB128(&offset);
984 data.Skip_LEB128(&offset);
985 return offset - data_offset;
Greg Claytonc6c37562011-12-01 04:06:15 +0000986
987 case DW_OP_implicit_value: // 0x9e ULEB128 size followed by block of that size (DWARF4)
988 {
989 uint64_t block_len = data.Skip_LEB128(&offset);
990 offset += block_len;
991 return offset - data_offset;
992 }
993
Greg Claytona1b9a902011-11-13 04:15:56 +0000994 default:
Greg Clayton2f28ece2012-01-04 22:56:43 +0000995 break;
Greg Claytona1b9a902011-11-13 04:15:56 +0000996 }
997 return UINT32_MAX;
998}
999
1000bool
Greg Clayton2f28ece2012-01-04 22:56:43 +00001001DWARFExpression::LocationContains_DW_OP_addr (lldb::addr_t file_addr, bool &error) const
Greg Claytona1b9a902011-11-13 04:15:56 +00001002{
Greg Clayton2f28ece2012-01-04 22:56:43 +00001003 error = false;
Greg Claytona1b9a902011-11-13 04:15:56 +00001004 if (IsLocationList())
1005 return false;
1006 uint32_t offset = 0;
1007 while (m_data.ValidOffset(offset))
1008 {
1009 const uint8_t op = m_data.GetU8(&offset);
1010
1011 if (op == DW_OP_addr)
1012 {
1013 if (file_addr == LLDB_INVALID_ADDRESS)
1014 return true;
1015 addr_t op_file_addr = m_data.GetAddress(&offset);
1016 if (op_file_addr == file_addr)
1017 return true;
1018 }
1019 else
1020 {
1021 const uint32_t op_arg_size = GetOpcodeDataSize (m_data, offset, op);
1022 if (op_arg_size == UINT32_MAX)
Greg Clayton2f28ece2012-01-04 22:56:43 +00001023 {
1024 error = true;
Greg Claytona1b9a902011-11-13 04:15:56 +00001025 break;
Greg Clayton2f28ece2012-01-04 22:56:43 +00001026 }
Greg Claytona1b9a902011-11-13 04:15:56 +00001027 offset += op_arg_size;
1028 }
1029 }
1030 return false;
1031}
1032
1033bool
1034DWARFExpression::Update_DW_OP_addr (lldb::addr_t file_addr)
1035{
1036 if (IsLocationList())
1037 return false;
1038 uint32_t offset = 0;
1039 while (m_data.ValidOffset(offset))
1040 {
1041 const uint8_t op = m_data.GetU8(&offset);
1042
1043 if (op == DW_OP_addr)
1044 {
1045 const uint8_t addr_byte_size = m_data.GetAddressByteSize();
1046 // We have to make a copy of the data as we don't know if this
1047 // data is from a read only memory mapped buffer, so we duplicate
1048 // all of the data first, then modify it, and if all goes well,
1049 // we then replace the data for this expression
1050
1051 // So first we copy the data into a heap buffer
1052 std::auto_ptr<DataBufferHeap> head_data_ap (new DataBufferHeap (m_data.GetDataStart(),
1053 m_data.GetByteSize()));
1054
1055 // Make en encoder so we can write the address into the buffer using
1056 // the correct byte order (endianness)
1057 DataEncoder encoder (head_data_ap->GetBytes(),
1058 head_data_ap->GetByteSize(),
1059 m_data.GetByteOrder(),
1060 addr_byte_size);
1061
1062 // Replace the address in the new buffer
1063 if (encoder.PutMaxU64 (offset, addr_byte_size, file_addr) == UINT32_MAX)
1064 return false;
1065
1066 // All went well, so now we can reset the data using a shared
1067 // pointer to the heap data so "m_data" will now correctly
1068 // manage the heap data.
1069 m_data.SetData (DataBufferSP (head_data_ap.release()));
1070 return true;
1071 }
1072 else
1073 {
1074 const uint32_t op_arg_size = GetOpcodeDataSize (m_data, offset, op);
1075 if (op_arg_size == UINT32_MAX)
1076 break;
1077 offset += op_arg_size;
1078 }
1079 }
1080 return false;
1081}
1082
Greg Claytonb04e7a82010-08-24 21:05:24 +00001083bool
Greg Clayton178710c2010-09-14 02:20:48 +00001084DWARFExpression::LocationListContainsAddress (lldb::addr_t loclist_base_addr, lldb::addr_t addr) const
Greg Claytonb04e7a82010-08-24 21:05:24 +00001085{
Greg Clayton178710c2010-09-14 02:20:48 +00001086 if (addr == LLDB_INVALID_ADDRESS)
Greg Claytonb04e7a82010-08-24 21:05:24 +00001087 return false;
1088
Chris Lattner24943d22010-06-08 16:52:24 +00001089 if (IsLocationList())
1090 {
1091 uint32_t offset = 0;
Chris Lattner24943d22010-06-08 16:52:24 +00001092
Greg Clayton178710c2010-09-14 02:20:48 +00001093 if (loclist_base_addr == LLDB_INVALID_ADDRESS)
Chris Lattner24943d22010-06-08 16:52:24 +00001094 return false;
1095
1096 while (m_data.ValidOffset(offset))
1097 {
1098 // We need to figure out what the value is for the location.
1099 addr_t lo_pc = m_data.GetAddress(&offset);
1100 addr_t hi_pc = m_data.GetAddress(&offset);
1101 if (lo_pc == 0 && hi_pc == 0)
1102 break;
1103 else
1104 {
Greg Clayton178710c2010-09-14 02:20:48 +00001105 lo_pc += loclist_base_addr - m_loclist_slide;
1106 hi_pc += loclist_base_addr - m_loclist_slide;
Chris Lattner24943d22010-06-08 16:52:24 +00001107
Greg Clayton178710c2010-09-14 02:20:48 +00001108 if (lo_pc <= addr && addr < hi_pc)
Chris Lattner24943d22010-06-08 16:52:24 +00001109 return true;
1110
1111 offset += m_data.GetU16(&offset);
1112 }
1113 }
1114 }
1115 return false;
1116}
Greg Claytonb04e7a82010-08-24 21:05:24 +00001117
Chris Lattner24943d22010-06-08 16:52:24 +00001118bool
Greg Clayton9b82f862011-07-11 05:12:02 +00001119DWARFExpression::GetLocation (addr_t base_addr, addr_t pc, uint32_t &offset, uint32_t &length)
1120{
1121 offset = 0;
1122 if (!IsLocationList())
1123 {
1124 length = m_data.GetByteSize();
1125 return true;
1126 }
1127
1128 if (base_addr != LLDB_INVALID_ADDRESS && pc != LLDB_INVALID_ADDRESS)
1129 {
1130 addr_t curr_base_addr = base_addr;
1131
1132 while (m_data.ValidOffset(offset))
1133 {
1134 // We need to figure out what the value is for the location.
1135 addr_t lo_pc = m_data.GetAddress(&offset);
1136 addr_t hi_pc = m_data.GetAddress(&offset);
1137 if (lo_pc == 0 && hi_pc == 0)
1138 {
1139 break;
1140 }
1141 else
1142 {
1143 lo_pc += curr_base_addr - m_loclist_slide;
1144 hi_pc += curr_base_addr - m_loclist_slide;
1145
1146 length = m_data.GetU16(&offset);
1147
1148 if (length > 0 && lo_pc <= pc && pc < hi_pc)
1149 return true;
1150
1151 offset += length;
1152 }
1153 }
1154 }
1155 offset = UINT32_MAX;
1156 length = 0;
1157 return false;
1158}
1159
1160bool
1161DWARFExpression::DumpLocationForAddress (Stream *s,
1162 lldb::DescriptionLevel level,
1163 addr_t base_addr,
Greg Clayton5c3861d2011-09-02 01:15:17 +00001164 addr_t address,
1165 ABI *abi)
Greg Clayton9b82f862011-07-11 05:12:02 +00001166{
1167 uint32_t offset = 0;
1168 uint32_t length = 0;
1169
1170 if (GetLocation (base_addr, address, offset, length))
1171 {
1172 if (length > 0)
1173 {
Greg Clayton5c3861d2011-09-02 01:15:17 +00001174 DumpLocation(s, offset, length, level, abi);
Greg Clayton9b82f862011-07-11 05:12:02 +00001175 return true;
1176 }
1177 }
1178 return false;
1179}
1180
1181bool
Chris Lattner24943d22010-06-08 16:52:24 +00001182DWARFExpression::Evaluate
1183(
1184 ExecutionContextScope *exe_scope,
1185 clang::ASTContext *ast_context,
Greg Claytonbdcb6ab2011-01-25 23:55:37 +00001186 ClangExpressionVariableList *expr_locals,
1187 ClangExpressionDeclMap *decl_map,
Greg Clayton178710c2010-09-14 02:20:48 +00001188 lldb::addr_t loclist_base_load_addr,
Chris Lattner24943d22010-06-08 16:52:24 +00001189 const Value* initial_value_ptr,
1190 Value& result,
1191 Error *error_ptr
1192) const
1193{
1194 ExecutionContext exe_ctx (exe_scope);
Greg Claytonbdcb6ab2011-01-25 23:55:37 +00001195 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 +00001196}
1197
1198bool
1199DWARFExpression::Evaluate
1200(
1201 ExecutionContext *exe_ctx,
1202 clang::ASTContext *ast_context,
Greg Claytonbdcb6ab2011-01-25 23:55:37 +00001203 ClangExpressionVariableList *expr_locals,
1204 ClangExpressionDeclMap *decl_map,
Jason Molenda8e69de42010-11-20 01:28:30 +00001205 RegisterContext *reg_ctx,
Greg Clayton178710c2010-09-14 02:20:48 +00001206 lldb::addr_t loclist_base_load_addr,
Chris Lattner24943d22010-06-08 16:52:24 +00001207 const Value* initial_value_ptr,
1208 Value& result,
1209 Error *error_ptr
1210) const
1211{
1212 if (IsLocationList())
1213 {
1214 uint32_t offset = 0;
Jason Molenda8e69de42010-11-20 01:28:30 +00001215 addr_t pc;
Greg Clayton567e7f32011-09-22 04:58:26 +00001216 StackFrame *frame = NULL;
Jason Molenda8e69de42010-11-20 01:28:30 +00001217 if (reg_ctx)
1218 pc = reg_ctx->GetPC();
1219 else
Greg Clayton567e7f32011-09-22 04:58:26 +00001220 {
1221 frame = exe_ctx->GetFramePtr();
Sean Callanan86106812012-03-10 03:03:46 +00001222 if (!frame)
1223 return false;
1224 RegisterContextSP reg_ctx_sp = frame->GetRegisterContext();
1225 if (!reg_ctx_sp)
1226 return false;
1227 pc = reg_ctx_sp->GetPC();
Greg Clayton567e7f32011-09-22 04:58:26 +00001228 }
Chris Lattner24943d22010-06-08 16:52:24 +00001229
Greg Clayton178710c2010-09-14 02:20:48 +00001230 if (loclist_base_load_addr != LLDB_INVALID_ADDRESS)
Chris Lattner24943d22010-06-08 16:52:24 +00001231 {
Greg Clayton178710c2010-09-14 02:20:48 +00001232 if (pc == LLDB_INVALID_ADDRESS)
Chris Lattner24943d22010-06-08 16:52:24 +00001233 {
Greg Clayton178710c2010-09-14 02:20:48 +00001234 if (error_ptr)
1235 error_ptr->SetErrorString("Invalid PC in frame.");
1236 return false;
Chris Lattner24943d22010-06-08 16:52:24 +00001237 }
Greg Clayton178710c2010-09-14 02:20:48 +00001238
1239 addr_t curr_loclist_base_load_addr = loclist_base_load_addr;
1240
1241 while (m_data.ValidOffset(offset))
Chris Lattner24943d22010-06-08 16:52:24 +00001242 {
Greg Clayton178710c2010-09-14 02:20:48 +00001243 // We need to figure out what the value is for the location.
1244 addr_t lo_pc = m_data.GetAddress(&offset);
1245 addr_t hi_pc = m_data.GetAddress(&offset);
1246 if (lo_pc == 0 && hi_pc == 0)
Chris Lattner24943d22010-06-08 16:52:24 +00001247 {
Greg Clayton178710c2010-09-14 02:20:48 +00001248 break;
Chris Lattner24943d22010-06-08 16:52:24 +00001249 }
Greg Clayton178710c2010-09-14 02:20:48 +00001250 else
1251 {
1252 lo_pc += curr_loclist_base_load_addr - m_loclist_slide;
1253 hi_pc += curr_loclist_base_load_addr - m_loclist_slide;
1254
1255 uint16_t length = m_data.GetU16(&offset);
1256
1257 if (length > 0 && lo_pc <= pc && pc < hi_pc)
1258 {
Greg Claytonbdcb6ab2011-01-25 23:55:37 +00001259 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 +00001260 }
1261 offset += length;
1262 }
Chris Lattner24943d22010-06-08 16:52:24 +00001263 }
1264 }
1265 if (error_ptr)
Greg Clayton82f07462011-05-30 00:49:24 +00001266 error_ptr->SetErrorString ("variable not available");
Chris Lattner24943d22010-06-08 16:52:24 +00001267 return false;
1268 }
1269
1270 // Not a location list, just a single expression.
Greg Claytonbdcb6ab2011-01-25 23:55:37 +00001271 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 +00001272}
1273
1274
1275
1276bool
1277DWARFExpression::Evaluate
1278(
1279 ExecutionContext *exe_ctx,
1280 clang::ASTContext *ast_context,
Chris Lattner24943d22010-06-08 16:52:24 +00001281 ClangExpressionVariableList *expr_locals,
1282 ClangExpressionDeclMap *decl_map,
Jason Molenda8e69de42010-11-20 01:28:30 +00001283 RegisterContext *reg_ctx,
Greg Claytonbdcb6ab2011-01-25 23:55:37 +00001284 const DataExtractor& opcodes,
Chris Lattner24943d22010-06-08 16:52:24 +00001285 const uint32_t opcodes_offset,
1286 const uint32_t opcodes_length,
1287 const uint32_t reg_kind,
1288 const Value* initial_value_ptr,
1289 Value& result,
1290 Error *error_ptr
1291)
1292{
1293 std::vector<Value> stack;
1294
Greg Clayton567e7f32011-09-22 04:58:26 +00001295 Process *process = NULL;
1296 StackFrame *frame = NULL;
1297
1298 if (exe_ctx)
1299 {
1300 process = exe_ctx->GetProcessPtr();
1301 frame = exe_ctx->GetFramePtr();
1302 }
1303 if (reg_ctx == NULL && frame)
1304 reg_ctx = frame->GetRegisterContext().get();
Jason Molenda8e69de42010-11-20 01:28:30 +00001305
Chris Lattner24943d22010-06-08 16:52:24 +00001306 if (initial_value_ptr)
1307 stack.push_back(*initial_value_ptr);
1308
1309 uint32_t offset = opcodes_offset;
1310 const uint32_t end_offset = opcodes_offset + opcodes_length;
1311 Value tmp;
1312 uint32_t reg_num;
1313
1314 // Make sure all of the data is available in opcodes.
1315 if (!opcodes.ValidOffsetForDataOfSize(opcodes_offset, opcodes_length))
1316 {
1317 if (error_ptr)
1318 error_ptr->SetErrorString ("Invalid offset and/or length for opcodes buffer.");
1319 return false;
1320 }
Greg Claytone005f2c2010-11-06 01:53:30 +00001321 LogSP log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
Chris Lattner24943d22010-06-08 16:52:24 +00001322
1323
1324 while (opcodes.ValidOffset(offset) && offset < end_offset)
1325 {
1326 const uint32_t op_offset = offset;
1327 const uint8_t op = opcodes.GetU8(&offset);
1328
Sean Callanan67bbb112011-10-14 20:34:21 +00001329 if (log && log->GetVerbose())
Chris Lattner24943d22010-06-08 16:52:24 +00001330 {
Chris Lattner24943d22010-06-08 16:52:24 +00001331 size_t count = stack.size();
Jason Molenda7e5fa7f2011-09-20 21:44:10 +00001332 log->Printf("Stack before operation has %lu values:", count);
Chris Lattner24943d22010-06-08 16:52:24 +00001333 for (size_t i=0; i<count; ++i)
1334 {
1335 StreamString new_value;
1336 new_value.Printf("[%zu]", i);
1337 stack[i].Dump(&new_value);
Sean Callanan6184dfe2010-06-23 00:47:48 +00001338 log->Printf(" %s", new_value.GetData());
Chris Lattner24943d22010-06-08 16:52:24 +00001339 }
1340 log->Printf("0x%8.8x: %s", op_offset, DW_OP_value_to_name(op));
1341 }
1342 switch (op)
1343 {
1344 //----------------------------------------------------------------------
1345 // The DW_OP_addr operation has a single operand that encodes a machine
1346 // address and whose size is the size of an address on the target machine.
1347 //----------------------------------------------------------------------
1348 case DW_OP_addr:
Greg Clayton801417e2011-07-07 01:59:51 +00001349 stack.push_back(Scalar(opcodes.GetAddress(&offset)));
Chris Lattner24943d22010-06-08 16:52:24 +00001350 stack.back().SetValueType (Value::eValueTypeFileAddress);
1351 break;
1352
1353 //----------------------------------------------------------------------
1354 // The DW_OP_addr_sect_offset4 is used for any location expressions in
1355 // shared libraries that have a location like:
1356 // DW_OP_addr(0x1000)
1357 // If this address resides in a shared library, then this virtual
1358 // address won't make sense when it is evaluated in the context of a
1359 // running process where shared libraries have been slid. To account for
1360 // this, this new address type where we can store the section pointer
1361 // and a 4 byte offset.
1362 //----------------------------------------------------------------------
1363// case DW_OP_addr_sect_offset4:
1364// {
1365// result_type = eResultTypeFileAddress;
1366// lldb::Section *sect = (lldb::Section *)opcodes.GetMaxU64(&offset, sizeof(void *));
1367// lldb::addr_t sect_offset = opcodes.GetU32(&offset);
1368//
1369// Address so_addr (sect, sect_offset);
1370// lldb::addr_t load_addr = so_addr.GetLoadAddress();
1371// if (load_addr != LLDB_INVALID_ADDRESS)
1372// {
1373// // We successfully resolve a file address to a load
1374// // address.
1375// stack.push_back(load_addr);
1376// break;
1377// }
1378// else
1379// {
1380// // We were able
1381// if (error_ptr)
1382// error_ptr->SetErrorStringWithFormat ("Section %s in %s is not currently loaded.\n", sect->GetName().AsCString(), sect->GetModule()->GetFileSpec().GetFilename().AsCString());
1383// return false;
1384// }
1385// }
1386// break;
1387
1388 //----------------------------------------------------------------------
1389 // OPCODE: DW_OP_deref
1390 // OPERANDS: none
1391 // DESCRIPTION: Pops the top stack entry and treats it as an address.
1392 // The value retrieved from that address is pushed. The size of the
1393 // data retrieved from the dereferenced address is the size of an
1394 // address on the target machine.
1395 //----------------------------------------------------------------------
1396 case DW_OP_deref:
1397 {
1398 Value::ValueType value_type = stack.back().GetValueType();
1399 switch (value_type)
1400 {
1401 case Value::eValueTypeHostAddress:
1402 {
1403 void *src = (void *)stack.back().GetScalar().ULongLong();
1404 intptr_t ptr;
1405 ::memcpy (&ptr, src, sizeof(void *));
1406 stack.back().GetScalar() = ptr;
1407 stack.back().ClearContext();
1408 }
1409 break;
1410 case Value::eValueTypeLoadAddress:
1411 if (exe_ctx)
1412 {
Greg Clayton567e7f32011-09-22 04:58:26 +00001413 if (process)
Chris Lattner24943d22010-06-08 16:52:24 +00001414 {
1415 lldb::addr_t pointer_addr = stack.back().GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1416 uint8_t addr_bytes[sizeof(lldb::addr_t)];
Greg Clayton567e7f32011-09-22 04:58:26 +00001417 uint32_t addr_size = process->GetAddressByteSize();
Chris Lattner24943d22010-06-08 16:52:24 +00001418 Error error;
Greg Clayton567e7f32011-09-22 04:58:26 +00001419 if (process->ReadMemory(pointer_addr, &addr_bytes, addr_size, error) == addr_size)
Chris Lattner24943d22010-06-08 16:52:24 +00001420 {
Greg Clayton567e7f32011-09-22 04:58:26 +00001421 DataExtractor addr_data(addr_bytes, sizeof(addr_bytes), process->GetByteOrder(), addr_size);
Chris Lattner24943d22010-06-08 16:52:24 +00001422 uint32_t addr_data_offset = 0;
1423 stack.back().GetScalar() = addr_data.GetPointer(&addr_data_offset);
1424 stack.back().ClearContext();
1425 }
1426 else
1427 {
1428 if (error_ptr)
1429 error_ptr->SetErrorStringWithFormat ("Failed to dereference pointer from 0x%llx for DW_OP_deref: %s\n",
1430 pointer_addr,
1431 error.AsCString());
1432 return false;
1433 }
1434 }
1435 else
1436 {
1437 if (error_ptr)
1438 error_ptr->SetErrorStringWithFormat ("NULL process for DW_OP_deref.\n");
1439 return false;
1440 }
1441 }
1442 else
1443 {
1444 if (error_ptr)
1445 error_ptr->SetErrorStringWithFormat ("NULL execution context for DW_OP_deref.\n");
1446 return false;
1447 }
1448 break;
1449
1450 default:
1451 break;
1452 }
1453
1454 }
1455 break;
1456
1457 //----------------------------------------------------------------------
1458 // OPCODE: DW_OP_deref_size
1459 // OPERANDS: 1
1460 // 1 - uint8_t that specifies the size of the data to dereference.
1461 // DESCRIPTION: Behaves like the DW_OP_deref operation: it pops the top
1462 // stack entry and treats it as an address. The value retrieved from that
1463 // address is pushed. In the DW_OP_deref_size operation, however, the
1464 // size in bytes of the data retrieved from the dereferenced address is
1465 // specified by the single operand. This operand is a 1-byte unsigned
1466 // integral constant whose value may not be larger than the size of an
1467 // address on the target machine. The data retrieved is zero extended
1468 // to the size of an address on the target machine before being pushed
1469 // on the expression stack.
1470 //----------------------------------------------------------------------
1471 case DW_OP_deref_size:
Jason Molenda8e69de42010-11-20 01:28:30 +00001472 {
1473 uint8_t size = opcodes.GetU8(&offset);
1474 Value::ValueType value_type = stack.back().GetValueType();
1475 switch (value_type)
1476 {
1477 case Value::eValueTypeHostAddress:
1478 {
1479 void *src = (void *)stack.back().GetScalar().ULongLong();
1480 intptr_t ptr;
1481 ::memcpy (&ptr, src, sizeof(void *));
1482 // I can't decide whether the size operand should apply to the bytes in their
1483 // lldb-host endianness or the target endianness.. I doubt this'll ever come up
1484 // but I'll opt for assuming big endian regardless.
1485 switch (size)
1486 {
1487 case 1: ptr = ptr & 0xff; break;
1488 case 2: ptr = ptr & 0xffff; break;
1489 case 3: ptr = ptr & 0xffffff; break;
1490 case 4: ptr = ptr & 0xffffffff; break;
Jason Molendaa99bcaa2010-11-29 21:38:58 +00001491 // the casts are added to work around the case where intptr_t is a 32 bit quantity;
1492 // presumably we won't hit the 5..7 cases if (void*) is 32-bits in this program.
1493 case 5: ptr = (intptr_t) ptr & 0xffffffffffULL; break;
1494 case 6: ptr = (intptr_t) ptr & 0xffffffffffffULL; break;
1495 case 7: ptr = (intptr_t) ptr & 0xffffffffffffffULL; break;
Jason Molenda8e69de42010-11-20 01:28:30 +00001496 default: break;
1497 }
1498 stack.back().GetScalar() = ptr;
1499 stack.back().ClearContext();
1500 }
1501 break;
1502 case Value::eValueTypeLoadAddress:
1503 if (exe_ctx)
1504 {
Greg Clayton567e7f32011-09-22 04:58:26 +00001505 if (process)
Jason Molenda8e69de42010-11-20 01:28:30 +00001506 {
1507 lldb::addr_t pointer_addr = stack.back().GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1508 uint8_t addr_bytes[sizeof(lldb::addr_t)];
1509 Error error;
Greg Clayton567e7f32011-09-22 04:58:26 +00001510 if (process->ReadMemory(pointer_addr, &addr_bytes, size, error) == size)
Jason Molenda8e69de42010-11-20 01:28:30 +00001511 {
Greg Clayton567e7f32011-09-22 04:58:26 +00001512 DataExtractor addr_data(addr_bytes, sizeof(addr_bytes), process->GetByteOrder(), size);
Jason Molenda8e69de42010-11-20 01:28:30 +00001513 uint32_t addr_data_offset = 0;
1514 switch (size)
1515 {
1516 case 1: stack.back().GetScalar() = addr_data.GetU8(&addr_data_offset); break;
1517 case 2: stack.back().GetScalar() = addr_data.GetU16(&addr_data_offset); break;
1518 case 4: stack.back().GetScalar() = addr_data.GetU32(&addr_data_offset); break;
1519 case 8: stack.back().GetScalar() = addr_data.GetU64(&addr_data_offset); break;
1520 default: stack.back().GetScalar() = addr_data.GetPointer(&addr_data_offset);
1521 }
1522 stack.back().ClearContext();
1523 }
1524 else
1525 {
1526 if (error_ptr)
1527 error_ptr->SetErrorStringWithFormat ("Failed to dereference pointer from 0x%llx for DW_OP_deref: %s\n",
1528 pointer_addr,
1529 error.AsCString());
1530 return false;
1531 }
1532 }
1533 else
1534 {
1535 if (error_ptr)
1536 error_ptr->SetErrorStringWithFormat ("NULL process for DW_OP_deref.\n");
1537 return false;
1538 }
1539 }
1540 else
1541 {
1542 if (error_ptr)
1543 error_ptr->SetErrorStringWithFormat ("NULL execution context for DW_OP_deref.\n");
1544 return false;
1545 }
1546 break;
1547
1548 default:
1549 break;
1550 }
1551
1552 }
1553 break;
Chris Lattner24943d22010-06-08 16:52:24 +00001554
1555 //----------------------------------------------------------------------
1556 // OPCODE: DW_OP_xderef_size
1557 // OPERANDS: 1
1558 // 1 - uint8_t that specifies the size of the data to dereference.
1559 // DESCRIPTION: Behaves like the DW_OP_xderef operation: the entry at
1560 // the top of the stack is treated as an address. The second stack
Greg Clayton33ed1702010-08-24 00:45:41 +00001561 // entry is treated as an "address space identifier" for those
Chris Lattner24943d22010-06-08 16:52:24 +00001562 // architectures that support multiple address spaces. The top two
1563 // stack elements are popped, a data item is retrieved through an
1564 // implementation-defined address calculation and pushed as the new
1565 // stack top. In the DW_OP_xderef_size operation, however, the size in
1566 // bytes of the data retrieved from the dereferenced address is
1567 // specified by the single operand. This operand is a 1-byte unsigned
1568 // integral constant whose value may not be larger than the size of an
1569 // address on the target machine. The data retrieved is zero extended
1570 // to the size of an address on the target machine before being pushed
1571 // on the expression stack.
1572 //----------------------------------------------------------------------
1573 case DW_OP_xderef_size:
1574 if (error_ptr)
1575 error_ptr->SetErrorString("Unimplemented opcode: DW_OP_xderef_size.");
1576 return false;
1577 //----------------------------------------------------------------------
1578 // OPCODE: DW_OP_xderef
1579 // OPERANDS: none
1580 // DESCRIPTION: Provides an extended dereference mechanism. The entry at
1581 // the top of the stack is treated as an address. The second stack entry
1582 // is treated as an "address space identifier" for those architectures
1583 // that support multiple address spaces. The top two stack elements are
1584 // popped, a data item is retrieved through an implementation-defined
1585 // address calculation and pushed as the new stack top. The size of the
1586 // data retrieved from the dereferenced address is the size of an address
1587 // on the target machine.
1588 //----------------------------------------------------------------------
1589 case DW_OP_xderef:
1590 if (error_ptr)
1591 error_ptr->SetErrorString("Unimplemented opcode: DW_OP_xderef.");
1592 return false;
1593
1594 //----------------------------------------------------------------------
1595 // All DW_OP_constXXX opcodes have a single operand as noted below:
1596 //
1597 // Opcode Operand 1
1598 // --------------- ----------------------------------------------------
1599 // DW_OP_const1u 1-byte unsigned integer constant
1600 // DW_OP_const1s 1-byte signed integer constant
1601 // DW_OP_const2u 2-byte unsigned integer constant
1602 // DW_OP_const2s 2-byte signed integer constant
1603 // DW_OP_const4u 4-byte unsigned integer constant
1604 // DW_OP_const4s 4-byte signed integer constant
1605 // DW_OP_const8u 8-byte unsigned integer constant
1606 // DW_OP_const8s 8-byte signed integer constant
1607 // DW_OP_constu unsigned LEB128 integer constant
1608 // DW_OP_consts signed LEB128 integer constant
1609 //----------------------------------------------------------------------
Greg Clayton801417e2011-07-07 01:59:51 +00001610 case DW_OP_const1u : stack.push_back(Scalar(( uint8_t)opcodes.GetU8 (&offset))); break;
1611 case DW_OP_const1s : stack.push_back(Scalar(( int8_t)opcodes.GetU8 (&offset))); break;
1612 case DW_OP_const2u : stack.push_back(Scalar((uint16_t)opcodes.GetU16 (&offset))); break;
1613 case DW_OP_const2s : stack.push_back(Scalar(( int16_t)opcodes.GetU16 (&offset))); break;
1614 case DW_OP_const4u : stack.push_back(Scalar((uint32_t)opcodes.GetU32 (&offset))); break;
1615 case DW_OP_const4s : stack.push_back(Scalar(( int32_t)opcodes.GetU32 (&offset))); break;
1616 case DW_OP_const8u : stack.push_back(Scalar((uint64_t)opcodes.GetU64 (&offset))); break;
1617 case DW_OP_const8s : stack.push_back(Scalar(( int64_t)opcodes.GetU64 (&offset))); break;
1618 case DW_OP_constu : stack.push_back(Scalar(opcodes.GetULEB128 (&offset))); break;
1619 case DW_OP_consts : stack.push_back(Scalar(opcodes.GetSLEB128 (&offset))); break;
Chris Lattner24943d22010-06-08 16:52:24 +00001620
1621 //----------------------------------------------------------------------
1622 // OPCODE: DW_OP_dup
1623 // OPERANDS: none
1624 // DESCRIPTION: duplicates the value at the top of the stack
1625 //----------------------------------------------------------------------
1626 case DW_OP_dup:
1627 if (stack.empty())
1628 {
1629 if (error_ptr)
1630 error_ptr->SetErrorString("Expression stack empty for DW_OP_dup.");
1631 return false;
1632 }
1633 else
1634 stack.push_back(stack.back());
1635 break;
1636
1637 //----------------------------------------------------------------------
1638 // OPCODE: DW_OP_drop
1639 // OPERANDS: none
1640 // DESCRIPTION: pops the value at the top of the stack
1641 //----------------------------------------------------------------------
1642 case DW_OP_drop:
1643 if (stack.empty())
1644 {
1645 if (error_ptr)
1646 error_ptr->SetErrorString("Expression stack empty for DW_OP_drop.");
1647 return false;
1648 }
1649 else
1650 stack.pop_back();
1651 break;
1652
1653 //----------------------------------------------------------------------
1654 // OPCODE: DW_OP_over
1655 // OPERANDS: none
1656 // DESCRIPTION: Duplicates the entry currently second in the stack at
1657 // the top of the stack.
1658 //----------------------------------------------------------------------
1659 case DW_OP_over:
1660 if (stack.size() < 2)
1661 {
1662 if (error_ptr)
1663 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_over.");
1664 return false;
1665 }
1666 else
1667 stack.push_back(stack[stack.size() - 2]);
1668 break;
1669
1670
1671 //----------------------------------------------------------------------
1672 // OPCODE: DW_OP_pick
1673 // OPERANDS: uint8_t index into the current stack
1674 // DESCRIPTION: The stack entry with the specified index (0 through 255,
1675 // inclusive) is pushed on the stack
1676 //----------------------------------------------------------------------
1677 case DW_OP_pick:
1678 {
1679 uint8_t pick_idx = opcodes.GetU8(&offset);
1680 if (pick_idx < stack.size())
1681 stack.push_back(stack[pick_idx]);
1682 else
1683 {
1684 if (error_ptr)
1685 error_ptr->SetErrorStringWithFormat("Index %u out of range for DW_OP_pick.\n", pick_idx);
1686 return false;
1687 }
1688 }
1689 break;
1690
1691 //----------------------------------------------------------------------
1692 // OPCODE: DW_OP_swap
1693 // OPERANDS: none
1694 // DESCRIPTION: swaps the top two stack entries. The entry at the top
1695 // of the stack becomes the second stack entry, and the second entry
1696 // becomes the top of the stack
1697 //----------------------------------------------------------------------
1698 case DW_OP_swap:
1699 if (stack.size() < 2)
1700 {
1701 if (error_ptr)
1702 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_swap.");
1703 return false;
1704 }
1705 else
1706 {
1707 tmp = stack.back();
1708 stack.back() = stack[stack.size() - 2];
1709 stack[stack.size() - 2] = tmp;
1710 }
1711 break;
1712
1713 //----------------------------------------------------------------------
1714 // OPCODE: DW_OP_rot
1715 // OPERANDS: none
1716 // DESCRIPTION: Rotates the first three stack entries. The entry at
1717 // the top of the stack becomes the third stack entry, the second
1718 // entry becomes the top of the stack, and the third entry becomes
1719 // the second entry.
1720 //----------------------------------------------------------------------
1721 case DW_OP_rot:
1722 if (stack.size() < 3)
1723 {
1724 if (error_ptr)
1725 error_ptr->SetErrorString("Expression stack needs at least 3 items for DW_OP_rot.");
1726 return false;
1727 }
1728 else
1729 {
1730 size_t last_idx = stack.size() - 1;
1731 Value old_top = stack[last_idx];
1732 stack[last_idx] = stack[last_idx - 1];
1733 stack[last_idx - 1] = stack[last_idx - 2];
1734 stack[last_idx - 2] = old_top;
1735 }
1736 break;
1737
1738 //----------------------------------------------------------------------
1739 // OPCODE: DW_OP_abs
1740 // OPERANDS: none
1741 // DESCRIPTION: pops the top stack entry, interprets it as a signed
1742 // value and pushes its absolute value. If the absolute value can not be
1743 // represented, the result is undefined.
1744 //----------------------------------------------------------------------
1745 case DW_OP_abs:
1746 if (stack.empty())
1747 {
1748 if (error_ptr)
1749 error_ptr->SetErrorString("Expression stack needs at least 1 item for DW_OP_abs.");
1750 return false;
1751 }
1752 else if (stack.back().ResolveValue(exe_ctx, ast_context).AbsoluteValue() == false)
1753 {
1754 if (error_ptr)
1755 error_ptr->SetErrorString("Failed to take the absolute value of the first stack item.");
1756 return false;
1757 }
1758 break;
1759
1760 //----------------------------------------------------------------------
1761 // OPCODE: DW_OP_and
1762 // OPERANDS: none
1763 // DESCRIPTION: pops the top two stack values, performs a bitwise and
1764 // operation on the two, and pushes the result.
1765 //----------------------------------------------------------------------
1766 case DW_OP_and:
1767 if (stack.size() < 2)
1768 {
1769 if (error_ptr)
1770 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_and.");
1771 return false;
1772 }
1773 else
1774 {
1775 tmp = stack.back();
1776 stack.pop_back();
1777 stack.back().ResolveValue(exe_ctx, ast_context) = stack.back().ResolveValue(exe_ctx, ast_context) & tmp.ResolveValue(exe_ctx, ast_context);
1778 }
1779 break;
1780
1781 //----------------------------------------------------------------------
1782 // OPCODE: DW_OP_div
1783 // OPERANDS: none
1784 // DESCRIPTION: pops the top two stack values, divides the former second
1785 // entry by the former top of the stack using signed division, and
1786 // pushes the result.
1787 //----------------------------------------------------------------------
1788 case DW_OP_div:
1789 if (stack.size() < 2)
1790 {
1791 if (error_ptr)
1792 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_div.");
1793 return false;
1794 }
1795 else
1796 {
1797 tmp = stack.back();
1798 if (tmp.ResolveValue(exe_ctx, ast_context).IsZero())
1799 {
1800 if (error_ptr)
1801 error_ptr->SetErrorString("Divide by zero.");
1802 return false;
1803 }
1804 else
1805 {
1806 stack.pop_back();
1807 stack.back() = stack.back().ResolveValue(exe_ctx, ast_context) / tmp.ResolveValue(exe_ctx, ast_context);
1808 if (!stack.back().ResolveValue(exe_ctx, ast_context).IsValid())
1809 {
1810 if (error_ptr)
1811 error_ptr->SetErrorString("Divide failed.");
1812 return false;
1813 }
1814 }
1815 }
1816 break;
1817
1818 //----------------------------------------------------------------------
1819 // OPCODE: DW_OP_minus
1820 // OPERANDS: none
1821 // DESCRIPTION: pops the top two stack values, subtracts the former top
1822 // of the stack from the former second entry, and pushes the result.
1823 //----------------------------------------------------------------------
1824 case DW_OP_minus:
1825 if (stack.size() < 2)
1826 {
1827 if (error_ptr)
1828 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_minus.");
1829 return false;
1830 }
1831 else
1832 {
1833 tmp = stack.back();
1834 stack.pop_back();
1835 stack.back().ResolveValue(exe_ctx, ast_context) = stack.back().ResolveValue(exe_ctx, ast_context) - tmp.ResolveValue(exe_ctx, ast_context);
1836 }
1837 break;
1838
1839 //----------------------------------------------------------------------
1840 // OPCODE: DW_OP_mod
1841 // OPERANDS: none
1842 // DESCRIPTION: pops the top two stack values and pushes the result of
1843 // the calculation: former second stack entry modulo the former top of
1844 // the stack.
1845 //----------------------------------------------------------------------
1846 case DW_OP_mod:
1847 if (stack.size() < 2)
1848 {
1849 if (error_ptr)
1850 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_mod.");
1851 return false;
1852 }
1853 else
1854 {
1855 tmp = stack.back();
1856 stack.pop_back();
1857 stack.back().ResolveValue(exe_ctx, ast_context) = stack.back().ResolveValue(exe_ctx, ast_context) % tmp.ResolveValue(exe_ctx, ast_context);
1858 }
1859 break;
1860
1861
1862 //----------------------------------------------------------------------
1863 // OPCODE: DW_OP_mul
1864 // OPERANDS: none
1865 // DESCRIPTION: pops the top two stack entries, multiplies them
1866 // together, and pushes the result.
1867 //----------------------------------------------------------------------
1868 case DW_OP_mul:
1869 if (stack.size() < 2)
1870 {
1871 if (error_ptr)
1872 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_mul.");
1873 return false;
1874 }
1875 else
1876 {
1877 tmp = stack.back();
1878 stack.pop_back();
1879 stack.back().ResolveValue(exe_ctx, ast_context) = stack.back().ResolveValue(exe_ctx, ast_context) * tmp.ResolveValue(exe_ctx, ast_context);
1880 }
1881 break;
1882
1883 //----------------------------------------------------------------------
1884 // OPCODE: DW_OP_neg
1885 // OPERANDS: none
1886 // DESCRIPTION: pops the top stack entry, and pushes its negation.
1887 //----------------------------------------------------------------------
1888 case DW_OP_neg:
1889 if (stack.empty())
1890 {
1891 if (error_ptr)
1892 error_ptr->SetErrorString("Expression stack needs at least 1 item for DW_OP_neg.");
1893 return false;
1894 }
1895 else
1896 {
1897 if (stack.back().ResolveValue(exe_ctx, ast_context).UnaryNegate() == false)
1898 {
1899 if (error_ptr)
1900 error_ptr->SetErrorString("Unary negate failed.");
1901 return false;
1902 }
1903 }
1904 break;
1905
1906 //----------------------------------------------------------------------
1907 // OPCODE: DW_OP_not
1908 // OPERANDS: none
1909 // DESCRIPTION: pops the top stack entry, and pushes its bitwise
1910 // complement
1911 //----------------------------------------------------------------------
1912 case DW_OP_not:
1913 if (stack.empty())
1914 {
1915 if (error_ptr)
1916 error_ptr->SetErrorString("Expression stack needs at least 1 item for DW_OP_not.");
1917 return false;
1918 }
1919 else
1920 {
1921 if (stack.back().ResolveValue(exe_ctx, ast_context).OnesComplement() == false)
1922 {
1923 if (error_ptr)
1924 error_ptr->SetErrorString("Logical NOT failed.");
1925 return false;
1926 }
1927 }
1928 break;
1929
1930 //----------------------------------------------------------------------
1931 // OPCODE: DW_OP_or
1932 // OPERANDS: none
1933 // DESCRIPTION: pops the top two stack entries, performs a bitwise or
1934 // operation on the two, and pushes the result.
1935 //----------------------------------------------------------------------
1936 case DW_OP_or:
1937 if (stack.size() < 2)
1938 {
1939 if (error_ptr)
1940 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_or.");
1941 return false;
1942 }
1943 else
1944 {
1945 tmp = stack.back();
1946 stack.pop_back();
1947 stack.back().ResolveValue(exe_ctx, ast_context) = stack.back().ResolveValue(exe_ctx, ast_context) | tmp.ResolveValue(exe_ctx, ast_context);
1948 }
1949 break;
1950
1951 //----------------------------------------------------------------------
1952 // OPCODE: DW_OP_plus
1953 // OPERANDS: none
1954 // DESCRIPTION: pops the top two stack entries, adds them together, and
1955 // pushes the result.
1956 //----------------------------------------------------------------------
1957 case DW_OP_plus:
1958 if (stack.size() < 2)
1959 {
1960 if (error_ptr)
1961 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_plus.");
1962 return false;
1963 }
1964 else
1965 {
1966 tmp = stack.back();
1967 stack.pop_back();
1968 stack.back().ResolveValue(exe_ctx, ast_context) = stack.back().ResolveValue(exe_ctx, ast_context) + tmp.ResolveValue(exe_ctx, ast_context);
1969 }
1970 break;
1971
1972 //----------------------------------------------------------------------
1973 // OPCODE: DW_OP_plus_uconst
1974 // OPERANDS: none
1975 // DESCRIPTION: pops the top stack entry, adds it to the unsigned LEB128
1976 // constant operand and pushes the result.
1977 //----------------------------------------------------------------------
1978 case DW_OP_plus_uconst:
1979 if (stack.empty())
1980 {
1981 if (error_ptr)
1982 error_ptr->SetErrorString("Expression stack needs at least 1 item for DW_OP_plus_uconst.");
1983 return false;
1984 }
1985 else
1986 {
1987 uint32_t uconst_value = opcodes.GetULEB128(&offset);
1988 // Implicit conversion from a UINT to a Scalar...
1989 stack.back().ResolveValue(exe_ctx, ast_context) += uconst_value;
1990 if (!stack.back().ResolveValue(exe_ctx, ast_context).IsValid())
1991 {
1992 if (error_ptr)
1993 error_ptr->SetErrorString("DW_OP_plus_uconst failed.");
1994 return false;
1995 }
1996 }
1997 break;
1998
1999 //----------------------------------------------------------------------
2000 // OPCODE: DW_OP_shl
2001 // OPERANDS: none
2002 // DESCRIPTION: pops the top two stack entries, shifts the former
2003 // second entry left by the number of bits specified by the former top
2004 // of the stack, and pushes the result.
2005 //----------------------------------------------------------------------
2006 case DW_OP_shl:
2007 if (stack.size() < 2)
2008 {
2009 if (error_ptr)
2010 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_shl.");
2011 return false;
2012 }
2013 else
2014 {
2015 tmp = stack.back();
2016 stack.pop_back();
2017 stack.back().ResolveValue(exe_ctx, ast_context) <<= tmp.ResolveValue(exe_ctx, ast_context);
2018 }
2019 break;
2020
2021 //----------------------------------------------------------------------
2022 // OPCODE: DW_OP_shr
2023 // OPERANDS: none
2024 // DESCRIPTION: pops the top two stack entries, shifts the former second
2025 // entry right logically (filling with zero bits) by the number of bits
2026 // specified by the former top of the stack, and pushes the result.
2027 //----------------------------------------------------------------------
2028 case DW_OP_shr:
2029 if (stack.size() < 2)
2030 {
2031 if (error_ptr)
2032 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_shr.");
2033 return false;
2034 }
2035 else
2036 {
2037 tmp = stack.back();
2038 stack.pop_back();
2039 if (stack.back().ResolveValue(exe_ctx, ast_context).ShiftRightLogical(tmp.ResolveValue(exe_ctx, ast_context)) == false)
2040 {
2041 if (error_ptr)
2042 error_ptr->SetErrorString("DW_OP_shr failed.");
2043 return false;
2044 }
2045 }
2046 break;
2047
2048 //----------------------------------------------------------------------
2049 // OPCODE: DW_OP_shra
2050 // OPERANDS: none
2051 // DESCRIPTION: pops the top two stack entries, shifts the former second
2052 // entry right arithmetically (divide the magnitude by 2, keep the same
2053 // sign for the result) by the number of bits specified by the former
2054 // top of the stack, and pushes the result.
2055 //----------------------------------------------------------------------
2056 case DW_OP_shra:
2057 if (stack.size() < 2)
2058 {
2059 if (error_ptr)
2060 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_shra.");
2061 return false;
2062 }
2063 else
2064 {
2065 tmp = stack.back();
2066 stack.pop_back();
2067 stack.back().ResolveValue(exe_ctx, ast_context) >>= tmp.ResolveValue(exe_ctx, ast_context);
2068 }
2069 break;
2070
2071 //----------------------------------------------------------------------
2072 // OPCODE: DW_OP_xor
2073 // OPERANDS: none
2074 // DESCRIPTION: pops the top two stack entries, performs the bitwise
2075 // exclusive-or operation on the two, and pushes the result.
2076 //----------------------------------------------------------------------
2077 case DW_OP_xor:
2078 if (stack.size() < 2)
2079 {
2080 if (error_ptr)
2081 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_xor.");
2082 return false;
2083 }
2084 else
2085 {
2086 tmp = stack.back();
2087 stack.pop_back();
2088 stack.back().ResolveValue(exe_ctx, ast_context) = stack.back().ResolveValue(exe_ctx, ast_context) ^ tmp.ResolveValue(exe_ctx, ast_context);
2089 }
2090 break;
2091
2092
2093 //----------------------------------------------------------------------
2094 // OPCODE: DW_OP_skip
2095 // OPERANDS: int16_t
2096 // DESCRIPTION: An unconditional branch. Its single operand is a 2-byte
2097 // signed integer constant. The 2-byte constant is the number of bytes
2098 // of the DWARF expression to skip forward or backward from the current
2099 // operation, beginning after the 2-byte constant.
2100 //----------------------------------------------------------------------
2101 case DW_OP_skip:
2102 {
2103 int16_t skip_offset = (int16_t)opcodes.GetU16(&offset);
2104 uint32_t new_offset = offset + skip_offset;
2105 if (new_offset >= opcodes_offset && new_offset < end_offset)
2106 offset = new_offset;
2107 else
2108 {
2109 if (error_ptr)
2110 error_ptr->SetErrorString("Invalid opcode offset in DW_OP_skip.");
2111 return false;
2112 }
2113 }
2114 break;
2115
2116 //----------------------------------------------------------------------
2117 // OPCODE: DW_OP_bra
2118 // OPERANDS: int16_t
2119 // DESCRIPTION: A conditional branch. Its single operand is a 2-byte
2120 // signed integer constant. This operation pops the top of stack. If
2121 // the value popped is not the constant 0, the 2-byte constant operand
2122 // is the number of bytes of the DWARF expression to skip forward or
2123 // backward from the current operation, beginning after the 2-byte
2124 // constant.
2125 //----------------------------------------------------------------------
2126 case DW_OP_bra:
2127 {
2128 tmp = stack.back();
2129 stack.pop_back();
2130 int16_t bra_offset = (int16_t)opcodes.GetU16(&offset);
2131 Scalar zero(0);
2132 if (tmp.ResolveValue(exe_ctx, ast_context) != zero)
2133 {
2134 uint32_t new_offset = offset + bra_offset;
2135 if (new_offset >= opcodes_offset && new_offset < end_offset)
2136 offset = new_offset;
2137 else
2138 {
2139 if (error_ptr)
2140 error_ptr->SetErrorString("Invalid opcode offset in DW_OP_bra.");
2141 return false;
2142 }
2143 }
2144 }
2145 break;
2146
2147 //----------------------------------------------------------------------
2148 // OPCODE: DW_OP_eq
2149 // OPERANDS: none
2150 // DESCRIPTION: pops the top two stack values, compares using the
2151 // equals (==) operator.
2152 // STACK RESULT: push the constant value 1 onto the stack if the result
2153 // of the operation is true or the constant value 0 if the result of the
2154 // operation is false.
2155 //----------------------------------------------------------------------
2156 case DW_OP_eq:
2157 if (stack.size() < 2)
2158 {
2159 if (error_ptr)
2160 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_eq.");
2161 return false;
2162 }
2163 else
2164 {
2165 tmp = stack.back();
2166 stack.pop_back();
2167 stack.back().ResolveValue(exe_ctx, ast_context) = stack.back().ResolveValue(exe_ctx, ast_context) == tmp.ResolveValue(exe_ctx, ast_context);
2168 }
2169 break;
2170
2171 //----------------------------------------------------------------------
2172 // OPCODE: DW_OP_ge
2173 // OPERANDS: none
2174 // DESCRIPTION: pops the top two stack values, compares using the
2175 // greater than or equal to (>=) operator.
2176 // STACK RESULT: push the constant value 1 onto the stack if the result
2177 // of the operation is true or the constant value 0 if the result of the
2178 // operation is false.
2179 //----------------------------------------------------------------------
2180 case DW_OP_ge:
2181 if (stack.size() < 2)
2182 {
2183 if (error_ptr)
2184 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_ge.");
2185 return false;
2186 }
2187 else
2188 {
2189 tmp = stack.back();
2190 stack.pop_back();
2191 stack.back().ResolveValue(exe_ctx, ast_context) = stack.back().ResolveValue(exe_ctx, ast_context) >= tmp.ResolveValue(exe_ctx, ast_context);
2192 }
2193 break;
2194
2195 //----------------------------------------------------------------------
2196 // OPCODE: DW_OP_gt
2197 // OPERANDS: none
2198 // DESCRIPTION: pops the top two stack values, compares using the
2199 // greater than (>) operator.
2200 // STACK RESULT: push the constant value 1 onto the stack if the result
2201 // of the operation is true or the constant value 0 if the result of the
2202 // operation is false.
2203 //----------------------------------------------------------------------
2204 case DW_OP_gt:
2205 if (stack.size() < 2)
2206 {
2207 if (error_ptr)
2208 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_gt.");
2209 return false;
2210 }
2211 else
2212 {
2213 tmp = stack.back();
2214 stack.pop_back();
2215 stack.back().ResolveValue(exe_ctx, ast_context) = stack.back().ResolveValue(exe_ctx, ast_context) > tmp.ResolveValue(exe_ctx, ast_context);
2216 }
2217 break;
2218
2219 //----------------------------------------------------------------------
2220 // OPCODE: DW_OP_le
2221 // OPERANDS: none
2222 // DESCRIPTION: pops the top two stack values, compares using the
2223 // less than or equal to (<=) operator.
2224 // STACK RESULT: push the constant value 1 onto the stack if the result
2225 // of the operation is true or the constant value 0 if the result of the
2226 // operation is false.
2227 //----------------------------------------------------------------------
2228 case DW_OP_le:
2229 if (stack.size() < 2)
2230 {
2231 if (error_ptr)
2232 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_le.");
2233 return false;
2234 }
2235 else
2236 {
2237 tmp = stack.back();
2238 stack.pop_back();
2239 stack.back().ResolveValue(exe_ctx, ast_context) = stack.back().ResolveValue(exe_ctx, ast_context) <= tmp.ResolveValue(exe_ctx, ast_context);
2240 }
2241 break;
2242
2243 //----------------------------------------------------------------------
2244 // OPCODE: DW_OP_lt
2245 // OPERANDS: none
2246 // DESCRIPTION: pops the top two stack values, compares using the
2247 // less than (<) operator.
2248 // STACK RESULT: push the constant value 1 onto the stack if the result
2249 // of the operation is true or the constant value 0 if the result of the
2250 // operation is false.
2251 //----------------------------------------------------------------------
2252 case DW_OP_lt:
2253 if (stack.size() < 2)
2254 {
2255 if (error_ptr)
2256 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_lt.");
2257 return false;
2258 }
2259 else
2260 {
2261 tmp = stack.back();
2262 stack.pop_back();
2263 stack.back().ResolveValue(exe_ctx, ast_context) = stack.back().ResolveValue(exe_ctx, ast_context) < tmp.ResolveValue(exe_ctx, ast_context);
2264 }
2265 break;
2266
2267 //----------------------------------------------------------------------
2268 // OPCODE: DW_OP_ne
2269 // OPERANDS: none
2270 // DESCRIPTION: pops the top two stack values, compares using the
2271 // not equal (!=) operator.
2272 // STACK RESULT: push the constant value 1 onto the stack if the result
2273 // of the operation is true or the constant value 0 if the result of the
2274 // operation is false.
2275 //----------------------------------------------------------------------
2276 case DW_OP_ne:
2277 if (stack.size() < 2)
2278 {
2279 if (error_ptr)
2280 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_ne.");
2281 return false;
2282 }
2283 else
2284 {
2285 tmp = stack.back();
2286 stack.pop_back();
2287 stack.back().ResolveValue(exe_ctx, ast_context) = stack.back().ResolveValue(exe_ctx, ast_context) != tmp.ResolveValue(exe_ctx, ast_context);
2288 }
2289 break;
2290
2291 //----------------------------------------------------------------------
2292 // OPCODE: DW_OP_litn
2293 // OPERANDS: none
2294 // DESCRIPTION: encode the unsigned literal values from 0 through 31.
2295 // STACK RESULT: push the unsigned literal constant value onto the top
2296 // of the stack.
2297 //----------------------------------------------------------------------
2298 case DW_OP_lit0:
2299 case DW_OP_lit1:
2300 case DW_OP_lit2:
2301 case DW_OP_lit3:
2302 case DW_OP_lit4:
2303 case DW_OP_lit5:
2304 case DW_OP_lit6:
2305 case DW_OP_lit7:
2306 case DW_OP_lit8:
2307 case DW_OP_lit9:
2308 case DW_OP_lit10:
2309 case DW_OP_lit11:
2310 case DW_OP_lit12:
2311 case DW_OP_lit13:
2312 case DW_OP_lit14:
2313 case DW_OP_lit15:
2314 case DW_OP_lit16:
2315 case DW_OP_lit17:
2316 case DW_OP_lit18:
2317 case DW_OP_lit19:
2318 case DW_OP_lit20:
2319 case DW_OP_lit21:
2320 case DW_OP_lit22:
2321 case DW_OP_lit23:
2322 case DW_OP_lit24:
2323 case DW_OP_lit25:
2324 case DW_OP_lit26:
2325 case DW_OP_lit27:
2326 case DW_OP_lit28:
2327 case DW_OP_lit29:
2328 case DW_OP_lit30:
2329 case DW_OP_lit31:
Greg Clayton801417e2011-07-07 01:59:51 +00002330 stack.push_back(Scalar(op - DW_OP_lit0));
Chris Lattner24943d22010-06-08 16:52:24 +00002331 break;
2332
2333 //----------------------------------------------------------------------
2334 // OPCODE: DW_OP_regN
2335 // OPERANDS: none
2336 // DESCRIPTION: Push the value in register n on the top of the stack.
2337 //----------------------------------------------------------------------
2338 case DW_OP_reg0:
2339 case DW_OP_reg1:
2340 case DW_OP_reg2:
2341 case DW_OP_reg3:
2342 case DW_OP_reg4:
2343 case DW_OP_reg5:
2344 case DW_OP_reg6:
2345 case DW_OP_reg7:
2346 case DW_OP_reg8:
2347 case DW_OP_reg9:
2348 case DW_OP_reg10:
2349 case DW_OP_reg11:
2350 case DW_OP_reg12:
2351 case DW_OP_reg13:
2352 case DW_OP_reg14:
2353 case DW_OP_reg15:
2354 case DW_OP_reg16:
2355 case DW_OP_reg17:
2356 case DW_OP_reg18:
2357 case DW_OP_reg19:
2358 case DW_OP_reg20:
2359 case DW_OP_reg21:
2360 case DW_OP_reg22:
2361 case DW_OP_reg23:
2362 case DW_OP_reg24:
2363 case DW_OP_reg25:
2364 case DW_OP_reg26:
2365 case DW_OP_reg27:
2366 case DW_OP_reg28:
2367 case DW_OP_reg29:
2368 case DW_OP_reg30:
2369 case DW_OP_reg31:
2370 {
2371 reg_num = op - DW_OP_reg0;
2372
Jason Molenda8e69de42010-11-20 01:28:30 +00002373 if (ReadRegisterValueAsScalar (reg_ctx, reg_kind, reg_num, error_ptr, tmp))
Chris Lattner24943d22010-06-08 16:52:24 +00002374 stack.push_back(tmp);
2375 else
2376 return false;
2377 }
2378 break;
2379 //----------------------------------------------------------------------
2380 // OPCODE: DW_OP_regx
2381 // OPERANDS:
2382 // ULEB128 literal operand that encodes the register.
2383 // DESCRIPTION: Push the value in register on the top of the stack.
2384 //----------------------------------------------------------------------
2385 case DW_OP_regx:
2386 {
2387 reg_num = opcodes.GetULEB128(&offset);
Jason Molenda8e69de42010-11-20 01:28:30 +00002388 if (ReadRegisterValueAsScalar (reg_ctx, reg_kind, reg_num, error_ptr, tmp))
Chris Lattner24943d22010-06-08 16:52:24 +00002389 stack.push_back(tmp);
2390 else
2391 return false;
2392 }
2393 break;
2394
2395 //----------------------------------------------------------------------
2396 // OPCODE: DW_OP_bregN
2397 // OPERANDS:
2398 // SLEB128 offset from register N
2399 // DESCRIPTION: Value is in memory at the address specified by register
2400 // N plus an offset.
2401 //----------------------------------------------------------------------
2402 case DW_OP_breg0:
2403 case DW_OP_breg1:
2404 case DW_OP_breg2:
2405 case DW_OP_breg3:
2406 case DW_OP_breg4:
2407 case DW_OP_breg5:
2408 case DW_OP_breg6:
2409 case DW_OP_breg7:
2410 case DW_OP_breg8:
2411 case DW_OP_breg9:
2412 case DW_OP_breg10:
2413 case DW_OP_breg11:
2414 case DW_OP_breg12:
2415 case DW_OP_breg13:
2416 case DW_OP_breg14:
2417 case DW_OP_breg15:
2418 case DW_OP_breg16:
2419 case DW_OP_breg17:
2420 case DW_OP_breg18:
2421 case DW_OP_breg19:
2422 case DW_OP_breg20:
2423 case DW_OP_breg21:
2424 case DW_OP_breg22:
2425 case DW_OP_breg23:
2426 case DW_OP_breg24:
2427 case DW_OP_breg25:
2428 case DW_OP_breg26:
2429 case DW_OP_breg27:
2430 case DW_OP_breg28:
2431 case DW_OP_breg29:
2432 case DW_OP_breg30:
2433 case DW_OP_breg31:
2434 {
2435 reg_num = op - DW_OP_breg0;
2436
Jason Molenda8e69de42010-11-20 01:28:30 +00002437 if (ReadRegisterValueAsScalar (reg_ctx, reg_kind, reg_num, error_ptr, tmp))
Chris Lattner24943d22010-06-08 16:52:24 +00002438 {
2439 int64_t breg_offset = opcodes.GetSLEB128(&offset);
2440 tmp.ResolveValue(exe_ctx, ast_context) += (uint64_t)breg_offset;
Sean Callanan6fc5c712012-01-06 18:24:47 +00002441 tmp.ClearContext();
Chris Lattner24943d22010-06-08 16:52:24 +00002442 stack.push_back(tmp);
2443 stack.back().SetValueType (Value::eValueTypeLoadAddress);
2444 }
2445 else
2446 return false;
2447 }
2448 break;
2449 //----------------------------------------------------------------------
2450 // OPCODE: DW_OP_bregx
2451 // OPERANDS: 2
2452 // ULEB128 literal operand that encodes the register.
2453 // SLEB128 offset from register N
2454 // DESCRIPTION: Value is in memory at the address specified by register
2455 // N plus an offset.
2456 //----------------------------------------------------------------------
2457 case DW_OP_bregx:
2458 {
2459 reg_num = opcodes.GetULEB128(&offset);
2460
Jason Molenda8e69de42010-11-20 01:28:30 +00002461 if (ReadRegisterValueAsScalar (reg_ctx, reg_kind, reg_num, error_ptr, tmp))
Chris Lattner24943d22010-06-08 16:52:24 +00002462 {
2463 int64_t breg_offset = opcodes.GetSLEB128(&offset);
2464 tmp.ResolveValue(exe_ctx, ast_context) += (uint64_t)breg_offset;
Sean Callanan6fc5c712012-01-06 18:24:47 +00002465 tmp.ClearContext();
Chris Lattner24943d22010-06-08 16:52:24 +00002466 stack.push_back(tmp);
2467 stack.back().SetValueType (Value::eValueTypeLoadAddress);
2468 }
2469 else
2470 return false;
2471 }
2472 break;
2473
2474 case DW_OP_fbreg:
Greg Clayton567e7f32011-09-22 04:58:26 +00002475 if (exe_ctx)
Chris Lattner24943d22010-06-08 16:52:24 +00002476 {
Greg Clayton567e7f32011-09-22 04:58:26 +00002477 if (frame)
Chris Lattner24943d22010-06-08 16:52:24 +00002478 {
Greg Clayton567e7f32011-09-22 04:58:26 +00002479 Scalar value;
2480 if (frame->GetFrameBaseValue(value, error_ptr))
2481 {
2482 int64_t fbreg_offset = opcodes.GetSLEB128(&offset);
2483 value += fbreg_offset;
2484 stack.push_back(value);
2485 stack.back().SetValueType (Value::eValueTypeLoadAddress);
2486 }
2487 else
2488 return false;
Chris Lattner24943d22010-06-08 16:52:24 +00002489 }
2490 else
Greg Clayton567e7f32011-09-22 04:58:26 +00002491 {
2492 if (error_ptr)
2493 error_ptr->SetErrorString ("Invalid stack frame in context for DW_OP_fbreg opcode.");
Chris Lattner24943d22010-06-08 16:52:24 +00002494 return false;
Greg Clayton567e7f32011-09-22 04:58:26 +00002495 }
Chris Lattner24943d22010-06-08 16:52:24 +00002496 }
2497 else
2498 {
2499 if (error_ptr)
Greg Clayton567e7f32011-09-22 04:58:26 +00002500 error_ptr->SetErrorStringWithFormat ("NULL execution context for DW_OP_fbreg.\n");
Chris Lattner24943d22010-06-08 16:52:24 +00002501 return false;
2502 }
Greg Clayton567e7f32011-09-22 04:58:26 +00002503
Chris Lattner24943d22010-06-08 16:52:24 +00002504 break;
2505
2506 //----------------------------------------------------------------------
2507 // OPCODE: DW_OP_nop
2508 // OPERANDS: none
2509 // DESCRIPTION: A place holder. It has no effect on the location stack
2510 // or any of its values.
2511 //----------------------------------------------------------------------
2512 case DW_OP_nop:
2513 break;
2514
2515 //----------------------------------------------------------------------
2516 // OPCODE: DW_OP_piece
2517 // OPERANDS: 1
2518 // ULEB128: byte size of the piece
2519 // DESCRIPTION: The operand describes the size in bytes of the piece of
2520 // the object referenced by the DWARF expression whose result is at the
2521 // top of the stack. If the piece is located in a register, but does not
2522 // occupy the entire register, the placement of the piece within that
2523 // register is defined by the ABI.
2524 //
2525 // Many compilers store a single variable in sets of registers, or store
2526 // a variable partially in memory and partially in registers.
2527 // DW_OP_piece provides a way of describing how large a part of a
2528 // variable a particular DWARF expression refers to.
2529 //----------------------------------------------------------------------
2530 case DW_OP_piece:
2531 if (error_ptr)
2532 error_ptr->SetErrorString ("Unimplemented opcode DW_OP_piece.");
2533 return false;
2534
2535 //----------------------------------------------------------------------
2536 // OPCODE: DW_OP_push_object_address
2537 // OPERANDS: none
2538 // DESCRIPTION: Pushes the address of the object currently being
2539 // evaluated as part of evaluation of a user presented expression.
2540 // This object may correspond to an independent variable described by
2541 // its own DIE or it may be a component of an array, structure, or class
2542 // whose address has been dynamically determined by an earlier step
2543 // during user expression evaluation.
2544 //----------------------------------------------------------------------
2545 case DW_OP_push_object_address:
2546 if (error_ptr)
2547 error_ptr->SetErrorString ("Unimplemented opcode DW_OP_push_object_address.");
2548 return false;
2549
2550 //----------------------------------------------------------------------
2551 // OPCODE: DW_OP_call2
2552 // OPERANDS:
2553 // uint16_t compile unit relative offset of a DIE
2554 // DESCRIPTION: Performs subroutine calls during evaluation
2555 // of a DWARF expression. The operand is the 2-byte unsigned offset
2556 // of a debugging information entry in the current compilation unit.
2557 //
2558 // Operand interpretation is exactly like that for DW_FORM_ref2.
2559 //
2560 // This operation transfers control of DWARF expression evaluation
2561 // to the DW_AT_location attribute of the referenced DIE. If there is
2562 // no such attribute, then there is no effect. Execution of the DWARF
2563 // expression of a DW_AT_location attribute may add to and/or remove from
2564 // values on the stack. Execution returns to the point following the call
2565 // when the end of the attribute is reached. Values on the stack at the
2566 // time of the call may be used as parameters by the called expression
2567 // and values left on the stack by the called expression may be used as
2568 // return values by prior agreement between the calling and called
2569 // expressions.
2570 //----------------------------------------------------------------------
2571 case DW_OP_call2:
2572 if (error_ptr)
2573 error_ptr->SetErrorString ("Unimplemented opcode DW_OP_call2.");
2574 return false;
2575 //----------------------------------------------------------------------
2576 // OPCODE: DW_OP_call4
2577 // OPERANDS: 1
2578 // uint32_t compile unit relative offset of a DIE
2579 // DESCRIPTION: Performs a subroutine call during evaluation of a DWARF
2580 // expression. For DW_OP_call4, the operand is a 4-byte unsigned offset
2581 // of a debugging information entry in the current compilation unit.
2582 //
2583 // Operand interpretation DW_OP_call4 is exactly like that for
2584 // DW_FORM_ref4.
2585 //
2586 // This operation transfers control of DWARF expression evaluation
2587 // to the DW_AT_location attribute of the referenced DIE. If there is
2588 // no such attribute, then there is no effect. Execution of the DWARF
2589 // expression of a DW_AT_location attribute may add to and/or remove from
2590 // values on the stack. Execution returns to the point following the call
2591 // when the end of the attribute is reached. Values on the stack at the
2592 // time of the call may be used as parameters by the called expression
2593 // and values left on the stack by the called expression may be used as
2594 // return values by prior agreement between the calling and called
2595 // expressions.
2596 //----------------------------------------------------------------------
2597 case DW_OP_call4:
2598 if (error_ptr)
2599 error_ptr->SetErrorString ("Unimplemented opcode DW_OP_call4.");
2600 return false;
2601
Greg Claytona1b9a902011-11-13 04:15:56 +00002602#if 0
Chris Lattner24943d22010-06-08 16:52:24 +00002603 //----------------------------------------------------------------------
2604 // OPCODE: DW_OP_call_ref
2605 // OPERANDS:
2606 // uint32_t absolute DIE offset for 32-bit DWARF or a uint64_t
2607 // absolute DIE offset for 64 bit DWARF.
2608 // DESCRIPTION: Performs a subroutine call during evaluation of a DWARF
2609 // expression. Takes a single operand. In the 32-bit DWARF format, the
2610 // operand is a 4-byte unsigned value; in the 64-bit DWARF format, it
2611 // is an 8-byte unsigned value. The operand is used as the offset of a
2612 // debugging information entry in a .debug_info section which may be
2613 // contained in a shared object for executable other than that
2614 // containing the operator. For references from one shared object or
2615 // executable to another, the relocation must be performed by the
2616 // consumer.
2617 //
2618 // Operand interpretation of DW_OP_call_ref is exactly like that for
2619 // DW_FORM_ref_addr.
2620 //
2621 // This operation transfers control of DWARF expression evaluation
2622 // to the DW_AT_location attribute of the referenced DIE. If there is
2623 // no such attribute, then there is no effect. Execution of the DWARF
2624 // expression of a DW_AT_location attribute may add to and/or remove from
2625 // values on the stack. Execution returns to the point following the call
2626 // when the end of the attribute is reached. Values on the stack at the
2627 // time of the call may be used as parameters by the called expression
2628 // and values left on the stack by the called expression may be used as
2629 // return values by prior agreement between the calling and called
2630 // expressions.
2631 //----------------------------------------------------------------------
2632 case DW_OP_call_ref:
2633 if (error_ptr)
2634 error_ptr->SetErrorString ("Unimplemented opcode DW_OP_call_ref.");
2635 return false;
2636
Greg Claytona1b9a902011-11-13 04:15:56 +00002637 //----------------------------------------------------------------------
2638 // OPCODE: DW_OP_APPLE_array_ref
2639 // OPERANDS: none
2640 // DESCRIPTION: Pops a value off the stack and uses it as the array
2641 // index. Pops a second value off the stack and uses it as the array
2642 // itself. Pushes a value onto the stack representing the element of
2643 // the array specified by the index.
2644 //----------------------------------------------------------------------
2645 case DW_OP_APPLE_array_ref:
Chris Lattner24943d22010-06-08 16:52:24 +00002646 {
2647 if (stack.size() < 2)
2648 {
2649 if (error_ptr)
2650 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_APPLE_array_ref.");
2651 return false;
2652 }
2653
2654 Value index_val = stack.back();
2655 stack.pop_back();
2656 Value array_val = stack.back();
2657 stack.pop_back();
2658
2659 Scalar &index_scalar = index_val.ResolveValue(exe_ctx, ast_context);
Greg Clayton381f9682011-04-01 18:14:08 +00002660 int64_t index = index_scalar.SLongLong(LLONG_MAX);
Chris Lattner24943d22010-06-08 16:52:24 +00002661
Greg Clayton381f9682011-04-01 18:14:08 +00002662 if (index == LLONG_MAX)
Chris Lattner24943d22010-06-08 16:52:24 +00002663 {
2664 if (error_ptr)
2665 error_ptr->SetErrorString("Invalid array index.");
2666 return false;
2667 }
Greg Claytona1b9a902011-11-13 04:15:56 +00002668
Greg Clayton6916e352010-11-13 03:52:47 +00002669 if (array_val.GetContextType() != Value::eContextTypeClangType)
Chris Lattner24943d22010-06-08 16:52:24 +00002670 {
2671 if (error_ptr)
2672 error_ptr->SetErrorString("Arrays without Clang types are unhandled at this time.");
2673 return false;
2674 }
2675
2676 if (array_val.GetValueType() != Value::eValueTypeLoadAddress &&
2677 array_val.GetValueType() != Value::eValueTypeHostAddress)
2678 {
2679 if (error_ptr)
2680 error_ptr->SetErrorString("Array must be stored in memory.");
2681 return false;
2682 }
2683
Greg Clayton462d4142010-09-29 01:12:09 +00002684 void *array_type = array_val.GetClangType();
Chris Lattner24943d22010-06-08 16:52:24 +00002685
2686 void *member_type;
2687 uint64_t size = 0;
2688
2689 if ((!ClangASTContext::IsPointerType(array_type, &member_type)) &&
2690 (!ClangASTContext::IsArrayType(array_type, &member_type, &size)))
2691 {
2692 if (error_ptr)
2693 error_ptr->SetErrorString("Array reference from something that is neither a pointer nor an array.");
2694 return false;
2695 }
2696
2697 if (size && (index >= size || index < 0))
2698 {
2699 if (error_ptr)
2700 error_ptr->SetErrorStringWithFormat("Out of bounds array access. %lld is not in [0, %llu]", index, size);
2701 return false;
2702 }
2703
Greg Clayton960d6a42010-08-03 00:35:52 +00002704 uint64_t member_bit_size = ClangASTType::GetClangTypeBitWidth(ast_context, member_type);
2705 uint64_t member_bit_align = ClangASTType::GetTypeBitAlign(ast_context, member_type);
Chris Lattner24943d22010-06-08 16:52:24 +00002706 uint64_t member_bit_incr = ((member_bit_size + member_bit_align - 1) / member_bit_align) * member_bit_align;
2707 if (member_bit_incr % 8)
2708 {
2709 if (error_ptr)
Jason Molenda95b7b432011-09-20 00:26:08 +00002710 error_ptr->SetErrorStringWithFormat("Array increment is not byte aligned");
Chris Lattner24943d22010-06-08 16:52:24 +00002711 return false;
2712 }
2713 int64_t member_offset = (int64_t)(member_bit_incr / 8) * index;
2714
2715 Value member;
2716
Greg Clayton6916e352010-11-13 03:52:47 +00002717 member.SetContext(Value::eContextTypeClangType, member_type);
Chris Lattner24943d22010-06-08 16:52:24 +00002718 member.SetValueType(array_val.GetValueType());
2719
2720 addr_t array_base = (addr_t)array_val.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
2721 addr_t member_loc = array_base + member_offset;
2722 member.GetScalar() = (uint64_t)member_loc;
2723
2724 stack.push_back(member);
2725 }
Greg Claytona1b9a902011-11-13 04:15:56 +00002726 break;
Chris Lattner24943d22010-06-08 16:52:24 +00002727
2728 //----------------------------------------------------------------------
2729 // OPCODE: DW_OP_APPLE_uninit
2730 // OPERANDS: none
2731 // DESCRIPTION: Lets us know that the value is currently not initialized
2732 //----------------------------------------------------------------------
2733 case DW_OP_APPLE_uninit:
2734 //return eResultTypeErrorUninitialized;
2735 break; // Ignore this as we have seen cases where this value is incorrectly added
2736
2737 //----------------------------------------------------------------------
2738 // OPCODE: DW_OP_APPLE_assign
2739 // OPERANDS: none
2740 // DESCRIPTION: Pops a value off of the stack and assigns it to the next
2741 // item on the stack which must be something assignable (inferior
2742 // Variable, inferior Type with address, inferior register, or
2743 // expression local variable.
2744 //----------------------------------------------------------------------
2745 case DW_OP_APPLE_assign:
2746 if (stack.size() < 2)
2747 {
2748 if (error_ptr)
2749 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_APPLE_assign.");
2750 return false;
2751 }
2752 else
2753 {
2754 tmp = stack.back();
2755 stack.pop_back();
2756 Value::ContextType context_type = stack.back().GetContextType();
Greg Claytoncd548032011-02-01 01:31:41 +00002757 StreamString new_value(Stream::eBinary, 4, lldb::endian::InlHostByteOrder());
Chris Lattner24943d22010-06-08 16:52:24 +00002758 switch (context_type)
2759 {
Greg Clayton6916e352010-11-13 03:52:47 +00002760 case Value::eContextTypeClangType:
Chris Lattner24943d22010-06-08 16:52:24 +00002761 {
Greg Clayton462d4142010-09-29 01:12:09 +00002762 void *clang_type = stack.back().GetClangType();
Chris Lattner24943d22010-06-08 16:52:24 +00002763
2764 if (ClangASTContext::IsAggregateType (clang_type))
2765 {
2766 Value::ValueType source_value_type = tmp.GetValueType();
2767 Value::ValueType target_value_type = stack.back().GetValueType();
2768
2769 addr_t source_addr = (addr_t)tmp.GetScalar().ULongLong();
2770 addr_t target_addr = (addr_t)stack.back().GetScalar().ULongLong();
2771
Greg Clayton960d6a42010-08-03 00:35:52 +00002772 size_t byte_size = (ClangASTType::GetClangTypeBitWidth(ast_context, clang_type) + 7) / 8;
Chris Lattner24943d22010-06-08 16:52:24 +00002773
2774 switch (source_value_type)
2775 {
Greg Clayton4fdf7602011-03-20 04:57:14 +00002776 case Value::eValueTypeScalar:
2777 case Value::eValueTypeFileAddress:
2778 break;
2779
Chris Lattner24943d22010-06-08 16:52:24 +00002780 case Value::eValueTypeLoadAddress:
2781 switch (target_value_type)
2782 {
2783 case Value::eValueTypeLoadAddress:
2784 {
2785 DataBufferHeap data;
2786 data.SetByteSize(byte_size);
2787
2788 Error error;
Greg Clayton567e7f32011-09-22 04:58:26 +00002789 if (process->ReadMemory (source_addr, data.GetBytes(), byte_size, error) != byte_size)
Chris Lattner24943d22010-06-08 16:52:24 +00002790 {
2791 if (error_ptr)
2792 error_ptr->SetErrorStringWithFormat ("Couldn't read a composite type from the target: %s", error.AsCString());
2793 return false;
2794 }
2795
Greg Clayton567e7f32011-09-22 04:58:26 +00002796 if (process->WriteMemory (target_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 write a composite type to the target: %s", error.AsCString());
2800 return false;
2801 }
2802 }
2803 break;
2804 case Value::eValueTypeHostAddress:
Greg Clayton567e7f32011-09-22 04:58:26 +00002805 if (process->GetByteOrder() != lldb::endian::InlHostByteOrder())
Chris Lattner24943d22010-06-08 16:52:24 +00002806 {
2807 if (error_ptr)
2808 error_ptr->SetErrorStringWithFormat ("Copy of composite types between incompatible byte orders is unimplemented");
2809 return false;
2810 }
2811 else
2812 {
2813 Error error;
Greg Clayton567e7f32011-09-22 04:58:26 +00002814 if (process->ReadMemory (source_addr, (uint8_t*)target_addr, byte_size, error) != byte_size)
Chris Lattner24943d22010-06-08 16:52:24 +00002815 {
2816 if (error_ptr)
2817 error_ptr->SetErrorStringWithFormat ("Couldn't read a composite type from the target: %s", error.AsCString());
2818 return false;
2819 }
2820 }
2821 break;
2822 default:
2823 return false;
2824 }
2825 break;
2826 case Value::eValueTypeHostAddress:
2827 switch (target_value_type)
2828 {
2829 case Value::eValueTypeLoadAddress:
Greg Clayton567e7f32011-09-22 04:58:26 +00002830 if (process->GetByteOrder() != lldb::endian::InlHostByteOrder())
Chris Lattner24943d22010-06-08 16:52:24 +00002831 {
2832 if (error_ptr)
2833 error_ptr->SetErrorStringWithFormat ("Copy of composite types between incompatible byte orders is unimplemented");
2834 return false;
2835 }
2836 else
2837 {
2838 Error error;
Greg Clayton567e7f32011-09-22 04:58:26 +00002839 if (process->WriteMemory (target_addr, (uint8_t*)source_addr, byte_size, error) != byte_size)
Chris Lattner24943d22010-06-08 16:52:24 +00002840 {
2841 if (error_ptr)
2842 error_ptr->SetErrorStringWithFormat ("Couldn't write a composite type to the target: %s", error.AsCString());
2843 return false;
2844 }
2845 }
2846 case Value::eValueTypeHostAddress:
2847 memcpy ((uint8_t*)target_addr, (uint8_t*)source_addr, byte_size);
2848 break;
2849 default:
2850 return false;
2851 }
2852 }
2853 }
2854 else
2855 {
Greg Clayton1674b122010-07-21 22:12:05 +00002856 if (!ClangASTType::SetValueFromScalar (ast_context,
2857 clang_type,
2858 tmp.ResolveValue(exe_ctx, ast_context),
2859 new_value))
Chris Lattner24943d22010-06-08 16:52:24 +00002860 {
2861 if (error_ptr)
2862 error_ptr->SetErrorStringWithFormat ("Couldn't extract a value from an integral type.\n");
2863 return false;
2864 }
2865
2866 Value::ValueType value_type = stack.back().GetValueType();
2867
2868 switch (value_type)
2869 {
2870 case Value::eValueTypeLoadAddress:
2871 case Value::eValueTypeHostAddress:
2872 {
Greg Claytonb3448432011-03-24 21:19:54 +00002873 AddressType address_type = (value_type == Value::eValueTypeLoadAddress ? eAddressTypeLoad : eAddressTypeHost);
Chris Lattner24943d22010-06-08 16:52:24 +00002874 lldb::addr_t addr = stack.back().GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton1674b122010-07-21 22:12:05 +00002875 if (!ClangASTType::WriteToMemory (ast_context,
2876 clang_type,
2877 exe_ctx,
2878 addr,
2879 address_type,
2880 new_value))
Chris Lattner24943d22010-06-08 16:52:24 +00002881 {
2882 if (error_ptr)
2883 error_ptr->SetErrorStringWithFormat ("Failed to write value to memory at 0x%llx.\n", addr);
2884 return false;
2885 }
2886 }
2887 break;
2888
2889 default:
2890 break;
2891 }
2892 }
2893 }
2894 break;
2895
2896 default:
2897 if (error_ptr)
2898 error_ptr->SetErrorString ("Assign failed.");
2899 return false;
2900 }
2901 }
2902 break;
2903
2904 //----------------------------------------------------------------------
2905 // OPCODE: DW_OP_APPLE_address_of
2906 // OPERANDS: none
2907 // DESCRIPTION: Pops a value off of the stack and pushed its address.
2908 // The top item on the stack must be a variable, or already be a memory
2909 // location.
2910 //----------------------------------------------------------------------
2911 case DW_OP_APPLE_address_of:
2912 if (stack.empty())
2913 {
2914 if (error_ptr)
2915 error_ptr->SetErrorString("Expression stack needs at least 1 item for DW_OP_APPLE_address_of.");
2916 return false;
2917 }
2918 else
2919 {
2920 Value::ValueType value_type = stack.back().GetValueType();
2921 switch (value_type)
2922 {
2923 default:
2924 case Value::eValueTypeScalar: // raw scalar value
2925 if (error_ptr)
2926 error_ptr->SetErrorString("Top stack item isn't a memory based object.");
2927 return false;
2928
2929 case Value::eValueTypeLoadAddress: // load address value
2930 case Value::eValueTypeFileAddress: // file address value
2931 case Value::eValueTypeHostAddress: // host address value (for memory in the process that is using liblldb)
2932 // Taking the address of an object reduces it to the address
2933 // of the value and removes any extra context it had.
2934 //stack.back().SetValueType(Value::eValueTypeScalar);
2935 stack.back().ClearContext();
2936 break;
2937 }
2938 }
2939 break;
2940
2941 //----------------------------------------------------------------------
2942 // OPCODE: DW_OP_APPLE_value_of
2943 // OPERANDS: none
2944 // DESCRIPTION: Pops a value off of the stack and pushed its value.
2945 // The top item on the stack must be a variable, expression variable.
2946 //----------------------------------------------------------------------
2947 case DW_OP_APPLE_value_of:
2948 if (stack.empty())
2949 {
2950 if (error_ptr)
2951 error_ptr->SetErrorString("Expression stack needs at least 1 items for DW_OP_APPLE_value_of.");
2952 return false;
2953 }
2954 else if (!stack.back().ValueOf(exe_ctx, ast_context))
2955 {
2956 if (error_ptr)
2957 error_ptr->SetErrorString ("Top stack item isn't a valid candidate for DW_OP_APPLE_value_of.");
2958 return false;
2959 }
2960 break;
2961
2962 //----------------------------------------------------------------------
2963 // OPCODE: DW_OP_APPLE_deref_type
2964 // OPERANDS: none
2965 // DESCRIPTION: gets the value pointed to by the top stack item
2966 //----------------------------------------------------------------------
2967 case DW_OP_APPLE_deref_type:
2968 {
2969 if (stack.empty())
2970 {
2971 if (error_ptr)
2972 error_ptr->SetErrorString("Expression stack needs at least 1 items for DW_OP_APPLE_deref_type.");
2973 return false;
2974 }
2975
2976 tmp = stack.back();
2977 stack.pop_back();
2978
Greg Clayton6916e352010-11-13 03:52:47 +00002979 if (tmp.GetContextType() != Value::eContextTypeClangType)
Chris Lattner24943d22010-06-08 16:52:24 +00002980 {
2981 if (error_ptr)
2982 error_ptr->SetErrorString("Item at top of expression stack must have a Clang type");
2983 return false;
2984 }
2985
Greg Clayton462d4142010-09-29 01:12:09 +00002986 void *ptr_type = tmp.GetClangType();
Chris Lattner24943d22010-06-08 16:52:24 +00002987 void *target_type;
2988
2989 if (!ClangASTContext::IsPointerType(ptr_type, &target_type))
2990 {
2991 if (error_ptr)
2992 error_ptr->SetErrorString("Dereferencing a non-pointer type");
2993 return false;
2994 }
2995
2996 // TODO do we want all pointers to be dereferenced as load addresses?
2997 Value::ValueType value_type = tmp.GetValueType();
2998
2999 tmp.ResolveValue(exe_ctx, ast_context);
3000
3001 tmp.SetValueType(value_type);
Greg Clayton6916e352010-11-13 03:52:47 +00003002 tmp.SetContext(Value::eContextTypeClangType, target_type);
Chris Lattner24943d22010-06-08 16:52:24 +00003003
3004 stack.push_back(tmp);
3005 }
3006 break;
3007
3008 //----------------------------------------------------------------------
3009 // OPCODE: DW_OP_APPLE_expr_local
3010 // OPERANDS: ULEB128
3011 // DESCRIPTION: pushes the expression local variable index onto the
3012 // stack and set the appropriate context so we know the stack item is
3013 // an expression local variable index.
3014 //----------------------------------------------------------------------
3015 case DW_OP_APPLE_expr_local:
3016 {
Sean Callanana6223432010-08-20 01:02:30 +00003017 /*
Chris Lattner24943d22010-06-08 16:52:24 +00003018 uint32_t idx = opcodes.GetULEB128(&offset);
3019 if (expr_locals == NULL)
3020 {
3021 if (error_ptr)
3022 error_ptr->SetErrorStringWithFormat ("DW_OP_APPLE_expr_local(%u) opcode encountered with no local variable list.\n", idx);
3023 return false;
3024 }
3025 Value *expr_local_variable = expr_locals->GetVariableAtIndex(idx);
3026 if (expr_local_variable == NULL)
3027 {
3028 if (error_ptr)
3029 error_ptr->SetErrorStringWithFormat ("DW_OP_APPLE_expr_local(%u) with invalid index %u.\n", idx, idx);
3030 return false;
3031 }
Greg Clayton801417e2011-07-07 01:59:51 +00003032 // The proxy code has been removed. If it is ever re-added, please
3033 // use shared pointers or return by value to avoid possible memory
3034 // leak (there is no leak here, but in general, no returning pointers
3035 // that must be manually freed please.
Chris Lattner24943d22010-06-08 16:52:24 +00003036 Value *proxy = expr_local_variable->CreateProxy();
3037 stack.push_back(*proxy);
3038 delete proxy;
Greg Clayton6916e352010-11-13 03:52:47 +00003039 //stack.back().SetContext (Value::eContextTypeClangType, expr_local_variable->GetClangType());
Sean Callanana6223432010-08-20 01:02:30 +00003040 */
Chris Lattner24943d22010-06-08 16:52:24 +00003041 }
3042 break;
3043
3044 //----------------------------------------------------------------------
3045 // OPCODE: DW_OP_APPLE_extern
3046 // OPERANDS: ULEB128
3047 // DESCRIPTION: pushes a proxy for the extern object index onto the
3048 // stack.
3049 //----------------------------------------------------------------------
3050 case DW_OP_APPLE_extern:
3051 {
Sean Callanan8c127202010-08-23 23:09:38 +00003052 /*
Chris Lattner24943d22010-06-08 16:52:24 +00003053 uint32_t idx = opcodes.GetULEB128(&offset);
3054 if (!decl_map)
3055 {
3056 if (error_ptr)
3057 error_ptr->SetErrorStringWithFormat ("DW_OP_APPLE_extern(%u) opcode encountered with no decl map.\n", idx);
3058 return false;
3059 }
3060 Value *extern_var = decl_map->GetValueForIndex(idx);
3061 if (!extern_var)
3062 {
3063 if (error_ptr)
3064 error_ptr->SetErrorStringWithFormat ("DW_OP_APPLE_extern(%u) with invalid index %u.\n", idx, idx);
3065 return false;
3066 }
Greg Clayton801417e2011-07-07 01:59:51 +00003067 // The proxy code has been removed. If it is ever re-added, please
3068 // use shared pointers or return by value to avoid possible memory
3069 // leak (there is no leak here, but in general, no returning pointers
3070 // that must be manually freed please.
Chris Lattner24943d22010-06-08 16:52:24 +00003071 Value *proxy = extern_var->CreateProxy();
3072 stack.push_back(*proxy);
3073 delete proxy;
Sean Callanan8c127202010-08-23 23:09:38 +00003074 */
Chris Lattner24943d22010-06-08 16:52:24 +00003075 }
3076 break;
3077
3078 case DW_OP_APPLE_scalar_cast:
3079 if (stack.empty())
3080 {
3081 if (error_ptr)
3082 error_ptr->SetErrorString("Expression stack needs at least 1 item for DW_OP_APPLE_scalar_cast.");
3083 return false;
3084 }
3085 else
3086 {
3087 // Simple scalar cast
3088 if (!stack.back().ResolveValue(exe_ctx, ast_context).Cast((Scalar::Type)opcodes.GetU8(&offset)))
3089 {
3090 if (error_ptr)
3091 error_ptr->SetErrorString("Cast failed.");
3092 return false;
3093 }
3094 }
3095 break;
3096
3097
3098 case DW_OP_APPLE_clang_cast:
3099 if (stack.empty())
3100 {
3101 if (error_ptr)
3102 error_ptr->SetErrorString("Expression stack needs at least 1 item for DW_OP_APPLE_clang_cast.");
3103 return false;
3104 }
3105 else
3106 {
3107 void *clang_type = (void *)opcodes.GetMaxU64(&offset, sizeof(void*));
Greg Clayton6916e352010-11-13 03:52:47 +00003108 stack.back().SetContext (Value::eContextTypeClangType, clang_type);
Chris Lattner24943d22010-06-08 16:52:24 +00003109 }
3110 break;
3111 //----------------------------------------------------------------------
3112 // OPCODE: DW_OP_APPLE_constf
3113 // OPERANDS: 1 byte float length, followed by that many bytes containing
3114 // the constant float data.
3115 // DESCRIPTION: Push a float value onto the expression stack.
3116 //----------------------------------------------------------------------
3117 case DW_OP_APPLE_constf: // 0xF6 - 1 byte float size, followed by constant float data
3118 {
3119 uint8_t float_length = opcodes.GetU8(&offset);
3120 if (sizeof(float) == float_length)
3121 tmp.ResolveValue(exe_ctx, ast_context) = opcodes.GetFloat (&offset);
3122 else if (sizeof(double) == float_length)
3123 tmp.ResolveValue(exe_ctx, ast_context) = opcodes.GetDouble (&offset);
3124 else if (sizeof(long double) == float_length)
3125 tmp.ResolveValue(exe_ctx, ast_context) = opcodes.GetLongDouble (&offset);
3126 else
3127 {
3128 StreamString new_value;
3129 opcodes.Dump(&new_value, offset, eFormatBytes, 1, float_length, UINT32_MAX, DW_INVALID_ADDRESS, 0, 0);
3130
3131 if (error_ptr)
3132 error_ptr->SetErrorStringWithFormat ("DW_OP_APPLE_constf(<%u> %s) unsupported float size.\n", float_length, new_value.GetData());
3133 return false;
3134 }
3135 tmp.SetValueType(Value::eValueTypeScalar);
3136 tmp.ClearContext();
3137 stack.push_back(tmp);
3138 }
3139 break;
3140 //----------------------------------------------------------------------
3141 // OPCODE: DW_OP_APPLE_clear
3142 // OPERANDS: none
3143 // DESCRIPTION: Clears the expression stack.
3144 //----------------------------------------------------------------------
3145 case DW_OP_APPLE_clear:
3146 stack.clear();
3147 break;
3148
3149 //----------------------------------------------------------------------
3150 // OPCODE: DW_OP_APPLE_error
3151 // OPERANDS: none
3152 // DESCRIPTION: Pops a value off of the stack and pushed its value.
3153 // The top item on the stack must be a variable, expression variable.
3154 //----------------------------------------------------------------------
3155 case DW_OP_APPLE_error: // 0xFF - Stops expression evaluation and returns an error (no args)
3156 if (error_ptr)
3157 error_ptr->SetErrorString ("Generic error.");
3158 return false;
Greg Claytona1b9a902011-11-13 04:15:56 +00003159#endif // #if 0
3160
Chris Lattner24943d22010-06-08 16:52:24 +00003161 }
3162 }
3163
3164 if (stack.empty())
3165 {
3166 if (error_ptr)
3167 error_ptr->SetErrorString ("Stack empty after evaluation.");
3168 return false;
3169 }
Sean Callanan67bbb112011-10-14 20:34:21 +00003170 else if (log && log->GetVerbose())
Chris Lattner24943d22010-06-08 16:52:24 +00003171 {
Chris Lattner24943d22010-06-08 16:52:24 +00003172 size_t count = stack.size();
Jason Molenda7e5fa7f2011-09-20 21:44:10 +00003173 log->Printf("Stack after operation has %lu values:", count);
Chris Lattner24943d22010-06-08 16:52:24 +00003174 for (size_t i=0; i<count; ++i)
3175 {
3176 StreamString new_value;
3177 new_value.Printf("[%zu]", i);
3178 stack[i].Dump(&new_value);
Sean Callanan6184dfe2010-06-23 00:47:48 +00003179 log->Printf(" %s", new_value.GetData());
Chris Lattner24943d22010-06-08 16:52:24 +00003180 }
3181 }
3182
3183 result = stack.back();
3184 return true; // Return true on success
3185}
3186