Commit | Line | Data |
---|---|---|
cfc14b3a MK |
1 | /* Frame unwinder for frames with DWARF Call Frame Information. |
2 | ||
9b254dd1 | 3 | Copyright (C) 2003, 2004, 2005, 2007, 2008 Free Software Foundation, Inc. |
cfc14b3a MK |
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 | |
a9762ec7 | 11 | the Free Software Foundation; either version 3 of the License, or |
cfc14b3a MK |
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 | |
a9762ec7 | 20 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
cfc14b3a MK |
21 | |
22 | #include "defs.h" | |
23 | #include "dwarf2expr.h" | |
24 | #include "elf/dwarf2.h" | |
25 | #include "frame.h" | |
26 | #include "frame-base.h" | |
27 | #include "frame-unwind.h" | |
28 | #include "gdbcore.h" | |
29 | #include "gdbtypes.h" | |
30 | #include "symtab.h" | |
31 | #include "objfiles.h" | |
32 | #include "regcache.h" | |
f2da6b3a | 33 | #include "value.h" |
cfc14b3a MK |
34 | |
35 | #include "gdb_assert.h" | |
36 | #include "gdb_string.h" | |
37 | ||
6896c0c7 | 38 | #include "complaints.h" |
cfc14b3a MK |
39 | #include "dwarf2-frame.h" |
40 | ||
ae0d2f24 UW |
41 | struct comp_unit; |
42 | ||
cfc14b3a MK |
43 | /* Call Frame Information (CFI). */ |
44 | ||
45 | /* Common Information Entry (CIE). */ | |
46 | ||
47 | struct dwarf2_cie | |
48 | { | |
ae0d2f24 UW |
49 | /* Computation Unit for this CIE. */ |
50 | struct comp_unit *unit; | |
51 | ||
cfc14b3a MK |
52 | /* Offset into the .debug_frame section where this CIE was found. |
53 | Used to identify this CIE. */ | |
54 | ULONGEST cie_pointer; | |
55 | ||
56 | /* Constant that is factored out of all advance location | |
57 | instructions. */ | |
58 | ULONGEST code_alignment_factor; | |
59 | ||
60 | /* Constants that is factored out of all offset instructions. */ | |
61 | LONGEST data_alignment_factor; | |
62 | ||
63 | /* Return address column. */ | |
64 | ULONGEST return_address_register; | |
65 | ||
66 | /* Instruction sequence to initialize a register set. */ | |
852483bc MK |
67 | gdb_byte *initial_instructions; |
68 | gdb_byte *end; | |
cfc14b3a | 69 | |
303b6f5d DJ |
70 | /* Saved augmentation, in case it's needed later. */ |
71 | char *augmentation; | |
72 | ||
cfc14b3a | 73 | /* Encoding of addresses. */ |
852483bc | 74 | gdb_byte encoding; |
cfc14b3a | 75 | |
ae0d2f24 UW |
76 | /* Target address size in bytes. */ |
77 | int addr_size; | |
78 | ||
7131cb6e RH |
79 | /* True if a 'z' augmentation existed. */ |
80 | unsigned char saw_z_augmentation; | |
81 | ||
56c987f6 AO |
82 | /* True if an 'S' augmentation existed. */ |
83 | unsigned char signal_frame; | |
84 | ||
303b6f5d DJ |
85 | /* The version recorded in the CIE. */ |
86 | unsigned char version; | |
87 | ||
cfc14b3a MK |
88 | struct dwarf2_cie *next; |
89 | }; | |
90 | ||
91 | /* Frame Description Entry (FDE). */ | |
92 | ||
93 | struct dwarf2_fde | |
94 | { | |
95 | /* CIE for this FDE. */ | |
96 | struct dwarf2_cie *cie; | |
97 | ||
98 | /* First location associated with this FDE. */ | |
99 | CORE_ADDR initial_location; | |
100 | ||
101 | /* Number of bytes of program instructions described by this FDE. */ | |
102 | CORE_ADDR address_range; | |
103 | ||
104 | /* Instruction sequence. */ | |
852483bc MK |
105 | gdb_byte *instructions; |
106 | gdb_byte *end; | |
cfc14b3a | 107 | |
4bf8967c AS |
108 | /* True if this FDE is read from a .eh_frame instead of a .debug_frame |
109 | section. */ | |
110 | unsigned char eh_frame_p; | |
111 | ||
cfc14b3a MK |
112 | struct dwarf2_fde *next; |
113 | }; | |
114 | ||
ae0d2f24 UW |
115 | /* A minimal decoding of DWARF2 compilation units. We only decode |
116 | what's needed to get to the call frame information. */ | |
117 | ||
118 | struct comp_unit | |
119 | { | |
120 | /* Keep the bfd convenient. */ | |
121 | bfd *abfd; | |
122 | ||
123 | struct objfile *objfile; | |
124 | ||
125 | /* Linked list of CIEs for this object. */ | |
126 | struct dwarf2_cie *cie; | |
127 | ||
128 | /* Pointer to the .debug_frame section loaded into memory. */ | |
129 | gdb_byte *dwarf_frame_buffer; | |
130 | ||
131 | /* Length of the loaded .debug_frame section. */ | |
132 | unsigned long dwarf_frame_size; | |
133 | ||
134 | /* Pointer to the .debug_frame section. */ | |
135 | asection *dwarf_frame_section; | |
136 | ||
137 | /* Base for DW_EH_PE_datarel encodings. */ | |
138 | bfd_vma dbase; | |
139 | ||
140 | /* Base for DW_EH_PE_textrel encodings. */ | |
141 | bfd_vma tbase; | |
142 | }; | |
143 | ||
cfc14b3a | 144 | static struct dwarf2_fde *dwarf2_frame_find_fde (CORE_ADDR *pc); |
4fc771b8 DJ |
145 | |
146 | static int dwarf2_frame_adjust_regnum (struct gdbarch *gdbarch, int regnum, | |
147 | int eh_frame_p); | |
ae0d2f24 UW |
148 | |
149 | static CORE_ADDR read_encoded_value (struct comp_unit *unit, gdb_byte encoding, | |
150 | int ptr_len, gdb_byte *buf, | |
151 | unsigned int *bytes_read_ptr, | |
152 | CORE_ADDR func_base); | |
cfc14b3a MK |
153 | \f |
154 | ||
155 | /* Structure describing a frame state. */ | |
156 | ||
157 | struct dwarf2_frame_state | |
158 | { | |
159 | /* Each register save state can be described in terms of a CFA slot, | |
160 | another register, or a location expression. */ | |
161 | struct dwarf2_frame_state_reg_info | |
162 | { | |
05cbe71a | 163 | struct dwarf2_frame_state_reg *reg; |
cfc14b3a MK |
164 | int num_regs; |
165 | ||
166 | /* Used to implement DW_CFA_remember_state. */ | |
167 | struct dwarf2_frame_state_reg_info *prev; | |
168 | } regs; | |
169 | ||
170 | LONGEST cfa_offset; | |
171 | ULONGEST cfa_reg; | |
852483bc | 172 | gdb_byte *cfa_exp; |
cfc14b3a MK |
173 | enum { |
174 | CFA_UNSET, | |
175 | CFA_REG_OFFSET, | |
176 | CFA_EXP | |
177 | } cfa_how; | |
178 | ||
179 | /* The PC described by the current frame state. */ | |
180 | CORE_ADDR pc; | |
181 | ||
182 | /* Initial register set from the CIE. | |
183 | Used to implement DW_CFA_restore. */ | |
184 | struct dwarf2_frame_state_reg_info initial; | |
185 | ||
186 | /* The information we care about from the CIE. */ | |
187 | LONGEST data_align; | |
188 | ULONGEST code_align; | |
189 | ULONGEST retaddr_column; | |
303b6f5d DJ |
190 | |
191 | /* Flags for known producer quirks. */ | |
192 | ||
193 | /* The ARM compilers, in DWARF2 mode, assume that DW_CFA_def_cfa | |
194 | and DW_CFA_def_cfa_offset takes a factored offset. */ | |
195 | int armcc_cfa_offsets_sf; | |
196 | ||
197 | /* The ARM compilers, in DWARF2 or DWARF3 mode, may assume that | |
198 | the CFA is defined as REG - OFFSET rather than REG + OFFSET. */ | |
199 | int armcc_cfa_offsets_reversed; | |
cfc14b3a MK |
200 | }; |
201 | ||
202 | /* Store the length the expression for the CFA in the `cfa_reg' field, | |
203 | which is unused in that case. */ | |
204 | #define cfa_exp_len cfa_reg | |
205 | ||
f57d151a | 206 | /* Assert that the register set RS is large enough to store gdbarch_num_regs |
cfc14b3a MK |
207 | columns. If necessary, enlarge the register set. */ |
208 | ||
209 | static void | |
210 | dwarf2_frame_state_alloc_regs (struct dwarf2_frame_state_reg_info *rs, | |
211 | int num_regs) | |
212 | { | |
213 | size_t size = sizeof (struct dwarf2_frame_state_reg); | |
214 | ||
215 | if (num_regs <= rs->num_regs) | |
216 | return; | |
217 | ||
218 | rs->reg = (struct dwarf2_frame_state_reg *) | |
219 | xrealloc (rs->reg, num_regs * size); | |
220 | ||
221 | /* Initialize newly allocated registers. */ | |
2473a4a9 | 222 | memset (rs->reg + rs->num_regs, 0, (num_regs - rs->num_regs) * size); |
cfc14b3a MK |
223 | rs->num_regs = num_regs; |
224 | } | |
225 | ||
226 | /* Copy the register columns in register set RS into newly allocated | |
227 | memory and return a pointer to this newly created copy. */ | |
228 | ||
229 | static struct dwarf2_frame_state_reg * | |
230 | dwarf2_frame_state_copy_regs (struct dwarf2_frame_state_reg_info *rs) | |
231 | { | |
d10891d4 | 232 | size_t size = rs->num_regs * sizeof (struct dwarf2_frame_state_reg); |
cfc14b3a MK |
233 | struct dwarf2_frame_state_reg *reg; |
234 | ||
235 | reg = (struct dwarf2_frame_state_reg *) xmalloc (size); | |
236 | memcpy (reg, rs->reg, size); | |
237 | ||
238 | return reg; | |
239 | } | |
240 | ||
241 | /* Release the memory allocated to register set RS. */ | |
242 | ||
243 | static void | |
244 | dwarf2_frame_state_free_regs (struct dwarf2_frame_state_reg_info *rs) | |
245 | { | |
246 | if (rs) | |
247 | { | |
248 | dwarf2_frame_state_free_regs (rs->prev); | |
249 | ||
250 | xfree (rs->reg); | |
251 | xfree (rs); | |
252 | } | |
253 | } | |
254 | ||
255 | /* Release the memory allocated to the frame state FS. */ | |
256 | ||
257 | static void | |
258 | dwarf2_frame_state_free (void *p) | |
259 | { | |
260 | struct dwarf2_frame_state *fs = p; | |
261 | ||
262 | dwarf2_frame_state_free_regs (fs->initial.prev); | |
263 | dwarf2_frame_state_free_regs (fs->regs.prev); | |
264 | xfree (fs->initial.reg); | |
265 | xfree (fs->regs.reg); | |
266 | xfree (fs); | |
267 | } | |
268 | \f | |
269 | ||
270 | /* Helper functions for execute_stack_op. */ | |
271 | ||
272 | static CORE_ADDR | |
273 | read_reg (void *baton, int reg) | |
274 | { | |
4a4e5149 DJ |
275 | struct frame_info *this_frame = (struct frame_info *) baton; |
276 | struct gdbarch *gdbarch = get_frame_arch (this_frame); | |
cfc14b3a | 277 | int regnum; |
852483bc | 278 | gdb_byte *buf; |
cfc14b3a | 279 | |
ad010def | 280 | regnum = gdbarch_dwarf2_reg_to_regnum (gdbarch, reg); |
cfc14b3a | 281 | |
852483bc | 282 | buf = alloca (register_size (gdbarch, regnum)); |
4a4e5149 | 283 | get_frame_register (this_frame, regnum, buf); |
f2da6b3a DJ |
284 | |
285 | /* Convert the register to an integer. This returns a LONGEST | |
286 | rather than a CORE_ADDR, but unpack_pointer does the same thing | |
287 | under the covers, and this makes more sense for non-pointer | |
288 | registers. Maybe read_reg and the associated interfaces should | |
289 | deal with "struct value" instead of CORE_ADDR. */ | |
290 | return unpack_long (register_type (gdbarch, regnum), buf); | |
cfc14b3a MK |
291 | } |
292 | ||
293 | static void | |
852483bc | 294 | read_mem (void *baton, gdb_byte *buf, CORE_ADDR addr, size_t len) |
cfc14b3a MK |
295 | { |
296 | read_memory (addr, buf, len); | |
297 | } | |
298 | ||
299 | static void | |
852483bc | 300 | no_get_frame_base (void *baton, gdb_byte **start, size_t *length) |
cfc14b3a MK |
301 | { |
302 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 303 | _("Support for DW_OP_fbreg is unimplemented")); |
cfc14b3a MK |
304 | } |
305 | ||
306 | static CORE_ADDR | |
307 | no_get_tls_address (void *baton, CORE_ADDR offset) | |
308 | { | |
309 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 310 | _("Support for DW_OP_GNU_push_tls_address is unimplemented")); |
cfc14b3a MK |
311 | } |
312 | ||
a6a5a945 LM |
313 | /* Execute the required actions for both the DW_CFA_restore and |
314 | DW_CFA_restore_extended instructions. */ | |
315 | static void | |
316 | dwarf2_restore_rule (struct gdbarch *gdbarch, ULONGEST reg_num, | |
317 | struct dwarf2_frame_state *fs, int eh_frame_p) | |
318 | { | |
319 | ULONGEST reg; | |
320 | ||
321 | gdb_assert (fs->initial.reg); | |
322 | reg = dwarf2_frame_adjust_regnum (gdbarch, reg_num, eh_frame_p); | |
323 | dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1); | |
324 | ||
325 | /* Check if this register was explicitly initialized in the | |
326 | CIE initial instructions. If not, default the rule to | |
327 | UNSPECIFIED. */ | |
328 | if (reg < fs->initial.num_regs) | |
329 | fs->regs.reg[reg] = fs->initial.reg[reg]; | |
330 | else | |
331 | fs->regs.reg[reg].how = DWARF2_FRAME_REG_UNSPECIFIED; | |
332 | ||
333 | if (fs->regs.reg[reg].how == DWARF2_FRAME_REG_UNSPECIFIED) | |
334 | complaint (&symfile_complaints, _("\ | |
335 | incomplete CFI data; DW_CFA_restore unspecified\n\ | |
336 | register %s (#%d) at 0x%s"), | |
337 | gdbarch_register_name | |
338 | (gdbarch, gdbarch_dwarf2_reg_to_regnum (gdbarch, reg)), | |
339 | gdbarch_dwarf2_reg_to_regnum (gdbarch, reg), | |
340 | paddr (fs->pc)); | |
341 | } | |
342 | ||
cfc14b3a | 343 | static CORE_ADDR |
ae0d2f24 | 344 | execute_stack_op (gdb_byte *exp, ULONGEST len, int addr_size, |
4a4e5149 | 345 | struct frame_info *this_frame, CORE_ADDR initial) |
cfc14b3a MK |
346 | { |
347 | struct dwarf_expr_context *ctx; | |
348 | CORE_ADDR result; | |
349 | ||
350 | ctx = new_dwarf_expr_context (); | |
f7fd4728 | 351 | ctx->gdbarch = get_frame_arch (this_frame); |
ae0d2f24 | 352 | ctx->addr_size = addr_size; |
4a4e5149 | 353 | ctx->baton = this_frame; |
cfc14b3a MK |
354 | ctx->read_reg = read_reg; |
355 | ctx->read_mem = read_mem; | |
356 | ctx->get_frame_base = no_get_frame_base; | |
357 | ctx->get_tls_address = no_get_tls_address; | |
358 | ||
359 | dwarf_expr_push (ctx, initial); | |
360 | dwarf_expr_eval (ctx, exp, len); | |
361 | result = dwarf_expr_fetch (ctx, 0); | |
362 | ||
363 | if (ctx->in_reg) | |
4a4e5149 | 364 | result = read_reg (this_frame, result); |
cfc14b3a MK |
365 | |
366 | free_dwarf_expr_context (ctx); | |
367 | ||
368 | return result; | |
369 | } | |
370 | \f | |
371 | ||
372 | static void | |
ae0d2f24 | 373 | execute_cfa_program (struct dwarf2_fde *fde, gdb_byte *insn_ptr, |
4a4e5149 | 374 | gdb_byte *insn_end, struct frame_info *this_frame, |
ae0d2f24 | 375 | struct dwarf2_frame_state *fs) |
cfc14b3a | 376 | { |
ae0d2f24 | 377 | int eh_frame_p = fde->eh_frame_p; |
4a4e5149 | 378 | CORE_ADDR pc = get_frame_pc (this_frame); |
cfc14b3a | 379 | int bytes_read; |
4a4e5149 | 380 | struct gdbarch *gdbarch = get_frame_arch (this_frame); |
cfc14b3a MK |
381 | |
382 | while (insn_ptr < insn_end && fs->pc <= pc) | |
383 | { | |
852483bc | 384 | gdb_byte insn = *insn_ptr++; |
cfc14b3a MK |
385 | ULONGEST utmp, reg; |
386 | LONGEST offset; | |
387 | ||
388 | if ((insn & 0xc0) == DW_CFA_advance_loc) | |
389 | fs->pc += (insn & 0x3f) * fs->code_align; | |
390 | else if ((insn & 0xc0) == DW_CFA_offset) | |
391 | { | |
392 | reg = insn & 0x3f; | |
4fc771b8 | 393 | reg = dwarf2_frame_adjust_regnum (gdbarch, reg, eh_frame_p); |
cfc14b3a MK |
394 | insn_ptr = read_uleb128 (insn_ptr, insn_end, &utmp); |
395 | offset = utmp * fs->data_align; | |
396 | dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1); | |
05cbe71a | 397 | fs->regs.reg[reg].how = DWARF2_FRAME_REG_SAVED_OFFSET; |
cfc14b3a MK |
398 | fs->regs.reg[reg].loc.offset = offset; |
399 | } | |
400 | else if ((insn & 0xc0) == DW_CFA_restore) | |
401 | { | |
cfc14b3a | 402 | reg = insn & 0x3f; |
a6a5a945 | 403 | dwarf2_restore_rule (gdbarch, reg, fs, eh_frame_p); |
cfc14b3a MK |
404 | } |
405 | else | |
406 | { | |
407 | switch (insn) | |
408 | { | |
409 | case DW_CFA_set_loc: | |
ae0d2f24 UW |
410 | fs->pc = read_encoded_value (fde->cie->unit, fde->cie->encoding, |
411 | fde->cie->addr_size, insn_ptr, | |
412 | &bytes_read, fde->initial_location); | |
413 | /* Apply the objfile offset for relocatable objects. */ | |
414 | fs->pc += ANOFFSET (fde->cie->unit->objfile->section_offsets, | |
415 | SECT_OFF_TEXT (fde->cie->unit->objfile)); | |
cfc14b3a MK |
416 | insn_ptr += bytes_read; |
417 | break; | |
418 | ||
419 | case DW_CFA_advance_loc1: | |
420 | utmp = extract_unsigned_integer (insn_ptr, 1); | |
421 | fs->pc += utmp * fs->code_align; | |
422 | insn_ptr++; | |
423 | break; | |
424 | case DW_CFA_advance_loc2: | |
425 | utmp = extract_unsigned_integer (insn_ptr, 2); | |
426 | fs->pc += utmp * fs->code_align; | |
427 | insn_ptr += 2; | |
428 | break; | |
429 | case DW_CFA_advance_loc4: | |
430 | utmp = extract_unsigned_integer (insn_ptr, 4); | |
431 | fs->pc += utmp * fs->code_align; | |
432 | insn_ptr += 4; | |
433 | break; | |
434 | ||
435 | case DW_CFA_offset_extended: | |
436 | insn_ptr = read_uleb128 (insn_ptr, insn_end, ®); | |
4fc771b8 | 437 | reg = dwarf2_frame_adjust_regnum (gdbarch, reg, eh_frame_p); |
cfc14b3a MK |
438 | insn_ptr = read_uleb128 (insn_ptr, insn_end, &utmp); |
439 | offset = utmp * fs->data_align; | |
440 | dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1); | |
05cbe71a | 441 | fs->regs.reg[reg].how = DWARF2_FRAME_REG_SAVED_OFFSET; |
cfc14b3a MK |
442 | fs->regs.reg[reg].loc.offset = offset; |
443 | break; | |
444 | ||
445 | case DW_CFA_restore_extended: | |
cfc14b3a | 446 | insn_ptr = read_uleb128 (insn_ptr, insn_end, ®); |
a6a5a945 | 447 | dwarf2_restore_rule (gdbarch, reg, fs, eh_frame_p); |
cfc14b3a MK |
448 | break; |
449 | ||
450 | case DW_CFA_undefined: | |
451 | insn_ptr = read_uleb128 (insn_ptr, insn_end, ®); | |
4fc771b8 | 452 | reg = dwarf2_frame_adjust_regnum (gdbarch, reg, eh_frame_p); |
cfc14b3a | 453 | dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1); |
05cbe71a | 454 | fs->regs.reg[reg].how = DWARF2_FRAME_REG_UNDEFINED; |
cfc14b3a MK |
455 | break; |
456 | ||
457 | case DW_CFA_same_value: | |
458 | insn_ptr = read_uleb128 (insn_ptr, insn_end, ®); | |
4fc771b8 | 459 | reg = dwarf2_frame_adjust_regnum (gdbarch, reg, eh_frame_p); |
cfc14b3a | 460 | dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1); |
05cbe71a | 461 | fs->regs.reg[reg].how = DWARF2_FRAME_REG_SAME_VALUE; |
cfc14b3a MK |
462 | break; |
463 | ||
464 | case DW_CFA_register: | |
465 | insn_ptr = read_uleb128 (insn_ptr, insn_end, ®); | |
4fc771b8 | 466 | reg = dwarf2_frame_adjust_regnum (gdbarch, reg, eh_frame_p); |
cfc14b3a | 467 | insn_ptr = read_uleb128 (insn_ptr, insn_end, &utmp); |
4fc771b8 | 468 | utmp = dwarf2_frame_adjust_regnum (gdbarch, utmp, eh_frame_p); |
cfc14b3a | 469 | dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1); |
05cbe71a | 470 | fs->regs.reg[reg].how = DWARF2_FRAME_REG_SAVED_REG; |
cfc14b3a MK |
471 | fs->regs.reg[reg].loc.reg = utmp; |
472 | break; | |
473 | ||
474 | case DW_CFA_remember_state: | |
475 | { | |
476 | struct dwarf2_frame_state_reg_info *new_rs; | |
477 | ||
478 | new_rs = XMALLOC (struct dwarf2_frame_state_reg_info); | |
479 | *new_rs = fs->regs; | |
480 | fs->regs.reg = dwarf2_frame_state_copy_regs (&fs->regs); | |
481 | fs->regs.prev = new_rs; | |
482 | } | |
483 | break; | |
484 | ||
485 | case DW_CFA_restore_state: | |
486 | { | |
487 | struct dwarf2_frame_state_reg_info *old_rs = fs->regs.prev; | |
488 | ||
50ea7769 MK |
489 | if (old_rs == NULL) |
490 | { | |
e2e0b3e5 AC |
491 | complaint (&symfile_complaints, _("\ |
492 | bad CFI data; mismatched DW_CFA_restore_state at 0x%s"), paddr (fs->pc)); | |
50ea7769 MK |
493 | } |
494 | else | |
495 | { | |
496 | xfree (fs->regs.reg); | |
497 | fs->regs = *old_rs; | |
498 | xfree (old_rs); | |
499 | } | |
cfc14b3a MK |
500 | } |
501 | break; | |
502 | ||
503 | case DW_CFA_def_cfa: | |
504 | insn_ptr = read_uleb128 (insn_ptr, insn_end, &fs->cfa_reg); | |
505 | insn_ptr = read_uleb128 (insn_ptr, insn_end, &utmp); | |
303b6f5d DJ |
506 | |
507 | if (fs->armcc_cfa_offsets_sf) | |
508 | utmp *= fs->data_align; | |
509 | ||
cfc14b3a MK |
510 | fs->cfa_offset = utmp; |
511 | fs->cfa_how = CFA_REG_OFFSET; | |
512 | break; | |
513 | ||
514 | case DW_CFA_def_cfa_register: | |
515 | insn_ptr = read_uleb128 (insn_ptr, insn_end, &fs->cfa_reg); | |
4fc771b8 DJ |
516 | fs->cfa_reg = dwarf2_frame_adjust_regnum (gdbarch, fs->cfa_reg, |
517 | eh_frame_p); | |
cfc14b3a MK |
518 | fs->cfa_how = CFA_REG_OFFSET; |
519 | break; | |
520 | ||
521 | case DW_CFA_def_cfa_offset: | |
852483bc | 522 | insn_ptr = read_uleb128 (insn_ptr, insn_end, &utmp); |
303b6f5d DJ |
523 | |
524 | if (fs->armcc_cfa_offsets_sf) | |
525 | utmp *= fs->data_align; | |
526 | ||
852483bc | 527 | fs->cfa_offset = utmp; |
cfc14b3a MK |
528 | /* cfa_how deliberately not set. */ |
529 | break; | |
530 | ||
a8504492 MK |
531 | case DW_CFA_nop: |
532 | break; | |
533 | ||
cfc14b3a MK |
534 | case DW_CFA_def_cfa_expression: |
535 | insn_ptr = read_uleb128 (insn_ptr, insn_end, &fs->cfa_exp_len); | |
536 | fs->cfa_exp = insn_ptr; | |
537 | fs->cfa_how = CFA_EXP; | |
538 | insn_ptr += fs->cfa_exp_len; | |
539 | break; | |
540 | ||
541 | case DW_CFA_expression: | |
542 | insn_ptr = read_uleb128 (insn_ptr, insn_end, ®); | |
4fc771b8 | 543 | reg = dwarf2_frame_adjust_regnum (gdbarch, reg, eh_frame_p); |
cfc14b3a MK |
544 | dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1); |
545 | insn_ptr = read_uleb128 (insn_ptr, insn_end, &utmp); | |
546 | fs->regs.reg[reg].loc.exp = insn_ptr; | |
547 | fs->regs.reg[reg].exp_len = utmp; | |
05cbe71a | 548 | fs->regs.reg[reg].how = DWARF2_FRAME_REG_SAVED_EXP; |
cfc14b3a MK |
549 | insn_ptr += utmp; |
550 | break; | |
551 | ||
a8504492 MK |
552 | case DW_CFA_offset_extended_sf: |
553 | insn_ptr = read_uleb128 (insn_ptr, insn_end, ®); | |
4fc771b8 | 554 | reg = dwarf2_frame_adjust_regnum (gdbarch, reg, eh_frame_p); |
a8504492 | 555 | insn_ptr = read_sleb128 (insn_ptr, insn_end, &offset); |
f6da8dd8 | 556 | offset *= fs->data_align; |
a8504492 | 557 | dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1); |
05cbe71a | 558 | fs->regs.reg[reg].how = DWARF2_FRAME_REG_SAVED_OFFSET; |
a8504492 MK |
559 | fs->regs.reg[reg].loc.offset = offset; |
560 | break; | |
561 | ||
46ea248b AO |
562 | case DW_CFA_val_offset: |
563 | insn_ptr = read_uleb128 (insn_ptr, insn_end, ®); | |
564 | dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1); | |
565 | insn_ptr = read_uleb128 (insn_ptr, insn_end, &utmp); | |
566 | offset = utmp * fs->data_align; | |
567 | fs->regs.reg[reg].how = DWARF2_FRAME_REG_SAVED_VAL_OFFSET; | |
568 | fs->regs.reg[reg].loc.offset = offset; | |
569 | break; | |
570 | ||
571 | case DW_CFA_val_offset_sf: | |
572 | insn_ptr = read_uleb128 (insn_ptr, insn_end, ®); | |
573 | dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1); | |
574 | insn_ptr = read_sleb128 (insn_ptr, insn_end, &offset); | |
575 | offset *= fs->data_align; | |
576 | fs->regs.reg[reg].how = DWARF2_FRAME_REG_SAVED_VAL_OFFSET; | |
577 | fs->regs.reg[reg].loc.offset = offset; | |
578 | break; | |
579 | ||
580 | case DW_CFA_val_expression: | |
581 | insn_ptr = read_uleb128 (insn_ptr, insn_end, ®); | |
582 | dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1); | |
583 | insn_ptr = read_uleb128 (insn_ptr, insn_end, &utmp); | |
584 | fs->regs.reg[reg].loc.exp = insn_ptr; | |
585 | fs->regs.reg[reg].exp_len = utmp; | |
586 | fs->regs.reg[reg].how = DWARF2_FRAME_REG_SAVED_VAL_EXP; | |
587 | insn_ptr += utmp; | |
588 | break; | |
589 | ||
a8504492 MK |
590 | case DW_CFA_def_cfa_sf: |
591 | insn_ptr = read_uleb128 (insn_ptr, insn_end, &fs->cfa_reg); | |
4fc771b8 DJ |
592 | fs->cfa_reg = dwarf2_frame_adjust_regnum (gdbarch, fs->cfa_reg, |
593 | eh_frame_p); | |
a8504492 MK |
594 | insn_ptr = read_sleb128 (insn_ptr, insn_end, &offset); |
595 | fs->cfa_offset = offset * fs->data_align; | |
596 | fs->cfa_how = CFA_REG_OFFSET; | |
597 | break; | |
598 | ||
599 | case DW_CFA_def_cfa_offset_sf: | |
600 | insn_ptr = read_sleb128 (insn_ptr, insn_end, &offset); | |
601 | fs->cfa_offset = offset * fs->data_align; | |
602 | /* cfa_how deliberately not set. */ | |
cfc14b3a MK |
603 | break; |
604 | ||
a77f4086 MK |
605 | case DW_CFA_GNU_window_save: |
606 | /* This is SPARC-specific code, and contains hard-coded | |
607 | constants for the register numbering scheme used by | |
608 | GCC. Rather than having a architecture-specific | |
609 | operation that's only ever used by a single | |
610 | architecture, we provide the implementation here. | |
611 | Incidentally that's what GCC does too in its | |
612 | unwinder. */ | |
613 | { | |
4a4e5149 | 614 | int size = register_size (gdbarch, 0); |
a77f4086 MK |
615 | dwarf2_frame_state_alloc_regs (&fs->regs, 32); |
616 | for (reg = 8; reg < 16; reg++) | |
617 | { | |
618 | fs->regs.reg[reg].how = DWARF2_FRAME_REG_SAVED_REG; | |
619 | fs->regs.reg[reg].loc.reg = reg + 16; | |
620 | } | |
621 | for (reg = 16; reg < 32; reg++) | |
622 | { | |
623 | fs->regs.reg[reg].how = DWARF2_FRAME_REG_SAVED_OFFSET; | |
624 | fs->regs.reg[reg].loc.offset = (reg - 16) * size; | |
625 | } | |
626 | } | |
627 | break; | |
628 | ||
cfc14b3a MK |
629 | case DW_CFA_GNU_args_size: |
630 | /* Ignored. */ | |
631 | insn_ptr = read_uleb128 (insn_ptr, insn_end, &utmp); | |
632 | break; | |
633 | ||
58894217 JK |
634 | case DW_CFA_GNU_negative_offset_extended: |
635 | insn_ptr = read_uleb128 (insn_ptr, insn_end, ®); | |
4fc771b8 | 636 | reg = dwarf2_frame_adjust_regnum (gdbarch, reg, eh_frame_p); |
58894217 JK |
637 | insn_ptr = read_uleb128 (insn_ptr, insn_end, &offset); |
638 | offset *= fs->data_align; | |
639 | dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1); | |
640 | fs->regs.reg[reg].how = DWARF2_FRAME_REG_SAVED_OFFSET; | |
641 | fs->regs.reg[reg].loc.offset = -offset; | |
642 | break; | |
643 | ||
cfc14b3a | 644 | default: |
e2e0b3e5 | 645 | internal_error (__FILE__, __LINE__, _("Unknown CFI encountered.")); |
cfc14b3a MK |
646 | } |
647 | } | |
648 | } | |
649 | ||
650 | /* Don't allow remember/restore between CIE and FDE programs. */ | |
651 | dwarf2_frame_state_free_regs (fs->regs.prev); | |
652 | fs->regs.prev = NULL; | |
653 | } | |
8f22cb90 | 654 | \f |
cfc14b3a | 655 | |
8f22cb90 | 656 | /* Architecture-specific operations. */ |
cfc14b3a | 657 | |
8f22cb90 MK |
658 | /* Per-architecture data key. */ |
659 | static struct gdbarch_data *dwarf2_frame_data; | |
660 | ||
661 | struct dwarf2_frame_ops | |
662 | { | |
663 | /* Pre-initialize the register state REG for register REGNUM. */ | |
aff37fc1 DM |
664 | void (*init_reg) (struct gdbarch *, int, struct dwarf2_frame_state_reg *, |
665 | struct frame_info *); | |
3ed09a32 | 666 | |
4a4e5149 | 667 | /* Check whether the THIS_FRAME is a signal trampoline. */ |
3ed09a32 | 668 | int (*signal_frame_p) (struct gdbarch *, struct frame_info *); |
4bf8967c | 669 | |
4fc771b8 DJ |
670 | /* Convert .eh_frame register number to DWARF register number, or |
671 | adjust .debug_frame register number. */ | |
672 | int (*adjust_regnum) (struct gdbarch *, int, int); | |
cfc14b3a MK |
673 | }; |
674 | ||
8f22cb90 MK |
675 | /* Default architecture-specific register state initialization |
676 | function. */ | |
677 | ||
678 | static void | |
679 | dwarf2_frame_default_init_reg (struct gdbarch *gdbarch, int regnum, | |
aff37fc1 | 680 | struct dwarf2_frame_state_reg *reg, |
4a4e5149 | 681 | struct frame_info *this_frame) |
8f22cb90 MK |
682 | { |
683 | /* If we have a register that acts as a program counter, mark it as | |
684 | a destination for the return address. If we have a register that | |
685 | serves as the stack pointer, arrange for it to be filled with the | |
686 | call frame address (CFA). The other registers are marked as | |
687 | unspecified. | |
688 | ||
689 | We copy the return address to the program counter, since many | |
690 | parts in GDB assume that it is possible to get the return address | |
691 | by unwinding the program counter register. However, on ISA's | |
692 | with a dedicated return address register, the CFI usually only | |
693 | contains information to unwind that return address register. | |
694 | ||
695 | The reason we're treating the stack pointer special here is | |
696 | because in many cases GCC doesn't emit CFI for the stack pointer | |
697 | and implicitly assumes that it is equal to the CFA. This makes | |
698 | some sense since the DWARF specification (version 3, draft 8, | |
699 | p. 102) says that: | |
700 | ||
701 | "Typically, the CFA is defined to be the value of the stack | |
702 | pointer at the call site in the previous frame (which may be | |
703 | different from its value on entry to the current frame)." | |
704 | ||
705 | However, this isn't true for all platforms supported by GCC | |
706 | (e.g. IBM S/390 and zSeries). Those architectures should provide | |
707 | their own architecture-specific initialization function. */ | |
05cbe71a | 708 | |
ad010def | 709 | if (regnum == gdbarch_pc_regnum (gdbarch)) |
8f22cb90 | 710 | reg->how = DWARF2_FRAME_REG_RA; |
ad010def | 711 | else if (regnum == gdbarch_sp_regnum (gdbarch)) |
8f22cb90 MK |
712 | reg->how = DWARF2_FRAME_REG_CFA; |
713 | } | |
05cbe71a | 714 | |
8f22cb90 | 715 | /* Return a default for the architecture-specific operations. */ |
05cbe71a | 716 | |
8f22cb90 | 717 | static void * |
030f20e1 | 718 | dwarf2_frame_init (struct obstack *obstack) |
8f22cb90 MK |
719 | { |
720 | struct dwarf2_frame_ops *ops; | |
721 | ||
030f20e1 | 722 | ops = OBSTACK_ZALLOC (obstack, struct dwarf2_frame_ops); |
8f22cb90 MK |
723 | ops->init_reg = dwarf2_frame_default_init_reg; |
724 | return ops; | |
725 | } | |
05cbe71a | 726 | |
8f22cb90 MK |
727 | /* Set the architecture-specific register state initialization |
728 | function for GDBARCH to INIT_REG. */ | |
729 | ||
730 | void | |
731 | dwarf2_frame_set_init_reg (struct gdbarch *gdbarch, | |
732 | void (*init_reg) (struct gdbarch *, int, | |
aff37fc1 DM |
733 | struct dwarf2_frame_state_reg *, |
734 | struct frame_info *)) | |
8f22cb90 | 735 | { |
030f20e1 | 736 | struct dwarf2_frame_ops *ops = gdbarch_data (gdbarch, dwarf2_frame_data); |
8f22cb90 | 737 | |
8f22cb90 MK |
738 | ops->init_reg = init_reg; |
739 | } | |
740 | ||
741 | /* Pre-initialize the register state REG for register REGNUM. */ | |
05cbe71a MK |
742 | |
743 | static void | |
744 | dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum, | |
aff37fc1 | 745 | struct dwarf2_frame_state_reg *reg, |
4a4e5149 | 746 | struct frame_info *this_frame) |
05cbe71a | 747 | { |
030f20e1 | 748 | struct dwarf2_frame_ops *ops = gdbarch_data (gdbarch, dwarf2_frame_data); |
8f22cb90 | 749 | |
4a4e5149 | 750 | ops->init_reg (gdbarch, regnum, reg, this_frame); |
05cbe71a | 751 | } |
3ed09a32 DJ |
752 | |
753 | /* Set the architecture-specific signal trampoline recognition | |
754 | function for GDBARCH to SIGNAL_FRAME_P. */ | |
755 | ||
756 | void | |
757 | dwarf2_frame_set_signal_frame_p (struct gdbarch *gdbarch, | |
758 | int (*signal_frame_p) (struct gdbarch *, | |
759 | struct frame_info *)) | |
760 | { | |
761 | struct dwarf2_frame_ops *ops = gdbarch_data (gdbarch, dwarf2_frame_data); | |
762 | ||
763 | ops->signal_frame_p = signal_frame_p; | |
764 | } | |
765 | ||
766 | /* Query the architecture-specific signal frame recognizer for | |
4a4e5149 | 767 | THIS_FRAME. */ |
3ed09a32 DJ |
768 | |
769 | static int | |
770 | dwarf2_frame_signal_frame_p (struct gdbarch *gdbarch, | |
4a4e5149 | 771 | struct frame_info *this_frame) |
3ed09a32 DJ |
772 | { |
773 | struct dwarf2_frame_ops *ops = gdbarch_data (gdbarch, dwarf2_frame_data); | |
774 | ||
775 | if (ops->signal_frame_p == NULL) | |
776 | return 0; | |
4a4e5149 | 777 | return ops->signal_frame_p (gdbarch, this_frame); |
3ed09a32 | 778 | } |
4bf8967c | 779 | |
4fc771b8 DJ |
780 | /* Set the architecture-specific adjustment of .eh_frame and .debug_frame |
781 | register numbers. */ | |
4bf8967c AS |
782 | |
783 | void | |
4fc771b8 DJ |
784 | dwarf2_frame_set_adjust_regnum (struct gdbarch *gdbarch, |
785 | int (*adjust_regnum) (struct gdbarch *, | |
786 | int, int)) | |
4bf8967c AS |
787 | { |
788 | struct dwarf2_frame_ops *ops = gdbarch_data (gdbarch, dwarf2_frame_data); | |
789 | ||
4fc771b8 | 790 | ops->adjust_regnum = adjust_regnum; |
4bf8967c AS |
791 | } |
792 | ||
4fc771b8 DJ |
793 | /* Translate a .eh_frame register to DWARF register, or adjust a .debug_frame |
794 | register. */ | |
4bf8967c | 795 | |
4fc771b8 DJ |
796 | static int |
797 | dwarf2_frame_adjust_regnum (struct gdbarch *gdbarch, int regnum, int eh_frame_p) | |
4bf8967c AS |
798 | { |
799 | struct dwarf2_frame_ops *ops = gdbarch_data (gdbarch, dwarf2_frame_data); | |
800 | ||
4fc771b8 | 801 | if (ops->adjust_regnum == NULL) |
4bf8967c | 802 | return regnum; |
4fc771b8 | 803 | return ops->adjust_regnum (gdbarch, regnum, eh_frame_p); |
4bf8967c | 804 | } |
303b6f5d DJ |
805 | |
806 | static void | |
807 | dwarf2_frame_find_quirks (struct dwarf2_frame_state *fs, | |
808 | struct dwarf2_fde *fde) | |
809 | { | |
810 | static const char *arm_idents[] = { | |
811 | "ARM C Compiler, ADS", | |
812 | "Thumb C Compiler, ADS", | |
813 | "ARM C++ Compiler, ADS", | |
814 | "Thumb C++ Compiler, ADS", | |
815 | "ARM/Thumb C/C++ Compiler, RVCT" | |
816 | }; | |
817 | int i; | |
818 | ||
819 | struct symtab *s; | |
820 | ||
821 | s = find_pc_symtab (fs->pc); | |
822 | if (s == NULL || s->producer == NULL) | |
823 | return; | |
824 | ||
825 | for (i = 0; i < ARRAY_SIZE (arm_idents); i++) | |
826 | if (strncmp (s->producer, arm_idents[i], strlen (arm_idents[i])) == 0) | |
827 | { | |
828 | if (fde->cie->version == 1) | |
829 | fs->armcc_cfa_offsets_sf = 1; | |
830 | ||
831 | if (fde->cie->version == 1) | |
832 | fs->armcc_cfa_offsets_reversed = 1; | |
833 | ||
834 | /* The reversed offset problem is present in some compilers | |
835 | using DWARF3, but it was eventually fixed. Check the ARM | |
836 | defined augmentations, which are in the format "armcc" followed | |
837 | by a list of one-character options. The "+" option means | |
838 | this problem is fixed (no quirk needed). If the armcc | |
839 | augmentation is missing, the quirk is needed. */ | |
840 | if (fde->cie->version == 3 | |
841 | && (strncmp (fde->cie->augmentation, "armcc", 5) != 0 | |
842 | || strchr (fde->cie->augmentation + 5, '+') == NULL)) | |
843 | fs->armcc_cfa_offsets_reversed = 1; | |
844 | ||
845 | return; | |
846 | } | |
847 | } | |
8f22cb90 MK |
848 | \f |
849 | ||
850 | struct dwarf2_frame_cache | |
851 | { | |
852 | /* DWARF Call Frame Address. */ | |
853 | CORE_ADDR cfa; | |
854 | ||
0228dfb9 DJ |
855 | /* Set if the return address column was marked as undefined. */ |
856 | int undefined_retaddr; | |
857 | ||
8f22cb90 MK |
858 | /* Saved registers, indexed by GDB register number, not by DWARF |
859 | register number. */ | |
860 | struct dwarf2_frame_state_reg *reg; | |
8d5a9abc MK |
861 | |
862 | /* Return address register. */ | |
863 | struct dwarf2_frame_state_reg retaddr_reg; | |
ae0d2f24 UW |
864 | |
865 | /* Target address size in bytes. */ | |
866 | int addr_size; | |
8f22cb90 | 867 | }; |
05cbe71a | 868 | |
b9362cc7 | 869 | static struct dwarf2_frame_cache * |
4a4e5149 | 870 | dwarf2_frame_cache (struct frame_info *this_frame, void **this_cache) |
cfc14b3a MK |
871 | { |
872 | struct cleanup *old_chain; | |
4a4e5149 | 873 | struct gdbarch *gdbarch = get_frame_arch (this_frame); |
ad010def UW |
874 | const int num_regs = gdbarch_num_regs (gdbarch) |
875 | + gdbarch_num_pseudo_regs (gdbarch); | |
cfc14b3a MK |
876 | struct dwarf2_frame_cache *cache; |
877 | struct dwarf2_frame_state *fs; | |
878 | struct dwarf2_fde *fde; | |
cfc14b3a MK |
879 | |
880 | if (*this_cache) | |
881 | return *this_cache; | |
882 | ||
883 | /* Allocate a new cache. */ | |
884 | cache = FRAME_OBSTACK_ZALLOC (struct dwarf2_frame_cache); | |
885 | cache->reg = FRAME_OBSTACK_CALLOC (num_regs, struct dwarf2_frame_state_reg); | |
886 | ||
887 | /* Allocate and initialize the frame state. */ | |
888 | fs = XMALLOC (struct dwarf2_frame_state); | |
889 | memset (fs, 0, sizeof (struct dwarf2_frame_state)); | |
890 | old_chain = make_cleanup (dwarf2_frame_state_free, fs); | |
891 | ||
892 | /* Unwind the PC. | |
893 | ||
4a4e5149 | 894 | Note that if the next frame is never supposed to return (i.e. a call |
cfc14b3a | 895 | to abort), the compiler might optimize away the instruction at |
4a4e5149 | 896 | its return address. As a result the return address will |
cfc14b3a | 897 | point at some random instruction, and the CFI for that |
e4e9607c | 898 | instruction is probably worthless to us. GCC's unwinder solves |
cfc14b3a MK |
899 | this problem by substracting 1 from the return address to get an |
900 | address in the middle of a presumed call instruction (or the | |
901 | instruction in the associated delay slot). This should only be | |
902 | done for "normal" frames and not for resume-type frames (signal | |
e4e9607c | 903 | handlers, sentinel frames, dummy frames). The function |
ad1193e7 | 904 | get_frame_address_in_block does just this. It's not clear how |
e4e9607c MK |
905 | reliable the method is though; there is the potential for the |
906 | register state pre-call being different to that on return. */ | |
4a4e5149 | 907 | fs->pc = get_frame_address_in_block (this_frame); |
cfc14b3a MK |
908 | |
909 | /* Find the correct FDE. */ | |
910 | fde = dwarf2_frame_find_fde (&fs->pc); | |
911 | gdb_assert (fde != NULL); | |
912 | ||
913 | /* Extract any interesting information from the CIE. */ | |
914 | fs->data_align = fde->cie->data_alignment_factor; | |
915 | fs->code_align = fde->cie->code_alignment_factor; | |
916 | fs->retaddr_column = fde->cie->return_address_register; | |
ae0d2f24 | 917 | cache->addr_size = fde->cie->addr_size; |
cfc14b3a | 918 | |
303b6f5d DJ |
919 | /* Check for "quirks" - known bugs in producers. */ |
920 | dwarf2_frame_find_quirks (fs, fde); | |
921 | ||
cfc14b3a | 922 | /* First decode all the insns in the CIE. */ |
ae0d2f24 | 923 | execute_cfa_program (fde, fde->cie->initial_instructions, |
4a4e5149 | 924 | fde->cie->end, this_frame, fs); |
cfc14b3a MK |
925 | |
926 | /* Save the initialized register set. */ | |
927 | fs->initial = fs->regs; | |
928 | fs->initial.reg = dwarf2_frame_state_copy_regs (&fs->regs); | |
929 | ||
930 | /* Then decode the insns in the FDE up to our target PC. */ | |
4a4e5149 | 931 | execute_cfa_program (fde, fde->instructions, fde->end, this_frame, fs); |
cfc14b3a | 932 | |
938f5214 | 933 | /* Calculate the CFA. */ |
cfc14b3a MK |
934 | switch (fs->cfa_how) |
935 | { | |
936 | case CFA_REG_OFFSET: | |
4a4e5149 | 937 | cache->cfa = read_reg (this_frame, fs->cfa_reg); |
303b6f5d DJ |
938 | if (fs->armcc_cfa_offsets_reversed) |
939 | cache->cfa -= fs->cfa_offset; | |
940 | else | |
941 | cache->cfa += fs->cfa_offset; | |
cfc14b3a MK |
942 | break; |
943 | ||
944 | case CFA_EXP: | |
945 | cache->cfa = | |
ae0d2f24 | 946 | execute_stack_op (fs->cfa_exp, fs->cfa_exp_len, |
4a4e5149 | 947 | cache->addr_size, this_frame, 0); |
cfc14b3a MK |
948 | break; |
949 | ||
950 | default: | |
e2e0b3e5 | 951 | internal_error (__FILE__, __LINE__, _("Unknown CFA rule.")); |
cfc14b3a MK |
952 | } |
953 | ||
05cbe71a | 954 | /* Initialize the register state. */ |
3e2c4033 AC |
955 | { |
956 | int regnum; | |
e4e9607c | 957 | |
3e2c4033 | 958 | for (regnum = 0; regnum < num_regs; regnum++) |
4a4e5149 | 959 | dwarf2_frame_init_reg (gdbarch, regnum, &cache->reg[regnum], this_frame); |
3e2c4033 AC |
960 | } |
961 | ||
962 | /* Go through the DWARF2 CFI generated table and save its register | |
79c4cb80 MK |
963 | location information in the cache. Note that we don't skip the |
964 | return address column; it's perfectly all right for it to | |
965 | correspond to a real register. If it doesn't correspond to a | |
966 | real register, or if we shouldn't treat it as such, | |
055d23b8 | 967 | gdbarch_dwarf2_reg_to_regnum should be defined to return a number outside |
f57d151a | 968 | the range [0, gdbarch_num_regs). */ |
3e2c4033 AC |
969 | { |
970 | int column; /* CFI speak for "register number". */ | |
e4e9607c | 971 | |
3e2c4033 AC |
972 | for (column = 0; column < fs->regs.num_regs; column++) |
973 | { | |
3e2c4033 | 974 | /* Use the GDB register number as the destination index. */ |
ad010def | 975 | int regnum = gdbarch_dwarf2_reg_to_regnum (gdbarch, column); |
3e2c4033 AC |
976 | |
977 | /* If there's no corresponding GDB register, ignore it. */ | |
978 | if (regnum < 0 || regnum >= num_regs) | |
979 | continue; | |
980 | ||
981 | /* NOTE: cagney/2003-09-05: CFI should specify the disposition | |
e4e9607c MK |
982 | of all debug info registers. If it doesn't, complain (but |
983 | not too loudly). It turns out that GCC assumes that an | |
3e2c4033 AC |
984 | unspecified register implies "same value" when CFI (draft |
985 | 7) specifies nothing at all. Such a register could equally | |
986 | be interpreted as "undefined". Also note that this check | |
e4e9607c MK |
987 | isn't sufficient; it only checks that all registers in the |
988 | range [0 .. max column] are specified, and won't detect | |
3e2c4033 | 989 | problems when a debug info register falls outside of the |
e4e9607c | 990 | table. We need a way of iterating through all the valid |
3e2c4033 | 991 | DWARF2 register numbers. */ |
05cbe71a | 992 | if (fs->regs.reg[column].how == DWARF2_FRAME_REG_UNSPECIFIED) |
f059bf6f AC |
993 | { |
994 | if (cache->reg[regnum].how == DWARF2_FRAME_REG_UNSPECIFIED) | |
e2e0b3e5 AC |
995 | complaint (&symfile_complaints, _("\ |
996 | incomplete CFI data; unspecified registers (e.g., %s) at 0x%s"), | |
f059bf6f AC |
997 | gdbarch_register_name (gdbarch, regnum), |
998 | paddr_nz (fs->pc)); | |
999 | } | |
35889917 MK |
1000 | else |
1001 | cache->reg[regnum] = fs->regs.reg[column]; | |
3e2c4033 AC |
1002 | } |
1003 | } | |
cfc14b3a | 1004 | |
8d5a9abc MK |
1005 | /* Eliminate any DWARF2_FRAME_REG_RA rules, and save the information |
1006 | we need for evaluating DWARF2_FRAME_REG_RA_OFFSET rules. */ | |
35889917 MK |
1007 | { |
1008 | int regnum; | |
1009 | ||
1010 | for (regnum = 0; regnum < num_regs; regnum++) | |
1011 | { | |
8d5a9abc MK |
1012 | if (cache->reg[regnum].how == DWARF2_FRAME_REG_RA |
1013 | || cache->reg[regnum].how == DWARF2_FRAME_REG_RA_OFFSET) | |
35889917 | 1014 | { |
05cbe71a MK |
1015 | struct dwarf2_frame_state_reg *retaddr_reg = |
1016 | &fs->regs.reg[fs->retaddr_column]; | |
1017 | ||
d4f10bf2 MK |
1018 | /* It seems rather bizarre to specify an "empty" column as |
1019 | the return adress column. However, this is exactly | |
1020 | what GCC does on some targets. It turns out that GCC | |
1021 | assumes that the return address can be found in the | |
1022 | register corresponding to the return address column. | |
8d5a9abc MK |
1023 | Incidentally, that's how we should treat a return |
1024 | address column specifying "same value" too. */ | |
d4f10bf2 | 1025 | if (fs->retaddr_column < fs->regs.num_regs |
05cbe71a MK |
1026 | && retaddr_reg->how != DWARF2_FRAME_REG_UNSPECIFIED |
1027 | && retaddr_reg->how != DWARF2_FRAME_REG_SAME_VALUE) | |
8d5a9abc MK |
1028 | { |
1029 | if (cache->reg[regnum].how == DWARF2_FRAME_REG_RA) | |
1030 | cache->reg[regnum] = *retaddr_reg; | |
1031 | else | |
1032 | cache->retaddr_reg = *retaddr_reg; | |
1033 | } | |
35889917 MK |
1034 | else |
1035 | { | |
8d5a9abc MK |
1036 | if (cache->reg[regnum].how == DWARF2_FRAME_REG_RA) |
1037 | { | |
1038 | cache->reg[regnum].loc.reg = fs->retaddr_column; | |
1039 | cache->reg[regnum].how = DWARF2_FRAME_REG_SAVED_REG; | |
1040 | } | |
1041 | else | |
1042 | { | |
1043 | cache->retaddr_reg.loc.reg = fs->retaddr_column; | |
1044 | cache->retaddr_reg.how = DWARF2_FRAME_REG_SAVED_REG; | |
1045 | } | |
35889917 MK |
1046 | } |
1047 | } | |
1048 | } | |
1049 | } | |
cfc14b3a | 1050 | |
0228dfb9 DJ |
1051 | if (fs->retaddr_column < fs->regs.num_regs |
1052 | && fs->regs.reg[fs->retaddr_column].how == DWARF2_FRAME_REG_UNDEFINED) | |
1053 | cache->undefined_retaddr = 1; | |
1054 | ||
cfc14b3a MK |
1055 | do_cleanups (old_chain); |
1056 | ||
1057 | *this_cache = cache; | |
1058 | return cache; | |
1059 | } | |
1060 | ||
1061 | static void | |
4a4e5149 | 1062 | dwarf2_frame_this_id (struct frame_info *this_frame, void **this_cache, |
cfc14b3a MK |
1063 | struct frame_id *this_id) |
1064 | { | |
1065 | struct dwarf2_frame_cache *cache = | |
4a4e5149 | 1066 | dwarf2_frame_cache (this_frame, this_cache); |
cfc14b3a | 1067 | |
0228dfb9 DJ |
1068 | if (cache->undefined_retaddr) |
1069 | return; | |
1070 | ||
4a4e5149 | 1071 | (*this_id) = frame_id_build (cache->cfa, get_frame_func (this_frame)); |
93d42b30 DJ |
1072 | } |
1073 | ||
4a4e5149 DJ |
1074 | static struct value * |
1075 | dwarf2_frame_prev_register (struct frame_info *this_frame, void **this_cache, | |
1076 | int regnum) | |
93d42b30 | 1077 | { |
4a4e5149 | 1078 | struct gdbarch *gdbarch = get_frame_arch (this_frame); |
93d42b30 | 1079 | struct dwarf2_frame_cache *cache = |
4a4e5149 DJ |
1080 | dwarf2_frame_cache (this_frame, this_cache); |
1081 | CORE_ADDR addr; | |
1082 | int realnum; | |
cfc14b3a MK |
1083 | |
1084 | switch (cache->reg[regnum].how) | |
1085 | { | |
05cbe71a | 1086 | case DWARF2_FRAME_REG_UNDEFINED: |
3e2c4033 | 1087 | /* If CFI explicitly specified that the value isn't defined, |
e4e9607c | 1088 | mark it as optimized away; the value isn't available. */ |
4a4e5149 | 1089 | return frame_unwind_got_optimized (this_frame, regnum); |
cfc14b3a | 1090 | |
05cbe71a | 1091 | case DWARF2_FRAME_REG_SAVED_OFFSET: |
4a4e5149 DJ |
1092 | addr = cache->cfa + cache->reg[regnum].loc.offset; |
1093 | return frame_unwind_got_memory (this_frame, regnum, addr); | |
cfc14b3a | 1094 | |
05cbe71a | 1095 | case DWARF2_FRAME_REG_SAVED_REG: |
4a4e5149 DJ |
1096 | realnum |
1097 | = gdbarch_dwarf2_reg_to_regnum (gdbarch, cache->reg[regnum].loc.reg); | |
1098 | return frame_unwind_got_register (this_frame, regnum, realnum); | |
cfc14b3a | 1099 | |
05cbe71a | 1100 | case DWARF2_FRAME_REG_SAVED_EXP: |
4a4e5149 DJ |
1101 | addr = execute_stack_op (cache->reg[regnum].loc.exp, |
1102 | cache->reg[regnum].exp_len, | |
1103 | cache->addr_size, this_frame, cache->cfa); | |
1104 | return frame_unwind_got_memory (this_frame, regnum, addr); | |
cfc14b3a | 1105 | |
46ea248b | 1106 | case DWARF2_FRAME_REG_SAVED_VAL_OFFSET: |
4a4e5149 DJ |
1107 | addr = cache->cfa + cache->reg[regnum].loc.offset; |
1108 | return frame_unwind_got_constant (this_frame, regnum, addr); | |
46ea248b AO |
1109 | |
1110 | case DWARF2_FRAME_REG_SAVED_VAL_EXP: | |
4a4e5149 DJ |
1111 | addr = execute_stack_op (cache->reg[regnum].loc.exp, |
1112 | cache->reg[regnum].exp_len, | |
1113 | cache->addr_size, this_frame, cache->cfa); | |
1114 | return frame_unwind_got_constant (this_frame, regnum, addr); | |
46ea248b | 1115 | |
05cbe71a | 1116 | case DWARF2_FRAME_REG_UNSPECIFIED: |
3e2c4033 AC |
1117 | /* GCC, in its infinite wisdom decided to not provide unwind |
1118 | information for registers that are "same value". Since | |
1119 | DWARF2 (3 draft 7) doesn't define such behavior, said | |
1120 | registers are actually undefined (which is different to CFI | |
1121 | "undefined"). Code above issues a complaint about this. | |
1122 | Here just fudge the books, assume GCC, and that the value is | |
1123 | more inner on the stack. */ | |
4a4e5149 | 1124 | return frame_unwind_got_register (this_frame, regnum, regnum); |
3e2c4033 | 1125 | |
05cbe71a | 1126 | case DWARF2_FRAME_REG_SAME_VALUE: |
4a4e5149 | 1127 | return frame_unwind_got_register (this_frame, regnum, regnum); |
cfc14b3a | 1128 | |
05cbe71a | 1129 | case DWARF2_FRAME_REG_CFA: |
4a4e5149 | 1130 | return frame_unwind_got_address (this_frame, regnum, cache->cfa); |
35889917 | 1131 | |
ea7963f0 | 1132 | case DWARF2_FRAME_REG_CFA_OFFSET: |
4a4e5149 DJ |
1133 | addr = cache->cfa + cache->reg[regnum].loc.offset; |
1134 | return frame_unwind_got_address (this_frame, regnum, addr); | |
ea7963f0 | 1135 | |
8d5a9abc | 1136 | case DWARF2_FRAME_REG_RA_OFFSET: |
4a4e5149 DJ |
1137 | addr = cache->reg[regnum].loc.offset; |
1138 | regnum = gdbarch_dwarf2_reg_to_regnum | |
1139 | (gdbarch, cache->retaddr_reg.loc.reg); | |
1140 | addr += get_frame_register_unsigned (this_frame, regnum); | |
1141 | return frame_unwind_got_address (this_frame, regnum, addr); | |
8d5a9abc | 1142 | |
b39cc962 DJ |
1143 | case DWARF2_FRAME_REG_FN: |
1144 | return cache->reg[regnum].loc.fn (this_frame, this_cache, regnum); | |
1145 | ||
cfc14b3a | 1146 | default: |
e2e0b3e5 | 1147 | internal_error (__FILE__, __LINE__, _("Unknown register rule.")); |
cfc14b3a MK |
1148 | } |
1149 | } | |
1150 | ||
4a4e5149 DJ |
1151 | static int |
1152 | dwarf2_frame_sniffer (const struct frame_unwind *self, | |
1153 | struct frame_info *this_frame, void **this_cache) | |
cfc14b3a | 1154 | { |
1ce5d6dd | 1155 | /* Grab an address that is guarenteed to reside somewhere within the |
4a4e5149 | 1156 | function. get_frame_pc(), with a no-return next function, can |
93d42b30 DJ |
1157 | end up returning something past the end of this function's body. |
1158 | If the frame we're sniffing for is a signal frame whose start | |
1159 | address is placed on the stack by the OS, its FDE must | |
4a4e5149 DJ |
1160 | extend one byte before its start address or we could potentially |
1161 | select the FDE of the previous function. */ | |
1162 | CORE_ADDR block_addr = get_frame_address_in_block (this_frame); | |
56c987f6 AO |
1163 | struct dwarf2_fde *fde = dwarf2_frame_find_fde (&block_addr); |
1164 | if (!fde) | |
4a4e5149 | 1165 | return 0; |
3ed09a32 DJ |
1166 | |
1167 | /* On some targets, signal trampolines may have unwind information. | |
1168 | We need to recognize them so that we set the frame type | |
1169 | correctly. */ | |
1170 | ||
56c987f6 | 1171 | if (fde->cie->signal_frame |
4a4e5149 DJ |
1172 | || dwarf2_frame_signal_frame_p (get_frame_arch (this_frame), |
1173 | this_frame)) | |
1174 | return self->type == SIGTRAMP_FRAME; | |
1175 | ||
1176 | return self->type != SIGTRAMP_FRAME; | |
1177 | } | |
1178 | ||
1179 | static const struct frame_unwind dwarf2_frame_unwind = | |
1180 | { | |
1181 | NORMAL_FRAME, | |
1182 | dwarf2_frame_this_id, | |
1183 | dwarf2_frame_prev_register, | |
1184 | NULL, | |
1185 | dwarf2_frame_sniffer | |
1186 | }; | |
1187 | ||
1188 | static const struct frame_unwind dwarf2_signal_frame_unwind = | |
1189 | { | |
1190 | SIGTRAMP_FRAME, | |
1191 | dwarf2_frame_this_id, | |
1192 | dwarf2_frame_prev_register, | |
1193 | NULL, | |
1194 | dwarf2_frame_sniffer | |
1195 | }; | |
cfc14b3a | 1196 | |
4a4e5149 DJ |
1197 | /* Append the DWARF-2 frame unwinders to GDBARCH's list. */ |
1198 | ||
1199 | void | |
1200 | dwarf2_append_unwinders (struct gdbarch *gdbarch) | |
1201 | { | |
1202 | frame_unwind_append_unwinder (gdbarch, &dwarf2_frame_unwind); | |
1203 | frame_unwind_append_unwinder (gdbarch, &dwarf2_signal_frame_unwind); | |
cfc14b3a MK |
1204 | } |
1205 | \f | |
1206 | ||
1207 | /* There is no explicitly defined relationship between the CFA and the | |
1208 | location of frame's local variables and arguments/parameters. | |
1209 | Therefore, frame base methods on this page should probably only be | |
1210 | used as a last resort, just to avoid printing total garbage as a | |
1211 | response to the "info frame" command. */ | |
1212 | ||
1213 | static CORE_ADDR | |
4a4e5149 | 1214 | dwarf2_frame_base_address (struct frame_info *this_frame, void **this_cache) |
cfc14b3a MK |
1215 | { |
1216 | struct dwarf2_frame_cache *cache = | |
4a4e5149 | 1217 | dwarf2_frame_cache (this_frame, this_cache); |
cfc14b3a MK |
1218 | |
1219 | return cache->cfa; | |
1220 | } | |
1221 | ||
1222 | static const struct frame_base dwarf2_frame_base = | |
1223 | { | |
1224 | &dwarf2_frame_unwind, | |
1225 | dwarf2_frame_base_address, | |
1226 | dwarf2_frame_base_address, | |
1227 | dwarf2_frame_base_address | |
1228 | }; | |
1229 | ||
1230 | const struct frame_base * | |
4a4e5149 | 1231 | dwarf2_frame_base_sniffer (struct frame_info *this_frame) |
cfc14b3a | 1232 | { |
4a4e5149 | 1233 | CORE_ADDR block_addr = get_frame_address_in_block (this_frame); |
93d42b30 | 1234 | if (dwarf2_frame_find_fde (&block_addr)) |
cfc14b3a MK |
1235 | return &dwarf2_frame_base; |
1236 | ||
1237 | return NULL; | |
1238 | } | |
1239 | \f | |
8f22cb90 | 1240 | const struct objfile_data *dwarf2_frame_objfile_data; |
0d0e1a63 | 1241 | |
cfc14b3a | 1242 | static unsigned int |
852483bc | 1243 | read_1_byte (bfd *abfd, gdb_byte *buf) |
cfc14b3a | 1244 | { |
852483bc | 1245 | return bfd_get_8 (abfd, buf); |
cfc14b3a MK |
1246 | } |
1247 | ||
1248 | static unsigned int | |
852483bc | 1249 | read_4_bytes (bfd *abfd, gdb_byte *buf) |
cfc14b3a | 1250 | { |
852483bc | 1251 | return bfd_get_32 (abfd, buf); |
cfc14b3a MK |
1252 | } |
1253 | ||
1254 | static ULONGEST | |
852483bc | 1255 | read_8_bytes (bfd *abfd, gdb_byte *buf) |
cfc14b3a | 1256 | { |
852483bc | 1257 | return bfd_get_64 (abfd, buf); |
cfc14b3a MK |
1258 | } |
1259 | ||
1260 | static ULONGEST | |
852483bc | 1261 | read_unsigned_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
cfc14b3a MK |
1262 | { |
1263 | ULONGEST result; | |
1264 | unsigned int num_read; | |
1265 | int shift; | |
852483bc | 1266 | gdb_byte byte; |
cfc14b3a MK |
1267 | |
1268 | result = 0; | |
1269 | shift = 0; | |
1270 | num_read = 0; | |
1271 | ||
1272 | do | |
1273 | { | |
1274 | byte = bfd_get_8 (abfd, (bfd_byte *) buf); | |
1275 | buf++; | |
1276 | num_read++; | |
1277 | result |= ((byte & 0x7f) << shift); | |
1278 | shift += 7; | |
1279 | } | |
1280 | while (byte & 0x80); | |
1281 | ||
1282 | *bytes_read_ptr = num_read; | |
1283 | ||
1284 | return result; | |
1285 | } | |
1286 | ||
1287 | static LONGEST | |
852483bc | 1288 | read_signed_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
cfc14b3a MK |
1289 | { |
1290 | LONGEST result; | |
1291 | int shift; | |
1292 | unsigned int num_read; | |
852483bc | 1293 | gdb_byte byte; |
cfc14b3a MK |
1294 | |
1295 | result = 0; | |
1296 | shift = 0; | |
1297 | num_read = 0; | |
1298 | ||
1299 | do | |
1300 | { | |
1301 | byte = bfd_get_8 (abfd, (bfd_byte *) buf); | |
1302 | buf++; | |
1303 | num_read++; | |
1304 | result |= ((byte & 0x7f) << shift); | |
1305 | shift += 7; | |
1306 | } | |
1307 | while (byte & 0x80); | |
1308 | ||
77e0b926 DJ |
1309 | if (shift < 8 * sizeof (result) && (byte & 0x40)) |
1310 | result |= -(((LONGEST)1) << shift); | |
cfc14b3a MK |
1311 | |
1312 | *bytes_read_ptr = num_read; | |
1313 | ||
1314 | return result; | |
1315 | } | |
1316 | ||
1317 | static ULONGEST | |
852483bc | 1318 | read_initial_length (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
cfc14b3a MK |
1319 | { |
1320 | LONGEST result; | |
1321 | ||
852483bc | 1322 | result = bfd_get_32 (abfd, buf); |
cfc14b3a MK |
1323 | if (result == 0xffffffff) |
1324 | { | |
852483bc | 1325 | result = bfd_get_64 (abfd, buf + 4); |
cfc14b3a MK |
1326 | *bytes_read_ptr = 12; |
1327 | } | |
1328 | else | |
1329 | *bytes_read_ptr = 4; | |
1330 | ||
1331 | return result; | |
1332 | } | |
1333 | \f | |
1334 | ||
1335 | /* Pointer encoding helper functions. */ | |
1336 | ||
1337 | /* GCC supports exception handling based on DWARF2 CFI. However, for | |
1338 | technical reasons, it encodes addresses in its FDE's in a different | |
1339 | way. Several "pointer encodings" are supported. The encoding | |
1340 | that's used for a particular FDE is determined by the 'R' | |
1341 | augmentation in the associated CIE. The argument of this | |
1342 | augmentation is a single byte. | |
1343 | ||
1344 | The address can be encoded as 2 bytes, 4 bytes, 8 bytes, or as a | |
1345 | LEB128. This is encoded in bits 0, 1 and 2. Bit 3 encodes whether | |
1346 | the address is signed or unsigned. Bits 4, 5 and 6 encode how the | |
1347 | address should be interpreted (absolute, relative to the current | |
1348 | position in the FDE, ...). Bit 7, indicates that the address | |
1349 | should be dereferenced. */ | |
1350 | ||
852483bc | 1351 | static gdb_byte |
cfc14b3a MK |
1352 | encoding_for_size (unsigned int size) |
1353 | { | |
1354 | switch (size) | |
1355 | { | |
1356 | case 2: | |
1357 | return DW_EH_PE_udata2; | |
1358 | case 4: | |
1359 | return DW_EH_PE_udata4; | |
1360 | case 8: | |
1361 | return DW_EH_PE_udata8; | |
1362 | default: | |
e2e0b3e5 | 1363 | internal_error (__FILE__, __LINE__, _("Unsupported address size")); |
cfc14b3a MK |
1364 | } |
1365 | } | |
1366 | ||
cfc14b3a | 1367 | static CORE_ADDR |
852483bc | 1368 | read_encoded_value (struct comp_unit *unit, gdb_byte encoding, |
ae0d2f24 UW |
1369 | int ptr_len, gdb_byte *buf, unsigned int *bytes_read_ptr, |
1370 | CORE_ADDR func_base) | |
cfc14b3a | 1371 | { |
68f6cf99 | 1372 | ptrdiff_t offset; |
cfc14b3a MK |
1373 | CORE_ADDR base; |
1374 | ||
1375 | /* GCC currently doesn't generate DW_EH_PE_indirect encodings for | |
1376 | FDE's. */ | |
1377 | if (encoding & DW_EH_PE_indirect) | |
1378 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 1379 | _("Unsupported encoding: DW_EH_PE_indirect")); |
cfc14b3a | 1380 | |
68f6cf99 MK |
1381 | *bytes_read_ptr = 0; |
1382 | ||
cfc14b3a MK |
1383 | switch (encoding & 0x70) |
1384 | { | |
1385 | case DW_EH_PE_absptr: | |
1386 | base = 0; | |
1387 | break; | |
1388 | case DW_EH_PE_pcrel: | |
f2fec864 | 1389 | base = bfd_get_section_vma (unit->abfd, unit->dwarf_frame_section); |
852483bc | 1390 | base += (buf - unit->dwarf_frame_buffer); |
cfc14b3a | 1391 | break; |
0912c7f2 MK |
1392 | case DW_EH_PE_datarel: |
1393 | base = unit->dbase; | |
1394 | break; | |
0fd85043 CV |
1395 | case DW_EH_PE_textrel: |
1396 | base = unit->tbase; | |
1397 | break; | |
03ac2a74 | 1398 | case DW_EH_PE_funcrel: |
ae0d2f24 | 1399 | base = func_base; |
03ac2a74 | 1400 | break; |
68f6cf99 MK |
1401 | case DW_EH_PE_aligned: |
1402 | base = 0; | |
852483bc | 1403 | offset = buf - unit->dwarf_frame_buffer; |
68f6cf99 MK |
1404 | if ((offset % ptr_len) != 0) |
1405 | { | |
1406 | *bytes_read_ptr = ptr_len - (offset % ptr_len); | |
1407 | buf += *bytes_read_ptr; | |
1408 | } | |
1409 | break; | |
cfc14b3a | 1410 | default: |
e2e0b3e5 | 1411 | internal_error (__FILE__, __LINE__, _("Invalid or unsupported encoding")); |
cfc14b3a MK |
1412 | } |
1413 | ||
b04de778 | 1414 | if ((encoding & 0x07) == 0x00) |
f2fec864 DJ |
1415 | { |
1416 | encoding |= encoding_for_size (ptr_len); | |
1417 | if (bfd_get_sign_extend_vma (unit->abfd)) | |
1418 | encoding |= DW_EH_PE_signed; | |
1419 | } | |
cfc14b3a MK |
1420 | |
1421 | switch (encoding & 0x0f) | |
1422 | { | |
a81b10ae MK |
1423 | case DW_EH_PE_uleb128: |
1424 | { | |
1425 | ULONGEST value; | |
852483bc | 1426 | gdb_byte *end_buf = buf + (sizeof (value) + 1) * 8 / 7; |
a7289609 | 1427 | *bytes_read_ptr += read_uleb128 (buf, end_buf, &value) - buf; |
a81b10ae MK |
1428 | return base + value; |
1429 | } | |
cfc14b3a | 1430 | case DW_EH_PE_udata2: |
68f6cf99 | 1431 | *bytes_read_ptr += 2; |
cfc14b3a MK |
1432 | return (base + bfd_get_16 (unit->abfd, (bfd_byte *) buf)); |
1433 | case DW_EH_PE_udata4: | |
68f6cf99 | 1434 | *bytes_read_ptr += 4; |
cfc14b3a MK |
1435 | return (base + bfd_get_32 (unit->abfd, (bfd_byte *) buf)); |
1436 | case DW_EH_PE_udata8: | |
68f6cf99 | 1437 | *bytes_read_ptr += 8; |
cfc14b3a | 1438 | return (base + bfd_get_64 (unit->abfd, (bfd_byte *) buf)); |
a81b10ae MK |
1439 | case DW_EH_PE_sleb128: |
1440 | { | |
1441 | LONGEST value; | |
852483bc | 1442 | gdb_byte *end_buf = buf + (sizeof (value) + 1) * 8 / 7; |
a7289609 | 1443 | *bytes_read_ptr += read_sleb128 (buf, end_buf, &value) - buf; |
a81b10ae MK |
1444 | return base + value; |
1445 | } | |
cfc14b3a | 1446 | case DW_EH_PE_sdata2: |
68f6cf99 | 1447 | *bytes_read_ptr += 2; |
cfc14b3a MK |
1448 | return (base + bfd_get_signed_16 (unit->abfd, (bfd_byte *) buf)); |
1449 | case DW_EH_PE_sdata4: | |
68f6cf99 | 1450 | *bytes_read_ptr += 4; |
cfc14b3a MK |
1451 | return (base + bfd_get_signed_32 (unit->abfd, (bfd_byte *) buf)); |
1452 | case DW_EH_PE_sdata8: | |
68f6cf99 | 1453 | *bytes_read_ptr += 8; |
cfc14b3a MK |
1454 | return (base + bfd_get_signed_64 (unit->abfd, (bfd_byte *) buf)); |
1455 | default: | |
e2e0b3e5 | 1456 | internal_error (__FILE__, __LINE__, _("Invalid or unsupported encoding")); |
cfc14b3a MK |
1457 | } |
1458 | } | |
1459 | \f | |
1460 | ||
1461 | /* GCC uses a single CIE for all FDEs in a .debug_frame section. | |
1462 | That's why we use a simple linked list here. */ | |
1463 | ||
1464 | static struct dwarf2_cie * | |
1465 | find_cie (struct comp_unit *unit, ULONGEST cie_pointer) | |
1466 | { | |
1467 | struct dwarf2_cie *cie = unit->cie; | |
1468 | ||
1469 | while (cie) | |
1470 | { | |
1471 | if (cie->cie_pointer == cie_pointer) | |
1472 | return cie; | |
1473 | ||
1474 | cie = cie->next; | |
1475 | } | |
1476 | ||
1477 | return NULL; | |
1478 | } | |
1479 | ||
1480 | static void | |
1481 | add_cie (struct comp_unit *unit, struct dwarf2_cie *cie) | |
1482 | { | |
1483 | cie->next = unit->cie; | |
1484 | unit->cie = cie; | |
ae0d2f24 | 1485 | cie->unit = unit; |
cfc14b3a MK |
1486 | } |
1487 | ||
1488 | /* Find the FDE for *PC. Return a pointer to the FDE, and store the | |
1489 | inital location associated with it into *PC. */ | |
1490 | ||
1491 | static struct dwarf2_fde * | |
1492 | dwarf2_frame_find_fde (CORE_ADDR *pc) | |
1493 | { | |
1494 | struct objfile *objfile; | |
1495 | ||
1496 | ALL_OBJFILES (objfile) | |
1497 | { | |
1498 | struct dwarf2_fde *fde; | |
1499 | CORE_ADDR offset; | |
1500 | ||
8f22cb90 | 1501 | fde = objfile_data (objfile, dwarf2_frame_objfile_data); |
4ae9ee8e DJ |
1502 | if (fde == NULL) |
1503 | continue; | |
1504 | ||
1505 | gdb_assert (objfile->section_offsets); | |
1506 | offset = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
1507 | ||
cfc14b3a MK |
1508 | while (fde) |
1509 | { | |
1510 | if (*pc >= fde->initial_location + offset | |
1511 | && *pc < fde->initial_location + offset + fde->address_range) | |
1512 | { | |
1513 | *pc = fde->initial_location + offset; | |
1514 | return fde; | |
1515 | } | |
1516 | ||
1517 | fde = fde->next; | |
1518 | } | |
1519 | } | |
1520 | ||
1521 | return NULL; | |
1522 | } | |
1523 | ||
1524 | static void | |
1525 | add_fde (struct comp_unit *unit, struct dwarf2_fde *fde) | |
1526 | { | |
8f22cb90 MK |
1527 | fde->next = objfile_data (unit->objfile, dwarf2_frame_objfile_data); |
1528 | set_objfile_data (unit->objfile, dwarf2_frame_objfile_data, fde); | |
cfc14b3a MK |
1529 | } |
1530 | ||
1531 | #ifdef CC_HAS_LONG_LONG | |
1532 | #define DW64_CIE_ID 0xffffffffffffffffULL | |
1533 | #else | |
1534 | #define DW64_CIE_ID ~0 | |
1535 | #endif | |
1536 | ||
852483bc MK |
1537 | static gdb_byte *decode_frame_entry (struct comp_unit *unit, gdb_byte *start, |
1538 | int eh_frame_p); | |
cfc14b3a | 1539 | |
6896c0c7 RH |
1540 | /* Decode the next CIE or FDE. Return NULL if invalid input, otherwise |
1541 | the next byte to be processed. */ | |
852483bc MK |
1542 | static gdb_byte * |
1543 | decode_frame_entry_1 (struct comp_unit *unit, gdb_byte *start, int eh_frame_p) | |
cfc14b3a | 1544 | { |
5e2b427d | 1545 | struct gdbarch *gdbarch = get_objfile_arch (unit->objfile); |
852483bc | 1546 | gdb_byte *buf, *end; |
cfc14b3a MK |
1547 | LONGEST length; |
1548 | unsigned int bytes_read; | |
6896c0c7 RH |
1549 | int dwarf64_p; |
1550 | ULONGEST cie_id; | |
cfc14b3a | 1551 | ULONGEST cie_pointer; |
cfc14b3a | 1552 | |
6896c0c7 | 1553 | buf = start; |
cfc14b3a MK |
1554 | length = read_initial_length (unit->abfd, buf, &bytes_read); |
1555 | buf += bytes_read; | |
1556 | end = buf + length; | |
1557 | ||
6896c0c7 RH |
1558 | /* Are we still within the section? */ |
1559 | if (end > unit->dwarf_frame_buffer + unit->dwarf_frame_size) | |
1560 | return NULL; | |
1561 | ||
cfc14b3a MK |
1562 | if (length == 0) |
1563 | return end; | |
1564 | ||
6896c0c7 RH |
1565 | /* Distinguish between 32 and 64-bit encoded frame info. */ |
1566 | dwarf64_p = (bytes_read == 12); | |
cfc14b3a | 1567 | |
6896c0c7 | 1568 | /* In a .eh_frame section, zero is used to distinguish CIEs from FDEs. */ |
cfc14b3a MK |
1569 | if (eh_frame_p) |
1570 | cie_id = 0; | |
1571 | else if (dwarf64_p) | |
1572 | cie_id = DW64_CIE_ID; | |
6896c0c7 RH |
1573 | else |
1574 | cie_id = DW_CIE_ID; | |
cfc14b3a MK |
1575 | |
1576 | if (dwarf64_p) | |
1577 | { | |
1578 | cie_pointer = read_8_bytes (unit->abfd, buf); | |
1579 | buf += 8; | |
1580 | } | |
1581 | else | |
1582 | { | |
1583 | cie_pointer = read_4_bytes (unit->abfd, buf); | |
1584 | buf += 4; | |
1585 | } | |
1586 | ||
1587 | if (cie_pointer == cie_id) | |
1588 | { | |
1589 | /* This is a CIE. */ | |
1590 | struct dwarf2_cie *cie; | |
1591 | char *augmentation; | |
28ba0b33 | 1592 | unsigned int cie_version; |
cfc14b3a MK |
1593 | |
1594 | /* Record the offset into the .debug_frame section of this CIE. */ | |
1595 | cie_pointer = start - unit->dwarf_frame_buffer; | |
1596 | ||
1597 | /* Check whether we've already read it. */ | |
1598 | if (find_cie (unit, cie_pointer)) | |
1599 | return end; | |
1600 | ||
1601 | cie = (struct dwarf2_cie *) | |
8b92e4d5 | 1602 | obstack_alloc (&unit->objfile->objfile_obstack, |
cfc14b3a MK |
1603 | sizeof (struct dwarf2_cie)); |
1604 | cie->initial_instructions = NULL; | |
1605 | cie->cie_pointer = cie_pointer; | |
1606 | ||
1607 | /* The encoding for FDE's in a normal .debug_frame section | |
32b05c07 MK |
1608 | depends on the target address size. */ |
1609 | cie->encoding = DW_EH_PE_absptr; | |
cfc14b3a | 1610 | |
ae0d2f24 UW |
1611 | /* The target address size. For .eh_frame FDEs this is considered |
1612 | equal to the size of a target pointer. For .dwarf_frame FDEs, | |
1613 | this is supposed to be the target address size from the associated | |
1614 | CU header. FIXME: We do not have a good way to determine the | |
1615 | latter. Always use the target pointer size for now. */ | |
5e2b427d | 1616 | cie->addr_size = gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT; |
ae0d2f24 | 1617 | |
56c987f6 AO |
1618 | /* We'll determine the final value later, but we need to |
1619 | initialize it conservatively. */ | |
1620 | cie->signal_frame = 0; | |
1621 | ||
cfc14b3a | 1622 | /* Check version number. */ |
28ba0b33 PB |
1623 | cie_version = read_1_byte (unit->abfd, buf); |
1624 | if (cie_version != 1 && cie_version != 3) | |
6896c0c7 | 1625 | return NULL; |
303b6f5d | 1626 | cie->version = cie_version; |
cfc14b3a MK |
1627 | buf += 1; |
1628 | ||
1629 | /* Interpret the interesting bits of the augmentation. */ | |
303b6f5d | 1630 | cie->augmentation = augmentation = (char *) buf; |
852483bc | 1631 | buf += (strlen (augmentation) + 1); |
cfc14b3a | 1632 | |
303b6f5d DJ |
1633 | /* Ignore armcc augmentations. We only use them for quirks, |
1634 | and that doesn't happen until later. */ | |
1635 | if (strncmp (augmentation, "armcc", 5) == 0) | |
1636 | augmentation += strlen (augmentation); | |
1637 | ||
cfc14b3a MK |
1638 | /* The GCC 2.x "eh" augmentation has a pointer immediately |
1639 | following the augmentation string, so it must be handled | |
1640 | first. */ | |
1641 | if (augmentation[0] == 'e' && augmentation[1] == 'h') | |
1642 | { | |
1643 | /* Skip. */ | |
5e2b427d | 1644 | buf += gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT; |
cfc14b3a MK |
1645 | augmentation += 2; |
1646 | } | |
1647 | ||
1648 | cie->code_alignment_factor = | |
1649 | read_unsigned_leb128 (unit->abfd, buf, &bytes_read); | |
1650 | buf += bytes_read; | |
1651 | ||
1652 | cie->data_alignment_factor = | |
1653 | read_signed_leb128 (unit->abfd, buf, &bytes_read); | |
1654 | buf += bytes_read; | |
1655 | ||
28ba0b33 PB |
1656 | if (cie_version == 1) |
1657 | { | |
1658 | cie->return_address_register = read_1_byte (unit->abfd, buf); | |
1659 | bytes_read = 1; | |
1660 | } | |
1661 | else | |
1662 | cie->return_address_register = read_unsigned_leb128 (unit->abfd, buf, | |
1663 | &bytes_read); | |
4fc771b8 | 1664 | cie->return_address_register |
5e2b427d | 1665 | = dwarf2_frame_adjust_regnum (gdbarch, |
4fc771b8 DJ |
1666 | cie->return_address_register, |
1667 | eh_frame_p); | |
4bf8967c | 1668 | |
28ba0b33 | 1669 | buf += bytes_read; |
cfc14b3a | 1670 | |
7131cb6e RH |
1671 | cie->saw_z_augmentation = (*augmentation == 'z'); |
1672 | if (cie->saw_z_augmentation) | |
cfc14b3a MK |
1673 | { |
1674 | ULONGEST length; | |
1675 | ||
1676 | length = read_unsigned_leb128 (unit->abfd, buf, &bytes_read); | |
1677 | buf += bytes_read; | |
6896c0c7 RH |
1678 | if (buf > end) |
1679 | return NULL; | |
cfc14b3a MK |
1680 | cie->initial_instructions = buf + length; |
1681 | augmentation++; | |
1682 | } | |
1683 | ||
1684 | while (*augmentation) | |
1685 | { | |
1686 | /* "L" indicates a byte showing how the LSDA pointer is encoded. */ | |
1687 | if (*augmentation == 'L') | |
1688 | { | |
1689 | /* Skip. */ | |
1690 | buf++; | |
1691 | augmentation++; | |
1692 | } | |
1693 | ||
1694 | /* "R" indicates a byte indicating how FDE addresses are encoded. */ | |
1695 | else if (*augmentation == 'R') | |
1696 | { | |
1697 | cie->encoding = *buf++; | |
1698 | augmentation++; | |
1699 | } | |
1700 | ||
1701 | /* "P" indicates a personality routine in the CIE augmentation. */ | |
1702 | else if (*augmentation == 'P') | |
1703 | { | |
1234d960 | 1704 | /* Skip. Avoid indirection since we throw away the result. */ |
852483bc | 1705 | gdb_byte encoding = (*buf++) & ~DW_EH_PE_indirect; |
ae0d2f24 UW |
1706 | read_encoded_value (unit, encoding, cie->addr_size, |
1707 | buf, &bytes_read, 0); | |
f724bf08 | 1708 | buf += bytes_read; |
cfc14b3a MK |
1709 | augmentation++; |
1710 | } | |
1711 | ||
56c987f6 AO |
1712 | /* "S" indicates a signal frame, such that the return |
1713 | address must not be decremented to locate the call frame | |
1714 | info for the previous frame; it might even be the first | |
1715 | instruction of a function, so decrementing it would take | |
1716 | us to a different function. */ | |
1717 | else if (*augmentation == 'S') | |
1718 | { | |
1719 | cie->signal_frame = 1; | |
1720 | augmentation++; | |
1721 | } | |
1722 | ||
3e9a2e52 DJ |
1723 | /* Otherwise we have an unknown augmentation. Assume that either |
1724 | there is no augmentation data, or we saw a 'z' prefix. */ | |
cfc14b3a MK |
1725 | else |
1726 | { | |
3e9a2e52 DJ |
1727 | if (cie->initial_instructions) |
1728 | buf = cie->initial_instructions; | |
cfc14b3a MK |
1729 | break; |
1730 | } | |
1731 | } | |
1732 | ||
1733 | cie->initial_instructions = buf; | |
1734 | cie->end = end; | |
1735 | ||
1736 | add_cie (unit, cie); | |
1737 | } | |
1738 | else | |
1739 | { | |
1740 | /* This is a FDE. */ | |
1741 | struct dwarf2_fde *fde; | |
1742 | ||
6896c0c7 RH |
1743 | /* In an .eh_frame section, the CIE pointer is the delta between the |
1744 | address within the FDE where the CIE pointer is stored and the | |
1745 | address of the CIE. Convert it to an offset into the .eh_frame | |
1746 | section. */ | |
cfc14b3a MK |
1747 | if (eh_frame_p) |
1748 | { | |
cfc14b3a MK |
1749 | cie_pointer = buf - unit->dwarf_frame_buffer - cie_pointer; |
1750 | cie_pointer -= (dwarf64_p ? 8 : 4); | |
1751 | } | |
1752 | ||
6896c0c7 RH |
1753 | /* In either case, validate the result is still within the section. */ |
1754 | if (cie_pointer >= unit->dwarf_frame_size) | |
1755 | return NULL; | |
1756 | ||
cfc14b3a | 1757 | fde = (struct dwarf2_fde *) |
8b92e4d5 | 1758 | obstack_alloc (&unit->objfile->objfile_obstack, |
cfc14b3a MK |
1759 | sizeof (struct dwarf2_fde)); |
1760 | fde->cie = find_cie (unit, cie_pointer); | |
1761 | if (fde->cie == NULL) | |
1762 | { | |
1763 | decode_frame_entry (unit, unit->dwarf_frame_buffer + cie_pointer, | |
1764 | eh_frame_p); | |
1765 | fde->cie = find_cie (unit, cie_pointer); | |
1766 | } | |
1767 | ||
1768 | gdb_assert (fde->cie != NULL); | |
1769 | ||
1770 | fde->initial_location = | |
ae0d2f24 UW |
1771 | read_encoded_value (unit, fde->cie->encoding, fde->cie->addr_size, |
1772 | buf, &bytes_read, 0); | |
cfc14b3a MK |
1773 | buf += bytes_read; |
1774 | ||
1775 | fde->address_range = | |
ae0d2f24 UW |
1776 | read_encoded_value (unit, fde->cie->encoding & 0x0f, |
1777 | fde->cie->addr_size, buf, &bytes_read, 0); | |
cfc14b3a MK |
1778 | buf += bytes_read; |
1779 | ||
7131cb6e RH |
1780 | /* A 'z' augmentation in the CIE implies the presence of an |
1781 | augmentation field in the FDE as well. The only thing known | |
1782 | to be in here at present is the LSDA entry for EH. So we | |
1783 | can skip the whole thing. */ | |
1784 | if (fde->cie->saw_z_augmentation) | |
1785 | { | |
1786 | ULONGEST length; | |
1787 | ||
1788 | length = read_unsigned_leb128 (unit->abfd, buf, &bytes_read); | |
1789 | buf += bytes_read + length; | |
6896c0c7 RH |
1790 | if (buf > end) |
1791 | return NULL; | |
7131cb6e RH |
1792 | } |
1793 | ||
cfc14b3a MK |
1794 | fde->instructions = buf; |
1795 | fde->end = end; | |
1796 | ||
4bf8967c AS |
1797 | fde->eh_frame_p = eh_frame_p; |
1798 | ||
cfc14b3a MK |
1799 | add_fde (unit, fde); |
1800 | } | |
1801 | ||
1802 | return end; | |
1803 | } | |
6896c0c7 RH |
1804 | |
1805 | /* Read a CIE or FDE in BUF and decode it. */ | |
852483bc MK |
1806 | static gdb_byte * |
1807 | decode_frame_entry (struct comp_unit *unit, gdb_byte *start, int eh_frame_p) | |
6896c0c7 RH |
1808 | { |
1809 | enum { NONE, ALIGN4, ALIGN8, FAIL } workaround = NONE; | |
852483bc | 1810 | gdb_byte *ret; |
6896c0c7 RH |
1811 | const char *msg; |
1812 | ptrdiff_t start_offset; | |
1813 | ||
1814 | while (1) | |
1815 | { | |
1816 | ret = decode_frame_entry_1 (unit, start, eh_frame_p); | |
1817 | if (ret != NULL) | |
1818 | break; | |
1819 | ||
1820 | /* We have corrupt input data of some form. */ | |
1821 | ||
1822 | /* ??? Try, weakly, to work around compiler/assembler/linker bugs | |
1823 | and mismatches wrt padding and alignment of debug sections. */ | |
1824 | /* Note that there is no requirement in the standard for any | |
1825 | alignment at all in the frame unwind sections. Testing for | |
1826 | alignment before trying to interpret data would be incorrect. | |
1827 | ||
1828 | However, GCC traditionally arranged for frame sections to be | |
1829 | sized such that the FDE length and CIE fields happen to be | |
1830 | aligned (in theory, for performance). This, unfortunately, | |
1831 | was done with .align directives, which had the side effect of | |
1832 | forcing the section to be aligned by the linker. | |
1833 | ||
1834 | This becomes a problem when you have some other producer that | |
1835 | creates frame sections that are not as strictly aligned. That | |
1836 | produces a hole in the frame info that gets filled by the | |
1837 | linker with zeros. | |
1838 | ||
1839 | The GCC behaviour is arguably a bug, but it's effectively now | |
1840 | part of the ABI, so we're now stuck with it, at least at the | |
1841 | object file level. A smart linker may decide, in the process | |
1842 | of compressing duplicate CIE information, that it can rewrite | |
1843 | the entire output section without this extra padding. */ | |
1844 | ||
1845 | start_offset = start - unit->dwarf_frame_buffer; | |
1846 | if (workaround < ALIGN4 && (start_offset & 3) != 0) | |
1847 | { | |
1848 | start += 4 - (start_offset & 3); | |
1849 | workaround = ALIGN4; | |
1850 | continue; | |
1851 | } | |
1852 | if (workaround < ALIGN8 && (start_offset & 7) != 0) | |
1853 | { | |
1854 | start += 8 - (start_offset & 7); | |
1855 | workaround = ALIGN8; | |
1856 | continue; | |
1857 | } | |
1858 | ||
1859 | /* Nothing left to try. Arrange to return as if we've consumed | |
1860 | the entire input section. Hopefully we'll get valid info from | |
1861 | the other of .debug_frame/.eh_frame. */ | |
1862 | workaround = FAIL; | |
1863 | ret = unit->dwarf_frame_buffer + unit->dwarf_frame_size; | |
1864 | break; | |
1865 | } | |
1866 | ||
1867 | switch (workaround) | |
1868 | { | |
1869 | case NONE: | |
1870 | break; | |
1871 | ||
1872 | case ALIGN4: | |
1873 | complaint (&symfile_complaints, | |
e2e0b3e5 | 1874 | _("Corrupt data in %s:%s; align 4 workaround apparently succeeded"), |
6896c0c7 RH |
1875 | unit->dwarf_frame_section->owner->filename, |
1876 | unit->dwarf_frame_section->name); | |
1877 | break; | |
1878 | ||
1879 | case ALIGN8: | |
1880 | complaint (&symfile_complaints, | |
e2e0b3e5 | 1881 | _("Corrupt data in %s:%s; align 8 workaround apparently succeeded"), |
6896c0c7 RH |
1882 | unit->dwarf_frame_section->owner->filename, |
1883 | unit->dwarf_frame_section->name); | |
1884 | break; | |
1885 | ||
1886 | default: | |
1887 | complaint (&symfile_complaints, | |
e2e0b3e5 | 1888 | _("Corrupt data in %s:%s"), |
6896c0c7 RH |
1889 | unit->dwarf_frame_section->owner->filename, |
1890 | unit->dwarf_frame_section->name); | |
1891 | break; | |
1892 | } | |
1893 | ||
1894 | return ret; | |
1895 | } | |
cfc14b3a MK |
1896 | \f |
1897 | ||
1898 | /* FIXME: kettenis/20030504: This still needs to be integrated with | |
1899 | dwarf2read.c in a better way. */ | |
1900 | ||
1901 | /* Imported from dwarf2read.c. */ | |
cfc14b3a | 1902 | extern asection *dwarf_frame_section; |
cfc14b3a MK |
1903 | extern asection *dwarf_eh_frame_section; |
1904 | ||
1905 | /* Imported from dwarf2read.c. */ | |
1193688d | 1906 | extern gdb_byte *dwarf2_read_section (struct objfile *objfile, asection *sectp); |
cfc14b3a MK |
1907 | |
1908 | void | |
1909 | dwarf2_build_frame_info (struct objfile *objfile) | |
1910 | { | |
ae0d2f24 | 1911 | struct comp_unit *unit; |
852483bc | 1912 | gdb_byte *frame_ptr; |
cfc14b3a MK |
1913 | |
1914 | /* Build a minimal decoding of the DWARF2 compilation unit. */ | |
ae0d2f24 UW |
1915 | unit = (struct comp_unit *) obstack_alloc (&objfile->objfile_obstack, |
1916 | sizeof (struct comp_unit)); | |
1917 | unit->abfd = objfile->obfd; | |
1918 | unit->objfile = objfile; | |
1919 | unit->dbase = 0; | |
1920 | unit->tbase = 0; | |
cfc14b3a MK |
1921 | |
1922 | /* First add the information from the .eh_frame section. That way, | |
1923 | the FDEs from that section are searched last. */ | |
188dd5d6 | 1924 | if (dwarf_eh_frame_section) |
cfc14b3a | 1925 | { |
0fd85043 | 1926 | asection *got, *txt; |
0912c7f2 | 1927 | |
ae0d2f24 UW |
1928 | unit->cie = NULL; |
1929 | unit->dwarf_frame_buffer = dwarf2_read_section (objfile, | |
1930 | dwarf_eh_frame_section); | |
cfc14b3a | 1931 | |
ae0d2f24 UW |
1932 | unit->dwarf_frame_size = bfd_get_section_size (dwarf_eh_frame_section); |
1933 | unit->dwarf_frame_section = dwarf_eh_frame_section; | |
cfc14b3a | 1934 | |
0912c7f2 | 1935 | /* FIXME: kettenis/20030602: This is the DW_EH_PE_datarel base |
37b517aa MK |
1936 | that is used for the i386/amd64 target, which currently is |
1937 | the only target in GCC that supports/uses the | |
1938 | DW_EH_PE_datarel encoding. */ | |
ae0d2f24 | 1939 | got = bfd_get_section_by_name (unit->abfd, ".got"); |
0912c7f2 | 1940 | if (got) |
ae0d2f24 | 1941 | unit->dbase = got->vma; |
0912c7f2 | 1942 | |
22c7ba1a MK |
1943 | /* GCC emits the DW_EH_PE_textrel encoding type on sh and ia64 |
1944 | so far. */ | |
ae0d2f24 | 1945 | txt = bfd_get_section_by_name (unit->abfd, ".text"); |
0fd85043 | 1946 | if (txt) |
ae0d2f24 | 1947 | unit->tbase = txt->vma; |
0fd85043 | 1948 | |
ae0d2f24 UW |
1949 | frame_ptr = unit->dwarf_frame_buffer; |
1950 | while (frame_ptr < unit->dwarf_frame_buffer + unit->dwarf_frame_size) | |
1951 | frame_ptr = decode_frame_entry (unit, frame_ptr, 1); | |
cfc14b3a MK |
1952 | } |
1953 | ||
188dd5d6 | 1954 | if (dwarf_frame_section) |
cfc14b3a | 1955 | { |
ae0d2f24 UW |
1956 | unit->cie = NULL; |
1957 | unit->dwarf_frame_buffer = dwarf2_read_section (objfile, | |
1958 | dwarf_frame_section); | |
1959 | unit->dwarf_frame_size = bfd_get_section_size (dwarf_frame_section); | |
1960 | unit->dwarf_frame_section = dwarf_frame_section; | |
1961 | ||
1962 | frame_ptr = unit->dwarf_frame_buffer; | |
1963 | while (frame_ptr < unit->dwarf_frame_buffer + unit->dwarf_frame_size) | |
1964 | frame_ptr = decode_frame_entry (unit, frame_ptr, 0); | |
cfc14b3a MK |
1965 | } |
1966 | } | |
0d0e1a63 MK |
1967 | |
1968 | /* Provide a prototype to silence -Wmissing-prototypes. */ | |
1969 | void _initialize_dwarf2_frame (void); | |
1970 | ||
1971 | void | |
1972 | _initialize_dwarf2_frame (void) | |
1973 | { | |
030f20e1 | 1974 | dwarf2_frame_data = gdbarch_data_register_pre_init (dwarf2_frame_init); |
8f22cb90 | 1975 | dwarf2_frame_objfile_data = register_objfile_data (); |
0d0e1a63 | 1976 | } |