1e2411fabSZachary Turner //===-- FunctionCaller.cpp ---------------------------------------*- C++-*-===//
2151c032cSJim Ingham //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6151c032cSJim Ingham //
7151c032cSJim Ingham //===----------------------------------------------------------------------===//
8151c032cSJim Ingham 
9151c032cSJim Ingham 
10579e70c9SSean Callanan #include "lldb/Expression/FunctionCaller.h"
11151c032cSJim Ingham #include "lldb/Core/Module.h"
12151c032cSJim Ingham #include "lldb/Core/ValueObject.h"
13151c032cSJim Ingham #include "lldb/Core/ValueObjectList.h"
14579e70c9SSean Callanan #include "lldb/Expression/DiagnosticManager.h"
15151c032cSJim Ingham #include "lldb/Expression/IRExecutionUnit.h"
16151c032cSJim Ingham #include "lldb/Interpreter/CommandReturnObject.h"
17151c032cSJim Ingham #include "lldb/Symbol/Function.h"
18151c032cSJim Ingham #include "lldb/Symbol/Type.h"
19151c032cSJim Ingham #include "lldb/Target/ExecutionContext.h"
20151c032cSJim Ingham #include "lldb/Target/Process.h"
21151c032cSJim Ingham #include "lldb/Target/RegisterContext.h"
22151c032cSJim Ingham #include "lldb/Target/Target.h"
23151c032cSJim Ingham #include "lldb/Target/Thread.h"
24151c032cSJim Ingham #include "lldb/Target/ThreadPlan.h"
25151c032cSJim Ingham #include "lldb/Target/ThreadPlanCallFunction.h"
26666cc0b2SZachary Turner #include "lldb/Utility/DataExtractor.h"
276f9e6901SZachary Turner #include "lldb/Utility/Log.h"
28d821c997SPavel Labath #include "lldb/Utility/State.h"
29151c032cSJim Ingham 
30151c032cSJim Ingham using namespace lldb_private;
31151c032cSJim Ingham 
32*52f3a2faSRaphael Isemann char FunctionCaller::ID;
33*52f3a2faSRaphael Isemann 
34151c032cSJim Ingham // FunctionCaller constructor
35b9c1b51eSKate Stone FunctionCaller::FunctionCaller(ExecutionContextScope &exe_scope,
36151c032cSJim Ingham                                const CompilerType &return_type,
37151c032cSJim Ingham                                const Address &functionAddress,
38151c032cSJim Ingham                                const ValueList &arg_value_list,
39b9c1b51eSKate Stone                                const char *name)
40*52f3a2faSRaphael Isemann     : Expression(exe_scope), m_execution_unit_sp(), m_parser(),
41*52f3a2faSRaphael Isemann       m_jit_module_wp(), m_name(name ? name : "<unknown>"),
42248a1305SKonrad Kleine       m_function_ptr(nullptr), m_function_addr(functionAddress),
43151c032cSJim Ingham       m_function_return_type(return_type),
44151c032cSJim Ingham       m_wrapper_function_name("__lldb_caller_function"),
45b9c1b51eSKate Stone       m_wrapper_struct_name("__lldb_caller_struct"), m_wrapper_args_addrs(),
46a6922415SJason Molenda       m_struct_valid(false), m_arg_values(arg_value_list), m_compiled(false),
47a6922415SJason Molenda       m_JITted(false) {
48151c032cSJim Ingham   m_jit_process_wp = lldb::ProcessWP(exe_scope.CalculateProcess());
49151c032cSJim Ingham   // Can't make a FunctionCaller without a process.
50151c032cSJim Ingham   assert(m_jit_process_wp.lock());
51151c032cSJim Ingham }
52151c032cSJim Ingham 
53151c032cSJim Ingham // Destructor
54b9c1b51eSKate Stone FunctionCaller::~FunctionCaller() {
55151c032cSJim Ingham   lldb::ProcessSP process_sp(m_jit_process_wp.lock());
56b9c1b51eSKate Stone   if (process_sp) {
57151c032cSJim Ingham     lldb::ModuleSP jit_module_sp(m_jit_module_wp.lock());
58151c032cSJim Ingham     if (jit_module_sp)
59151c032cSJim Ingham       process_sp->GetTarget().GetImages().Remove(jit_module_sp);
60151c032cSJim Ingham   }
61151c032cSJim Ingham }
62151c032cSJim Ingham 
63b9c1b51eSKate Stone bool FunctionCaller::WriteFunctionWrapper(
64b9c1b51eSKate Stone     ExecutionContext &exe_ctx, DiagnosticManager &diagnostic_manager) {
65151c032cSJim Ingham   Process *process = exe_ctx.GetProcessPtr();
66151c032cSJim Ingham 
67151c032cSJim Ingham   if (!process)
68151c032cSJim Ingham     return false;
69151c032cSJim Ingham 
70151c032cSJim Ingham   lldb::ProcessSP jit_process_sp(m_jit_process_wp.lock());
71151c032cSJim Ingham 
72151c032cSJim Ingham   if (process != jit_process_sp.get())
73151c032cSJim Ingham     return false;
74151c032cSJim Ingham 
75151c032cSJim Ingham   if (!m_compiled)
76151c032cSJim Ingham     return false;
77151c032cSJim Ingham 
78151c032cSJim Ingham   if (m_JITted)
79151c032cSJim Ingham     return true;
80151c032cSJim Ingham 
81151c032cSJim Ingham   bool can_interpret = false; // should stay that way
82151c032cSJim Ingham 
8397206d57SZachary Turner   Status jit_error(m_parser->PrepareForExecution(
84b9c1b51eSKate Stone       m_jit_start_addr, m_jit_end_addr, m_execution_unit_sp, exe_ctx,
85b9c1b51eSKate Stone       can_interpret, eExecutionPolicyAlways));
86151c032cSJim Ingham 
870d231f71SJim Ingham   if (!jit_error.Success()) {
880d231f71SJim Ingham     diagnostic_manager.Printf(eDiagnosticSeverityError,
890d231f71SJim Ingham                               "Error in PrepareForExecution: %s.",
900d231f71SJim Ingham                               jit_error.AsCString());
91151c032cSJim Ingham     return false;
920d231f71SJim Ingham   }
93151c032cSJim Ingham 
94b9c1b51eSKate Stone   if (m_parser->GetGenerateDebugInfo()) {
95151c032cSJim Ingham     lldb::ModuleSP jit_module_sp(m_execution_unit_sp->GetJITModule());
96151c032cSJim Ingham 
97b9c1b51eSKate Stone     if (jit_module_sp) {
98151c032cSJim Ingham       ConstString const_func_name(FunctionName());
99151c032cSJim Ingham       FileSpec jit_file;
100151c032cSJim Ingham       jit_file.GetFilename() = const_func_name;
101151c032cSJim Ingham       jit_module_sp->SetFileSpecAndObjectName(jit_file, ConstString());
102151c032cSJim Ingham       m_jit_module_wp = jit_module_sp;
1031724a179SJason Molenda       process->GetTarget().GetImages().Append(jit_module_sp,
1041724a179SJason Molenda                                               true /* notify */);
105151c032cSJim Ingham     }
106151c032cSJim Ingham   }
107151c032cSJim Ingham   if (process && m_jit_start_addr)
108151c032cSJim Ingham     m_jit_process_wp = process->shared_from_this();
109151c032cSJim Ingham 
110151c032cSJim Ingham   m_JITted = true;
111151c032cSJim Ingham 
112151c032cSJim Ingham   return true;
113151c032cSJim Ingham }
114151c032cSJim Ingham 
115b9c1b51eSKate Stone bool FunctionCaller::WriteFunctionArguments(
116b9c1b51eSKate Stone     ExecutionContext &exe_ctx, lldb::addr_t &args_addr_ref,
117b9c1b51eSKate Stone     DiagnosticManager &diagnostic_manager) {
118b9c1b51eSKate Stone   return WriteFunctionArguments(exe_ctx, args_addr_ref, m_arg_values,
119b9c1b51eSKate Stone                                 diagnostic_manager);
120151c032cSJim Ingham }
121151c032cSJim Ingham 
122b9c1b51eSKate Stone // FIXME: Assure that the ValueList we were passed in is consistent with the one
123b9c1b51eSKate Stone // that defined this function.
124151c032cSJim Ingham 
125b9c1b51eSKate Stone bool FunctionCaller::WriteFunctionArguments(
126b9c1b51eSKate Stone     ExecutionContext &exe_ctx, lldb::addr_t &args_addr_ref,
127b9c1b51eSKate Stone     ValueList &arg_values, DiagnosticManager &diagnostic_manager) {
128151c032cSJim Ingham   // All the information to reconstruct the struct is provided by the
129151c032cSJim Ingham   // StructExtractor.
130b9c1b51eSKate Stone   if (!m_struct_valid) {
131e2411fabSZachary Turner     diagnostic_manager.PutString(eDiagnosticSeverityError,
132b9c1b51eSKate Stone                                  "Argument information was not correctly "
133b9c1b51eSKate Stone                                  "parsed, so the function cannot be called.");
134151c032cSJim Ingham     return false;
135151c032cSJim Ingham   }
136151c032cSJim Ingham 
13797206d57SZachary Turner   Status error;
138151c032cSJim Ingham   lldb::ExpressionResults return_value = lldb::eExpressionSetupError;
139151c032cSJim Ingham 
140151c032cSJim Ingham   Process *process = exe_ctx.GetProcessPtr();
141151c032cSJim Ingham 
142248a1305SKonrad Kleine   if (process == nullptr)
143151c032cSJim Ingham     return return_value;
144151c032cSJim Ingham 
145151c032cSJim Ingham   lldb::ProcessSP jit_process_sp(m_jit_process_wp.lock());
146151c032cSJim Ingham 
147151c032cSJim Ingham   if (process != jit_process_sp.get())
148151c032cSJim Ingham     return false;
149151c032cSJim Ingham 
150b9c1b51eSKate Stone   if (args_addr_ref == LLDB_INVALID_ADDRESS) {
151b9c1b51eSKate Stone     args_addr_ref = process->AllocateMemory(
152b9c1b51eSKate Stone         m_struct_size, lldb::ePermissionsReadable | lldb::ePermissionsWritable,
153b9c1b51eSKate Stone         error);
154151c032cSJim Ingham     if (args_addr_ref == LLDB_INVALID_ADDRESS)
155151c032cSJim Ingham       return false;
156151c032cSJim Ingham     m_wrapper_args_addrs.push_back(args_addr_ref);
157b9c1b51eSKate Stone   } else {
158151c032cSJim Ingham     // Make sure this is an address that we've already handed out.
159b9c1b51eSKate Stone     if (find(m_wrapper_args_addrs.begin(), m_wrapper_args_addrs.end(),
160b9c1b51eSKate Stone              args_addr_ref) == m_wrapper_args_addrs.end()) {
161151c032cSJim Ingham       return false;
162151c032cSJim Ingham     }
163151c032cSJim Ingham   }
164151c032cSJim Ingham 
165151c032cSJim Ingham   // TODO: verify fun_addr needs to be a callable address
166b9c1b51eSKate Stone   Scalar fun_addr(
167b9c1b51eSKate Stone       m_function_addr.GetCallableLoadAddress(exe_ctx.GetTargetPtr()));
168151c032cSJim Ingham   uint64_t first_offset = m_member_offsets[0];
169b9c1b51eSKate Stone   process->WriteScalarToMemory(args_addr_ref + first_offset, fun_addr,
170b9c1b51eSKate Stone                                process->GetAddressByteSize(), error);
171151c032cSJim Ingham 
172151c032cSJim Ingham   // FIXME: We will need to extend this for Variadic functions.
173151c032cSJim Ingham 
17497206d57SZachary Turner   Status value_error;
175151c032cSJim Ingham 
176151c032cSJim Ingham   size_t num_args = arg_values.GetSize();
177b9c1b51eSKate Stone   if (num_args != m_arg_values.GetSize()) {
178b9c1b51eSKate Stone     diagnostic_manager.Printf(
179b9c1b51eSKate Stone         eDiagnosticSeverityError,
180579e70c9SSean Callanan         "Wrong number of arguments - was: %" PRIu64 " should be: %" PRIu64 "",
181579e70c9SSean Callanan         (uint64_t)num_args, (uint64_t)m_arg_values.GetSize());
182151c032cSJim Ingham     return false;
183151c032cSJim Ingham   }
184151c032cSJim Ingham 
185b9c1b51eSKate Stone   for (size_t i = 0; i < num_args; i++) {
186151c032cSJim Ingham     // FIXME: We should sanity check sizes.
187151c032cSJim Ingham 
188151c032cSJim Ingham     uint64_t offset = m_member_offsets[i + 1]; // Clang sizes are in bytes.
189151c032cSJim Ingham     Value *arg_value = arg_values.GetValueAtIndex(i);
190151c032cSJim Ingham 
191151c032cSJim Ingham     // FIXME: For now just do scalars:
192151c032cSJim Ingham 
193b9c1b51eSKate Stone     // Special case: if it's a pointer, don't do anything (the ABI supports
194b9c1b51eSKate Stone     // passing cstrings)
195151c032cSJim Ingham 
196151c032cSJim Ingham     if (arg_value->GetValueType() == Value::eValueTypeHostAddress &&
197151c032cSJim Ingham         arg_value->GetContextType() == Value::eContextTypeInvalid &&
198151c032cSJim Ingham         arg_value->GetCompilerType().IsPointerType())
199151c032cSJim Ingham       continue;
200151c032cSJim Ingham 
201151c032cSJim Ingham     const Scalar &arg_scalar = arg_value->ResolveValue(&exe_ctx);
202151c032cSJim Ingham 
203b9c1b51eSKate Stone     if (!process->WriteScalarToMemory(args_addr_ref + offset, arg_scalar,
204b9c1b51eSKate Stone                                       arg_scalar.GetByteSize(), error))
205151c032cSJim Ingham       return false;
206151c032cSJim Ingham   }
207151c032cSJim Ingham 
208151c032cSJim Ingham   return true;
209151c032cSJim Ingham }
210151c032cSJim Ingham 
211b9c1b51eSKate Stone bool FunctionCaller::InsertFunction(ExecutionContext &exe_ctx,
212b9c1b51eSKate Stone                                     lldb::addr_t &args_addr_ref,
213b9c1b51eSKate Stone                                     DiagnosticManager &diagnostic_manager) {
2146896b355SJim Ingham   if (CompileFunction(exe_ctx.GetThreadSP(), diagnostic_manager) != 0)
215151c032cSJim Ingham     return false;
216579e70c9SSean Callanan   if (!WriteFunctionWrapper(exe_ctx, diagnostic_manager))
217151c032cSJim Ingham     return false;
218579e70c9SSean Callanan   if (!WriteFunctionArguments(exe_ctx, args_addr_ref, diagnostic_manager))
219151c032cSJim Ingham     return false;
220151c032cSJim Ingham 
221151c032cSJim Ingham   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
22263e5fb76SJonas Devlieghere   LLDB_LOGF(log, "Call Address: 0x%" PRIx64 " Struct Address: 0x%" PRIx64 ".\n",
223b9c1b51eSKate Stone             m_jit_start_addr, args_addr_ref);
224151c032cSJim Ingham 
225151c032cSJim Ingham   return true;
226151c032cSJim Ingham }
227151c032cSJim Ingham 
228b9c1b51eSKate Stone lldb::ThreadPlanSP FunctionCaller::GetThreadPlanToCallFunction(
229b9c1b51eSKate Stone     ExecutionContext &exe_ctx, lldb::addr_t args_addr,
230151c032cSJim Ingham     const EvaluateExpressionOptions &options,
231b9c1b51eSKate Stone     DiagnosticManager &diagnostic_manager) {
232b9c1b51eSKate Stone   Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_EXPRESSIONS |
233b9c1b51eSKate Stone                                                   LIBLLDB_LOG_STEP));
234151c032cSJim Ingham 
23563e5fb76SJonas Devlieghere   LLDB_LOGF(log,
23663e5fb76SJonas Devlieghere             "-- [FunctionCaller::GetThreadPlanToCallFunction] Creating "
237b9c1b51eSKate Stone             "thread plan to call function \"%s\" --",
238b9c1b51eSKate Stone             m_name.c_str());
239151c032cSJim Ingham 
240151c032cSJim Ingham   // FIXME: Use the errors Stream for better error reporting.
241151c032cSJim Ingham   Thread *thread = exe_ctx.GetThreadPtr();
242248a1305SKonrad Kleine   if (thread == nullptr) {
243e2411fabSZachary Turner     diagnostic_manager.PutString(
244b9c1b51eSKate Stone         eDiagnosticSeverityError,
245b9c1b51eSKate Stone         "Can't call a function without a valid thread.");
246248a1305SKonrad Kleine     return nullptr;
247151c032cSJim Ingham   }
248151c032cSJim Ingham 
249151c032cSJim Ingham   // Okay, now run the function:
250151c032cSJim Ingham 
251151c032cSJim Ingham   Address wrapper_address(m_jit_start_addr);
252151c032cSJim Ingham 
253151c032cSJim Ingham   lldb::addr_t args = {args_addr};
254151c032cSJim Ingham 
255b9c1b51eSKate Stone   lldb::ThreadPlanSP new_plan_sp(new ThreadPlanCallFunction(
256b9c1b51eSKate Stone       *thread, wrapper_address, CompilerType(), args, options));
257151c032cSJim Ingham   new_plan_sp->SetIsMasterPlan(true);
258151c032cSJim Ingham   new_plan_sp->SetOkayToDiscard(false);
259151c032cSJim Ingham   return new_plan_sp;
260151c032cSJim Ingham }
261151c032cSJim Ingham 
262b9c1b51eSKate Stone bool FunctionCaller::FetchFunctionResults(ExecutionContext &exe_ctx,
263b9c1b51eSKate Stone                                           lldb::addr_t args_addr,
264b9c1b51eSKate Stone                                           Value &ret_value) {
265151c032cSJim Ingham   // Read the return value - it is the last field in the struct:
266b9c1b51eSKate Stone   // FIXME: How does clang tell us there's no return value?  We need to handle
267b9c1b51eSKate Stone   // that case.
268b9c1b51eSKate Stone   // FIXME: Create our ThreadPlanCallFunction with the return CompilerType, and
269b9c1b51eSKate Stone   // then use GetReturnValueObject
270151c032cSJim Ingham   // to fetch the value.  That way we can fetch any values we need.
271151c032cSJim Ingham 
272b9c1b51eSKate Stone   Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_EXPRESSIONS |
273b9c1b51eSKate Stone                                                   LIBLLDB_LOG_STEP));
274151c032cSJim Ingham 
27563e5fb76SJonas Devlieghere   LLDB_LOGF(log,
27663e5fb76SJonas Devlieghere             "-- [FunctionCaller::FetchFunctionResults] Fetching function "
277b9c1b51eSKate Stone             "results for \"%s\"--",
278b9c1b51eSKate Stone             m_name.c_str());
279151c032cSJim Ingham 
280151c032cSJim Ingham   Process *process = exe_ctx.GetProcessPtr();
281151c032cSJim Ingham 
282248a1305SKonrad Kleine   if (process == nullptr)
283151c032cSJim Ingham     return false;
284151c032cSJim Ingham 
285151c032cSJim Ingham   lldb::ProcessSP jit_process_sp(m_jit_process_wp.lock());
286151c032cSJim Ingham 
287151c032cSJim Ingham   if (process != jit_process_sp.get())
288151c032cSJim Ingham     return false;
289151c032cSJim Ingham 
29097206d57SZachary Turner   Status error;
291b9c1b51eSKate Stone   ret_value.GetScalar() = process->ReadUnsignedIntegerFromMemory(
292b9c1b51eSKate Stone       args_addr + m_return_offset, m_return_size, 0, error);
293151c032cSJim Ingham 
294151c032cSJim Ingham   if (error.Fail())
295151c032cSJim Ingham     return false;
296151c032cSJim Ingham 
297151c032cSJim Ingham   ret_value.SetCompilerType(m_function_return_type);
298151c032cSJim Ingham   ret_value.SetValueType(Value::eValueTypeScalar);
299151c032cSJim Ingham   return true;
300151c032cSJim Ingham }
301151c032cSJim Ingham 
302b9c1b51eSKate Stone void FunctionCaller::DeallocateFunctionResults(ExecutionContext &exe_ctx,
303b9c1b51eSKate Stone                                                lldb::addr_t args_addr) {
304151c032cSJim Ingham   std::list<lldb::addr_t>::iterator pos;
305b9c1b51eSKate Stone   pos = std::find(m_wrapper_args_addrs.begin(), m_wrapper_args_addrs.end(),
306b9c1b51eSKate Stone                   args_addr);
307151c032cSJim Ingham   if (pos != m_wrapper_args_addrs.end())
308151c032cSJim Ingham     m_wrapper_args_addrs.erase(pos);
309151c032cSJim Ingham 
310151c032cSJim Ingham   exe_ctx.GetProcessRef().DeallocateMemory(args_addr);
311151c032cSJim Ingham }
312151c032cSJim Ingham 
313b9c1b51eSKate Stone lldb::ExpressionResults FunctionCaller::ExecuteFunction(
314b9c1b51eSKate Stone     ExecutionContext &exe_ctx, lldb::addr_t *args_addr_ptr,
315b9c1b51eSKate Stone     const EvaluateExpressionOptions &options,
316b9c1b51eSKate Stone     DiagnosticManager &diagnostic_manager, Value &results) {
317151c032cSJim Ingham   lldb::ExpressionResults return_value = lldb::eExpressionSetupError;
318151c032cSJim Ingham 
31905097246SAdrian Prantl   // FunctionCaller::ExecuteFunction execution is always just to get the
32005097246SAdrian Prantl   // result. Do make sure we ignore breakpoints, unwind on error, and don't try
32105097246SAdrian Prantl   // to debug it.
322151c032cSJim Ingham   EvaluateExpressionOptions real_options = options;
323151c032cSJim Ingham   real_options.SetDebug(false);
324151c032cSJim Ingham   real_options.SetUnwindOnError(true);
325151c032cSJim Ingham   real_options.SetIgnoreBreakpoints(true);
326151c032cSJim Ingham 
327151c032cSJim Ingham   lldb::addr_t args_addr;
328151c032cSJim Ingham 
329248a1305SKonrad Kleine   if (args_addr_ptr != nullptr)
330151c032cSJim Ingham     args_addr = *args_addr_ptr;
331151c032cSJim Ingham   else
332151c032cSJim Ingham     args_addr = LLDB_INVALID_ADDRESS;
333151c032cSJim Ingham 
3346896b355SJim Ingham   if (CompileFunction(exe_ctx.GetThreadSP(), diagnostic_manager) != 0)
335151c032cSJim Ingham     return lldb::eExpressionSetupError;
336151c032cSJim Ingham 
337b9c1b51eSKate Stone   if (args_addr == LLDB_INVALID_ADDRESS) {
338579e70c9SSean Callanan     if (!InsertFunction(exe_ctx, args_addr, diagnostic_manager))
339151c032cSJim Ingham       return lldb::eExpressionSetupError;
340151c032cSJim Ingham   }
341151c032cSJim Ingham 
342b9c1b51eSKate Stone   Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_EXPRESSIONS |
343b9c1b51eSKate Stone                                                   LIBLLDB_LOG_STEP));
344151c032cSJim Ingham 
34563e5fb76SJonas Devlieghere   LLDB_LOGF(log,
346b9c1b51eSKate Stone             "== [FunctionCaller::ExecuteFunction] Executing function \"%s\" ==",
347b9c1b51eSKate Stone             m_name.c_str());
348151c032cSJim Ingham 
349b9c1b51eSKate Stone   lldb::ThreadPlanSP call_plan_sp = GetThreadPlanToCallFunction(
350b9c1b51eSKate Stone       exe_ctx, args_addr, real_options, diagnostic_manager);
351151c032cSJim Ingham   if (!call_plan_sp)
352151c032cSJim Ingham     return lldb::eExpressionSetupError;
353151c032cSJim Ingham 
354b9c1b51eSKate Stone   // We need to make sure we record the fact that we are running an expression
35505097246SAdrian Prantl   // here otherwise this fact will fail to be recorded when fetching an
35605097246SAdrian Prantl   // Objective-C object description
357151c032cSJim Ingham   if (exe_ctx.GetProcessPtr())
358151c032cSJim Ingham     exe_ctx.GetProcessPtr()->SetRunningUserExpression(true);
359151c032cSJim Ingham 
360b9c1b51eSKate Stone   return_value = exe_ctx.GetProcessRef().RunThreadPlan(
361b9c1b51eSKate Stone       exe_ctx, call_plan_sp, real_options, diagnostic_manager);
362151c032cSJim Ingham 
363b9c1b51eSKate Stone   if (log) {
364b9c1b51eSKate Stone     if (return_value != lldb::eExpressionCompleted) {
36563e5fb76SJonas Devlieghere       LLDB_LOGF(log,
36663e5fb76SJonas Devlieghere                 "== [FunctionCaller::ExecuteFunction] Execution of \"%s\" "
367b9c1b51eSKate Stone                 "completed abnormally ==",
368b9c1b51eSKate Stone                 m_name.c_str());
369b9c1b51eSKate Stone     } else {
37063e5fb76SJonas Devlieghere       LLDB_LOGF(log,
37163e5fb76SJonas Devlieghere                 "== [FunctionCaller::ExecuteFunction] Execution of \"%s\" "
372b9c1b51eSKate Stone                 "completed normally ==",
373b9c1b51eSKate Stone                 m_name.c_str());
374151c032cSJim Ingham     }
375151c032cSJim Ingham   }
376151c032cSJim Ingham 
377151c032cSJim Ingham   if (exe_ctx.GetProcessPtr())
378151c032cSJim Ingham     exe_ctx.GetProcessPtr()->SetRunningUserExpression(false);
379151c032cSJim Ingham 
380248a1305SKonrad Kleine   if (args_addr_ptr != nullptr)
381151c032cSJim Ingham     *args_addr_ptr = args_addr;
382151c032cSJim Ingham 
383151c032cSJim Ingham   if (return_value != lldb::eExpressionCompleted)
384151c032cSJim Ingham     return return_value;
385151c032cSJim Ingham 
386151c032cSJim Ingham   FetchFunctionResults(exe_ctx, args_addr, results);
387151c032cSJim Ingham 
388248a1305SKonrad Kleine   if (args_addr_ptr == nullptr)
389151c032cSJim Ingham     DeallocateFunctionResults(exe_ctx, args_addr);
390151c032cSJim Ingham 
391151c032cSJim Ingham   return lldb::eExpressionCompleted;
392151c032cSJim Ingham }
393