]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Target/ThreadPlanCallFunctionUsingABI.cpp
Merge ^/head r313301 through r313643.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Target / ThreadPlanCallFunctionUsingABI.cpp
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
28 // instead of JIT
29 //-------------------------------------------------------------------------------------------
30 ThreadPlanCallFunctionUsingABI::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;
39
40   if (!ConstructorSetup(thread, abi, start_load_addr, function_load_addr))
41     return;
42
43   if (!abi->PrepareTrivialCall(thread, m_function_sp, function_load_addr,
44                                start_load_addr, prototype, args))
45     return;
46
47   ReportRegisterState("ABI Function call was set up.  Register state was:");
48
49   m_valid = true;
50 }
51
52 ThreadPlanCallFunctionUsingABI::~ThreadPlanCallFunctionUsingABI() = default;
53
54 void 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   }
63 }
64
65 void ThreadPlanCallFunctionUsingABI::SetReturnValue() {
66   ProcessSP process_sp(m_thread.GetProcess());
67   const ABI *abi = process_sp ? process_sp->GetABI().get() : nullptr;
68
69   // 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   }
75 }