Eugene Zelenko | e65b2cf | 2015-12-15 01:33:19 +0000 | [diff] [blame] | 1 | //===-- ThreadPlanCallFunctionUsingABI.cpp ----------------------*- C++ -*-===// |
Ewan Crawford | 90ff791 | 2015-07-14 10:56:58 +0000 | [diff] [blame] | 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 | |
Ewan Crawford | 90ff791 | 2015-07-14 10:56:58 +0000 | [diff] [blame] | 10 | // C Includes |
| 11 | // C++ Includes |
| 12 | // Other libraries and framework includes |
Ewan Crawford | 90ff791 | 2015-07-14 10:56:58 +0000 | [diff] [blame] | 13 | // Project includes |
Eugene Zelenko | e65b2cf | 2015-12-15 01:33:19 +0000 | [diff] [blame] | 14 | #include "lldb/Target/ThreadPlanCallFunctionUsingABI.h" |
Ewan Crawford | 90ff791 | 2015-07-14 10:56:58 +0000 | [diff] [blame] | 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 | //-------------------------------------------------------------------------------------------- |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 27 | // ThreadPlanCallFunctionUsingABI: Plan to call a single function using the ABI |
| 28 | // instead of JIT |
Ewan Crawford | 90ff791 | 2015-07-14 10:56:58 +0000 | [diff] [blame] | 29 | //------------------------------------------------------------------------------------------- |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 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; |
Ewan Crawford | 90ff791 | 2015-07-14 10:56:58 +0000 | [diff] [blame] | 39 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 40 | if (!ConstructorSetup(thread, abi, start_load_addr, function_load_addr)) |
| 41 | return; |
Ewan Crawford | 90ff791 | 2015-07-14 10:56:58 +0000 | [diff] [blame] | 42 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 43 | if (!abi->PrepareTrivialCall(thread, m_function_sp, function_load_addr, |
| 44 | start_load_addr, prototype, args)) |
| 45 | return; |
Ewan Crawford | 90ff791 | 2015-07-14 10:56:58 +0000 | [diff] [blame] | 46 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 47 | ReportRegisterState("ABI Function call was set up. Register state was:"); |
Ewan Crawford | 90ff791 | 2015-07-14 10:56:58 +0000 | [diff] [blame] | 48 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 49 | m_valid = true; |
Ewan Crawford | 90ff791 | 2015-07-14 10:56:58 +0000 | [diff] [blame] | 50 | } |
| 51 | |
Eugene Zelenko | e65b2cf | 2015-12-15 01:33:19 +0000 | [diff] [blame] | 52 | ThreadPlanCallFunctionUsingABI::~ThreadPlanCallFunctionUsingABI() = default; |
Ewan Crawford | 90ff791 | 2015-07-14 10:56:58 +0000 | [diff] [blame] | 53 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 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 | } |
Ewan Crawford | 90ff791 | 2015-07-14 10:56:58 +0000 | [diff] [blame] | 63 | } |
| 64 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 65 | void ThreadPlanCallFunctionUsingABI::SetReturnValue() { |
| 66 | ProcessSP process_sp(m_thread.GetProcess()); |
| 67 | const ABI *abi = process_sp ? process_sp->GetABI().get() : nullptr; |
Ewan Crawford | 90ff791 | 2015-07-14 10:56:58 +0000 | [diff] [blame] | 68 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 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 | } |
Ewan Crawford | 90ff791 | 2015-07-14 10:56:58 +0000 | [diff] [blame] | 75 | } |