blob: 6c5969577a905fc51847ca8855c43ba6134a310a [file] [log] [blame]
Eugene Zelenkoe65b2cf2015-12-15 01:33:19 +00001//===-- ThreadPlanCallFunctionUsingABI.cpp ----------------------*- C++ -*-===//
Ewan Crawford90ff7912015-07-14 10:56:58 +00002//
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
Ewan Crawford90ff7912015-07-14 10:56:58 +000010// C Includes
11// C++ Includes
12// Other libraries and framework includes
Ewan Crawford90ff7912015-07-14 10:56:58 +000013// Project includes
Eugene Zelenkoe65b2cf2015-12-15 01:33:19 +000014#include "lldb/Target/ThreadPlanCallFunctionUsingABI.h"
Ewan Crawford90ff7912015-07-14 10:56:58 +000015#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
23using namespace lldb;
24using namespace lldb_private;
25
26//--------------------------------------------------------------------------------------------
Kate Stoneb9c1b512016-09-06 20:57:50 +000027// ThreadPlanCallFunctionUsingABI: Plan to call a single function using the ABI
28// instead of JIT
Ewan Crawford90ff7912015-07-14 10:56:58 +000029//-------------------------------------------------------------------------------------------
Kate Stoneb9c1b512016-09-06 20:57:50 +000030ThreadPlanCallFunctionUsingABI::ThreadPlanCallFunctionUsingABI(
31 Thread &thread, const Address &function, llvm::Type &prototype,
32 llvm::Type &return_type, llvm::ArrayRef<ABI::CallArgument> args,
33 const EvaluateExpressionOptions &options)
34 : ThreadPlanCallFunction(thread, function, options),
35 m_return_type(return_type) {
36 lldb::addr_t start_load_addr = LLDB_INVALID_ADDRESS;
37 lldb::addr_t function_load_addr = LLDB_INVALID_ADDRESS;
38 ABI *abi = nullptr;
Ewan Crawford90ff7912015-07-14 10:56:58 +000039
Kate Stoneb9c1b512016-09-06 20:57:50 +000040 if (!ConstructorSetup(thread, abi, start_load_addr, function_load_addr))
41 return;
Ewan Crawford90ff7912015-07-14 10:56:58 +000042
Kate Stoneb9c1b512016-09-06 20:57:50 +000043 if (!abi->PrepareTrivialCall(thread, m_function_sp, function_load_addr,
44 start_load_addr, prototype, args))
45 return;
Ewan Crawford90ff7912015-07-14 10:56:58 +000046
Kate Stoneb9c1b512016-09-06 20:57:50 +000047 ReportRegisterState("ABI Function call was set up. Register state was:");
Ewan Crawford90ff7912015-07-14 10:56:58 +000048
Kate Stoneb9c1b512016-09-06 20:57:50 +000049 m_valid = true;
Ewan Crawford90ff7912015-07-14 10:56:58 +000050}
51
Eugene Zelenkoe65b2cf2015-12-15 01:33:19 +000052ThreadPlanCallFunctionUsingABI::~ThreadPlanCallFunctionUsingABI() = default;
Ewan Crawford90ff7912015-07-14 10:56:58 +000053
Kate Stoneb9c1b512016-09-06 20:57:50 +000054void ThreadPlanCallFunctionUsingABI::GetDescription(Stream *s,
55 DescriptionLevel level) {
56 if (level == eDescriptionLevelBrief) {
57 s->Printf("Function call thread plan using ABI instead of JIT");
58 } else {
59 TargetSP target_sp(m_thread.CalculateTarget());
60 s->Printf("Thread plan to call 0x%" PRIx64 " using ABI instead of JIT",
61 m_function_addr.GetLoadAddress(target_sp.get()));
62 }
Ewan Crawford90ff7912015-07-14 10:56:58 +000063}
64
Kate Stoneb9c1b512016-09-06 20:57:50 +000065void ThreadPlanCallFunctionUsingABI::SetReturnValue() {
66 ProcessSP process_sp(m_thread.GetProcess());
67 const ABI *abi = process_sp ? process_sp->GetABI().get() : nullptr;
Ewan Crawford90ff7912015-07-14 10:56:58 +000068
Kate Stoneb9c1b512016-09-06 20:57:50 +000069 // Ask the abi for the return value
70 if (abi) {
71 const bool persistent = false;
72 m_return_valobj_sp =
73 abi->GetReturnValueObject(m_thread, m_return_type, persistent);
74 }
Ewan Crawford90ff7912015-07-14 10:56:58 +000075}