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 
32151c032cSJim Ingham // FunctionCaller constructor
33b9c1b51eSKate Stone FunctionCaller::FunctionCaller(ExecutionContextScope &exe_scope,
34151c032cSJim Ingham                                const CompilerType &return_type,
35151c032cSJim Ingham                                const Address &functionAddress,
36151c032cSJim Ingham                                const ValueList &arg_value_list,
37b9c1b51eSKate Stone                                const char *name)
38248a1305SKonrad Kleine     : Expression(exe_scope, eKindFunctionCaller), m_execution_unit_sp(),
39248a1305SKonrad Kleine       m_parser(), m_jit_module_wp(), m_name(name ? name : "<unknown>"),
40248a1305SKonrad Kleine       m_function_ptr(nullptr), m_function_addr(functionAddress),
41151c032cSJim Ingham       m_function_return_type(return_type),
42151c032cSJim Ingham       m_wrapper_function_name("__lldb_caller_function"),
43b9c1b51eSKate Stone       m_wrapper_struct_name("__lldb_caller_struct"), m_wrapper_args_addrs(),
44a6922415SJason Molenda       m_struct_valid(false), m_arg_values(arg_value_list), m_compiled(false),
45a6922415SJason Molenda       m_JITted(false) {
46151c032cSJim Ingham   m_jit_process_wp = lldb::ProcessWP(exe_scope.CalculateProcess());
47151c032cSJim Ingham   // Can't make a FunctionCaller without a process.
48151c032cSJim Ingham   assert(m_jit_process_wp.lock());
49151c032cSJim Ingham }
50151c032cSJim Ingham 
51151c032cSJim Ingham // Destructor
52b9c1b51eSKate Stone FunctionCaller::~FunctionCaller() {
53151c032cSJim Ingham   lldb::ProcessSP process_sp(m_jit_process_wp.lock());
54b9c1b51eSKate Stone   if (process_sp) {
55151c032cSJim Ingham     lldb::ModuleSP jit_module_sp(m_jit_module_wp.lock());
56151c032cSJim Ingham     if (jit_module_sp)
57151c032cSJim Ingham       process_sp->GetTarget().GetImages().Remove(jit_module_sp);
58151c032cSJim Ingham   }
59151c032cSJim Ingham }
60151c032cSJim Ingham 
61b9c1b51eSKate Stone bool FunctionCaller::WriteFunctionWrapper(
62b9c1b51eSKate Stone     ExecutionContext &exe_ctx, DiagnosticManager &diagnostic_manager) {
63151c032cSJim Ingham   Process *process = exe_ctx.GetProcessPtr();
64151c032cSJim Ingham 
65151c032cSJim Ingham   if (!process)
66151c032cSJim Ingham     return false;
67151c032cSJim Ingham 
68151c032cSJim Ingham   lldb::ProcessSP jit_process_sp(m_jit_process_wp.lock());
69151c032cSJim Ingham 
70151c032cSJim Ingham   if (process != jit_process_sp.get())
71151c032cSJim Ingham     return false;
72151c032cSJim Ingham 
73151c032cSJim Ingham   if (!m_compiled)
74151c032cSJim Ingham     return false;
75151c032cSJim Ingham 
76151c032cSJim Ingham   if (m_JITted)
77151c032cSJim Ingham     return true;
78151c032cSJim Ingham 
79151c032cSJim Ingham   bool can_interpret = false; // should stay that way
80151c032cSJim Ingham 
8197206d57SZachary Turner   Status jit_error(m_parser->PrepareForExecution(
82b9c1b51eSKate Stone       m_jit_start_addr, m_jit_end_addr, m_execution_unit_sp, exe_ctx,
83b9c1b51eSKate Stone       can_interpret, eExecutionPolicyAlways));
84151c032cSJim Ingham 
850d231f71SJim Ingham   if (!jit_error.Success()) {
860d231f71SJim Ingham     diagnostic_manager.Printf(eDiagnosticSeverityError,
870d231f71SJim Ingham                               "Error in PrepareForExecution: %s.",
880d231f71SJim Ingham                               jit_error.AsCString());
89151c032cSJim Ingham     return false;
900d231f71SJim Ingham   }
91151c032cSJim Ingham 
92b9c1b51eSKate Stone   if (m_parser->GetGenerateDebugInfo()) {
93151c032cSJim Ingham     lldb::ModuleSP jit_module_sp(m_execution_unit_sp->GetJITModule());
94151c032cSJim Ingham 
95b9c1b51eSKate Stone     if (jit_module_sp) {
96151c032cSJim Ingham       ConstString const_func_name(FunctionName());
97151c032cSJim Ingham       FileSpec jit_file;
98151c032cSJim Ingham       jit_file.GetFilename() = const_func_name;
99151c032cSJim Ingham       jit_module_sp->SetFileSpecAndObjectName(jit_file, ConstString());
100151c032cSJim Ingham       m_jit_module_wp = jit_module_sp;
1011724a179SJason Molenda       process->GetTarget().GetImages().Append(jit_module_sp,
1021724a179SJason Molenda                                               true /* notify */);
103151c032cSJim Ingham     }
104151c032cSJim Ingham   }
105151c032cSJim Ingham   if (process && m_jit_start_addr)
106151c032cSJim Ingham     m_jit_process_wp = process->shared_from_this();
107151c032cSJim Ingham 
108151c032cSJim Ingham   m_JITted = true;
109151c032cSJim Ingham 
110151c032cSJim Ingham   return true;
111151c032cSJim Ingham }
112151c032cSJim Ingham 
113b9c1b51eSKate Stone bool FunctionCaller::WriteFunctionArguments(
114b9c1b51eSKate Stone     ExecutionContext &exe_ctx, lldb::addr_t &args_addr_ref,
115b9c1b51eSKate Stone     DiagnosticManager &diagnostic_manager) {
116b9c1b51eSKate Stone   return WriteFunctionArguments(exe_ctx, args_addr_ref, m_arg_values,
117b9c1b51eSKate Stone                                 diagnostic_manager);
118151c032cSJim Ingham }
119151c032cSJim Ingham 
120b9c1b51eSKate Stone // FIXME: Assure that the ValueList we were passed in is consistent with the one
121b9c1b51eSKate Stone // that defined this function.
122151c032cSJim Ingham 
123b9c1b51eSKate Stone bool FunctionCaller::WriteFunctionArguments(
124b9c1b51eSKate Stone     ExecutionContext &exe_ctx, lldb::addr_t &args_addr_ref,
125b9c1b51eSKate Stone     ValueList &arg_values, DiagnosticManager &diagnostic_manager) {
126151c032cSJim Ingham   // All the information to reconstruct the struct is provided by the
127151c032cSJim Ingham   // StructExtractor.
128b9c1b51eSKate Stone   if (!m_struct_valid) {
129e2411fabSZachary Turner     diagnostic_manager.PutString(eDiagnosticSeverityError,
130b9c1b51eSKate Stone                                  "Argument information was not correctly "
131b9c1b51eSKate Stone                                  "parsed, so the function cannot be called.");
132151c032cSJim Ingham     return false;
133151c032cSJim Ingham   }
134151c032cSJim Ingham 
13597206d57SZachary Turner   Status error;
136151c032cSJim Ingham   lldb::ExpressionResults return_value = lldb::eExpressionSetupError;
137151c032cSJim Ingham 
138151c032cSJim Ingham   Process *process = exe_ctx.GetProcessPtr();
139151c032cSJim Ingham 
140248a1305SKonrad Kleine   if (process == nullptr)
141151c032cSJim Ingham     return return_value;
142151c032cSJim Ingham 
143151c032cSJim Ingham   lldb::ProcessSP jit_process_sp(m_jit_process_wp.lock());
144151c032cSJim Ingham 
145151c032cSJim Ingham   if (process != jit_process_sp.get())
146151c032cSJim Ingham     return false;
147151c032cSJim Ingham 
148b9c1b51eSKate Stone   if (args_addr_ref == LLDB_INVALID_ADDRESS) {
149b9c1b51eSKate Stone     args_addr_ref = process->AllocateMemory(
150b9c1b51eSKate Stone         m_struct_size, lldb::ePermissionsReadable | lldb::ePermissionsWritable,
151b9c1b51eSKate Stone         error);
152151c032cSJim Ingham     if (args_addr_ref == LLDB_INVALID_ADDRESS)
153151c032cSJim Ingham       return false;
154151c032cSJim Ingham     m_wrapper_args_addrs.push_back(args_addr_ref);
155b9c1b51eSKate Stone   } else {
156151c032cSJim Ingham     // Make sure this is an address that we've already handed out.
157b9c1b51eSKate Stone     if (find(m_wrapper_args_addrs.begin(), m_wrapper_args_addrs.end(),
158b9c1b51eSKate Stone              args_addr_ref) == m_wrapper_args_addrs.end()) {
159151c032cSJim Ingham       return false;
160151c032cSJim Ingham     }
161151c032cSJim Ingham   }
162151c032cSJim Ingham 
163151c032cSJim Ingham   // TODO: verify fun_addr needs to be a callable address
164b9c1b51eSKate Stone   Scalar fun_addr(
165b9c1b51eSKate Stone       m_function_addr.GetCallableLoadAddress(exe_ctx.GetTargetPtr()));
166151c032cSJim Ingham   uint64_t first_offset = m_member_offsets[0];
167b9c1b51eSKate Stone   process->WriteScalarToMemory(args_addr_ref + first_offset, fun_addr,
168b9c1b51eSKate Stone                                process->GetAddressByteSize(), error);
169151c032cSJim Ingham 
170151c032cSJim Ingham   // FIXME: We will need to extend this for Variadic functions.
171151c032cSJim Ingham 
17297206d57SZachary Turner   Status value_error;
173151c032cSJim Ingham 
174151c032cSJim Ingham   size_t num_args = arg_values.GetSize();
175b9c1b51eSKate Stone   if (num_args != m_arg_values.GetSize()) {
176b9c1b51eSKate Stone     diagnostic_manager.Printf(
177b9c1b51eSKate Stone         eDiagnosticSeverityError,
178579e70c9SSean Callanan         "Wrong number of arguments - was: %" PRIu64 " should be: %" PRIu64 "",
179579e70c9SSean Callanan         (uint64_t)num_args, (uint64_t)m_arg_values.GetSize());
180151c032cSJim Ingham     return false;
181151c032cSJim Ingham   }
182151c032cSJim Ingham 
183b9c1b51eSKate Stone   for (size_t i = 0; i < num_args; i++) {
184151c032cSJim Ingham     // FIXME: We should sanity check sizes.
185151c032cSJim Ingham 
186151c032cSJim Ingham     uint64_t offset = m_member_offsets[i + 1]; // Clang sizes are in bytes.
187151c032cSJim Ingham     Value *arg_value = arg_values.GetValueAtIndex(i);
188151c032cSJim Ingham 
189151c032cSJim Ingham     // FIXME: For now just do scalars:
190151c032cSJim Ingham 
191b9c1b51eSKate Stone     // Special case: if it's a pointer, don't do anything (the ABI supports
192b9c1b51eSKate Stone     // passing cstrings)
193151c032cSJim Ingham 
194151c032cSJim Ingham     if (arg_value->GetValueType() == Value::eValueTypeHostAddress &&
195151c032cSJim Ingham         arg_value->GetContextType() == Value::eContextTypeInvalid &&
196151c032cSJim Ingham         arg_value->GetCompilerType().IsPointerType())
197151c032cSJim Ingham       continue;
198151c032cSJim Ingham 
199151c032cSJim Ingham     const Scalar &arg_scalar = arg_value->ResolveValue(&exe_ctx);
200151c032cSJim Ingham 
201b9c1b51eSKate Stone     if (!process->WriteScalarToMemory(args_addr_ref + offset, arg_scalar,
202b9c1b51eSKate Stone                                       arg_scalar.GetByteSize(), error))
203151c032cSJim Ingham       return false;
204151c032cSJim Ingham   }
205151c032cSJim Ingham 
206151c032cSJim Ingham   return true;
207151c032cSJim Ingham }
208151c032cSJim Ingham 
209b9c1b51eSKate Stone bool FunctionCaller::InsertFunction(ExecutionContext &exe_ctx,
210b9c1b51eSKate Stone                                     lldb::addr_t &args_addr_ref,
211b9c1b51eSKate Stone                                     DiagnosticManager &diagnostic_manager) {
2126896b355SJim Ingham   if (CompileFunction(exe_ctx.GetThreadSP(), diagnostic_manager) != 0)
213151c032cSJim Ingham     return false;
214579e70c9SSean Callanan   if (!WriteFunctionWrapper(exe_ctx, diagnostic_manager))
215151c032cSJim Ingham     return false;
216579e70c9SSean Callanan   if (!WriteFunctionArguments(exe_ctx, args_addr_ref, diagnostic_manager))
217151c032cSJim Ingham     return false;
218151c032cSJim Ingham 
219151c032cSJim Ingham   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
220*63e5fb76SJonas Devlieghere   LLDB_LOGF(log, "Call Address: 0x%" PRIx64 " Struct Address: 0x%" PRIx64 ".\n",
221b9c1b51eSKate Stone             m_jit_start_addr, args_addr_ref);
222151c032cSJim Ingham 
223151c032cSJim Ingham   return true;
224151c032cSJim Ingham }
225151c032cSJim Ingham 
226b9c1b51eSKate Stone lldb::ThreadPlanSP FunctionCaller::GetThreadPlanToCallFunction(
227b9c1b51eSKate Stone     ExecutionContext &exe_ctx, lldb::addr_t args_addr,
228151c032cSJim Ingham     const EvaluateExpressionOptions &options,
229b9c1b51eSKate Stone     DiagnosticManager &diagnostic_manager) {
230b9c1b51eSKate Stone   Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_EXPRESSIONS |
231b9c1b51eSKate Stone                                                   LIBLLDB_LOG_STEP));
232151c032cSJim Ingham 
233*63e5fb76SJonas Devlieghere   LLDB_LOGF(log,
234*63e5fb76SJonas Devlieghere             "-- [FunctionCaller::GetThreadPlanToCallFunction] Creating "
235b9c1b51eSKate Stone             "thread plan to call function \"%s\" --",
236b9c1b51eSKate Stone             m_name.c_str());
237151c032cSJim Ingham 
238151c032cSJim Ingham   // FIXME: Use the errors Stream for better error reporting.
239151c032cSJim Ingham   Thread *thread = exe_ctx.GetThreadPtr();
240248a1305SKonrad Kleine   if (thread == nullptr) {
241e2411fabSZachary Turner     diagnostic_manager.PutString(
242b9c1b51eSKate Stone         eDiagnosticSeverityError,
243b9c1b51eSKate Stone         "Can't call a function without a valid thread.");
244248a1305SKonrad Kleine     return nullptr;
245151c032cSJim Ingham   }
246151c032cSJim Ingham 
247151c032cSJim Ingham   // Okay, now run the function:
248151c032cSJim Ingham 
249151c032cSJim Ingham   Address wrapper_address(m_jit_start_addr);
250151c032cSJim Ingham 
251151c032cSJim Ingham   lldb::addr_t args = {args_addr};
252151c032cSJim Ingham 
253b9c1b51eSKate Stone   lldb::ThreadPlanSP new_plan_sp(new ThreadPlanCallFunction(
254b9c1b51eSKate Stone       *thread, wrapper_address, CompilerType(), args, options));
255151c032cSJim Ingham   new_plan_sp->SetIsMasterPlan(true);
256151c032cSJim Ingham   new_plan_sp->SetOkayToDiscard(false);
257151c032cSJim Ingham   return new_plan_sp;
258151c032cSJim Ingham }
259151c032cSJim Ingham 
260b9c1b51eSKate Stone bool FunctionCaller::FetchFunctionResults(ExecutionContext &exe_ctx,
261b9c1b51eSKate Stone                                           lldb::addr_t args_addr,
262b9c1b51eSKate Stone                                           Value &ret_value) {
263151c032cSJim Ingham   // Read the return value - it is the last field in the struct:
264b9c1b51eSKate Stone   // FIXME: How does clang tell us there's no return value?  We need to handle
265b9c1b51eSKate Stone   // that case.
266b9c1b51eSKate Stone   // FIXME: Create our ThreadPlanCallFunction with the return CompilerType, and
267b9c1b51eSKate Stone   // then use GetReturnValueObject
268151c032cSJim Ingham   // to fetch the value.  That way we can fetch any values we need.
269151c032cSJim Ingham 
270b9c1b51eSKate Stone   Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_EXPRESSIONS |
271b9c1b51eSKate Stone                                                   LIBLLDB_LOG_STEP));
272151c032cSJim Ingham 
273*63e5fb76SJonas Devlieghere   LLDB_LOGF(log,
274*63e5fb76SJonas Devlieghere             "-- [FunctionCaller::FetchFunctionResults] Fetching function "
275b9c1b51eSKate Stone             "results for \"%s\"--",
276b9c1b51eSKate Stone             m_name.c_str());
277151c032cSJim Ingham 
278151c032cSJim Ingham   Process *process = exe_ctx.GetProcessPtr();
279151c032cSJim Ingham 
280248a1305SKonrad Kleine   if (process == nullptr)
281151c032cSJim Ingham     return false;
282151c032cSJim Ingham 
283151c032cSJim Ingham   lldb::ProcessSP jit_process_sp(m_jit_process_wp.lock());
284151c032cSJim Ingham 
285151c032cSJim Ingham   if (process != jit_process_sp.get())
286151c032cSJim Ingham     return false;
287151c032cSJim Ingham 
28897206d57SZachary Turner   Status error;
289b9c1b51eSKate Stone   ret_value.GetScalar() = process->ReadUnsignedIntegerFromMemory(
290b9c1b51eSKate Stone       args_addr + m_return_offset, m_return_size, 0, error);
291151c032cSJim Ingham 
292151c032cSJim Ingham   if (error.Fail())
293151c032cSJim Ingham     return false;
294151c032cSJim Ingham 
295151c032cSJim Ingham   ret_value.SetCompilerType(m_function_return_type);
296151c032cSJim Ingham   ret_value.SetValueType(Value::eValueTypeScalar);
297151c032cSJim Ingham   return true;
298151c032cSJim Ingham }
299151c032cSJim Ingham 
300b9c1b51eSKate Stone void FunctionCaller::DeallocateFunctionResults(ExecutionContext &exe_ctx,
301b9c1b51eSKate Stone                                                lldb::addr_t args_addr) {
302151c032cSJim Ingham   std::list<lldb::addr_t>::iterator pos;
303b9c1b51eSKate Stone   pos = std::find(m_wrapper_args_addrs.begin(), m_wrapper_args_addrs.end(),
304b9c1b51eSKate Stone                   args_addr);
305151c032cSJim Ingham   if (pos != m_wrapper_args_addrs.end())
306151c032cSJim Ingham     m_wrapper_args_addrs.erase(pos);
307151c032cSJim Ingham 
308151c032cSJim Ingham   exe_ctx.GetProcessRef().DeallocateMemory(args_addr);
309151c032cSJim Ingham }
310151c032cSJim Ingham 
311b9c1b51eSKate Stone lldb::ExpressionResults FunctionCaller::ExecuteFunction(
312b9c1b51eSKate Stone     ExecutionContext &exe_ctx, lldb::addr_t *args_addr_ptr,
313b9c1b51eSKate Stone     const EvaluateExpressionOptions &options,
314b9c1b51eSKate Stone     DiagnosticManager &diagnostic_manager, Value &results) {
315151c032cSJim Ingham   lldb::ExpressionResults return_value = lldb::eExpressionSetupError;
316151c032cSJim Ingham 
31705097246SAdrian Prantl   // FunctionCaller::ExecuteFunction execution is always just to get the
31805097246SAdrian Prantl   // result. Do make sure we ignore breakpoints, unwind on error, and don't try
31905097246SAdrian Prantl   // to debug it.
320151c032cSJim Ingham   EvaluateExpressionOptions real_options = options;
321151c032cSJim Ingham   real_options.SetDebug(false);
322151c032cSJim Ingham   real_options.SetUnwindOnError(true);
323151c032cSJim Ingham   real_options.SetIgnoreBreakpoints(true);
324151c032cSJim Ingham 
325151c032cSJim Ingham   lldb::addr_t args_addr;
326151c032cSJim Ingham 
327248a1305SKonrad Kleine   if (args_addr_ptr != nullptr)
328151c032cSJim Ingham     args_addr = *args_addr_ptr;
329151c032cSJim Ingham   else
330151c032cSJim Ingham     args_addr = LLDB_INVALID_ADDRESS;
331151c032cSJim Ingham 
3326896b355SJim Ingham   if (CompileFunction(exe_ctx.GetThreadSP(), diagnostic_manager) != 0)
333151c032cSJim Ingham     return lldb::eExpressionSetupError;
334151c032cSJim Ingham 
335b9c1b51eSKate Stone   if (args_addr == LLDB_INVALID_ADDRESS) {
336579e70c9SSean Callanan     if (!InsertFunction(exe_ctx, args_addr, diagnostic_manager))
337151c032cSJim Ingham       return lldb::eExpressionSetupError;
338151c032cSJim Ingham   }
339151c032cSJim Ingham 
340b9c1b51eSKate Stone   Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_EXPRESSIONS |
341b9c1b51eSKate Stone                                                   LIBLLDB_LOG_STEP));
342151c032cSJim Ingham 
343*63e5fb76SJonas Devlieghere   LLDB_LOGF(log,
344b9c1b51eSKate Stone             "== [FunctionCaller::ExecuteFunction] Executing function \"%s\" ==",
345b9c1b51eSKate Stone             m_name.c_str());
346151c032cSJim Ingham 
347b9c1b51eSKate Stone   lldb::ThreadPlanSP call_plan_sp = GetThreadPlanToCallFunction(
348b9c1b51eSKate Stone       exe_ctx, args_addr, real_options, diagnostic_manager);
349151c032cSJim Ingham   if (!call_plan_sp)
350151c032cSJim Ingham     return lldb::eExpressionSetupError;
351151c032cSJim Ingham 
352b9c1b51eSKate Stone   // We need to make sure we record the fact that we are running an expression
35305097246SAdrian Prantl   // here otherwise this fact will fail to be recorded when fetching an
35405097246SAdrian Prantl   // Objective-C object description
355151c032cSJim Ingham   if (exe_ctx.GetProcessPtr())
356151c032cSJim Ingham     exe_ctx.GetProcessPtr()->SetRunningUserExpression(true);
357151c032cSJim Ingham 
358b9c1b51eSKate Stone   return_value = exe_ctx.GetProcessRef().RunThreadPlan(
359b9c1b51eSKate Stone       exe_ctx, call_plan_sp, real_options, diagnostic_manager);
360151c032cSJim Ingham 
361b9c1b51eSKate Stone   if (log) {
362b9c1b51eSKate Stone     if (return_value != lldb::eExpressionCompleted) {
363*63e5fb76SJonas Devlieghere       LLDB_LOGF(log,
364*63e5fb76SJonas Devlieghere                 "== [FunctionCaller::ExecuteFunction] Execution of \"%s\" "
365b9c1b51eSKate Stone                 "completed abnormally ==",
366b9c1b51eSKate Stone                 m_name.c_str());
367b9c1b51eSKate Stone     } else {
368*63e5fb76SJonas Devlieghere       LLDB_LOGF(log,
369*63e5fb76SJonas Devlieghere                 "== [FunctionCaller::ExecuteFunction] Execution of \"%s\" "
370b9c1b51eSKate Stone                 "completed normally ==",
371b9c1b51eSKate Stone                 m_name.c_str());
372151c032cSJim Ingham     }
373151c032cSJim Ingham   }
374151c032cSJim Ingham 
375151c032cSJim Ingham   if (exe_ctx.GetProcessPtr())
376151c032cSJim Ingham     exe_ctx.GetProcessPtr()->SetRunningUserExpression(false);
377151c032cSJim Ingham 
378248a1305SKonrad Kleine   if (args_addr_ptr != nullptr)
379151c032cSJim Ingham     *args_addr_ptr = args_addr;
380151c032cSJim Ingham 
381151c032cSJim Ingham   if (return_value != lldb::eExpressionCompleted)
382151c032cSJim Ingham     return return_value;
383151c032cSJim Ingham 
384151c032cSJim Ingham   FetchFunctionResults(exe_ctx, args_addr, results);
385151c032cSJim Ingham 
386248a1305SKonrad Kleine   if (args_addr_ptr == nullptr)
387151c032cSJim Ingham     DeallocateFunctionResults(exe_ctx, args_addr);
388151c032cSJim Ingham 
389151c032cSJim Ingham   return lldb::eExpressionCompleted;
390151c032cSJim Ingham }
391