blob: 366a11526d2d492cf2afba75e707d3481eb4445e [file] [log] [blame]
Sean Callanan3bfdaa22011-09-15 02:13:07 +00001//===-- IRInterpreter.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
Sean Callananfefe43c2013-04-25 18:55:45 +000010#include "lldb/Core/DataExtractor.h"
11#include "lldb/Core/Error.h"
Sean Callanan3bfdaa22011-09-15 02:13:07 +000012#include "lldb/Core/Log.h"
Sean Callananfefe43c2013-04-25 18:55:45 +000013#include "lldb/Core/Scalar.h"
14#include "lldb/Core/StreamString.h"
15#include "lldb/Expression/IRMemoryMap.h"
Sean Callanan3bfdaa22011-09-15 02:13:07 +000016#include "lldb/Expression/IRInterpreter.h"
17
Chandler Carruth1e157582013-01-02 12:20:07 +000018#include "llvm/IR/Constants.h"
Sean Callananfefe43c2013-04-25 18:55:45 +000019#include "llvm/IR/DataLayout.h"
Chandler Carruth1e157582013-01-02 12:20:07 +000020#include "llvm/IR/Function.h"
21#include "llvm/IR/Instructions.h"
22#include "llvm/IR/Module.h"
Sean Callanan3bfdaa22011-09-15 02:13:07 +000023#include "llvm/Support/raw_ostream.h"
Sean Callanan3bfdaa22011-09-15 02:13:07 +000024
25#include <map>
26
27using namespace llvm;
28
Sean Callanan3bfdaa22011-09-15 02:13:07 +000029static std::string
30PrintValue(const Value *value, bool truncate = false)
31{
32 std::string s;
33 raw_string_ostream rso(s);
34 value->print(rso);
35 rso.flush();
36 if (truncate)
37 s.resize(s.length() - 1);
38
39 size_t offset;
40 while ((offset = s.find('\n')) != s.npos)
41 s.erase(offset, 1);
42 while (s[0] == ' ' || s[0] == '\t')
43 s.erase(0, 1);
44
45 return s;
46}
47
48static std::string
49PrintType(const Type *type, bool truncate = false)
50{
51 std::string s;
52 raw_string_ostream rso(s);
53 type->print(rso);
54 rso.flush();
55 if (truncate)
56 s.resize(s.length() - 1);
57 return s;
58}
59
Sean Callanan3bfdaa22011-09-15 02:13:07 +000060class InterpreterStackFrame
61{
62public:
Sean Callanan08052af2013-04-17 07:50:58 +000063 typedef std::map <const Value*, lldb::addr_t> ValueMap;
64
Sean Callanan3bfdaa22011-09-15 02:13:07 +000065 ValueMap m_values;
Micah Villmow8468dbe2012-10-08 16:28:57 +000066 DataLayout &m_target_data;
Sean Callanan179b5482013-04-16 23:49:09 +000067 lldb_private::IRMemoryMap &m_memory_map;
Sean Callanan3bfdaa22011-09-15 02:13:07 +000068 const BasicBlock *m_bb;
69 BasicBlock::const_iterator m_ii;
70 BasicBlock::const_iterator m_ie;
71
Sean Callanan1582ee62013-04-18 22:06:33 +000072 lldb::addr_t m_frame_process_address;
73 size_t m_frame_size;
74 lldb::addr_t m_stack_pointer;
75
Sean Callanan3bfdaa22011-09-15 02:13:07 +000076 lldb::ByteOrder m_byte_order;
77 size_t m_addr_byte_size;
78
Micah Villmow8468dbe2012-10-08 16:28:57 +000079 InterpreterStackFrame (DataLayout &target_data,
Sean Callanandf565402013-04-27 02:19:33 +000080 lldb_private::IRMemoryMap &memory_map,
81 lldb::addr_t stack_frame_bottom,
82 lldb::addr_t stack_frame_top) :
Daniel Dunbara08823f2011-10-31 22:50:49 +000083 m_target_data (target_data),
Sean Callanan179b5482013-04-16 23:49:09 +000084 m_memory_map (memory_map)
Sean Callanan3bfdaa22011-09-15 02:13:07 +000085 {
86 m_byte_order = (target_data.isLittleEndian() ? lldb::eByteOrderLittle : lldb::eByteOrderBig);
Sean Callanan95769bf2012-10-11 22:00:52 +000087 m_addr_byte_size = (target_data.getPointerSize(0));
Sean Callanandf565402013-04-27 02:19:33 +000088
89 m_frame_process_address = stack_frame_bottom;
90 m_frame_size = stack_frame_top - stack_frame_bottom;
91 m_stack_pointer = stack_frame_top;
Sean Callanan1582ee62013-04-18 22:06:33 +000092 }
93
94 ~InterpreterStackFrame ()
95 {
Sean Callanan3bfdaa22011-09-15 02:13:07 +000096 }
97
98 void Jump (const BasicBlock *bb)
99 {
100 m_bb = bb;
101 m_ii = m_bb->begin();
102 m_ie = m_bb->end();
103 }
104
Sean Callanan3bfdaa22011-09-15 02:13:07 +0000105 std::string SummarizeValue (const Value *value)
106 {
107 lldb_private::StreamString ss;
108
109 ss.Printf("%s", PrintValue(value).c_str());
110
111 ValueMap::iterator i = m_values.find(value);
112
113 if (i != m_values.end())
114 {
Sean Callanan08052af2013-04-17 07:50:58 +0000115 lldb::addr_t addr = i->second;
Sean Callanan3bfdaa22011-09-15 02:13:07 +0000116
Sean Callanan08052af2013-04-17 07:50:58 +0000117 ss.Printf(" 0x%llx", (unsigned long long)addr);
Sean Callanan3bfdaa22011-09-15 02:13:07 +0000118 }
119
120 return ss.GetString();
121 }
122
123 bool AssignToMatchType (lldb_private::Scalar &scalar, uint64_t u64value, Type *type)
124 {
125 size_t type_size = m_target_data.getTypeStoreSize(type);
126
127 switch (type_size)
128 {
129 case 1:
130 scalar = (uint8_t)u64value;
131 break;
132 case 2:
133 scalar = (uint16_t)u64value;
134 break;
135 case 4:
136 scalar = (uint32_t)u64value;
137 break;
138 case 8:
139 scalar = (uint64_t)u64value;
140 break;
141 default:
142 return false;
143 }
144
145 return true;
146 }
147
148 bool EvaluateValue (lldb_private::Scalar &scalar, const Value *value, Module &module)
149 {
150 const Constant *constant = dyn_cast<Constant>(value);
151
152 if (constant)
153 {
154 if (const ConstantInt *constant_int = dyn_cast<ConstantInt>(constant))
155 {
156 return AssignToMatchType(scalar, constant_int->getLimitedValue(), value->getType());
157 }
158 }
159 else
160 {
Sean Callanan08052af2013-04-17 07:50:58 +0000161 lldb::addr_t process_address = ResolveValue(value, module);
162 size_t value_size = m_target_data.getTypeStoreSize(value->getType());
163
164 lldb_private::DataExtractor value_extractor;
165 lldb_private::Error extract_error;
Sean Callanan3bfdaa22011-09-15 02:13:07 +0000166
Sean Callanan08052af2013-04-17 07:50:58 +0000167 m_memory_map.GetMemoryData(value_extractor, process_address, value_size, extract_error);
168
169 if (!extract_error.Success())
Sean Callanan3bfdaa22011-09-15 02:13:07 +0000170 return false;
171
Greg Claytonc7bece562013-01-25 18:06:21 +0000172 lldb::offset_t offset = 0;
Greg Clayton78e44bd2013-04-25 00:57:05 +0000173 if (value_size <= 8)
174 {
175 uint64_t u64value = value_extractor.GetMaxU64(&offset, value_size);
176 return AssignToMatchType(scalar, u64value, value->getType());
177 }
Sean Callanan3bfdaa22011-09-15 02:13:07 +0000178 }
179
180 return false;
181 }
182
183 bool AssignValue (const Value *value, lldb_private::Scalar &scalar, Module &module)
184 {
Sean Callanan08052af2013-04-17 07:50:58 +0000185 lldb::addr_t process_address = ResolveValue (value, module);
186
187 if (process_address == LLDB_INVALID_ADDRESS)
188 return false;
Sean Callanan3bfdaa22011-09-15 02:13:07 +0000189
190 lldb_private::Scalar cast_scalar;
191
192 if (!AssignToMatchType(cast_scalar, scalar.GetRawBits64(0), value->getType()))
193 return false;
Sean Callanan08052af2013-04-17 07:50:58 +0000194
195 size_t value_byte_size = m_target_data.getTypeStoreSize(value->getType());
Sean Callanan3bfdaa22011-09-15 02:13:07 +0000196
Sean Callanan08052af2013-04-17 07:50:58 +0000197 lldb_private::DataBufferHeap buf(value_byte_size, 0);
Sean Callanan3bfdaa22011-09-15 02:13:07 +0000198
Sean Callanan08052af2013-04-17 07:50:58 +0000199 lldb_private::Error get_data_error;
Sean Callanan3bfdaa22011-09-15 02:13:07 +0000200
Sean Callanan08052af2013-04-17 07:50:58 +0000201 if (!cast_scalar.GetAsMemoryData(buf.GetBytes(), buf.GetByteSize(), m_byte_order, get_data_error))
Sean Callanan3bfdaa22011-09-15 02:13:07 +0000202 return false;
203
Sean Callanan08052af2013-04-17 07:50:58 +0000204 lldb_private::Error write_error;
Sean Callanan3bfdaa22011-09-15 02:13:07 +0000205
Sean Callanan08052af2013-04-17 07:50:58 +0000206 m_memory_map.WriteMemory(process_address, buf.GetBytes(), buf.GetByteSize(), write_error);
Sean Callananc8675502013-02-15 23:07:52 +0000207
Sean Callanan08052af2013-04-17 07:50:58 +0000208 return write_error.Success();
Sean Callanan3bfdaa22011-09-15 02:13:07 +0000209 }
210
Sean Callanan94a9a392012-02-08 01:27:49 +0000211 bool ResolveConstantValue (APInt &value, const Constant *constant)
Sean Callanan3bfdaa22011-09-15 02:13:07 +0000212 {
Sean Callanan1582ee62013-04-18 22:06:33 +0000213 switch (constant->getValueID())
Sean Callanan3bfdaa22011-09-15 02:13:07 +0000214 {
Sean Callanan1582ee62013-04-18 22:06:33 +0000215 default:
216 break;
217 case Value::ConstantIntVal:
218 if (const ConstantInt *constant_int = dyn_cast<ConstantInt>(constant))
Sean Callanan80c48c12011-10-21 05:18:02 +0000219 {
Sean Callanan1582ee62013-04-18 22:06:33 +0000220 value = constant_int->getValue();
221 return true;
222 }
223 break;
224 case Value::ConstantFPVal:
225 if (const ConstantFP *constant_fp = dyn_cast<ConstantFP>(constant))
226 {
227 value = constant_fp->getValueAPF().bitcastToAPInt();
228 return true;
229 }
230 break;
231 case Value::ConstantExprVal:
232 if (const ConstantExpr *constant_expr = dyn_cast<ConstantExpr>(constant))
233 {
234 switch (constant_expr->getOpcode())
Sean Callanan94a9a392012-02-08 01:27:49 +0000235 {
Sean Callanan1582ee62013-04-18 22:06:33 +0000236 default:
Sean Callanan94a9a392012-02-08 01:27:49 +0000237 return false;
Sean Callanan1582ee62013-04-18 22:06:33 +0000238 case Instruction::IntToPtr:
239 case Instruction::PtrToInt:
240 case Instruction::BitCast:
241 return ResolveConstantValue(value, constant_expr->getOperand(0));
242 case Instruction::GetElementPtr:
243 {
244 ConstantExpr::const_op_iterator op_cursor = constant_expr->op_begin();
245 ConstantExpr::const_op_iterator op_end = constant_expr->op_end();
246
247 Constant *base = dyn_cast<Constant>(*op_cursor);
248
249 if (!base)
250 return false;
251
252 if (!ResolveConstantValue(value, base))
253 return false;
254
255 op_cursor++;
256
257 if (op_cursor == op_end)
258 return true; // no offset to apply!
259
260 SmallVector <Value *, 8> indices (op_cursor, op_end);
261
262 uint64_t offset = m_target_data.getIndexedOffset(base->getType(), indices);
263
264 const bool is_signed = true;
265 value += APInt(value.getBitWidth(), offset, is_signed);
266
267 return true;
268 }
Sean Callanan94a9a392012-02-08 01:27:49 +0000269 }
Sean Callanan80c48c12011-10-21 05:18:02 +0000270 }
Sean Callanan1582ee62013-04-18 22:06:33 +0000271 break;
272 case Value::ConstantPointerNullVal:
273 if (isa<ConstantPointerNull>(constant))
274 {
275 value = APInt(m_target_data.getPointerSizeInBits(), 0);
276 return true;
277 }
278 break;
279 }
280 return false;
281 }
282
283 bool MakeArgument(const Argument *value, uint64_t address)
284 {
285 lldb::addr_t data_address = Malloc(value->getType());
286
287 if (data_address == LLDB_INVALID_ADDRESS)
288 return false;
289
290 lldb_private::Error write_error;
291
292 m_memory_map.WritePointerToMemory(data_address, address, write_error);
293
294 if (!write_error.Success())
295 {
296 lldb_private::Error free_error;
297 m_memory_map.Free(data_address, free_error);
298 return false;
Sean Callanan80c48c12011-10-21 05:18:02 +0000299 }
Sean Callanan3bfdaa22011-09-15 02:13:07 +0000300
Sean Callanan1582ee62013-04-18 22:06:33 +0000301 m_values[value] = data_address;
302
303 lldb_private::Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
304
305 if (log)
306 {
307 log->Printf("Made an allocation for argument %s", PrintValue(value).c_str());
308 log->Printf(" Data region : %llx", (unsigned long long)address);
309 log->Printf(" Ref region : %llx", (unsigned long long)data_address);
310 }
311
312 return true;
Sean Callanan3bfdaa22011-09-15 02:13:07 +0000313 }
314
Sean Callanan08052af2013-04-17 07:50:58 +0000315 bool ResolveConstant (lldb::addr_t process_address, const Constant *constant)
Sean Callanan94a9a392012-02-08 01:27:49 +0000316 {
317 APInt resolved_value;
318
319 if (!ResolveConstantValue(resolved_value, constant))
320 return false;
321
322 const uint64_t *raw_data = resolved_value.getRawData();
323
324 size_t constant_size = m_target_data.getTypeStoreSize(constant->getType());
Sean Callanan94a9a392012-02-08 01:27:49 +0000325
Sean Callanan08052af2013-04-17 07:50:58 +0000326 lldb_private::Error write_error;
327
328 m_memory_map.WriteMemory(process_address, (uint8_t*)raw_data, constant_size, write_error);
329
330 return write_error.Success();
331 }
332
Sean Callanan1582ee62013-04-18 22:06:33 +0000333 lldb::addr_t Malloc (size_t size, uint8_t byte_alignment)
334 {
335 lldb::addr_t ret = m_stack_pointer;
336
337 ret -= size;
338 ret -= (ret % byte_alignment);
339
340 if (ret < m_frame_process_address)
341 return LLDB_INVALID_ADDRESS;
342
343 m_stack_pointer = ret;
344 return ret;
345 }
346
Sean Callanan08052af2013-04-17 07:50:58 +0000347 lldb::addr_t MallocPointer ()
348 {
Sean Callanan1582ee62013-04-18 22:06:33 +0000349 return Malloc(m_target_data.getPointerSize(), m_target_data.getPointerPrefAlignment());
Sean Callanan08052af2013-04-17 07:50:58 +0000350 }
351
Sean Callanan1582ee62013-04-18 22:06:33 +0000352 lldb::addr_t Malloc (llvm::Type *type)
Sean Callanan08052af2013-04-17 07:50:58 +0000353 {
354 lldb_private::Error alloc_error;
355
Sean Callanan1582ee62013-04-18 22:06:33 +0000356 return Malloc(m_target_data.getTypeAllocSize(type), m_target_data.getPrefTypeAlignment(type));
Sean Callanan08052af2013-04-17 07:50:58 +0000357 }
358
Sean Callanan08052af2013-04-17 07:50:58 +0000359 std::string PrintData (lldb::addr_t addr, llvm::Type *type)
360 {
361 size_t length = m_target_data.getTypeStoreSize(type);
362
363 lldb_private::DataBufferHeap buf(length, 0);
364
365 lldb_private::Error read_error;
366
367 m_memory_map.ReadMemory(buf.GetBytes(), addr, length, read_error);
368
369 if (!read_error.Success())
370 return std::string("<couldn't read data>");
371
372 lldb_private::StreamString ss;
373
374 for (size_t i = 0; i < length; i++)
375 {
376 if ((!(i & 0xf)) && i)
377 ss.Printf("%02hhx - ", buf.GetBytes()[i]);
378 else
379 ss.Printf("%02hhx ", buf.GetBytes()[i]);
380 }
381
382 return ss.GetString();
383 }
384
385 lldb::addr_t ResolveValue (const Value *value, Module &module)
Sean Callanan3bfdaa22011-09-15 02:13:07 +0000386 {
387 ValueMap::iterator i = m_values.find(value);
388
389 if (i != m_values.end())
390 return i->second;
391
Sean Callanan1582ee62013-04-18 22:06:33 +0000392 // Fall back and allocate space [allocation type Alloca]
393
394 lldb::addr_t data_address = Malloc(value->getType());
395
396 if (const Constant *constant = dyn_cast<Constant>(value))
397 {
398 if (!ResolveConstant (data_address, constant))
399 {
400 lldb_private::Error free_error;
401 m_memory_map.Free(data_address, free_error);
402 return LLDB_INVALID_ADDRESS;
403 }
404 }
405
406 m_values[value] = data_address;
407 return data_address;
Sean Callanan3bfdaa22011-09-15 02:13:07 +0000408 }
409};
410
Sean Callanan175a0d02012-01-24 22:06:48 +0000411static const char *unsupported_opcode_error = "Interpreter doesn't handle one of the expression's opcodes";
Greg Claytone01e07b2013-04-18 18:10:51 +0000412//static const char *interpreter_initialization_error = "Interpreter couldn't be initialized";
Sean Callanan175a0d02012-01-24 22:06:48 +0000413static const char *interpreter_internal_error = "Interpreter encountered an internal error";
414static const char *bad_value_error = "Interpreter couldn't resolve a value during execution";
415static const char *memory_allocation_error = "Interpreter couldn't allocate memory";
416static const char *memory_write_error = "Interpreter couldn't write to memory";
417static const char *memory_read_error = "Interpreter couldn't read from memory";
418static const char *infinite_loop_error = "Interpreter ran for too many cycles";
Sean Callanan44342732013-04-19 08:14:32 +0000419//static const char *bad_result_error = "Result of expression is in bad memory";
Sean Callanan175a0d02012-01-24 22:06:48 +0000420
Sean Callanan3bfdaa22011-09-15 02:13:07 +0000421bool
Sean Callanan44342732013-04-19 08:14:32 +0000422IRInterpreter::CanInterpret (llvm::Module &module,
423 llvm::Function &function,
424 lldb_private::Error &error)
Sean Callanan3bfdaa22011-09-15 02:13:07 +0000425{
Greg Clayton5160ce52013-03-27 23:08:40 +0000426 lldb_private::Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
Sean Callanan3bfdaa22011-09-15 02:13:07 +0000427
Sean Callanan44342732013-04-19 08:14:32 +0000428 for (Function::iterator bbi = function.begin(), bbe = function.end();
Sean Callanan3bfdaa22011-09-15 02:13:07 +0000429 bbi != bbe;
430 ++bbi)
431 {
432 for (BasicBlock::iterator ii = bbi->begin(), ie = bbi->end();
433 ii != ie;
434 ++ii)
435 {
436 switch (ii->getOpcode())
437 {
438 default:
439 {
440 if (log)
441 log->Printf("Unsupported instruction: %s", PrintValue(ii).c_str());
Sean Callanan44342732013-04-19 08:14:32 +0000442 error.SetErrorToGenericError();
443 error.SetErrorString(unsupported_opcode_error);
Sean Callanan3bfdaa22011-09-15 02:13:07 +0000444 return false;
445 }
446 case Instruction::Add:
447 case Instruction::Alloca:
448 case Instruction::BitCast:
449 case Instruction::Br:
450 case Instruction::GetElementPtr:
451 break;
452 case Instruction::ICmp:
453 {
454 ICmpInst *icmp_inst = dyn_cast<ICmpInst>(ii);
455
456 if (!icmp_inst)
Sean Callanan175a0d02012-01-24 22:06:48 +0000457 {
Sean Callanan44342732013-04-19 08:14:32 +0000458 error.SetErrorToGenericError();
459 error.SetErrorString(interpreter_internal_error);
Sean Callanan3bfdaa22011-09-15 02:13:07 +0000460 return false;
Sean Callanan175a0d02012-01-24 22:06:48 +0000461 }
Sean Callanan3bfdaa22011-09-15 02:13:07 +0000462
463 switch (icmp_inst->getPredicate())
464 {
465 default:
Sean Callanan44342732013-04-19 08:14:32 +0000466 {
467 if (log)
468 log->Printf("Unsupported ICmp predicate: %s", PrintValue(ii).c_str());
469
470 error.SetErrorToGenericError();
471 error.SetErrorString(unsupported_opcode_error);
472 return false;
473 }
Sean Callanan3bfdaa22011-09-15 02:13:07 +0000474 case CmpInst::ICMP_EQ:
475 case CmpInst::ICMP_NE:
476 case CmpInst::ICMP_UGT:
477 case CmpInst::ICMP_UGE:
478 case CmpInst::ICMP_ULT:
479 case CmpInst::ICMP_ULE:
480 case CmpInst::ICMP_SGT:
481 case CmpInst::ICMP_SGE:
482 case CmpInst::ICMP_SLT:
483 case CmpInst::ICMP_SLE:
484 break;
485 }
486 }
487 break;
Sean Callanan087f4372013-01-09 22:44:41 +0000488 case Instruction::And:
489 case Instruction::AShr:
Sean Callanan80c48c12011-10-21 05:18:02 +0000490 case Instruction::IntToPtr:
Sean Callanan2abffe02012-12-01 00:09:34 +0000491 case Instruction::PtrToInt:
Sean Callanan3bfdaa22011-09-15 02:13:07 +0000492 case Instruction::Load:
Sean Callanan087f4372013-01-09 22:44:41 +0000493 case Instruction::LShr:
Sean Callanan3bfdaa22011-09-15 02:13:07 +0000494 case Instruction::Mul:
Sean Callanan087f4372013-01-09 22:44:41 +0000495 case Instruction::Or:
Sean Callanan3bfdaa22011-09-15 02:13:07 +0000496 case Instruction::Ret:
497 case Instruction::SDiv:
Sean Callanan087f4372013-01-09 22:44:41 +0000498 case Instruction::Shl:
Sean Callananf466a6e2012-12-21 22:27:55 +0000499 case Instruction::SRem:
Sean Callanan3bfdaa22011-09-15 02:13:07 +0000500 case Instruction::Store:
501 case Instruction::Sub:
502 case Instruction::UDiv:
Sean Callananf466a6e2012-12-21 22:27:55 +0000503 case Instruction::URem:
Sean Callanan087f4372013-01-09 22:44:41 +0000504 case Instruction::Xor:
Sean Callanan1ef77432012-04-23 17:25:38 +0000505 case Instruction::ZExt:
Sean Callanan3bfdaa22011-09-15 02:13:07 +0000506 break;
507 }
508 }
509 }
510
Sean Callanan44342732013-04-19 08:14:32 +0000511 return true;}
Sean Callanan14cb2aa2013-04-17 18:35:47 +0000512
513bool
514IRInterpreter::Interpret (llvm::Module &module,
515 llvm::Function &function,
Sean Callanan1582ee62013-04-18 22:06:33 +0000516 llvm::ArrayRef<lldb::addr_t> args,
Sean Callanan14cb2aa2013-04-17 18:35:47 +0000517 lldb_private::IRMemoryMap &memory_map,
Sean Callanandf565402013-04-27 02:19:33 +0000518 lldb_private::Error &error,
519 lldb::addr_t stack_frame_bottom,
520 lldb::addr_t stack_frame_top)
Sean Callanan14cb2aa2013-04-17 18:35:47 +0000521{
522 lldb_private::Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
523
Sean Callanan1582ee62013-04-18 22:06:33 +0000524 if (log)
525 {
526 std::string s;
527 raw_string_ostream oss(s);
528
529 module.print(oss, NULL);
530
531 oss.flush();
532
533 log->Printf("Module as passed in to IRInterpreter::Interpret: \n\"%s\"", s.c_str());
534 }
535
Sean Callanan14cb2aa2013-04-17 18:35:47 +0000536 DataLayout data_layout(&module);
537
Sean Callanandf565402013-04-27 02:19:33 +0000538 InterpreterStackFrame frame(data_layout, memory_map, stack_frame_bottom, stack_frame_top);
Sean Callanan14cb2aa2013-04-17 18:35:47 +0000539
Sean Callanan1582ee62013-04-18 22:06:33 +0000540 if (frame.m_frame_process_address == LLDB_INVALID_ADDRESS)
541 {
542 error.SetErrorString("Couldn't allocate stack frame");
543 }
544
545 int arg_index = 0;
546
547 for (llvm::Function::arg_iterator ai = function.arg_begin(), ae = function.arg_end();
548 ai != ae;
549 ++ai, ++arg_index)
550 {
551 if (args.size() < arg_index)
552 {
553 error.SetErrorString ("Not enough arguments passed in to function");
554 return false;
555 }
556
557 lldb::addr_t ptr = args[arg_index];
558
559 frame.MakeArgument(ai, ptr);
560 }
561
Sean Callanan14cb2aa2013-04-17 18:35:47 +0000562 uint32_t num_insts = 0;
563
564 frame.Jump(function.begin());
565
566 while (frame.m_ii != frame.m_ie && (++num_insts < 4096))
567 {
568 const Instruction *inst = frame.m_ii;
569
570 if (log)
571 log->Printf("Interpreting %s", PrintValue(inst).c_str());
572
573 switch (inst->getOpcode())
574 {
575 default:
576 break;
577 case Instruction::Add:
578 case Instruction::Sub:
579 case Instruction::Mul:
580 case Instruction::SDiv:
581 case Instruction::UDiv:
582 case Instruction::SRem:
583 case Instruction::URem:
584 case Instruction::Shl:
585 case Instruction::LShr:
586 case Instruction::AShr:
587 case Instruction::And:
588 case Instruction::Or:
589 case Instruction::Xor:
590 {
591 const BinaryOperator *bin_op = dyn_cast<BinaryOperator>(inst);
592
593 if (!bin_op)
594 {
595 if (log)
596 log->Printf("getOpcode() returns %s, but instruction is not a BinaryOperator", inst->getOpcodeName());
597 error.SetErrorToGenericError();
598 error.SetErrorString(interpreter_internal_error);
599 return false;
600 }
601
602 Value *lhs = inst->getOperand(0);
603 Value *rhs = inst->getOperand(1);
604
605 lldb_private::Scalar L;
606 lldb_private::Scalar R;
607
608 if (!frame.EvaluateValue(L, lhs, module))
609 {
610 if (log)
611 log->Printf("Couldn't evaluate %s", PrintValue(lhs).c_str());
612 error.SetErrorToGenericError();
613 error.SetErrorString(bad_value_error);
614 return false;
615 }
616
617 if (!frame.EvaluateValue(R, rhs, module))
618 {
619 if (log)
620 log->Printf("Couldn't evaluate %s", PrintValue(rhs).c_str());
621 error.SetErrorToGenericError();
622 error.SetErrorString(bad_value_error);
623 return false;
624 }
625
626 lldb_private::Scalar result;
627
628 switch (inst->getOpcode())
629 {
630 default:
631 break;
632 case Instruction::Add:
633 result = L + R;
634 break;
635 case Instruction::Mul:
636 result = L * R;
637 break;
638 case Instruction::Sub:
639 result = L - R;
640 break;
641 case Instruction::SDiv:
642 result = L / R;
643 break;
644 case Instruction::UDiv:
645 result = L.GetRawBits64(0) / R.GetRawBits64(1);
646 break;
647 case Instruction::SRem:
648 result = L % R;
649 break;
650 case Instruction::URem:
651 result = L.GetRawBits64(0) % R.GetRawBits64(1);
652 break;
653 case Instruction::Shl:
654 result = L << R;
655 break;
656 case Instruction::AShr:
657 result = L >> R;
658 break;
659 case Instruction::LShr:
660 result = L;
661 result.ShiftRightLogical(R);
662 break;
663 case Instruction::And:
664 result = L & R;
665 break;
666 case Instruction::Or:
667 result = L | R;
668 break;
669 case Instruction::Xor:
670 result = L ^ R;
671 break;
672 }
673
674 frame.AssignValue(inst, result, module);
675
676 if (log)
677 {
678 log->Printf("Interpreted a %s", inst->getOpcodeName());
679 log->Printf(" L : %s", frame.SummarizeValue(lhs).c_str());
680 log->Printf(" R : %s", frame.SummarizeValue(rhs).c_str());
681 log->Printf(" = : %s", frame.SummarizeValue(inst).c_str());
682 }
683 }
684 break;
685 case Instruction::Alloca:
686 {
687 const AllocaInst *alloca_inst = dyn_cast<AllocaInst>(inst);
688
689 if (!alloca_inst)
690 {
691 if (log)
692 log->Printf("getOpcode() returns Alloca, but instruction is not an AllocaInst");
693 error.SetErrorToGenericError();
694 error.SetErrorString(interpreter_internal_error);
695 return false;
696 }
697
698 if (alloca_inst->isArrayAllocation())
699 {
700 if (log)
701 log->Printf("AllocaInsts are not handled if isArrayAllocation() is true");
702 error.SetErrorToGenericError();
703 error.SetErrorString(unsupported_opcode_error);
704 return false;
705 }
706
707 // The semantics of Alloca are:
708 // Create a region R of virtual memory of type T, backed by a data buffer
709 // Create a region P of virtual memory of type T*, backed by a data buffer
710 // Write the virtual address of R into P
711
712 Type *T = alloca_inst->getAllocatedType();
713 Type *Tptr = alloca_inst->getType();
714
715 lldb::addr_t R = frame.Malloc(T);
716
717 if (R == LLDB_INVALID_ADDRESS)
718 {
719 if (log)
720 log->Printf("Couldn't allocate memory for an AllocaInst");
721 error.SetErrorToGenericError();
722 error.SetErrorString(memory_allocation_error);
723 return false;
724 }
725
726 lldb::addr_t P = frame.Malloc(Tptr);
727
728 if (P == LLDB_INVALID_ADDRESS)
729 {
730 if (log)
731 log->Printf("Couldn't allocate the result pointer for an AllocaInst");
732 error.SetErrorToGenericError();
733 error.SetErrorString(memory_allocation_error);
734 return false;
735 }
736
737 lldb_private::Error write_error;
738
739 memory_map.WritePointerToMemory(P, R, write_error);
740
741 if (!write_error.Success())
742 {
743 if (log)
744 log->Printf("Couldn't write the result pointer for an AllocaInst");
745 error.SetErrorToGenericError();
746 error.SetErrorString(memory_write_error);
747 lldb_private::Error free_error;
748 memory_map.Free(P, free_error);
749 memory_map.Free(R, free_error);
750 return false;
751 }
752
753 frame.m_values[alloca_inst] = P;
754
755 if (log)
756 {
757 log->Printf("Interpreted an AllocaInst");
758 log->Printf(" R : 0x%llx", R);
759 log->Printf(" P : 0x%llx", P);
760 }
761 }
762 break;
763 case Instruction::BitCast:
764 case Instruction::ZExt:
765 {
766 const CastInst *cast_inst = dyn_cast<CastInst>(inst);
767
768 if (!cast_inst)
769 {
770 if (log)
771 log->Printf("getOpcode() returns %s, but instruction is not a BitCastInst", cast_inst->getOpcodeName());
772 error.SetErrorToGenericError();
773 error.SetErrorString(interpreter_internal_error);
774 return false;
775 }
776
777 Value *source = cast_inst->getOperand(0);
778
779 lldb_private::Scalar S;
780
781 if (!frame.EvaluateValue(S, source, module))
782 {
783 if (log)
784 log->Printf("Couldn't evaluate %s", PrintValue(source).c_str());
785 error.SetErrorToGenericError();
786 error.SetErrorString(bad_value_error);
787 return false;
788 }
789
790 frame.AssignValue(inst, S, module);
791 }
792 break;
793 case Instruction::Br:
794 {
795 const BranchInst *br_inst = dyn_cast<BranchInst>(inst);
796
797 if (!br_inst)
798 {
799 if (log)
800 log->Printf("getOpcode() returns Br, but instruction is not a BranchInst");
801 error.SetErrorToGenericError();
802 error.SetErrorString(interpreter_internal_error);
803 return false;
804 }
805
806 if (br_inst->isConditional())
807 {
808 Value *condition = br_inst->getCondition();
809
810 lldb_private::Scalar C;
811
812 if (!frame.EvaluateValue(C, condition, module))
813 {
814 if (log)
815 log->Printf("Couldn't evaluate %s", PrintValue(condition).c_str());
816 error.SetErrorToGenericError();
817 error.SetErrorString(bad_value_error);
818 return false;
819 }
820
821 if (C.GetRawBits64(0))
822 frame.Jump(br_inst->getSuccessor(0));
823 else
824 frame.Jump(br_inst->getSuccessor(1));
825
826 if (log)
827 {
828 log->Printf("Interpreted a BrInst with a condition");
829 log->Printf(" cond : %s", frame.SummarizeValue(condition).c_str());
830 }
831 }
832 else
833 {
834 frame.Jump(br_inst->getSuccessor(0));
835
836 if (log)
837 {
838 log->Printf("Interpreted a BrInst with no condition");
839 }
840 }
841 }
842 continue;
843 case Instruction::GetElementPtr:
844 {
845 const GetElementPtrInst *gep_inst = dyn_cast<GetElementPtrInst>(inst);
846
847 if (!gep_inst)
848 {
849 if (log)
850 log->Printf("getOpcode() returns GetElementPtr, but instruction is not a GetElementPtrInst");
851 error.SetErrorToGenericError();
852 error.SetErrorString(interpreter_internal_error);
853 return false;
854 }
855
856 const Value *pointer_operand = gep_inst->getPointerOperand();
857 Type *pointer_type = pointer_operand->getType();
858
859 lldb_private::Scalar P;
860
861 if (!frame.EvaluateValue(P, pointer_operand, module))
862 {
863 if (log)
864 log->Printf("Couldn't evaluate %s", PrintValue(pointer_operand).c_str());
865 error.SetErrorToGenericError();
866 error.SetErrorString(bad_value_error);
867 return false;
868 }
869
870 typedef SmallVector <Value *, 8> IndexVector;
871 typedef IndexVector::iterator IndexIterator;
872
873 SmallVector <Value *, 8> indices (gep_inst->idx_begin(),
874 gep_inst->idx_end());
875
876 SmallVector <Value *, 8> const_indices;
877
878 for (IndexIterator ii = indices.begin(), ie = indices.end();
879 ii != ie;
880 ++ii)
881 {
882 ConstantInt *constant_index = dyn_cast<ConstantInt>(*ii);
883
884 if (!constant_index)
885 {
886 lldb_private::Scalar I;
887
888 if (!frame.EvaluateValue(I, *ii, module))
889 {
890 if (log)
891 log->Printf("Couldn't evaluate %s", PrintValue(*ii).c_str());
892 error.SetErrorToGenericError();
893 error.SetErrorString(bad_value_error);
894 return false;
895 }
896
897 if (log)
898 log->Printf("Evaluated constant index %s as %llu", PrintValue(*ii).c_str(), I.ULongLong(LLDB_INVALID_ADDRESS));
899
900 constant_index = cast<ConstantInt>(ConstantInt::get((*ii)->getType(), I.ULongLong(LLDB_INVALID_ADDRESS)));
901 }
902
903 const_indices.push_back(constant_index);
904 }
905
906 uint64_t offset = data_layout.getIndexedOffset(pointer_type, const_indices);
907
908 lldb_private::Scalar Poffset = P + offset;
909
910 frame.AssignValue(inst, Poffset, module);
911
912 if (log)
913 {
914 log->Printf("Interpreted a GetElementPtrInst");
915 log->Printf(" P : %s", frame.SummarizeValue(pointer_operand).c_str());
916 log->Printf(" Poffset : %s", frame.SummarizeValue(inst).c_str());
917 }
918 }
919 break;
920 case Instruction::ICmp:
921 {
922 const ICmpInst *icmp_inst = dyn_cast<ICmpInst>(inst);
923
924 if (!icmp_inst)
925 {
926 if (log)
927 log->Printf("getOpcode() returns ICmp, but instruction is not an ICmpInst");
928 error.SetErrorToGenericError();
929 error.SetErrorString(interpreter_internal_error);
930 return false;
931 }
932
933 CmpInst::Predicate predicate = icmp_inst->getPredicate();
934
935 Value *lhs = inst->getOperand(0);
936 Value *rhs = inst->getOperand(1);
937
938 lldb_private::Scalar L;
939 lldb_private::Scalar R;
940
941 if (!frame.EvaluateValue(L, lhs, module))
942 {
943 if (log)
944 log->Printf("Couldn't evaluate %s", PrintValue(lhs).c_str());
945 error.SetErrorToGenericError();
946 error.SetErrorString(bad_value_error);
947 return false;
948 }
949
950 if (!frame.EvaluateValue(R, rhs, module))
951 {
952 if (log)
953 log->Printf("Couldn't evaluate %s", PrintValue(rhs).c_str());
954 error.SetErrorToGenericError();
955 error.SetErrorString(bad_value_error);
956 return false;
957 }
958
959 lldb_private::Scalar result;
960
961 switch (predicate)
962 {
963 default:
964 return false;
965 case CmpInst::ICMP_EQ:
966 result = (L == R);
967 break;
968 case CmpInst::ICMP_NE:
969 result = (L != R);
970 break;
971 case CmpInst::ICMP_UGT:
972 result = (L.GetRawBits64(0) > R.GetRawBits64(0));
973 break;
974 case CmpInst::ICMP_UGE:
975 result = (L.GetRawBits64(0) >= R.GetRawBits64(0));
976 break;
977 case CmpInst::ICMP_ULT:
978 result = (L.GetRawBits64(0) < R.GetRawBits64(0));
979 break;
980 case CmpInst::ICMP_ULE:
981 result = (L.GetRawBits64(0) <= R.GetRawBits64(0));
982 break;
983 case CmpInst::ICMP_SGT:
984 result = (L > R);
985 break;
986 case CmpInst::ICMP_SGE:
987 result = (L >= R);
988 break;
989 case CmpInst::ICMP_SLT:
990 result = (L < R);
991 break;
992 case CmpInst::ICMP_SLE:
993 result = (L <= R);
994 break;
995 }
996
997 frame.AssignValue(inst, result, module);
998
999 if (log)
1000 {
1001 log->Printf("Interpreted an ICmpInst");
1002 log->Printf(" L : %s", frame.SummarizeValue(lhs).c_str());
1003 log->Printf(" R : %s", frame.SummarizeValue(rhs).c_str());
1004 log->Printf(" = : %s", frame.SummarizeValue(inst).c_str());
1005 }
1006 }
1007 break;
1008 case Instruction::IntToPtr:
1009 {
1010 const IntToPtrInst *int_to_ptr_inst = dyn_cast<IntToPtrInst>(inst);
1011
1012 if (!int_to_ptr_inst)
1013 {
1014 if (log)
1015 log->Printf("getOpcode() returns IntToPtr, but instruction is not an IntToPtrInst");
1016 error.SetErrorToGenericError();
1017 error.SetErrorString(interpreter_internal_error);
1018 return false;
1019 }
1020
1021 Value *src_operand = int_to_ptr_inst->getOperand(0);
1022
1023 lldb_private::Scalar I;
1024
1025 if (!frame.EvaluateValue(I, src_operand, module))
1026 {
1027 if (log)
1028 log->Printf("Couldn't evaluate %s", PrintValue(src_operand).c_str());
1029 error.SetErrorToGenericError();
1030 error.SetErrorString(bad_value_error);
1031 return false;
1032 }
1033
1034 frame.AssignValue(inst, I, module);
1035
1036 if (log)
1037 {
1038 log->Printf("Interpreted an IntToPtr");
1039 log->Printf(" Src : %s", frame.SummarizeValue(src_operand).c_str());
1040 log->Printf(" = : %s", frame.SummarizeValue(inst).c_str());
1041 }
1042 }
1043 break;
1044 case Instruction::PtrToInt:
1045 {
1046 const PtrToIntInst *ptr_to_int_inst = dyn_cast<PtrToIntInst>(inst);
1047
1048 if (!ptr_to_int_inst)
1049 {
1050 if (log)
1051 log->Printf("getOpcode() returns PtrToInt, but instruction is not an PtrToIntInst");
1052 error.SetErrorToGenericError();
1053 error.SetErrorString(interpreter_internal_error);
1054 return false;
1055 }
1056
1057 Value *src_operand = ptr_to_int_inst->getOperand(0);
1058
1059 lldb_private::Scalar I;
1060
1061 if (!frame.EvaluateValue(I, src_operand, module))
1062 {
1063 if (log)
1064 log->Printf("Couldn't evaluate %s", PrintValue(src_operand).c_str());
1065 error.SetErrorToGenericError();
1066 error.SetErrorString(bad_value_error);
1067 return false;
1068 }
1069
1070 frame.AssignValue(inst, I, module);
1071
1072 if (log)
1073 {
1074 log->Printf("Interpreted a PtrToInt");
1075 log->Printf(" Src : %s", frame.SummarizeValue(src_operand).c_str());
1076 log->Printf(" = : %s", frame.SummarizeValue(inst).c_str());
1077 }
1078 }
1079 break;
1080 case Instruction::Load:
1081 {
1082 const LoadInst *load_inst = dyn_cast<LoadInst>(inst);
1083
1084 if (!load_inst)
1085 {
1086 if (log)
1087 log->Printf("getOpcode() returns Load, but instruction is not a LoadInst");
1088 error.SetErrorToGenericError();
1089 error.SetErrorString(interpreter_internal_error);
1090 return false;
1091 }
1092
1093 // The semantics of Load are:
1094 // Create a region D that will contain the loaded data
1095 // Resolve the region P containing a pointer
1096 // Dereference P to get the region R that the data should be loaded from
1097 // Transfer a unit of type type(D) from R to D
1098
1099 const Value *pointer_operand = load_inst->getPointerOperand();
1100
1101 Type *pointer_ty = pointer_operand->getType();
1102 PointerType *pointer_ptr_ty = dyn_cast<PointerType>(pointer_ty);
1103 if (!pointer_ptr_ty)
1104 {
1105 if (log)
1106 log->Printf("getPointerOperand()->getType() is not a PointerType");
1107 error.SetErrorToGenericError();
1108 error.SetErrorString(interpreter_internal_error);
1109 return false;
1110 }
1111 Type *target_ty = pointer_ptr_ty->getElementType();
1112
1113 lldb::addr_t D = frame.ResolveValue(load_inst, module);
1114 lldb::addr_t P = frame.ResolveValue(pointer_operand, module);
1115
1116 if (D == LLDB_INVALID_ADDRESS)
1117 {
1118 if (log)
1119 log->Printf("LoadInst's value doesn't resolve to anything");
1120 error.SetErrorToGenericError();
1121 error.SetErrorString(bad_value_error);
1122 return false;
1123 }
1124
1125 if (P == LLDB_INVALID_ADDRESS)
1126 {
1127 if (log)
1128 log->Printf("LoadInst's pointer doesn't resolve to anything");
1129 error.SetErrorToGenericError();
1130 error.SetErrorString(bad_value_error);
1131 return false;
1132 }
1133
1134 lldb::addr_t R;
1135 lldb_private::Error read_error;
1136 memory_map.ReadPointerFromMemory(&R, P, read_error);
1137
1138 if (!read_error.Success())
1139 {
1140 if (log)
1141 log->Printf("Couldn't read the address to be loaded for a LoadInst");
1142 error.SetErrorToGenericError();
1143 error.SetErrorString(memory_read_error);
1144 return false;
1145 }
1146
1147 size_t target_size = data_layout.getTypeStoreSize(target_ty);
1148 lldb_private::DataBufferHeap buffer(target_size, 0);
1149
1150 read_error.Clear();
1151 memory_map.ReadMemory(buffer.GetBytes(), R, buffer.GetByteSize(), read_error);
1152 if (!read_error.Success())
1153 {
1154 if (log)
1155 log->Printf("Couldn't read from a region on behalf of a LoadInst");
1156 error.SetErrorToGenericError();
1157 error.SetErrorString(memory_read_error);
1158 return false;
1159 }
1160
1161 lldb_private::Error write_error;
1162 memory_map.WriteMemory(D, buffer.GetBytes(), buffer.GetByteSize(), write_error);
1163 if (!write_error.Success())
1164 {
1165 if (log)
1166 log->Printf("Couldn't write to a region on behalf of a LoadInst");
1167 error.SetErrorToGenericError();
1168 error.SetErrorString(memory_read_error);
1169 return false;
1170 }
1171
1172 if (log)
1173 {
1174 log->Printf("Interpreted a LoadInst");
1175 log->Printf(" P : 0x%llx", P);
1176 log->Printf(" R : 0x%llx", R);
1177 log->Printf(" D : 0x%llx", D);
1178 }
1179 }
1180 break;
1181 case Instruction::Ret:
1182 {
1183 return true;
1184 }
1185 case Instruction::Store:
1186 {
1187 const StoreInst *store_inst = dyn_cast<StoreInst>(inst);
1188
1189 if (!store_inst)
1190 {
1191 if (log)
1192 log->Printf("getOpcode() returns Store, but instruction is not a StoreInst");
1193 error.SetErrorToGenericError();
1194 error.SetErrorString(interpreter_internal_error);
1195 return false;
1196 }
1197
1198 // The semantics of Store are:
1199 // Resolve the region D containing the data to be stored
1200 // Resolve the region P containing a pointer
1201 // Dereference P to get the region R that the data should be stored in
1202 // Transfer a unit of type type(D) from D to R
1203
1204 const Value *value_operand = store_inst->getValueOperand();
1205 const Value *pointer_operand = store_inst->getPointerOperand();
1206
1207 Type *pointer_ty = pointer_operand->getType();
1208 PointerType *pointer_ptr_ty = dyn_cast<PointerType>(pointer_ty);
1209 if (!pointer_ptr_ty)
1210 return false;
1211 Type *target_ty = pointer_ptr_ty->getElementType();
1212
1213 lldb::addr_t D = frame.ResolveValue(value_operand, module);
1214 lldb::addr_t P = frame.ResolveValue(pointer_operand, module);
1215
1216 if (D == LLDB_INVALID_ADDRESS)
1217 {
1218 if (log)
1219 log->Printf("StoreInst's value doesn't resolve to anything");
1220 error.SetErrorToGenericError();
1221 error.SetErrorString(bad_value_error);
1222 return false;
1223 }
1224
1225 if (P == LLDB_INVALID_ADDRESS)
1226 {
1227 if (log)
1228 log->Printf("StoreInst's pointer doesn't resolve to anything");
1229 error.SetErrorToGenericError();
1230 error.SetErrorString(bad_value_error);
1231 return false;
1232 }
1233
1234 lldb::addr_t R;
1235 lldb_private::Error read_error;
1236 memory_map.ReadPointerFromMemory(&R, P, read_error);
1237
1238 if (!read_error.Success())
1239 {
1240 if (log)
1241 log->Printf("Couldn't read the address to be loaded for a LoadInst");
1242 error.SetErrorToGenericError();
1243 error.SetErrorString(memory_read_error);
1244 return false;
1245 }
1246
1247 size_t target_size = data_layout.getTypeStoreSize(target_ty);
1248 lldb_private::DataBufferHeap buffer(target_size, 0);
1249
1250 read_error.Clear();
1251 memory_map.ReadMemory(buffer.GetBytes(), D, buffer.GetByteSize(), read_error);
1252 if (!read_error.Success())
1253 {
1254 if (log)
1255 log->Printf("Couldn't read from a region on behalf of a StoreInst");
1256 error.SetErrorToGenericError();
1257 error.SetErrorString(memory_read_error);
1258 return false;
1259 }
1260
1261 lldb_private::Error write_error;
1262 memory_map.WriteMemory(R, buffer.GetBytes(), buffer.GetByteSize(), write_error);
1263 if (!write_error.Success())
1264 {
1265 if (log)
1266 log->Printf("Couldn't write to a region on behalf of a StoreInst");
1267 error.SetErrorToGenericError();
Sean Callanan49630e72013-04-20 02:39:24 +00001268 error.SetErrorString(memory_write_error);
Sean Callanan14cb2aa2013-04-17 18:35:47 +00001269 return false;
1270 }
1271
1272 if (log)
1273 {
1274 log->Printf("Interpreted a StoreInst");
1275 log->Printf(" D : 0x%llx", D);
1276 log->Printf(" P : 0x%llx", P);
1277 log->Printf(" R : 0x%llx", R);
1278 }
1279 }
1280 break;
1281 }
1282
1283 ++frame.m_ii;
1284 }
1285
1286 if (num_insts >= 4096)
1287 {
1288 error.SetErrorToGenericError();
1289 error.SetErrorString(infinite_loop_error);
1290 return false;
1291 }
1292
1293 return false;
1294}