1 //===-- ABI.h ---------------------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
10 #define liblldb_ABI_h_
12 #include "lldb/Core/PluginInterface.h"
13 #include "lldb/Symbol/UnwindPlan.h"
14 #include "lldb/Utility/Status.h"
15 #include "lldb/lldb-private.h"
17 #include "llvm/ADT/ArrayRef.h"
19 // forward define the llvm::Type class
24 namespace lldb_private {
26 class ABI : public PluginInterface {
30 HostPointer = 0, /* pointer to host data */
31 TargetValue, /* value is on the target or literal */
33 eType type; /* value of eType */
34 size_t size; /* size in bytes of this argument */
36 lldb::addr_t value; /* literal value */
37 std::unique_ptr<uint8_t[]> data_up; /* host data pointer */
42 virtual size_t GetRedZoneSize() const = 0;
44 virtual bool PrepareTrivialCall(lldb_private::Thread &thread, lldb::addr_t sp,
45 lldb::addr_t functionAddress,
46 lldb::addr_t returnAddress,
47 llvm::ArrayRef<lldb::addr_t> args) const = 0;
49 // Prepare trivial call used from ThreadPlanFunctionCallUsingABI
51 // . Because i don't want to change other ABI's this is not declared pure
53 // The dummy implementation will simply fail. Only HexagonABI will
56 // . Two PrepareTrivialCall's is not good design so perhaps this should be
59 virtual bool PrepareTrivialCall(lldb_private::Thread &thread, lldb::addr_t sp,
60 lldb::addr_t functionAddress,
61 lldb::addr_t returnAddress,
62 llvm::Type &prototype,
63 llvm::ArrayRef<CallArgument> args) const;
65 virtual bool GetArgumentValues(Thread &thread, ValueList &values) const = 0;
67 lldb::ValueObjectSP GetReturnValueObject(Thread &thread, CompilerType &type,
68 bool persistent = true) const;
70 // specialized to work with llvm IR types
71 lldb::ValueObjectSP GetReturnValueObject(Thread &thread, llvm::Type &type,
72 bool persistent = true) const;
74 // Set the Return value object in the current frame as though a function with
75 virtual Status SetReturnValueObject(lldb::StackFrameSP &frame_sp,
76 lldb::ValueObjectSP &new_value) = 0;
79 // This is the method the ABI will call to actually calculate the return
80 // value. Don't put it in a persistent value object, that will be done by the
81 // ABI::GetReturnValueObject.
82 virtual lldb::ValueObjectSP
83 GetReturnValueObjectImpl(Thread &thread, CompilerType &ast_type) const = 0;
85 // specialized to work with llvm IR types
86 virtual lldb::ValueObjectSP
87 GetReturnValueObjectImpl(Thread &thread, llvm::Type &ir_type) const;
89 /// Request to get a Process shared pointer.
91 /// This ABI object may not have been created with a Process object,
92 /// or the Process object may no longer be alive. Be sure to handle
93 /// the case where the shared pointer returned does not have an
95 lldb::ProcessSP GetProcessSP() const { return m_process_wp.lock(); }
98 virtual bool CreateFunctionEntryUnwindPlan(UnwindPlan &unwind_plan) = 0;
100 virtual bool CreateDefaultUnwindPlan(UnwindPlan &unwind_plan) = 0;
102 virtual bool RegisterIsVolatile(const RegisterInfo *reg_info) = 0;
105 GetFallbackRegisterLocation(const RegisterInfo *reg_info,
106 UnwindPlan::Row::RegisterLocation &unwind_regloc);
108 // Should take a look at a call frame address (CFA) which is just the stack
109 // pointer value upon entry to a function. ABIs usually impose alignment
110 // restrictions (4, 8 or 16 byte aligned), and zero is usually not allowed.
111 // This function should return true if "cfa" is valid call frame address for
112 // the ABI, and false otherwise. This is used by the generic stack frame
113 // unwinding code to help determine when a stack ends.
114 virtual bool CallFrameAddressIsValid(lldb::addr_t cfa) = 0;
116 // Validates a possible PC value and returns true if an opcode can be at
118 virtual bool CodeAddressIsValid(lldb::addr_t pc) = 0;
120 virtual lldb::addr_t FixCodeAddress(lldb::addr_t pc) {
121 // Some targets might use bits in a code address to indicate a mode switch.
122 // ARM uses bit zero to signify a code address is thumb, so any ARM ABI
123 // plug-ins would strip those bits.
127 virtual const RegisterInfo *GetRegisterInfoArray(uint32_t &count) = 0;
129 bool GetRegisterInfoByName(ConstString name, RegisterInfo &info);
131 bool GetRegisterInfoByKind(lldb::RegisterKind reg_kind, uint32_t reg_num,
134 virtual bool GetPointerReturnRegister(const char *&name) { return false; }
136 static lldb::ABISP FindPlugin(lldb::ProcessSP process_sp, const ArchSpec &arch);
139 // Classes that inherit from ABI can see and modify these
140 ABI(lldb::ProcessSP process_sp) {
141 if (process_sp.get())
142 m_process_wp = process_sp;
145 lldb::ProcessWP m_process_wp;
148 DISALLOW_COPY_AND_ASSIGN(ABI);
151 } // namespace lldb_private
153 #endif // liblldb_ABI_h_