LLDB mainline
ABI.h
Go to the documentation of this file.
1//===-- ABI.h ---------------------------------------------------*- C++ -*-===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_TARGET_ABI_H
10#define LLDB_TARGET_ABI_H
11
15#include "lldb/Utility/Status.h"
16#include "lldb/lldb-forward.h"
17#include "lldb/lldb-private.h"
18
19#include "llvm/ADT/ArrayRef.h"
20#include "llvm/MC/MCRegisterInfo.h"
21
22namespace llvm {
23class Type;
24}
25
26namespace lldb_private {
27
28class ABI : public PluginInterface {
29public:
30 struct CallArgument {
31 enum eType {
32 HostPointer = 0, /* pointer to host data */
33 TargetValue, /* value is on the target or literal */
34 };
35 eType type; /* value of eType */
36 size_t size; /* size in bytes of this argument */
37
38 lldb::addr_t value; /* literal value */
39 std::unique_ptr<uint8_t[]> data_up; /* host data pointer */
40 };
41
42 ~ABI() override;
43
44 virtual size_t GetRedZoneSize() const = 0;
45
47 lldb::addr_t functionAddress,
48 lldb::addr_t returnAddress,
49 llvm::ArrayRef<lldb::addr_t> args) const = 0;
50
51 // Prepare trivial call used from ThreadPlanFunctionCallUsingABI
52 // AD:
53 // . Because i don't want to change other ABI's this is not declared pure
54 // virtual.
55 // The dummy implementation will simply fail. Only HexagonABI will
56 // currently
57 // use this method.
58 // . Two PrepareTrivialCall's is not good design so perhaps this should be
59 // combined.
60 //
62 lldb::addr_t functionAddress,
63 lldb::addr_t returnAddress,
64 llvm::Type &prototype,
65 llvm::ArrayRef<CallArgument> args) const;
66
67 virtual bool GetArgumentValues(Thread &thread, ValueList &values) const = 0;
68
70 bool persistent = true) const;
71
72 // specialized to work with llvm IR types
73 lldb::ValueObjectSP GetReturnValueObject(Thread &thread, llvm::Type &type,
74 bool persistent = true) const;
75
76 // Set the Return value object in the current frame as though a function with
78 lldb::ValueObjectSP &new_value) = 0;
79
80protected:
81 // This is the method the ABI will call to actually calculate the return
82 // value. Don't put it in a persistent value object, that will be done by the
83 // ABI::GetReturnValueObject.
85 GetReturnValueObjectImpl(Thread &thread, CompilerType &ast_type) const = 0;
86
87 // specialized to work with llvm IR types
89 GetReturnValueObjectImpl(Thread &thread, llvm::Type &ir_type) const;
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 lldb::ProcessSP GetProcessSP() const { return m_process_wp.lock(); }
98
99public:
101
103
104 virtual bool RegisterIsVolatile(const RegisterInfo *reg_info) = 0;
105
106 virtual bool GetFallbackRegisterLocation(
107 const RegisterInfo *reg_info,
109
110 // Should take a look at a call frame address (CFA) which is just the stack
111 // pointer value upon entry to a function. ABIs usually impose alignment
112 // restrictions (4, 8 or 16 byte aligned), and zero is usually not allowed.
113 // This function should return true if "cfa" is valid call frame address for
114 // the ABI, and false otherwise. This is used by the generic stack frame
115 // unwinding code to help determine when a stack ends.
117
118 // Validates a possible PC value and returns true if an opcode can be at
119 // "pc".
121
122 /// Some targets might use bits in a code address to indicate a mode switch.
123 /// ARM uses bit zero to signify a code address is thumb, so any ARM ABI
124 /// plug-ins would strip those bits.
125 /// @{
128 /// @}
129
130 /// Use this method when you do not know, or do not care what kind of address
131 /// you are fixing. On platforms where there would be a difference between the
132 /// two types, it will pick the safest option.
133 ///
134 /// Its purpose is to signal that no specific choice was made and provide an
135 /// alternative to randomly picking FixCode/FixData address. Which could break
136 /// platforms where there is a difference (only Arm Thumb at this time).
138 // On Arm Thumb fixing a code address zeroes the bottom bit, so FixData is
139 // the safe choice. On any other platform (so far) code and data addresses
140 // are fixed in the same way.
141 return FixDataAddress(pc);
142 }
143
144 llvm::MCRegisterInfo &GetMCRegisterInfo() { return *m_mc_register_info_up; }
145
146 virtual void
147 AugmentRegisterInfo(std::vector<DynamicRegisterInfo::Register> &regs) = 0;
148
149 virtual bool GetPointerReturnRegister(const char *&name) { return false; }
150
151 virtual uint64_t GetStackFrameSize() { return 512 * 1024; }
152
153 static lldb::ABISP FindPlugin(lldb::ProcessSP process_sp, const ArchSpec &arch);
154
155protected:
156 ABI(lldb::ProcessSP process_sp, std::unique_ptr<llvm::MCRegisterInfo> info_up)
157 : m_process_wp(process_sp), m_mc_register_info_up(std::move(info_up)) {
158 assert(m_mc_register_info_up && "ABI must have MCRegisterInfo");
159 }
160
161 /// Utility function to construct a MCRegisterInfo using the ArchSpec triple.
162 /// Plugins wishing to customize the construction can construct the
163 /// MCRegisterInfo themselves.
164 static std::unique_ptr<llvm::MCRegisterInfo>
165 MakeMCRegisterInfo(const ArchSpec &arch);
166
168 std::unique_ptr<llvm::MCRegisterInfo> m_mc_register_info_up;
169
170private:
171 ABI(const ABI &) = delete;
172 const ABI &operator=(const ABI &) = delete;
173};
174
175class RegInfoBasedABI : public ABI {
176public:
178 std::vector<DynamicRegisterInfo::Register> &regs) override;
179
180protected:
181 using ABI::ABI;
182
183 bool GetRegisterInfoByName(llvm::StringRef name, RegisterInfo &info);
184
185 virtual const RegisterInfo *GetRegisterInfoArray(uint32_t &count) = 0;
186};
187
188class MCBasedABI : public ABI {
189public:
191 std::vector<DynamicRegisterInfo::Register> &regs) override;
192
193 /// If the register name is of the form "<from_prefix>[<number>]" then change
194 /// the name to "<to_prefix>[<number>]". Otherwise, leave the name unchanged.
195 static void MapRegisterName(std::string &reg, llvm::StringRef from_prefix,
196 llvm::StringRef to_prefix);
197
198protected:
199 using ABI::ABI;
200
201 /// Return eh_frame and dwarf numbers for the given register.
202 virtual std::pair<uint32_t, uint32_t> GetEHAndDWARFNums(llvm::StringRef reg);
203
204 /// Return the generic number of the given register.
205 virtual uint32_t GetGenericNum(llvm::StringRef reg) = 0;
206
207 /// For the given (capitalized) lldb register name, return the name of this
208 /// register in the MCRegisterInfo struct.
209 virtual std::string GetMCName(std::string reg) { return reg; }
210};
211
212} // namespace lldb_private
213
214#endif // LLDB_TARGET_ABI_H
virtual bool CodeAddressIsValid(lldb::addr_t pc)=0
virtual bool GetPointerReturnRegister(const char *&name)
Definition ABI.h:149
lldb::ProcessWP m_process_wp
Definition ABI.h:167
llvm::MCRegisterInfo & GetMCRegisterInfo()
Definition ABI.h:144
ABI(const ABI &)=delete
ABI(lldb::ProcessSP process_sp, std::unique_ptr< llvm::MCRegisterInfo > info_up)
Definition ABI.h:156
const ABI & operator=(const ABI &)=delete
virtual lldb::addr_t FixAnyAddress(lldb::addr_t pc)
Use this method when you do not know, or do not care what kind of address you are fixing.
Definition ABI.h:137
virtual lldb::UnwindPlanSP CreateDefaultUnwindPlan()=0
virtual bool CallFrameAddressIsValid(lldb::addr_t cfa)=0
virtual void AugmentRegisterInfo(std::vector< DynamicRegisterInfo::Register > &regs)=0
virtual bool GetFallbackRegisterLocation(const RegisterInfo *reg_info, UnwindPlan::Row::AbstractRegisterLocation &unwind_regloc)
Definition ABI.cpp:211
virtual lldb::ValueObjectSP GetReturnValueObjectImpl(Thread &thread, CompilerType &ast_type) const =0
static lldb::ABISP FindPlugin(lldb::ProcessSP process_sp, const ArchSpec &arch)
Definition ABI.cpp:27
virtual bool PrepareTrivialCall(lldb_private::Thread &thread, lldb::addr_t sp, lldb::addr_t functionAddress, lldb::addr_t returnAddress, llvm::ArrayRef< lldb::addr_t > args) const =0
virtual bool PrepareTrivialCall(lldb_private::Thread &thread, lldb::addr_t sp, lldb::addr_t functionAddress, lldb::addr_t returnAddress, llvm::Type &prototype, llvm::ArrayRef< CallArgument > args) const
virtual bool GetArgumentValues(Thread &thread, ValueList &values) const =0
lldb::ValueObjectSP GetReturnValueObject(Thread &thread, CompilerType &type, bool persistent=true) const
Definition ABI.cpp:70
static std::unique_ptr< llvm::MCRegisterInfo > MakeMCRegisterInfo(const ArchSpec &arch)
Utility function to construct a MCRegisterInfo using the ArchSpec triple.
Definition ABI.cpp:234
virtual lldb::UnwindPlanSP CreateFunctionEntryUnwindPlan()=0
virtual bool RegisterIsVolatile(const RegisterInfo *reg_info)=0
virtual size_t GetRedZoneSize() const =0
std::unique_ptr< llvm::MCRegisterInfo > m_mc_register_info_up
Definition ABI.h:168
virtual lldb::addr_t FixCodeAddress(lldb::addr_t pc)
Some targets might use bits in a code address to indicate a mode switch.
Definition ABI.cpp:150
lldb::ProcessSP GetProcessSP() const
Request to get a Process shared pointer.
Definition ABI.h:97
virtual lldb::addr_t FixDataAddress(lldb::addr_t pc)
Definition ABI.cpp:167
virtual uint64_t GetStackFrameSize()
Definition ABI.h:151
virtual Status SetReturnValueObject(lldb::StackFrameSP &frame_sp, lldb::ValueObjectSP &new_value)=0
An architecture specification class.
Definition ArchSpec.h:31
Generic representation of a type in a programming language.
virtual std::string GetMCName(std::string reg)
For the given (capitalized) lldb register name, return the name of this register in the MCRegisterInf...
Definition ABI.h:209
void AugmentRegisterInfo(std::vector< DynamicRegisterInfo::Register > &regs) override
Definition ABI.cpp:271
virtual uint32_t GetGenericNum(llvm::StringRef reg)=0
Return the generic number of the given register.
ABI(lldb::ProcessSP process_sp, std::unique_ptr< llvm::MCRegisterInfo > info_up)
Definition ABI.h:156
virtual std::pair< uint32_t, uint32_t > GetEHAndDWARFNums(llvm::StringRef reg)
Return eh_frame and dwarf numbers for the given register.
Definition ABI.cpp:287
static void MapRegisterName(std::string &reg, llvm::StringRef from_prefix, llvm::StringRef to_prefix)
If the register name is of the form "<from_prefix>[<number>]" then change the name to "<to_prefix>[<n...
Definition ABI.cpp:305
bool GetRegisterInfoByName(llvm::StringRef name, RegisterInfo &info)
Definition ABI.cpp:46
virtual const RegisterInfo * GetRegisterInfoArray(uint32_t &count)=0
ABI(lldb::ProcessSP process_sp, std::unique_ptr< llvm::MCRegisterInfo > info_up)
Definition ABI.h:156
void AugmentRegisterInfo(std::vector< DynamicRegisterInfo::Register > &regs) override
Definition ABI.cpp:251
An error handling class.
Definition Status.h:118
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::ABI > ABISP
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
std::shared_ptr< lldb_private::Process > ProcessSP
std::weak_ptr< lldb_private::Process > ProcessWP
std::shared_ptr< lldb_private::UnwindPlan > UnwindPlanSP
uint64_t addr_t
Definition lldb-types.h:80
std::unique_ptr< uint8_t[]> data_up
Definition ABI.h:39
Every register is described in detail including its name, alternate name (optional),...