blob: e3e3bb35367465a6af1160e96e21640581b68ad7 [file] [log] [blame]
Chris Lattner30fdc8d2010-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
Virgile Bellobdae3782013-08-28 12:14:27 +000012// C Includes
13#include <inttypes.h>
14
15// C++ Includes
Chris Lattner30fdc8d2010-06-08 16:52:24 +000016#include <vector>
17
Greg Clayton2fc93ea2011-11-13 04:15:56 +000018#include "lldb/Core/DataEncoder.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019#include "lldb/Core/dwarf.h"
20#include "lldb/Core/Log.h"
Greg Clayton7349bd92011-05-09 20:18:18 +000021#include "lldb/Core/RegisterValue.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000022#include "lldb/Core/StreamString.h"
23#include "lldb/Core/Scalar.h"
24#include "lldb/Core/Value.h"
Greg Clayton016a95e2010-09-14 02:20:48 +000025#include "lldb/Core/VMRange.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000026
27#include "lldb/Expression/ClangExpressionDeclMap.h"
28#include "lldb/Expression/ClangExpressionVariable.h"
29
Greg Clayton7fb56d02011-02-01 01:31:41 +000030#include "lldb/Host/Endian.h"
Jim Inghamf220d592011-12-01 03:01:30 +000031#include "lldb/Host/Host.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000032
33#include "lldb/lldb-private-log.h"
34
Greg Claytonafacd142011-09-02 01:15:17 +000035#include "lldb/Target/ABI.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000036#include "lldb/Target/ExecutionContext.h"
37#include "lldb/Target/Process.h"
38#include "lldb/Target/RegisterContext.h"
Jason Molendab57e4a12013-11-04 09:33:30 +000039#include "lldb/Target/StackFrame.h"
Ashok Thirumurthi6e264d32013-07-29 16:05:11 +000040#include "lldb/Target/StackID.h"
Richard Mitton0a558352013-10-17 21:14:00 +000041#include "lldb/Target/Thread.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000042
43using namespace lldb;
44using namespace lldb_private;
45
Richard Mitton0a558352013-10-17 21:14:00 +000046// TODO- why is this also defined (in a better way) in DWARFDefines.cpp?
Chris Lattner30fdc8d2010-06-08 16:52:24 +000047const char *
48DW_OP_value_to_name (uint32_t val)
49{
50 static char invalid[100];
51 switch (val) {
52 case 0x03: return "DW_OP_addr";
53 case 0x06: return "DW_OP_deref";
54 case 0x08: return "DW_OP_const1u";
55 case 0x09: return "DW_OP_const1s";
56 case 0x0a: return "DW_OP_const2u";
57 case 0x0b: return "DW_OP_const2s";
58 case 0x0c: return "DW_OP_const4u";
59 case 0x0d: return "DW_OP_const4s";
60 case 0x0e: return "DW_OP_const8u";
61 case 0x0f: return "DW_OP_const8s";
62 case 0x10: return "DW_OP_constu";
63 case 0x11: return "DW_OP_consts";
64 case 0x12: return "DW_OP_dup";
65 case 0x13: return "DW_OP_drop";
66 case 0x14: return "DW_OP_over";
67 case 0x15: return "DW_OP_pick";
68 case 0x16: return "DW_OP_swap";
69 case 0x17: return "DW_OP_rot";
70 case 0x18: return "DW_OP_xderef";
71 case 0x19: return "DW_OP_abs";
72 case 0x1a: return "DW_OP_and";
73 case 0x1b: return "DW_OP_div";
74 case 0x1c: return "DW_OP_minus";
75 case 0x1d: return "DW_OP_mod";
76 case 0x1e: return "DW_OP_mul";
77 case 0x1f: return "DW_OP_neg";
78 case 0x20: return "DW_OP_not";
79 case 0x21: return "DW_OP_or";
80 case 0x22: return "DW_OP_plus";
81 case 0x23: return "DW_OP_plus_uconst";
82 case 0x24: return "DW_OP_shl";
83 case 0x25: return "DW_OP_shr";
84 case 0x26: return "DW_OP_shra";
85 case 0x27: return "DW_OP_xor";
86 case 0x2f: return "DW_OP_skip";
87 case 0x28: return "DW_OP_bra";
88 case 0x29: return "DW_OP_eq";
89 case 0x2a: return "DW_OP_ge";
90 case 0x2b: return "DW_OP_gt";
91 case 0x2c: return "DW_OP_le";
92 case 0x2d: return "DW_OP_lt";
93 case 0x2e: return "DW_OP_ne";
94 case 0x30: return "DW_OP_lit0";
95 case 0x31: return "DW_OP_lit1";
96 case 0x32: return "DW_OP_lit2";
97 case 0x33: return "DW_OP_lit3";
98 case 0x34: return "DW_OP_lit4";
99 case 0x35: return "DW_OP_lit5";
100 case 0x36: return "DW_OP_lit6";
101 case 0x37: return "DW_OP_lit7";
102 case 0x38: return "DW_OP_lit8";
103 case 0x39: return "DW_OP_lit9";
104 case 0x3a: return "DW_OP_lit10";
105 case 0x3b: return "DW_OP_lit11";
106 case 0x3c: return "DW_OP_lit12";
107 case 0x3d: return "DW_OP_lit13";
108 case 0x3e: return "DW_OP_lit14";
109 case 0x3f: return "DW_OP_lit15";
110 case 0x40: return "DW_OP_lit16";
111 case 0x41: return "DW_OP_lit17";
112 case 0x42: return "DW_OP_lit18";
113 case 0x43: return "DW_OP_lit19";
114 case 0x44: return "DW_OP_lit20";
115 case 0x45: return "DW_OP_lit21";
116 case 0x46: return "DW_OP_lit22";
117 case 0x47: return "DW_OP_lit23";
118 case 0x48: return "DW_OP_lit24";
119 case 0x49: return "DW_OP_lit25";
120 case 0x4a: return "DW_OP_lit26";
121 case 0x4b: return "DW_OP_lit27";
122 case 0x4c: return "DW_OP_lit28";
123 case 0x4d: return "DW_OP_lit29";
124 case 0x4e: return "DW_OP_lit30";
125 case 0x4f: return "DW_OP_lit31";
126 case 0x50: return "DW_OP_reg0";
127 case 0x51: return "DW_OP_reg1";
128 case 0x52: return "DW_OP_reg2";
129 case 0x53: return "DW_OP_reg3";
130 case 0x54: return "DW_OP_reg4";
131 case 0x55: return "DW_OP_reg5";
132 case 0x56: return "DW_OP_reg6";
133 case 0x57: return "DW_OP_reg7";
134 case 0x58: return "DW_OP_reg8";
135 case 0x59: return "DW_OP_reg9";
136 case 0x5a: return "DW_OP_reg10";
137 case 0x5b: return "DW_OP_reg11";
138 case 0x5c: return "DW_OP_reg12";
139 case 0x5d: return "DW_OP_reg13";
140 case 0x5e: return "DW_OP_reg14";
141 case 0x5f: return "DW_OP_reg15";
142 case 0x60: return "DW_OP_reg16";
143 case 0x61: return "DW_OP_reg17";
144 case 0x62: return "DW_OP_reg18";
145 case 0x63: return "DW_OP_reg19";
146 case 0x64: return "DW_OP_reg20";
147 case 0x65: return "DW_OP_reg21";
148 case 0x66: return "DW_OP_reg22";
149 case 0x67: return "DW_OP_reg23";
150 case 0x68: return "DW_OP_reg24";
151 case 0x69: return "DW_OP_reg25";
152 case 0x6a: return "DW_OP_reg26";
153 case 0x6b: return "DW_OP_reg27";
154 case 0x6c: return "DW_OP_reg28";
155 case 0x6d: return "DW_OP_reg29";
156 case 0x6e: return "DW_OP_reg30";
157 case 0x6f: return "DW_OP_reg31";
158 case 0x70: return "DW_OP_breg0";
159 case 0x71: return "DW_OP_breg1";
160 case 0x72: return "DW_OP_breg2";
161 case 0x73: return "DW_OP_breg3";
162 case 0x74: return "DW_OP_breg4";
163 case 0x75: return "DW_OP_breg5";
164 case 0x76: return "DW_OP_breg6";
165 case 0x77: return "DW_OP_breg7";
166 case 0x78: return "DW_OP_breg8";
167 case 0x79: return "DW_OP_breg9";
168 case 0x7a: return "DW_OP_breg10";
169 case 0x7b: return "DW_OP_breg11";
170 case 0x7c: return "DW_OP_breg12";
171 case 0x7d: return "DW_OP_breg13";
172 case 0x7e: return "DW_OP_breg14";
173 case 0x7f: return "DW_OP_breg15";
174 case 0x80: return "DW_OP_breg16";
175 case 0x81: return "DW_OP_breg17";
176 case 0x82: return "DW_OP_breg18";
177 case 0x83: return "DW_OP_breg19";
178 case 0x84: return "DW_OP_breg20";
179 case 0x85: return "DW_OP_breg21";
180 case 0x86: return "DW_OP_breg22";
181 case 0x87: return "DW_OP_breg23";
182 case 0x88: return "DW_OP_breg24";
183 case 0x89: return "DW_OP_breg25";
184 case 0x8a: return "DW_OP_breg26";
185 case 0x8b: return "DW_OP_breg27";
186 case 0x8c: return "DW_OP_breg28";
187 case 0x8d: return "DW_OP_breg29";
188 case 0x8e: return "DW_OP_breg30";
189 case 0x8f: return "DW_OP_breg31";
190 case 0x90: return "DW_OP_regx";
191 case 0x91: return "DW_OP_fbreg";
192 case 0x92: return "DW_OP_bregx";
193 case 0x93: return "DW_OP_piece";
194 case 0x94: return "DW_OP_deref_size";
195 case 0x95: return "DW_OP_xderef_size";
196 case 0x96: return "DW_OP_nop";
197 case 0x97: return "DW_OP_push_object_address";
198 case 0x98: return "DW_OP_call2";
199 case 0x99: return "DW_OP_call4";
200 case 0x9a: return "DW_OP_call_ref";
Greg Clayton2fc93ea2011-11-13 04:15:56 +0000201// case DW_OP_APPLE_array_ref: return "DW_OP_APPLE_array_ref";
202// case DW_OP_APPLE_extern: return "DW_OP_APPLE_extern";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000203 case DW_OP_APPLE_uninit: return "DW_OP_APPLE_uninit";
Greg Clayton2fc93ea2011-11-13 04:15:56 +0000204// case DW_OP_APPLE_assign: return "DW_OP_APPLE_assign";
205// case DW_OP_APPLE_address_of: return "DW_OP_APPLE_address_of";
206// case DW_OP_APPLE_value_of: return "DW_OP_APPLE_value_of";
207// case DW_OP_APPLE_deref_type: return "DW_OP_APPLE_deref_type";
208// case DW_OP_APPLE_expr_local: return "DW_OP_APPLE_expr_local";
209// case DW_OP_APPLE_constf: return "DW_OP_APPLE_constf";
210// case DW_OP_APPLE_scalar_cast: return "DW_OP_APPLE_scalar_cast";
211// case DW_OP_APPLE_clang_cast: return "DW_OP_APPLE_clang_cast";
212// case DW_OP_APPLE_clear: return "DW_OP_APPLE_clear";
213// case DW_OP_APPLE_error: return "DW_OP_APPLE_error";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000214 default:
215 snprintf (invalid, sizeof(invalid), "Unknown DW_OP constant: 0x%x", val);
216 return invalid;
217 }
218}
219
220
221//----------------------------------------------------------------------
222// DWARFExpression constructor
223//----------------------------------------------------------------------
224DWARFExpression::DWARFExpression() :
Richard Mitton0a558352013-10-17 21:14:00 +0000225 m_module_wp(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000226 m_data(),
227 m_reg_kind (eRegisterKindDWARF),
Greg Clayton1a65ae12011-01-25 23:55:37 +0000228 m_loclist_slide (LLDB_INVALID_ADDRESS)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000229{
230}
231
232DWARFExpression::DWARFExpression(const DWARFExpression& rhs) :
Richard Mitton0a558352013-10-17 21:14:00 +0000233 m_module_wp(rhs.m_module_wp),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000234 m_data(rhs.m_data),
235 m_reg_kind (rhs.m_reg_kind),
Greg Clayton1a65ae12011-01-25 23:55:37 +0000236 m_loclist_slide(rhs.m_loclist_slide)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000237{
238}
239
240
Richard Mitton0a558352013-10-17 21:14:00 +0000241DWARFExpression::DWARFExpression(lldb::ModuleSP module_sp, const DataExtractor& data, lldb::offset_t data_offset, lldb::offset_t data_length) :
242 m_module_wp(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000243 m_data(data, data_offset, data_length),
244 m_reg_kind (eRegisterKindDWARF),
Greg Clayton1a65ae12011-01-25 23:55:37 +0000245 m_loclist_slide(LLDB_INVALID_ADDRESS)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000246{
Richard Mitton0a558352013-10-17 21:14:00 +0000247 if (module_sp)
248 m_module_wp = module_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000249}
250
251//----------------------------------------------------------------------
252// Destructor
253//----------------------------------------------------------------------
254DWARFExpression::~DWARFExpression()
255{
256}
257
258
259bool
260DWARFExpression::IsValid() const
261{
262 return m_data.GetByteSize() > 0;
263}
264
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000265void
Greg Clayton016a95e2010-09-14 02:20:48 +0000266DWARFExpression::SetOpcodeData (const DataExtractor& data)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000267{
268 m_data = data;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000269}
270
271void
Richard Mitton0a558352013-10-17 21:14:00 +0000272DWARFExpression::CopyOpcodeData (lldb::ModuleSP module_sp, const DataExtractor& data, lldb::offset_t data_offset, lldb::offset_t data_length)
Greg Clayton8179bca2012-08-10 23:33:27 +0000273{
274 const uint8_t *bytes = data.PeekData(data_offset, data_length);
Greg Clayton7f4c7432012-08-11 00:49:14 +0000275 if (bytes)
276 {
Richard Mitton0a558352013-10-17 21:14:00 +0000277 m_module_wp = module_sp;
Greg Clayton7f4c7432012-08-11 00:49:14 +0000278 m_data.SetData(DataBufferSP(new DataBufferHeap(bytes, data_length)));
279 m_data.SetByteOrder(data.GetByteOrder());
280 m_data.SetAddressByteSize(data.GetAddressByteSize());
281 }
Greg Clayton8179bca2012-08-10 23:33:27 +0000282}
283
284void
Richard Mitton0a558352013-10-17 21:14:00 +0000285DWARFExpression::SetOpcodeData (lldb::ModuleSP module_sp, const DataExtractor& data, lldb::offset_t data_offset, lldb::offset_t data_length)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000286{
Richard Mitton0a558352013-10-17 21:14:00 +0000287 m_module_wp = module_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000288 m_data.SetData(data, data_offset, data_length);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000289}
290
291void
Greg Claytonc7bece562013-01-25 18:06:21 +0000292DWARFExpression::DumpLocation (Stream *s, lldb::offset_t offset, lldb::offset_t length, lldb::DescriptionLevel level, ABI *abi) const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000293{
294 if (!m_data.ValidOffsetForDataOfSize(offset, length))
295 return;
Greg Claytonc7bece562013-01-25 18:06:21 +0000296 const lldb::offset_t start_offset = offset;
297 const lldb::offset_t end_offset = offset + length;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000298 while (m_data.ValidOffset(offset) && offset < end_offset)
299 {
Greg Claytonc7bece562013-01-25 18:06:21 +0000300 const lldb::offset_t op_offset = offset;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000301 const uint8_t op = m_data.GetU8(&offset);
302
303 switch (level)
304 {
Greg Claytonc982c762010-07-09 20:39:50 +0000305 default:
306 break;
307
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000308 case lldb::eDescriptionLevelBrief:
309 if (offset > start_offset)
310 s->PutChar(' ');
311 break;
312
313 case lldb::eDescriptionLevelFull:
314 case lldb::eDescriptionLevelVerbose:
315 if (offset > start_offset)
316 s->EOL();
317 s->Indent();
318 if (level == lldb::eDescriptionLevelFull)
319 break;
320 // Fall through for verbose and print offset and DW_OP prefix..
Greg Claytonc7bece562013-01-25 18:06:21 +0000321 s->Printf("0x%8.8" PRIx64 ": %s", op_offset, op >= DW_OP_APPLE_uninit ? "DW_OP_APPLE_" : "DW_OP_");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000322 break;
323 }
324
325 switch (op)
326 {
Greg Claytonc749eb82011-07-11 05:12:02 +0000327 case DW_OP_addr: *s << "DW_OP_addr(" << m_data.GetAddress(&offset) << ") "; break; // 0x03 1 address
328 case DW_OP_deref: *s << "DW_OP_deref"; break; // 0x06
329 case DW_OP_const1u: s->Printf("DW_OP_const1u(0x%2.2x) ", m_data.GetU8(&offset)); break; // 0x08 1 1-byte constant
330 case DW_OP_const1s: s->Printf("DW_OP_const1s(0x%2.2x) ", m_data.GetU8(&offset)); break; // 0x09 1 1-byte constant
331 case DW_OP_const2u: s->Printf("DW_OP_const2u(0x%4.4x) ", m_data.GetU16(&offset)); break; // 0x0a 1 2-byte constant
332 case DW_OP_const2s: s->Printf("DW_OP_const2s(0x%4.4x) ", m_data.GetU16(&offset)); break; // 0x0b 1 2-byte constant
333 case DW_OP_const4u: s->Printf("DW_OP_const4u(0x%8.8x) ", m_data.GetU32(&offset)); break; // 0x0c 1 4-byte constant
334 case DW_OP_const4s: s->Printf("DW_OP_const4s(0x%8.8x) ", m_data.GetU32(&offset)); break; // 0x0d 1 4-byte constant
Daniel Malead01b2952012-11-29 21:49:15 +0000335 case DW_OP_const8u: s->Printf("DW_OP_const8u(0x%16.16" PRIx64 ") ", m_data.GetU64(&offset)); break; // 0x0e 1 8-byte constant
336 case DW_OP_const8s: s->Printf("DW_OP_const8s(0x%16.16" PRIx64 ") ", m_data.GetU64(&offset)); break; // 0x0f 1 8-byte constant
337 case DW_OP_constu: s->Printf("DW_OP_constu(0x%" PRIx64 ") ", m_data.GetULEB128(&offset)); break; // 0x10 1 ULEB128 constant
338 case DW_OP_consts: s->Printf("DW_OP_consts(0x%" PRId64 ") ", m_data.GetSLEB128(&offset)); break; // 0x11 1 SLEB128 constant
Greg Claytonc749eb82011-07-11 05:12:02 +0000339 case DW_OP_dup: s->PutCString("DW_OP_dup"); break; // 0x12
340 case DW_OP_drop: s->PutCString("DW_OP_drop"); break; // 0x13
341 case DW_OP_over: s->PutCString("DW_OP_over"); break; // 0x14
342 case DW_OP_pick: s->Printf("DW_OP_pick(0x%2.2x) ", m_data.GetU8(&offset)); break; // 0x15 1 1-byte stack index
343 case DW_OP_swap: s->PutCString("DW_OP_swap"); break; // 0x16
344 case DW_OP_rot: s->PutCString("DW_OP_rot"); break; // 0x17
345 case DW_OP_xderef: s->PutCString("DW_OP_xderef"); break; // 0x18
346 case DW_OP_abs: s->PutCString("DW_OP_abs"); break; // 0x19
347 case DW_OP_and: s->PutCString("DW_OP_and"); break; // 0x1a
348 case DW_OP_div: s->PutCString("DW_OP_div"); break; // 0x1b
349 case DW_OP_minus: s->PutCString("DW_OP_minus"); break; // 0x1c
350 case DW_OP_mod: s->PutCString("DW_OP_mod"); break; // 0x1d
351 case DW_OP_mul: s->PutCString("DW_OP_mul"); break; // 0x1e
352 case DW_OP_neg: s->PutCString("DW_OP_neg"); break; // 0x1f
353 case DW_OP_not: s->PutCString("DW_OP_not"); break; // 0x20
354 case DW_OP_or: s->PutCString("DW_OP_or"); break; // 0x21
355 case DW_OP_plus: s->PutCString("DW_OP_plus"); break; // 0x22
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000356 case DW_OP_plus_uconst: // 0x23 1 ULEB128 addend
Daniel Malead01b2952012-11-29 21:49:15 +0000357 s->Printf("DW_OP_plus_uconst(0x%" PRIx64 ") ", m_data.GetULEB128(&offset));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000358 break;
359
Greg Claytonc749eb82011-07-11 05:12:02 +0000360 case DW_OP_shl: s->PutCString("DW_OP_shl"); break; // 0x24
361 case DW_OP_shr: s->PutCString("DW_OP_shr"); break; // 0x25
362 case DW_OP_shra: s->PutCString("DW_OP_shra"); break; // 0x26
363 case DW_OP_xor: s->PutCString("DW_OP_xor"); break; // 0x27
364 case DW_OP_skip: s->Printf("DW_OP_skip(0x%4.4x)", m_data.GetU16(&offset)); break; // 0x2f 1 signed 2-byte constant
365 case DW_OP_bra: s->Printf("DW_OP_bra(0x%4.4x)", m_data.GetU16(&offset)); break; // 0x28 1 signed 2-byte constant
366 case DW_OP_eq: s->PutCString("DW_OP_eq"); break; // 0x29
367 case DW_OP_ge: s->PutCString("DW_OP_ge"); break; // 0x2a
368 case DW_OP_gt: s->PutCString("DW_OP_gt"); break; // 0x2b
369 case DW_OP_le: s->PutCString("DW_OP_le"); break; // 0x2c
370 case DW_OP_lt: s->PutCString("DW_OP_lt"); break; // 0x2d
371 case DW_OP_ne: s->PutCString("DW_OP_ne"); break; // 0x2e
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000372
373 case DW_OP_lit0: // 0x30
374 case DW_OP_lit1: // 0x31
375 case DW_OP_lit2: // 0x32
376 case DW_OP_lit3: // 0x33
377 case DW_OP_lit4: // 0x34
378 case DW_OP_lit5: // 0x35
379 case DW_OP_lit6: // 0x36
380 case DW_OP_lit7: // 0x37
381 case DW_OP_lit8: // 0x38
382 case DW_OP_lit9: // 0x39
383 case DW_OP_lit10: // 0x3A
384 case DW_OP_lit11: // 0x3B
385 case DW_OP_lit12: // 0x3C
386 case DW_OP_lit13: // 0x3D
387 case DW_OP_lit14: // 0x3E
388 case DW_OP_lit15: // 0x3F
389 case DW_OP_lit16: // 0x40
390 case DW_OP_lit17: // 0x41
391 case DW_OP_lit18: // 0x42
392 case DW_OP_lit19: // 0x43
393 case DW_OP_lit20: // 0x44
394 case DW_OP_lit21: // 0x45
395 case DW_OP_lit22: // 0x46
396 case DW_OP_lit23: // 0x47
397 case DW_OP_lit24: // 0x48
398 case DW_OP_lit25: // 0x49
399 case DW_OP_lit26: // 0x4A
400 case DW_OP_lit27: // 0x4B
401 case DW_OP_lit28: // 0x4C
402 case DW_OP_lit29: // 0x4D
403 case DW_OP_lit30: // 0x4E
Greg Claytonc749eb82011-07-11 05:12:02 +0000404 case DW_OP_lit31: s->Printf("DW_OP_lit%i", op - DW_OP_lit0); break; // 0x4f
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000405
406 case DW_OP_reg0: // 0x50
407 case DW_OP_reg1: // 0x51
408 case DW_OP_reg2: // 0x52
409 case DW_OP_reg3: // 0x53
410 case DW_OP_reg4: // 0x54
411 case DW_OP_reg5: // 0x55
412 case DW_OP_reg6: // 0x56
413 case DW_OP_reg7: // 0x57
414 case DW_OP_reg8: // 0x58
415 case DW_OP_reg9: // 0x59
416 case DW_OP_reg10: // 0x5A
417 case DW_OP_reg11: // 0x5B
418 case DW_OP_reg12: // 0x5C
419 case DW_OP_reg13: // 0x5D
420 case DW_OP_reg14: // 0x5E
421 case DW_OP_reg15: // 0x5F
422 case DW_OP_reg16: // 0x60
423 case DW_OP_reg17: // 0x61
424 case DW_OP_reg18: // 0x62
425 case DW_OP_reg19: // 0x63
426 case DW_OP_reg20: // 0x64
427 case DW_OP_reg21: // 0x65
428 case DW_OP_reg22: // 0x66
429 case DW_OP_reg23: // 0x67
430 case DW_OP_reg24: // 0x68
431 case DW_OP_reg25: // 0x69
432 case DW_OP_reg26: // 0x6A
433 case DW_OP_reg27: // 0x6B
434 case DW_OP_reg28: // 0x6C
435 case DW_OP_reg29: // 0x6D
436 case DW_OP_reg30: // 0x6E
Greg Claytonafacd142011-09-02 01:15:17 +0000437 case DW_OP_reg31: // 0x6F
438 {
439 uint32_t reg_num = op - DW_OP_reg0;
440 if (abi)
441 {
442 RegisterInfo reg_info;
443 if (abi->GetRegisterInfoByKind(m_reg_kind, reg_num, reg_info))
444 {
445 if (reg_info.name)
446 {
447 s->PutCString (reg_info.name);
448 break;
449 }
450 else if (reg_info.alt_name)
451 {
452 s->PutCString (reg_info.alt_name);
453 break;
454 }
455 }
456 }
457 s->Printf("DW_OP_reg%u", reg_num); break;
458 }
459 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000460
461 case DW_OP_breg0:
462 case DW_OP_breg1:
463 case DW_OP_breg2:
464 case DW_OP_breg3:
465 case DW_OP_breg4:
466 case DW_OP_breg5:
467 case DW_OP_breg6:
468 case DW_OP_breg7:
469 case DW_OP_breg8:
470 case DW_OP_breg9:
471 case DW_OP_breg10:
472 case DW_OP_breg11:
473 case DW_OP_breg12:
474 case DW_OP_breg13:
475 case DW_OP_breg14:
476 case DW_OP_breg15:
477 case DW_OP_breg16:
478 case DW_OP_breg17:
479 case DW_OP_breg18:
480 case DW_OP_breg19:
481 case DW_OP_breg20:
482 case DW_OP_breg21:
483 case DW_OP_breg22:
484 case DW_OP_breg23:
485 case DW_OP_breg24:
486 case DW_OP_breg25:
487 case DW_OP_breg26:
488 case DW_OP_breg27:
489 case DW_OP_breg28:
490 case DW_OP_breg29:
491 case DW_OP_breg30:
Greg Claytonafacd142011-09-02 01:15:17 +0000492 case DW_OP_breg31:
493 {
494 uint32_t reg_num = op - DW_OP_breg0;
495 int64_t reg_offset = m_data.GetSLEB128(&offset);
496 if (abi)
497 {
498 RegisterInfo reg_info;
499 if (abi->GetRegisterInfoByKind(m_reg_kind, reg_num, reg_info))
500 {
501 if (reg_info.name)
502 {
Daniel Malead01b2952012-11-29 21:49:15 +0000503 s->Printf("[%s%+" PRIi64 "]", reg_info.name, reg_offset);
Greg Claytonafacd142011-09-02 01:15:17 +0000504 break;
505 }
506 else if (reg_info.alt_name)
507 {
Daniel Malead01b2952012-11-29 21:49:15 +0000508 s->Printf("[%s%+" PRIi64 "]", reg_info.alt_name, reg_offset);
Greg Claytonafacd142011-09-02 01:15:17 +0000509 break;
510 }
511 }
512 }
Daniel Malead01b2952012-11-29 21:49:15 +0000513 s->Printf("DW_OP_breg%i(0x%" PRIx64 ")", reg_num, reg_offset);
Greg Claytonafacd142011-09-02 01:15:17 +0000514 }
515 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000516
517 case DW_OP_regx: // 0x90 1 ULEB128 register
Greg Claytonafacd142011-09-02 01:15:17 +0000518 {
Greg Claytonc7bece562013-01-25 18:06:21 +0000519 uint32_t reg_num = m_data.GetULEB128(&offset);
Greg Claytonafacd142011-09-02 01:15:17 +0000520 if (abi)
521 {
522 RegisterInfo reg_info;
523 if (abi->GetRegisterInfoByKind(m_reg_kind, reg_num, reg_info))
524 {
525 if (reg_info.name)
526 {
527 s->PutCString (reg_info.name);
528 break;
529 }
530 else if (reg_info.alt_name)
531 {
532 s->PutCString (reg_info.alt_name);
533 break;
534 }
535 }
536 }
Greg Claytonc7bece562013-01-25 18:06:21 +0000537 s->Printf("DW_OP_regx(%" PRIu32 ")", reg_num); break;
Greg Claytonafacd142011-09-02 01:15:17 +0000538 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000539 break;
540 case DW_OP_fbreg: // 0x91 1 SLEB128 offset
Daniel Malead01b2952012-11-29 21:49:15 +0000541 s->Printf("DW_OP_fbreg(%" PRIi64 ")",m_data.GetSLEB128(&offset));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000542 break;
543 case DW_OP_bregx: // 0x92 2 ULEB128 register followed by SLEB128 offset
Greg Claytonafacd142011-09-02 01:15:17 +0000544 {
545 uint32_t reg_num = m_data.GetULEB128(&offset);
546 int64_t reg_offset = m_data.GetSLEB128(&offset);
547 if (abi)
548 {
549 RegisterInfo reg_info;
550 if (abi->GetRegisterInfoByKind(m_reg_kind, reg_num, reg_info))
551 {
552 if (reg_info.name)
553 {
Daniel Malead01b2952012-11-29 21:49:15 +0000554 s->Printf("[%s%+" PRIi64 "]", reg_info.name, reg_offset);
Greg Claytonafacd142011-09-02 01:15:17 +0000555 break;
556 }
557 else if (reg_info.alt_name)
558 {
Daniel Malead01b2952012-11-29 21:49:15 +0000559 s->Printf("[%s%+" PRIi64 "]", reg_info.alt_name, reg_offset);
Greg Claytonafacd142011-09-02 01:15:17 +0000560 break;
561 }
562 }
563 }
Greg Claytonc7bece562013-01-25 18:06:21 +0000564 s->Printf("DW_OP_bregx(reg=%" PRIu32 ",offset=%" PRIi64 ")", reg_num, reg_offset);
Greg Claytonafacd142011-09-02 01:15:17 +0000565 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000566 break;
567 case DW_OP_piece: // 0x93 1 ULEB128 size of piece addressed
Daniel Malead01b2952012-11-29 21:49:15 +0000568 s->Printf("DW_OP_piece(0x%" PRIx64 ")", m_data.GetULEB128(&offset));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000569 break;
570 case DW_OP_deref_size: // 0x94 1 1-byte size of data retrieved
Greg Claytonc749eb82011-07-11 05:12:02 +0000571 s->Printf("DW_OP_deref_size(0x%2.2x)", m_data.GetU8(&offset));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000572 break;
573 case DW_OP_xderef_size: // 0x95 1 1-byte size of data retrieved
Greg Claytonc749eb82011-07-11 05:12:02 +0000574 s->Printf("DW_OP_xderef_size(0x%2.2x)", m_data.GetU8(&offset));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000575 break;
Greg Claytonc749eb82011-07-11 05:12:02 +0000576 case DW_OP_nop: s->PutCString("DW_OP_nop"); break; // 0x96
577 case DW_OP_push_object_address: s->PutCString("DW_OP_push_object_address"); break; // 0x97 DWARF3
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000578 case DW_OP_call2: // 0x98 DWARF3 1 2-byte offset of DIE
Greg Claytonc749eb82011-07-11 05:12:02 +0000579 s->Printf("DW_OP_call2(0x%4.4x)", m_data.GetU16(&offset));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000580 break;
581 case DW_OP_call4: // 0x99 DWARF3 1 4-byte offset of DIE
Greg Claytonc749eb82011-07-11 05:12:02 +0000582 s->Printf("DW_OP_call4(0x%8.8x)", m_data.GetU32(&offset));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000583 break;
584 case DW_OP_call_ref: // 0x9a DWARF3 1 4- or 8-byte offset of DIE
Daniel Malead01b2952012-11-29 21:49:15 +0000585 s->Printf("DW_OP_call_ref(0x%8.8" PRIx64 ")", m_data.GetAddress(&offset));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000586 break;
587// case DW_OP_form_tls_address: s << "form_tls_address"; break; // 0x9b DWARF3
588// case DW_OP_call_frame_cfa: s << "call_frame_cfa"; break; // 0x9c DWARF3
589// case DW_OP_bit_piece: // 0x9d DWARF3 2
Greg Claytonc749eb82011-07-11 05:12:02 +0000590// s->Printf("DW_OP_bit_piece(0x%x, 0x%x)", m_data.GetULEB128(&offset), m_data.GetULEB128(&offset));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000591// break;
Greg Claytonc749eb82011-07-11 05:12:02 +0000592// case DW_OP_lo_user: s->PutCString("DW_OP_lo_user"); break; // 0xe0
593// case DW_OP_hi_user: s->PutCString("DW_OP_hi_user"); break; // 0xff
Greg Clayton2fc93ea2011-11-13 04:15:56 +0000594// case DW_OP_APPLE_extern:
Daniel Malead01b2952012-11-29 21:49:15 +0000595// s->Printf("DW_OP_APPLE_extern(%" PRIu64 ")", m_data.GetULEB128(&offset));
Greg Clayton2fc93ea2011-11-13 04:15:56 +0000596// break;
597// case DW_OP_APPLE_array_ref:
598// s->PutCString("DW_OP_APPLE_array_ref");
599// break;
Richard Mitton0a558352013-10-17 21:14:00 +0000600 case DW_OP_GNU_push_tls_address:
601 s->PutCString("DW_OP_GNU_push_tls_address"); // 0xe0
602 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000603 case DW_OP_APPLE_uninit:
Greg Claytonc749eb82011-07-11 05:12:02 +0000604 s->PutCString("DW_OP_APPLE_uninit"); // 0xF0
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000605 break;
Greg Clayton2fc93ea2011-11-13 04:15:56 +0000606// case DW_OP_APPLE_assign: // 0xF1 - pops value off and assigns it to second item on stack (2nd item must have assignable context)
607// s->PutCString("DW_OP_APPLE_assign");
608// break;
609// 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)
610// s->PutCString("DW_OP_APPLE_address_of");
611// break;
612// 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)
613// s->PutCString("DW_OP_APPLE_value_of");
614// break;
615// 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)
616// s->PutCString("DW_OP_APPLE_deref_type");
617// break;
618// case DW_OP_APPLE_expr_local: // 0xF5 - ULEB128 expression local index
Daniel Malead01b2952012-11-29 21:49:15 +0000619// s->Printf("DW_OP_APPLE_expr_local(%" PRIu64 ")", m_data.GetULEB128(&offset));
Greg Clayton2fc93ea2011-11-13 04:15:56 +0000620// break;
621// case DW_OP_APPLE_constf: // 0xF6 - 1 byte float size, followed by constant float data
622// {
623// uint8_t float_length = m_data.GetU8(&offset);
624// s->Printf("DW_OP_APPLE_constf(<%u> ", float_length);
625// m_data.Dump(s, offset, eFormatHex, float_length, 1, UINT32_MAX, DW_INVALID_ADDRESS, 0, 0);
626// s->PutChar(')');
627// // Consume the float data
628// m_data.GetData(&offset, float_length);
629// }
630// break;
631// case DW_OP_APPLE_scalar_cast:
632// s->Printf("DW_OP_APPLE_scalar_cast(%s)", Scalar::GetValueTypeAsCString ((Scalar::Type)m_data.GetU8(&offset)));
633// break;
634// case DW_OP_APPLE_clang_cast:
635// {
636// clang::Type *clang_type = (clang::Type *)m_data.GetMaxU64(&offset, sizeof(void*));
637// s->Printf("DW_OP_APPLE_clang_cast(%p)", clang_type);
638// }
639// break;
640// case DW_OP_APPLE_clear:
641// s->PutCString("DW_OP_APPLE_clear");
642// break;
643// case DW_OP_APPLE_error: // 0xFF - Stops expression evaluation and returns an error (no args)
644// s->PutCString("DW_OP_APPLE_error");
645// break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000646 }
647 }
648}
649
650void
Greg Clayton016a95e2010-09-14 02:20:48 +0000651DWARFExpression::SetLocationListSlide (addr_t slide)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000652{
Greg Clayton016a95e2010-09-14 02:20:48 +0000653 m_loclist_slide = slide;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000654}
655
656int
657DWARFExpression::GetRegisterKind ()
658{
659 return m_reg_kind;
660}
661
662void
Greg Claytonafacd142011-09-02 01:15:17 +0000663DWARFExpression::SetRegisterKind (RegisterKind reg_kind)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000664{
665 m_reg_kind = reg_kind;
666}
667
668bool
669DWARFExpression::IsLocationList() const
670{
Greg Clayton016a95e2010-09-14 02:20:48 +0000671 return m_loclist_slide != LLDB_INVALID_ADDRESS;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000672}
673
674void
Greg Claytonafacd142011-09-02 01:15:17 +0000675DWARFExpression::GetDescription (Stream *s, lldb::DescriptionLevel level, addr_t location_list_base_addr, ABI *abi) const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000676{
677 if (IsLocationList())
678 {
679 // We have a location list
Greg Claytonc7bece562013-01-25 18:06:21 +0000680 lldb::offset_t offset = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000681 uint32_t count = 0;
Greg Clayton016a95e2010-09-14 02:20:48 +0000682 addr_t curr_base_addr = location_list_base_addr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000683 while (m_data.ValidOffset(offset))
684 {
685 lldb::addr_t begin_addr_offset = m_data.GetAddress(&offset);
686 lldb::addr_t end_addr_offset = m_data.GetAddress(&offset);
687 if (begin_addr_offset < end_addr_offset)
688 {
689 if (count > 0)
690 s->PutCString(", ");
Greg Clayton016a95e2010-09-14 02:20:48 +0000691 VMRange addr_range(curr_base_addr + begin_addr_offset, curr_base_addr + end_addr_offset);
692 addr_range.Dump(s, 0, 8);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000693 s->PutChar('{');
Greg Claytonc7bece562013-01-25 18:06:21 +0000694 lldb::offset_t location_length = m_data.GetU16(&offset);
Greg Claytonafacd142011-09-02 01:15:17 +0000695 DumpLocation (s, offset, location_length, level, abi);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000696 s->PutChar('}');
697 offset += location_length;
698 }
699 else if (begin_addr_offset == 0 && end_addr_offset == 0)
700 {
701 // The end of the location list is marked by both the start and end offset being zero
702 break;
703 }
704 else
705 {
Greg Claytone0d378b2011-03-24 21:19:54 +0000706 if ((m_data.GetAddressByteSize() == 4 && (begin_addr_offset == UINT32_MAX)) ||
707 (m_data.GetAddressByteSize() == 8 && (begin_addr_offset == UINT64_MAX)))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000708 {
Greg Clayton016a95e2010-09-14 02:20:48 +0000709 curr_base_addr = end_addr_offset + location_list_base_addr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000710 // We have a new base address
711 if (count > 0)
712 s->PutCString(", ");
713 *s << "base_addr = " << end_addr_offset;
714 }
715 }
716
717 count++;
718 }
719 }
720 else
721 {
722 // We have a normal location that contains DW_OP location opcodes
Greg Claytonafacd142011-09-02 01:15:17 +0000723 DumpLocation (s, 0, m_data.GetByteSize(), level, abi);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000724 }
725}
726
727static bool
728ReadRegisterValueAsScalar
729(
Greg Clayton7349bd92011-05-09 20:18:18 +0000730 RegisterContext *reg_ctx,
Jean-Daniel Dupase7c7c3d2014-07-02 09:51:28 +0000731 lldb::RegisterKind reg_kind,
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000732 uint32_t reg_num,
733 Error *error_ptr,
734 Value &value
735)
736{
Greg Clayton7349bd92011-05-09 20:18:18 +0000737 if (reg_ctx == NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000738 {
Jason Molenda2d107dd2010-11-20 01:28:30 +0000739 if (error_ptr)
740 error_ptr->SetErrorStringWithFormat("No register context in frame.\n");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000741 }
742 else
743 {
Greg Clayton7349bd92011-05-09 20:18:18 +0000744 uint32_t native_reg = reg_ctx->ConvertRegisterKindToRegisterNumber(reg_kind, reg_num);
Jason Molenda2d107dd2010-11-20 01:28:30 +0000745 if (native_reg == LLDB_INVALID_REGNUM)
746 {
747 if (error_ptr)
748 error_ptr->SetErrorStringWithFormat("Unable to convert register kind=%u reg_num=%u to a native register number.\n", reg_kind, reg_num);
749 }
750 else
751 {
Greg Clayton7349bd92011-05-09 20:18:18 +0000752 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex(native_reg);
753 RegisterValue reg_value;
754 if (reg_ctx->ReadRegister (reg_info, reg_value))
755 {
756 if (reg_value.GetScalarValue(value.GetScalar()))
757 {
758 value.SetValueType (Value::eValueTypeScalar);
Greg Clayton007d5be2011-05-30 00:49:24 +0000759 value.SetContext (Value::eContextTypeRegisterInfo,
760 const_cast<RegisterInfo *>(reg_info));
Greg Clayton7349bd92011-05-09 20:18:18 +0000761 if (error_ptr)
762 error_ptr->Clear();
763 return true;
764 }
765 else
766 {
Greg Clayton007d5be2011-05-30 00:49:24 +0000767 // If we get this error, then we need to implement a value
768 // buffer in the dwarf expression evaluation function...
Greg Clayton7349bd92011-05-09 20:18:18 +0000769 if (error_ptr)
Greg Clayton007d5be2011-05-30 00:49:24 +0000770 error_ptr->SetErrorStringWithFormat ("register %s can't be converted to a scalar value",
771 reg_info->name);
Greg Clayton7349bd92011-05-09 20:18:18 +0000772 }
773 }
774 else
775 {
776 if (error_ptr)
Greg Clayton007d5be2011-05-30 00:49:24 +0000777 error_ptr->SetErrorStringWithFormat("register %s is not available", reg_info->name);
Greg Clayton7349bd92011-05-09 20:18:18 +0000778 }
Jason Molenda2d107dd2010-11-20 01:28:30 +0000779 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000780 }
781 return false;
782}
783
Greg Clayton016a95e2010-09-14 02:20:48 +0000784//bool
785//DWARFExpression::LocationListContainsLoadAddress (Process* process, const Address &addr) const
786//{
787// return LocationListContainsLoadAddress(process, addr.GetLoadAddress(process));
788//}
789//
790//bool
791//DWARFExpression::LocationListContainsLoadAddress (Process* process, addr_t load_addr) const
792//{
793// if (load_addr == LLDB_INVALID_ADDRESS)
794// return false;
795//
796// if (IsLocationList())
797// {
Greg Claytonc7bece562013-01-25 18:06:21 +0000798// lldb::offset_t offset = 0;
Greg Clayton016a95e2010-09-14 02:20:48 +0000799//
800// addr_t loc_list_base_addr = m_loclist_slide.GetLoadAddress(process);
801//
802// if (loc_list_base_addr == LLDB_INVALID_ADDRESS)
803// return false;
804//
805// while (m_data.ValidOffset(offset))
806// {
807// // We need to figure out what the value is for the location.
808// addr_t lo_pc = m_data.GetAddress(&offset);
809// addr_t hi_pc = m_data.GetAddress(&offset);
810// if (lo_pc == 0 && hi_pc == 0)
811// break;
812// else
813// {
814// lo_pc += loc_list_base_addr;
815// hi_pc += loc_list_base_addr;
816//
817// if (lo_pc <= load_addr && load_addr < hi_pc)
818// return true;
819//
820// offset += m_data.GetU16(&offset);
821// }
822// }
823// }
824// return false;
825//}
Greg Clayton9da7bd02010-08-24 21:05:24 +0000826
Greg Claytonc7bece562013-01-25 18:06:21 +0000827static offset_t
828GetOpcodeDataSize (const DataExtractor &data, const lldb::offset_t data_offset, const uint8_t op)
Greg Clayton2fc93ea2011-11-13 04:15:56 +0000829{
Greg Claytonc7bece562013-01-25 18:06:21 +0000830 lldb::offset_t offset = data_offset;
Greg Clayton2fc93ea2011-11-13 04:15:56 +0000831 switch (op)
832 {
833 case DW_OP_addr:
834 case DW_OP_call_ref: // 0x9a 1 address sized offset of DIE (DWARF3)
835 return data.GetAddressByteSize();
836
837 // Opcodes with no arguments
838 case DW_OP_deref: // 0x06
839 case DW_OP_dup: // 0x12
840 case DW_OP_drop: // 0x13
841 case DW_OP_over: // 0x14
842 case DW_OP_swap: // 0x16
843 case DW_OP_rot: // 0x17
844 case DW_OP_xderef: // 0x18
845 case DW_OP_abs: // 0x19
846 case DW_OP_and: // 0x1a
847 case DW_OP_div: // 0x1b
848 case DW_OP_minus: // 0x1c
849 case DW_OP_mod: // 0x1d
850 case DW_OP_mul: // 0x1e
851 case DW_OP_neg: // 0x1f
852 case DW_OP_not: // 0x20
853 case DW_OP_or: // 0x21
854 case DW_OP_plus: // 0x22
855 case DW_OP_shl: // 0x24
856 case DW_OP_shr: // 0x25
857 case DW_OP_shra: // 0x26
858 case DW_OP_xor: // 0x27
859 case DW_OP_eq: // 0x29
860 case DW_OP_ge: // 0x2a
861 case DW_OP_gt: // 0x2b
862 case DW_OP_le: // 0x2c
863 case DW_OP_lt: // 0x2d
864 case DW_OP_ne: // 0x2e
865 case DW_OP_lit0: // 0x30
866 case DW_OP_lit1: // 0x31
867 case DW_OP_lit2: // 0x32
868 case DW_OP_lit3: // 0x33
869 case DW_OP_lit4: // 0x34
870 case DW_OP_lit5: // 0x35
871 case DW_OP_lit6: // 0x36
872 case DW_OP_lit7: // 0x37
873 case DW_OP_lit8: // 0x38
874 case DW_OP_lit9: // 0x39
875 case DW_OP_lit10: // 0x3A
876 case DW_OP_lit11: // 0x3B
877 case DW_OP_lit12: // 0x3C
878 case DW_OP_lit13: // 0x3D
879 case DW_OP_lit14: // 0x3E
880 case DW_OP_lit15: // 0x3F
881 case DW_OP_lit16: // 0x40
882 case DW_OP_lit17: // 0x41
883 case DW_OP_lit18: // 0x42
884 case DW_OP_lit19: // 0x43
885 case DW_OP_lit20: // 0x44
886 case DW_OP_lit21: // 0x45
887 case DW_OP_lit22: // 0x46
888 case DW_OP_lit23: // 0x47
889 case DW_OP_lit24: // 0x48
890 case DW_OP_lit25: // 0x49
891 case DW_OP_lit26: // 0x4A
892 case DW_OP_lit27: // 0x4B
893 case DW_OP_lit28: // 0x4C
894 case DW_OP_lit29: // 0x4D
895 case DW_OP_lit30: // 0x4E
896 case DW_OP_lit31: // 0x4f
897 case DW_OP_reg0: // 0x50
898 case DW_OP_reg1: // 0x51
899 case DW_OP_reg2: // 0x52
900 case DW_OP_reg3: // 0x53
901 case DW_OP_reg4: // 0x54
902 case DW_OP_reg5: // 0x55
903 case DW_OP_reg6: // 0x56
904 case DW_OP_reg7: // 0x57
905 case DW_OP_reg8: // 0x58
906 case DW_OP_reg9: // 0x59
907 case DW_OP_reg10: // 0x5A
908 case DW_OP_reg11: // 0x5B
909 case DW_OP_reg12: // 0x5C
910 case DW_OP_reg13: // 0x5D
911 case DW_OP_reg14: // 0x5E
912 case DW_OP_reg15: // 0x5F
913 case DW_OP_reg16: // 0x60
914 case DW_OP_reg17: // 0x61
915 case DW_OP_reg18: // 0x62
916 case DW_OP_reg19: // 0x63
917 case DW_OP_reg20: // 0x64
918 case DW_OP_reg21: // 0x65
919 case DW_OP_reg22: // 0x66
920 case DW_OP_reg23: // 0x67
921 case DW_OP_reg24: // 0x68
922 case DW_OP_reg25: // 0x69
923 case DW_OP_reg26: // 0x6A
924 case DW_OP_reg27: // 0x6B
925 case DW_OP_reg28: // 0x6C
926 case DW_OP_reg29: // 0x6D
927 case DW_OP_reg30: // 0x6E
928 case DW_OP_reg31: // 0x6F
929 case DW_OP_nop: // 0x96
930 case DW_OP_push_object_address: // 0x97 DWARF3
931 case DW_OP_form_tls_address: // 0x9b DWARF3
932 case DW_OP_call_frame_cfa: // 0x9c DWARF3
Greg Claytoneaeaf6f2011-12-01 04:06:15 +0000933 case DW_OP_stack_value: // 0x9f DWARF4
Richard Mitton0a558352013-10-17 21:14:00 +0000934 case DW_OP_GNU_push_tls_address: // 0xe0 GNU extension
935 return 0;
Greg Clayton2fc93ea2011-11-13 04:15:56 +0000936
937 // Opcodes with a single 1 byte arguments
938 case DW_OP_const1u: // 0x08 1 1-byte constant
939 case DW_OP_const1s: // 0x09 1 1-byte constant
940 case DW_OP_pick: // 0x15 1 1-byte stack index
941 case DW_OP_deref_size: // 0x94 1 1-byte size of data retrieved
942 case DW_OP_xderef_size: // 0x95 1 1-byte size of data retrieved
943 return 1;
944
945 // Opcodes with a single 2 byte arguments
946 case DW_OP_const2u: // 0x0a 1 2-byte constant
947 case DW_OP_const2s: // 0x0b 1 2-byte constant
948 case DW_OP_skip: // 0x2f 1 signed 2-byte constant
949 case DW_OP_bra: // 0x28 1 signed 2-byte constant
950 case DW_OP_call2: // 0x98 1 2-byte offset of DIE (DWARF3)
951 return 2;
952
953 // Opcodes with a single 4 byte arguments
954 case DW_OP_const4u: // 0x0c 1 4-byte constant
955 case DW_OP_const4s: // 0x0d 1 4-byte constant
956 case DW_OP_call4: // 0x99 1 4-byte offset of DIE (DWARF3)
957 return 4;
958
959 // Opcodes with a single 8 byte arguments
960 case DW_OP_const8u: // 0x0e 1 8-byte constant
961 case DW_OP_const8s: // 0x0f 1 8-byte constant
962 return 8;
963
964 // All opcodes that have a single ULEB (signed or unsigned) argument
965 case DW_OP_constu: // 0x10 1 ULEB128 constant
966 case DW_OP_consts: // 0x11 1 SLEB128 constant
967 case DW_OP_plus_uconst: // 0x23 1 ULEB128 addend
968 case DW_OP_breg0: // 0x70 1 ULEB128 register
969 case DW_OP_breg1: // 0x71 1 ULEB128 register
970 case DW_OP_breg2: // 0x72 1 ULEB128 register
971 case DW_OP_breg3: // 0x73 1 ULEB128 register
972 case DW_OP_breg4: // 0x74 1 ULEB128 register
973 case DW_OP_breg5: // 0x75 1 ULEB128 register
974 case DW_OP_breg6: // 0x76 1 ULEB128 register
975 case DW_OP_breg7: // 0x77 1 ULEB128 register
976 case DW_OP_breg8: // 0x78 1 ULEB128 register
977 case DW_OP_breg9: // 0x79 1 ULEB128 register
978 case DW_OP_breg10: // 0x7a 1 ULEB128 register
979 case DW_OP_breg11: // 0x7b 1 ULEB128 register
980 case DW_OP_breg12: // 0x7c 1 ULEB128 register
981 case DW_OP_breg13: // 0x7d 1 ULEB128 register
982 case DW_OP_breg14: // 0x7e 1 ULEB128 register
983 case DW_OP_breg15: // 0x7f 1 ULEB128 register
984 case DW_OP_breg16: // 0x80 1 ULEB128 register
985 case DW_OP_breg17: // 0x81 1 ULEB128 register
986 case DW_OP_breg18: // 0x82 1 ULEB128 register
987 case DW_OP_breg19: // 0x83 1 ULEB128 register
988 case DW_OP_breg20: // 0x84 1 ULEB128 register
989 case DW_OP_breg21: // 0x85 1 ULEB128 register
990 case DW_OP_breg22: // 0x86 1 ULEB128 register
991 case DW_OP_breg23: // 0x87 1 ULEB128 register
992 case DW_OP_breg24: // 0x88 1 ULEB128 register
993 case DW_OP_breg25: // 0x89 1 ULEB128 register
994 case DW_OP_breg26: // 0x8a 1 ULEB128 register
995 case DW_OP_breg27: // 0x8b 1 ULEB128 register
996 case DW_OP_breg28: // 0x8c 1 ULEB128 register
997 case DW_OP_breg29: // 0x8d 1 ULEB128 register
998 case DW_OP_breg30: // 0x8e 1 ULEB128 register
999 case DW_OP_breg31: // 0x8f 1 ULEB128 register
1000 case DW_OP_regx: // 0x90 1 ULEB128 register
1001 case DW_OP_fbreg: // 0x91 1 SLEB128 offset
1002 case DW_OP_piece: // 0x93 1 ULEB128 size of piece addressed
1003 data.Skip_LEB128(&offset);
1004 return offset - data_offset;
1005
Greg Claytoneaeaf6f2011-12-01 04:06:15 +00001006 // All opcodes that have a 2 ULEB (signed or unsigned) arguments
Greg Clayton2fc93ea2011-11-13 04:15:56 +00001007 case DW_OP_bregx: // 0x92 2 ULEB128 register followed by SLEB128 offset
1008 case DW_OP_bit_piece: // 0x9d ULEB128 bit size, ULEB128 bit offset (DWARF3);
1009 data.Skip_LEB128(&offset);
1010 data.Skip_LEB128(&offset);
1011 return offset - data_offset;
Greg Claytoneaeaf6f2011-12-01 04:06:15 +00001012
1013 case DW_OP_implicit_value: // 0x9e ULEB128 size followed by block of that size (DWARF4)
1014 {
1015 uint64_t block_len = data.Skip_LEB128(&offset);
1016 offset += block_len;
1017 return offset - data_offset;
1018 }
1019
Greg Clayton2fc93ea2011-11-13 04:15:56 +00001020 default:
Greg Clayton96c09682012-01-04 22:56:43 +00001021 break;
Greg Clayton2fc93ea2011-11-13 04:15:56 +00001022 }
Greg Claytonc7bece562013-01-25 18:06:21 +00001023 return LLDB_INVALID_OFFSET;
Greg Clayton2fc93ea2011-11-13 04:15:56 +00001024}
1025
Greg Clayton9422dd62013-03-04 21:46:16 +00001026lldb::addr_t
1027DWARFExpression::GetLocation_DW_OP_addr (uint32_t op_addr_idx, bool &error) const
Greg Clayton2fc93ea2011-11-13 04:15:56 +00001028{
Greg Clayton96c09682012-01-04 22:56:43 +00001029 error = false;
Greg Clayton2fc93ea2011-11-13 04:15:56 +00001030 if (IsLocationList())
Greg Clayton9422dd62013-03-04 21:46:16 +00001031 return LLDB_INVALID_ADDRESS;
Greg Claytonc7bece562013-01-25 18:06:21 +00001032 lldb::offset_t offset = 0;
Greg Clayton9422dd62013-03-04 21:46:16 +00001033 uint32_t curr_op_addr_idx = 0;
Greg Clayton2fc93ea2011-11-13 04:15:56 +00001034 while (m_data.ValidOffset(offset))
1035 {
1036 const uint8_t op = m_data.GetU8(&offset);
1037
1038 if (op == DW_OP_addr)
1039 {
Greg Clayton9422dd62013-03-04 21:46:16 +00001040 const lldb::addr_t op_file_addr = m_data.GetAddress(&offset);
1041 if (curr_op_addr_idx == op_addr_idx)
1042 return op_file_addr;
1043 else
1044 ++curr_op_addr_idx;
Greg Clayton2fc93ea2011-11-13 04:15:56 +00001045 }
1046 else
1047 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001048 const offset_t op_arg_size = GetOpcodeDataSize (m_data, offset, op);
1049 if (op_arg_size == LLDB_INVALID_OFFSET)
Greg Clayton96c09682012-01-04 22:56:43 +00001050 {
1051 error = true;
Greg Clayton2fc93ea2011-11-13 04:15:56 +00001052 break;
Greg Clayton96c09682012-01-04 22:56:43 +00001053 }
Greg Clayton2fc93ea2011-11-13 04:15:56 +00001054 offset += op_arg_size;
1055 }
1056 }
Greg Clayton9422dd62013-03-04 21:46:16 +00001057 return LLDB_INVALID_ADDRESS;
Greg Clayton2fc93ea2011-11-13 04:15:56 +00001058}
1059
1060bool
1061DWARFExpression::Update_DW_OP_addr (lldb::addr_t file_addr)
1062{
1063 if (IsLocationList())
1064 return false;
Greg Claytonc7bece562013-01-25 18:06:21 +00001065 lldb::offset_t offset = 0;
Greg Clayton2fc93ea2011-11-13 04:15:56 +00001066 while (m_data.ValidOffset(offset))
1067 {
1068 const uint8_t op = m_data.GetU8(&offset);
1069
1070 if (op == DW_OP_addr)
1071 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001072 const uint32_t addr_byte_size = m_data.GetAddressByteSize();
Greg Clayton2fc93ea2011-11-13 04:15:56 +00001073 // We have to make a copy of the data as we don't know if this
1074 // data is from a read only memory mapped buffer, so we duplicate
1075 // all of the data first, then modify it, and if all goes well,
1076 // we then replace the data for this expression
1077
1078 // So first we copy the data into a heap buffer
Greg Clayton7b0992d2013-04-18 22:45:39 +00001079 std::unique_ptr<DataBufferHeap> head_data_ap (new DataBufferHeap (m_data.GetDataStart(),
Greg Claytone01e07b2013-04-18 18:10:51 +00001080 m_data.GetByteSize()));
Greg Clayton2fc93ea2011-11-13 04:15:56 +00001081
1082 // Make en encoder so we can write the address into the buffer using
1083 // the correct byte order (endianness)
1084 DataEncoder encoder (head_data_ap->GetBytes(),
1085 head_data_ap->GetByteSize(),
1086 m_data.GetByteOrder(),
1087 addr_byte_size);
1088
1089 // Replace the address in the new buffer
1090 if (encoder.PutMaxU64 (offset, addr_byte_size, file_addr) == UINT32_MAX)
1091 return false;
1092
1093 // All went well, so now we can reset the data using a shared
1094 // pointer to the heap data so "m_data" will now correctly
1095 // manage the heap data.
1096 m_data.SetData (DataBufferSP (head_data_ap.release()));
1097 return true;
1098 }
1099 else
1100 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001101 const offset_t op_arg_size = GetOpcodeDataSize (m_data, offset, op);
1102 if (op_arg_size == LLDB_INVALID_OFFSET)
Greg Clayton2fc93ea2011-11-13 04:15:56 +00001103 break;
1104 offset += op_arg_size;
1105 }
1106 }
1107 return false;
1108}
1109
Greg Clayton9da7bd02010-08-24 21:05:24 +00001110bool
Greg Clayton016a95e2010-09-14 02:20:48 +00001111DWARFExpression::LocationListContainsAddress (lldb::addr_t loclist_base_addr, lldb::addr_t addr) const
Greg Clayton9da7bd02010-08-24 21:05:24 +00001112{
Greg Clayton016a95e2010-09-14 02:20:48 +00001113 if (addr == LLDB_INVALID_ADDRESS)
Greg Clayton9da7bd02010-08-24 21:05:24 +00001114 return false;
1115
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001116 if (IsLocationList())
1117 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001118 lldb::offset_t offset = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001119
Greg Clayton016a95e2010-09-14 02:20:48 +00001120 if (loclist_base_addr == LLDB_INVALID_ADDRESS)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001121 return false;
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 break;
1130 else
1131 {
Greg Clayton016a95e2010-09-14 02:20:48 +00001132 lo_pc += loclist_base_addr - m_loclist_slide;
1133 hi_pc += loclist_base_addr - m_loclist_slide;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001134
Greg Clayton016a95e2010-09-14 02:20:48 +00001135 if (lo_pc <= addr && addr < hi_pc)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001136 return true;
1137
1138 offset += m_data.GetU16(&offset);
1139 }
1140 }
1141 }
1142 return false;
1143}
Greg Clayton9da7bd02010-08-24 21:05:24 +00001144
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001145bool
Greg Claytonc7bece562013-01-25 18:06:21 +00001146DWARFExpression::GetLocation (addr_t base_addr, addr_t pc, lldb::offset_t &offset, lldb::offset_t &length)
Greg Claytonc749eb82011-07-11 05:12:02 +00001147{
1148 offset = 0;
1149 if (!IsLocationList())
1150 {
1151 length = m_data.GetByteSize();
1152 return true;
1153 }
1154
1155 if (base_addr != LLDB_INVALID_ADDRESS && pc != LLDB_INVALID_ADDRESS)
1156 {
1157 addr_t curr_base_addr = base_addr;
1158
1159 while (m_data.ValidOffset(offset))
1160 {
1161 // We need to figure out what the value is for the location.
1162 addr_t lo_pc = m_data.GetAddress(&offset);
1163 addr_t hi_pc = m_data.GetAddress(&offset);
1164 if (lo_pc == 0 && hi_pc == 0)
1165 {
1166 break;
1167 }
1168 else
1169 {
1170 lo_pc += curr_base_addr - m_loclist_slide;
1171 hi_pc += curr_base_addr - m_loclist_slide;
1172
1173 length = m_data.GetU16(&offset);
1174
1175 if (length > 0 && lo_pc <= pc && pc < hi_pc)
1176 return true;
1177
1178 offset += length;
1179 }
1180 }
1181 }
Greg Claytonc7bece562013-01-25 18:06:21 +00001182 offset = LLDB_INVALID_OFFSET;
Greg Claytonc749eb82011-07-11 05:12:02 +00001183 length = 0;
1184 return false;
1185}
1186
1187bool
1188DWARFExpression::DumpLocationForAddress (Stream *s,
1189 lldb::DescriptionLevel level,
1190 addr_t base_addr,
Greg Claytonafacd142011-09-02 01:15:17 +00001191 addr_t address,
1192 ABI *abi)
Greg Claytonc749eb82011-07-11 05:12:02 +00001193{
Greg Claytonc7bece562013-01-25 18:06:21 +00001194 lldb::offset_t offset = 0;
1195 lldb::offset_t length = 0;
Greg Claytonc749eb82011-07-11 05:12:02 +00001196
1197 if (GetLocation (base_addr, address, offset, length))
1198 {
1199 if (length > 0)
1200 {
Greg Claytonafacd142011-09-02 01:15:17 +00001201 DumpLocation(s, offset, length, level, abi);
Greg Claytonc749eb82011-07-11 05:12:02 +00001202 return true;
1203 }
1204 }
1205 return false;
1206}
1207
1208bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001209DWARFExpression::Evaluate
1210(
1211 ExecutionContextScope *exe_scope,
Greg Clayton1a65ae12011-01-25 23:55:37 +00001212 ClangExpressionVariableList *expr_locals,
1213 ClangExpressionDeclMap *decl_map,
Greg Clayton016a95e2010-09-14 02:20:48 +00001214 lldb::addr_t loclist_base_load_addr,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001215 const Value* initial_value_ptr,
1216 Value& result,
1217 Error *error_ptr
1218) const
1219{
1220 ExecutionContext exe_ctx (exe_scope);
Greg Clayton57ee3062013-07-11 22:46:58 +00001221 return Evaluate(&exe_ctx, expr_locals, decl_map, NULL, loclist_base_load_addr, initial_value_ptr, result, error_ptr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001222}
1223
1224bool
1225DWARFExpression::Evaluate
1226(
1227 ExecutionContext *exe_ctx,
Greg Clayton1a65ae12011-01-25 23:55:37 +00001228 ClangExpressionVariableList *expr_locals,
1229 ClangExpressionDeclMap *decl_map,
Jason Molenda2d107dd2010-11-20 01:28:30 +00001230 RegisterContext *reg_ctx,
Greg Clayton016a95e2010-09-14 02:20:48 +00001231 lldb::addr_t loclist_base_load_addr,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001232 const Value* initial_value_ptr,
1233 Value& result,
1234 Error *error_ptr
1235) const
1236{
Richard Mitton0a558352013-10-17 21:14:00 +00001237 ModuleSP module_sp = m_module_wp.lock();
1238
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001239 if (IsLocationList())
1240 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001241 lldb::offset_t offset = 0;
Jason Molenda2d107dd2010-11-20 01:28:30 +00001242 addr_t pc;
Jason Molendab57e4a12013-11-04 09:33:30 +00001243 StackFrame *frame = NULL;
Jason Molenda2d107dd2010-11-20 01:28:30 +00001244 if (reg_ctx)
1245 pc = reg_ctx->GetPC();
1246 else
Greg Claytonc14ee322011-09-22 04:58:26 +00001247 {
1248 frame = exe_ctx->GetFramePtr();
Sean Callananb7de9602012-03-10 03:03:46 +00001249 if (!frame)
1250 return false;
1251 RegisterContextSP reg_ctx_sp = frame->GetRegisterContext();
1252 if (!reg_ctx_sp)
1253 return false;
1254 pc = reg_ctx_sp->GetPC();
Greg Claytonc14ee322011-09-22 04:58:26 +00001255 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001256
Greg Clayton016a95e2010-09-14 02:20:48 +00001257 if (loclist_base_load_addr != LLDB_INVALID_ADDRESS)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001258 {
Greg Clayton016a95e2010-09-14 02:20:48 +00001259 if (pc == LLDB_INVALID_ADDRESS)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001260 {
Greg Clayton016a95e2010-09-14 02:20:48 +00001261 if (error_ptr)
1262 error_ptr->SetErrorString("Invalid PC in frame.");
1263 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001264 }
Greg Clayton016a95e2010-09-14 02:20:48 +00001265
1266 addr_t curr_loclist_base_load_addr = loclist_base_load_addr;
1267
1268 while (m_data.ValidOffset(offset))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001269 {
Greg Clayton016a95e2010-09-14 02:20:48 +00001270 // We need to figure out what the value is for the location.
1271 addr_t lo_pc = m_data.GetAddress(&offset);
1272 addr_t hi_pc = m_data.GetAddress(&offset);
1273 if (lo_pc == 0 && hi_pc == 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001274 {
Greg Clayton016a95e2010-09-14 02:20:48 +00001275 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001276 }
Greg Clayton016a95e2010-09-14 02:20:48 +00001277 else
1278 {
1279 lo_pc += curr_loclist_base_load_addr - m_loclist_slide;
1280 hi_pc += curr_loclist_base_load_addr - m_loclist_slide;
1281
1282 uint16_t length = m_data.GetU16(&offset);
1283
1284 if (length > 0 && lo_pc <= pc && pc < hi_pc)
1285 {
Richard Mitton0a558352013-10-17 21:14:00 +00001286 return DWARFExpression::Evaluate (exe_ctx, expr_locals, decl_map, reg_ctx, module_sp, m_data, offset, length, m_reg_kind, initial_value_ptr, result, error_ptr);
Greg Clayton016a95e2010-09-14 02:20:48 +00001287 }
1288 offset += length;
1289 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001290 }
1291 }
1292 if (error_ptr)
Greg Clayton007d5be2011-05-30 00:49:24 +00001293 error_ptr->SetErrorString ("variable not available");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001294 return false;
1295 }
1296
1297 // Not a location list, just a single expression.
Richard Mitton0a558352013-10-17 21:14:00 +00001298 return DWARFExpression::Evaluate (exe_ctx, expr_locals, decl_map, reg_ctx, module_sp, m_data, 0, m_data.GetByteSize(), m_reg_kind, initial_value_ptr, result, error_ptr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001299}
1300
1301
1302
1303bool
1304DWARFExpression::Evaluate
1305(
1306 ExecutionContext *exe_ctx,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001307 ClangExpressionVariableList *expr_locals,
1308 ClangExpressionDeclMap *decl_map,
Jason Molenda2d107dd2010-11-20 01:28:30 +00001309 RegisterContext *reg_ctx,
Richard Mitton0a558352013-10-17 21:14:00 +00001310 lldb::ModuleSP opcode_ctx,
Greg Clayton1a65ae12011-01-25 23:55:37 +00001311 const DataExtractor& opcodes,
Greg Claytonc7bece562013-01-25 18:06:21 +00001312 const lldb::offset_t opcodes_offset,
1313 const lldb::offset_t opcodes_length,
Jean-Daniel Dupase7c7c3d2014-07-02 09:51:28 +00001314 const lldb::RegisterKind reg_kind,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001315 const Value* initial_value_ptr,
1316 Value& result,
1317 Error *error_ptr
1318)
1319{
Greg Clayton9e9f2192013-05-17 00:55:28 +00001320
1321 if (opcodes_length == 0)
1322 {
1323 if (error_ptr)
1324 error_ptr->SetErrorString ("no location, value may have been optimized out");
1325 return false;
1326 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001327 std::vector<Value> stack;
1328
Greg Claytonc14ee322011-09-22 04:58:26 +00001329 Process *process = NULL;
Jason Molendab57e4a12013-11-04 09:33:30 +00001330 StackFrame *frame = NULL;
Greg Claytonc14ee322011-09-22 04:58:26 +00001331
1332 if (exe_ctx)
1333 {
1334 process = exe_ctx->GetProcessPtr();
1335 frame = exe_ctx->GetFramePtr();
1336 }
1337 if (reg_ctx == NULL && frame)
1338 reg_ctx = frame->GetRegisterContext().get();
Jason Molenda2d107dd2010-11-20 01:28:30 +00001339
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001340 if (initial_value_ptr)
1341 stack.push_back(*initial_value_ptr);
1342
Greg Claytonc7bece562013-01-25 18:06:21 +00001343 lldb::offset_t offset = opcodes_offset;
1344 const lldb::offset_t end_offset = opcodes_offset + opcodes_length;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001345 Value tmp;
1346 uint32_t reg_num;
1347
Greg Clayton27407872014-07-12 00:24:33 +00001348 /// Insertion point for evaluating multi-piece expression.
1349 uint64_t op_piece_offset = 0;
1350
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001351 // Make sure all of the data is available in opcodes.
1352 if (!opcodes.ValidOffsetForDataOfSize(opcodes_offset, opcodes_length))
1353 {
1354 if (error_ptr)
Greg Clayton9e9f2192013-05-17 00:55:28 +00001355 error_ptr->SetErrorString ("invalid offset and/or length for opcodes buffer.");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001356 return false;
1357 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001358 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001359
1360
1361 while (opcodes.ValidOffset(offset) && offset < end_offset)
1362 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001363 const lldb::offset_t op_offset = offset;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001364 const uint8_t op = opcodes.GetU8(&offset);
1365
Sean Callanan7dd98122011-10-14 20:34:21 +00001366 if (log && log->GetVerbose())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001367 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001368 size_t count = stack.size();
Greg Clayton6fea17e2014-03-03 19:15:20 +00001369 log->Printf("Stack before operation has %" PRIu64 " values:", (uint64_t)count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001370 for (size_t i=0; i<count; ++i)
1371 {
1372 StreamString new_value;
Daniel Malead01b2952012-11-29 21:49:15 +00001373 new_value.Printf("[%" PRIu64 "]", (uint64_t)i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001374 stack[i].Dump(&new_value);
Sean Callananf06ba8d2010-06-23 00:47:48 +00001375 log->Printf(" %s", new_value.GetData());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001376 }
Greg Claytonc7bece562013-01-25 18:06:21 +00001377 log->Printf("0x%8.8" PRIx64 ": %s", op_offset, DW_OP_value_to_name(op));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001378 }
1379 switch (op)
1380 {
1381 //----------------------------------------------------------------------
1382 // The DW_OP_addr operation has a single operand that encodes a machine
1383 // address and whose size is the size of an address on the target machine.
1384 //----------------------------------------------------------------------
1385 case DW_OP_addr:
Greg Clayton644247c2011-07-07 01:59:51 +00001386 stack.push_back(Scalar(opcodes.GetAddress(&offset)));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001387 stack.back().SetValueType (Value::eValueTypeFileAddress);
1388 break;
1389
1390 //----------------------------------------------------------------------
1391 // The DW_OP_addr_sect_offset4 is used for any location expressions in
1392 // shared libraries that have a location like:
1393 // DW_OP_addr(0x1000)
1394 // If this address resides in a shared library, then this virtual
1395 // address won't make sense when it is evaluated in the context of a
1396 // running process where shared libraries have been slid. To account for
1397 // this, this new address type where we can store the section pointer
1398 // and a 4 byte offset.
1399 //----------------------------------------------------------------------
1400// case DW_OP_addr_sect_offset4:
1401// {
1402// result_type = eResultTypeFileAddress;
1403// lldb::Section *sect = (lldb::Section *)opcodes.GetMaxU64(&offset, sizeof(void *));
1404// lldb::addr_t sect_offset = opcodes.GetU32(&offset);
1405//
1406// Address so_addr (sect, sect_offset);
1407// lldb::addr_t load_addr = so_addr.GetLoadAddress();
1408// if (load_addr != LLDB_INVALID_ADDRESS)
1409// {
1410// // We successfully resolve a file address to a load
1411// // address.
1412// stack.push_back(load_addr);
1413// break;
1414// }
1415// else
1416// {
1417// // We were able
1418// if (error_ptr)
1419// error_ptr->SetErrorStringWithFormat ("Section %s in %s is not currently loaded.\n", sect->GetName().AsCString(), sect->GetModule()->GetFileSpec().GetFilename().AsCString());
1420// return false;
1421// }
1422// }
1423// break;
1424
1425 //----------------------------------------------------------------------
1426 // OPCODE: DW_OP_deref
1427 // OPERANDS: none
1428 // DESCRIPTION: Pops the top stack entry and treats it as an address.
1429 // The value retrieved from that address is pushed. The size of the
1430 // data retrieved from the dereferenced address is the size of an
1431 // address on the target machine.
1432 //----------------------------------------------------------------------
1433 case DW_OP_deref:
1434 {
Ed Maste93447872014-01-13 14:53:09 +00001435 if (stack.empty())
1436 {
1437 if (error_ptr)
1438 error_ptr->SetErrorString("Expression stack empty for DW_OP_deref.");
1439 return false;
1440 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001441 Value::ValueType value_type = stack.back().GetValueType();
1442 switch (value_type)
1443 {
1444 case Value::eValueTypeHostAddress:
1445 {
1446 void *src = (void *)stack.back().GetScalar().ULongLong();
1447 intptr_t ptr;
1448 ::memcpy (&ptr, src, sizeof(void *));
1449 stack.back().GetScalar() = ptr;
1450 stack.back().ClearContext();
1451 }
1452 break;
1453 case Value::eValueTypeLoadAddress:
1454 if (exe_ctx)
1455 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001456 if (process)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001457 {
1458 lldb::addr_t pointer_addr = stack.back().GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1459 uint8_t addr_bytes[sizeof(lldb::addr_t)];
Greg Claytonc14ee322011-09-22 04:58:26 +00001460 uint32_t addr_size = process->GetAddressByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001461 Error error;
Greg Claytonc14ee322011-09-22 04:58:26 +00001462 if (process->ReadMemory(pointer_addr, &addr_bytes, addr_size, error) == addr_size)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001463 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001464 DataExtractor addr_data(addr_bytes, sizeof(addr_bytes), process->GetByteOrder(), addr_size);
Greg Claytonc7bece562013-01-25 18:06:21 +00001465 lldb::offset_t addr_data_offset = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001466 stack.back().GetScalar() = addr_data.GetPointer(&addr_data_offset);
1467 stack.back().ClearContext();
1468 }
1469 else
1470 {
1471 if (error_ptr)
Daniel Malead01b2952012-11-29 21:49:15 +00001472 error_ptr->SetErrorStringWithFormat ("Failed to dereference pointer from 0x%" PRIx64 " for DW_OP_deref: %s\n",
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001473 pointer_addr,
1474 error.AsCString());
1475 return false;
1476 }
1477 }
1478 else
1479 {
1480 if (error_ptr)
1481 error_ptr->SetErrorStringWithFormat ("NULL process for DW_OP_deref.\n");
1482 return false;
1483 }
1484 }
1485 else
1486 {
1487 if (error_ptr)
1488 error_ptr->SetErrorStringWithFormat ("NULL execution context for DW_OP_deref.\n");
1489 return false;
1490 }
1491 break;
1492
1493 default:
1494 break;
1495 }
1496
1497 }
1498 break;
1499
1500 //----------------------------------------------------------------------
1501 // OPCODE: DW_OP_deref_size
1502 // OPERANDS: 1
1503 // 1 - uint8_t that specifies the size of the data to dereference.
1504 // DESCRIPTION: Behaves like the DW_OP_deref operation: it pops the top
1505 // stack entry and treats it as an address. The value retrieved from that
1506 // address is pushed. In the DW_OP_deref_size operation, however, the
1507 // size in bytes of the data retrieved from the dereferenced address is
1508 // specified by the single operand. This operand is a 1-byte unsigned
1509 // integral constant whose value may not be larger than the size of an
1510 // address on the target machine. The data retrieved is zero extended
1511 // to the size of an address on the target machine before being pushed
1512 // on the expression stack.
1513 //----------------------------------------------------------------------
1514 case DW_OP_deref_size:
Jason Molenda2d107dd2010-11-20 01:28:30 +00001515 {
Ed Maste93447872014-01-13 14:53:09 +00001516 if (stack.empty())
1517 {
1518 if (error_ptr)
1519 error_ptr->SetErrorString("Expression stack empty for DW_OP_deref_size.");
1520 return false;
1521 }
Jason Molenda2d107dd2010-11-20 01:28:30 +00001522 uint8_t size = opcodes.GetU8(&offset);
1523 Value::ValueType value_type = stack.back().GetValueType();
1524 switch (value_type)
1525 {
1526 case Value::eValueTypeHostAddress:
1527 {
1528 void *src = (void *)stack.back().GetScalar().ULongLong();
1529 intptr_t ptr;
1530 ::memcpy (&ptr, src, sizeof(void *));
1531 // I can't decide whether the size operand should apply to the bytes in their
1532 // lldb-host endianness or the target endianness.. I doubt this'll ever come up
1533 // but I'll opt for assuming big endian regardless.
1534 switch (size)
1535 {
1536 case 1: ptr = ptr & 0xff; break;
1537 case 2: ptr = ptr & 0xffff; break;
1538 case 3: ptr = ptr & 0xffffff; break;
1539 case 4: ptr = ptr & 0xffffffff; break;
Jason Molendac1903402010-11-29 21:38:58 +00001540 // the casts are added to work around the case where intptr_t is a 32 bit quantity;
1541 // presumably we won't hit the 5..7 cases if (void*) is 32-bits in this program.
1542 case 5: ptr = (intptr_t) ptr & 0xffffffffffULL; break;
1543 case 6: ptr = (intptr_t) ptr & 0xffffffffffffULL; break;
1544 case 7: ptr = (intptr_t) ptr & 0xffffffffffffffULL; break;
Jason Molenda2d107dd2010-11-20 01:28:30 +00001545 default: break;
1546 }
1547 stack.back().GetScalar() = ptr;
1548 stack.back().ClearContext();
1549 }
1550 break;
1551 case Value::eValueTypeLoadAddress:
1552 if (exe_ctx)
1553 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001554 if (process)
Jason Molenda2d107dd2010-11-20 01:28:30 +00001555 {
1556 lldb::addr_t pointer_addr = stack.back().GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1557 uint8_t addr_bytes[sizeof(lldb::addr_t)];
1558 Error error;
Greg Claytonc14ee322011-09-22 04:58:26 +00001559 if (process->ReadMemory(pointer_addr, &addr_bytes, size, error) == size)
Jason Molenda2d107dd2010-11-20 01:28:30 +00001560 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001561 DataExtractor addr_data(addr_bytes, sizeof(addr_bytes), process->GetByteOrder(), size);
Greg Claytonc7bece562013-01-25 18:06:21 +00001562 lldb::offset_t addr_data_offset = 0;
Jason Molenda2d107dd2010-11-20 01:28:30 +00001563 switch (size)
1564 {
1565 case 1: stack.back().GetScalar() = addr_data.GetU8(&addr_data_offset); break;
1566 case 2: stack.back().GetScalar() = addr_data.GetU16(&addr_data_offset); break;
1567 case 4: stack.back().GetScalar() = addr_data.GetU32(&addr_data_offset); break;
1568 case 8: stack.back().GetScalar() = addr_data.GetU64(&addr_data_offset); break;
1569 default: stack.back().GetScalar() = addr_data.GetPointer(&addr_data_offset);
1570 }
1571 stack.back().ClearContext();
1572 }
1573 else
1574 {
1575 if (error_ptr)
Daniel Malead01b2952012-11-29 21:49:15 +00001576 error_ptr->SetErrorStringWithFormat ("Failed to dereference pointer from 0x%" PRIx64 " for DW_OP_deref: %s\n",
Jason Molenda2d107dd2010-11-20 01:28:30 +00001577 pointer_addr,
1578 error.AsCString());
1579 return false;
1580 }
1581 }
1582 else
1583 {
1584 if (error_ptr)
1585 error_ptr->SetErrorStringWithFormat ("NULL process for DW_OP_deref.\n");
1586 return false;
1587 }
1588 }
1589 else
1590 {
1591 if (error_ptr)
1592 error_ptr->SetErrorStringWithFormat ("NULL execution context for DW_OP_deref.\n");
1593 return false;
1594 }
1595 break;
1596
1597 default:
1598 break;
1599 }
1600
1601 }
1602 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001603
1604 //----------------------------------------------------------------------
1605 // OPCODE: DW_OP_xderef_size
1606 // OPERANDS: 1
1607 // 1 - uint8_t that specifies the size of the data to dereference.
1608 // DESCRIPTION: Behaves like the DW_OP_xderef operation: the entry at
1609 // the top of the stack is treated as an address. The second stack
Greg Clayton1b72fcb2010-08-24 00:45:41 +00001610 // entry is treated as an "address space identifier" for those
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001611 // architectures that support multiple address spaces. The top two
1612 // stack elements are popped, a data item is retrieved through an
1613 // implementation-defined address calculation and pushed as the new
1614 // stack top. In the DW_OP_xderef_size operation, however, the size in
1615 // bytes of the data retrieved from the dereferenced address is
1616 // specified by the single operand. This operand is a 1-byte unsigned
1617 // integral constant whose value may not be larger than the size of an
1618 // address on the target machine. The data retrieved is zero extended
1619 // to the size of an address on the target machine before being pushed
1620 // on the expression stack.
1621 //----------------------------------------------------------------------
1622 case DW_OP_xderef_size:
1623 if (error_ptr)
1624 error_ptr->SetErrorString("Unimplemented opcode: DW_OP_xderef_size.");
1625 return false;
1626 //----------------------------------------------------------------------
1627 // OPCODE: DW_OP_xderef
1628 // OPERANDS: none
1629 // DESCRIPTION: Provides an extended dereference mechanism. The entry at
1630 // the top of the stack is treated as an address. The second stack entry
1631 // is treated as an "address space identifier" for those architectures
1632 // that support multiple address spaces. The top two stack elements are
1633 // popped, a data item is retrieved through an implementation-defined
1634 // address calculation and pushed as the new stack top. The size of the
1635 // data retrieved from the dereferenced address is the size of an address
1636 // on the target machine.
1637 //----------------------------------------------------------------------
1638 case DW_OP_xderef:
1639 if (error_ptr)
1640 error_ptr->SetErrorString("Unimplemented opcode: DW_OP_xderef.");
1641 return false;
1642
1643 //----------------------------------------------------------------------
1644 // All DW_OP_constXXX opcodes have a single operand as noted below:
1645 //
1646 // Opcode Operand 1
1647 // --------------- ----------------------------------------------------
1648 // DW_OP_const1u 1-byte unsigned integer constant
1649 // DW_OP_const1s 1-byte signed integer constant
1650 // DW_OP_const2u 2-byte unsigned integer constant
1651 // DW_OP_const2s 2-byte signed integer constant
1652 // DW_OP_const4u 4-byte unsigned integer constant
1653 // DW_OP_const4s 4-byte signed integer constant
1654 // DW_OP_const8u 8-byte unsigned integer constant
1655 // DW_OP_const8s 8-byte signed integer constant
1656 // DW_OP_constu unsigned LEB128 integer constant
1657 // DW_OP_consts signed LEB128 integer constant
1658 //----------------------------------------------------------------------
Greg Clayton644247c2011-07-07 01:59:51 +00001659 case DW_OP_const1u : stack.push_back(Scalar(( uint8_t)opcodes.GetU8 (&offset))); break;
1660 case DW_OP_const1s : stack.push_back(Scalar(( int8_t)opcodes.GetU8 (&offset))); break;
1661 case DW_OP_const2u : stack.push_back(Scalar((uint16_t)opcodes.GetU16 (&offset))); break;
1662 case DW_OP_const2s : stack.push_back(Scalar(( int16_t)opcodes.GetU16 (&offset))); break;
1663 case DW_OP_const4u : stack.push_back(Scalar((uint32_t)opcodes.GetU32 (&offset))); break;
1664 case DW_OP_const4s : stack.push_back(Scalar(( int32_t)opcodes.GetU32 (&offset))); break;
1665 case DW_OP_const8u : stack.push_back(Scalar((uint64_t)opcodes.GetU64 (&offset))); break;
1666 case DW_OP_const8s : stack.push_back(Scalar(( int64_t)opcodes.GetU64 (&offset))); break;
1667 case DW_OP_constu : stack.push_back(Scalar(opcodes.GetULEB128 (&offset))); break;
1668 case DW_OP_consts : stack.push_back(Scalar(opcodes.GetSLEB128 (&offset))); break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001669
1670 //----------------------------------------------------------------------
1671 // OPCODE: DW_OP_dup
1672 // OPERANDS: none
1673 // DESCRIPTION: duplicates the value at the top of the stack
1674 //----------------------------------------------------------------------
1675 case DW_OP_dup:
1676 if (stack.empty())
1677 {
1678 if (error_ptr)
1679 error_ptr->SetErrorString("Expression stack empty for DW_OP_dup.");
1680 return false;
1681 }
1682 else
1683 stack.push_back(stack.back());
1684 break;
1685
1686 //----------------------------------------------------------------------
1687 // OPCODE: DW_OP_drop
1688 // OPERANDS: none
1689 // DESCRIPTION: pops the value at the top of the stack
1690 //----------------------------------------------------------------------
1691 case DW_OP_drop:
1692 if (stack.empty())
1693 {
1694 if (error_ptr)
1695 error_ptr->SetErrorString("Expression stack empty for DW_OP_drop.");
1696 return false;
1697 }
1698 else
1699 stack.pop_back();
1700 break;
1701
1702 //----------------------------------------------------------------------
1703 // OPCODE: DW_OP_over
1704 // OPERANDS: none
1705 // DESCRIPTION: Duplicates the entry currently second in the stack at
1706 // the top of the stack.
1707 //----------------------------------------------------------------------
1708 case DW_OP_over:
1709 if (stack.size() < 2)
1710 {
1711 if (error_ptr)
1712 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_over.");
1713 return false;
1714 }
1715 else
1716 stack.push_back(stack[stack.size() - 2]);
1717 break;
1718
1719
1720 //----------------------------------------------------------------------
1721 // OPCODE: DW_OP_pick
1722 // OPERANDS: uint8_t index into the current stack
1723 // DESCRIPTION: The stack entry with the specified index (0 through 255,
1724 // inclusive) is pushed on the stack
1725 //----------------------------------------------------------------------
1726 case DW_OP_pick:
1727 {
1728 uint8_t pick_idx = opcodes.GetU8(&offset);
1729 if (pick_idx < stack.size())
1730 stack.push_back(stack[pick_idx]);
1731 else
1732 {
1733 if (error_ptr)
1734 error_ptr->SetErrorStringWithFormat("Index %u out of range for DW_OP_pick.\n", pick_idx);
1735 return false;
1736 }
1737 }
1738 break;
1739
1740 //----------------------------------------------------------------------
1741 // OPCODE: DW_OP_swap
1742 // OPERANDS: none
1743 // DESCRIPTION: swaps the top two stack entries. The entry at the top
1744 // of the stack becomes the second stack entry, and the second entry
1745 // becomes the top of the stack
1746 //----------------------------------------------------------------------
1747 case DW_OP_swap:
1748 if (stack.size() < 2)
1749 {
1750 if (error_ptr)
1751 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_swap.");
1752 return false;
1753 }
1754 else
1755 {
1756 tmp = stack.back();
1757 stack.back() = stack[stack.size() - 2];
1758 stack[stack.size() - 2] = tmp;
1759 }
1760 break;
1761
1762 //----------------------------------------------------------------------
1763 // OPCODE: DW_OP_rot
1764 // OPERANDS: none
1765 // DESCRIPTION: Rotates the first three stack entries. The entry at
1766 // the top of the stack becomes the third stack entry, the second
1767 // entry becomes the top of the stack, and the third entry becomes
1768 // the second entry.
1769 //----------------------------------------------------------------------
1770 case DW_OP_rot:
1771 if (stack.size() < 3)
1772 {
1773 if (error_ptr)
1774 error_ptr->SetErrorString("Expression stack needs at least 3 items for DW_OP_rot.");
1775 return false;
1776 }
1777 else
1778 {
1779 size_t last_idx = stack.size() - 1;
1780 Value old_top = stack[last_idx];
1781 stack[last_idx] = stack[last_idx - 1];
1782 stack[last_idx - 1] = stack[last_idx - 2];
1783 stack[last_idx - 2] = old_top;
1784 }
1785 break;
1786
1787 //----------------------------------------------------------------------
1788 // OPCODE: DW_OP_abs
1789 // OPERANDS: none
1790 // DESCRIPTION: pops the top stack entry, interprets it as a signed
1791 // value and pushes its absolute value. If the absolute value can not be
1792 // represented, the result is undefined.
1793 //----------------------------------------------------------------------
1794 case DW_OP_abs:
1795 if (stack.empty())
1796 {
1797 if (error_ptr)
1798 error_ptr->SetErrorString("Expression stack needs at least 1 item for DW_OP_abs.");
1799 return false;
1800 }
Greg Clayton57ee3062013-07-11 22:46:58 +00001801 else if (stack.back().ResolveValue(exe_ctx).AbsoluteValue() == false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001802 {
1803 if (error_ptr)
1804 error_ptr->SetErrorString("Failed to take the absolute value of the first stack item.");
1805 return false;
1806 }
1807 break;
1808
1809 //----------------------------------------------------------------------
1810 // OPCODE: DW_OP_and
1811 // OPERANDS: none
1812 // DESCRIPTION: pops the top two stack values, performs a bitwise and
1813 // operation on the two, and pushes the result.
1814 //----------------------------------------------------------------------
1815 case DW_OP_and:
1816 if (stack.size() < 2)
1817 {
1818 if (error_ptr)
1819 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_and.");
1820 return false;
1821 }
1822 else
1823 {
1824 tmp = stack.back();
1825 stack.pop_back();
Greg Clayton57ee3062013-07-11 22:46:58 +00001826 stack.back().ResolveValue(exe_ctx) = stack.back().ResolveValue(exe_ctx) & tmp.ResolveValue(exe_ctx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001827 }
1828 break;
1829
1830 //----------------------------------------------------------------------
1831 // OPCODE: DW_OP_div
1832 // OPERANDS: none
1833 // DESCRIPTION: pops the top two stack values, divides the former second
1834 // entry by the former top of the stack using signed division, and
1835 // pushes the result.
1836 //----------------------------------------------------------------------
1837 case DW_OP_div:
1838 if (stack.size() < 2)
1839 {
1840 if (error_ptr)
1841 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_div.");
1842 return false;
1843 }
1844 else
1845 {
1846 tmp = stack.back();
Greg Clayton57ee3062013-07-11 22:46:58 +00001847 if (tmp.ResolveValue(exe_ctx).IsZero())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001848 {
1849 if (error_ptr)
1850 error_ptr->SetErrorString("Divide by zero.");
1851 return false;
1852 }
1853 else
1854 {
1855 stack.pop_back();
Greg Clayton57ee3062013-07-11 22:46:58 +00001856 stack.back() = stack.back().ResolveValue(exe_ctx) / tmp.ResolveValue(exe_ctx);
1857 if (!stack.back().ResolveValue(exe_ctx).IsValid())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001858 {
1859 if (error_ptr)
1860 error_ptr->SetErrorString("Divide failed.");
1861 return false;
1862 }
1863 }
1864 }
1865 break;
1866
1867 //----------------------------------------------------------------------
1868 // OPCODE: DW_OP_minus
1869 // OPERANDS: none
1870 // DESCRIPTION: pops the top two stack values, subtracts the former top
1871 // of the stack from the former second entry, and pushes the result.
1872 //----------------------------------------------------------------------
1873 case DW_OP_minus:
1874 if (stack.size() < 2)
1875 {
1876 if (error_ptr)
1877 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_minus.");
1878 return false;
1879 }
1880 else
1881 {
1882 tmp = stack.back();
1883 stack.pop_back();
Greg Clayton57ee3062013-07-11 22:46:58 +00001884 stack.back().ResolveValue(exe_ctx) = stack.back().ResolveValue(exe_ctx) - tmp.ResolveValue(exe_ctx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001885 }
1886 break;
1887
1888 //----------------------------------------------------------------------
1889 // OPCODE: DW_OP_mod
1890 // OPERANDS: none
1891 // DESCRIPTION: pops the top two stack values and pushes the result of
1892 // the calculation: former second stack entry modulo the former top of
1893 // the stack.
1894 //----------------------------------------------------------------------
1895 case DW_OP_mod:
1896 if (stack.size() < 2)
1897 {
1898 if (error_ptr)
1899 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_mod.");
1900 return false;
1901 }
1902 else
1903 {
1904 tmp = stack.back();
1905 stack.pop_back();
Greg Clayton57ee3062013-07-11 22:46:58 +00001906 stack.back().ResolveValue(exe_ctx) = stack.back().ResolveValue(exe_ctx) % tmp.ResolveValue(exe_ctx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001907 }
1908 break;
1909
1910
1911 //----------------------------------------------------------------------
1912 // OPCODE: DW_OP_mul
1913 // OPERANDS: none
1914 // DESCRIPTION: pops the top two stack entries, multiplies them
1915 // together, and pushes the result.
1916 //----------------------------------------------------------------------
1917 case DW_OP_mul:
1918 if (stack.size() < 2)
1919 {
1920 if (error_ptr)
1921 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_mul.");
1922 return false;
1923 }
1924 else
1925 {
1926 tmp = stack.back();
1927 stack.pop_back();
Greg Clayton57ee3062013-07-11 22:46:58 +00001928 stack.back().ResolveValue(exe_ctx) = stack.back().ResolveValue(exe_ctx) * tmp.ResolveValue(exe_ctx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001929 }
1930 break;
1931
1932 //----------------------------------------------------------------------
1933 // OPCODE: DW_OP_neg
1934 // OPERANDS: none
1935 // DESCRIPTION: pops the top stack entry, and pushes its negation.
1936 //----------------------------------------------------------------------
1937 case DW_OP_neg:
1938 if (stack.empty())
1939 {
1940 if (error_ptr)
1941 error_ptr->SetErrorString("Expression stack needs at least 1 item for DW_OP_neg.");
1942 return false;
1943 }
1944 else
1945 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001946 if (stack.back().ResolveValue(exe_ctx).UnaryNegate() == false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001947 {
1948 if (error_ptr)
1949 error_ptr->SetErrorString("Unary negate failed.");
1950 return false;
1951 }
1952 }
1953 break;
1954
1955 //----------------------------------------------------------------------
1956 // OPCODE: DW_OP_not
1957 // OPERANDS: none
1958 // DESCRIPTION: pops the top stack entry, and pushes its bitwise
1959 // complement
1960 //----------------------------------------------------------------------
1961 case DW_OP_not:
1962 if (stack.empty())
1963 {
1964 if (error_ptr)
1965 error_ptr->SetErrorString("Expression stack needs at least 1 item for DW_OP_not.");
1966 return false;
1967 }
1968 else
1969 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001970 if (stack.back().ResolveValue(exe_ctx).OnesComplement() == false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001971 {
1972 if (error_ptr)
1973 error_ptr->SetErrorString("Logical NOT failed.");
1974 return false;
1975 }
1976 }
1977 break;
1978
1979 //----------------------------------------------------------------------
1980 // OPCODE: DW_OP_or
1981 // OPERANDS: none
1982 // DESCRIPTION: pops the top two stack entries, performs a bitwise or
1983 // operation on the two, and pushes the result.
1984 //----------------------------------------------------------------------
1985 case DW_OP_or:
1986 if (stack.size() < 2)
1987 {
1988 if (error_ptr)
1989 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_or.");
1990 return false;
1991 }
1992 else
1993 {
1994 tmp = stack.back();
1995 stack.pop_back();
Greg Clayton57ee3062013-07-11 22:46:58 +00001996 stack.back().ResolveValue(exe_ctx) = stack.back().ResolveValue(exe_ctx) | tmp.ResolveValue(exe_ctx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001997 }
1998 break;
1999
2000 //----------------------------------------------------------------------
2001 // OPCODE: DW_OP_plus
2002 // OPERANDS: none
2003 // DESCRIPTION: pops the top two stack entries, adds them together, and
2004 // pushes the result.
2005 //----------------------------------------------------------------------
2006 case DW_OP_plus:
2007 if (stack.size() < 2)
2008 {
2009 if (error_ptr)
2010 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_plus.");
2011 return false;
2012 }
2013 else
2014 {
2015 tmp = stack.back();
2016 stack.pop_back();
Greg Clayton57ee3062013-07-11 22:46:58 +00002017 stack.back().ResolveValue(exe_ctx) = stack.back().ResolveValue(exe_ctx) + tmp.ResolveValue(exe_ctx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002018 }
2019 break;
2020
2021 //----------------------------------------------------------------------
2022 // OPCODE: DW_OP_plus_uconst
2023 // OPERANDS: none
2024 // DESCRIPTION: pops the top stack entry, adds it to the unsigned LEB128
2025 // constant operand and pushes the result.
2026 //----------------------------------------------------------------------
2027 case DW_OP_plus_uconst:
2028 if (stack.empty())
2029 {
2030 if (error_ptr)
2031 error_ptr->SetErrorString("Expression stack needs at least 1 item for DW_OP_plus_uconst.");
2032 return false;
2033 }
2034 else
2035 {
Greg Claytonc7bece562013-01-25 18:06:21 +00002036 const uint64_t uconst_value = opcodes.GetULEB128(&offset);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002037 // Implicit conversion from a UINT to a Scalar...
Greg Clayton57ee3062013-07-11 22:46:58 +00002038 stack.back().ResolveValue(exe_ctx) += uconst_value;
2039 if (!stack.back().ResolveValue(exe_ctx).IsValid())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002040 {
2041 if (error_ptr)
2042 error_ptr->SetErrorString("DW_OP_plus_uconst failed.");
2043 return false;
2044 }
2045 }
2046 break;
2047
2048 //----------------------------------------------------------------------
2049 // OPCODE: DW_OP_shl
2050 // OPERANDS: none
2051 // DESCRIPTION: pops the top two stack entries, shifts the former
2052 // second entry left by the number of bits specified by the former top
2053 // of the stack, and pushes the result.
2054 //----------------------------------------------------------------------
2055 case DW_OP_shl:
2056 if (stack.size() < 2)
2057 {
2058 if (error_ptr)
2059 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_shl.");
2060 return false;
2061 }
2062 else
2063 {
2064 tmp = stack.back();
2065 stack.pop_back();
Greg Clayton57ee3062013-07-11 22:46:58 +00002066 stack.back().ResolveValue(exe_ctx) <<= tmp.ResolveValue(exe_ctx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002067 }
2068 break;
2069
2070 //----------------------------------------------------------------------
2071 // OPCODE: DW_OP_shr
2072 // OPERANDS: none
2073 // DESCRIPTION: pops the top two stack entries, shifts the former second
2074 // entry right logically (filling with zero bits) by the number of bits
2075 // specified by the former top of the stack, and pushes the result.
2076 //----------------------------------------------------------------------
2077 case DW_OP_shr:
2078 if (stack.size() < 2)
2079 {
2080 if (error_ptr)
2081 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_shr.");
2082 return false;
2083 }
2084 else
2085 {
2086 tmp = stack.back();
2087 stack.pop_back();
Greg Clayton57ee3062013-07-11 22:46:58 +00002088 if (stack.back().ResolveValue(exe_ctx).ShiftRightLogical(tmp.ResolveValue(exe_ctx)) == false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002089 {
2090 if (error_ptr)
2091 error_ptr->SetErrorString("DW_OP_shr failed.");
2092 return false;
2093 }
2094 }
2095 break;
2096
2097 //----------------------------------------------------------------------
2098 // OPCODE: DW_OP_shra
2099 // OPERANDS: none
2100 // DESCRIPTION: pops the top two stack entries, shifts the former second
2101 // entry right arithmetically (divide the magnitude by 2, keep the same
2102 // sign for the result) by the number of bits specified by the former
2103 // top of the stack, and pushes the result.
2104 //----------------------------------------------------------------------
2105 case DW_OP_shra:
2106 if (stack.size() < 2)
2107 {
2108 if (error_ptr)
2109 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_shra.");
2110 return false;
2111 }
2112 else
2113 {
2114 tmp = stack.back();
2115 stack.pop_back();
Greg Clayton57ee3062013-07-11 22:46:58 +00002116 stack.back().ResolveValue(exe_ctx) >>= tmp.ResolveValue(exe_ctx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002117 }
2118 break;
2119
2120 //----------------------------------------------------------------------
2121 // OPCODE: DW_OP_xor
2122 // OPERANDS: none
2123 // DESCRIPTION: pops the top two stack entries, performs the bitwise
2124 // exclusive-or operation on the two, and pushes the result.
2125 //----------------------------------------------------------------------
2126 case DW_OP_xor:
2127 if (stack.size() < 2)
2128 {
2129 if (error_ptr)
2130 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_xor.");
2131 return false;
2132 }
2133 else
2134 {
2135 tmp = stack.back();
2136 stack.pop_back();
Greg Clayton57ee3062013-07-11 22:46:58 +00002137 stack.back().ResolveValue(exe_ctx) = stack.back().ResolveValue(exe_ctx) ^ tmp.ResolveValue(exe_ctx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002138 }
2139 break;
2140
2141
2142 //----------------------------------------------------------------------
2143 // OPCODE: DW_OP_skip
2144 // OPERANDS: int16_t
2145 // DESCRIPTION: An unconditional branch. Its single operand is a 2-byte
2146 // signed integer constant. The 2-byte constant is the number of bytes
2147 // of the DWARF expression to skip forward or backward from the current
2148 // operation, beginning after the 2-byte constant.
2149 //----------------------------------------------------------------------
2150 case DW_OP_skip:
2151 {
2152 int16_t skip_offset = (int16_t)opcodes.GetU16(&offset);
Greg Claytonc7bece562013-01-25 18:06:21 +00002153 lldb::offset_t new_offset = offset + skip_offset;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002154 if (new_offset >= opcodes_offset && new_offset < end_offset)
2155 offset = new_offset;
2156 else
2157 {
2158 if (error_ptr)
2159 error_ptr->SetErrorString("Invalid opcode offset in DW_OP_skip.");
2160 return false;
2161 }
2162 }
2163 break;
2164
2165 //----------------------------------------------------------------------
2166 // OPCODE: DW_OP_bra
2167 // OPERANDS: int16_t
2168 // DESCRIPTION: A conditional branch. Its single operand is a 2-byte
2169 // signed integer constant. This operation pops the top of stack. If
2170 // the value popped is not the constant 0, the 2-byte constant operand
2171 // is the number of bytes of the DWARF expression to skip forward or
2172 // backward from the current operation, beginning after the 2-byte
2173 // constant.
2174 //----------------------------------------------------------------------
2175 case DW_OP_bra:
2176 {
2177 tmp = stack.back();
2178 stack.pop_back();
2179 int16_t bra_offset = (int16_t)opcodes.GetU16(&offset);
2180 Scalar zero(0);
Greg Clayton57ee3062013-07-11 22:46:58 +00002181 if (tmp.ResolveValue(exe_ctx) != zero)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002182 {
Greg Claytonc7bece562013-01-25 18:06:21 +00002183 lldb::offset_t new_offset = offset + bra_offset;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002184 if (new_offset >= opcodes_offset && new_offset < end_offset)
2185 offset = new_offset;
2186 else
2187 {
2188 if (error_ptr)
2189 error_ptr->SetErrorString("Invalid opcode offset in DW_OP_bra.");
2190 return false;
2191 }
2192 }
2193 }
2194 break;
2195
2196 //----------------------------------------------------------------------
2197 // OPCODE: DW_OP_eq
2198 // OPERANDS: none
2199 // DESCRIPTION: pops the top two stack values, compares using the
2200 // equals (==) operator.
2201 // STACK RESULT: push the constant value 1 onto the stack if the result
2202 // of the operation is true or the constant value 0 if the result of the
2203 // operation is false.
2204 //----------------------------------------------------------------------
2205 case DW_OP_eq:
2206 if (stack.size() < 2)
2207 {
2208 if (error_ptr)
2209 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_eq.");
2210 return false;
2211 }
2212 else
2213 {
2214 tmp = stack.back();
2215 stack.pop_back();
Greg Clayton57ee3062013-07-11 22:46:58 +00002216 stack.back().ResolveValue(exe_ctx) = stack.back().ResolveValue(exe_ctx) == tmp.ResolveValue(exe_ctx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002217 }
2218 break;
2219
2220 //----------------------------------------------------------------------
2221 // OPCODE: DW_OP_ge
2222 // OPERANDS: none
2223 // DESCRIPTION: pops the top two stack values, compares using the
2224 // greater than or equal to (>=) operator.
2225 // STACK RESULT: push the constant value 1 onto the stack if the result
2226 // of the operation is true or the constant value 0 if the result of the
2227 // operation is false.
2228 //----------------------------------------------------------------------
2229 case DW_OP_ge:
2230 if (stack.size() < 2)
2231 {
2232 if (error_ptr)
2233 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_ge.");
2234 return false;
2235 }
2236 else
2237 {
2238 tmp = stack.back();
2239 stack.pop_back();
Greg Clayton57ee3062013-07-11 22:46:58 +00002240 stack.back().ResolveValue(exe_ctx) = stack.back().ResolveValue(exe_ctx) >= tmp.ResolveValue(exe_ctx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002241 }
2242 break;
2243
2244 //----------------------------------------------------------------------
2245 // OPCODE: DW_OP_gt
2246 // OPERANDS: none
2247 // DESCRIPTION: pops the top two stack values, compares using the
2248 // greater than (>) operator.
2249 // STACK RESULT: push the constant value 1 onto the stack if the result
2250 // of the operation is true or the constant value 0 if the result of the
2251 // operation is false.
2252 //----------------------------------------------------------------------
2253 case DW_OP_gt:
2254 if (stack.size() < 2)
2255 {
2256 if (error_ptr)
2257 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_gt.");
2258 return false;
2259 }
2260 else
2261 {
2262 tmp = stack.back();
2263 stack.pop_back();
Greg Clayton57ee3062013-07-11 22:46:58 +00002264 stack.back().ResolveValue(exe_ctx) = stack.back().ResolveValue(exe_ctx) > tmp.ResolveValue(exe_ctx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002265 }
2266 break;
2267
2268 //----------------------------------------------------------------------
2269 // OPCODE: DW_OP_le
2270 // OPERANDS: none
2271 // DESCRIPTION: pops the top two stack values, compares using the
2272 // less than or equal to (<=) operator.
2273 // STACK RESULT: push the constant value 1 onto the stack if the result
2274 // of the operation is true or the constant value 0 if the result of the
2275 // operation is false.
2276 //----------------------------------------------------------------------
2277 case DW_OP_le:
2278 if (stack.size() < 2)
2279 {
2280 if (error_ptr)
2281 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_le.");
2282 return false;
2283 }
2284 else
2285 {
2286 tmp = stack.back();
2287 stack.pop_back();
Greg Clayton57ee3062013-07-11 22:46:58 +00002288 stack.back().ResolveValue(exe_ctx) = stack.back().ResolveValue(exe_ctx) <= tmp.ResolveValue(exe_ctx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002289 }
2290 break;
2291
2292 //----------------------------------------------------------------------
2293 // OPCODE: DW_OP_lt
2294 // OPERANDS: none
2295 // DESCRIPTION: pops the top two stack values, compares using the
2296 // less than (<) operator.
2297 // STACK RESULT: push the constant value 1 onto the stack if the result
2298 // of the operation is true or the constant value 0 if the result of the
2299 // operation is false.
2300 //----------------------------------------------------------------------
2301 case DW_OP_lt:
2302 if (stack.size() < 2)
2303 {
2304 if (error_ptr)
2305 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_lt.");
2306 return false;
2307 }
2308 else
2309 {
2310 tmp = stack.back();
2311 stack.pop_back();
Greg Clayton57ee3062013-07-11 22:46:58 +00002312 stack.back().ResolveValue(exe_ctx) = stack.back().ResolveValue(exe_ctx) < tmp.ResolveValue(exe_ctx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002313 }
2314 break;
2315
2316 //----------------------------------------------------------------------
2317 // OPCODE: DW_OP_ne
2318 // OPERANDS: none
2319 // DESCRIPTION: pops the top two stack values, compares using the
2320 // not equal (!=) operator.
2321 // STACK RESULT: push the constant value 1 onto the stack if the result
2322 // of the operation is true or the constant value 0 if the result of the
2323 // operation is false.
2324 //----------------------------------------------------------------------
2325 case DW_OP_ne:
2326 if (stack.size() < 2)
2327 {
2328 if (error_ptr)
2329 error_ptr->SetErrorString("Expression stack needs at least 2 items for DW_OP_ne.");
2330 return false;
2331 }
2332 else
2333 {
2334 tmp = stack.back();
2335 stack.pop_back();
Greg Clayton57ee3062013-07-11 22:46:58 +00002336 stack.back().ResolveValue(exe_ctx) = stack.back().ResolveValue(exe_ctx) != tmp.ResolveValue(exe_ctx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002337 }
2338 break;
2339
2340 //----------------------------------------------------------------------
2341 // OPCODE: DW_OP_litn
2342 // OPERANDS: none
2343 // DESCRIPTION: encode the unsigned literal values from 0 through 31.
2344 // STACK RESULT: push the unsigned literal constant value onto the top
2345 // of the stack.
2346 //----------------------------------------------------------------------
2347 case DW_OP_lit0:
2348 case DW_OP_lit1:
2349 case DW_OP_lit2:
2350 case DW_OP_lit3:
2351 case DW_OP_lit4:
2352 case DW_OP_lit5:
2353 case DW_OP_lit6:
2354 case DW_OP_lit7:
2355 case DW_OP_lit8:
2356 case DW_OP_lit9:
2357 case DW_OP_lit10:
2358 case DW_OP_lit11:
2359 case DW_OP_lit12:
2360 case DW_OP_lit13:
2361 case DW_OP_lit14:
2362 case DW_OP_lit15:
2363 case DW_OP_lit16:
2364 case DW_OP_lit17:
2365 case DW_OP_lit18:
2366 case DW_OP_lit19:
2367 case DW_OP_lit20:
2368 case DW_OP_lit21:
2369 case DW_OP_lit22:
2370 case DW_OP_lit23:
2371 case DW_OP_lit24:
2372 case DW_OP_lit25:
2373 case DW_OP_lit26:
2374 case DW_OP_lit27:
2375 case DW_OP_lit28:
2376 case DW_OP_lit29:
2377 case DW_OP_lit30:
2378 case DW_OP_lit31:
Greg Clayton644247c2011-07-07 01:59:51 +00002379 stack.push_back(Scalar(op - DW_OP_lit0));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002380 break;
2381
2382 //----------------------------------------------------------------------
2383 // OPCODE: DW_OP_regN
2384 // OPERANDS: none
2385 // DESCRIPTION: Push the value in register n on the top of the stack.
2386 //----------------------------------------------------------------------
2387 case DW_OP_reg0:
2388 case DW_OP_reg1:
2389 case DW_OP_reg2:
2390 case DW_OP_reg3:
2391 case DW_OP_reg4:
2392 case DW_OP_reg5:
2393 case DW_OP_reg6:
2394 case DW_OP_reg7:
2395 case DW_OP_reg8:
2396 case DW_OP_reg9:
2397 case DW_OP_reg10:
2398 case DW_OP_reg11:
2399 case DW_OP_reg12:
2400 case DW_OP_reg13:
2401 case DW_OP_reg14:
2402 case DW_OP_reg15:
2403 case DW_OP_reg16:
2404 case DW_OP_reg17:
2405 case DW_OP_reg18:
2406 case DW_OP_reg19:
2407 case DW_OP_reg20:
2408 case DW_OP_reg21:
2409 case DW_OP_reg22:
2410 case DW_OP_reg23:
2411 case DW_OP_reg24:
2412 case DW_OP_reg25:
2413 case DW_OP_reg26:
2414 case DW_OP_reg27:
2415 case DW_OP_reg28:
2416 case DW_OP_reg29:
2417 case DW_OP_reg30:
2418 case DW_OP_reg31:
2419 {
2420 reg_num = op - DW_OP_reg0;
2421
Jason Molenda2d107dd2010-11-20 01:28:30 +00002422 if (ReadRegisterValueAsScalar (reg_ctx, reg_kind, reg_num, error_ptr, tmp))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002423 stack.push_back(tmp);
2424 else
2425 return false;
2426 }
2427 break;
2428 //----------------------------------------------------------------------
2429 // OPCODE: DW_OP_regx
2430 // OPERANDS:
2431 // ULEB128 literal operand that encodes the register.
2432 // DESCRIPTION: Push the value in register on the top of the stack.
2433 //----------------------------------------------------------------------
2434 case DW_OP_regx:
2435 {
2436 reg_num = opcodes.GetULEB128(&offset);
Jason Molenda2d107dd2010-11-20 01:28:30 +00002437 if (ReadRegisterValueAsScalar (reg_ctx, reg_kind, reg_num, error_ptr, tmp))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002438 stack.push_back(tmp);
2439 else
2440 return false;
2441 }
2442 break;
2443
2444 //----------------------------------------------------------------------
2445 // OPCODE: DW_OP_bregN
2446 // OPERANDS:
2447 // SLEB128 offset from register N
2448 // DESCRIPTION: Value is in memory at the address specified by register
2449 // N plus an offset.
2450 //----------------------------------------------------------------------
2451 case DW_OP_breg0:
2452 case DW_OP_breg1:
2453 case DW_OP_breg2:
2454 case DW_OP_breg3:
2455 case DW_OP_breg4:
2456 case DW_OP_breg5:
2457 case DW_OP_breg6:
2458 case DW_OP_breg7:
2459 case DW_OP_breg8:
2460 case DW_OP_breg9:
2461 case DW_OP_breg10:
2462 case DW_OP_breg11:
2463 case DW_OP_breg12:
2464 case DW_OP_breg13:
2465 case DW_OP_breg14:
2466 case DW_OP_breg15:
2467 case DW_OP_breg16:
2468 case DW_OP_breg17:
2469 case DW_OP_breg18:
2470 case DW_OP_breg19:
2471 case DW_OP_breg20:
2472 case DW_OP_breg21:
2473 case DW_OP_breg22:
2474 case DW_OP_breg23:
2475 case DW_OP_breg24:
2476 case DW_OP_breg25:
2477 case DW_OP_breg26:
2478 case DW_OP_breg27:
2479 case DW_OP_breg28:
2480 case DW_OP_breg29:
2481 case DW_OP_breg30:
2482 case DW_OP_breg31:
2483 {
2484 reg_num = op - DW_OP_breg0;
2485
Jason Molenda2d107dd2010-11-20 01:28:30 +00002486 if (ReadRegisterValueAsScalar (reg_ctx, reg_kind, reg_num, error_ptr, tmp))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002487 {
2488 int64_t breg_offset = opcodes.GetSLEB128(&offset);
Greg Clayton57ee3062013-07-11 22:46:58 +00002489 tmp.ResolveValue(exe_ctx) += (uint64_t)breg_offset;
Sean Callanand1a5e012012-01-06 18:24:47 +00002490 tmp.ClearContext();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002491 stack.push_back(tmp);
2492 stack.back().SetValueType (Value::eValueTypeLoadAddress);
2493 }
2494 else
2495 return false;
2496 }
2497 break;
2498 //----------------------------------------------------------------------
2499 // OPCODE: DW_OP_bregx
2500 // OPERANDS: 2
2501 // ULEB128 literal operand that encodes the register.
2502 // SLEB128 offset from register N
2503 // DESCRIPTION: Value is in memory at the address specified by register
2504 // N plus an offset.
2505 //----------------------------------------------------------------------
2506 case DW_OP_bregx:
2507 {
2508 reg_num = opcodes.GetULEB128(&offset);
2509
Jason Molenda2d107dd2010-11-20 01:28:30 +00002510 if (ReadRegisterValueAsScalar (reg_ctx, reg_kind, reg_num, error_ptr, tmp))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002511 {
2512 int64_t breg_offset = opcodes.GetSLEB128(&offset);
Greg Clayton57ee3062013-07-11 22:46:58 +00002513 tmp.ResolveValue(exe_ctx) += (uint64_t)breg_offset;
Sean Callanand1a5e012012-01-06 18:24:47 +00002514 tmp.ClearContext();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002515 stack.push_back(tmp);
2516 stack.back().SetValueType (Value::eValueTypeLoadAddress);
2517 }
2518 else
2519 return false;
2520 }
2521 break;
2522
2523 case DW_OP_fbreg:
Greg Claytonc14ee322011-09-22 04:58:26 +00002524 if (exe_ctx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002525 {
Greg Claytonc14ee322011-09-22 04:58:26 +00002526 if (frame)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002527 {
Greg Claytonc14ee322011-09-22 04:58:26 +00002528 Scalar value;
2529 if (frame->GetFrameBaseValue(value, error_ptr))
2530 {
2531 int64_t fbreg_offset = opcodes.GetSLEB128(&offset);
2532 value += fbreg_offset;
2533 stack.push_back(value);
2534 stack.back().SetValueType (Value::eValueTypeLoadAddress);
2535 }
2536 else
2537 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002538 }
2539 else
Greg Claytonc14ee322011-09-22 04:58:26 +00002540 {
2541 if (error_ptr)
2542 error_ptr->SetErrorString ("Invalid stack frame in context for DW_OP_fbreg opcode.");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002543 return false;
Greg Claytonc14ee322011-09-22 04:58:26 +00002544 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002545 }
2546 else
2547 {
2548 if (error_ptr)
Greg Claytonc14ee322011-09-22 04:58:26 +00002549 error_ptr->SetErrorStringWithFormat ("NULL execution context for DW_OP_fbreg.\n");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002550 return false;
2551 }
Greg Claytonc14ee322011-09-22 04:58:26 +00002552
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002553 break;
2554
2555 //----------------------------------------------------------------------
2556 // OPCODE: DW_OP_nop
2557 // OPERANDS: none
2558 // DESCRIPTION: A place holder. It has no effect on the location stack
2559 // or any of its values.
2560 //----------------------------------------------------------------------
2561 case DW_OP_nop:
2562 break;
2563
2564 //----------------------------------------------------------------------
2565 // OPCODE: DW_OP_piece
2566 // OPERANDS: 1
2567 // ULEB128: byte size of the piece
2568 // DESCRIPTION: The operand describes the size in bytes of the piece of
2569 // the object referenced by the DWARF expression whose result is at the
2570 // top of the stack. If the piece is located in a register, but does not
2571 // occupy the entire register, the placement of the piece within that
2572 // register is defined by the ABI.
2573 //
2574 // Many compilers store a single variable in sets of registers, or store
2575 // a variable partially in memory and partially in registers.
2576 // DW_OP_piece provides a way of describing how large a part of a
2577 // variable a particular DWARF expression refers to.
2578 //----------------------------------------------------------------------
2579 case DW_OP_piece:
Greg Clayton27407872014-07-12 00:24:33 +00002580 if (stack.size() < 1 ||
2581 (op_piece_offset > 0 && stack.size() < 2))
Greg Clayton7a1bd0b2014-02-12 23:16:19 +00002582 {
Greg Clayton27407872014-07-12 00:24:33 +00002583 // In a multi-piece expression, this means that the current piece is not available.
2584 // We don't have a way to signal partial availabilty.
Greg Clayton7a1bd0b2014-02-12 23:16:19 +00002585 if (error_ptr)
Greg Clayton27407872014-07-12 00:24:33 +00002586 error_ptr->SetErrorString("Partially unavailable DW_OP_piece expressions are not yet supported.");
Greg Clayton7a1bd0b2014-02-12 23:16:19 +00002587 return false;
2588 }
2589 else
2590 {
2591 const uint64_t piece_byte_size = opcodes.GetULEB128(&offset);
2592 switch (stack.back().GetValueType())
2593 {
2594 case Value::eValueTypeScalar:
2595 case Value::eValueTypeFileAddress:
2596 case Value::eValueTypeLoadAddress:
2597 case Value::eValueTypeHostAddress:
2598 {
2599 uint32_t bit_size = piece_byte_size * 8;
2600 uint32_t bit_offset = 0;
2601 if (!stack.back().GetScalar().ExtractBitfield (bit_size, bit_offset))
2602 {
2603 if (error_ptr)
2604 error_ptr->SetErrorStringWithFormat("unable to extract %" PRIu64 " bytes from a %" PRIu64 " byte scalar value.", piece_byte_size, (uint64_t)stack.back().GetScalar().GetByteSize());
2605 return false;
2606 }
Greg Clayton27407872014-07-12 00:24:33 +00002607
2608 // Multiple pieces of a large value are assembled in a memory buffer value.
2609 if (op_piece_offset)
2610 {
2611 Error error;
2612 Scalar cur_piece = stack.back().GetScalar();
2613 stack.pop_back();
2614
2615 switch (stack.back().GetValueType())
2616 {
2617 case Value::eValueTypeScalar:
2618 {
2619 // We already have something on the stack that will becomes the first
2620 // bytes of our buffer, we need to populate these bytes into the buffer
2621 // and then we will add the current bytes to it.
2622
2623 // Promote top of stack to a memory buffer.
2624 Scalar prev_piece = stack.back().GetScalar();
2625 stack.pop_back();
2626 stack.push_back(Value());
2627 Value &piece_value = stack.back();
2628 piece_value.ResizeData(op_piece_offset);
2629 prev_piece.GetAsMemoryData(piece_value.GetBuffer().GetBytes(), op_piece_offset, lldb::endian::InlHostByteOrder(), error);
2630 if (error.Fail())
2631 {
2632 if (error_ptr)
2633 error_ptr->SetErrorString(error.AsCString());
2634 return false;
2635 }
2636 }
2637 // Fall through to host address case...
2638
2639 case Value::eValueTypeHostAddress:
2640 {
2641 if (stack.back().GetBuffer().GetByteSize() != op_piece_offset)
2642 {
2643 if (error_ptr)
2644 error_ptr->SetErrorStringWithFormat ("DW_OP_piece for offset %" PRIu64 " but top of stack is of size %" PRIu64,
2645 op_piece_offset,
2646 stack.back().GetBuffer().GetByteSize());
2647 return false;
2648 }
2649
2650 // Append the current piece to the buffer.
2651 size_t len = op_piece_offset + piece_byte_size;
2652 stack.back().ResizeData(len);
2653 cur_piece.GetAsMemoryData (stack.back().GetBuffer().GetBytes() + op_piece_offset,
2654 piece_byte_size,
2655 lldb::endian::InlHostByteOrder(),
2656 error);
2657 if (error.Fail())
2658 {
2659 if (error_ptr)
2660 error_ptr->SetErrorString(error.AsCString());
2661 return false;
2662 }
2663 }
2664 break;
2665
2666 default:
2667 // Expect top of stack to be a memory buffer.
2668 if (error_ptr)
2669 error_ptr->SetErrorStringWithFormat("DW_OP_piece for offset %" PRIu64 ": top of stack is not a piece", op_piece_offset);
2670 return false;
2671 }
2672
2673 }
2674 op_piece_offset += piece_byte_size;
Greg Clayton7a1bd0b2014-02-12 23:16:19 +00002675 }
2676 break;
2677
2678 case Value::eValueTypeVector:
2679 {
2680 if (stack.back().GetVector().length >= piece_byte_size)
2681 stack.back().GetVector().length = piece_byte_size;
2682 else
2683 {
2684 if (error_ptr)
2685 error_ptr->SetErrorStringWithFormat("unable to extract %" PRIu64 " bytes from a %" PRIu64 " byte vector value.", piece_byte_size, (uint64_t)stack.back().GetVector().length);
2686 return false;
2687 }
2688 }
2689 break;
2690 }
2691 }
2692 break;
2693
2694 case DW_OP_bit_piece: // 0x9d ULEB128 bit size, ULEB128 bit offset (DWARF3);
2695 if (stack.size() < 1)
2696 {
2697 if (error_ptr)
2698 error_ptr->SetErrorString("Expression stack needs at least 1 item for DW_OP_bit_piece.");
2699 return false;
2700 }
2701 else
2702 {
2703 const uint64_t piece_bit_size = opcodes.GetULEB128(&offset);
2704 const uint64_t piece_bit_offset = opcodes.GetULEB128(&offset);
2705 switch (stack.back().GetValueType())
2706 {
2707 case Value::eValueTypeScalar:
2708 case Value::eValueTypeFileAddress:
2709 case Value::eValueTypeLoadAddress:
2710 case Value::eValueTypeHostAddress:
2711 {
2712 if (!stack.back().GetScalar().ExtractBitfield (piece_bit_size, piece_bit_offset))
2713 {
2714 if (error_ptr)
2715 error_ptr->SetErrorStringWithFormat("unable to extract %" PRIu64 " bit value with %" PRIu64 " bit offset from a %" PRIu64 " bit scalar value.",
2716 piece_bit_size,
2717 piece_bit_offset,
2718 (uint64_t)(stack.back().GetScalar().GetByteSize()*8));
2719 return false;
2720 }
2721 }
2722 break;
2723
2724 case Value::eValueTypeVector:
2725 if (error_ptr)
2726 {
2727 error_ptr->SetErrorStringWithFormat ("unable to extract %" PRIu64 " bit value with %" PRIu64 " bit offset from a vector value.",
2728 piece_bit_size,
2729 piece_bit_offset);
2730 }
2731 return false;
2732 }
2733 }
2734 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002735
2736 //----------------------------------------------------------------------
2737 // OPCODE: DW_OP_push_object_address
2738 // OPERANDS: none
2739 // DESCRIPTION: Pushes the address of the object currently being
2740 // evaluated as part of evaluation of a user presented expression.
2741 // This object may correspond to an independent variable described by
2742 // its own DIE or it may be a component of an array, structure, or class
2743 // whose address has been dynamically determined by an earlier step
2744 // during user expression evaluation.
2745 //----------------------------------------------------------------------
2746 case DW_OP_push_object_address:
2747 if (error_ptr)
2748 error_ptr->SetErrorString ("Unimplemented opcode DW_OP_push_object_address.");
2749 return false;
2750
2751 //----------------------------------------------------------------------
2752 // OPCODE: DW_OP_call2
2753 // OPERANDS:
2754 // uint16_t compile unit relative offset of a DIE
2755 // DESCRIPTION: Performs subroutine calls during evaluation
2756 // of a DWARF expression. The operand is the 2-byte unsigned offset
2757 // of a debugging information entry in the current compilation unit.
2758 //
2759 // Operand interpretation is exactly like that for DW_FORM_ref2.
2760 //
2761 // This operation transfers control of DWARF expression evaluation
2762 // to the DW_AT_location attribute of the referenced DIE. If there is
2763 // no such attribute, then there is no effect. Execution of the DWARF
2764 // expression of a DW_AT_location attribute may add to and/or remove from
2765 // values on the stack. Execution returns to the point following the call
2766 // when the end of the attribute is reached. Values on the stack at the
2767 // time of the call may be used as parameters by the called expression
2768 // and values left on the stack by the called expression may be used as
2769 // return values by prior agreement between the calling and called
2770 // expressions.
2771 //----------------------------------------------------------------------
2772 case DW_OP_call2:
2773 if (error_ptr)
2774 error_ptr->SetErrorString ("Unimplemented opcode DW_OP_call2.");
2775 return false;
2776 //----------------------------------------------------------------------
2777 // OPCODE: DW_OP_call4
2778 // OPERANDS: 1
2779 // uint32_t compile unit relative offset of a DIE
2780 // DESCRIPTION: Performs a subroutine call during evaluation of a DWARF
2781 // expression. For DW_OP_call4, the operand is a 4-byte unsigned offset
2782 // of a debugging information entry in the current compilation unit.
2783 //
2784 // Operand interpretation DW_OP_call4 is exactly like that for
2785 // DW_FORM_ref4.
2786 //
2787 // This operation transfers control of DWARF expression evaluation
2788 // to the DW_AT_location attribute of the referenced DIE. If there is
2789 // no such attribute, then there is no effect. Execution of the DWARF
2790 // expression of a DW_AT_location attribute may add to and/or remove from
2791 // values on the stack. Execution returns to the point following the call
2792 // when the end of the attribute is reached. Values on the stack at the
2793 // time of the call may be used as parameters by the called expression
2794 // and values left on the stack by the called expression may be used as
2795 // return values by prior agreement between the calling and called
2796 // expressions.
2797 //----------------------------------------------------------------------
2798 case DW_OP_call4:
2799 if (error_ptr)
2800 error_ptr->SetErrorString ("Unimplemented opcode DW_OP_call4.");
2801 return false;
2802
Andrew Kaylor9e9f1db2013-03-06 21:13:09 +00002803 //----------------------------------------------------------------------
2804 // OPCODE: DW_OP_stack_value
2805 // OPERANDS: None
2806 // DESCRIPTION: Specifies that the object does not exist in memory but
2807 // rather is a constant value. The value from the top of the stack is
2808 // the value to be used. This is the actual object value and not the
2809 // location.
2810 //----------------------------------------------------------------------
2811 case DW_OP_stack_value:
2812 stack.back().SetValueType(Value::eValueTypeScalar);
2813 break;
Ashok Thirumurthi6e264d32013-07-29 16:05:11 +00002814
2815 //----------------------------------------------------------------------
2816 // OPCODE: DW_OP_call_frame_cfa
2817 // OPERANDS: None
2818 // DESCRIPTION: Specifies a DWARF expression that pushes the value of
2819 // the canonical frame address consistent with the call frame information
2820 // located in .debug_frame (or in the FDEs of the eh_frame section).
2821 //----------------------------------------------------------------------
2822 case DW_OP_call_frame_cfa:
2823 if (frame)
2824 {
2825 // Note that we don't have to parse FDEs because this DWARF expression
2826 // is commonly evaluated with a valid stack frame.
2827 StackID id = frame->GetStackID();
2828 addr_t cfa = id.GetCallFrameAddress();
2829 if (cfa != LLDB_INVALID_ADDRESS)
2830 {
2831 stack.push_back(Scalar(cfa));
2832 stack.back().SetValueType (Value::eValueTypeHostAddress);
2833 }
2834 else
2835 if (error_ptr)
2836 error_ptr->SetErrorString ("Stack frame does not include a canonical frame address for DW_OP_call_frame_cfa opcode.");
2837 }
2838 else
2839 {
2840 if (error_ptr)
2841 error_ptr->SetErrorString ("Invalid stack frame in context for DW_OP_call_frame_cfa opcode.");
2842 return false;
2843 }
2844 break;
Richard Mitton0a558352013-10-17 21:14:00 +00002845
2846 //----------------------------------------------------------------------
2847 // OPCODE: DW_OP_GNU_push_tls_address
2848 // OPERANDS: none
2849 // DESCRIPTION: Pops a TLS offset from the stack, converts it to
2850 // an absolute value, and pushes it back on.
2851 //----------------------------------------------------------------------
2852 case DW_OP_GNU_push_tls_address:
2853 {
2854 if (stack.size() < 1)
2855 {
2856 if (error_ptr)
2857 error_ptr->SetErrorString("DW_OP_GNU_push_tls_address needs an argument.");
2858 return false;
2859 }
2860
2861 if (!exe_ctx || !opcode_ctx)
2862 {
2863 if (error_ptr)
2864 error_ptr->SetErrorString("No context to evaluate TLS within.");
2865 return false;
2866 }
2867
2868 Thread *thread = exe_ctx->GetThreadPtr();
2869 if (!thread)
2870 {
2871 if (error_ptr)
2872 error_ptr->SetErrorString("No thread to evaluate TLS within.");
2873 return false;
2874 }
2875
2876 // Lookup the TLS block address for this thread and module.
2877 addr_t tls_addr = thread->GetThreadLocalData (opcode_ctx);
2878
2879 if (tls_addr == LLDB_INVALID_ADDRESS)
2880 {
2881 if (error_ptr)
2882 error_ptr->SetErrorString ("No TLS data currently exists for this thread.");
2883 return false;
2884 }
2885
2886 // Convert the TLS offset into the absolute address.
2887 Scalar tmp = stack.back().ResolveValue(exe_ctx);
2888 stack.back() = tmp + tls_addr;
2889 stack.back().SetValueType (Value::eValueTypeLoadAddress);
2890 }
2891 break;
2892
Daniel Malea8f0c4462013-07-30 21:26:24 +00002893 default:
Ashok Thirumurthi3e0afb82013-07-31 03:56:45 +00002894 if (log)
2895 log->Printf("Unhandled opcode %s in DWARFExpression.", DW_OP_value_to_name(op));
2896 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002897 }
2898 }
2899
2900 if (stack.empty())
2901 {
2902 if (error_ptr)
2903 error_ptr->SetErrorString ("Stack empty after evaluation.");
2904 return false;
2905 }
Sean Callanan7dd98122011-10-14 20:34:21 +00002906 else if (log && log->GetVerbose())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002907 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002908 size_t count = stack.size();
Greg Clayton6fea17e2014-03-03 19:15:20 +00002909 log->Printf("Stack after operation has %" PRIu64 " values:", (uint64_t)count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002910 for (size_t i=0; i<count; ++i)
2911 {
2912 StreamString new_value;
Daniel Malead01b2952012-11-29 21:49:15 +00002913 new_value.Printf("[%" PRIu64 "]", (uint64_t)i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002914 stack[i].Dump(&new_value);
Sean Callananf06ba8d2010-06-23 00:47:48 +00002915 log->Printf(" %s", new_value.GetData());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002916 }
2917 }
2918
2919 result = stack.back();
2920 return true; // Return true on success
2921}
2922