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