]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Target/ABI.h
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Target / ABI.h
1 //===-- ABI.h ---------------------------------------------------*- C++ -*-===//
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
10 #ifndef liblldb_ABI_h_
11 #define liblldb_ABI_h_
12
13 #include "lldb/Core/PluginInterface.h"
14 #include "lldb/Symbol/UnwindPlan.h"
15 #include "lldb/Utility/Status.h"
16 #include "lldb/lldb-private.h"
17
18 #include "llvm/ADT/ArrayRef.h"
19
20 // forward define the llvm::Type class
21 namespace llvm {
22 class Type;
23 }
24
25 namespace lldb_private {
26
27 class ABI : public PluginInterface {
28 public:
29   struct CallArgument {
30     enum eType {
31       HostPointer = 0, /* pointer to host data */
32       TargetValue,     /* value is on the target or literal */
33     };
34     eType type;  /* value of eType */
35     size_t size; /* size in bytes of this argument */
36
37     lldb::addr_t value;                 /* literal value */
38     std::unique_ptr<uint8_t[]> data_ap; /* host data pointer */
39   };
40
41   ~ABI() override;
42
43   virtual size_t GetRedZoneSize() const = 0;
44
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;
49
50   // Prepare trivial call used from ThreadPlanFunctionCallUsingABI
51   // AD:
52   //  . Because i don't want to change other ABI's this is not declared pure
53   //  virtual.
54   //    The dummy implementation will simply fail.  Only HexagonABI will
55   //    currently
56   //    use this method.
57   //  . Two PrepareTrivialCall's is not good design so perhaps this should be
58   //  combined.
59   //
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;
65
66   virtual bool GetArgumentValues(Thread &thread, ValueList &values) const = 0;
67
68   lldb::ValueObjectSP GetReturnValueObject(Thread &thread, CompilerType &type,
69                                            bool persistent = true) const;
70
71   // specialized to work with llvm IR types
72   lldb::ValueObjectSP GetReturnValueObject(Thread &thread, llvm::Type &type,
73                                            bool persistent = true) const;
74
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;
78
79 protected:
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;
85
86   // specialized to work with llvm IR types
87   virtual lldb::ValueObjectSP
88   GetReturnValueObjectImpl(Thread &thread, llvm::Type &ir_type) const;
89
90   //------------------------------------------------------------------
91   /// Request to get a Process shared pointer.
92   ///
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
96   /// object inside it.
97   //------------------------------------------------------------------
98   lldb::ProcessSP GetProcessSP() const { return m_process_wp.lock(); }
99
100 public:
101   virtual bool CreateFunctionEntryUnwindPlan(UnwindPlan &unwind_plan) = 0;
102
103   virtual bool CreateDefaultUnwindPlan(UnwindPlan &unwind_plan) = 0;
104
105   virtual bool RegisterIsVolatile(const RegisterInfo *reg_info) = 0;
106
107   virtual bool
108   GetFallbackRegisterLocation(const RegisterInfo *reg_info,
109                               UnwindPlan::Row::RegisterLocation &unwind_regloc);
110
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;
118
119   // Validates a possible PC value and returns true if an opcode can be at
120   // "pc".
121   virtual bool CodeAddressIsValid(lldb::addr_t pc) = 0;
122
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.
127     return pc;
128   }
129
130   virtual const RegisterInfo *GetRegisterInfoArray(uint32_t &count) = 0;
131
132   bool GetRegisterInfoByName(const ConstString &name, RegisterInfo &info);
133
134   bool GetRegisterInfoByKind(lldb::RegisterKind reg_kind, uint32_t reg_num,
135                              RegisterInfo &info);
136
137   virtual bool GetPointerReturnRegister(const char *&name) { return false; }
138
139   static lldb::ABISP FindPlugin(lldb::ProcessSP process_sp, const ArchSpec &arch);
140
141 protected:
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;
148   }
149
150   lldb::ProcessWP m_process_wp;
151
152 private:
153   DISALLOW_COPY_AND_ASSIGN(ABI);
154 };
155
156 } // namespace lldb_private
157
158 #endif // liblldb_ABI_h_