1 /* Frame unwinder for frames with DWARF Call Frame Information.
3 Copyright (C) 2003-2024 Free Software Foundation, Inc.
5 Contributed by Mark Kettenis.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #ifndef GDB_DWARF2_FRAME_H
23 #define GDB_DWARF2_FRAME_H
27 struct dwarf2_per_cu_data
;
33 enum dwarf2_frame_reg_rule
35 /* Make certain that 0 maps onto the correct enum value; the
36 corresponding structure is being initialized using memset zero.
37 This indicates that CFI didn't provide any information at all
38 about a register, leaving how to obtain its value totally
40 DWARF2_FRAME_REG_UNSPECIFIED
= 0,
42 /* The term "undefined" comes from the DWARF2 CFI spec which this
43 code is modeling; it indicates that the register's value is
44 "undefined". GCC uses the less formal term "unsaved". Its
45 definition is a combination of REG_UNDEFINED and REG_UNSPECIFIED.
46 The failure to differentiate the two helps explain a few problems
47 with the CFI generated by GCC. */
48 DWARF2_FRAME_REG_UNDEFINED
,
49 DWARF2_FRAME_REG_SAVED_OFFSET
,
50 DWARF2_FRAME_REG_SAVED_REG
,
51 DWARF2_FRAME_REG_SAVED_EXP
,
52 DWARF2_FRAME_REG_SAME_VALUE
,
54 /* These are defined in Dwarf3. */
55 DWARF2_FRAME_REG_SAVED_VAL_OFFSET
,
56 DWARF2_FRAME_REG_SAVED_VAL_EXP
,
58 /* These aren't defined by the DWARF2 CFI specification, but are
59 used internally by GDB. */
60 DWARF2_FRAME_REG_FN
, /* Call a registered function. */
61 DWARF2_FRAME_REG_RA
, /* Return Address. */
62 DWARF2_FRAME_REG_RA_OFFSET
, /* Return Address with offset. */
63 DWARF2_FRAME_REG_CFA
, /* Call Frame Address. */
64 DWARF2_FRAME_REG_CFA_OFFSET
/* Call Frame Address with offset. */
69 typedef struct value
*(*fn_prev_register
) (const frame_info_ptr
&this_frame
,
70 void **this_cache
, int regnum
);
72 struct dwarf2_frame_state_reg
74 /* Each register save state can be described in terms of a CFA slot,
75 another register, or a location expression. */
81 const gdb_byte
*start
;
86 enum dwarf2_frame_reg_rule how
;
96 struct dwarf2_frame_state_reg_info
98 dwarf2_frame_state_reg_info () = default;
99 ~dwarf2_frame_state_reg_info ()
104 /* Copy constructor. */
105 dwarf2_frame_state_reg_info (const dwarf2_frame_state_reg_info
&src
)
106 : reg (src
.reg
), cfa_offset (src
.cfa_offset
),
107 cfa_reg (src
.cfa_reg
), cfa_how (src
.cfa_how
), cfa_exp (src
.cfa_exp
),
112 /* Assignment operator for both move-assignment and copy-assignment. */
113 dwarf2_frame_state_reg_info
&
114 operator= (dwarf2_frame_state_reg_info rhs
)
120 /* Move constructor. */
121 dwarf2_frame_state_reg_info (dwarf2_frame_state_reg_info
&&rhs
) noexcept
122 : reg (std::move (rhs
.reg
)), cfa_offset (rhs
.cfa_offset
),
123 cfa_reg (rhs
.cfa_reg
), cfa_how (rhs
.cfa_how
), cfa_exp (rhs
.cfa_exp
),
129 /* If necessary, enlarge the register set to hold NUM_REGS_REQUESTED
131 void alloc_regs (int num_regs_requested
)
133 gdb_assert (num_regs_requested
> 0);
135 if (num_regs_requested
<= reg
.size ())
138 reg
.resize (num_regs_requested
);
141 std::vector
<struct dwarf2_frame_state_reg
> reg
;
143 LONGEST cfa_offset
= 0;
144 ULONGEST cfa_reg
= 0;
145 enum cfa_how_kind cfa_how
= CFA_UNSET
;
146 const gdb_byte
*cfa_exp
= NULL
;
148 /* Used to implement DW_CFA_remember_state. */
149 struct dwarf2_frame_state_reg_info
*prev
= NULL
;
152 friend void swap (dwarf2_frame_state_reg_info
& lhs
,
153 dwarf2_frame_state_reg_info
& rhs
)
157 swap (lhs
.reg
, rhs
.reg
);
158 swap (lhs
.cfa_offset
, rhs
.cfa_offset
);
159 swap (lhs
.cfa_reg
, rhs
.cfa_reg
);
160 swap (lhs
.cfa_how
, rhs
.cfa_how
);
161 swap (lhs
.cfa_exp
, rhs
.cfa_exp
);
162 swap (lhs
.prev
, rhs
.prev
);
168 /* Structure describing a frame state. */
170 struct dwarf2_frame_state
172 dwarf2_frame_state (CORE_ADDR pc
, struct dwarf2_cie
*cie
);
174 /* Each register save state can be described in terms of a CFA slot,
175 another register, or a location expression. */
176 struct dwarf2_frame_state_reg_info regs
{};
178 /* The PC described by the current frame state. */
181 /* Initial register set from the CIE.
182 Used to implement DW_CFA_restore. */
183 struct dwarf2_frame_state_reg_info initial
{};
185 /* The information we care about from the CIE. */
186 const LONGEST data_align
;
187 const ULONGEST code_align
;
188 const ULONGEST retaddr_column
;
190 /* Flags for known producer quirks. */
192 /* The ARM compilers, in DWARF2 mode, assume that DW_CFA_def_cfa
193 and DW_CFA_def_cfa_offset takes a factored offset. */
194 bool armcc_cfa_offsets_sf
= false;
196 /* The ARM compilers, in DWARF2 or DWARF3 mode, may assume that
197 the CFA is defined as REG - OFFSET rather than REG + OFFSET. */
198 bool armcc_cfa_offsets_reversed
= false;
201 /* Set the architecture-specific register state initialization
202 function for GDBARCH to INIT_REG. */
204 extern void dwarf2_frame_set_init_reg (
205 gdbarch
*gdbarch
, void (*init_reg
) (struct gdbarch
*, int,
206 dwarf2_frame_state_reg
*,
207 const frame_info_ptr
&));
209 /* Set the architecture-specific signal trampoline recognition
210 function for GDBARCH to SIGNAL_FRAME_P. */
212 extern void dwarf2_frame_set_signal_frame_p
213 (gdbarch
*gdbarch
, int (*signal_frame_p
) (struct gdbarch
*,
214 const frame_info_ptr
&));
216 /* Set the architecture-specific adjustment of .eh_frame and .debug_frame
220 dwarf2_frame_set_adjust_regnum (struct gdbarch
*gdbarch
,
221 int (*adjust_regnum
) (struct gdbarch
*,
224 /* Append the DWARF-2 frame unwinders to GDBARCH's list. */
226 void dwarf2_append_unwinders (struct gdbarch
*gdbarch
);
228 /* Return the frame base methods for the function that contains PC, or
229 NULL if it can't be handled by the DWARF CFI frame unwinder. */
231 extern const struct frame_base
*
232 dwarf2_frame_base_sniffer (const frame_info_ptr
&this_frame
);
234 /* Compute the DWARF CFA for a frame. */
236 CORE_ADDR
dwarf2_frame_cfa (const frame_info_ptr
&this_frame
);
238 /* Find the CFA information for PC.
240 Return 1 if a register is used for the CFA, or 0 if another
241 expression is used. Throw an exception on error.
243 GDBARCH is the architecture to use.
244 DATA is the per-CU data.
246 REGNUM_OUT is an out parameter that is set to the register number.
247 OFFSET_OUT is the offset to use from this register.
248 These are only filled in when 1 is returned.
250 TEXT_OFFSET_OUT, CFA_START_OUT, and CFA_END_OUT describe the CFA
251 in other cases. These are only used when 0 is returned. */
253 extern int dwarf2_fetch_cfa_info (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
254 struct dwarf2_per_cu_data
*data
,
255 int *regnum_out
, LONGEST
*offset_out
,
256 CORE_ADDR
*text_offset_out
,
257 const gdb_byte
**cfa_start_out
,
258 const gdb_byte
**cfa_end_out
);
261 /* Allocate a new instance of the function unique data.
263 The main purpose of this custom function data object is to allow caching the
264 value of expensive lookups in the prev_register implementation.
266 THIS_FRAME is the frame that the custom data object should be associated
268 THIS_CACHE is the dwarf2 cache object to store the pointer on.
269 COOKIE is the key for the prev_function implementation.
270 SIZE is the size of the custom data object to allocate. */
272 extern void *dwarf2_frame_allocate_fn_data (const frame_info_ptr
&this_frame
,
274 fn_prev_register cookie
,
277 /* Retrieve the function unique data for this frame or NULL if none exists.
279 The main purpose of this custom function data object is to allow caching the
280 value of expensive lookups in the prev_register implementation.
282 THIS_FRAME is the frame that the custom data object should be associated
284 THIS_CACHE is the dwarf2 cache object to store the pointer on.
285 COOKIE is the key for the prev_function implementation. */
287 extern void *dwarf2_frame_get_fn_data (const frame_info_ptr
&this_frame
,
289 fn_prev_register cookie
);
291 #endif /* GDB_DWARF2_FRAME_H */