GDB (xrefs)
/tmp/gdb-8.1/gdb/dwarf2-frame.h
Go to the documentation of this file.
1 /* Frame unwinder for frames with DWARF Call Frame Information.
2 
3  Copyright (C) 2003-2018 Free Software Foundation, Inc.
4 
5  Contributed by Mark Kettenis.
6 
7  This file is part of GDB.
8 
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.
13 
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.
18 
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/>. */
21 
22 #ifndef DWARF2_FRAME_H
23 #define DWARF2_FRAME_H 1
24 
25 struct gdbarch;
26 struct objfile;
27 struct frame_info;
28 struct dwarf2_per_cu_data;
29 struct agent_expr;
30 struct axs_value;
31 
32 /* Register rule. */
33 
35 {
36  /* Make certain that 0 maps onto the correct enum value; the
37  corresponding structure is being initialized using memset zero.
38  This indicates that CFI didn't provide any information at all
39  about a register, leaving how to obtain its value totally
40  unspecified. */
42 
43  /* The term "undefined" comes from the DWARF2 CFI spec which this
44  code is moddeling; it indicates that the register's value is
45  "undefined". GCC uses the less formal term "unsaved". Its
46  definition is a combination of REG_UNDEFINED and REG_UNSPECIFIED.
47  The failure to differentiate the two helps explain a few problems
48  with the CFI generated by GCC. */
54 
55  /* These are defined in Dwarf3. */
58 
59  /* These aren't defined by the DWARF2 CFI specification, but are
60  used internally by GDB. */
61  DWARF2_FRAME_REG_FN, /* Call a registered function. */
62  DWARF2_FRAME_REG_RA, /* Return Address. */
63  DWARF2_FRAME_REG_RA_OFFSET, /* Return Address with offset. */
64  DWARF2_FRAME_REG_CFA, /* Call Frame Address. */
65  DWARF2_FRAME_REG_CFA_OFFSET /* Call Frame Address with offset. */
66 };
67 
68 /* Register state. */
69 
71 {
72  /* Each register save state can be described in terms of a CFA slot,
73  another register, or a location expression. */
74  union {
77  struct
78  {
79  const gdb_byte *start;
81  } exp;
82  struct value *(*fn) (struct frame_info *this_frame, void **this_cache,
83  int regnum);
84  } loc;
86 };
87 
89 {
93 };
94 
96 {
97  dwarf2_frame_state_reg_info () = default;
99  {
100  delete prev;
101  xfree (reg);
102  }
103 
104  /* Copy constructor. */
106  : num_regs (src.num_regs), cfa_offset (src.cfa_offset),
107  cfa_reg (src.cfa_reg), cfa_how (src.cfa_how), cfa_exp (src.cfa_exp),
108  prev (src.prev)
109  {
110  size_t size = src.num_regs * sizeof (struct dwarf2_frame_state_reg);
111 
112  reg = (struct dwarf2_frame_state_reg *) xmalloc (size);
113  memcpy (reg, src.reg, size);
114  }
115 
116  /* Assignment operator for both move-assignment and copy-assignment. */
119  {
120  swap (*this, rhs);
121  return *this;
122  }
123 
124  /* Move constructor. */
126  : reg (rhs.reg), num_regs (rhs.num_regs), cfa_offset (rhs.cfa_offset),
127  cfa_reg (rhs.cfa_reg), cfa_how (rhs.cfa_how), cfa_exp (rhs.cfa_exp),
128  prev (rhs.prev)
129  {
130  rhs.prev = nullptr;
131  rhs.reg = nullptr;
132  }
133 
134 /* Assert that the register set RS is large enough to store gdbarch_num_regs
135  columns. If necessary, enlarge the register set. */
136  void alloc_regs (int num_regs_requested)
137  {
138  if (num_regs_requested <= num_regs)
139  return;
140 
141  size_t size = sizeof (struct dwarf2_frame_state_reg);
142 
143  reg = (struct dwarf2_frame_state_reg *)
144  xrealloc (reg, num_regs_requested * size);
145 
146  /* Initialize newly allocated registers. */
147  memset (reg + num_regs, 0, (num_regs_requested - num_regs) * size);
148  num_regs = num_regs_requested;
149  }
150 
151  struct dwarf2_frame_state_reg *reg = NULL;
152  int num_regs = 0;
153 
157  const gdb_byte *cfa_exp = NULL;
158 
159  /* Used to implement DW_CFA_remember_state. */
161 
162 private:
165  {
166  using std::swap;
167 
168  swap (lhs.reg, rhs.reg);
169  swap (lhs.num_regs, rhs.num_regs);
170  swap (lhs.cfa_offset, rhs.cfa_offset);
171  swap (lhs.cfa_reg, rhs.cfa_reg);
172  swap (lhs.cfa_how, rhs.cfa_how);
173  swap (lhs.cfa_exp, rhs.cfa_exp);
174  swap (lhs.prev, rhs.prev);
175  }
176 };
177 
178 struct dwarf2_cie;
179 
180 /* Structure describing a frame state. */
181 
183 {
184  dwarf2_frame_state (CORE_ADDR pc, struct dwarf2_cie *cie);
185 
186  /* Each register save state can be described in terms of a CFA slot,
187  another register, or a location expression. */
189 
190  /* The PC described by the current frame state. */
192 
193  /* Initial register set from the CIE.
194  Used to implement DW_CFA_restore. */
196 
197  /* The information we care about from the CIE. */
201 
202  /* Flags for known producer quirks. */
203 
204  /* The ARM compilers, in DWARF2 mode, assume that DW_CFA_def_cfa
205  and DW_CFA_def_cfa_offset takes a factored offset. */
206  bool armcc_cfa_offsets_sf = false;
207 
208  /* The ARM compilers, in DWARF2 or DWARF3 mode, may assume that
209  the CFA is defined as REG - OFFSET rather than REG + OFFSET. */
211 };
212 
213 /* Set the architecture-specific register state initialization
214  function for GDBARCH to INIT_REG. */
215 
216 extern void dwarf2_frame_set_init_reg (struct gdbarch *gdbarch,
217  void (*init_reg) (struct gdbarch *, int,
218  struct dwarf2_frame_state_reg *,
219  struct frame_info *));
220 
221 /* Set the architecture-specific signal trampoline recognition
222  function for GDBARCH to SIGNAL_FRAME_P. */
223 
224 extern void
226  int (*signal_frame_p) (struct gdbarch *,
227  struct frame_info *));
228 
229 /* Set the architecture-specific adjustment of .eh_frame and .debug_frame
230  register numbers. */
231 
232 extern void
234  int (*adjust_regnum) (struct gdbarch *,
235  int, int));
236 
237 /* Append the DWARF-2 frame unwinders to GDBARCH's list. */
238 
240 
241 /* Return the frame base methods for the function that contains PC, or
242  NULL if it can't be handled by the DWARF CFI frame unwinder. */
243 
244 extern const struct frame_base *
245  dwarf2_frame_base_sniffer (struct frame_info *this_frame);
246 
247 /* Compute the DWARF CFA for a frame. */
248 
249 CORE_ADDR dwarf2_frame_cfa (struct frame_info *this_frame);
250 
251 /* Find the CFA information for PC.
252 
253  Return 1 if a register is used for the CFA, or 0 if another
254  expression is used. Throw an exception on error.
255 
256  GDBARCH is the architecture to use.
257  DATA is the per-CU data.
258 
259  REGNUM_OUT is an out parameter that is set to the register number.
260  OFFSET_OUT is the offset to use from this register.
261  These are only filled in when 1 is returned.
262 
263  TEXT_OFFSET_OUT, CFA_START_OUT, and CFA_END_OUT describe the CFA
264  in other cases. These are only used when 0 is returned. */
265 
266 extern int dwarf2_fetch_cfa_info (struct gdbarch *gdbarch, CORE_ADDR pc,
267  struct dwarf2_per_cu_data *data,
268  int *regnum_out, LONGEST *offset_out,
269  CORE_ADDR *text_offset_out,
270  const gdb_byte **cfa_start_out,
271  const gdb_byte **cfa_end_out);
272 
273 #endif /* dwarf2-frame.h */
dwarf2_frame_state(CORE_ADDR pc, struct dwarf2_cie *cie)
Definition: dwarf2-frame.c:176
const LONGEST data_align
Definition: dwarf2-frame.h:198
bfd_vma CORE_ADDR
Definition: common-types.h:41
void xfree(void *)
void dwarf2_frame_set_signal_frame_p(struct gdbarch *gdbarch, int(*signal_frame_p)(struct gdbarch *, struct frame_info *))
Definition: dwarf2-frame.c:771
dwarf2_frame_reg_rule
Definition: dwarf2-frame.h:34
const ULONGEST retaddr_column
Definition: dwarf2-frame.h:200
void * memset(T *s, int c, size_t n)=delete
union dwarf2_frame_state_reg::@36 loc
Definition: ax.h:83
const gdb_byte * start
Definition: dwarf2-frame.h:79
const ULONGEST code_align
Definition: dwarf2-frame.h:199
void alloc_regs(int num_regs_requested)
Definition: dwarf2-frame.h:136
void dwarf2_frame_set_adjust_regnum(struct gdbarch *gdbarch, int(*adjust_regnum)(struct gdbarch *, int, int))
Definition: dwarf2-frame.c:800
CORE_ADDR dwarf2_frame_cfa(struct frame_info *this_frame)
dwarf2_frame_state_reg_info(dwarf2_frame_state_reg_info &&rhs) noexcept
Definition: dwarf2-frame.h:125
struct dwarf2_frame_state_reg::@36::@37 exp
enum cfa_how_kind cfa_how
Definition: dwarf2-frame.h:156
dwarf2_frame_state_reg_info & operator=(dwarf2_frame_state_reg_info rhs)
Definition: dwarf2-frame.h:118
int dwarf2_fetch_cfa_info(struct gdbarch *gdbarch, CORE_ADDR pc, struct dwarf2_per_cu_data *data, int *regnum_out, LONGEST *offset_out, CORE_ADDR *text_offset_out, const gdb_byte **cfa_start_out, const gdb_byte **cfa_end_out)
Definition: dwarf2-frame.c:862
void dwarf2_append_unwinders(struct gdbarch *gdbarch)
const gdb_byte * cfa_exp
Definition: dwarf2-frame.h:157
int regnum
Definition: aarch64-tdep.c:77
void * xmalloc(YYSIZE_T)
const struct frame_base * dwarf2_frame_base_sniffer(struct frame_info *this_frame)
Definition: regdef.h:22
Definition: value.c:169
PTR xrealloc(PTR ptr, size_t size)
Definition: common-utils.c:52
bfd_byte gdb_byte
Definition: common-types.h:38
dwarf2_frame_state_reg_info(const dwarf2_frame_state_reg_info &src)
Definition: dwarf2-frame.h:105
bool armcc_cfa_offsets_reversed
Definition: dwarf2-frame.h:210
cfa_how_kind
Definition: dwarf2-frame.h:88
friend void swap(dwarf2_frame_state_reg_info &lhs, dwarf2_frame_state_reg_info &rhs)
Definition: dwarf2-frame.h:163
void dwarf2_frame_set_init_reg(struct gdbarch *gdbarch, void(*init_reg)(struct gdbarch *, int, struct dwarf2_frame_state_reg *, struct frame_info *))
Definition: dwarf2-frame.c:743
unsigned long long ULONGEST
Definition: common-types.h:53
struct dwarf2_frame_state_reg * reg
Definition: dwarf2-frame.h:151
enum dwarf2_frame_reg_rule how
Definition: dwarf2-frame.h:85
size_t size
Definition: go32-nat.c:242
long long LONGEST
Definition: common-types.h:52
struct dwarf2_frame_state_reg_info * prev
Definition: dwarf2-frame.h:160