LLDB mainline
Architecture.h
Go to the documentation of this file.
1//===-- Architecture.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_CORE_ARCHITECTURE_H
10#define LLDB_CORE_ARCHITECTURE_H
11
16
17namespace lldb_private {
18
20public:
21 /// This is currently intended to handle cases where a
22 /// program stops at an instruction that won't get executed and it
23 /// allows the stop reason, like "breakpoint hit", to be replaced
24 /// with a different stop reason like "no stop reason".
25 ///
26 /// This is specifically used for ARM in Thumb code when we stop in
27 /// an IT instruction (if/then/else) where the instruction won't get
28 /// executed and therefore it wouldn't be correct to show the program
29 /// stopped at the current PC. The code is generic and applies to all
30 /// ARM CPUs.
31 virtual void OverrideStopInfo(Thread &thread) const = 0;
32
33 /// This method is used to get the number of bytes that should be
34 /// skipped, from function start address, to reach the first
35 /// instruction after the prologue. If overrode, it must return
36 /// non-zero only if the current address matches one of the known
37 /// function entry points.
38 ///
39 /// This method is called only if the standard platform-independent
40 /// code fails to get the number of bytes to skip, giving the plugin
41 /// a chance to try to find the missing info.
42 ///
43 /// This is specifically used for PPC64, where functions may have
44 /// more than one entry point, global and local, so both should
45 /// be compared with current address, in order to find out the
46 /// number of bytes that should be skipped, in case we are stopped
47 /// at either function entry point.
48 virtual size_t GetBytesToSkip(Symbol &func, const Address &curr_addr) const {
49 return 0;
50 }
51
52 /// Adjust function breakpoint address, if needed. In some cases,
53 /// the function start address is not the right place to set the
54 /// breakpoint, specially in functions with multiple entry points.
55 ///
56 /// This is specifically used for PPC64, for functions that have
57 /// both a global and a local entry point. In this case, the
58 /// breakpoint is adjusted to the first function address reached
59 /// by both entry points.
60 virtual void AdjustBreakpointAddress(const Symbol &func,
61 Address &addr) const {}
62
63 /// If \a addr falls within the non-executable header at a function's start,
64 /// return the address of the first instruction past the header. Otherwise
65 /// return \a addr unchanged.
66 ///
67 /// Some formats begin a function with bytes that are part of the function but
68 /// are not executable instructions, so an address at the raw function start
69 /// cannot hold a breakpoint and cannot be disassembled. This is specifically
70 /// used for WebAssembly, where a function begins with a local variable
71 /// declaration header.
72 virtual Address SkipFunctionHeader(Address addr) const { return addr; }
73
74 /// Get \a load_addr as a callable code load address for this target
75 ///
76 /// Take \a load_addr and potentially add any address bits that are
77 /// needed to make the address callable. For ARM this can set bit
78 /// zero (if it already isn't) if \a load_addr is a thumb function.
79 /// If \a addr_class is set to AddressClass::eInvalid, then the address
80 /// adjustment will always happen. If it is set to an address class
81 /// that doesn't have code in it, LLDB_INVALID_ADDRESS will be
82 /// returned.
84 lldb::addr_t addr, AddressClass addr_class = AddressClass::eInvalid) const {
85 return addr;
86 }
87
88 /// Get \a load_addr as an opcode for this target.
89 ///
90 /// Take \a load_addr and potentially strip any address bits that are
91 /// needed to make the address point to an opcode. For ARM this can
92 /// clear bit zero (if it already isn't) if \a load_addr is a
93 /// thumb function and load_addr is in code.
94 /// If \a addr_class is set to AddressClass::eInvalid, then the address
95 /// adjustment will always happen. If it is set to an address class
96 /// that doesn't have code in it, LLDB_INVALID_ADDRESS will be
97 /// returned.
98
100 lldb::addr_t addr, AddressClass addr_class = AddressClass::eInvalid) const {
101 return addr;
102 }
103
104 // Get load_addr as breakable load address for this target. Take a addr and
105 // check if for any reason there is a better address than this to put a
106 // breakpoint on. If there is then return that address. For MIPS, if
107 // instruction at addr is a delay slot instruction then this method will find
108 // the address of its previous instruction and return that address.
110 Target &target) const {
111 return addr;
112 }
113
114 // Returns a pointer to an object that can manage memory tags for this
115 // Architecture E.g. masking out tags, unpacking tag streams etc. Returns
116 // nullptr if the architecture does not have a memory tagging extension.
117 //
118 // The return pointer being valid does not mean that the current process has
119 // memory tagging enabled, just that a tagging technology exists for this
120 // architecture.
121 virtual const MemoryTagManager *GetMemoryTagManager() const {
122 return nullptr;
123 }
124
125 // This returns true if a write to the named register should cause lldb to
126 // reconfigure its register information. For example on AArch64 writing to vg
127 // to change the vector length means lldb has to change the size of registers.
128 virtual bool
129 RegisterWriteCausesReconfigure(const llvm::StringRef name) const {
130 return false;
131 }
132
133 // Call this after writing a register for which RegisterWriteCausesReconfigure
134 // returns true. This method will update the layout of registers according to
135 // the new state e.g. the new length of scalable vector registers.
136 // Returns true if anything changed, which means existing register values must
137 // be invalidated.
139 DataExtractor &reg_data,
140 RegisterContext &reg_context) const {
141 return false;
142 }
143
144 /// Return an UnwindPlan that allows architecture-defined rules for finding
145 /// saved registers, given a particular set of register values.
148 std::shared_ptr<const UnwindPlan> current_unwindplan) {
149 return lldb::UnwindPlanSP();
150 }
151
152 /// Returns whether a given byte sequence is a valid trap instruction for the
153 /// architecture. Some architectures feature instructions that have immediates
154 /// that can take on any value, resulting in a family of valid byte sequences.
155 /// If the observed byte sequence is shorter than the reference then they are
156 /// considered not to match, even if the initial bytes would match.
157 virtual bool IsValidTrapInstruction(llvm::ArrayRef<uint8_t> reference,
158 llvm::ArrayRef<uint8_t> observed) const {
159 if (reference.size() > observed.size())
160 return false;
161 return !std::memcmp(reference.data(), observed.data(), reference.size());
162 }
163};
164
165} // namespace lldb_private
166
167#endif // LLDB_CORE_ARCHITECTURE_H
A section + offset based address class.
Definition Address.h:62
virtual void AdjustBreakpointAddress(const Symbol &func, Address &addr) const
Adjust function breakpoint address, if needed.
virtual lldb::addr_t GetCallableLoadAddress(lldb::addr_t addr, AddressClass addr_class=AddressClass::eInvalid) const
Get load_addr as a callable code load address for this target.
virtual bool ReconfigureRegisterInfo(DynamicRegisterInfo &reg_info, DataExtractor &reg_data, RegisterContext &reg_context) const
virtual lldb::addr_t GetOpcodeLoadAddress(lldb::addr_t addr, AddressClass addr_class=AddressClass::eInvalid) const
Get load_addr as an opcode for this target.
virtual const MemoryTagManager * GetMemoryTagManager() const
virtual lldb::UnwindPlanSP GetArchitectureUnwindPlan(lldb_private::Thread &thread, lldb_private::RegisterContextUnwind *regctx, std::shared_ptr< const UnwindPlan > current_unwindplan)
Return an UnwindPlan that allows architecture-defined rules for finding saved registers,...
virtual bool RegisterWriteCausesReconfigure(const llvm::StringRef name) const
virtual Address SkipFunctionHeader(Address addr) const
If addr falls within the non-executable header at a function's start, return the address of the first...
virtual size_t GetBytesToSkip(Symbol &func, const Address &curr_addr) const
This method is used to get the number of bytes that should be skipped, from function start address,...
virtual void OverrideStopInfo(Thread &thread) const =0
This is currently intended to handle cases where a program stops at an instruction that won't get exe...
virtual lldb::addr_t GetBreakableLoadAddress(lldb::addr_t addr, Target &target) const
virtual bool IsValidTrapInstruction(llvm::ArrayRef< uint8_t > reference, llvm::ArrayRef< uint8_t > observed) const
Returns whether a given byte sequence is a valid trap instruction for the architecture.
An data extractor class.
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::UnwindPlan > UnwindPlanSP
uint64_t addr_t
Definition lldb-types.h:80