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