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