]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Target/ABI.h
Merge clang 7.0.1 and several follow-up changes
[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 // C Includes
14 // C++ Includes
15 // Other libraries and framework includes
16 // Project 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"
21
22 #include "llvm/ADT/ArrayRef.h"
23
24 // forward define the llvm::Type class
25 namespace llvm {
26 class Type;
27 }
28
29 namespace lldb_private {
30
31 class ABI : public PluginInterface {
32 public:
33   struct CallArgument {
34     enum eType {
35       HostPointer = 0, /* pointer to host data */
36       TargetValue,     /* value is on the target or literal */
37     };
38     eType type;  /* value of eType */
39     size_t size; /* size in bytes of this argument */
40
41     lldb::addr_t value;                 /* literal value */
42     std::unique_ptr<uint8_t[]> data_ap; /* host data pointer */
43   };
44
45   ~ABI() override;
46
47   virtual size_t GetRedZoneSize() const = 0;
48
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;
53
54   // Prepare trivial call used from ThreadPlanFunctionCallUsingABI
55   // AD:
56   //  . Because i don't want to change other ABI's this is not declared pure
57   //  virtual.
58   //    The dummy implementation will simply fail.  Only HexagonABI will
59   //    currently
60   //    use this method.
61   //  . Two PrepareTrivialCall's is not good design so perhaps this should be
62   //  combined.
63   //
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;
69
70   virtual bool GetArgumentValues(Thread &thread, ValueList &values) const = 0;
71
72   lldb::ValueObjectSP GetReturnValueObject(Thread &thread, CompilerType &type,
73                                            bool persistent = true) const;
74
75   // specialized to work with llvm IR types
76   lldb::ValueObjectSP GetReturnValueObject(Thread &thread, llvm::Type &type,
77                                            bool persistent = true) const;
78
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;
82
83 protected:
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;
89
90   // specialized to work with llvm IR types
91   virtual lldb::ValueObjectSP
92   GetReturnValueObjectImpl(Thread &thread, llvm::Type &ir_type) const;
93
94   //------------------------------------------------------------------
95   /// Request to get a Process shared pointer.
96   ///
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(); }
103
104 public:
105   virtual bool CreateFunctionEntryUnwindPlan(UnwindPlan &unwind_plan) = 0;
106
107   virtual bool CreateDefaultUnwindPlan(UnwindPlan &unwind_plan) = 0;
108
109   virtual bool RegisterIsVolatile(const RegisterInfo *reg_info) = 0;
110
111   virtual bool
112   GetFallbackRegisterLocation(const RegisterInfo *reg_info,
113                               UnwindPlan::Row::RegisterLocation &unwind_regloc);
114
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;
122
123   // Validates a possible PC value and returns true if an opcode can be at
124   // "pc".
125   virtual bool CodeAddressIsValid(lldb::addr_t pc) = 0;
126
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.
131     return pc;
132   }
133
134   virtual const RegisterInfo *GetRegisterInfoArray(uint32_t &count) = 0;
135
136   bool GetRegisterInfoByName(const ConstString &name, RegisterInfo &info);
137
138   bool GetRegisterInfoByKind(lldb::RegisterKind reg_kind, uint32_t reg_num,
139                              RegisterInfo &info);
140
141   virtual bool GetPointerReturnRegister(const char *&name) { return false; }
142
143   static lldb::ABISP FindPlugin(lldb::ProcessSP process_sp, const ArchSpec &arch);
144
145 protected:
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;
152   }
153
154   lldb::ProcessWP m_process_wp;
155
156 private:
157   DISALLOW_COPY_AND_ASSIGN(ABI);
158 };
159
160 } // namespace lldb_private
161
162 #endif // liblldb_ABI_h_