LLVM: include/llvm/DebugInfo/DWARF/LowLevel/DWARFCFIProgram.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9#ifndef LLVM_DEBUGINFO_DWARF_LOWLEVEL_DWARFCFIPROGRAM_H
10#define LLVM_DEBUGINFO_DWARF_LOWLEVEL_DWARFCFIPROGRAM_H
11
20#include
21
22namespace llvm {
23
25
26
27
28
29
30
31
33public:
36
37
38
39
54
55 using InstrList = std::vector;
58
63
64 unsigned size() const { return (unsigned)Instructions.size(); }
65 bool empty() const { return Instructions.empty(); }
67 int64_t dataAlign() const { return DataAlignmentFactor; }
69
72 : CodeAlignmentFactor(CodeAlignmentFactor),
73 DataAlignmentFactor(DataAlignmentFactor), Arch(Arch) {}
74
75
76
77
78
79 template
82
83 const uint8_t DWARF_CFI_PRIMARY_OPCODE_MASK = 0xc0;
84 const uint8_t DWARF_CFI_PRIMARY_OPERAND_MASK = 0x3f;
85
87 while (C && C.tell() < EndOffset) {
88 uint8_t Opcode = Data.getRelocatedValue(C, 1);
89 if ()
90 break;
91
92
93 if (uint8_t Primary = Opcode & DWARF_CFI_PRIMARY_OPCODE_MASK) {
94
95
96 uint64_t Op1 = Opcode & DWARF_CFI_PRIMARY_OPERAND_MASK;
97 switch (Primary) {
98 case DW_CFA_advance_loc:
99 case DW_CFA_restore:
101 break;
102 case DW_CFA_offset:
104 break;
105 default:
107 }
108 continue;
109 }
110
111
112 switch (Opcode) {
113 default:
115 "invalid extended CFI opcode 0x%" PRIx8,
116 Opcode);
117 case DW_CFA_nop:
118 case DW_CFA_remember_state:
119 case DW_CFA_restore_state:
120 case DW_CFA_GNU_window_save:
121 case DW_CFA_AARCH64_negate_ra_state_with_pc:
122
124 break;
125 case DW_CFA_set_loc:
126
128 break;
129 case DW_CFA_advance_loc1:
130
132 break;
133 case DW_CFA_advance_loc2:
134
136 break;
137 case DW_CFA_advance_loc4:
138
140 break;
141 case DW_CFA_restore_extended:
142 case DW_CFA_undefined:
143 case DW_CFA_same_value:
144 case DW_CFA_def_cfa_register:
145 case DW_CFA_def_cfa_offset:
146 case DW_CFA_GNU_args_size:
147
149 break;
150 case DW_CFA_def_cfa_offset_sf:
151
153 break;
154 case DW_CFA_LLVM_def_aspace_cfa:
155 case DW_CFA_LLVM_def_aspace_cfa_sf: {
156 auto RegNum = Data.getULEB128(C);
157 auto CfaOffset = Opcode == DW_CFA_LLVM_def_aspace_cfa
162 break;
163 }
164 case DW_CFA_offset_extended:
165 case DW_CFA_register:
166 case DW_CFA_def_cfa:
167 case DW_CFA_val_offset: {
168
169
170
171
175 break;
176 }
177 case DW_CFA_offset_extended_sf:
178 case DW_CFA_def_cfa_sf:
179 case DW_CFA_val_offset_sf: {
180
181
185 break;
186 }
187 case DW_CFA_def_cfa_expression: {
191
193 Data.getAddressSize());
194
195
196
197 Instructions.back().Expression =
199 break;
200 }
201 case DW_CFA_expression:
202 case DW_CFA_val_expression: {
205
209 Data.getAddressSize());
210
211
212
213 Instructions.back().Expression =
215 break;
216 }
217 }
218 }
219
221 return C.takeError();
222 }
223
225
226
228
229
230
231
232
233
234
247
248
250
251
252
254
255
259
260
262 Instructions.push_back(Instruction(Opcode));
263 Instructions.back().Ops.push_back(Operand1);
264 }
265
266
268 Instructions.push_back(Instruction(Opcode));
269 Instructions.back().Ops.push_back(Operand1);
270 Instructions.back().Ops.push_back(Operand2);
271 }
272
273
276 Instructions.push_back(Instruction(Opcode));
277 Instructions.back().Ops.push_back(Operand1);
278 Instructions.back().Ops.push_back(Operand2);
279 Instructions.back().Ops.push_back(Operand3);
280 }
281
282private:
283 std::vector Instructions;
284 const uint64_t CodeAlignmentFactor;
285 const int64_t DataAlignmentFactor;
287};
288
289}
290
291}
292
293#endif
This file defines the SmallString class.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Lightweight error class with error context and mandatory checking.
Tagged union holding either a T or a Error.
Class representing an expression and its matching format.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
std::vector< Instruction > InstrList
Definition DWARFCFIProgram.h:55
const_iterator end() const
Definition DWARFCFIProgram.h:62
void addInstruction(uint8_t Opcode, uint64_t Operand1, uint64_t Operand2)
Add a new instruction that has two operands.
Definition DWARFCFIProgram.h:267
InstrList::const_iterator const_iterator
Definition DWARFCFIProgram.h:57
Triple::ArchType triple() const
Definition DWARFCFIProgram.h:68
InstrList::iterator iterator
Definition DWARFCFIProgram.h:56
OperandType
Types of operands to CFI instructions In DWARF, this type is implicitly tied to a CFI instruction opc...
Definition DWARFCFIProgram.h:235
@ OT_Expression
Definition DWARFCFIProgram.h:245
@ OT_FactoredCodeOffset
Definition DWARFCFIProgram.h:240
@ OT_AddressSpace
Definition DWARFCFIProgram.h:244
@ OT_None
Definition DWARFCFIProgram.h:237
@ OT_SignedFactDataOffset
Definition DWARFCFIProgram.h:241
@ OT_Unset
Definition DWARFCFIProgram.h:236
@ OT_Offset
Definition DWARFCFIProgram.h:239
@ OT_Register
Definition DWARFCFIProgram.h:243
@ OT_UnsignedFactDataOffset
Definition DWARFCFIProgram.h:242
@ OT_Address
Definition DWARFCFIProgram.h:238
void addInstruction(uint8_t Opcode, uint64_t Operand1, uint64_t Operand2, uint64_t Operand3)
Add a new instruction that has three operands.
Definition DWARFCFIProgram.h:274
uint64_t codeAlign() const
Definition DWARFCFIProgram.h:66
static constexpr size_t MaxOperands
Definition DWARFCFIProgram.h:34
Error parse(DWARFDataExtractorBase< T > &Data, uint64_t *Offset, uint64_t EndOffset)
Parse and store a sequence of CFI instructions from Data, starting at *Offset and ending at EndOffset...
Definition DWARFCFIProgram.h:80
static LLVM_ABI ArrayRef< OperandType[MaxOperands]> getOperandTypes()
Retrieve the array describing the types of operands according to the enum above.
SmallVector< uint64_t, MaxOperands > Operands
Definition DWARFCFIProgram.h:35
iterator end()
Definition DWARFCFIProgram.h:61
const_iterator begin() const
Definition DWARFCFIProgram.h:60
bool empty() const
Definition DWARFCFIProgram.h:65
iterator begin()
Definition DWARFCFIProgram.h:59
void addInstruction(const Instruction &I)
Definition DWARFCFIProgram.h:224
CFIProgram(uint64_t CodeAlignmentFactor, int64_t DataAlignmentFactor, Triple::ArchType Arch)
Definition DWARFCFIProgram.h:70
int64_t dataAlign() const
Definition DWARFCFIProgram.h:67
unsigned size() const
Definition DWARFCFIProgram.h:64
static LLVM_ABI const char * operandTypeString(OperandType OT)
Get the OperandType as a "const char *".
LLVM_ABI StringRef callFrameString(unsigned Opcode) const
Get a DWARF CFI call frame string for the given DW_CFA opcode.
void addInstruction(uint8_t Opcode, uint64_t Operand1)
Add a new single-operand instruction.
Definition DWARFCFIProgram.h:261
void addInstruction(uint8_t Opcode)
Convenience method to add a new instruction with the given opcode.
Definition DWARFCFIProgram.h:256
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
Calculates the starting offsets for various sections within the .debug_names section.
This is an optimization pass for GlobalISel generic memory operations.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
FunctionAddr VTableAddr uintptr_t uintptr_t Data
An instruction consists of a DWARF CFI opcode and an optional sequence of operands.
Definition DWARFCFIProgram.h:40
std::optional< DWARFExpression > Expression
Definition DWARFCFIProgram.h:46
LLVM_ABI Expected< uint64_t > getOperandAsUnsigned(const CFIProgram &CFIP, uint32_t OperandIdx) const
uint8_t Opcode
Definition DWARFCFIProgram.h:43
Operands Ops
Definition DWARFCFIProgram.h:44
Instruction(uint8_t Opcode)
Definition DWARFCFIProgram.h:41
LLVM_ABI Expected< int64_t > getOperandAsSigned(const CFIProgram &CFIP, uint32_t OperandIdx) const