1 //===-- IRInterpreter.cpp -------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Expression/IRInterpreter.h"
10 #include "lldb/Core/Debugger.h"
11 #include "lldb/Core/Module.h"
12 #include "lldb/Core/ModuleSpec.h"
13 #include "lldb/Expression/DiagnosticManager.h"
14 #include "lldb/Expression/IRExecutionUnit.h"
15 #include "lldb/Expression/IRMemoryMap.h"
16 #include "lldb/Utility/ConstString.h"
17 #include "lldb/Utility/DataExtractor.h"
18 #include "lldb/Utility/Endian.h"
19 #include "lldb/Utility/LLDBLog.h"
20 #include "lldb/Utility/Log.h"
21 #include "lldb/Utility/Scalar.h"
22 #include "lldb/Utility/Status.h"
23 #include "lldb/Utility/StreamString.h"
24 #include "lldb/ValueObject/ValueObject.h"
26 #include "lldb/Target/ABI.h"
27 #include "lldb/Target/ExecutionContext.h"
28 #include "lldb/Target/Target.h"
29 #include "lldb/Target/Thread.h"
30 #include "lldb/Target/ThreadPlan.h"
31 #include "lldb/Target/ThreadPlanCallFunctionUsingABI.h"
33 #include "llvm/IR/Constants.h"
34 #include "llvm/IR/DataLayout.h"
35 #include "llvm/IR/Function.h"
36 #include "llvm/IR/Instructions.h"
37 #include "llvm/IR/Intrinsics.h"
38 #include "llvm/IR/LLVMContext.h"
39 #include "llvm/IR/Module.h"
40 #include "llvm/IR/Operator.h"
41 #include "llvm/Support/raw_ostream.h"
46 using lldb_private::LLDBLog
;
48 static std::string
PrintValue(const Value
*value
, bool truncate
= false) {
50 raw_string_ostream
rso(s
);
53 s
.resize(s
.length() - 1);
56 while ((offset
= s
.find('\n')) != s
.npos
)
58 while (s
[0] == ' ' || s
[0] == '\t')
64 static std::string
PrintType(const Type
*type
, bool truncate
= false) {
66 raw_string_ostream
rso(s
);
69 s
.resize(s
.length() - 1);
73 static bool CanIgnoreCall(const CallInst
*call
) {
74 const llvm::Function
*called_function
= call
->getCalledFunction();
79 if (called_function
->isIntrinsic()) {
80 switch (called_function
->getIntrinsicID()) {
83 case llvm::Intrinsic::dbg_declare
:
84 case llvm::Intrinsic::dbg_value
:
92 class InterpreterStackFrame
{
94 typedef std::map
<const Value
*, lldb::addr_t
> ValueMap
;
97 const DataLayout
&m_target_data
;
98 lldb_private::IRExecutionUnit
&m_execution_unit
;
99 const BasicBlock
*m_bb
= nullptr;
100 const BasicBlock
*m_prev_bb
= nullptr;
101 BasicBlock::const_iterator m_ii
;
102 BasicBlock::const_iterator m_ie
;
104 lldb::addr_t m_frame_process_address
;
106 lldb::addr_t m_stack_pointer
;
108 lldb::ByteOrder m_byte_order
;
109 size_t m_addr_byte_size
;
111 InterpreterStackFrame(const DataLayout
&target_data
,
112 lldb_private::IRExecutionUnit
&execution_unit
,
113 lldb::addr_t stack_frame_bottom
,
114 lldb::addr_t stack_frame_top
)
115 : m_target_data(target_data
), m_execution_unit(execution_unit
) {
116 m_byte_order
= (target_data
.isLittleEndian() ? lldb::eByteOrderLittle
117 : lldb::eByteOrderBig
);
118 m_addr_byte_size
= (target_data
.getPointerSize(0));
120 m_frame_process_address
= stack_frame_bottom
;
121 m_frame_size
= stack_frame_top
- stack_frame_bottom
;
122 m_stack_pointer
= stack_frame_top
;
125 ~InterpreterStackFrame() = default;
127 void Jump(const BasicBlock
*bb
) {
130 m_ii
= m_bb
->begin();
134 std::string
SummarizeValue(const Value
*value
) {
135 lldb_private::StreamString ss
;
137 ss
.Printf("%s", PrintValue(value
).c_str());
139 ValueMap::iterator i
= m_values
.find(value
);
141 if (i
!= m_values
.end()) {
142 lldb::addr_t addr
= i
->second
;
144 ss
.Printf(" 0x%llx", (unsigned long long)addr
);
147 return std::string(ss
.GetString());
150 bool AssignToMatchType(lldb_private::Scalar
&scalar
, llvm::APInt value
,
152 size_t type_size
= m_target_data
.getTypeStoreSize(type
);
158 type_size
= PowerOf2Ceil(type_size
);
160 scalar
= value
.zextOrTrunc(type_size
* 8);
164 bool EvaluateValue(lldb_private::Scalar
&scalar
, const Value
*value
,
166 const Constant
*constant
= dyn_cast
<Constant
>(value
);
169 if (constant
->getValueID() == Value::ConstantFPVal
) {
170 if (auto *cfp
= dyn_cast
<ConstantFP
>(constant
)) {
171 if (cfp
->getType()->isDoubleTy())
172 scalar
= cfp
->getValueAPF().convertToDouble();
173 else if (cfp
->getType()->isFloatTy())
174 scalar
= cfp
->getValueAPF().convertToFloat();
183 if (!ResolveConstantValue(value_apint
, constant
))
186 return AssignToMatchType(scalar
, value_apint
, value
->getType());
189 lldb::addr_t process_address
= ResolveValue(value
, module
);
190 size_t value_size
= m_target_data
.getTypeStoreSize(value
->getType());
192 lldb_private::DataExtractor value_extractor
;
193 lldb_private::Status extract_error
;
195 m_execution_unit
.GetMemoryData(value_extractor
, process_address
,
196 value_size
, extract_error
);
198 if (!extract_error
.Success())
201 lldb::offset_t offset
= 0;
202 if (value_size
<= 8) {
203 Type
*ty
= value
->getType();
204 if (ty
->isDoubleTy()) {
205 scalar
= value_extractor
.GetDouble(&offset
);
207 } else if (ty
->isFloatTy()) {
208 scalar
= value_extractor
.GetFloat(&offset
);
211 uint64_t u64value
= value_extractor
.GetMaxU64(&offset
, value_size
);
212 return AssignToMatchType(scalar
, llvm::APInt(64, u64value
),
220 bool AssignValue(const Value
*value
, lldb_private::Scalar scalar
,
222 lldb::addr_t process_address
= ResolveValue(value
, module
);
224 if (process_address
== LLDB_INVALID_ADDRESS
)
227 lldb_private::Scalar cast_scalar
;
228 Type
*vty
= value
->getType();
229 if (vty
->isFloatTy() || vty
->isDoubleTy()) {
230 cast_scalar
= scalar
;
232 scalar
.MakeUnsigned();
233 if (!AssignToMatchType(cast_scalar
, scalar
.UInt128(llvm::APInt()),
238 size_t value_byte_size
= m_target_data
.getTypeStoreSize(value
->getType());
240 lldb_private::DataBufferHeap
buf(value_byte_size
, 0);
242 lldb_private::Status get_data_error
;
244 if (!cast_scalar
.GetAsMemoryData(buf
.GetBytes(), buf
.GetByteSize(),
245 m_byte_order
, get_data_error
))
248 lldb_private::Status write_error
;
250 m_execution_unit
.WriteMemory(process_address
, buf
.GetBytes(),
251 buf
.GetByteSize(), write_error
);
253 return write_error
.Success();
256 bool ResolveConstantValue(APInt
&value
, const Constant
*constant
) {
257 switch (constant
->getValueID()) {
260 case Value::FunctionVal
:
261 if (const Function
*constant_func
= dyn_cast
<Function
>(constant
)) {
262 lldb_private::ConstString
name(constant_func
->getName());
263 bool missing_weak
= false;
264 lldb::addr_t addr
= m_execution_unit
.FindSymbol(name
, missing_weak
);
265 if (addr
== LLDB_INVALID_ADDRESS
)
267 value
= APInt(m_target_data
.getPointerSizeInBits(), addr
);
271 case Value::ConstantIntVal
:
272 if (const ConstantInt
*constant_int
= dyn_cast
<ConstantInt
>(constant
)) {
273 value
= constant_int
->getValue();
277 case Value::ConstantFPVal
:
278 if (const ConstantFP
*constant_fp
= dyn_cast
<ConstantFP
>(constant
)) {
279 value
= constant_fp
->getValueAPF().bitcastToAPInt();
283 case Value::ConstantExprVal
:
284 if (const ConstantExpr
*constant_expr
=
285 dyn_cast
<ConstantExpr
>(constant
)) {
286 switch (constant_expr
->getOpcode()) {
289 case Instruction::IntToPtr
:
290 case Instruction::PtrToInt
:
291 case Instruction::BitCast
:
292 return ResolveConstantValue(value
, constant_expr
->getOperand(0));
293 case Instruction::GetElementPtr
: {
294 ConstantExpr::const_op_iterator op_cursor
= constant_expr
->op_begin();
295 ConstantExpr::const_op_iterator op_end
= constant_expr
->op_end();
297 Constant
*base
= dyn_cast
<Constant
>(*op_cursor
);
302 if (!ResolveConstantValue(value
, base
))
307 if (op_cursor
== op_end
)
308 return true; // no offset to apply!
310 SmallVector
<Value
*, 8> indices(op_cursor
, op_end
);
312 cast
<GEPOperator
>(constant_expr
)->getSourceElementType();
314 // DataLayout::getIndexedOffsetInType assumes the indices are
315 // instances of ConstantInt.
317 m_target_data
.getIndexedOffsetInType(src_elem_ty
, indices
);
319 const bool is_signed
= true;
320 value
+= APInt(value
.getBitWidth(), offset
, is_signed
);
327 case Value::ConstantPointerNullVal
:
328 if (isa
<ConstantPointerNull
>(constant
)) {
329 value
= APInt(m_target_data
.getPointerSizeInBits(), 0);
337 bool MakeArgument(const Argument
*value
, uint64_t address
) {
338 lldb::addr_t data_address
= Malloc(value
->getType());
340 if (data_address
== LLDB_INVALID_ADDRESS
)
343 lldb_private::Status write_error
;
345 m_execution_unit
.WritePointerToMemory(data_address
, address
, write_error
);
347 if (!write_error
.Success()) {
348 lldb_private::Status free_error
;
349 m_execution_unit
.Free(data_address
, free_error
);
353 m_values
[value
] = data_address
;
355 lldb_private::Log
*log(GetLog(LLDBLog::Expressions
));
358 LLDB_LOGF(log
, "Made an allocation for argument %s",
359 PrintValue(value
).c_str());
360 LLDB_LOGF(log
, " Data region : %llx", (unsigned long long)address
);
361 LLDB_LOGF(log
, " Ref region : %llx",
362 (unsigned long long)data_address
);
368 bool ResolveConstant(lldb::addr_t process_address
, const Constant
*constant
) {
369 APInt resolved_value
;
371 if (!ResolveConstantValue(resolved_value
, constant
))
374 size_t constant_size
= m_target_data
.getTypeStoreSize(constant
->getType());
375 lldb_private::DataBufferHeap
buf(constant_size
, 0);
377 lldb_private::Status get_data_error
;
379 lldb_private::Scalar
resolved_scalar(
380 resolved_value
.zextOrTrunc(llvm::NextPowerOf2(constant_size
) * 8));
381 if (!resolved_scalar
.GetAsMemoryData(buf
.GetBytes(), buf
.GetByteSize(),
382 m_byte_order
, get_data_error
))
385 lldb_private::Status write_error
;
387 m_execution_unit
.WriteMemory(process_address
, buf
.GetBytes(),
388 buf
.GetByteSize(), write_error
);
390 return write_error
.Success();
393 lldb::addr_t
Malloc(size_t size
, uint8_t byte_alignment
) {
394 lldb::addr_t ret
= m_stack_pointer
;
397 ret
-= (ret
% byte_alignment
);
399 if (ret
< m_frame_process_address
)
400 return LLDB_INVALID_ADDRESS
;
402 m_stack_pointer
= ret
;
406 lldb::addr_t
Malloc(llvm::Type
*type
) {
407 lldb_private::Status alloc_error
;
409 return Malloc(m_target_data
.getTypeAllocSize(type
),
410 m_target_data
.getPrefTypeAlign(type
).value());
413 std::string
PrintData(lldb::addr_t addr
, llvm::Type
*type
) {
414 size_t length
= m_target_data
.getTypeStoreSize(type
);
416 lldb_private::DataBufferHeap
buf(length
, 0);
418 lldb_private::Status read_error
;
420 m_execution_unit
.ReadMemory(buf
.GetBytes(), addr
, length
, read_error
);
422 if (!read_error
.Success())
423 return std::string("<couldn't read data>");
425 lldb_private::StreamString ss
;
427 for (size_t i
= 0; i
< length
; i
++) {
428 if ((!(i
& 0xf)) && i
)
429 ss
.Printf("%02hhx - ", buf
.GetBytes()[i
]);
431 ss
.Printf("%02hhx ", buf
.GetBytes()[i
]);
434 return std::string(ss
.GetString());
437 lldb::addr_t
ResolveValue(const Value
*value
, Module
&module
) {
438 ValueMap::iterator i
= m_values
.find(value
);
440 if (i
!= m_values
.end())
443 // Fall back and allocate space [allocation type Alloca]
445 lldb::addr_t data_address
= Malloc(value
->getType());
447 if (const Constant
*constant
= dyn_cast
<Constant
>(value
)) {
448 if (!ResolveConstant(data_address
, constant
)) {
449 lldb_private::Status free_error
;
450 m_execution_unit
.Free(data_address
, free_error
);
451 return LLDB_INVALID_ADDRESS
;
455 m_values
[value
] = data_address
;
460 static const char *unsupported_opcode_error
=
461 "Interpreter doesn't handle one of the expression's opcodes";
462 static const char *unsupported_operand_error
=
463 "Interpreter doesn't handle one of the expression's operands";
464 static const char *interpreter_internal_error
=
465 "Interpreter encountered an internal error";
466 static const char *interrupt_error
=
467 "Interrupted while interpreting expression";
468 static const char *bad_value_error
=
469 "Interpreter couldn't resolve a value during execution";
470 static const char *memory_allocation_error
=
471 "Interpreter couldn't allocate memory";
472 static const char *memory_write_error
= "Interpreter couldn't write to memory";
473 static const char *memory_read_error
= "Interpreter couldn't read from memory";
474 static const char *timeout_error
=
475 "Reached timeout while interpreting expression";
476 static const char *too_many_functions_error
=
477 "Interpreter doesn't handle modules with multiple function bodies.";
479 static bool CanResolveConstant(llvm::Constant
*constant
) {
480 switch (constant
->getValueID()) {
483 case Value::ConstantIntVal
:
484 case Value::ConstantFPVal
:
485 case Value::FunctionVal
:
487 case Value::ConstantExprVal
:
488 if (const ConstantExpr
*constant_expr
= dyn_cast
<ConstantExpr
>(constant
)) {
489 switch (constant_expr
->getOpcode()) {
492 case Instruction::IntToPtr
:
493 case Instruction::PtrToInt
:
494 case Instruction::BitCast
:
495 return CanResolveConstant(constant_expr
->getOperand(0));
496 case Instruction::GetElementPtr
: {
497 // Check that the base can be constant-resolved.
498 ConstantExpr::const_op_iterator op_cursor
= constant_expr
->op_begin();
499 Constant
*base
= dyn_cast
<Constant
>(*op_cursor
);
500 if (!base
|| !CanResolveConstant(base
))
503 // Check that all other operands are just ConstantInt.
504 for (Value
*op
: make_range(constant_expr
->op_begin() + 1,
505 constant_expr
->op_end())) {
506 ConstantInt
*constant_int
= dyn_cast
<ConstantInt
>(op
);
516 case Value::ConstantPointerNullVal
:
521 bool IRInterpreter::CanInterpret(llvm::Module
&module
, llvm::Function
&function
,
522 lldb_private::Status
&error
,
523 const bool support_function_calls
) {
524 lldb_private::Log
*log(GetLog(LLDBLog::Expressions
));
526 bool saw_function_with_body
= false;
527 for (Function
&f
: module
) {
528 if (f
.begin() != f
.end()) {
529 if (saw_function_with_body
) {
530 LLDB_LOGF(log
, "More than one function in the module has a body");
531 error
= lldb_private::Status::FromErrorString(too_many_functions_error
);
534 saw_function_with_body
= true;
535 LLDB_LOGF(log
, "Saw function with body: %s", f
.getName().str().c_str());
539 for (BasicBlock
&bb
: function
) {
540 for (Instruction
&ii
: bb
) {
541 switch (ii
.getOpcode()) {
543 LLDB_LOGF(log
, "Unsupported instruction: %s", PrintValue(&ii
).c_str());
544 error
= lldb_private::Status::FromErrorString(unsupported_opcode_error
);
547 case Instruction::Add
:
548 case Instruction::Alloca
:
549 case Instruction::BitCast
:
550 case Instruction::Br
:
551 case Instruction::PHI
:
553 case Instruction::Call
: {
554 CallInst
*call_inst
= dyn_cast
<CallInst
>(&ii
);
558 lldb_private::Status::FromErrorString(interpreter_internal_error
);
562 if (!CanIgnoreCall(call_inst
) && !support_function_calls
) {
563 LLDB_LOGF(log
, "Unsupported instruction: %s",
564 PrintValue(&ii
).c_str());
566 lldb_private::Status::FromErrorString(unsupported_opcode_error
);
570 case Instruction::GetElementPtr
:
572 case Instruction::FCmp
:
573 case Instruction::ICmp
: {
574 CmpInst
*cmp_inst
= dyn_cast
<CmpInst
>(&ii
);
578 lldb_private::Status::FromErrorString(interpreter_internal_error
);
582 switch (cmp_inst
->getPredicate()) {
584 LLDB_LOGF(log
, "Unsupported ICmp predicate: %s",
585 PrintValue(&ii
).c_str());
588 lldb_private::Status::FromErrorString(unsupported_opcode_error
);
591 case CmpInst::FCMP_OEQ
:
592 case CmpInst::ICMP_EQ
:
593 case CmpInst::FCMP_UNE
:
594 case CmpInst::ICMP_NE
:
595 case CmpInst::FCMP_OGT
:
596 case CmpInst::ICMP_UGT
:
597 case CmpInst::FCMP_OGE
:
598 case CmpInst::ICMP_UGE
:
599 case CmpInst::FCMP_OLT
:
600 case CmpInst::ICMP_ULT
:
601 case CmpInst::FCMP_OLE
:
602 case CmpInst::ICMP_ULE
:
603 case CmpInst::ICMP_SGT
:
604 case CmpInst::ICMP_SGE
:
605 case CmpInst::ICMP_SLT
:
606 case CmpInst::ICMP_SLE
:
610 case Instruction::And
:
611 case Instruction::AShr
:
612 case Instruction::IntToPtr
:
613 case Instruction::PtrToInt
:
614 case Instruction::Load
:
615 case Instruction::LShr
:
616 case Instruction::Mul
:
617 case Instruction::Or
:
618 case Instruction::Ret
:
619 case Instruction::SDiv
:
620 case Instruction::SExt
:
621 case Instruction::Shl
:
622 case Instruction::SRem
:
623 case Instruction::Store
:
624 case Instruction::Sub
:
625 case Instruction::Trunc
:
626 case Instruction::UDiv
:
627 case Instruction::URem
:
628 case Instruction::Xor
:
629 case Instruction::ZExt
:
631 case Instruction::FAdd
:
632 case Instruction::FSub
:
633 case Instruction::FMul
:
634 case Instruction::FDiv
:
638 for (unsigned oi
= 0, oe
= ii
.getNumOperands(); oi
!= oe
; ++oi
) {
639 Value
*operand
= ii
.getOperand(oi
);
640 Type
*operand_type
= operand
->getType();
642 switch (operand_type
->getTypeID()) {
645 case Type::FixedVectorTyID
:
646 case Type::ScalableVectorTyID
: {
647 LLDB_LOGF(log
, "Unsupported operand type: %s",
648 PrintType(operand_type
).c_str());
650 lldb_private::Status::FromErrorString(unsupported_operand_error
);
655 // The IR interpreter currently doesn't know about
656 // 128-bit integers. As they're not that frequent,
657 // we can just fall back to the JIT rather than
659 if (operand_type
->getPrimitiveSizeInBits() > 64) {
660 LLDB_LOGF(log
, "Unsupported operand type: %s",
661 PrintType(operand_type
).c_str());
663 lldb_private::Status::FromErrorString(unsupported_operand_error
);
667 if (Constant
*constant
= llvm::dyn_cast
<Constant
>(operand
)) {
668 if (!CanResolveConstant(constant
)) {
669 LLDB_LOGF(log
, "Unsupported constant: %s",
670 PrintValue(constant
).c_str());
671 error
= lldb_private::Status::FromErrorString(
672 unsupported_operand_error
);
683 bool IRInterpreter::Interpret(llvm::Module
&module
, llvm::Function
&function
,
684 llvm::ArrayRef
<lldb::addr_t
> args
,
685 lldb_private::IRExecutionUnit
&execution_unit
,
686 lldb_private::Status
&error
,
687 lldb::addr_t stack_frame_bottom
,
688 lldb::addr_t stack_frame_top
,
689 lldb_private::ExecutionContext
&exe_ctx
,
690 lldb_private::Timeout
<std::micro
> timeout
) {
691 lldb_private::Log
*log(GetLog(LLDBLog::Expressions
));
695 raw_string_ostream
oss(s
);
697 module
.print(oss
, nullptr);
699 LLDB_LOGF(log
, "Module as passed in to IRInterpreter::Interpret: \n\"%s\"",
703 const DataLayout
&data_layout
= module
.getDataLayout();
705 InterpreterStackFrame
frame(data_layout
, execution_unit
, stack_frame_bottom
,
708 if (frame
.m_frame_process_address
== LLDB_INVALID_ADDRESS
) {
710 lldb_private::Status::FromErrorString("Couldn't allocate stack frame");
715 for (llvm::Function::arg_iterator ai
= function
.arg_begin(),
716 ae
= function
.arg_end();
717 ai
!= ae
; ++ai
, ++arg_index
) {
718 if (args
.size() <= static_cast<size_t>(arg_index
)) {
719 error
= lldb_private::Status::FromErrorString(
720 "Not enough arguments passed in to function");
724 lldb::addr_t ptr
= args
[arg_index
];
726 frame
.MakeArgument(&*ai
, ptr
);
729 frame
.Jump(&function
.front());
731 lldb_private::Process
*process
= exe_ctx
.GetProcessPtr();
732 lldb_private::Target
*target
= exe_ctx
.GetTargetPtr();
734 using clock
= std::chrono::steady_clock
;
736 // Compute the time at which the timeout has been exceeded.
737 std::optional
<clock::time_point
> end_time
;
738 if (timeout
&& timeout
->count() > 0)
739 end_time
= clock::now() + *timeout
;
741 while (frame
.m_ii
!= frame
.m_ie
) {
742 // Timeout reached: stop interpreting.
743 if (end_time
&& clock::now() >= *end_time
) {
744 error
= lldb_private::Status::FromErrorString(timeout_error
);
748 // If we have access to the debugger we can honor an interrupt request.
750 if (INTERRUPT_REQUESTED(target
->GetDebugger(),
751 "Interrupted in IR interpreting.")) {
752 error
= lldb_private::Status::FromErrorString(interrupt_error
);
757 const Instruction
*inst
= &*frame
.m_ii
;
759 LLDB_LOGF(log
, "Interpreting %s", PrintValue(inst
).c_str());
761 switch (inst
->getOpcode()) {
765 case Instruction::Add
:
766 case Instruction::Sub
:
767 case Instruction::Mul
:
768 case Instruction::SDiv
:
769 case Instruction::UDiv
:
770 case Instruction::SRem
:
771 case Instruction::URem
:
772 case Instruction::Shl
:
773 case Instruction::LShr
:
774 case Instruction::AShr
:
775 case Instruction::And
:
776 case Instruction::Or
:
777 case Instruction::Xor
:
778 case Instruction::FAdd
:
779 case Instruction::FSub
:
780 case Instruction::FMul
:
781 case Instruction::FDiv
: {
782 const BinaryOperator
*bin_op
= dyn_cast
<BinaryOperator
>(inst
);
787 "getOpcode() returns %s, but instruction is not a BinaryOperator",
788 inst
->getOpcodeName());
790 lldb_private::Status::FromErrorString(interpreter_internal_error
);
794 Value
*lhs
= inst
->getOperand(0);
795 Value
*rhs
= inst
->getOperand(1);
797 lldb_private::Scalar L
;
798 lldb_private::Scalar R
;
800 if (!frame
.EvaluateValue(L
, lhs
, module
)) {
801 LLDB_LOGF(log
, "Couldn't evaluate %s", PrintValue(lhs
).c_str());
802 error
= lldb_private::Status::FromErrorString(bad_value_error
);
806 if (!frame
.EvaluateValue(R
, rhs
, module
)) {
807 LLDB_LOGF(log
, "Couldn't evaluate %s", PrintValue(rhs
).c_str());
808 error
= lldb_private::Status::FromErrorString(bad_value_error
);
812 lldb_private::Scalar result
;
814 switch (inst
->getOpcode()) {
817 case Instruction::Add
:
818 case Instruction::FAdd
:
821 case Instruction::Mul
:
822 case Instruction::FMul
:
825 case Instruction::Sub
:
826 case Instruction::FSub
:
829 case Instruction::SDiv
:
834 case Instruction::UDiv
:
839 case Instruction::FDiv
:
842 case Instruction::SRem
:
847 case Instruction::URem
:
852 case Instruction::Shl
:
855 case Instruction::AShr
:
858 case Instruction::LShr
:
860 result
.ShiftRightLogical(R
);
862 case Instruction::And
:
865 case Instruction::Or
:
868 case Instruction::Xor
:
873 frame
.AssignValue(inst
, result
, module
);
876 LLDB_LOGF(log
, "Interpreted a %s", inst
->getOpcodeName());
877 LLDB_LOGF(log
, " L : %s", frame
.SummarizeValue(lhs
).c_str());
878 LLDB_LOGF(log
, " R : %s", frame
.SummarizeValue(rhs
).c_str());
879 LLDB_LOGF(log
, " = : %s", frame
.SummarizeValue(inst
).c_str());
882 case Instruction::Alloca
: {
883 const AllocaInst
*alloca_inst
= cast
<AllocaInst
>(inst
);
885 if (alloca_inst
->isArrayAllocation()) {
887 "AllocaInsts are not handled if isArrayAllocation() is true");
888 error
= lldb_private::Status::FromErrorString(unsupported_opcode_error
);
892 // The semantics of Alloca are:
893 // Create a region R of virtual memory of type T, backed by a data
895 // Create a region P of virtual memory of type T*, backed by a data
897 // Write the virtual address of R into P
899 Type
*T
= alloca_inst
->getAllocatedType();
900 Type
*Tptr
= alloca_inst
->getType();
902 lldb::addr_t R
= frame
.Malloc(T
);
904 if (R
== LLDB_INVALID_ADDRESS
) {
905 LLDB_LOGF(log
, "Couldn't allocate memory for an AllocaInst");
906 error
= lldb_private::Status::FromErrorString(memory_allocation_error
);
910 lldb::addr_t P
= frame
.Malloc(Tptr
);
912 if (P
== LLDB_INVALID_ADDRESS
) {
914 "Couldn't allocate the result pointer for an AllocaInst");
915 error
= lldb_private::Status::FromErrorString(memory_allocation_error
);
919 lldb_private::Status write_error
;
921 execution_unit
.WritePointerToMemory(P
, R
, write_error
);
923 if (!write_error
.Success()) {
924 LLDB_LOGF(log
, "Couldn't write the result pointer for an AllocaInst");
925 error
= lldb_private::Status::FromErrorString(memory_write_error
);
926 lldb_private::Status free_error
;
927 execution_unit
.Free(P
, free_error
);
928 execution_unit
.Free(R
, free_error
);
932 frame
.m_values
[alloca_inst
] = P
;
935 LLDB_LOGF(log
, "Interpreted an AllocaInst");
936 LLDB_LOGF(log
, " R : 0x%" PRIx64
, R
);
937 LLDB_LOGF(log
, " P : 0x%" PRIx64
, P
);
940 case Instruction::BitCast
:
941 case Instruction::ZExt
: {
942 const CastInst
*cast_inst
= cast
<CastInst
>(inst
);
944 Value
*source
= cast_inst
->getOperand(0);
946 lldb_private::Scalar S
;
948 if (!frame
.EvaluateValue(S
, source
, module
)) {
949 LLDB_LOGF(log
, "Couldn't evaluate %s", PrintValue(source
).c_str());
950 error
= lldb_private::Status::FromErrorString(bad_value_error
);
954 frame
.AssignValue(inst
, S
, module
);
956 case Instruction::SExt
: {
957 const CastInst
*cast_inst
= cast
<CastInst
>(inst
);
959 Value
*source
= cast_inst
->getOperand(0);
961 lldb_private::Scalar S
;
963 if (!frame
.EvaluateValue(S
, source
, module
)) {
964 LLDB_LOGF(log
, "Couldn't evaluate %s", PrintValue(source
).c_str());
965 error
= lldb_private::Status::FromErrorString(bad_value_error
);
971 lldb_private::Scalar
S_signextend(S
.SLongLong());
973 frame
.AssignValue(inst
, S_signextend
, module
);
975 case Instruction::Br
: {
976 const BranchInst
*br_inst
= cast
<BranchInst
>(inst
);
978 if (br_inst
->isConditional()) {
979 Value
*condition
= br_inst
->getCondition();
981 lldb_private::Scalar C
;
983 if (!frame
.EvaluateValue(C
, condition
, module
)) {
984 LLDB_LOGF(log
, "Couldn't evaluate %s", PrintValue(condition
).c_str());
985 error
= lldb_private::Status::FromErrorString(bad_value_error
);
990 frame
.Jump(br_inst
->getSuccessor(0));
992 frame
.Jump(br_inst
->getSuccessor(1));
995 LLDB_LOGF(log
, "Interpreted a BrInst with a condition");
996 LLDB_LOGF(log
, " cond : %s",
997 frame
.SummarizeValue(condition
).c_str());
1000 frame
.Jump(br_inst
->getSuccessor(0));
1003 LLDB_LOGF(log
, "Interpreted a BrInst with no condition");
1008 case Instruction::PHI
: {
1009 const PHINode
*phi_inst
= cast
<PHINode
>(inst
);
1010 if (!frame
.m_prev_bb
) {
1012 "Encountered PHI node without having jumped from another "
1015 lldb_private::Status::FromErrorString(interpreter_internal_error
);
1019 Value
*value
= phi_inst
->getIncomingValueForBlock(frame
.m_prev_bb
);
1020 lldb_private::Scalar result
;
1021 if (!frame
.EvaluateValue(result
, value
, module
)) {
1022 LLDB_LOGF(log
, "Couldn't evaluate %s", PrintValue(value
).c_str());
1023 error
= lldb_private::Status::FromErrorString(bad_value_error
);
1026 frame
.AssignValue(inst
, result
, module
);
1029 LLDB_LOGF(log
, "Interpreted a %s", inst
->getOpcodeName());
1030 LLDB_LOGF(log
, " Incoming value : %s",
1031 frame
.SummarizeValue(value
).c_str());
1034 case Instruction::GetElementPtr
: {
1035 const GetElementPtrInst
*gep_inst
= cast
<GetElementPtrInst
>(inst
);
1037 const Value
*pointer_operand
= gep_inst
->getPointerOperand();
1038 Type
*src_elem_ty
= gep_inst
->getSourceElementType();
1040 lldb_private::Scalar P
;
1042 if (!frame
.EvaluateValue(P
, pointer_operand
, module
)) {
1043 LLDB_LOGF(log
, "Couldn't evaluate %s",
1044 PrintValue(pointer_operand
).c_str());
1045 error
= lldb_private::Status::FromErrorString(bad_value_error
);
1049 typedef SmallVector
<Value
*, 8> IndexVector
;
1050 typedef IndexVector::iterator IndexIterator
;
1052 SmallVector
<Value
*, 8> indices(gep_inst
->idx_begin(),
1053 gep_inst
->idx_end());
1055 SmallVector
<Value
*, 8> const_indices
;
1057 for (IndexIterator ii
= indices
.begin(), ie
= indices
.end(); ii
!= ie
;
1059 ConstantInt
*constant_index
= dyn_cast
<ConstantInt
>(*ii
);
1061 if (!constant_index
) {
1062 lldb_private::Scalar I
;
1064 if (!frame
.EvaluateValue(I
, *ii
, module
)) {
1065 LLDB_LOGF(log
, "Couldn't evaluate %s", PrintValue(*ii
).c_str());
1066 error
= lldb_private::Status::FromErrorString(bad_value_error
);
1070 LLDB_LOGF(log
, "Evaluated constant index %s as %llu",
1071 PrintValue(*ii
).c_str(), I
.ULongLong(LLDB_INVALID_ADDRESS
));
1073 constant_index
= cast
<ConstantInt
>(ConstantInt::get(
1074 (*ii
)->getType(), I
.ULongLong(LLDB_INVALID_ADDRESS
)));
1077 const_indices
.push_back(constant_index
);
1081 data_layout
.getIndexedOffsetInType(src_elem_ty
, const_indices
);
1083 lldb_private::Scalar Poffset
= P
+ offset
;
1085 frame
.AssignValue(inst
, Poffset
, module
);
1088 LLDB_LOGF(log
, "Interpreted a GetElementPtrInst");
1089 LLDB_LOGF(log
, " P : %s",
1090 frame
.SummarizeValue(pointer_operand
).c_str());
1091 LLDB_LOGF(log
, " Poffset : %s", frame
.SummarizeValue(inst
).c_str());
1094 case Instruction::FCmp
:
1095 case Instruction::ICmp
: {
1096 const CmpInst
*icmp_inst
= cast
<CmpInst
>(inst
);
1098 CmpInst::Predicate predicate
= icmp_inst
->getPredicate();
1100 Value
*lhs
= inst
->getOperand(0);
1101 Value
*rhs
= inst
->getOperand(1);
1103 lldb_private::Scalar L
;
1104 lldb_private::Scalar R
;
1106 if (!frame
.EvaluateValue(L
, lhs
, module
)) {
1107 LLDB_LOGF(log
, "Couldn't evaluate %s", PrintValue(lhs
).c_str());
1108 error
= lldb_private::Status::FromErrorString(bad_value_error
);
1112 if (!frame
.EvaluateValue(R
, rhs
, module
)) {
1113 LLDB_LOGF(log
, "Couldn't evaluate %s", PrintValue(rhs
).c_str());
1114 error
= lldb_private::Status::FromErrorString(bad_value_error
);
1118 lldb_private::Scalar result
;
1120 switch (predicate
) {
1123 case CmpInst::ICMP_EQ
:
1124 case CmpInst::FCMP_OEQ
:
1127 case CmpInst::ICMP_NE
:
1128 case CmpInst::FCMP_UNE
:
1131 case CmpInst::ICMP_UGT
:
1136 case CmpInst::ICMP_UGE
:
1141 case CmpInst::FCMP_OGE
:
1144 case CmpInst::FCMP_OGT
:
1147 case CmpInst::ICMP_ULT
:
1152 case CmpInst::FCMP_OLT
:
1155 case CmpInst::ICMP_ULE
:
1160 case CmpInst::FCMP_OLE
:
1163 case CmpInst::ICMP_SGT
:
1168 case CmpInst::ICMP_SGE
:
1173 case CmpInst::ICMP_SLT
:
1178 case CmpInst::ICMP_SLE
:
1185 frame
.AssignValue(inst
, result
, module
);
1188 LLDB_LOGF(log
, "Interpreted an ICmpInst");
1189 LLDB_LOGF(log
, " L : %s", frame
.SummarizeValue(lhs
).c_str());
1190 LLDB_LOGF(log
, " R : %s", frame
.SummarizeValue(rhs
).c_str());
1191 LLDB_LOGF(log
, " = : %s", frame
.SummarizeValue(inst
).c_str());
1194 case Instruction::IntToPtr
: {
1195 const IntToPtrInst
*int_to_ptr_inst
= cast
<IntToPtrInst
>(inst
);
1197 Value
*src_operand
= int_to_ptr_inst
->getOperand(0);
1199 lldb_private::Scalar I
;
1201 if (!frame
.EvaluateValue(I
, src_operand
, module
)) {
1202 LLDB_LOGF(log
, "Couldn't evaluate %s", PrintValue(src_operand
).c_str());
1203 error
= lldb_private::Status::FromErrorString(bad_value_error
);
1207 frame
.AssignValue(inst
, I
, module
);
1210 LLDB_LOGF(log
, "Interpreted an IntToPtr");
1211 LLDB_LOGF(log
, " Src : %s", frame
.SummarizeValue(src_operand
).c_str());
1212 LLDB_LOGF(log
, " = : %s", frame
.SummarizeValue(inst
).c_str());
1215 case Instruction::PtrToInt
: {
1216 const PtrToIntInst
*ptr_to_int_inst
= cast
<PtrToIntInst
>(inst
);
1218 Value
*src_operand
= ptr_to_int_inst
->getOperand(0);
1220 lldb_private::Scalar I
;
1222 if (!frame
.EvaluateValue(I
, src_operand
, module
)) {
1223 LLDB_LOGF(log
, "Couldn't evaluate %s", PrintValue(src_operand
).c_str());
1224 error
= lldb_private::Status::FromErrorString(bad_value_error
);
1228 frame
.AssignValue(inst
, I
, module
);
1231 LLDB_LOGF(log
, "Interpreted a PtrToInt");
1232 LLDB_LOGF(log
, " Src : %s", frame
.SummarizeValue(src_operand
).c_str());
1233 LLDB_LOGF(log
, " = : %s", frame
.SummarizeValue(inst
).c_str());
1236 case Instruction::Trunc
: {
1237 const TruncInst
*trunc_inst
= cast
<TruncInst
>(inst
);
1239 Value
*src_operand
= trunc_inst
->getOperand(0);
1241 lldb_private::Scalar I
;
1243 if (!frame
.EvaluateValue(I
, src_operand
, module
)) {
1244 LLDB_LOGF(log
, "Couldn't evaluate %s", PrintValue(src_operand
).c_str());
1245 error
= lldb_private::Status::FromErrorString(bad_value_error
);
1249 frame
.AssignValue(inst
, I
, module
);
1252 LLDB_LOGF(log
, "Interpreted a Trunc");
1253 LLDB_LOGF(log
, " Src : %s", frame
.SummarizeValue(src_operand
).c_str());
1254 LLDB_LOGF(log
, " = : %s", frame
.SummarizeValue(inst
).c_str());
1257 case Instruction::Load
: {
1258 const LoadInst
*load_inst
= cast
<LoadInst
>(inst
);
1260 // The semantics of Load are:
1261 // Create a region D that will contain the loaded data
1262 // Resolve the region P containing a pointer
1263 // Dereference P to get the region R that the data should be loaded from
1264 // Transfer a unit of type type(D) from R to D
1266 const Value
*pointer_operand
= load_inst
->getPointerOperand();
1268 lldb::addr_t D
= frame
.ResolveValue(load_inst
, module
);
1269 lldb::addr_t P
= frame
.ResolveValue(pointer_operand
, module
);
1271 if (D
== LLDB_INVALID_ADDRESS
) {
1272 LLDB_LOGF(log
, "LoadInst's value doesn't resolve to anything");
1273 error
= lldb_private::Status::FromErrorString(bad_value_error
);
1277 if (P
== LLDB_INVALID_ADDRESS
) {
1278 LLDB_LOGF(log
, "LoadInst's pointer doesn't resolve to anything");
1279 error
= lldb_private::Status::FromErrorString(bad_value_error
);
1284 lldb_private::Status read_error
;
1285 execution_unit
.ReadPointerFromMemory(&R
, P
, read_error
);
1287 if (!read_error
.Success()) {
1288 LLDB_LOGF(log
, "Couldn't read the address to be loaded for a LoadInst");
1289 error
= lldb_private::Status::FromErrorString(memory_read_error
);
1293 Type
*target_ty
= load_inst
->getType();
1294 size_t target_size
= data_layout
.getTypeStoreSize(target_ty
);
1295 lldb_private::DataBufferHeap
buffer(target_size
, 0);
1298 execution_unit
.ReadMemory(buffer
.GetBytes(), R
, buffer
.GetByteSize(),
1300 if (!read_error
.Success()) {
1301 LLDB_LOGF(log
, "Couldn't read from a region on behalf of a LoadInst");
1302 error
= lldb_private::Status::FromErrorString(memory_read_error
);
1306 lldb_private::Status write_error
;
1307 execution_unit
.WriteMemory(D
, buffer
.GetBytes(), buffer
.GetByteSize(),
1309 if (!write_error
.Success()) {
1310 LLDB_LOGF(log
, "Couldn't write to a region on behalf of a LoadInst");
1311 error
= lldb_private::Status::FromErrorString(memory_write_error
);
1316 LLDB_LOGF(log
, "Interpreted a LoadInst");
1317 LLDB_LOGF(log
, " P : 0x%" PRIx64
, P
);
1318 LLDB_LOGF(log
, " R : 0x%" PRIx64
, R
);
1319 LLDB_LOGF(log
, " D : 0x%" PRIx64
, D
);
1322 case Instruction::Ret
: {
1325 case Instruction::Store
: {
1326 const StoreInst
*store_inst
= cast
<StoreInst
>(inst
);
1328 // The semantics of Store are:
1329 // Resolve the region D containing the data to be stored
1330 // Resolve the region P containing a pointer
1331 // Dereference P to get the region R that the data should be stored in
1332 // Transfer a unit of type type(D) from D to R
1334 const Value
*value_operand
= store_inst
->getValueOperand();
1335 const Value
*pointer_operand
= store_inst
->getPointerOperand();
1337 lldb::addr_t D
= frame
.ResolveValue(value_operand
, module
);
1338 lldb::addr_t P
= frame
.ResolveValue(pointer_operand
, module
);
1340 if (D
== LLDB_INVALID_ADDRESS
) {
1341 LLDB_LOGF(log
, "StoreInst's value doesn't resolve to anything");
1342 error
= lldb_private::Status::FromErrorString(bad_value_error
);
1346 if (P
== LLDB_INVALID_ADDRESS
) {
1347 LLDB_LOGF(log
, "StoreInst's pointer doesn't resolve to anything");
1348 error
= lldb_private::Status::FromErrorString(bad_value_error
);
1353 lldb_private::Status read_error
;
1354 execution_unit
.ReadPointerFromMemory(&R
, P
, read_error
);
1356 if (!read_error
.Success()) {
1357 LLDB_LOGF(log
, "Couldn't read the address to be loaded for a LoadInst");
1358 error
= lldb_private::Status::FromErrorString(memory_read_error
);
1362 Type
*target_ty
= value_operand
->getType();
1363 size_t target_size
= data_layout
.getTypeStoreSize(target_ty
);
1364 lldb_private::DataBufferHeap
buffer(target_size
, 0);
1367 execution_unit
.ReadMemory(buffer
.GetBytes(), D
, buffer
.GetByteSize(),
1369 if (!read_error
.Success()) {
1370 LLDB_LOGF(log
, "Couldn't read from a region on behalf of a StoreInst");
1371 error
= lldb_private::Status::FromErrorString(memory_read_error
);
1375 lldb_private::Status write_error
;
1376 execution_unit
.WriteMemory(R
, buffer
.GetBytes(), buffer
.GetByteSize(),
1378 if (!write_error
.Success()) {
1379 LLDB_LOGF(log
, "Couldn't write to a region on behalf of a StoreInst");
1380 error
= lldb_private::Status::FromErrorString(memory_write_error
);
1385 LLDB_LOGF(log
, "Interpreted a StoreInst");
1386 LLDB_LOGF(log
, " D : 0x%" PRIx64
, D
);
1387 LLDB_LOGF(log
, " P : 0x%" PRIx64
, P
);
1388 LLDB_LOGF(log
, " R : 0x%" PRIx64
, R
);
1391 case Instruction::Call
: {
1392 const CallInst
*call_inst
= cast
<CallInst
>(inst
);
1394 if (CanIgnoreCall(call_inst
))
1397 // Get the return type
1398 llvm::Type
*returnType
= call_inst
->getType();
1399 if (returnType
== nullptr) {
1400 error
= lldb_private::Status::FromErrorString(
1401 "unable to access return type");
1405 // Work with void, integer and pointer return types
1406 if (!returnType
->isVoidTy() && !returnType
->isIntegerTy() &&
1407 !returnType
->isPointerTy()) {
1408 error
= lldb_private::Status::FromErrorString(
1409 "return type is not supported");
1413 // Check we can actually get a thread
1414 if (exe_ctx
.GetThreadPtr() == nullptr) {
1416 lldb_private::Status::FromErrorString("unable to acquire thread");
1420 // Make sure we have a valid process
1423 lldb_private::Status::FromErrorString("unable to get the process");
1427 // Find the address of the callee function
1428 lldb_private::Scalar I
;
1429 const llvm::Value
*val
= call_inst
->getCalledOperand();
1431 if (!frame
.EvaluateValue(I
, val
, module
)) {
1432 error
= lldb_private::Status::FromErrorString(
1433 "unable to get address of function");
1436 lldb_private::Address
funcAddr(I
.ULongLong(LLDB_INVALID_ADDRESS
));
1438 lldb_private::DiagnosticManager diagnostics
;
1439 lldb_private::EvaluateExpressionOptions options
;
1441 llvm::FunctionType
*prototype
= call_inst
->getFunctionType();
1443 // Find number of arguments
1444 const int numArgs
= call_inst
->arg_size();
1446 // We work with a fixed array of 16 arguments which is our upper limit
1447 static lldb_private::ABI::CallArgument rawArgs
[16];
1448 if (numArgs
>= 16) {
1449 error
= lldb_private::Status::FromErrorString(
1450 "function takes too many arguments");
1454 // Push all function arguments to the argument list that will be passed
1455 // to the call function thread plan
1456 for (int i
= 0; i
< numArgs
; i
++) {
1457 // Get details of this argument
1458 llvm::Value
*arg_op
= call_inst
->getArgOperand(i
);
1459 llvm::Type
*arg_ty
= arg_op
->getType();
1461 // Ensure that this argument is an supported type
1462 if (!arg_ty
->isIntegerTy() && !arg_ty
->isPointerTy()) {
1463 error
= lldb_private::Status::FromErrorStringWithFormat(
1464 "argument %d must be integer type", i
);
1468 // Extract the arguments value
1469 lldb_private::Scalar tmp_op
= 0;
1470 if (!frame
.EvaluateValue(tmp_op
, arg_op
, module
)) {
1471 error
= lldb_private::Status::FromErrorStringWithFormat(
1472 "unable to evaluate argument %d", i
);
1476 // Check if this is a string literal or constant string pointer
1477 if (arg_ty
->isPointerTy()) {
1478 lldb::addr_t addr
= tmp_op
.ULongLong();
1479 size_t dataSize
= 0;
1481 bool Success
= execution_unit
.GetAllocSize(addr
, dataSize
);
1482 UNUSED_IF_ASSERT_DISABLED(Success
);
1484 "unable to locate host data for transfer to device");
1485 // Create the required buffer
1486 rawArgs
[i
].size
= dataSize
;
1487 rawArgs
[i
].data_up
.reset(new uint8_t[dataSize
+ 1]);
1489 // Read string from host memory
1490 execution_unit
.ReadMemory(rawArgs
[i
].data_up
.get(), addr
, dataSize
,
1492 assert(!error
.Fail() &&
1493 "we have failed to read the string from memory");
1495 // Add null terminator
1496 rawArgs
[i
].data_up
[dataSize
] = '\0';
1497 rawArgs
[i
].type
= lldb_private::ABI::CallArgument::HostPointer
;
1498 } else /* if ( arg_ty->isPointerTy() ) */
1500 rawArgs
[i
].type
= lldb_private::ABI::CallArgument::TargetValue
;
1501 // Get argument size in bytes
1502 rawArgs
[i
].size
= arg_ty
->getIntegerBitWidth() / 8;
1503 // Push value into argument list for thread plan
1504 rawArgs
[i
].value
= tmp_op
.ULongLong();
1508 // Pack the arguments into an llvm::array
1509 llvm::ArrayRef
<lldb_private::ABI::CallArgument
> args(rawArgs
, numArgs
);
1511 // Setup a thread plan to call the target function
1512 lldb::ThreadPlanSP
call_plan_sp(
1513 new lldb_private::ThreadPlanCallFunctionUsingABI(
1514 exe_ctx
.GetThreadRef(), funcAddr
, *prototype
, *returnType
, args
,
1517 // Check if the plan is valid
1518 lldb_private::StreamString ss
;
1519 if (!call_plan_sp
|| !call_plan_sp
->ValidatePlan(&ss
)) {
1520 error
= lldb_private::Status::FromErrorStringWithFormat(
1521 "unable to make ThreadPlanCallFunctionUsingABI for 0x%llx",
1526 process
->SetRunningUserExpression(true);
1528 // Execute the actual function call thread plan
1529 lldb::ExpressionResults res
=
1530 process
->RunThreadPlan(exe_ctx
, call_plan_sp
, options
, diagnostics
);
1532 // Check that the thread plan completed successfully
1533 if (res
!= lldb::ExpressionResults::eExpressionCompleted
) {
1534 error
= lldb_private::Status::FromErrorString(
1535 "ThreadPlanCallFunctionUsingABI failed");
1539 process
->SetRunningUserExpression(false);
1542 if (returnType
->isVoidTy()) {
1543 // Cant assign to void types, so we leave the frame untouched
1545 // Integer or pointer return type
1546 if (returnType
->isIntegerTy() || returnType
->isPointerTy()) {
1547 // Get the encapsulated return value
1548 lldb::ValueObjectSP retVal
= call_plan_sp
.get()->GetReturnValueObject();
1550 lldb_private::Scalar returnVal
= -1;
1551 lldb_private::ValueObject
*vobj
= retVal
.get();
1553 // Check if the return value is valid
1554 if (vobj
== nullptr || !retVal
) {
1555 error
= lldb_private::Status::FromErrorString(
1556 "unable to get the return value");
1560 // Extract the return value as a integer
1561 lldb_private::Value
&value
= vobj
->GetValue();
1562 returnVal
= value
.GetScalar();
1564 // Push the return value as the result
1565 frame
.AssignValue(inst
, returnVal
, module
);