1e2411fabSZachary Turner //===-- FunctionCaller.cpp ---------------------------------------*- C++-*-===//
2151c032cSJim Ingham //
3151c032cSJim Ingham //                     The LLVM Compiler Infrastructure
4151c032cSJim Ingham //
5151c032cSJim Ingham // This file is distributed under the University of Illinois Open Source
6151c032cSJim Ingham // License. See LICENSE.TXT for details.
7151c032cSJim Ingham //
8151c032cSJim Ingham //===----------------------------------------------------------------------===//
9151c032cSJim Ingham 
10151c032cSJim Ingham // C Includes
11151c032cSJim Ingham // C++ Includes
12151c032cSJim Ingham // Other libraries and framework includes
13151c032cSJim Ingham 
14151c032cSJim Ingham // Project includes
15579e70c9SSean Callanan #include "lldb/Expression/FunctionCaller.h"
16151c032cSJim Ingham #include "lldb/Core/Module.h"
17151c032cSJim Ingham #include "lldb/Core/State.h"
18151c032cSJim Ingham #include "lldb/Core/ValueObject.h"
19151c032cSJim Ingham #include "lldb/Core/ValueObjectList.h"
20579e70c9SSean Callanan #include "lldb/Expression/DiagnosticManager.h"
21151c032cSJim Ingham #include "lldb/Expression/IRExecutionUnit.h"
22151c032cSJim Ingham #include "lldb/Interpreter/CommandReturnObject.h"
23151c032cSJim Ingham #include "lldb/Symbol/Function.h"
24151c032cSJim Ingham #include "lldb/Symbol/Type.h"
25151c032cSJim Ingham #include "lldb/Target/ExecutionContext.h"
26151c032cSJim Ingham #include "lldb/Target/Process.h"
27151c032cSJim Ingham #include "lldb/Target/RegisterContext.h"
28151c032cSJim Ingham #include "lldb/Target/Target.h"
29151c032cSJim Ingham #include "lldb/Target/Thread.h"
30151c032cSJim Ingham #include "lldb/Target/ThreadPlan.h"
31151c032cSJim Ingham #include "lldb/Target/ThreadPlanCallFunction.h"
32666cc0b2SZachary Turner #include "lldb/Utility/DataExtractor.h"
336f9e6901SZachary Turner #include "lldb/Utility/Log.h"
34151c032cSJim Ingham 
35151c032cSJim Ingham using namespace lldb_private;
36151c032cSJim Ingham 
37151c032cSJim Ingham //----------------------------------------------------------------------
38151c032cSJim Ingham // FunctionCaller constructor
39151c032cSJim Ingham //----------------------------------------------------------------------
40b9c1b51eSKate Stone FunctionCaller::FunctionCaller(ExecutionContextScope &exe_scope,
41151c032cSJim Ingham                                const CompilerType &return_type,
42151c032cSJim Ingham                                const Address &functionAddress,
43151c032cSJim Ingham                                const ValueList &arg_value_list,
44b9c1b51eSKate Stone                                const char *name)
45b9c1b51eSKate Stone     : Expression(exe_scope), m_execution_unit_sp(), m_parser(),
46b9c1b51eSKate Stone       m_jit_module_wp(), m_name(name ? name : "<unknown>"),
47b9c1b51eSKate Stone       m_function_ptr(NULL), m_function_addr(functionAddress),
48151c032cSJim Ingham       m_function_return_type(return_type),
49151c032cSJim Ingham       m_wrapper_function_name("__lldb_caller_function"),
50b9c1b51eSKate Stone       m_wrapper_struct_name("__lldb_caller_struct"), m_wrapper_args_addrs(),
51a6922415SJason Molenda       m_struct_valid(false), m_arg_values(arg_value_list), m_compiled(false),
52a6922415SJason Molenda       m_JITted(false) {
53151c032cSJim Ingham   m_jit_process_wp = lldb::ProcessWP(exe_scope.CalculateProcess());
54151c032cSJim Ingham   // Can't make a FunctionCaller without a process.
55151c032cSJim Ingham   assert(m_jit_process_wp.lock());
56151c032cSJim Ingham }
57151c032cSJim Ingham 
58151c032cSJim Ingham //----------------------------------------------------------------------
59151c032cSJim Ingham // Destructor
60151c032cSJim Ingham //----------------------------------------------------------------------
61b9c1b51eSKate Stone FunctionCaller::~FunctionCaller() {
62151c032cSJim Ingham   lldb::ProcessSP process_sp(m_jit_process_wp.lock());
63b9c1b51eSKate Stone   if (process_sp) {
64151c032cSJim Ingham     lldb::ModuleSP jit_module_sp(m_jit_module_wp.lock());
65151c032cSJim Ingham     if (jit_module_sp)
66151c032cSJim Ingham       process_sp->GetTarget().GetImages().Remove(jit_module_sp);
67151c032cSJim Ingham   }
68151c032cSJim Ingham }
69151c032cSJim Ingham 
70b9c1b51eSKate Stone bool FunctionCaller::WriteFunctionWrapper(
71b9c1b51eSKate Stone     ExecutionContext &exe_ctx, DiagnosticManager &diagnostic_manager) {
72151c032cSJim Ingham   Process *process = exe_ctx.GetProcessPtr();
73151c032cSJim Ingham 
74151c032cSJim Ingham   if (!process)
75151c032cSJim Ingham     return false;
76151c032cSJim Ingham 
77151c032cSJim Ingham   lldb::ProcessSP jit_process_sp(m_jit_process_wp.lock());
78151c032cSJim Ingham 
79151c032cSJim Ingham   if (process != jit_process_sp.get())
80151c032cSJim Ingham     return false;
81151c032cSJim Ingham 
82151c032cSJim Ingham   if (!m_compiled)
83151c032cSJim Ingham     return false;
84151c032cSJim Ingham 
85151c032cSJim Ingham   if (m_JITted)
86151c032cSJim Ingham     return true;
87151c032cSJim Ingham 
88151c032cSJim Ingham   bool can_interpret = false; // should stay that way
89151c032cSJim Ingham 
9097206d57SZachary Turner   Status jit_error(m_parser->PrepareForExecution(
91b9c1b51eSKate Stone       m_jit_start_addr, m_jit_end_addr, m_execution_unit_sp, exe_ctx,
92b9c1b51eSKate Stone       can_interpret, eExecutionPolicyAlways));
93151c032cSJim Ingham 
94*0d231f71SJim Ingham   if (!jit_error.Success()) {
95*0d231f71SJim Ingham     diagnostic_manager.Printf(eDiagnosticSeverityError,
96*0d231f71SJim Ingham                               "Error in PrepareForExecution: %s.",
97*0d231f71SJim Ingham                               jit_error.AsCString());
98151c032cSJim Ingham     return false;
99*0d231f71SJim Ingham   }
100151c032cSJim Ingham 
101b9c1b51eSKate Stone   if (m_parser->GetGenerateDebugInfo()) {
102151c032cSJim Ingham     lldb::ModuleSP jit_module_sp(m_execution_unit_sp->GetJITModule());
103151c032cSJim Ingham 
104b9c1b51eSKate Stone     if (jit_module_sp) {
105151c032cSJim Ingham       ConstString const_func_name(FunctionName());
106151c032cSJim Ingham       FileSpec jit_file;
107151c032cSJim Ingham       jit_file.GetFilename() = const_func_name;
108151c032cSJim Ingham       jit_module_sp->SetFileSpecAndObjectName(jit_file, ConstString());
109151c032cSJim Ingham       m_jit_module_wp = jit_module_sp;
110151c032cSJim Ingham       process->GetTarget().GetImages().Append(jit_module_sp);
111151c032cSJim Ingham     }
112151c032cSJim Ingham   }
113151c032cSJim Ingham   if (process && m_jit_start_addr)
114151c032cSJim Ingham     m_jit_process_wp = process->shared_from_this();
115151c032cSJim Ingham 
116151c032cSJim Ingham   m_JITted = true;
117151c032cSJim Ingham 
118151c032cSJim Ingham   return true;
119151c032cSJim Ingham }
120151c032cSJim Ingham 
121b9c1b51eSKate Stone bool FunctionCaller::WriteFunctionArguments(
122b9c1b51eSKate Stone     ExecutionContext &exe_ctx, lldb::addr_t &args_addr_ref,
123b9c1b51eSKate Stone     DiagnosticManager &diagnostic_manager) {
124b9c1b51eSKate Stone   return WriteFunctionArguments(exe_ctx, args_addr_ref, m_arg_values,
125b9c1b51eSKate Stone                                 diagnostic_manager);
126151c032cSJim Ingham }
127151c032cSJim Ingham 
128b9c1b51eSKate Stone // FIXME: Assure that the ValueList we were passed in is consistent with the one
129b9c1b51eSKate Stone // that defined this function.
130151c032cSJim Ingham 
131b9c1b51eSKate Stone bool FunctionCaller::WriteFunctionArguments(
132b9c1b51eSKate Stone     ExecutionContext &exe_ctx, lldb::addr_t &args_addr_ref,
133b9c1b51eSKate Stone     ValueList &arg_values, DiagnosticManager &diagnostic_manager) {
134151c032cSJim Ingham   // All the information to reconstruct the struct is provided by the
135151c032cSJim Ingham   // StructExtractor.
136b9c1b51eSKate Stone   if (!m_struct_valid) {
137e2411fabSZachary Turner     diagnostic_manager.PutString(eDiagnosticSeverityError,
138b9c1b51eSKate Stone                                  "Argument information was not correctly "
139b9c1b51eSKate Stone                                  "parsed, so the function cannot be called.");
140151c032cSJim Ingham     return false;
141151c032cSJim Ingham   }
142151c032cSJim Ingham 
14397206d57SZachary Turner   Status error;
144151c032cSJim Ingham   lldb::ExpressionResults return_value = lldb::eExpressionSetupError;
145151c032cSJim Ingham 
146151c032cSJim Ingham   Process *process = exe_ctx.GetProcessPtr();
147151c032cSJim Ingham 
148151c032cSJim Ingham   if (process == NULL)
149151c032cSJim Ingham     return return_value;
150151c032cSJim Ingham 
151151c032cSJim Ingham   lldb::ProcessSP jit_process_sp(m_jit_process_wp.lock());
152151c032cSJim Ingham 
153151c032cSJim Ingham   if (process != jit_process_sp.get())
154151c032cSJim Ingham     return false;
155151c032cSJim Ingham 
156b9c1b51eSKate Stone   if (args_addr_ref == LLDB_INVALID_ADDRESS) {
157b9c1b51eSKate Stone     args_addr_ref = process->AllocateMemory(
158b9c1b51eSKate Stone         m_struct_size, lldb::ePermissionsReadable | lldb::ePermissionsWritable,
159b9c1b51eSKate Stone         error);
160151c032cSJim Ingham     if (args_addr_ref == LLDB_INVALID_ADDRESS)
161151c032cSJim Ingham       return false;
162151c032cSJim Ingham     m_wrapper_args_addrs.push_back(args_addr_ref);
163b9c1b51eSKate Stone   } else {
164151c032cSJim Ingham     // Make sure this is an address that we've already handed out.
165b9c1b51eSKate Stone     if (find(m_wrapper_args_addrs.begin(), m_wrapper_args_addrs.end(),
166b9c1b51eSKate Stone              args_addr_ref) == m_wrapper_args_addrs.end()) {
167151c032cSJim Ingham       return false;
168151c032cSJim Ingham     }
169151c032cSJim Ingham   }
170151c032cSJim Ingham 
171151c032cSJim Ingham   // TODO: verify fun_addr needs to be a callable address
172b9c1b51eSKate Stone   Scalar fun_addr(
173b9c1b51eSKate Stone       m_function_addr.GetCallableLoadAddress(exe_ctx.GetTargetPtr()));
174151c032cSJim Ingham   uint64_t first_offset = m_member_offsets[0];
175b9c1b51eSKate Stone   process->WriteScalarToMemory(args_addr_ref + first_offset, fun_addr,
176b9c1b51eSKate Stone                                process->GetAddressByteSize(), error);
177151c032cSJim Ingham 
178151c032cSJim Ingham   // FIXME: We will need to extend this for Variadic functions.
179151c032cSJim Ingham 
18097206d57SZachary Turner   Status value_error;
181151c032cSJim Ingham 
182151c032cSJim Ingham   size_t num_args = arg_values.GetSize();
183b9c1b51eSKate Stone   if (num_args != m_arg_values.GetSize()) {
184b9c1b51eSKate Stone     diagnostic_manager.Printf(
185b9c1b51eSKate Stone         eDiagnosticSeverityError,
186579e70c9SSean Callanan         "Wrong number of arguments - was: %" PRIu64 " should be: %" PRIu64 "",
187579e70c9SSean Callanan         (uint64_t)num_args, (uint64_t)m_arg_values.GetSize());
188151c032cSJim Ingham     return false;
189151c032cSJim Ingham   }
190151c032cSJim Ingham 
191b9c1b51eSKate Stone   for (size_t i = 0; i < num_args; i++) {
192151c032cSJim Ingham     // FIXME: We should sanity check sizes.
193151c032cSJim Ingham 
194151c032cSJim Ingham     uint64_t offset = m_member_offsets[i + 1]; // Clang sizes are in bytes.
195151c032cSJim Ingham     Value *arg_value = arg_values.GetValueAtIndex(i);
196151c032cSJim Ingham 
197151c032cSJim Ingham     // FIXME: For now just do scalars:
198151c032cSJim Ingham 
199b9c1b51eSKate Stone     // Special case: if it's a pointer, don't do anything (the ABI supports
200b9c1b51eSKate Stone     // passing cstrings)
201151c032cSJim Ingham 
202151c032cSJim Ingham     if (arg_value->GetValueType() == Value::eValueTypeHostAddress &&
203151c032cSJim Ingham         arg_value->GetContextType() == Value::eContextTypeInvalid &&
204151c032cSJim Ingham         arg_value->GetCompilerType().IsPointerType())
205151c032cSJim Ingham       continue;
206151c032cSJim Ingham 
207151c032cSJim Ingham     const Scalar &arg_scalar = arg_value->ResolveValue(&exe_ctx);
208151c032cSJim Ingham 
209b9c1b51eSKate Stone     if (!process->WriteScalarToMemory(args_addr_ref + offset, arg_scalar,
210b9c1b51eSKate Stone                                       arg_scalar.GetByteSize(), error))
211151c032cSJim Ingham       return false;
212151c032cSJim Ingham   }
213151c032cSJim Ingham 
214151c032cSJim Ingham   return true;
215151c032cSJim Ingham }
216151c032cSJim Ingham 
217b9c1b51eSKate Stone bool FunctionCaller::InsertFunction(ExecutionContext &exe_ctx,
218b9c1b51eSKate Stone                                     lldb::addr_t &args_addr_ref,
219b9c1b51eSKate Stone                                     DiagnosticManager &diagnostic_manager) {
2206896b355SJim Ingham   if (CompileFunction(exe_ctx.GetThreadSP(), diagnostic_manager) != 0)
221151c032cSJim Ingham     return false;
222579e70c9SSean Callanan   if (!WriteFunctionWrapper(exe_ctx, diagnostic_manager))
223151c032cSJim Ingham     return false;
224579e70c9SSean Callanan   if (!WriteFunctionArguments(exe_ctx, args_addr_ref, diagnostic_manager))
225151c032cSJim Ingham     return false;
226151c032cSJim Ingham 
227151c032cSJim Ingham   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
228151c032cSJim Ingham   if (log)
229b9c1b51eSKate Stone     log->Printf("Call Address: 0x%" PRIx64 " Struct Address: 0x%" PRIx64 ".\n",
230b9c1b51eSKate Stone                 m_jit_start_addr, args_addr_ref);
231151c032cSJim Ingham 
232151c032cSJim Ingham   return true;
233151c032cSJim Ingham }
234151c032cSJim Ingham 
235b9c1b51eSKate Stone lldb::ThreadPlanSP FunctionCaller::GetThreadPlanToCallFunction(
236b9c1b51eSKate Stone     ExecutionContext &exe_ctx, lldb::addr_t args_addr,
237151c032cSJim Ingham     const EvaluateExpressionOptions &options,
238b9c1b51eSKate Stone     DiagnosticManager &diagnostic_manager) {
239b9c1b51eSKate Stone   Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_EXPRESSIONS |
240b9c1b51eSKate Stone                                                   LIBLLDB_LOG_STEP));
241151c032cSJim Ingham 
242151c032cSJim Ingham   if (log)
243b9c1b51eSKate Stone     log->Printf("-- [FunctionCaller::GetThreadPlanToCallFunction] Creating "
244b9c1b51eSKate Stone                 "thread plan to call function \"%s\" --",
245b9c1b51eSKate Stone                 m_name.c_str());
246151c032cSJim Ingham 
247151c032cSJim Ingham   // FIXME: Use the errors Stream for better error reporting.
248151c032cSJim Ingham   Thread *thread = exe_ctx.GetThreadPtr();
249b9c1b51eSKate Stone   if (thread == NULL) {
250e2411fabSZachary Turner     diagnostic_manager.PutString(
251b9c1b51eSKate Stone         eDiagnosticSeverityError,
252b9c1b51eSKate Stone         "Can't call a function without a valid thread.");
253151c032cSJim Ingham     return NULL;
254151c032cSJim Ingham   }
255151c032cSJim Ingham 
256151c032cSJim Ingham   // Okay, now run the function:
257151c032cSJim Ingham 
258151c032cSJim Ingham   Address wrapper_address(m_jit_start_addr);
259151c032cSJim Ingham 
260151c032cSJim Ingham   lldb::addr_t args = {args_addr};
261151c032cSJim Ingham 
262b9c1b51eSKate Stone   lldb::ThreadPlanSP new_plan_sp(new ThreadPlanCallFunction(
263b9c1b51eSKate Stone       *thread, wrapper_address, CompilerType(), args, options));
264151c032cSJim Ingham   new_plan_sp->SetIsMasterPlan(true);
265151c032cSJim Ingham   new_plan_sp->SetOkayToDiscard(false);
266151c032cSJim Ingham   return new_plan_sp;
267151c032cSJim Ingham }
268151c032cSJim Ingham 
269b9c1b51eSKate Stone bool FunctionCaller::FetchFunctionResults(ExecutionContext &exe_ctx,
270b9c1b51eSKate Stone                                           lldb::addr_t args_addr,
271b9c1b51eSKate Stone                                           Value &ret_value) {
272151c032cSJim Ingham   // Read the return value - it is the last field in the struct:
273b9c1b51eSKate Stone   // FIXME: How does clang tell us there's no return value?  We need to handle
274b9c1b51eSKate Stone   // that case.
275b9c1b51eSKate Stone   // FIXME: Create our ThreadPlanCallFunction with the return CompilerType, and
276b9c1b51eSKate Stone   // then use GetReturnValueObject
277151c032cSJim Ingham   // to fetch the value.  That way we can fetch any values we need.
278151c032cSJim Ingham 
279b9c1b51eSKate Stone   Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_EXPRESSIONS |
280b9c1b51eSKate Stone                                                   LIBLLDB_LOG_STEP));
281151c032cSJim Ingham 
282151c032cSJim Ingham   if (log)
283b9c1b51eSKate Stone     log->Printf("-- [FunctionCaller::FetchFunctionResults] Fetching function "
284b9c1b51eSKate Stone                 "results for \"%s\"--",
285b9c1b51eSKate Stone                 m_name.c_str());
286151c032cSJim Ingham 
287151c032cSJim Ingham   Process *process = exe_ctx.GetProcessPtr();
288151c032cSJim Ingham 
289151c032cSJim Ingham   if (process == NULL)
290151c032cSJim Ingham     return false;
291151c032cSJim Ingham 
292151c032cSJim Ingham   lldb::ProcessSP jit_process_sp(m_jit_process_wp.lock());
293151c032cSJim Ingham 
294151c032cSJim Ingham   if (process != jit_process_sp.get())
295151c032cSJim Ingham     return false;
296151c032cSJim Ingham 
29797206d57SZachary Turner   Status error;
298b9c1b51eSKate Stone   ret_value.GetScalar() = process->ReadUnsignedIntegerFromMemory(
299b9c1b51eSKate Stone       args_addr + m_return_offset, m_return_size, 0, error);
300151c032cSJim Ingham 
301151c032cSJim Ingham   if (error.Fail())
302151c032cSJim Ingham     return false;
303151c032cSJim Ingham 
304151c032cSJim Ingham   ret_value.SetCompilerType(m_function_return_type);
305151c032cSJim Ingham   ret_value.SetValueType(Value::eValueTypeScalar);
306151c032cSJim Ingham   return true;
307151c032cSJim Ingham }
308151c032cSJim Ingham 
309b9c1b51eSKate Stone void FunctionCaller::DeallocateFunctionResults(ExecutionContext &exe_ctx,
310b9c1b51eSKate Stone                                                lldb::addr_t args_addr) {
311151c032cSJim Ingham   std::list<lldb::addr_t>::iterator pos;
312b9c1b51eSKate Stone   pos = std::find(m_wrapper_args_addrs.begin(), m_wrapper_args_addrs.end(),
313b9c1b51eSKate Stone                   args_addr);
314151c032cSJim Ingham   if (pos != m_wrapper_args_addrs.end())
315151c032cSJim Ingham     m_wrapper_args_addrs.erase(pos);
316151c032cSJim Ingham 
317151c032cSJim Ingham   exe_ctx.GetProcessRef().DeallocateMemory(args_addr);
318151c032cSJim Ingham }
319151c032cSJim Ingham 
320b9c1b51eSKate Stone lldb::ExpressionResults FunctionCaller::ExecuteFunction(
321b9c1b51eSKate Stone     ExecutionContext &exe_ctx, lldb::addr_t *args_addr_ptr,
322b9c1b51eSKate Stone     const EvaluateExpressionOptions &options,
323b9c1b51eSKate Stone     DiagnosticManager &diagnostic_manager, Value &results) {
324151c032cSJim Ingham   lldb::ExpressionResults return_value = lldb::eExpressionSetupError;
325151c032cSJim Ingham 
32605097246SAdrian Prantl   // FunctionCaller::ExecuteFunction execution is always just to get the
32705097246SAdrian Prantl   // result. Do make sure we ignore breakpoints, unwind on error, and don't try
32805097246SAdrian Prantl   // to debug it.
329151c032cSJim Ingham   EvaluateExpressionOptions real_options = options;
330151c032cSJim Ingham   real_options.SetDebug(false);
331151c032cSJim Ingham   real_options.SetUnwindOnError(true);
332151c032cSJim Ingham   real_options.SetIgnoreBreakpoints(true);
333151c032cSJim Ingham 
334151c032cSJim Ingham   lldb::addr_t args_addr;
335151c032cSJim Ingham 
336151c032cSJim Ingham   if (args_addr_ptr != NULL)
337151c032cSJim Ingham     args_addr = *args_addr_ptr;
338151c032cSJim Ingham   else
339151c032cSJim Ingham     args_addr = LLDB_INVALID_ADDRESS;
340151c032cSJim Ingham 
3416896b355SJim Ingham   if (CompileFunction(exe_ctx.GetThreadSP(), diagnostic_manager) != 0)
342151c032cSJim Ingham     return lldb::eExpressionSetupError;
343151c032cSJim Ingham 
344b9c1b51eSKate Stone   if (args_addr == LLDB_INVALID_ADDRESS) {
345579e70c9SSean Callanan     if (!InsertFunction(exe_ctx, args_addr, diagnostic_manager))
346151c032cSJim Ingham       return lldb::eExpressionSetupError;
347151c032cSJim Ingham   }
348151c032cSJim Ingham 
349b9c1b51eSKate Stone   Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_EXPRESSIONS |
350b9c1b51eSKate Stone                                                   LIBLLDB_LOG_STEP));
351151c032cSJim Ingham 
352151c032cSJim Ingham   if (log)
353b9c1b51eSKate Stone     log->Printf(
354b9c1b51eSKate Stone         "== [FunctionCaller::ExecuteFunction] Executing function \"%s\" ==",
355b9c1b51eSKate Stone         m_name.c_str());
356151c032cSJim Ingham 
357b9c1b51eSKate Stone   lldb::ThreadPlanSP call_plan_sp = GetThreadPlanToCallFunction(
358b9c1b51eSKate Stone       exe_ctx, args_addr, real_options, diagnostic_manager);
359151c032cSJim Ingham   if (!call_plan_sp)
360151c032cSJim Ingham     return lldb::eExpressionSetupError;
361151c032cSJim Ingham 
362b9c1b51eSKate Stone   // We need to make sure we record the fact that we are running an expression
36305097246SAdrian Prantl   // here otherwise this fact will fail to be recorded when fetching an
36405097246SAdrian Prantl   // Objective-C object description
365151c032cSJim Ingham   if (exe_ctx.GetProcessPtr())
366151c032cSJim Ingham     exe_ctx.GetProcessPtr()->SetRunningUserExpression(true);
367151c032cSJim Ingham 
368b9c1b51eSKate Stone   return_value = exe_ctx.GetProcessRef().RunThreadPlan(
369b9c1b51eSKate Stone       exe_ctx, call_plan_sp, real_options, diagnostic_manager);
370151c032cSJim Ingham 
371b9c1b51eSKate Stone   if (log) {
372b9c1b51eSKate Stone     if (return_value != lldb::eExpressionCompleted) {
373b9c1b51eSKate Stone       log->Printf("== [FunctionCaller::ExecuteFunction] Execution of \"%s\" "
374b9c1b51eSKate Stone                   "completed abnormally ==",
375b9c1b51eSKate Stone                   m_name.c_str());
376b9c1b51eSKate Stone     } else {
377b9c1b51eSKate Stone       log->Printf("== [FunctionCaller::ExecuteFunction] Execution of \"%s\" "
378b9c1b51eSKate Stone                   "completed normally ==",
379b9c1b51eSKate Stone                   m_name.c_str());
380151c032cSJim Ingham     }
381151c032cSJim Ingham   }
382151c032cSJim Ingham 
383151c032cSJim Ingham   if (exe_ctx.GetProcessPtr())
384151c032cSJim Ingham     exe_ctx.GetProcessPtr()->SetRunningUserExpression(false);
385151c032cSJim Ingham 
386151c032cSJim Ingham   if (args_addr_ptr != NULL)
387151c032cSJim Ingham     *args_addr_ptr = args_addr;
388151c032cSJim Ingham 
389151c032cSJim Ingham   if (return_value != lldb::eExpressionCompleted)
390151c032cSJim Ingham     return return_value;
391151c032cSJim Ingham 
392151c032cSJim Ingham   FetchFunctionResults(exe_ctx, args_addr, results);
393151c032cSJim Ingham 
394151c032cSJim Ingham   if (args_addr_ptr == NULL)
395151c032cSJim Ingham     DeallocateFunctionResults(exe_ctx, args_addr);
396151c032cSJim Ingham 
397151c032cSJim Ingham   return lldb::eExpressionCompleted;
398151c032cSJim Ingham }
399