1 //===-- ThreadPlanCallFunctionUsingABI.cpp ------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "lldb/Target/ThreadPlanCallFunctionUsingABI.h"
11 
12 // C Includes
13 // C++ Includes
14 // Other libraries and framework includes
15 
16 // Project includes
17 #include "lldb/Core/Address.h"
18 #include "lldb/Core/Log.h"
19 #include "lldb/Core/Stream.h"
20 #include "lldb/Target/Process.h"
21 #include "lldb/Target/RegisterContext.h"
22 #include "lldb/Target/Target.h"
23 #include "lldb/Target/Thread.h"
24 
25 using namespace lldb;
26 using namespace lldb_private;
27 
28 //--------------------------------------------------------------------------------------------
29 // ThreadPlanCallFunctionUsingABI: Plan to call a single function using the ABI instead of JIT
30 //-------------------------------------------------------------------------------------------
31 ThreadPlanCallFunctionUsingABI::ThreadPlanCallFunctionUsingABI (Thread &thread,
32                                                           const Address &function,
33                                                           llvm::Type &prototype,
34                                                           llvm::Type &return_type,
35                                                           llvm::ArrayRef<ABI::CallArgument> args,
36                                                           const EvaluateExpressionOptions &options) :
37      ThreadPlanCallFunction(thread,function,options),
38      m_return_type(return_type)
39 {
40     lldb::addr_t start_load_addr = LLDB_INVALID_ADDRESS;
41     lldb::addr_t function_load_addr = LLDB_INVALID_ADDRESS;
42     ABI *abi = nullptr;
43 
44     if (!ConstructorSetup(thread, abi, start_load_addr, function_load_addr))
45         return;
46 
47     if (!abi->PrepareTrivialCall(thread,
48         m_function_sp,
49         function_load_addr,
50         start_load_addr,
51         prototype,
52         args))
53         return;
54 
55     ReportRegisterState("ABI Function call was set up.  Register state was:");
56 
57     m_valid = true;
58 }
59 
60 ThreadPlanCallFunctionUsingABI::~ThreadPlanCallFunctionUsingABI()
61 {
62 
63 }
64 
65 void
66 ThreadPlanCallFunctionUsingABI::GetDescription(Stream *s, DescriptionLevel level)
67 {
68     if (level == eDescriptionLevelBrief)
69     {
70         s->Printf("Function call thread plan using ABI instead of JIT");
71     }
72     else
73     {
74         TargetSP target_sp(m_thread.CalculateTarget());
75         s->Printf("Thread plan to call 0x%" PRIx64" using ABI instead of JIT", m_function_addr.GetLoadAddress(target_sp.get()));
76     }
77 }
78 
79 void
80 ThreadPlanCallFunctionUsingABI::SetReturnValue()
81 {
82     ProcessSP process_sp(m_thread.GetProcess());
83     const ABI *abi = process_sp ? process_sp->GetABI().get() : NULL;
84 
85     // Ask the abi for the return value
86     if (abi)
87     {
88         const bool persistent = false;
89         m_return_valobj_sp = abi->GetReturnValueObject(m_thread, m_return_type, persistent);
90     }
91 }
92