1 //===-- ABI.h ---------------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_ABI_h_
11 #define liblldb_ABI_h_
15 // Other libraries and framework includes
17 #include "lldb/Core/PluginInterface.h"
18 #include "lldb/Symbol/UnwindPlan.h"
19 #include "lldb/Utility/Status.h"
20 #include "lldb/lldb-private.h"
22 #include "llvm/ADT/ArrayRef.h"
24 // forward define the llvm::Type class
29 namespace lldb_private {
31 class ABI : public PluginInterface {
35 HostPointer = 0, /* pointer to host data */
36 TargetValue, /* value is on the target or literal */
38 eType type; /* value of eType */
39 size_t size; /* size in bytes of this argument */
41 lldb::addr_t value; /* literal value */
42 std::unique_ptr<uint8_t[]> data_ap; /* host data pointer */
47 virtual size_t GetRedZoneSize() const = 0;
49 virtual bool PrepareTrivialCall(lldb_private::Thread &thread, lldb::addr_t sp,
50 lldb::addr_t functionAddress,
51 lldb::addr_t returnAddress,
52 llvm::ArrayRef<lldb::addr_t> args) const = 0;
54 // Prepare trivial call used from ThreadPlanFunctionCallUsingABI
56 // . Because i don't want to change other ABI's this is not declared pure
58 // The dummy implementation will simply fail. Only HexagonABI will
61 // . Two PrepareTrivialCall's is not good design so perhaps this should be
64 virtual bool PrepareTrivialCall(lldb_private::Thread &thread, lldb::addr_t sp,
65 lldb::addr_t functionAddress,
66 lldb::addr_t returnAddress,
67 llvm::Type &prototype,
68 llvm::ArrayRef<CallArgument> args) const;
70 virtual bool GetArgumentValues(Thread &thread, ValueList &values) const = 0;
72 lldb::ValueObjectSP GetReturnValueObject(Thread &thread, CompilerType &type,
73 bool persistent = true) const;
75 // specialized to work with llvm IR types
76 lldb::ValueObjectSP GetReturnValueObject(Thread &thread, llvm::Type &type,
77 bool persistent = true) const;
79 // Set the Return value object in the current frame as though a function with
80 virtual Status SetReturnValueObject(lldb::StackFrameSP &frame_sp,
81 lldb::ValueObjectSP &new_value) = 0;
84 // This is the method the ABI will call to actually calculate the return
85 // value. Don't put it in a persistent value object, that will be done by the
86 // ABI::GetReturnValueObject.
87 virtual lldb::ValueObjectSP
88 GetReturnValueObjectImpl(Thread &thread, CompilerType &ast_type) const = 0;
90 // specialized to work with llvm IR types
91 virtual lldb::ValueObjectSP
92 GetReturnValueObjectImpl(Thread &thread, llvm::Type &ir_type) const;
94 //------------------------------------------------------------------
95 /// Request to get a Process shared pointer.
97 /// This ABI object may not have been created with a Process object,
98 /// or the Process object may no longer be alive. Be sure to handle
99 /// the case where the shared pointer returned does not have an
100 /// object inside it.
101 //------------------------------------------------------------------
102 lldb::ProcessSP GetProcessSP() const { return m_process_wp.lock(); }
105 virtual bool CreateFunctionEntryUnwindPlan(UnwindPlan &unwind_plan) = 0;
107 virtual bool CreateDefaultUnwindPlan(UnwindPlan &unwind_plan) = 0;
109 virtual bool RegisterIsVolatile(const RegisterInfo *reg_info) = 0;
112 GetFallbackRegisterLocation(const RegisterInfo *reg_info,
113 UnwindPlan::Row::RegisterLocation &unwind_regloc);
115 // Should take a look at a call frame address (CFA) which is just the stack
116 // pointer value upon entry to a function. ABIs usually impose alignment
117 // restrictions (4, 8 or 16 byte aligned), and zero is usually not allowed.
118 // This function should return true if "cfa" is valid call frame address for
119 // the ABI, and false otherwise. This is used by the generic stack frame
120 // unwinding code to help determine when a stack ends.
121 virtual bool CallFrameAddressIsValid(lldb::addr_t cfa) = 0;
123 // Validates a possible PC value and returns true if an opcode can be at
125 virtual bool CodeAddressIsValid(lldb::addr_t pc) = 0;
127 virtual lldb::addr_t FixCodeAddress(lldb::addr_t pc) {
128 // Some targets might use bits in a code address to indicate a mode switch.
129 // ARM uses bit zero to signify a code address is thumb, so any ARM ABI
130 // plug-ins would strip those bits.
134 virtual const RegisterInfo *GetRegisterInfoArray(uint32_t &count) = 0;
136 bool GetRegisterInfoByName(const ConstString &name, RegisterInfo &info);
138 bool GetRegisterInfoByKind(lldb::RegisterKind reg_kind, uint32_t reg_num,
141 virtual bool GetPointerReturnRegister(const char *&name) { return false; }
143 static lldb::ABISP FindPlugin(lldb::ProcessSP process_sp, const ArchSpec &arch);
146 //------------------------------------------------------------------
147 // Classes that inherit from ABI can see and modify these
148 //------------------------------------------------------------------
149 ABI(lldb::ProcessSP process_sp) {
150 if (process_sp.get())
151 m_process_wp = process_sp;
154 lldb::ProcessWP m_process_wp;
157 DISALLOW_COPY_AND_ASSIGN(ABI);
160 } // namespace lldb_private
162 #endif // liblldb_ABI_h_