1 //===-- ThreadPlanCallFunctionUsingABI.cpp ----------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "lldb/Target/ThreadPlanCallFunctionUsingABI.h" 10 #include "lldb/Core/Address.h" 11 #include "lldb/Target/Process.h" 12 #include "lldb/Target/RegisterContext.h" 13 #include "lldb/Target/Target.h" 14 #include "lldb/Target/Thread.h" 15 #include "lldb/Utility/Log.h" 16 #include "lldb/Utility/Stream.h" 17 18 using namespace lldb; 19 using namespace lldb_private; 20 21 //-------------------------------------------------------------------------------------------- 22 // ThreadPlanCallFunctionUsingABI: Plan to call a single function using the ABI 23 // instead of JIT 24 //------------------------------------------------------------------------------------------- 25 ThreadPlanCallFunctionUsingABI::ThreadPlanCallFunctionUsingABI( 26 Thread &thread, const Address &function, llvm::Type &prototype, 27 llvm::Type &return_type, llvm::ArrayRef<ABI::CallArgument> args, 28 const EvaluateExpressionOptions &options) 29 : ThreadPlanCallFunction(thread, function, options), 30 m_return_type(return_type) { 31 lldb::addr_t start_load_addr = LLDB_INVALID_ADDRESS; 32 lldb::addr_t function_load_addr = LLDB_INVALID_ADDRESS; 33 ABI *abi = nullptr; 34 35 if (!ConstructorSetup(thread, abi, start_load_addr, function_load_addr)) 36 return; 37 38 if (!abi->PrepareTrivialCall(thread, m_function_sp, function_load_addr, 39 start_load_addr, prototype, args)) 40 return; 41 42 ReportRegisterState("ABI Function call was set up. Register state was:"); 43 44 m_valid = true; 45 } 46 47 ThreadPlanCallFunctionUsingABI::~ThreadPlanCallFunctionUsingABI() = default; 48 49 void ThreadPlanCallFunctionUsingABI::GetDescription(Stream *s, 50 DescriptionLevel level) { 51 if (level == eDescriptionLevelBrief) { 52 s->Printf("Function call thread plan using ABI instead of JIT"); 53 } else { 54 TargetSP target_sp(m_thread.CalculateTarget()); 55 s->Printf("Thread plan to call 0x%" PRIx64 " using ABI instead of JIT", 56 m_function_addr.GetLoadAddress(target_sp.get())); 57 } 58 } 59 60 void ThreadPlanCallFunctionUsingABI::SetReturnValue() { 61 ProcessSP process_sp(m_thread.GetProcess()); 62 const ABI *abi = process_sp ? process_sp->GetABI().get() : nullptr; 63 64 // Ask the abi for the return value 65 if (abi) { 66 const bool persistent = false; 67 m_return_valobj_sp = 68 abi->GetReturnValueObject(m_thread, m_return_type, persistent); 69 } 70 } 71