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_
13 #include "lldb/Core/PluginInterface.h"
14 #include "lldb/Symbol/UnwindPlan.h"
15 #include "lldb/Utility/Status.h"
16 #include "lldb/lldb-private.h"
18 #include "llvm/ADT/ArrayRef.h"
20 // forward define the llvm::Type class
25 namespace lldb_private {
27 class ABI : public PluginInterface {
31 HostPointer = 0, /* pointer to host data */
32 TargetValue, /* value is on the target or literal */
34 eType type; /* value of eType */
35 size_t size; /* size in bytes of this argument */
37 lldb::addr_t value; /* literal value */
38 std::unique_ptr<uint8_t[]> data_ap; /* host data pointer */
43 virtual size_t GetRedZoneSize() const = 0;
45 virtual bool PrepareTrivialCall(lldb_private::Thread &thread, lldb::addr_t sp,
46 lldb::addr_t functionAddress,
47 lldb::addr_t returnAddress,
48 llvm::ArrayRef<lldb::addr_t> args) const = 0;
50 // Prepare trivial call used from ThreadPlanFunctionCallUsingABI
52 // . Because i don't want to change other ABI's this is not declared pure
54 // The dummy implementation will simply fail. Only HexagonABI will
57 // . Two PrepareTrivialCall's is not good design so perhaps this should be
60 virtual bool PrepareTrivialCall(lldb_private::Thread &thread, lldb::addr_t sp,
61 lldb::addr_t functionAddress,
62 lldb::addr_t returnAddress,
63 llvm::Type &prototype,
64 llvm::ArrayRef<CallArgument> args) const;
66 virtual bool GetArgumentValues(Thread &thread, ValueList &values) const = 0;
68 lldb::ValueObjectSP GetReturnValueObject(Thread &thread, CompilerType &type,
69 bool persistent = true) const;
71 // specialized to work with llvm IR types
72 lldb::ValueObjectSP GetReturnValueObject(Thread &thread, llvm::Type &type,
73 bool persistent = true) const;
75 // Set the Return value object in the current frame as though a function with
76 virtual Status SetReturnValueObject(lldb::StackFrameSP &frame_sp,
77 lldb::ValueObjectSP &new_value) = 0;
80 // This is the method the ABI will call to actually calculate the return
81 // value. Don't put it in a persistent value object, that will be done by the
82 // ABI::GetReturnValueObject.
83 virtual lldb::ValueObjectSP
84 GetReturnValueObjectImpl(Thread &thread, CompilerType &ast_type) const = 0;
86 // specialized to work with llvm IR types
87 virtual lldb::ValueObjectSP
88 GetReturnValueObjectImpl(Thread &thread, llvm::Type &ir_type) const;
90 //------------------------------------------------------------------
91 /// Request to get a Process shared pointer.
93 /// This ABI object may not have been created with a Process object,
94 /// or the Process object may no longer be alive. Be sure to handle
95 /// the case where the shared pointer returned does not have an
97 //------------------------------------------------------------------
98 lldb::ProcessSP GetProcessSP() const { return m_process_wp.lock(); }
101 virtual bool CreateFunctionEntryUnwindPlan(UnwindPlan &unwind_plan) = 0;
103 virtual bool CreateDefaultUnwindPlan(UnwindPlan &unwind_plan) = 0;
105 virtual bool RegisterIsVolatile(const RegisterInfo *reg_info) = 0;
108 GetFallbackRegisterLocation(const RegisterInfo *reg_info,
109 UnwindPlan::Row::RegisterLocation &unwind_regloc);
111 // Should take a look at a call frame address (CFA) which is just the stack
112 // pointer value upon entry to a function. ABIs usually impose alignment
113 // restrictions (4, 8 or 16 byte aligned), and zero is usually not allowed.
114 // This function should return true if "cfa" is valid call frame address for
115 // the ABI, and false otherwise. This is used by the generic stack frame
116 // unwinding code to help determine when a stack ends.
117 virtual bool CallFrameAddressIsValid(lldb::addr_t cfa) = 0;
119 // Validates a possible PC value and returns true if an opcode can be at
121 virtual bool CodeAddressIsValid(lldb::addr_t pc) = 0;
123 virtual lldb::addr_t FixCodeAddress(lldb::addr_t pc) {
124 // Some targets might use bits in a code address to indicate a mode switch.
125 // ARM uses bit zero to signify a code address is thumb, so any ARM ABI
126 // plug-ins would strip those bits.
130 virtual const RegisterInfo *GetRegisterInfoArray(uint32_t &count) = 0;
132 bool GetRegisterInfoByName(const ConstString &name, RegisterInfo &info);
134 bool GetRegisterInfoByKind(lldb::RegisterKind reg_kind, uint32_t reg_num,
137 virtual bool GetPointerReturnRegister(const char *&name) { return false; }
139 static lldb::ABISP FindPlugin(lldb::ProcessSP process_sp, const ArchSpec &arch);
142 //------------------------------------------------------------------
143 // Classes that inherit from ABI can see and modify these
144 //------------------------------------------------------------------
145 ABI(lldb::ProcessSP process_sp) {
146 if (process_sp.get())
147 m_process_wp = process_sp;
150 lldb::ProcessWP m_process_wp;
153 DISALLOW_COPY_AND_ASSIGN(ABI);
156 } // namespace lldb_private
158 #endif // liblldb_ABI_h_