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 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Ewan Crawford | 90ff791 | 2015-07-14 10:56:58 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
Eugene Zelenko | e65b2cf | 2015-12-15 01:33:19 +0000 | [diff] [blame] | 9 | #include "lldb/Target/ThreadPlanCallFunctionUsingABI.h" |
Ewan Crawford | 90ff791 | 2015-07-14 10:56:58 +0000 | [diff] [blame] | 10 | #include "lldb/Core/Address.h" |
Ewan Crawford | 90ff791 | 2015-07-14 10:56:58 +0000 | [diff] [blame] | 11 | #include "lldb/Target/Process.h" |
| 12 | #include "lldb/Target/RegisterContext.h" |
| 13 | #include "lldb/Target/Target.h" |
| 14 | #include "lldb/Target/Thread.h" |
Zachary Turner | 6f9e690 | 2017-03-03 20:56:28 +0000 | [diff] [blame] | 15 | #include "lldb/Utility/Log.h" |
Zachary Turner | bf9a773 | 2017-02-02 21:39:50 +0000 | [diff] [blame] | 16 | #include "lldb/Utility/Stream.h" |
Ewan Crawford | 90ff791 | 2015-07-14 10:56:58 +0000 | [diff] [blame] | 17 | |
| 18 | using namespace lldb; |
| 19 | using namespace lldb_private; |
| 20 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 21 | // ThreadPlanCallFunctionUsingABI: Plan to call a single function using the ABI |
| 22 | // instead of JIT |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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; |
Ewan Crawford | 90ff791 | 2015-07-14 10:56:58 +0000 | [diff] [blame] | 32 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 33 | if (!ConstructorSetup(thread, abi, start_load_addr, function_load_addr)) |
| 34 | return; |
Ewan Crawford | 90ff791 | 2015-07-14 10:56:58 +0000 | [diff] [blame] | 35 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 36 | if (!abi->PrepareTrivialCall(thread, m_function_sp, function_load_addr, |
| 37 | start_load_addr, prototype, args)) |
| 38 | return; |
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 | ReportRegisterState("ABI Function call was set up. Register state was:"); |
Ewan Crawford | 90ff791 | 2015-07-14 10:56:58 +0000 | [diff] [blame] | 41 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 42 | m_valid = true; |
Ewan Crawford | 90ff791 | 2015-07-14 10:56:58 +0000 | [diff] [blame] | 43 | } |
| 44 | |
Eugene Zelenko | e65b2cf | 2015-12-15 01:33:19 +0000 | [diff] [blame] | 45 | ThreadPlanCallFunctionUsingABI::~ThreadPlanCallFunctionUsingABI() = default; |
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 | void ThreadPlanCallFunctionUsingABI::GetDescription(Stream *s, |
| 48 | DescriptionLevel level) { |
| 49 | if (level == eDescriptionLevelBrief) { |
| 50 | s->Printf("Function call thread plan using ABI instead of JIT"); |
| 51 | } else { |
| 52 | TargetSP target_sp(m_thread.CalculateTarget()); |
| 53 | s->Printf("Thread plan to call 0x%" PRIx64 " using ABI instead of JIT", |
| 54 | m_function_addr.GetLoadAddress(target_sp.get())); |
| 55 | } |
Ewan Crawford | 90ff791 | 2015-07-14 10:56:58 +0000 | [diff] [blame] | 56 | } |
| 57 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 58 | void ThreadPlanCallFunctionUsingABI::SetReturnValue() { |
| 59 | ProcessSP process_sp(m_thread.GetProcess()); |
| 60 | const ABI *abi = process_sp ? process_sp->GetABI().get() : nullptr; |
Ewan Crawford | 90ff791 | 2015-07-14 10:56:58 +0000 | [diff] [blame] | 61 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 62 | // Ask the abi for the return value |
| 63 | if (abi) { |
| 64 | const bool persistent = false; |
| 65 | m_return_valobj_sp = |
| 66 | abi->GetReturnValueObject(m_thread, m_return_type, persistent); |
| 67 | } |
Ewan Crawford | 90ff791 | 2015-07-14 10:56:58 +0000 | [diff] [blame] | 68 | } |