1*dda28197Spatrick //===-- ThreadPlanCallFunctionUsingABI.cpp --------------------------------===//
2061da546Spatrick //
3061da546Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4061da546Spatrick // See https://llvm.org/LICENSE.txt for license information.
5061da546Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6061da546Spatrick //
7061da546Spatrick //===----------------------------------------------------------------------===//
8061da546Spatrick
9061da546Spatrick #include "lldb/Target/ThreadPlanCallFunctionUsingABI.h"
10061da546Spatrick #include "lldb/Core/Address.h"
11061da546Spatrick #include "lldb/Target/Process.h"
12061da546Spatrick #include "lldb/Target/RegisterContext.h"
13061da546Spatrick #include "lldb/Target/Target.h"
14061da546Spatrick #include "lldb/Target/Thread.h"
15061da546Spatrick #include "lldb/Utility/Log.h"
16061da546Spatrick #include "lldb/Utility/Stream.h"
17061da546Spatrick
18061da546Spatrick using namespace lldb;
19061da546Spatrick using namespace lldb_private;
20061da546Spatrick
21061da546Spatrick // ThreadPlanCallFunctionUsingABI: Plan to call a single function using the ABI
22061da546Spatrick // instead of JIT
ThreadPlanCallFunctionUsingABI(Thread & thread,const Address & function,llvm::Type & prototype,llvm::Type & return_type,llvm::ArrayRef<ABI::CallArgument> args,const EvaluateExpressionOptions & options)23061da546Spatrick ThreadPlanCallFunctionUsingABI::ThreadPlanCallFunctionUsingABI(
24061da546Spatrick Thread &thread, const Address &function, llvm::Type &prototype,
25061da546Spatrick llvm::Type &return_type, llvm::ArrayRef<ABI::CallArgument> args,
26061da546Spatrick const EvaluateExpressionOptions &options)
27061da546Spatrick : ThreadPlanCallFunction(thread, function, options),
28061da546Spatrick m_return_type(return_type) {
29061da546Spatrick lldb::addr_t start_load_addr = LLDB_INVALID_ADDRESS;
30061da546Spatrick lldb::addr_t function_load_addr = LLDB_INVALID_ADDRESS;
31061da546Spatrick ABI *abi = nullptr;
32061da546Spatrick
33061da546Spatrick if (!ConstructorSetup(thread, abi, start_load_addr, function_load_addr))
34061da546Spatrick return;
35061da546Spatrick
36061da546Spatrick if (!abi->PrepareTrivialCall(thread, m_function_sp, function_load_addr,
37061da546Spatrick start_load_addr, prototype, args))
38061da546Spatrick return;
39061da546Spatrick
40061da546Spatrick ReportRegisterState("ABI Function call was set up. Register state was:");
41061da546Spatrick
42061da546Spatrick m_valid = true;
43061da546Spatrick }
44061da546Spatrick
45061da546Spatrick ThreadPlanCallFunctionUsingABI::~ThreadPlanCallFunctionUsingABI() = default;
46061da546Spatrick
GetDescription(Stream * s,DescriptionLevel level)47061da546Spatrick void ThreadPlanCallFunctionUsingABI::GetDescription(Stream *s,
48061da546Spatrick DescriptionLevel level) {
49061da546Spatrick if (level == eDescriptionLevelBrief) {
50061da546Spatrick s->Printf("Function call thread plan using ABI instead of JIT");
51061da546Spatrick } else {
52061da546Spatrick s->Printf("Thread plan to call 0x%" PRIx64 " using ABI instead of JIT",
53*dda28197Spatrick m_function_addr.GetLoadAddress(&GetTarget()));
54061da546Spatrick }
55061da546Spatrick }
56061da546Spatrick
SetReturnValue()57061da546Spatrick void ThreadPlanCallFunctionUsingABI::SetReturnValue() {
58*dda28197Spatrick const ABI *abi = m_process.GetABI().get();
59061da546Spatrick
60061da546Spatrick // Ask the abi for the return value
61061da546Spatrick if (abi) {
62061da546Spatrick const bool persistent = false;
63061da546Spatrick m_return_valobj_sp =
64*dda28197Spatrick abi->GetReturnValueObject(GetThread(), m_return_type, persistent);
65061da546Spatrick }
66061da546Spatrick }
67