blob: 288bde9839160f6cceea997d659e9ec090413d78 [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
908 return 0;
909
910 // Opcodes with a single 1 byte arguments
911 case DW_OP_const1u: // 0x08 1 1-byte constant
912 case DW_OP_const1s: // 0x09 1 1-byte constant
913 case DW_OP_pick: // 0x15 1 1-byte stack index
914 case DW_OP_deref_size: // 0x94 1 1-byte size of data retrieved
915 case DW_OP_xderef_size: // 0x95 1 1-byte size of data retrieved
916 return 1;
917
918 // Opcodes with a single 2 byte arguments
919 case DW_OP_const2u: // 0x0a 1 2-byte constant
920 case DW_OP_const2s: // 0x0b 1 2-byte constant
921 case DW_OP_skip: // 0x2f 1 signed 2-byte constant
922 case DW_OP_bra: // 0x28 1 signed 2-byte constant
923 case DW_OP_call2: // 0x98 1 2-byte offset of DIE (DWARF3)
924 return 2;
925
926 // Opcodes with a single 4 byte arguments
927 case DW_OP_const4u: // 0x0c 1 4-byte constant
928 case DW_OP_const4s: // 0x0d 1 4-byte constant
929 case DW_OP_call4: // 0x99 1 4-byte offset of DIE (DWARF3)
930 return 4;
931
932 // Opcodes with a single 8 byte arguments
933 case DW_OP_const8u: // 0x0e 1 8-byte constant
934 case DW_OP_const8s: // 0x0f 1 8-byte constant
935 return 8;
936
937 // All opcodes that have a single ULEB (signed or unsigned) argument
938 case DW_OP_constu: // 0x10 1 ULEB128 constant
939 case DW_OP_consts: // 0x11 1 SLEB128 constant
940 case DW_OP_plus_uconst: // 0x23 1 ULEB128 addend
941 case DW_OP_breg0: // 0x70 1 ULEB128 register
942 case DW_OP_breg1: // 0x71 1 ULEB128 register
943 case DW_OP_breg2: // 0x72 1 ULEB128 register
944 case DW_OP_breg3: // 0x73 1 ULEB128 register
945 case DW_OP_breg4: // 0x74 1 ULEB128 register
946 case DW_OP_breg5: // 0x75 1 ULEB128 register
947 case DW_OP_breg6: // 0x76 1 ULEB128 register
948 case DW_OP_breg7: // 0x77 1 ULEB128 register
949 case DW_OP_breg8: // 0x78 1 ULEB128 register
950 case DW_OP_breg9: // 0x79 1 ULEB128 register
951 case DW_OP_breg10: // 0x7a 1 ULEB128 register
952 case DW_OP_breg11: // 0x7b 1 ULEB128 register
953 case DW_OP_breg12: // 0x7c 1 ULEB128 register
954 case DW_OP_breg13: // 0x7d 1 ULEB128 register
955 case DW_OP_breg14: // 0x7e 1 ULEB128 register
956 case DW_OP_breg15: // 0x7f 1 ULEB128 register
957 case DW_OP_breg16: // 0x80 1 ULEB128 register
958 case DW_OP_breg17: // 0x81 1 ULEB128 register
959 case DW_OP_breg18: // 0x82 1 ULEB128 register
960 case DW_OP_breg19: // 0x83 1 ULEB128 register
961 case DW_OP_breg20: // 0x84 1 ULEB128 register
962 case DW_OP_breg21: // 0x85 1 ULEB128 register
963 case DW_OP_breg22: // 0x86 1 ULEB128 register
964 case DW_OP_breg23: // 0x87 1 ULEB128 register
965 case DW_OP_breg24: // 0x88 1 ULEB128 register
966 case DW_OP_breg25: // 0x89 1 ULEB128 register
967 case DW_OP_breg26: // 0x8a 1 ULEB128 register
968 case DW_OP_breg27: // 0x8b 1 ULEB128 register
969 case DW_OP_breg28: // 0x8c 1 ULEB128 register
970 case DW_OP_breg29: // 0x8d 1 ULEB128 register
971 case DW_OP_breg30: // 0x8e 1 ULEB128 register
972 case DW_OP_breg31: // 0x8f 1 ULEB128 register
973 case DW_OP_regx: // 0x90 1 ULEB128 register
974 case DW_OP_fbreg: // 0x91 1 SLEB128 offset
975 case DW_OP_piece: // 0x93 1 ULEB128 size of piece addressed
976 data.Skip_LEB128(&offset);
977 return offset - data_offset;
978
979 // All opcodes that have a 2 ULEB (signed or unsigned) arguments
980 case DW_OP_bregx: // 0x92 2 ULEB128 register followed by SLEB128 offset
981 case DW_OP_bit_piece: // 0x9d ULEB128 bit size, ULEB128 bit offset (DWARF3);
982 data.Skip_LEB128(&offset);
983 data.Skip_LEB128(&offset);
984 return offset - data_offset;
985 default:
Jim Ingham8521b842011-12-01 03:01:30 +0000986 {
987 Host::SetCrashDescriptionWithFormat ("Unhandled DW_OP_XXX opcode: %d, add support for it.", op);
988 assert (!"Unhandled DW_OP_XXX opcode: %d, add support for it.");
989 }
990 break;
Greg Claytona1b9a902011-11-13 04:15:56 +0000991 }
992 return UINT32_MAX;
993}
994
995bool
996DWARFExpression::LocationContains_DW_OP_addr (lldb::addr_t file_addr) const
997{
998 if (IsLocationList())
999 return false;
1000 uint32_t offset = 0;
1001 while (m_data.ValidOffset(offset))
1002 {
1003 const uint8_t op = m_data.GetU8(&offset);
1004
1005 if (op == DW_OP_addr)
1006 {
1007 if (file_addr == LLDB_INVALID_ADDRESS)
1008 return true;
1009 addr_t op_file_addr = m_data.GetAddress(&offset);
1010 if (op_file_addr == file_addr)
1011 return true;
1012 }
1013 else
1014 {
1015 const uint32_t op_arg_size = GetOpcodeDataSize (m_data, offset, op);
1016 if (op_arg_size == UINT32_MAX)
1017 break;
1018 offset += op_arg_size;
1019 }
1020 }
1021 return false;
1022}
1023
1024bool
1025DWARFExpression::Update_DW_OP_addr (lldb::addr_t file_addr)
1026{
1027 if (IsLocationList())
1028 return false;
1029 uint32_t offset = 0;
1030 while (m_data.ValidOffset(offset))
1031 {
1032 const uint8_t op = m_data.GetU8(&offset);
1033
1034 if (op == DW_OP_addr)
1035 {
1036 const uint8_t addr_byte_size = m_data.GetAddressByteSize();
1037 // We have to make a copy of the data as we don't know if this
1038 // data is from a read only memory mapped buffer, so we duplicate
1039 // all of the data first, then modify it, and if all goes well,
1040 // we then replace the data for this expression
1041
1042 // So first we copy the data into a heap buffer
1043 std::auto_ptr<DataBufferHeap> head_data_ap (new DataBufferHeap (m_data.GetDataStart(),
1044 m_data.GetByteSize()));
1045
1046 // Make en encoder so we can write the address into the buffer using
1047 // the correct byte order (endianness)
1048 DataEncoder encoder (head_data_ap->GetBytes(),
1049 head_data_ap->GetByteSize(),
1050 m_data.GetByteOrder(),
1051 addr_byte_size);
1052
1053 // Replace the address in the new buffer
1054 if (encoder.PutMaxU64 (offset, addr_byte_size, file_addr) == UINT32_MAX)
1055 return false;
1056
1057 // All went well, so now we can reset the data using a shared
1058 // pointer to the heap data so "m_data" will now correctly
1059 // manage the heap data.
1060 m_data.SetData (DataBufferSP (head_data_ap.release()));
1061 return true;
1062 }
1063 else
1064 {
1065 const uint32_t op_arg_size = GetOpcodeDataSize (m_data, offset, op);
1066 if (op_arg_size == UINT32_MAX)
1067 break;
1068 offset += op_arg_size;
1069 }
1070 }
1071 return false;
1072}
1073
Greg Claytonb04e7a82010-08-24 21:05:24 +00001074bool
Greg Clayton178710c2010-09-14 02:20:48 +00001075DWARFExpression::LocationListContainsAddress (lldb::addr_t loclist_base_addr, lldb::addr_t addr) const
Greg Claytonb04e7a82010-08-24 21:05:24 +00001076{
Greg Clayton178710c2010-09-14 02:20:48 +00001077 if (addr == LLDB_INVALID_ADDRESS)
Greg Claytonb04e7a82010-08-24 21:05:24 +00001078 return false;
1079
Chris Lattner24943d22010-06-08 16:52:24 +00001080 if (IsLocationList())
1081 {
1082 uint32_t offset = 0;
Chris Lattner24943d22010-06-08 16:52:24 +00001083
Greg Clayton178710c2010-09-14 02:20:48 +00001084 if (loclist_base_addr == LLDB_INVALID_ADDRESS)
Chris Lattner24943d22010-06-08 16:52:24 +00001085 return false;
1086
1087 while (m_data.ValidOffset(offset))
1088 {
1089 // We need to figure out what the value is for the location.
1090 addr_t lo_pc = m_data.GetAddress(&offset);
1091 addr_t hi_pc = m_data.GetAddress(&offset);
1092 if (lo_pc == 0 && hi_pc == 0)
1093 break;
1094 else
1095 {
Greg Clayton178710c2010-09-14 02:20:48 +00001096 lo_pc += loclist_base_addr - m_loclist_slide;
1097 hi_pc += loclist_base_addr - m_loclist_slide;
Chris Lattner24943d22010-06-08 16:52:24 +00001098
Greg Clayton178710c2010-09-14 02:20:48 +00001099 if (lo_pc <= addr && addr < hi_pc)
Chris Lattner24943d22010-06-08 16:52:24 +00001100 return true;
1101
1102 offset += m_data.GetU16(&offset);
1103 }
1104 }
1105 }
1106 return false;
1107}
Greg Claytonb04e7a82010-08-24 21:05:24 +00001108
Chris Lattner24943d22010-06-08 16:52:24 +00001109bool
Greg Clayton9b82f862011-07-11 05:12:02 +00001110DWARFExpression::GetLocation (addr_t base_addr, addr_t pc, uint32_t &offset, uint32_t &length)
1111{
1112 offset = 0;
1113 if (!IsLocationList())
1114 {
1115 length = m_data.GetByteSize();
1116 return true;
1117 }
1118
1119 if (base_addr != LLDB_INVALID_ADDRESS && pc != LLDB_INVALID_ADDRESS)
1120 {
1121 addr_t curr_base_addr = base_addr;
1122
1123 while (m_data.ValidOffset(offset))
1124 {
1125 // We need to figure out what the value is for the location.
1126 addr_t lo_pc = m_data.GetAddress(&offset);
1127 addr_t hi_pc = m_data.GetAddress(&offset);
1128 if (lo_pc == 0 && hi_pc == 0)
1129 {
1130 break;
1131 }
1132 else
1133 {
1134 lo_pc += curr_base_addr - m_loclist_slide;
1135 hi_pc += curr_base_addr - m_loclist_slide;
1136
1137 length = m_data.GetU16(&offset);
1138
1139 if (length > 0 && lo_pc <= pc && pc < hi_pc)
1140 return true;
1141
1142 offset += length;
1143 }
1144 }
1145 }
1146 offset = UINT32_MAX;
1147 length = 0;
1148 return false;
1149}
1150
1151bool
1152DWARFExpression::DumpLocationForAddress (Stream *s,
1153 lldb::DescriptionLevel level,
1154 addr_t base_addr,
Greg Clayton5c3861d2011-09-02 01:15:17 +00001155 addr_t address,
1156 ABI *abi)
Greg Clayton9b82f862011-07-11 05:12:02 +00001157{
1158 uint32_t offset = 0;
1159 uint32_t length = 0;
1160
1161 if (GetLocation (base_addr, address, offset, length))
1162 {
1163 if (length > 0)
1164 {
Greg Clayton5c3861d2011-09-02 01:15:17 +00001165 DumpLocation(s, offset, length, level, abi);
Greg Clayton9b82f862011-07-11 05:12:02 +00001166 return true;
1167 }
1168 }
1169 return false;
1170}
1171
1172bool
Chris Lattner24943d22010-06-08 16:52:24 +00001173DWARFExpression::Evaluate
1174(
1175 ExecutionContextScope *exe_scope,
1176 clang::ASTContext *ast_context,
Greg Claytonbdcb6ab2011-01-25 23:55:37 +00001177 ClangExpressionVariableList *expr_locals,
1178 ClangExpressionDeclMap *decl_map,
Greg Clayton178710c2010-09-14 02:20:48 +00001179 lldb::addr_t loclist_base_load_addr,
Chris Lattner24943d22010-06-08 16:52:24 +00001180 const Value* initial_value_ptr,
1181 Value& result,
1182 Error *error_ptr
1183) const
1184{
1185 ExecutionContext exe_ctx (exe_scope);
Greg Claytonbdcb6ab2011-01-25 23:55:37 +00001186 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 +00001187}
1188
1189bool
1190DWARFExpression::Evaluate
1191(
1192 ExecutionContext *exe_ctx,
1193 clang::ASTContext *ast_context,
Greg Claytonbdcb6ab2011-01-25 23:55:37 +00001194 ClangExpressionVariableList *expr_locals,
1195 ClangExpressionDeclMap *decl_map,
Jason Molenda8e69de42010-11-20 01:28:30 +00001196 RegisterContext *reg_ctx,
Greg Clayton178710c2010-09-14 02:20:48 +00001197 lldb::addr_t loclist_base_load_addr,
Chris Lattner24943d22010-06-08 16:52:24 +00001198 const Value* initial_value_ptr,
1199 Value& result,
1200 Error *error_ptr
1201) const
1202{
1203 if (IsLocationList())
1204 {
1205 uint32_t offset = 0;
Jason Molenda8e69de42010-11-20 01:28:30 +00001206 addr_t pc;
Greg Clayton567e7f32011-09-22 04:58:26 +00001207 StackFrame *frame = NULL;
Jason Molenda8e69de42010-11-20 01:28:30 +00001208 if (reg_ctx)
1209 pc = reg_ctx->GetPC();
1210 else
Greg Clayton567e7f32011-09-22 04:58:26 +00001211 {
1212 frame = exe_ctx->GetFramePtr();
1213 pc = frame->GetRegisterContext()->GetPC();
1214 }
Chris Lattner24943d22010-06-08 16:52:24 +00001215
Greg Clayton178710c2010-09-14 02:20:48 +00001216 if (loclist_base_load_addr != LLDB_INVALID_ADDRESS)
Chris Lattner24943d22010-06-08 16:52:24 +00001217 {
Greg Clayton178710c2010-09-14 02:20:48 +00001218 if (pc == LLDB_INVALID_ADDRESS)
Chris Lattner24943d22010-06-08 16:52:24 +00001219 {
Greg Clayton178710c2010-09-14 02:20:48 +00001220 if (error_ptr)
1221 error_ptr->SetErrorString("Invalid PC in frame.");
1222 return false;
Chris Lattner24943d22010-06-08 16:52:24 +00001223 }
Greg Clayton178710c2010-09-14 02:20:48 +00001224
1225 addr_t curr_loclist_base_load_addr = loclist_base_load_addr;
1226
1227 while (m_data.ValidOffset(offset))
Chris Lattner24943d22010-06-08 16:52:24 +00001228 {
Greg Clayton178710c2010-09-14 02:20:48 +00001229 // We need to figure out what the value is for the location.
1230 addr_t lo_pc = m_data.GetAddress(&offset);
1231 addr_t hi_pc = m_data.GetAddress(&offset);
1232 if (lo_pc == 0 && hi_pc == 0)
Chris Lattner24943d22010-06-08 16:52:24 +00001233 {
Greg Clayton178710c2010-09-14 02:20:48 +00001234 break;
Chris Lattner24943d22010-06-08 16:52:24 +00001235 }
Greg Clayton178710c2010-09-14 02:20:48 +00001236 else
1237 {
1238 lo_pc += curr_loclist_base_load_addr - m_loclist_slide;
1239 hi_pc += curr_loclist_base_load_addr - m_loclist_slide;
1240
1241 uint16_t length = m_data.GetU16(&offset);
1242
1243 if (length > 0 && lo_pc <= pc && pc < hi_pc)
1244 {
Greg Claytonbdcb6ab2011-01-25 23:55:37 +00001245 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 +00001246 }
1247 offset += length;
1248 }
Chris Lattner24943d22010-06-08 16:52:24 +00001249 }
1250 }
1251 if (error_ptr)
Greg Clayton82f07462011-05-30 00:49:24 +00001252 error_ptr->SetErrorString ("variable not available");
Chris Lattner24943d22010-06-08 16:52:24 +00001253 return false;
1254 }
1255
1256 // Not a location list, just a single expression.
Greg Claytonbdcb6ab2011-01-25 23:55:37 +00001257 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 +00001258}
1259
1260
1261
1262bool
1263DWARFExpression::Evaluate
1264(
1265 ExecutionContext *exe_ctx,
1266 clang::ASTContext *ast_context,
Chris Lattner24943d22010-06-08 16:52:24 +00001267 ClangExpressionVariableList *expr_locals,
1268 ClangExpressionDeclMap *decl_map,
Jason Molenda8e69de42010-11-20 01:28:30 +00001269 RegisterContext *reg_ctx,
Greg Claytonbdcb6ab2011-01-25 23:55:37 +00001270 const DataExtractor& opcodes,
Chris Lattner24943d22010-06-08 16:52:24 +00001271 const uint32_t opcodes_offset,
1272 const uint32_t opcodes_length,
1273 const uint32_t reg_kind,
1274 const Value* initial_value_ptr,
1275 Value& result,
1276 Error *error_ptr
1277)
1278{
1279 std::vector<Value> stack;
1280
Greg Clayton567e7f32011-09-22 04:58:26 +00001281 Process *process = NULL;
1282 StackFrame *frame = NULL;
1283
1284 if (exe_ctx)
1285 {
1286 process = exe_ctx->GetProcessPtr();
1287 frame = exe_ctx->GetFramePtr();
1288 }
1289 if (reg_ctx == NULL && frame)
1290 reg_ctx = frame->GetRegisterContext().get();
Jason Molenda8e69de42010-11-20 01:28:30 +00001291
Chris Lattner24943d22010-06-08 16:52:24 +00001292 if (initial_value_ptr)
1293 stack.push_back(*initial_value_ptr);
1294
1295 uint32_t offset = opcodes_offset;
1296 const uint32_t end_offset = opcodes_offset + opcodes_length;
1297 Value tmp;
1298 uint32_t reg_num;
1299
1300 // Make sure all of the data is available in opcodes.
1301 if (!opcodes.ValidOffsetForDataOfSize(opcodes_offset, opcodes_length))
1302 {
1303 if (error_ptr)
1304 error_ptr->SetErrorString ("Invalid offset and/or length for opcodes buffer.");
1305 return false;
1306 }
Greg Claytone005f2c2010-11-06 01:53:30 +00001307 LogSP log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
Chris Lattner24943d22010-06-08 16:52:24 +00001308
1309
1310 while (opcodes.ValidOffset(offset) && offset < end_offset)
1311 {
1312 const uint32_t op_offset = offset;
1313 const uint8_t op = opcodes.GetU8(&offset);
1314
Sean Callanan67bbb112011-10-14 20:34:21 +00001315 if (log && log->GetVerbose())
Chris Lattner24943d22010-06-08 16:52:24 +00001316 {
Chris Lattner24943d22010-06-08 16:52:24 +00001317 size_t count = stack.size();
Jason Molenda7e5fa7f2011-09-20 21:44:10 +00001318 log->Printf("Stack before operation has %lu values:", count);
Chris Lattner24943d22010-06-08 16:52:24 +00001319 for (size_t i=0; i<count; ++i)
1320 {
1321 StreamString new_value;
1322 new_value.Printf("[%zu]", i);
1323 stack[i].Dump(&new_value);
Sean Callanan6184dfe2010-06-23 00:47:48 +00001324 log->Printf(" %s", new_value.GetData());
Chris Lattner24943d22010-06-08 16:52:24 +00001325 }
1326 log->Printf("0x%8.8x: %s", op_offset, DW_OP_value_to_name(op));
1327 }
1328 switch (op)
1329 {
1330 //----------------------------------------------------------------------
1331 // The DW_OP_addr operation has a single operand that encodes a machine
1332 // address and whose size is the size of an address on the target machine.
1333 //----------------------------------------------------------------------
1334 case DW_OP_addr:
Greg Clayton801417e2011-07-07 01:59:51 +00001335 stack.push_back(Scalar(opcodes.GetAddress(&offset)));
Chris Lattner24943d22010-06-08 16:52:24 +00001336 stack.back().SetValueType (Value::eValueTypeFileAddress);
1337 break;
1338
1339 //----------------------------------------------------------------------
1340 // The DW_OP_addr_sect_offset4 is used for any location expressions in
1341 // shared libraries that have a location like:
1342 // DW_OP_addr(0x1000)
1343 // If this address resides in a shared library, then this virtual
1344 // address won't make sense when it is evaluated in the context of a
1345 // running process where shared libraries have been slid. To account for
1346 // this, this new address type where we can store the section pointer
1347 // and a 4 byte offset.
1348 //----------------------------------------------------------------------
1349// case DW_OP_addr_sect_offset4:
1350// {
1351// result_type = eResultTypeFileAddress;
1352// lldb::Section *sect = (lldb::Section *)opcodes.GetMaxU64(&offset, sizeof(void *));
1353// lldb::addr_t sect_offset = opcodes.GetU32(&offset);
1354//
1355// Address so_addr (sect, sect_offset);
1356// lldb::addr_t load_addr = so_addr.GetLoadAddress();
1357// if (load_addr != LLDB_INVALID_ADDRESS)
1358// {
1359// // We successfully resolve a file address to a load
1360// // address.
1361// stack.push_back(load_addr);
1362// break;
1363// }
1364// else
1365// {
1366// // We were able
1367// if (error_ptr)
1368// error_ptr->SetErrorStringWithFormat ("Section %s in %s is not currently loaded.\n", sect->GetName().AsCString(), sect->GetModule()->GetFileSpec().GetFilename().AsCString());
1369// return false;
1370// }
1371// }
1372// break;
1373
1374 //----------------------------------------------------------------------
1375 // OPCODE: DW_OP_deref
1376 // OPERANDS: none
1377 // DESCRIPTION: Pops the top stack entry and treats it as an address.
1378 // The value retrieved from that address is pushed. The size of the
1379 // data retrieved from the dereferenced address is the size of an
1380 // address on the target machine.
1381 //----------------------------------------------------------------------
1382 case DW_OP_deref:
1383 {
1384 Value::ValueType value_type = stack.back().GetValueType();
1385 switch (value_type)
1386 {
1387 case Value::eValueTypeHostAddress:
1388 {
1389 void *src = (void *)stack.back().GetScalar().ULongLong();
1390 intptr_t ptr;
1391 ::memcpy (&ptr, src, sizeof(void *));
1392 stack.back().GetScalar() = ptr;
1393 stack.back().ClearContext();
1394 }
1395 break;
1396 case Value::eValueTypeLoadAddress:
1397 if (exe_ctx)
1398 {
Greg Clayton567e7f32011-09-22 04:58:26 +00001399 if (process)
Chris Lattner24943d22010-06-08 16:52:24 +00001400 {
1401 lldb::addr_t pointer_addr = stack.back().GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1402 uint8_t addr_bytes[sizeof(lldb::addr_t)];
Greg Clayton567e7f32011-09-22 04:58:26 +00001403 uint32_t addr_size = process->GetAddressByteSize();
Chris Lattner24943d22010-06-08 16:52:24 +00001404 Error error;
Greg Clayton567e7f32011-09-22 04:58:26 +00001405 if (process->ReadMemory(pointer_addr, &addr_bytes, addr_size, error) == addr_size)
Chris Lattner24943d22010-06-08 16:52:24 +00001406 {
Greg Clayton567e7f32011-09-22 04:58:26 +00001407 DataExtractor addr_data(addr_bytes, sizeof(addr_bytes), process->GetByteOrder(), addr_size);
Chris Lattner24943d22010-06-08 16:52:24 +00001408 uint32_t addr_data_offset = 0;
1409 stack.back().GetScalar() = addr_data.GetPointer(&addr_data_offset);
1410 stack.back().ClearContext();
1411 }
1412 else
1413 {
1414 if (error_ptr)
1415 error_ptr->SetErrorStringWithFormat ("Failed to dereference pointer from 0x%llx for DW_OP_deref: %s\n",
1416 pointer_addr,
1417 error.AsCString());
1418 return false;
1419 }
1420 }
1421 else
1422 {
1423 if (error_ptr)
1424 error_ptr->SetErrorStringWithFormat ("NULL process for DW_OP_deref.\n");
1425 return false;
1426 }
1427 }
1428 else
1429 {
1430 if (error_ptr)
1431 error_ptr->SetErrorStringWithFormat ("NULL execution context for DW_OP_deref.\n");
1432 return false;
1433 }
1434 break;
1435
1436 default:
1437 break;
1438 }
1439
1440 }
1441 break;
1442
1443 //----------------------------------------------------------------------
1444 // OPCODE: DW_OP_deref_size
1445 // OPERANDS: 1
1446 // 1 - uint8_t that specifies the size of the data to dereference.
1447 // DESCRIPTION: Behaves like the DW_OP_deref operation: it pops the top
1448 // stack entry and treats it as an address. The value retrieved from that
1449 // address is pushed. In the DW_OP_deref_size operation, however, the
1450 // size in bytes of the data retrieved from the dereferenced address is
1451 // specified by the single operand. This operand is a 1-byte unsigned
1452 // integral constant whose value may not be larger than the size of an
1453 // address on the target machine. The data retrieved is zero extended
1454 // to the size of an address on the target machine before being pushed
1455 // on the expression stack.
1456 //----------------------------------------------------------------------
1457 case DW_OP_deref_size:
Jason Molenda8e69de42010-11-20 01:28:30 +00001458 {
1459 uint8_t size = opcodes.GetU8(&offset);
1460 Value::ValueType value_type = stack.back().GetValueType();
1461 switch (value_type)
1462 {
1463 case Value::eValueTypeHostAddress:
1464 {
1465 void *src = (void *)stack.back().GetScalar().ULongLong();
1466 intptr_t ptr;
1467 ::memcpy (&ptr, src, sizeof(void *));
1468 // I can't decide whether the size operand should apply to the bytes in their
1469 // lldb-host endianness or the target endianness.. I doubt this'll ever come up
1470 // but I'll opt for assuming big endian regardless.
1471 switch (size)
1472 {
1473 case 1: ptr = ptr & 0xff; break;
1474 case 2: ptr = ptr & 0xffff; break;
1475 case 3: ptr = ptr & 0xffffff; break;
1476 case 4: ptr = ptr & 0xffffffff; break;
Jason Molendaa99bcaa2010-11-29 21:38:58 +00001477 // the casts are added to work around the case where intptr_t is a 32 bit quantity;
1478 // presumably we won't hit the 5..7 cases if (void*) is 32-bits in this program.
1479 case 5: ptr = (intptr_t) ptr & 0xffffffffffULL; break;
1480 case 6: ptr = (intptr_t) ptr & 0xffffffffffffULL; break;
1481 case 7: ptr = (intptr_t) ptr & 0xffffffffffffffULL; break;
Jason Molenda8e69de42010-11-20 01:28:30 +00001482 default: break;
1483 }
1484 stack.back().GetScalar() = ptr;
1485 stack.back().ClearContext();
1486 }
1487 break;
1488 case Value::eValueTypeLoadAddress:
1489 if (exe_ctx)
1490 {
Greg Clayton567e7f32011-09-22 04:58:26 +00001491 if (process)
Jason Molenda8e69de42010-11-20 01:28:30 +00001492 {
1493 lldb::addr_t pointer_addr = stack.back().GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1494 uint8_t addr_bytes[sizeof(lldb::addr_t)];
1495 Error error;
Greg Clayton567e7f32011-09-22 04:58:26 +00001496 if (process->ReadMemory(pointer_addr, &addr_bytes, size, error) == size)
Jason Molenda8e69de42010-11-20 01:28:30 +00001497 {
Greg Clayton567e7f32011-09-22 04:58:26 +00001498 DataExtractor addr_data(addr_bytes, sizeof(addr_bytes), process->GetByteOrder(), size);
Jason Molenda8e69de42010-11-20 01:28:30 +00001499 uint32_t addr_data_offset = 0;
1500 switch (size)
1501 {
1502 case 1: stack.back().GetScalar() = addr_data.GetU8(&addr_data_offset); break;
1503 case 2: stack.back().GetScalar() = addr_data.GetU16(&addr_data_offset); break;
1504 case 4: stack.back().GetScalar() = addr_data.GetU32(&addr_data_offset); break;
1505 case 8: stack.back().GetScalar() = addr_data.GetU64(&addr_data_offset); break;
1506 default: stack.back().GetScalar() = addr_data.GetPointer(&addr_data_offset);
1507 }
1508 stack.back().ClearContext();
1509 }
1510 else
1511 {
1512 if (error_ptr)
1513 error_ptr->SetErrorStringWithFormat ("Failed to dereference pointer from 0x%llx for DW_OP_deref: %s\n",
1514 pointer_addr,
1515 error.AsCString());
1516 return false;
1517 }
1518 }
1519 else
1520 {
1521 if (error_ptr)
1522 error_ptr->SetErrorStringWithFormat ("NULL process for DW_OP_deref.\n");
1523 return false;
1524 }
1525 }
1526 else
1527 {
1528 if (error_ptr)
1529 error_ptr->SetErrorStringWithFormat ("NULL execution context for DW_OP_deref.\n");
1530 return false;
1531 }
1532 break;
1533
1534 default:
1535 break;
1536 }
1537
1538 }
1539 break;
Chris Lattner24943d22010-06-08 16:52:24 +00001540
1541 //----------------------------------------------------------------------
1542 // OPCODE: DW_OP_xderef_size
1543 // OPERANDS: 1
1544 // 1 - uint8_t that specifies the size of the data to dereference.
1545 // DESCRIPTION: Behaves like the DW_OP_xderef operation: the entry at
1546 // the top of the stack is treated as an address. The second stack
Greg Clayton33ed1702010-08-24 00:45:41 +00001547 // entry is treated as an "address space identifier" for those
Chris Lattner24943d22010-06-08 16:52:24 +00001548 // architectures that support multiple address spaces. The top two
1549 // stack elements are popped, a data item is retrieved through an
1550 // implementation-defined address calculation and pushed as the new
1551 // stack top. In the DW_OP_xderef_size operation, however, the size in
1552 // bytes of the data retrieved from the dereferenced address is
1553 // specified by the single operand. This operand is a 1-byte unsigned
1554 // integral constant whose value may not be larger than the size of an
1555 // address on the target machine. The data retrieved is zero extended
1556 // to the size of an address on the target machine before being pushed
1557 // on the expression stack.
1558 //----------------------------------------------------------------------
1559 case DW_OP_xderef_size:
1560 if (error_ptr)
1561 error_ptr->SetErrorString("Unimplemented opcode: DW_OP_xderef_size.");
1562 return false;
1563 //----------------------------------------------------------------------
1564 // OPCODE: DW_OP_xderef
1565 // OPERANDS: none
1566 // DESCRIPTION: Provides an extended dereference mechanism. The entry at
1567 // the top of the stack is treated as an address. The second stack entry
1568 // is treated as an "address space identifier" for those architectures
1569 // that support multiple address spaces. The top two stack elements are
1570 // popped, a data item is retrieved through an implementation-defined
1571 // address calculation and pushed as the new stack top. The size of the
1572 // data retrieved from the dereferenced address is the size of an address
1573 // on the target machine.
1574 //----------------------------------------------------------------------
1575 case DW_OP_xderef:
1576 if (error_ptr)
1577 error_ptr->SetErrorString("Unimplemented opcode: DW_OP_xderef.");
1578 return false;
1579
1580 //----------------------------------------------------------------------
1581 // All DW_OP_constXXX opcodes have a single operand as noted below:
1582 //
1583 // Opcode Operand 1
1584 // --------------- ----------------------------------------------------
1585 // DW_OP_const1u 1-byte unsigned integer constant
1586 // DW_OP_const1s 1-byte signed integer constant
1587 // DW_OP_const2u 2-byte unsigned integer constant
1588 // DW_OP_const2s 2-byte signed integer constant
1589 // DW_OP_const4u 4-byte unsigned integer constant
1590 // DW_OP_const4s 4-byte signed integer constant
1591 // DW_OP_const8u 8-byte unsigned integer constant
1592 // DW_OP_const8s 8-byte signed integer constant
1593 // DW_OP_constu unsigned LEB128 integer constant
1594 // DW_OP_consts signed LEB128 integer constant
1595 //----------------------------------------------------------------------
Greg Clayton801417e2011-07-07 01:59:51 +00001596 case DW_OP_const1u : stack.push_back(Scalar(( uint8_t)opcodes.GetU8 (&offset))); break;
1597 case DW_OP_const1s : stack.push_back(Scalar(( int8_t)opcodes.GetU8 (&offset))); break;
1598 case DW_OP_const2u : stack.push_back(Scalar((uint16_t)opcodes.GetU16 (&offset))); break;
1599 case DW_OP_const2s : stack.push_back(Scalar(( int16_t)opcodes.GetU16 (&offset))); break;
1600 case DW_OP_const4u : stack.push_back(Scalar((uint32_t)opcodes.GetU32 (&offset))); break;
1601 case DW_OP_const4s : stack.push_back(Scalar(( int32_t)opcodes.GetU32 (&offset))); break;
1602 case DW_OP_const8u : stack.push_back(Scalar((uint64_t)opcodes.GetU64 (&offset))); break;
1603 case DW_OP_const8s : stack.push_back(Scalar(( int64_t)opcodes.GetU64 (&offset))); break;
1604 case DW_OP_constu : stack.push_back(Scalar(opcodes.GetULEB128 (&offset))); break;
1605 case DW_OP_consts : stack.push_back(Scalar(opcodes.GetSLEB128 (&offset))); break;
Chris Lattner24943d22010-06-08 16:52:24 +00001606
1607 //----------------------------------------------------------------------
1608 // OPCODE: DW_OP_dup
1609 // OPERANDS: none
1610 // DESCRIPTION: duplicates the value at the top of the stack
1611 //----------------------------------------------------------------------
1612 case DW_OP_dup:
1613 if (stack.empty())
1614 {
1615 if (error_ptr)
1616 error_ptr->SetErrorString("Expression stack empty for DW_OP_dup.");
1617 return false;
1618 }
1619 else
1620 stack.push_back(stack.back());
1621 break;
1622
1623 //----------------------------------------------------------------------
1624 // OPCODE: DW_OP_drop
1625 // OPERANDS: none
1626 // DESCRIPTION: pops the value at the top of the stack
1627 //----------------------------------------------------------------------
1628 case DW_OP_drop:
1629 if (stack.empty())
1630 {
1631 if (error_ptr)
1632 error_ptr->SetErrorString("Expression stack empty for DW_OP_drop.");
1633 return false;
1634 }
1635 else
1636 stack.pop_back();
1637 break;
1638
1639 //----------------------------------------------------------------------
1640 // OPCODE: DW_OP_over
1641 // OPERANDS: none
1642 // DESCRIPTION: Duplicates the entry currently second in the stack at
1643 // the top of the stack.
1644 //----------------------------------------------------------------------
1645 case DW_OP_over:
1646 if (stack.size() < 2)
1647 {
1648 if (error_ptr)
1649 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_over.");
1650 return false;
1651 }
1652 else
1653 stack.push_back(stack[stack.size() - 2]);
1654 break;
1655
1656
1657 //----------------------------------------------------------------------
1658 // OPCODE: DW_OP_pick
1659 // OPERANDS: uint8_t index into the current stack
1660 // DESCRIPTION: The stack entry with the specified index (0 through 255,
1661 // inclusive) is pushed on the stack
1662 //----------------------------------------------------------------------
1663 case DW_OP_pick:
1664 {
1665 uint8_t pick_idx = opcodes.GetU8(&offset);
1666 if (pick_idx < stack.size())
1667 stack.push_back(stack[pick_idx]);
1668 else
1669 {
1670 if (error_ptr)
1671 error_ptr->SetErrorStringWithFormat("Index %u out of range for DW_OP_pick.\n", pick_idx);
1672 return false;
1673 }
1674 }
1675 break;
1676
1677 //----------------------------------------------------------------------
1678 // OPCODE: DW_OP_swap
1679 // OPERANDS: none
1680 // DESCRIPTION: swaps the top two stack entries. The entry at the top
1681 // of the stack becomes the second stack entry, and the second entry
1682 // becomes the top of the stack
1683 //----------------------------------------------------------------------
1684 case DW_OP_swap:
1685 if (stack.size() < 2)
1686 {
1687 if (error_ptr)
1688 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_swap.");
1689 return false;
1690 }
1691 else
1692 {
1693 tmp = stack.back();
1694 stack.back() = stack[stack.size() - 2];
1695 stack[stack.size() - 2] = tmp;
1696 }
1697 break;
1698
1699 //----------------------------------------------------------------------
1700 // OPCODE: DW_OP_rot
1701 // OPERANDS: none
1702 // DESCRIPTION: Rotates the first three stack entries. The entry at
1703 // the top of the stack becomes the third stack entry, the second
1704 // entry becomes the top of the stack, and the third entry becomes
1705 // the second entry.
1706 //----------------------------------------------------------------------
1707 case DW_OP_rot:
1708 if (stack.size() < 3)
1709 {
1710 if (error_ptr)
1711 error_ptr->SetErrorString("Expression stack needs at least 3 items for DW_OP_rot.");
1712 return false;
1713 }
1714 else
1715 {
1716 size_t last_idx = stack.size() - 1;
1717 Value old_top = stack[last_idx];
1718 stack[last_idx] = stack[last_idx - 1];
1719 stack[last_idx - 1] = stack[last_idx - 2];
1720 stack[last_idx - 2] = old_top;
1721 }
1722 break;
1723
1724 //----------------------------------------------------------------------
1725 // OPCODE: DW_OP_abs
1726 // OPERANDS: none
1727 // DESCRIPTION: pops the top stack entry, interprets it as a signed
1728 // value and pushes its absolute value. If the absolute value can not be
1729 // represented, the result is undefined.
1730 //----------------------------------------------------------------------
1731 case DW_OP_abs:
1732 if (stack.empty())
1733 {
1734 if (error_ptr)
1735 error_ptr->SetErrorString("Expression stack needs at least 1 item for DW_OP_abs.");
1736 return false;
1737 }
1738 else if (stack.back().ResolveValue(exe_ctx, ast_context).AbsoluteValue() == false)
1739 {
1740 if (error_ptr)
1741 error_ptr->SetErrorString("Failed to take the absolute value of the first stack item.");
1742 return false;
1743 }
1744 break;
1745
1746 //----------------------------------------------------------------------
1747 // OPCODE: DW_OP_and
1748 // OPERANDS: none
1749 // DESCRIPTION: pops the top two stack values, performs a bitwise and
1750 // operation on the two, and pushes the result.
1751 //----------------------------------------------------------------------
1752 case DW_OP_and:
1753 if (stack.size() < 2)
1754 {
1755 if (error_ptr)
1756 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_and.");
1757 return false;
1758 }
1759 else
1760 {
1761 tmp = stack.back();
1762 stack.pop_back();
1763 stack.back().ResolveValue(exe_ctx, ast_context) = stack.back().ResolveValue(exe_ctx, ast_context) & tmp.ResolveValue(exe_ctx, ast_context);
1764 }
1765 break;
1766
1767 //----------------------------------------------------------------------
1768 // OPCODE: DW_OP_div
1769 // OPERANDS: none
1770 // DESCRIPTION: pops the top two stack values, divides the former second
1771 // entry by the former top of the stack using signed division, and
1772 // pushes the result.
1773 //----------------------------------------------------------------------
1774 case DW_OP_div:
1775 if (stack.size() < 2)
1776 {
1777 if (error_ptr)
1778 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_div.");
1779 return false;
1780 }
1781 else
1782 {
1783 tmp = stack.back();
1784 if (tmp.ResolveValue(exe_ctx, ast_context).IsZero())
1785 {
1786 if (error_ptr)
1787 error_ptr->SetErrorString("Divide by zero.");
1788 return false;
1789 }
1790 else
1791 {
1792 stack.pop_back();
1793 stack.back() = stack.back().ResolveValue(exe_ctx, ast_context) / tmp.ResolveValue(exe_ctx, ast_context);
1794 if (!stack.back().ResolveValue(exe_ctx, ast_context).IsValid())
1795 {
1796 if (error_ptr)
1797 error_ptr->SetErrorString("Divide failed.");
1798 return false;
1799 }
1800 }
1801 }
1802 break;
1803
1804 //----------------------------------------------------------------------
1805 // OPCODE: DW_OP_minus
1806 // OPERANDS: none
1807 // DESCRIPTION: pops the top two stack values, subtracts the former top
1808 // of the stack from the former second entry, and pushes the result.
1809 //----------------------------------------------------------------------
1810 case DW_OP_minus:
1811 if (stack.size() < 2)
1812 {
1813 if (error_ptr)
1814 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_minus.");
1815 return false;
1816 }
1817 else
1818 {
1819 tmp = stack.back();
1820 stack.pop_back();
1821 stack.back().ResolveValue(exe_ctx, ast_context) = stack.back().ResolveValue(exe_ctx, ast_context) - tmp.ResolveValue(exe_ctx, ast_context);
1822 }
1823 break;
1824
1825 //----------------------------------------------------------------------
1826 // OPCODE: DW_OP_mod
1827 // OPERANDS: none
1828 // DESCRIPTION: pops the top two stack values and pushes the result of
1829 // the calculation: former second stack entry modulo the former top of
1830 // the stack.
1831 //----------------------------------------------------------------------
1832 case DW_OP_mod:
1833 if (stack.size() < 2)
1834 {
1835 if (error_ptr)
1836 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_mod.");
1837 return false;
1838 }
1839 else
1840 {
1841 tmp = stack.back();
1842 stack.pop_back();
1843 stack.back().ResolveValue(exe_ctx, ast_context) = stack.back().ResolveValue(exe_ctx, ast_context) % tmp.ResolveValue(exe_ctx, ast_context);
1844 }
1845 break;
1846
1847
1848 //----------------------------------------------------------------------
1849 // OPCODE: DW_OP_mul
1850 // OPERANDS: none
1851 // DESCRIPTION: pops the top two stack entries, multiplies them
1852 // together, and pushes the result.
1853 //----------------------------------------------------------------------
1854 case DW_OP_mul:
1855 if (stack.size() < 2)
1856 {
1857 if (error_ptr)
1858 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_mul.");
1859 return false;
1860 }
1861 else
1862 {
1863 tmp = stack.back();
1864 stack.pop_back();
1865 stack.back().ResolveValue(exe_ctx, ast_context) = stack.back().ResolveValue(exe_ctx, ast_context) * tmp.ResolveValue(exe_ctx, ast_context);
1866 }
1867 break;
1868
1869 //----------------------------------------------------------------------
1870 // OPCODE: DW_OP_neg
1871 // OPERANDS: none
1872 // DESCRIPTION: pops the top stack entry, and pushes its negation.
1873 //----------------------------------------------------------------------
1874 case DW_OP_neg:
1875 if (stack.empty())
1876 {
1877 if (error_ptr)
1878 error_ptr->SetErrorString("Expression stack needs at least 1 item for DW_OP_neg.");
1879 return false;
1880 }
1881 else
1882 {
1883 if (stack.back().ResolveValue(exe_ctx, ast_context).UnaryNegate() == false)
1884 {
1885 if (error_ptr)
1886 error_ptr->SetErrorString("Unary negate failed.");
1887 return false;
1888 }
1889 }
1890 break;
1891
1892 //----------------------------------------------------------------------
1893 // OPCODE: DW_OP_not
1894 // OPERANDS: none
1895 // DESCRIPTION: pops the top stack entry, and pushes its bitwise
1896 // complement
1897 //----------------------------------------------------------------------
1898 case DW_OP_not:
1899 if (stack.empty())
1900 {
1901 if (error_ptr)
1902 error_ptr->SetErrorString("Expression stack needs at least 1 item for DW_OP_not.");
1903 return false;
1904 }
1905 else
1906 {
1907 if (stack.back().ResolveValue(exe_ctx, ast_context).OnesComplement() == false)
1908 {
1909 if (error_ptr)
1910 error_ptr->SetErrorString("Logical NOT failed.");
1911 return false;
1912 }
1913 }
1914 break;
1915
1916 //----------------------------------------------------------------------
1917 // OPCODE: DW_OP_or
1918 // OPERANDS: none
1919 // DESCRIPTION: pops the top two stack entries, performs a bitwise or
1920 // operation on the two, and pushes the result.
1921 //----------------------------------------------------------------------
1922 case DW_OP_or:
1923 if (stack.size() < 2)
1924 {
1925 if (error_ptr)
1926 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_or.");
1927 return false;
1928 }
1929 else
1930 {
1931 tmp = stack.back();
1932 stack.pop_back();
1933 stack.back().ResolveValue(exe_ctx, ast_context) = stack.back().ResolveValue(exe_ctx, ast_context) | tmp.ResolveValue(exe_ctx, ast_context);
1934 }
1935 break;
1936
1937 //----------------------------------------------------------------------
1938 // OPCODE: DW_OP_plus
1939 // OPERANDS: none
1940 // DESCRIPTION: pops the top two stack entries, adds them together, and
1941 // pushes the result.
1942 //----------------------------------------------------------------------
1943 case DW_OP_plus:
1944 if (stack.size() < 2)
1945 {
1946 if (error_ptr)
1947 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_plus.");
1948 return false;
1949 }
1950 else
1951 {
1952 tmp = stack.back();
1953 stack.pop_back();
1954 stack.back().ResolveValue(exe_ctx, ast_context) = stack.back().ResolveValue(exe_ctx, ast_context) + tmp.ResolveValue(exe_ctx, ast_context);
1955 }
1956 break;
1957
1958 //----------------------------------------------------------------------
1959 // OPCODE: DW_OP_plus_uconst
1960 // OPERANDS: none
1961 // DESCRIPTION: pops the top stack entry, adds it to the unsigned LEB128
1962 // constant operand and pushes the result.
1963 //----------------------------------------------------------------------
1964 case DW_OP_plus_uconst:
1965 if (stack.empty())
1966 {
1967 if (error_ptr)
1968 error_ptr->SetErrorString("Expression stack needs at least 1 item for DW_OP_plus_uconst.");
1969 return false;
1970 }
1971 else
1972 {
1973 uint32_t uconst_value = opcodes.GetULEB128(&offset);
1974 // Implicit conversion from a UINT to a Scalar...
1975 stack.back().ResolveValue(exe_ctx, ast_context) += uconst_value;
1976 if (!stack.back().ResolveValue(exe_ctx, ast_context).IsValid())
1977 {
1978 if (error_ptr)
1979 error_ptr->SetErrorString("DW_OP_plus_uconst failed.");
1980 return false;
1981 }
1982 }
1983 break;
1984
1985 //----------------------------------------------------------------------
1986 // OPCODE: DW_OP_shl
1987 // OPERANDS: none
1988 // DESCRIPTION: pops the top two stack entries, shifts the former
1989 // second entry left by the number of bits specified by the former top
1990 // of the stack, and pushes the result.
1991 //----------------------------------------------------------------------
1992 case DW_OP_shl:
1993 if (stack.size() < 2)
1994 {
1995 if (error_ptr)
1996 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_shl.");
1997 return false;
1998 }
1999 else
2000 {
2001 tmp = stack.back();
2002 stack.pop_back();
2003 stack.back().ResolveValue(exe_ctx, ast_context) <<= tmp.ResolveValue(exe_ctx, ast_context);
2004 }
2005 break;
2006
2007 //----------------------------------------------------------------------
2008 // OPCODE: DW_OP_shr
2009 // OPERANDS: none
2010 // DESCRIPTION: pops the top two stack entries, shifts the former second
2011 // entry right logically (filling with zero bits) by the number of bits
2012 // specified by the former top of the stack, and pushes the result.
2013 //----------------------------------------------------------------------
2014 case DW_OP_shr:
2015 if (stack.size() < 2)
2016 {
2017 if (error_ptr)
2018 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_shr.");
2019 return false;
2020 }
2021 else
2022 {
2023 tmp = stack.back();
2024 stack.pop_back();
2025 if (stack.back().ResolveValue(exe_ctx, ast_context).ShiftRightLogical(tmp.ResolveValue(exe_ctx, ast_context)) == false)
2026 {
2027 if (error_ptr)
2028 error_ptr->SetErrorString("DW_OP_shr failed.");
2029 return false;
2030 }
2031 }
2032 break;
2033
2034 //----------------------------------------------------------------------
2035 // OPCODE: DW_OP_shra
2036 // OPERANDS: none
2037 // DESCRIPTION: pops the top two stack entries, shifts the former second
2038 // entry right arithmetically (divide the magnitude by 2, keep the same
2039 // sign for the result) by the number of bits specified by the former
2040 // top of the stack, and pushes the result.
2041 //----------------------------------------------------------------------
2042 case DW_OP_shra:
2043 if (stack.size() < 2)
2044 {
2045 if (error_ptr)
2046 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_shra.");
2047 return false;
2048 }
2049 else
2050 {
2051 tmp = stack.back();
2052 stack.pop_back();
2053 stack.back().ResolveValue(exe_ctx, ast_context) >>= tmp.ResolveValue(exe_ctx, ast_context);
2054 }
2055 break;
2056
2057 //----------------------------------------------------------------------
2058 // OPCODE: DW_OP_xor
2059 // OPERANDS: none
2060 // DESCRIPTION: pops the top two stack entries, performs the bitwise
2061 // exclusive-or operation on the two, and pushes the result.
2062 //----------------------------------------------------------------------
2063 case DW_OP_xor:
2064 if (stack.size() < 2)
2065 {
2066 if (error_ptr)
2067 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_xor.");
2068 return false;
2069 }
2070 else
2071 {
2072 tmp = stack.back();
2073 stack.pop_back();
2074 stack.back().ResolveValue(exe_ctx, ast_context) = stack.back().ResolveValue(exe_ctx, ast_context) ^ tmp.ResolveValue(exe_ctx, ast_context);
2075 }
2076 break;
2077
2078
2079 //----------------------------------------------------------------------
2080 // OPCODE: DW_OP_skip
2081 // OPERANDS: int16_t
2082 // DESCRIPTION: An unconditional branch. Its single operand is a 2-byte
2083 // signed integer constant. The 2-byte constant is the number of bytes
2084 // of the DWARF expression to skip forward or backward from the current
2085 // operation, beginning after the 2-byte constant.
2086 //----------------------------------------------------------------------
2087 case DW_OP_skip:
2088 {
2089 int16_t skip_offset = (int16_t)opcodes.GetU16(&offset);
2090 uint32_t new_offset = offset + skip_offset;
2091 if (new_offset >= opcodes_offset && new_offset < end_offset)
2092 offset = new_offset;
2093 else
2094 {
2095 if (error_ptr)
2096 error_ptr->SetErrorString("Invalid opcode offset in DW_OP_skip.");
2097 return false;
2098 }
2099 }
2100 break;
2101
2102 //----------------------------------------------------------------------
2103 // OPCODE: DW_OP_bra
2104 // OPERANDS: int16_t
2105 // DESCRIPTION: A conditional branch. Its single operand is a 2-byte
2106 // signed integer constant. This operation pops the top of stack. If
2107 // the value popped is not the constant 0, the 2-byte constant operand
2108 // is the number of bytes of the DWARF expression to skip forward or
2109 // backward from the current operation, beginning after the 2-byte
2110 // constant.
2111 //----------------------------------------------------------------------
2112 case DW_OP_bra:
2113 {
2114 tmp = stack.back();
2115 stack.pop_back();
2116 int16_t bra_offset = (int16_t)opcodes.GetU16(&offset);
2117 Scalar zero(0);
2118 if (tmp.ResolveValue(exe_ctx, ast_context) != zero)
2119 {
2120 uint32_t new_offset = offset + bra_offset;
2121 if (new_offset >= opcodes_offset && new_offset < end_offset)
2122 offset = new_offset;
2123 else
2124 {
2125 if (error_ptr)
2126 error_ptr->SetErrorString("Invalid opcode offset in DW_OP_bra.");
2127 return false;
2128 }
2129 }
2130 }
2131 break;
2132
2133 //----------------------------------------------------------------------
2134 // OPCODE: DW_OP_eq
2135 // OPERANDS: none
2136 // DESCRIPTION: pops the top two stack values, compares using the
2137 // equals (==) operator.
2138 // STACK RESULT: push the constant value 1 onto the stack if the result
2139 // of the operation is true or the constant value 0 if the result of the
2140 // operation is false.
2141 //----------------------------------------------------------------------
2142 case DW_OP_eq:
2143 if (stack.size() < 2)
2144 {
2145 if (error_ptr)
2146 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_eq.");
2147 return false;
2148 }
2149 else
2150 {
2151 tmp = stack.back();
2152 stack.pop_back();
2153 stack.back().ResolveValue(exe_ctx, ast_context) = stack.back().ResolveValue(exe_ctx, ast_context) == tmp.ResolveValue(exe_ctx, ast_context);
2154 }
2155 break;
2156
2157 //----------------------------------------------------------------------
2158 // OPCODE: DW_OP_ge
2159 // OPERANDS: none
2160 // DESCRIPTION: pops the top two stack values, compares using the
2161 // greater than or equal to (>=) operator.
2162 // STACK RESULT: push the constant value 1 onto the stack if the result
2163 // of the operation is true or the constant value 0 if the result of the
2164 // operation is false.
2165 //----------------------------------------------------------------------
2166 case DW_OP_ge:
2167 if (stack.size() < 2)
2168 {
2169 if (error_ptr)
2170 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_ge.");
2171 return false;
2172 }
2173 else
2174 {
2175 tmp = stack.back();
2176 stack.pop_back();
2177 stack.back().ResolveValue(exe_ctx, ast_context) = stack.back().ResolveValue(exe_ctx, ast_context) >= tmp.ResolveValue(exe_ctx, ast_context);
2178 }
2179 break;
2180
2181 //----------------------------------------------------------------------
2182 // OPCODE: DW_OP_gt
2183 // OPERANDS: none
2184 // DESCRIPTION: pops the top two stack values, compares using the
2185 // greater than (>) operator.
2186 // STACK RESULT: push the constant value 1 onto the stack if the result
2187 // of the operation is true or the constant value 0 if the result of the
2188 // operation is false.
2189 //----------------------------------------------------------------------
2190 case DW_OP_gt:
2191 if (stack.size() < 2)
2192 {
2193 if (error_ptr)
2194 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_gt.");
2195 return false;
2196 }
2197 else
2198 {
2199 tmp = stack.back();
2200 stack.pop_back();
2201 stack.back().ResolveValue(exe_ctx, ast_context) = stack.back().ResolveValue(exe_ctx, ast_context) > tmp.ResolveValue(exe_ctx, ast_context);
2202 }
2203 break;
2204
2205 //----------------------------------------------------------------------
2206 // OPCODE: DW_OP_le
2207 // OPERANDS: none
2208 // DESCRIPTION: pops the top two stack values, compares using the
2209 // less than or equal to (<=) operator.
2210 // STACK RESULT: push the constant value 1 onto the stack if the result
2211 // of the operation is true or the constant value 0 if the result of the
2212 // operation is false.
2213 //----------------------------------------------------------------------
2214 case DW_OP_le:
2215 if (stack.size() < 2)
2216 {
2217 if (error_ptr)
2218 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_le.");
2219 return false;
2220 }
2221 else
2222 {
2223 tmp = stack.back();
2224 stack.pop_back();
2225 stack.back().ResolveValue(exe_ctx, ast_context) = stack.back().ResolveValue(exe_ctx, ast_context) <= tmp.ResolveValue(exe_ctx, ast_context);
2226 }
2227 break;
2228
2229 //----------------------------------------------------------------------
2230 // OPCODE: DW_OP_lt
2231 // OPERANDS: none
2232 // DESCRIPTION: pops the top two stack values, compares using the
2233 // less than (<) operator.
2234 // STACK RESULT: push the constant value 1 onto the stack if the result
2235 // of the operation is true or the constant value 0 if the result of the
2236 // operation is false.
2237 //----------------------------------------------------------------------
2238 case DW_OP_lt:
2239 if (stack.size() < 2)
2240 {
2241 if (error_ptr)
2242 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_lt.");
2243 return false;
2244 }
2245 else
2246 {
2247 tmp = stack.back();
2248 stack.pop_back();
2249 stack.back().ResolveValue(exe_ctx, ast_context) = stack.back().ResolveValue(exe_ctx, ast_context) < tmp.ResolveValue(exe_ctx, ast_context);
2250 }
2251 break;
2252
2253 //----------------------------------------------------------------------
2254 // OPCODE: DW_OP_ne
2255 // OPERANDS: none
2256 // DESCRIPTION: pops the top two stack values, compares using the
2257 // not equal (!=) operator.
2258 // STACK RESULT: push the constant value 1 onto the stack if the result
2259 // of the operation is true or the constant value 0 if the result of the
2260 // operation is false.
2261 //----------------------------------------------------------------------
2262 case DW_OP_ne:
2263 if (stack.size() < 2)
2264 {
2265 if (error_ptr)
2266 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_ne.");
2267 return false;
2268 }
2269 else
2270 {
2271 tmp = stack.back();
2272 stack.pop_back();
2273 stack.back().ResolveValue(exe_ctx, ast_context) = stack.back().ResolveValue(exe_ctx, ast_context) != tmp.ResolveValue(exe_ctx, ast_context);
2274 }
2275 break;
2276
2277 //----------------------------------------------------------------------
2278 // OPCODE: DW_OP_litn
2279 // OPERANDS: none
2280 // DESCRIPTION: encode the unsigned literal values from 0 through 31.
2281 // STACK RESULT: push the unsigned literal constant value onto the top
2282 // of the stack.
2283 //----------------------------------------------------------------------
2284 case DW_OP_lit0:
2285 case DW_OP_lit1:
2286 case DW_OP_lit2:
2287 case DW_OP_lit3:
2288 case DW_OP_lit4:
2289 case DW_OP_lit5:
2290 case DW_OP_lit6:
2291 case DW_OP_lit7:
2292 case DW_OP_lit8:
2293 case DW_OP_lit9:
2294 case DW_OP_lit10:
2295 case DW_OP_lit11:
2296 case DW_OP_lit12:
2297 case DW_OP_lit13:
2298 case DW_OP_lit14:
2299 case DW_OP_lit15:
2300 case DW_OP_lit16:
2301 case DW_OP_lit17:
2302 case DW_OP_lit18:
2303 case DW_OP_lit19:
2304 case DW_OP_lit20:
2305 case DW_OP_lit21:
2306 case DW_OP_lit22:
2307 case DW_OP_lit23:
2308 case DW_OP_lit24:
2309 case DW_OP_lit25:
2310 case DW_OP_lit26:
2311 case DW_OP_lit27:
2312 case DW_OP_lit28:
2313 case DW_OP_lit29:
2314 case DW_OP_lit30:
2315 case DW_OP_lit31:
Greg Clayton801417e2011-07-07 01:59:51 +00002316 stack.push_back(Scalar(op - DW_OP_lit0));
Chris Lattner24943d22010-06-08 16:52:24 +00002317 break;
2318
2319 //----------------------------------------------------------------------
2320 // OPCODE: DW_OP_regN
2321 // OPERANDS: none
2322 // DESCRIPTION: Push the value in register n on the top of the stack.
2323 //----------------------------------------------------------------------
2324 case DW_OP_reg0:
2325 case DW_OP_reg1:
2326 case DW_OP_reg2:
2327 case DW_OP_reg3:
2328 case DW_OP_reg4:
2329 case DW_OP_reg5:
2330 case DW_OP_reg6:
2331 case DW_OP_reg7:
2332 case DW_OP_reg8:
2333 case DW_OP_reg9:
2334 case DW_OP_reg10:
2335 case DW_OP_reg11:
2336 case DW_OP_reg12:
2337 case DW_OP_reg13:
2338 case DW_OP_reg14:
2339 case DW_OP_reg15:
2340 case DW_OP_reg16:
2341 case DW_OP_reg17:
2342 case DW_OP_reg18:
2343 case DW_OP_reg19:
2344 case DW_OP_reg20:
2345 case DW_OP_reg21:
2346 case DW_OP_reg22:
2347 case DW_OP_reg23:
2348 case DW_OP_reg24:
2349 case DW_OP_reg25:
2350 case DW_OP_reg26:
2351 case DW_OP_reg27:
2352 case DW_OP_reg28:
2353 case DW_OP_reg29:
2354 case DW_OP_reg30:
2355 case DW_OP_reg31:
2356 {
2357 reg_num = op - DW_OP_reg0;
2358
Jason Molenda8e69de42010-11-20 01:28:30 +00002359 if (ReadRegisterValueAsScalar (reg_ctx, reg_kind, reg_num, error_ptr, tmp))
Chris Lattner24943d22010-06-08 16:52:24 +00002360 stack.push_back(tmp);
2361 else
2362 return false;
2363 }
2364 break;
2365 //----------------------------------------------------------------------
2366 // OPCODE: DW_OP_regx
2367 // OPERANDS:
2368 // ULEB128 literal operand that encodes the register.
2369 // DESCRIPTION: Push the value in register on the top of the stack.
2370 //----------------------------------------------------------------------
2371 case DW_OP_regx:
2372 {
2373 reg_num = opcodes.GetULEB128(&offset);
Jason Molenda8e69de42010-11-20 01:28:30 +00002374 if (ReadRegisterValueAsScalar (reg_ctx, reg_kind, reg_num, error_ptr, tmp))
Chris Lattner24943d22010-06-08 16:52:24 +00002375 stack.push_back(tmp);
2376 else
2377 return false;
2378 }
2379 break;
2380
2381 //----------------------------------------------------------------------
2382 // OPCODE: DW_OP_bregN
2383 // OPERANDS:
2384 // SLEB128 offset from register N
2385 // DESCRIPTION: Value is in memory at the address specified by register
2386 // N plus an offset.
2387 //----------------------------------------------------------------------
2388 case DW_OP_breg0:
2389 case DW_OP_breg1:
2390 case DW_OP_breg2:
2391 case DW_OP_breg3:
2392 case DW_OP_breg4:
2393 case DW_OP_breg5:
2394 case DW_OP_breg6:
2395 case DW_OP_breg7:
2396 case DW_OP_breg8:
2397 case DW_OP_breg9:
2398 case DW_OP_breg10:
2399 case DW_OP_breg11:
2400 case DW_OP_breg12:
2401 case DW_OP_breg13:
2402 case DW_OP_breg14:
2403 case DW_OP_breg15:
2404 case DW_OP_breg16:
2405 case DW_OP_breg17:
2406 case DW_OP_breg18:
2407 case DW_OP_breg19:
2408 case DW_OP_breg20:
2409 case DW_OP_breg21:
2410 case DW_OP_breg22:
2411 case DW_OP_breg23:
2412 case DW_OP_breg24:
2413 case DW_OP_breg25:
2414 case DW_OP_breg26:
2415 case DW_OP_breg27:
2416 case DW_OP_breg28:
2417 case DW_OP_breg29:
2418 case DW_OP_breg30:
2419 case DW_OP_breg31:
2420 {
2421 reg_num = op - DW_OP_breg0;
2422
Jason Molenda8e69de42010-11-20 01:28:30 +00002423 if (ReadRegisterValueAsScalar (reg_ctx, reg_kind, reg_num, error_ptr, tmp))
Chris Lattner24943d22010-06-08 16:52:24 +00002424 {
2425 int64_t breg_offset = opcodes.GetSLEB128(&offset);
2426 tmp.ResolveValue(exe_ctx, ast_context) += (uint64_t)breg_offset;
2427 stack.push_back(tmp);
2428 stack.back().SetValueType (Value::eValueTypeLoadAddress);
2429 }
2430 else
2431 return false;
2432 }
2433 break;
2434 //----------------------------------------------------------------------
2435 // OPCODE: DW_OP_bregx
2436 // OPERANDS: 2
2437 // ULEB128 literal operand that encodes the register.
2438 // SLEB128 offset from register N
2439 // DESCRIPTION: Value is in memory at the address specified by register
2440 // N plus an offset.
2441 //----------------------------------------------------------------------
2442 case DW_OP_bregx:
2443 {
2444 reg_num = opcodes.GetULEB128(&offset);
2445
Jason Molenda8e69de42010-11-20 01:28:30 +00002446 if (ReadRegisterValueAsScalar (reg_ctx, reg_kind, reg_num, error_ptr, tmp))
Chris Lattner24943d22010-06-08 16:52:24 +00002447 {
2448 int64_t breg_offset = opcodes.GetSLEB128(&offset);
2449 tmp.ResolveValue(exe_ctx, ast_context) += (uint64_t)breg_offset;
2450 stack.push_back(tmp);
2451 stack.back().SetValueType (Value::eValueTypeLoadAddress);
2452 }
2453 else
2454 return false;
2455 }
2456 break;
2457
2458 case DW_OP_fbreg:
Greg Clayton567e7f32011-09-22 04:58:26 +00002459 if (exe_ctx)
Chris Lattner24943d22010-06-08 16:52:24 +00002460 {
Greg Clayton567e7f32011-09-22 04:58:26 +00002461 if (frame)
Chris Lattner24943d22010-06-08 16:52:24 +00002462 {
Greg Clayton567e7f32011-09-22 04:58:26 +00002463 Scalar value;
2464 if (frame->GetFrameBaseValue(value, error_ptr))
2465 {
2466 int64_t fbreg_offset = opcodes.GetSLEB128(&offset);
2467 value += fbreg_offset;
2468 stack.push_back(value);
2469 stack.back().SetValueType (Value::eValueTypeLoadAddress);
2470 }
2471 else
2472 return false;
Chris Lattner24943d22010-06-08 16:52:24 +00002473 }
2474 else
Greg Clayton567e7f32011-09-22 04:58:26 +00002475 {
2476 if (error_ptr)
2477 error_ptr->SetErrorString ("Invalid stack frame in context for DW_OP_fbreg opcode.");
Chris Lattner24943d22010-06-08 16:52:24 +00002478 return false;
Greg Clayton567e7f32011-09-22 04:58:26 +00002479 }
Chris Lattner24943d22010-06-08 16:52:24 +00002480 }
2481 else
2482 {
2483 if (error_ptr)
Greg Clayton567e7f32011-09-22 04:58:26 +00002484 error_ptr->SetErrorStringWithFormat ("NULL execution context for DW_OP_fbreg.\n");
Chris Lattner24943d22010-06-08 16:52:24 +00002485 return false;
2486 }
Greg Clayton567e7f32011-09-22 04:58:26 +00002487
Chris Lattner24943d22010-06-08 16:52:24 +00002488 break;
2489
2490 //----------------------------------------------------------------------
2491 // OPCODE: DW_OP_nop
2492 // OPERANDS: none
2493 // DESCRIPTION: A place holder. It has no effect on the location stack
2494 // or any of its values.
2495 //----------------------------------------------------------------------
2496 case DW_OP_nop:
2497 break;
2498
2499 //----------------------------------------------------------------------
2500 // OPCODE: DW_OP_piece
2501 // OPERANDS: 1
2502 // ULEB128: byte size of the piece
2503 // DESCRIPTION: The operand describes the size in bytes of the piece of
2504 // the object referenced by the DWARF expression whose result is at the
2505 // top of the stack. If the piece is located in a register, but does not
2506 // occupy the entire register, the placement of the piece within that
2507 // register is defined by the ABI.
2508 //
2509 // Many compilers store a single variable in sets of registers, or store
2510 // a variable partially in memory and partially in registers.
2511 // DW_OP_piece provides a way of describing how large a part of a
2512 // variable a particular DWARF expression refers to.
2513 //----------------------------------------------------------------------
2514 case DW_OP_piece:
2515 if (error_ptr)
2516 error_ptr->SetErrorString ("Unimplemented opcode DW_OP_piece.");
2517 return false;
2518
2519 //----------------------------------------------------------------------
2520 // OPCODE: DW_OP_push_object_address
2521 // OPERANDS: none
2522 // DESCRIPTION: Pushes the address of the object currently being
2523 // evaluated as part of evaluation of a user presented expression.
2524 // This object may correspond to an independent variable described by
2525 // its own DIE or it may be a component of an array, structure, or class
2526 // whose address has been dynamically determined by an earlier step
2527 // during user expression evaluation.
2528 //----------------------------------------------------------------------
2529 case DW_OP_push_object_address:
2530 if (error_ptr)
2531 error_ptr->SetErrorString ("Unimplemented opcode DW_OP_push_object_address.");
2532 return false;
2533
2534 //----------------------------------------------------------------------
2535 // OPCODE: DW_OP_call2
2536 // OPERANDS:
2537 // uint16_t compile unit relative offset of a DIE
2538 // DESCRIPTION: Performs subroutine calls during evaluation
2539 // of a DWARF expression. The operand is the 2-byte unsigned offset
2540 // of a debugging information entry in the current compilation unit.
2541 //
2542 // Operand interpretation is exactly like that for DW_FORM_ref2.
2543 //
2544 // This operation transfers control of DWARF expression evaluation
2545 // to the DW_AT_location attribute of the referenced DIE. If there is
2546 // no such attribute, then there is no effect. Execution of the DWARF
2547 // expression of a DW_AT_location attribute may add to and/or remove from
2548 // values on the stack. Execution returns to the point following the call
2549 // when the end of the attribute is reached. Values on the stack at the
2550 // time of the call may be used as parameters by the called expression
2551 // and values left on the stack by the called expression may be used as
2552 // return values by prior agreement between the calling and called
2553 // expressions.
2554 //----------------------------------------------------------------------
2555 case DW_OP_call2:
2556 if (error_ptr)
2557 error_ptr->SetErrorString ("Unimplemented opcode DW_OP_call2.");
2558 return false;
2559 //----------------------------------------------------------------------
2560 // OPCODE: DW_OP_call4
2561 // OPERANDS: 1
2562 // uint32_t compile unit relative offset of a DIE
2563 // DESCRIPTION: Performs a subroutine call during evaluation of a DWARF
2564 // expression. For DW_OP_call4, the operand is a 4-byte unsigned offset
2565 // of a debugging information entry in the current compilation unit.
2566 //
2567 // Operand interpretation DW_OP_call4 is exactly like that for
2568 // DW_FORM_ref4.
2569 //
2570 // This operation transfers control of DWARF expression evaluation
2571 // to the DW_AT_location attribute of the referenced DIE. If there is
2572 // no such attribute, then there is no effect. Execution of the DWARF
2573 // expression of a DW_AT_location attribute may add to and/or remove from
2574 // values on the stack. Execution returns to the point following the call
2575 // when the end of the attribute is reached. Values on the stack at the
2576 // time of the call may be used as parameters by the called expression
2577 // and values left on the stack by the called expression may be used as
2578 // return values by prior agreement between the calling and called
2579 // expressions.
2580 //----------------------------------------------------------------------
2581 case DW_OP_call4:
2582 if (error_ptr)
2583 error_ptr->SetErrorString ("Unimplemented opcode DW_OP_call4.");
2584 return false;
2585
Greg Claytona1b9a902011-11-13 04:15:56 +00002586#if 0
Chris Lattner24943d22010-06-08 16:52:24 +00002587 //----------------------------------------------------------------------
2588 // OPCODE: DW_OP_call_ref
2589 // OPERANDS:
2590 // uint32_t absolute DIE offset for 32-bit DWARF or a uint64_t
2591 // absolute DIE offset for 64 bit DWARF.
2592 // DESCRIPTION: Performs a subroutine call during evaluation of a DWARF
2593 // expression. Takes a single operand. In the 32-bit DWARF format, the
2594 // operand is a 4-byte unsigned value; in the 64-bit DWARF format, it
2595 // is an 8-byte unsigned value. The operand is used as the offset of a
2596 // debugging information entry in a .debug_info section which may be
2597 // contained in a shared object for executable other than that
2598 // containing the operator. For references from one shared object or
2599 // executable to another, the relocation must be performed by the
2600 // consumer.
2601 //
2602 // Operand interpretation of DW_OP_call_ref is exactly like that for
2603 // DW_FORM_ref_addr.
2604 //
2605 // This operation transfers control of DWARF expression evaluation
2606 // to the DW_AT_location attribute of the referenced DIE. If there is
2607 // no such attribute, then there is no effect. Execution of the DWARF
2608 // expression of a DW_AT_location attribute may add to and/or remove from
2609 // values on the stack. Execution returns to the point following the call
2610 // when the end of the attribute is reached. Values on the stack at the
2611 // time of the call may be used as parameters by the called expression
2612 // and values left on the stack by the called expression may be used as
2613 // return values by prior agreement between the calling and called
2614 // expressions.
2615 //----------------------------------------------------------------------
2616 case DW_OP_call_ref:
2617 if (error_ptr)
2618 error_ptr->SetErrorString ("Unimplemented opcode DW_OP_call_ref.");
2619 return false;
2620
Greg Claytona1b9a902011-11-13 04:15:56 +00002621 //----------------------------------------------------------------------
2622 // OPCODE: DW_OP_APPLE_array_ref
2623 // OPERANDS: none
2624 // DESCRIPTION: Pops a value off the stack and uses it as the array
2625 // index. Pops a second value off the stack and uses it as the array
2626 // itself. Pushes a value onto the stack representing the element of
2627 // the array specified by the index.
2628 //----------------------------------------------------------------------
2629 case DW_OP_APPLE_array_ref:
Chris Lattner24943d22010-06-08 16:52:24 +00002630 {
2631 if (stack.size() < 2)
2632 {
2633 if (error_ptr)
2634 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_APPLE_array_ref.");
2635 return false;
2636 }
2637
2638 Value index_val = stack.back();
2639 stack.pop_back();
2640 Value array_val = stack.back();
2641 stack.pop_back();
2642
2643 Scalar &index_scalar = index_val.ResolveValue(exe_ctx, ast_context);
Greg Clayton381f9682011-04-01 18:14:08 +00002644 int64_t index = index_scalar.SLongLong(LLONG_MAX);
Chris Lattner24943d22010-06-08 16:52:24 +00002645
Greg Clayton381f9682011-04-01 18:14:08 +00002646 if (index == LLONG_MAX)
Chris Lattner24943d22010-06-08 16:52:24 +00002647 {
2648 if (error_ptr)
2649 error_ptr->SetErrorString("Invalid array index.");
2650 return false;
2651 }
Greg Claytona1b9a902011-11-13 04:15:56 +00002652
Greg Clayton6916e352010-11-13 03:52:47 +00002653 if (array_val.GetContextType() != Value::eContextTypeClangType)
Chris Lattner24943d22010-06-08 16:52:24 +00002654 {
2655 if (error_ptr)
2656 error_ptr->SetErrorString("Arrays without Clang types are unhandled at this time.");
2657 return false;
2658 }
2659
2660 if (array_val.GetValueType() != Value::eValueTypeLoadAddress &&
2661 array_val.GetValueType() != Value::eValueTypeHostAddress)
2662 {
2663 if (error_ptr)
2664 error_ptr->SetErrorString("Array must be stored in memory.");
2665 return false;
2666 }
2667
Greg Clayton462d4142010-09-29 01:12:09 +00002668 void *array_type = array_val.GetClangType();
Chris Lattner24943d22010-06-08 16:52:24 +00002669
2670 void *member_type;
2671 uint64_t size = 0;
2672
2673 if ((!ClangASTContext::IsPointerType(array_type, &member_type)) &&
2674 (!ClangASTContext::IsArrayType(array_type, &member_type, &size)))
2675 {
2676 if (error_ptr)
2677 error_ptr->SetErrorString("Array reference from something that is neither a pointer nor an array.");
2678 return false;
2679 }
2680
2681 if (size && (index >= size || index < 0))
2682 {
2683 if (error_ptr)
2684 error_ptr->SetErrorStringWithFormat("Out of bounds array access. %lld is not in [0, %llu]", index, size);
2685 return false;
2686 }
2687
Greg Clayton960d6a42010-08-03 00:35:52 +00002688 uint64_t member_bit_size = ClangASTType::GetClangTypeBitWidth(ast_context, member_type);
2689 uint64_t member_bit_align = ClangASTType::GetTypeBitAlign(ast_context, member_type);
Chris Lattner24943d22010-06-08 16:52:24 +00002690 uint64_t member_bit_incr = ((member_bit_size + member_bit_align - 1) / member_bit_align) * member_bit_align;
2691 if (member_bit_incr % 8)
2692 {
2693 if (error_ptr)
Jason Molenda95b7b432011-09-20 00:26:08 +00002694 error_ptr->SetErrorStringWithFormat("Array increment is not byte aligned");
Chris Lattner24943d22010-06-08 16:52:24 +00002695 return false;
2696 }
2697 int64_t member_offset = (int64_t)(member_bit_incr / 8) * index;
2698
2699 Value member;
2700
Greg Clayton6916e352010-11-13 03:52:47 +00002701 member.SetContext(Value::eContextTypeClangType, member_type);
Chris Lattner24943d22010-06-08 16:52:24 +00002702 member.SetValueType(array_val.GetValueType());
2703
2704 addr_t array_base = (addr_t)array_val.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
2705 addr_t member_loc = array_base + member_offset;
2706 member.GetScalar() = (uint64_t)member_loc;
2707
2708 stack.push_back(member);
2709 }
Greg Claytona1b9a902011-11-13 04:15:56 +00002710 break;
Chris Lattner24943d22010-06-08 16:52:24 +00002711
2712 //----------------------------------------------------------------------
2713 // OPCODE: DW_OP_APPLE_uninit
2714 // OPERANDS: none
2715 // DESCRIPTION: Lets us know that the value is currently not initialized
2716 //----------------------------------------------------------------------
2717 case DW_OP_APPLE_uninit:
2718 //return eResultTypeErrorUninitialized;
2719 break; // Ignore this as we have seen cases where this value is incorrectly added
2720
2721 //----------------------------------------------------------------------
2722 // OPCODE: DW_OP_APPLE_assign
2723 // OPERANDS: none
2724 // DESCRIPTION: Pops a value off of the stack and assigns it to the next
2725 // item on the stack which must be something assignable (inferior
2726 // Variable, inferior Type with address, inferior register, or
2727 // expression local variable.
2728 //----------------------------------------------------------------------
2729 case DW_OP_APPLE_assign:
2730 if (stack.size() < 2)
2731 {
2732 if (error_ptr)
2733 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_APPLE_assign.");
2734 return false;
2735 }
2736 else
2737 {
2738 tmp = stack.back();
2739 stack.pop_back();
2740 Value::ContextType context_type = stack.back().GetContextType();
Greg Claytoncd548032011-02-01 01:31:41 +00002741 StreamString new_value(Stream::eBinary, 4, lldb::endian::InlHostByteOrder());
Chris Lattner24943d22010-06-08 16:52:24 +00002742 switch (context_type)
2743 {
Greg Clayton6916e352010-11-13 03:52:47 +00002744 case Value::eContextTypeClangType:
Chris Lattner24943d22010-06-08 16:52:24 +00002745 {
Greg Clayton462d4142010-09-29 01:12:09 +00002746 void *clang_type = stack.back().GetClangType();
Chris Lattner24943d22010-06-08 16:52:24 +00002747
2748 if (ClangASTContext::IsAggregateType (clang_type))
2749 {
2750 Value::ValueType source_value_type = tmp.GetValueType();
2751 Value::ValueType target_value_type = stack.back().GetValueType();
2752
2753 addr_t source_addr = (addr_t)tmp.GetScalar().ULongLong();
2754 addr_t target_addr = (addr_t)stack.back().GetScalar().ULongLong();
2755
Greg Clayton960d6a42010-08-03 00:35:52 +00002756 size_t byte_size = (ClangASTType::GetClangTypeBitWidth(ast_context, clang_type) + 7) / 8;
Chris Lattner24943d22010-06-08 16:52:24 +00002757
2758 switch (source_value_type)
2759 {
Greg Clayton4fdf7602011-03-20 04:57:14 +00002760 case Value::eValueTypeScalar:
2761 case Value::eValueTypeFileAddress:
2762 break;
2763
Chris Lattner24943d22010-06-08 16:52:24 +00002764 case Value::eValueTypeLoadAddress:
2765 switch (target_value_type)
2766 {
2767 case Value::eValueTypeLoadAddress:
2768 {
2769 DataBufferHeap data;
2770 data.SetByteSize(byte_size);
2771
2772 Error error;
Greg Clayton567e7f32011-09-22 04:58:26 +00002773 if (process->ReadMemory (source_addr, data.GetBytes(), byte_size, error) != byte_size)
Chris Lattner24943d22010-06-08 16:52:24 +00002774 {
2775 if (error_ptr)
2776 error_ptr->SetErrorStringWithFormat ("Couldn't read a composite type from the target: %s", error.AsCString());
2777 return false;
2778 }
2779
Greg Clayton567e7f32011-09-22 04:58:26 +00002780 if (process->WriteMemory (target_addr, data.GetBytes(), byte_size, error) != byte_size)
Chris Lattner24943d22010-06-08 16:52:24 +00002781 {
2782 if (error_ptr)
2783 error_ptr->SetErrorStringWithFormat ("Couldn't write a composite type to the target: %s", error.AsCString());
2784 return false;
2785 }
2786 }
2787 break;
2788 case Value::eValueTypeHostAddress:
Greg Clayton567e7f32011-09-22 04:58:26 +00002789 if (process->GetByteOrder() != lldb::endian::InlHostByteOrder())
Chris Lattner24943d22010-06-08 16:52:24 +00002790 {
2791 if (error_ptr)
2792 error_ptr->SetErrorStringWithFormat ("Copy of composite types between incompatible byte orders is unimplemented");
2793 return false;
2794 }
2795 else
2796 {
2797 Error error;
Greg Clayton567e7f32011-09-22 04:58:26 +00002798 if (process->ReadMemory (source_addr, (uint8_t*)target_addr, byte_size, error) != byte_size)
Chris Lattner24943d22010-06-08 16:52:24 +00002799 {
2800 if (error_ptr)
2801 error_ptr->SetErrorStringWithFormat ("Couldn't read a composite type from the target: %s", error.AsCString());
2802 return false;
2803 }
2804 }
2805 break;
2806 default:
2807 return false;
2808 }
2809 break;
2810 case Value::eValueTypeHostAddress:
2811 switch (target_value_type)
2812 {
2813 case Value::eValueTypeLoadAddress:
Greg Clayton567e7f32011-09-22 04:58:26 +00002814 if (process->GetByteOrder() != lldb::endian::InlHostByteOrder())
Chris Lattner24943d22010-06-08 16:52:24 +00002815 {
2816 if (error_ptr)
2817 error_ptr->SetErrorStringWithFormat ("Copy of composite types between incompatible byte orders is unimplemented");
2818 return false;
2819 }
2820 else
2821 {
2822 Error error;
Greg Clayton567e7f32011-09-22 04:58:26 +00002823 if (process->WriteMemory (target_addr, (uint8_t*)source_addr, byte_size, error) != byte_size)
Chris Lattner24943d22010-06-08 16:52:24 +00002824 {
2825 if (error_ptr)
2826 error_ptr->SetErrorStringWithFormat ("Couldn't write a composite type to the target: %s", error.AsCString());
2827 return false;
2828 }
2829 }
2830 case Value::eValueTypeHostAddress:
2831 memcpy ((uint8_t*)target_addr, (uint8_t*)source_addr, byte_size);
2832 break;
2833 default:
2834 return false;
2835 }
2836 }
2837 }
2838 else
2839 {
Greg Clayton1674b122010-07-21 22:12:05 +00002840 if (!ClangASTType::SetValueFromScalar (ast_context,
2841 clang_type,
2842 tmp.ResolveValue(exe_ctx, ast_context),
2843 new_value))
Chris Lattner24943d22010-06-08 16:52:24 +00002844 {
2845 if (error_ptr)
2846 error_ptr->SetErrorStringWithFormat ("Couldn't extract a value from an integral type.\n");
2847 return false;
2848 }
2849
2850 Value::ValueType value_type = stack.back().GetValueType();
2851
2852 switch (value_type)
2853 {
2854 case Value::eValueTypeLoadAddress:
2855 case Value::eValueTypeHostAddress:
2856 {
Greg Claytonb3448432011-03-24 21:19:54 +00002857 AddressType address_type = (value_type == Value::eValueTypeLoadAddress ? eAddressTypeLoad : eAddressTypeHost);
Chris Lattner24943d22010-06-08 16:52:24 +00002858 lldb::addr_t addr = stack.back().GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton1674b122010-07-21 22:12:05 +00002859 if (!ClangASTType::WriteToMemory (ast_context,
2860 clang_type,
2861 exe_ctx,
2862 addr,
2863 address_type,
2864 new_value))
Chris Lattner24943d22010-06-08 16:52:24 +00002865 {
2866 if (error_ptr)
2867 error_ptr->SetErrorStringWithFormat ("Failed to write value to memory at 0x%llx.\n", addr);
2868 return false;
2869 }
2870 }
2871 break;
2872
2873 default:
2874 break;
2875 }
2876 }
2877 }
2878 break;
2879
2880 default:
2881 if (error_ptr)
2882 error_ptr->SetErrorString ("Assign failed.");
2883 return false;
2884 }
2885 }
2886 break;
2887
2888 //----------------------------------------------------------------------
2889 // OPCODE: DW_OP_APPLE_address_of
2890 // OPERANDS: none
2891 // DESCRIPTION: Pops a value off of the stack and pushed its address.
2892 // The top item on the stack must be a variable, or already be a memory
2893 // location.
2894 //----------------------------------------------------------------------
2895 case DW_OP_APPLE_address_of:
2896 if (stack.empty())
2897 {
2898 if (error_ptr)
2899 error_ptr->SetErrorString("Expression stack needs at least 1 item for DW_OP_APPLE_address_of.");
2900 return false;
2901 }
2902 else
2903 {
2904 Value::ValueType value_type = stack.back().GetValueType();
2905 switch (value_type)
2906 {
2907 default:
2908 case Value::eValueTypeScalar: // raw scalar value
2909 if (error_ptr)
2910 error_ptr->SetErrorString("Top stack item isn't a memory based object.");
2911 return false;
2912
2913 case Value::eValueTypeLoadAddress: // load address value
2914 case Value::eValueTypeFileAddress: // file address value
2915 case Value::eValueTypeHostAddress: // host address value (for memory in the process that is using liblldb)
2916 // Taking the address of an object reduces it to the address
2917 // of the value and removes any extra context it had.
2918 //stack.back().SetValueType(Value::eValueTypeScalar);
2919 stack.back().ClearContext();
2920 break;
2921 }
2922 }
2923 break;
2924
2925 //----------------------------------------------------------------------
2926 // OPCODE: DW_OP_APPLE_value_of
2927 // OPERANDS: none
2928 // DESCRIPTION: Pops a value off of the stack and pushed its value.
2929 // The top item on the stack must be a variable, expression variable.
2930 //----------------------------------------------------------------------
2931 case DW_OP_APPLE_value_of:
2932 if (stack.empty())
2933 {
2934 if (error_ptr)
2935 error_ptr->SetErrorString("Expression stack needs at least 1 items for DW_OP_APPLE_value_of.");
2936 return false;
2937 }
2938 else if (!stack.back().ValueOf(exe_ctx, ast_context))
2939 {
2940 if (error_ptr)
2941 error_ptr->SetErrorString ("Top stack item isn't a valid candidate for DW_OP_APPLE_value_of.");
2942 return false;
2943 }
2944 break;
2945
2946 //----------------------------------------------------------------------
2947 // OPCODE: DW_OP_APPLE_deref_type
2948 // OPERANDS: none
2949 // DESCRIPTION: gets the value pointed to by the top stack item
2950 //----------------------------------------------------------------------
2951 case DW_OP_APPLE_deref_type:
2952 {
2953 if (stack.empty())
2954 {
2955 if (error_ptr)
2956 error_ptr->SetErrorString("Expression stack needs at least 1 items for DW_OP_APPLE_deref_type.");
2957 return false;
2958 }
2959
2960 tmp = stack.back();
2961 stack.pop_back();
2962
Greg Clayton6916e352010-11-13 03:52:47 +00002963 if (tmp.GetContextType() != Value::eContextTypeClangType)
Chris Lattner24943d22010-06-08 16:52:24 +00002964 {
2965 if (error_ptr)
2966 error_ptr->SetErrorString("Item at top of expression stack must have a Clang type");
2967 return false;
2968 }
2969
Greg Clayton462d4142010-09-29 01:12:09 +00002970 void *ptr_type = tmp.GetClangType();
Chris Lattner24943d22010-06-08 16:52:24 +00002971 void *target_type;
2972
2973 if (!ClangASTContext::IsPointerType(ptr_type, &target_type))
2974 {
2975 if (error_ptr)
2976 error_ptr->SetErrorString("Dereferencing a non-pointer type");
2977 return false;
2978 }
2979
2980 // TODO do we want all pointers to be dereferenced as load addresses?
2981 Value::ValueType value_type = tmp.GetValueType();
2982
2983 tmp.ResolveValue(exe_ctx, ast_context);
2984
2985 tmp.SetValueType(value_type);
Greg Clayton6916e352010-11-13 03:52:47 +00002986 tmp.SetContext(Value::eContextTypeClangType, target_type);
Chris Lattner24943d22010-06-08 16:52:24 +00002987
2988 stack.push_back(tmp);
2989 }
2990 break;
2991
2992 //----------------------------------------------------------------------
2993 // OPCODE: DW_OP_APPLE_expr_local
2994 // OPERANDS: ULEB128
2995 // DESCRIPTION: pushes the expression local variable index onto the
2996 // stack and set the appropriate context so we know the stack item is
2997 // an expression local variable index.
2998 //----------------------------------------------------------------------
2999 case DW_OP_APPLE_expr_local:
3000 {
Sean Callanana6223432010-08-20 01:02:30 +00003001 /*
Chris Lattner24943d22010-06-08 16:52:24 +00003002 uint32_t idx = opcodes.GetULEB128(&offset);
3003 if (expr_locals == NULL)
3004 {
3005 if (error_ptr)
3006 error_ptr->SetErrorStringWithFormat ("DW_OP_APPLE_expr_local(%u) opcode encountered with no local variable list.\n", idx);
3007 return false;
3008 }
3009 Value *expr_local_variable = expr_locals->GetVariableAtIndex(idx);
3010 if (expr_local_variable == NULL)
3011 {
3012 if (error_ptr)
3013 error_ptr->SetErrorStringWithFormat ("DW_OP_APPLE_expr_local(%u) with invalid index %u.\n", idx, idx);
3014 return false;
3015 }
Greg Clayton801417e2011-07-07 01:59:51 +00003016 // The proxy code has been removed. If it is ever re-added, please
3017 // use shared pointers or return by value to avoid possible memory
3018 // leak (there is no leak here, but in general, no returning pointers
3019 // that must be manually freed please.
Chris Lattner24943d22010-06-08 16:52:24 +00003020 Value *proxy = expr_local_variable->CreateProxy();
3021 stack.push_back(*proxy);
3022 delete proxy;
Greg Clayton6916e352010-11-13 03:52:47 +00003023 //stack.back().SetContext (Value::eContextTypeClangType, expr_local_variable->GetClangType());
Sean Callanana6223432010-08-20 01:02:30 +00003024 */
Chris Lattner24943d22010-06-08 16:52:24 +00003025 }
3026 break;
3027
3028 //----------------------------------------------------------------------
3029 // OPCODE: DW_OP_APPLE_extern
3030 // OPERANDS: ULEB128
3031 // DESCRIPTION: pushes a proxy for the extern object index onto the
3032 // stack.
3033 //----------------------------------------------------------------------
3034 case DW_OP_APPLE_extern:
3035 {
Sean Callanan8c127202010-08-23 23:09:38 +00003036 /*
Chris Lattner24943d22010-06-08 16:52:24 +00003037 uint32_t idx = opcodes.GetULEB128(&offset);
3038 if (!decl_map)
3039 {
3040 if (error_ptr)
3041 error_ptr->SetErrorStringWithFormat ("DW_OP_APPLE_extern(%u) opcode encountered with no decl map.\n", idx);
3042 return false;
3043 }
3044 Value *extern_var = decl_map->GetValueForIndex(idx);
3045 if (!extern_var)
3046 {
3047 if (error_ptr)
3048 error_ptr->SetErrorStringWithFormat ("DW_OP_APPLE_extern(%u) with invalid index %u.\n", idx, idx);
3049 return false;
3050 }
Greg Clayton801417e2011-07-07 01:59:51 +00003051 // The proxy code has been removed. If it is ever re-added, please
3052 // use shared pointers or return by value to avoid possible memory
3053 // leak (there is no leak here, but in general, no returning pointers
3054 // that must be manually freed please.
Chris Lattner24943d22010-06-08 16:52:24 +00003055 Value *proxy = extern_var->CreateProxy();
3056 stack.push_back(*proxy);
3057 delete proxy;
Sean Callanan8c127202010-08-23 23:09:38 +00003058 */
Chris Lattner24943d22010-06-08 16:52:24 +00003059 }
3060 break;
3061
3062 case DW_OP_APPLE_scalar_cast:
3063 if (stack.empty())
3064 {
3065 if (error_ptr)
3066 error_ptr->SetErrorString("Expression stack needs at least 1 item for DW_OP_APPLE_scalar_cast.");
3067 return false;
3068 }
3069 else
3070 {
3071 // Simple scalar cast
3072 if (!stack.back().ResolveValue(exe_ctx, ast_context).Cast((Scalar::Type)opcodes.GetU8(&offset)))
3073 {
3074 if (error_ptr)
3075 error_ptr->SetErrorString("Cast failed.");
3076 return false;
3077 }
3078 }
3079 break;
3080
3081
3082 case DW_OP_APPLE_clang_cast:
3083 if (stack.empty())
3084 {
3085 if (error_ptr)
3086 error_ptr->SetErrorString("Expression stack needs at least 1 item for DW_OP_APPLE_clang_cast.");
3087 return false;
3088 }
3089 else
3090 {
3091 void *clang_type = (void *)opcodes.GetMaxU64(&offset, sizeof(void*));
Greg Clayton6916e352010-11-13 03:52:47 +00003092 stack.back().SetContext (Value::eContextTypeClangType, clang_type);
Chris Lattner24943d22010-06-08 16:52:24 +00003093 }
3094 break;
3095 //----------------------------------------------------------------------
3096 // OPCODE: DW_OP_APPLE_constf
3097 // OPERANDS: 1 byte float length, followed by that many bytes containing
3098 // the constant float data.
3099 // DESCRIPTION: Push a float value onto the expression stack.
3100 //----------------------------------------------------------------------
3101 case DW_OP_APPLE_constf: // 0xF6 - 1 byte float size, followed by constant float data
3102 {
3103 uint8_t float_length = opcodes.GetU8(&offset);
3104 if (sizeof(float) == float_length)
3105 tmp.ResolveValue(exe_ctx, ast_context) = opcodes.GetFloat (&offset);
3106 else if (sizeof(double) == float_length)
3107 tmp.ResolveValue(exe_ctx, ast_context) = opcodes.GetDouble (&offset);
3108 else if (sizeof(long double) == float_length)
3109 tmp.ResolveValue(exe_ctx, ast_context) = opcodes.GetLongDouble (&offset);
3110 else
3111 {
3112 StreamString new_value;
3113 opcodes.Dump(&new_value, offset, eFormatBytes, 1, float_length, UINT32_MAX, DW_INVALID_ADDRESS, 0, 0);
3114
3115 if (error_ptr)
3116 error_ptr->SetErrorStringWithFormat ("DW_OP_APPLE_constf(<%u> %s) unsupported float size.\n", float_length, new_value.GetData());
3117 return false;
3118 }
3119 tmp.SetValueType(Value::eValueTypeScalar);
3120 tmp.ClearContext();
3121 stack.push_back(tmp);
3122 }
3123 break;
3124 //----------------------------------------------------------------------
3125 // OPCODE: DW_OP_APPLE_clear
3126 // OPERANDS: none
3127 // DESCRIPTION: Clears the expression stack.
3128 //----------------------------------------------------------------------
3129 case DW_OP_APPLE_clear:
3130 stack.clear();
3131 break;
3132
3133 //----------------------------------------------------------------------
3134 // OPCODE: DW_OP_APPLE_error
3135 // OPERANDS: none
3136 // DESCRIPTION: Pops a value off of the stack and pushed its value.
3137 // The top item on the stack must be a variable, expression variable.
3138 //----------------------------------------------------------------------
3139 case DW_OP_APPLE_error: // 0xFF - Stops expression evaluation and returns an error (no args)
3140 if (error_ptr)
3141 error_ptr->SetErrorString ("Generic error.");
3142 return false;
Greg Claytona1b9a902011-11-13 04:15:56 +00003143#endif // #if 0
3144
Chris Lattner24943d22010-06-08 16:52:24 +00003145 }
3146 }
3147
3148 if (stack.empty())
3149 {
3150 if (error_ptr)
3151 error_ptr->SetErrorString ("Stack empty after evaluation.");
3152 return false;
3153 }
Sean Callanan67bbb112011-10-14 20:34:21 +00003154 else if (log && log->GetVerbose())
Chris Lattner24943d22010-06-08 16:52:24 +00003155 {
Chris Lattner24943d22010-06-08 16:52:24 +00003156 size_t count = stack.size();
Jason Molenda7e5fa7f2011-09-20 21:44:10 +00003157 log->Printf("Stack after operation has %lu values:", count);
Chris Lattner24943d22010-06-08 16:52:24 +00003158 for (size_t i=0; i<count; ++i)
3159 {
3160 StreamString new_value;
3161 new_value.Printf("[%zu]", i);
3162 stack[i].Dump(&new_value);
Sean Callanan6184dfe2010-06-23 00:47:48 +00003163 log->Printf(" %s", new_value.GetData());
Chris Lattner24943d22010-06-08 16:52:24 +00003164 }
3165 }
3166
3167 result = stack.back();
3168 return true; // Return true on success
3169}
3170