LLDB  mainline
ThreadPlanCallFunctionUsingABI.cpp
Go to the documentation of this file.
1 //===-- ThreadPlanCallFunctionUsingABI.cpp --------------------------------===//
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 
10 #include "lldb/Core/Address.h"
11 #include "lldb/Target/Process.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 // ThreadPlanCallFunctionUsingABI: Plan to call a single function using the ABI
22 // instead of JIT
23 ThreadPlanCallFunctionUsingABI::ThreadPlanCallFunctionUsingABI(
24  Thread &thread, const Address &function, llvm::Type &prototype,
25  llvm::Type &return_type, llvm::ArrayRef<ABI::CallArgument> args,
26  const EvaluateExpressionOptions &options)
27  : ThreadPlanCallFunction(thread, function, options),
28  m_return_type(return_type) {
29  lldb::addr_t start_load_addr = LLDB_INVALID_ADDRESS;
30  lldb::addr_t function_load_addr = LLDB_INVALID_ADDRESS;
31  ABI *abi = nullptr;
32 
33  if (!ConstructorSetup(thread, abi, start_load_addr, function_load_addr))
34  return;
35 
36  if (!abi->PrepareTrivialCall(thread, m_function_sp, function_load_addr,
37  start_load_addr, prototype, args))
38  return;
39 
40  ReportRegisterState("ABI Function call was set up. Register state was:");
41 
42  m_valid = true;
43 }
44 
46 
48  DescriptionLevel level) {
49  if (level == eDescriptionLevelBrief) {
50  s->Printf("Function call thread plan using ABI instead of JIT");
51  } else {
52  s->Printf("Thread plan to call 0x%" PRIx64 " using ABI instead of JIT",
54  }
55 }
56 
58  const ABI *abi = m_process.GetABI().get();
59 
60  // Ask the abi for the return value
61  if (abi) {
62  const bool persistent = false;
64  abi->GetReturnValueObject(GetThread(), m_return_type, persistent);
65  }
66 }
lldb_private::ThreadPlan::GetThread
Thread & GetThread()
Returns the Thread that is using this thread plan.
Definition: ThreadPlan.cpp:41
lldb_private::ABI
Definition: ABI.h:27
lldb_private::EvaluateExpressionOptions
Definition: Target.h:259
lldb_private::ThreadPlanCallFunction::m_function_addr
Address m_function_addr
Definition: ThreadPlanCallFunction.h:124
lldb_private::Stream
Definition: Stream.h:28
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
Process.h
lldb_private::ThreadPlanCallFunction
Definition: ThreadPlanCallFunction.h:20
Target.h
lldb_private::ThreadPlanCallFunctionUsingABI::SetReturnValue
void SetReturnValue() override
Definition: ThreadPlanCallFunctionUsingABI.cpp:57
lldb_private::ThreadPlan::GetTarget
Target & GetTarget()
Definition: ThreadPlan.cpp:37
lldb_private::ThreadPlanCallFunction::m_function_sp
lldb::addr_t m_function_sp
Definition: ThreadPlanCallFunction.h:126
Log.h
lldb_private::Thread
Definition: Thread.h:60
lldb_private::ThreadPlanCallFunctionUsingABI::m_return_type
llvm::Type & m_return_type
Definition: ThreadPlanCallFunctionUsingABI.h:46
lldb_private::ThreadPlanCallFunction::ReportRegisterState
void ReportRegisterState(const char *message)
Definition: ThreadPlanCallFunction.cpp:145
lldb_private::ThreadPlanCallFunction::m_valid
bool m_valid
Definition: ThreadPlanCallFunction.h:118
Thread.h
Address.h
lldb_private::ThreadPlanCallFunction::ConstructorSetup
bool ConstructorSetup(Thread &thread, ABI *&abi, lldb::addr_t &start_load_addr, lldb::addr_t &function_load_addr)
Definition: ThreadPlanCallFunction.cpp:33
lldb_private::ThreadPlanCallFunctionUsingABI::GetDescription
void GetDescription(Stream *s, lldb::DescriptionLevel level) override
Print a description of this thread to the stream s.
Definition: ThreadPlanCallFunctionUsingABI.cpp:47
lldb_private::Address
Definition: Address.h:59
ThreadPlanCallFunctionUsingABI.h
lldb_private::Address::GetLoadAddress
lldb::addr_t GetLoadAddress(Target *target) const
Get the load address.
Definition: Address.cpp:310
lldb_private::ThreadPlanCallFunctionUsingABI::~ThreadPlanCallFunctionUsingABI
~ThreadPlanCallFunctionUsingABI() override
LLDB_INVALID_ADDRESS
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:86
lldb_private::Stream::Printf
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:107
lldb_private::ThreadPlanCallFunction::m_return_valobj_sp
lldb::ValueObjectSP m_return_valobj_sp
Definition: ThreadPlanCallFunction.h:137
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::ABI::PrepareTrivialCall
virtual bool PrepareTrivialCall(lldb_private::Thread &thread, lldb::addr_t sp, lldb::addr_t functionAddress, lldb::addr_t returnAddress, llvm::ArrayRef< lldb::addr_t > args) const =0
lldb_private::Process::GetABI
const lldb::ABISP & GetABI()
Definition: Process.cpp:1487
Stream.h
lldb_private::ABI::GetReturnValueObject
lldb::ValueObjectSP GetReturnValueObject(Thread &thread, CompilerType &type, bool persistent=true) const
Definition: ABI.cpp:69
lldb_private::ThreadPlan::m_process
Process & m_process
Definition: ThreadPlan.h:523
lldb
Definition: SBAddress.h:15
RegisterContext.h
lldb::eDescriptionLevelBrief
@ eDescriptionLevelBrief
Definition: lldb-enumerations.h:208
lldb::DescriptionLevel
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
Definition: lldb-enumerations.h:207