1 /* Frame unwinder for frames with DWARF Call Frame Information.
3 Copyright (C) 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011
4 Free Software Foundation, Inc.
6 Contributed by Mark Kettenis.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "dwarf2expr.h"
27 #include "frame-base.h"
28 #include "frame-unwind.h"
36 #include "gdb_assert.h"
37 #include "gdb_string.h"
39 #include "complaints.h"
40 #include "dwarf2-frame.h"
42 #include "dwarf2loc.h"
43 #include "exceptions.h"
47 /* Call Frame Information (CFI). */
49 /* Common Information Entry (CIE). */
53 /* Computation Unit for this CIE. */
54 struct comp_unit *unit;
56 /* Offset into the .debug_frame section where this CIE was found.
57 Used to identify this CIE. */
60 /* Constant that is factored out of all advance location
62 ULONGEST code_alignment_factor;
64 /* Constants that is factored out of all offset instructions. */
65 LONGEST data_alignment_factor;
67 /* Return address column. */
68 ULONGEST return_address_register;
70 /* Instruction sequence to initialize a register set. */
71 gdb_byte *initial_instructions;
74 /* Saved augmentation, in case it's needed later. */
77 /* Encoding of addresses. */
80 /* Target address size in bytes. */
83 /* Target pointer size in bytes. */
86 /* True if a 'z' augmentation existed. */
87 unsigned char saw_z_augmentation;
89 /* True if an 'S' augmentation existed. */
90 unsigned char signal_frame;
92 /* The version recorded in the CIE. */
93 unsigned char version;
95 /* The segment size. */
96 unsigned char segment_size;
99 struct dwarf2_cie_table
102 struct dwarf2_cie **entries;
105 /* Frame Description Entry (FDE). */
109 /* CIE for this FDE. */
110 struct dwarf2_cie *cie;
112 /* First location associated with this FDE. */
113 CORE_ADDR initial_location;
115 /* Number of bytes of program instructions described by this FDE. */
116 CORE_ADDR address_range;
118 /* Instruction sequence. */
119 gdb_byte *instructions;
122 /* True if this FDE is read from a .eh_frame instead of a .debug_frame
124 unsigned char eh_frame_p;
127 struct dwarf2_fde_table
130 struct dwarf2_fde **entries;
133 /* A minimal decoding of DWARF2 compilation units. We only decode
134 what's needed to get to the call frame information. */
138 /* Keep the bfd convenient. */
141 struct objfile *objfile;
143 /* Pointer to the .debug_frame section loaded into memory. */
144 gdb_byte *dwarf_frame_buffer;
146 /* Length of the loaded .debug_frame section. */
147 bfd_size_type dwarf_frame_size;
149 /* Pointer to the .debug_frame section. */
150 asection *dwarf_frame_section;
152 /* Base for DW_EH_PE_datarel encodings. */
155 /* Base for DW_EH_PE_textrel encodings. */
159 static struct dwarf2_fde *dwarf2_frame_find_fde (CORE_ADDR *pc,
160 CORE_ADDR *out_offset);
162 static int dwarf2_frame_adjust_regnum (struct gdbarch *gdbarch, int regnum,
165 static CORE_ADDR read_encoded_value (struct comp_unit *unit, gdb_byte encoding,
166 int ptr_len, const gdb_byte *buf,
167 unsigned int *bytes_read_ptr,
168 CORE_ADDR func_base);
171 /* Structure describing a frame state. */
173 struct dwarf2_frame_state
175 /* Each register save state can be described in terms of a CFA slot,
176 another register, or a location expression. */
177 struct dwarf2_frame_state_reg_info
179 struct dwarf2_frame_state_reg *reg;
189 const gdb_byte *cfa_exp;
191 /* Used to implement DW_CFA_remember_state. */
192 struct dwarf2_frame_state_reg_info *prev;
195 /* The PC described by the current frame state. */
198 /* Initial register set from the CIE.
199 Used to implement DW_CFA_restore. */
200 struct dwarf2_frame_state_reg_info initial;
202 /* The information we care about from the CIE. */
205 ULONGEST retaddr_column;
207 /* Flags for known producer quirks. */
209 /* The ARM compilers, in DWARF2 mode, assume that DW_CFA_def_cfa
210 and DW_CFA_def_cfa_offset takes a factored offset. */
211 int armcc_cfa_offsets_sf;
213 /* The ARM compilers, in DWARF2 or DWARF3 mode, may assume that
214 the CFA is defined as REG - OFFSET rather than REG + OFFSET. */
215 int armcc_cfa_offsets_reversed;
218 /* Store the length the expression for the CFA in the `cfa_reg' field,
219 which is unused in that case. */
220 #define cfa_exp_len cfa_reg
222 /* Assert that the register set RS is large enough to store gdbarch_num_regs
223 columns. If necessary, enlarge the register set. */
226 dwarf2_frame_state_alloc_regs (struct dwarf2_frame_state_reg_info *rs,
229 size_t size = sizeof (struct dwarf2_frame_state_reg);
231 if (num_regs <= rs->num_regs)
234 rs->reg = (struct dwarf2_frame_state_reg *)
235 xrealloc (rs->reg, num_regs * size);
237 /* Initialize newly allocated registers. */
238 memset (rs->reg + rs->num_regs, 0, (num_regs - rs->num_regs) * size);
239 rs->num_regs = num_regs;
242 /* Copy the register columns in register set RS into newly allocated
243 memory and return a pointer to this newly created copy. */
245 static struct dwarf2_frame_state_reg *
246 dwarf2_frame_state_copy_regs (struct dwarf2_frame_state_reg_info *rs)
248 size_t size = rs->num_regs * sizeof (struct dwarf2_frame_state_reg);
249 struct dwarf2_frame_state_reg *reg;
251 reg = (struct dwarf2_frame_state_reg *) xmalloc (size);
252 memcpy (reg, rs->reg, size);
257 /* Release the memory allocated to register set RS. */
260 dwarf2_frame_state_free_regs (struct dwarf2_frame_state_reg_info *rs)
264 dwarf2_frame_state_free_regs (rs->prev);
271 /* Release the memory allocated to the frame state FS. */
274 dwarf2_frame_state_free (void *p)
276 struct dwarf2_frame_state *fs = p;
278 dwarf2_frame_state_free_regs (fs->initial.prev);
279 dwarf2_frame_state_free_regs (fs->regs.prev);
280 xfree (fs->initial.reg);
281 xfree (fs->regs.reg);
286 /* Helper functions for execute_stack_op. */
289 read_reg (void *baton, int reg)
291 struct frame_info *this_frame = (struct frame_info *) baton;
292 struct gdbarch *gdbarch = get_frame_arch (this_frame);
296 regnum = gdbarch_dwarf2_reg_to_regnum (gdbarch, reg);
298 buf = alloca (register_size (gdbarch, regnum));
299 get_frame_register (this_frame, regnum, buf);
301 /* Convert the register to an integer. This returns a LONGEST
302 rather than a CORE_ADDR, but unpack_pointer does the same thing
303 under the covers, and this makes more sense for non-pointer
304 registers. Maybe read_reg and the associated interfaces should
305 deal with "struct value" instead of CORE_ADDR. */
306 return unpack_long (register_type (gdbarch, regnum), buf);
310 read_mem (void *baton, gdb_byte *buf, CORE_ADDR addr, size_t len)
312 read_memory (addr, buf, len);
316 no_get_frame_base (void *baton, const gdb_byte **start, size_t *length)
318 internal_error (__FILE__, __LINE__,
319 _("Support for DW_OP_fbreg is unimplemented"));
322 /* Helper function for execute_stack_op. */
325 no_get_frame_cfa (void *baton)
327 internal_error (__FILE__, __LINE__,
328 _("Support for DW_OP_call_frame_cfa is unimplemented"));
331 /* Helper function for execute_stack_op. */
334 no_get_frame_pc (void *baton)
336 internal_error (__FILE__, __LINE__, _("\
337 Support for DW_OP_GNU_implicit_pointer is unimplemented"));
341 no_get_tls_address (void *baton, CORE_ADDR offset)
343 internal_error (__FILE__, __LINE__, _("\
344 Support for DW_OP_GNU_push_tls_address is unimplemented"));
347 /* Helper function for execute_stack_op. */
350 no_dwarf_call (struct dwarf_expr_context *ctx, size_t die_offset)
352 internal_error (__FILE__, __LINE__,
353 _("Support for DW_OP_call* is invalid in CFI"));
356 /* Helper function for execute_stack_op. */
359 no_base_type (struct dwarf_expr_context *ctx, size_t die)
361 error (_("Support for typed DWARF is not supported in CFI"));
364 /* Execute the required actions for both the DW_CFA_restore and
365 DW_CFA_restore_extended instructions. */
367 dwarf2_restore_rule (struct gdbarch *gdbarch, ULONGEST reg_num,
368 struct dwarf2_frame_state *fs, int eh_frame_p)
372 gdb_assert (fs->initial.reg);
373 reg = dwarf2_frame_adjust_regnum (gdbarch, reg_num, eh_frame_p);
374 dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1);
376 /* Check if this register was explicitly initialized in the
377 CIE initial instructions. If not, default the rule to
379 if (reg < fs->initial.num_regs)
380 fs->regs.reg[reg] = fs->initial.reg[reg];
382 fs->regs.reg[reg].how = DWARF2_FRAME_REG_UNSPECIFIED;
384 if (fs->regs.reg[reg].how == DWARF2_FRAME_REG_UNSPECIFIED)
385 complaint (&symfile_complaints, _("\
386 incomplete CFI data; DW_CFA_restore unspecified\n\
387 register %s (#%d) at %s"),
388 gdbarch_register_name
389 (gdbarch, gdbarch_dwarf2_reg_to_regnum (gdbarch, reg)),
390 gdbarch_dwarf2_reg_to_regnum (gdbarch, reg),
391 paddress (gdbarch, fs->pc));
395 execute_stack_op (const gdb_byte *exp, ULONGEST len, int addr_size,
396 CORE_ADDR offset, struct frame_info *this_frame,
397 CORE_ADDR initial, int initial_in_stack_memory)
399 struct dwarf_expr_context *ctx;
401 struct cleanup *old_chain;
403 ctx = new_dwarf_expr_context ();
404 old_chain = make_cleanup_free_dwarf_expr_context (ctx);
406 ctx->gdbarch = get_frame_arch (this_frame);
407 ctx->addr_size = addr_size;
408 ctx->offset = offset;
409 ctx->baton = this_frame;
410 ctx->read_reg = read_reg;
411 ctx->read_mem = read_mem;
412 ctx->get_frame_base = no_get_frame_base;
413 ctx->get_frame_cfa = no_get_frame_cfa;
414 ctx->get_frame_pc = no_get_frame_pc;
415 ctx->get_tls_address = no_get_tls_address;
416 ctx->dwarf_call = no_dwarf_call;
417 ctx->get_base_type = no_base_type;
419 dwarf_expr_push_address (ctx, initial, initial_in_stack_memory);
420 dwarf_expr_eval (ctx, exp, len);
422 if (ctx->location == DWARF_VALUE_MEMORY)
423 result = dwarf_expr_fetch_address (ctx, 0);
424 else if (ctx->location == DWARF_VALUE_REGISTER)
425 result = read_reg (this_frame, value_as_long (dwarf_expr_fetch (ctx, 0)));
428 /* This is actually invalid DWARF, but if we ever do run across
429 it somehow, we might as well support it. So, instead, report
430 it as unimplemented. */
432 Not implemented: computing unwound register using explicit value operator"));
435 do_cleanups (old_chain);
442 execute_cfa_program (struct dwarf2_fde *fde, const gdb_byte *insn_ptr,
443 const gdb_byte *insn_end, struct gdbarch *gdbarch,
444 CORE_ADDR pc, struct dwarf2_frame_state *fs)
446 int eh_frame_p = fde->eh_frame_p;
448 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
450 while (insn_ptr < insn_end && fs->pc <= pc)
452 gdb_byte insn = *insn_ptr++;
456 if ((insn & 0xc0) == DW_CFA_advance_loc)
457 fs->pc += (insn & 0x3f) * fs->code_align;
458 else if ((insn & 0xc0) == DW_CFA_offset)
461 reg = dwarf2_frame_adjust_regnum (gdbarch, reg, eh_frame_p);
462 insn_ptr = read_uleb128 (insn_ptr, insn_end, &utmp);
463 offset = utmp * fs->data_align;
464 dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1);
465 fs->regs.reg[reg].how = DWARF2_FRAME_REG_SAVED_OFFSET;
466 fs->regs.reg[reg].loc.offset = offset;
468 else if ((insn & 0xc0) == DW_CFA_restore)
471 dwarf2_restore_rule (gdbarch, reg, fs, eh_frame_p);
478 fs->pc = read_encoded_value (fde->cie->unit, fde->cie->encoding,
479 fde->cie->ptr_size, insn_ptr,
480 &bytes_read, fde->initial_location);
481 /* Apply the objfile offset for relocatable objects. */
482 fs->pc += ANOFFSET (fde->cie->unit->objfile->section_offsets,
483 SECT_OFF_TEXT (fde->cie->unit->objfile));
484 insn_ptr += bytes_read;
487 case DW_CFA_advance_loc1:
488 utmp = extract_unsigned_integer (insn_ptr, 1, byte_order);
489 fs->pc += utmp * fs->code_align;
492 case DW_CFA_advance_loc2:
493 utmp = extract_unsigned_integer (insn_ptr, 2, byte_order);
494 fs->pc += utmp * fs->code_align;
497 case DW_CFA_advance_loc4:
498 utmp = extract_unsigned_integer (insn_ptr, 4, byte_order);
499 fs->pc += utmp * fs->code_align;
503 case DW_CFA_offset_extended:
504 insn_ptr = read_uleb128 (insn_ptr, insn_end, ®);
505 reg = dwarf2_frame_adjust_regnum (gdbarch, reg, eh_frame_p);
506 insn_ptr = read_uleb128 (insn_ptr, insn_end, &utmp);
507 offset = utmp * fs->data_align;
508 dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1);
509 fs->regs.reg[reg].how = DWARF2_FRAME_REG_SAVED_OFFSET;
510 fs->regs.reg[reg].loc.offset = offset;
513 case DW_CFA_restore_extended:
514 insn_ptr = read_uleb128 (insn_ptr, insn_end, ®);
515 dwarf2_restore_rule (gdbarch, reg, fs, eh_frame_p);
518 case DW_CFA_undefined:
519 insn_ptr = read_uleb128 (insn_ptr, insn_end, ®);
520 reg = dwarf2_frame_adjust_regnum (gdbarch, reg, eh_frame_p);
521 dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1);
522 fs->regs.reg[reg].how = DWARF2_FRAME_REG_UNDEFINED;
525 case DW_CFA_same_value:
526 insn_ptr = read_uleb128 (insn_ptr, insn_end, ®);
527 reg = dwarf2_frame_adjust_regnum (gdbarch, reg, eh_frame_p);
528 dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1);
529 fs->regs.reg[reg].how = DWARF2_FRAME_REG_SAME_VALUE;
532 case DW_CFA_register:
533 insn_ptr = read_uleb128 (insn_ptr, insn_end, ®);
534 reg = dwarf2_frame_adjust_regnum (gdbarch, reg, eh_frame_p);
535 insn_ptr = read_uleb128 (insn_ptr, insn_end, &utmp);
536 utmp = dwarf2_frame_adjust_regnum (gdbarch, utmp, eh_frame_p);
537 dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1);
538 fs->regs.reg[reg].how = DWARF2_FRAME_REG_SAVED_REG;
539 fs->regs.reg[reg].loc.reg = utmp;
542 case DW_CFA_remember_state:
544 struct dwarf2_frame_state_reg_info *new_rs;
546 new_rs = XMALLOC (struct dwarf2_frame_state_reg_info);
548 fs->regs.reg = dwarf2_frame_state_copy_regs (&fs->regs);
549 fs->regs.prev = new_rs;
553 case DW_CFA_restore_state:
555 struct dwarf2_frame_state_reg_info *old_rs = fs->regs.prev;
559 complaint (&symfile_complaints, _("\
560 bad CFI data; mismatched DW_CFA_restore_state at %s"),
561 paddress (gdbarch, fs->pc));
565 xfree (fs->regs.reg);
573 insn_ptr = read_uleb128 (insn_ptr, insn_end, &fs->regs.cfa_reg);
574 insn_ptr = read_uleb128 (insn_ptr, insn_end, &utmp);
576 if (fs->armcc_cfa_offsets_sf)
577 utmp *= fs->data_align;
579 fs->regs.cfa_offset = utmp;
580 fs->regs.cfa_how = CFA_REG_OFFSET;
583 case DW_CFA_def_cfa_register:
584 insn_ptr = read_uleb128 (insn_ptr, insn_end, &fs->regs.cfa_reg);
585 fs->regs.cfa_reg = dwarf2_frame_adjust_regnum (gdbarch,
588 fs->regs.cfa_how = CFA_REG_OFFSET;
591 case DW_CFA_def_cfa_offset:
592 insn_ptr = read_uleb128 (insn_ptr, insn_end, &utmp);
594 if (fs->armcc_cfa_offsets_sf)
595 utmp *= fs->data_align;
597 fs->regs.cfa_offset = utmp;
598 /* cfa_how deliberately not set. */
604 case DW_CFA_def_cfa_expression:
605 insn_ptr = read_uleb128 (insn_ptr, insn_end,
606 &fs->regs.cfa_exp_len);
607 fs->regs.cfa_exp = insn_ptr;
608 fs->regs.cfa_how = CFA_EXP;
609 insn_ptr += fs->regs.cfa_exp_len;
612 case DW_CFA_expression:
613 insn_ptr = read_uleb128 (insn_ptr, insn_end, ®);
614 reg = dwarf2_frame_adjust_regnum (gdbarch, reg, eh_frame_p);
615 dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1);
616 insn_ptr = read_uleb128 (insn_ptr, insn_end, &utmp);
617 fs->regs.reg[reg].loc.exp = insn_ptr;
618 fs->regs.reg[reg].exp_len = utmp;
619 fs->regs.reg[reg].how = DWARF2_FRAME_REG_SAVED_EXP;
623 case DW_CFA_offset_extended_sf:
624 insn_ptr = read_uleb128 (insn_ptr, insn_end, ®);
625 reg = dwarf2_frame_adjust_regnum (gdbarch, reg, eh_frame_p);
626 insn_ptr = read_sleb128 (insn_ptr, insn_end, &offset);
627 offset *= fs->data_align;
628 dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1);
629 fs->regs.reg[reg].how = DWARF2_FRAME_REG_SAVED_OFFSET;
630 fs->regs.reg[reg].loc.offset = offset;
633 case DW_CFA_val_offset:
634 insn_ptr = read_uleb128 (insn_ptr, insn_end, ®);
635 dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1);
636 insn_ptr = read_uleb128 (insn_ptr, insn_end, &utmp);
637 offset = utmp * fs->data_align;
638 fs->regs.reg[reg].how = DWARF2_FRAME_REG_SAVED_VAL_OFFSET;
639 fs->regs.reg[reg].loc.offset = offset;
642 case DW_CFA_val_offset_sf:
643 insn_ptr = read_uleb128 (insn_ptr, insn_end, ®);
644 dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1);
645 insn_ptr = read_sleb128 (insn_ptr, insn_end, &offset);
646 offset *= fs->data_align;
647 fs->regs.reg[reg].how = DWARF2_FRAME_REG_SAVED_VAL_OFFSET;
648 fs->regs.reg[reg].loc.offset = offset;
651 case DW_CFA_val_expression:
652 insn_ptr = read_uleb128 (insn_ptr, insn_end, ®);
653 dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1);
654 insn_ptr = read_uleb128 (insn_ptr, insn_end, &utmp);
655 fs->regs.reg[reg].loc.exp = insn_ptr;
656 fs->regs.reg[reg].exp_len = utmp;
657 fs->regs.reg[reg].how = DWARF2_FRAME_REG_SAVED_VAL_EXP;
661 case DW_CFA_def_cfa_sf:
662 insn_ptr = read_uleb128 (insn_ptr, insn_end, &fs->regs.cfa_reg);
663 fs->regs.cfa_reg = dwarf2_frame_adjust_regnum (gdbarch,
666 insn_ptr = read_sleb128 (insn_ptr, insn_end, &offset);
667 fs->regs.cfa_offset = offset * fs->data_align;
668 fs->regs.cfa_how = CFA_REG_OFFSET;
671 case DW_CFA_def_cfa_offset_sf:
672 insn_ptr = read_sleb128 (insn_ptr, insn_end, &offset);
673 fs->regs.cfa_offset = offset * fs->data_align;
674 /* cfa_how deliberately not set. */
677 case DW_CFA_GNU_window_save:
678 /* This is SPARC-specific code, and contains hard-coded
679 constants for the register numbering scheme used by
680 GCC. Rather than having a architecture-specific
681 operation that's only ever used by a single
682 architecture, we provide the implementation here.
683 Incidentally that's what GCC does too in its
686 int size = register_size (gdbarch, 0);
688 dwarf2_frame_state_alloc_regs (&fs->regs, 32);
689 for (reg = 8; reg < 16; reg++)
691 fs->regs.reg[reg].how = DWARF2_FRAME_REG_SAVED_REG;
692 fs->regs.reg[reg].loc.reg = reg + 16;
694 for (reg = 16; reg < 32; reg++)
696 fs->regs.reg[reg].how = DWARF2_FRAME_REG_SAVED_OFFSET;
697 fs->regs.reg[reg].loc.offset = (reg - 16) * size;
702 case DW_CFA_GNU_args_size:
704 insn_ptr = read_uleb128 (insn_ptr, insn_end, &utmp);
707 case DW_CFA_GNU_negative_offset_extended:
708 insn_ptr = read_uleb128 (insn_ptr, insn_end, ®);
709 reg = dwarf2_frame_adjust_regnum (gdbarch, reg, eh_frame_p);
710 insn_ptr = read_uleb128 (insn_ptr, insn_end, &offset);
711 offset *= fs->data_align;
712 dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1);
713 fs->regs.reg[reg].how = DWARF2_FRAME_REG_SAVED_OFFSET;
714 fs->regs.reg[reg].loc.offset = -offset;
718 internal_error (__FILE__, __LINE__,
719 _("Unknown CFI encountered."));
724 /* Don't allow remember/restore between CIE and FDE programs. */
725 dwarf2_frame_state_free_regs (fs->regs.prev);
726 fs->regs.prev = NULL;
730 /* Architecture-specific operations. */
732 /* Per-architecture data key. */
733 static struct gdbarch_data *dwarf2_frame_data;
735 struct dwarf2_frame_ops
737 /* Pre-initialize the register state REG for register REGNUM. */
738 void (*init_reg) (struct gdbarch *, int, struct dwarf2_frame_state_reg *,
739 struct frame_info *);
741 /* Check whether the THIS_FRAME is a signal trampoline. */
742 int (*signal_frame_p) (struct gdbarch *, struct frame_info *);
744 /* Convert .eh_frame register number to DWARF register number, or
745 adjust .debug_frame register number. */
746 int (*adjust_regnum) (struct gdbarch *, int, int);
749 /* Default architecture-specific register state initialization
753 dwarf2_frame_default_init_reg (struct gdbarch *gdbarch, int regnum,
754 struct dwarf2_frame_state_reg *reg,
755 struct frame_info *this_frame)
757 /* If we have a register that acts as a program counter, mark it as
758 a destination for the return address. If we have a register that
759 serves as the stack pointer, arrange for it to be filled with the
760 call frame address (CFA). The other registers are marked as
763 We copy the return address to the program counter, since many
764 parts in GDB assume that it is possible to get the return address
765 by unwinding the program counter register. However, on ISA's
766 with a dedicated return address register, the CFI usually only
767 contains information to unwind that return address register.
769 The reason we're treating the stack pointer special here is
770 because in many cases GCC doesn't emit CFI for the stack pointer
771 and implicitly assumes that it is equal to the CFA. This makes
772 some sense since the DWARF specification (version 3, draft 8,
775 "Typically, the CFA is defined to be the value of the stack
776 pointer at the call site in the previous frame (which may be
777 different from its value on entry to the current frame)."
779 However, this isn't true for all platforms supported by GCC
780 (e.g. IBM S/390 and zSeries). Those architectures should provide
781 their own architecture-specific initialization function. */
783 if (regnum == gdbarch_pc_regnum (gdbarch))
784 reg->how = DWARF2_FRAME_REG_RA;
785 else if (regnum == gdbarch_sp_regnum (gdbarch))
786 reg->how = DWARF2_FRAME_REG_CFA;
789 /* Return a default for the architecture-specific operations. */
792 dwarf2_frame_init (struct obstack *obstack)
794 struct dwarf2_frame_ops *ops;
796 ops = OBSTACK_ZALLOC (obstack, struct dwarf2_frame_ops);
797 ops->init_reg = dwarf2_frame_default_init_reg;
801 /* Set the architecture-specific register state initialization
802 function for GDBARCH to INIT_REG. */
805 dwarf2_frame_set_init_reg (struct gdbarch *gdbarch,
806 void (*init_reg) (struct gdbarch *, int,
807 struct dwarf2_frame_state_reg *,
808 struct frame_info *))
810 struct dwarf2_frame_ops *ops = gdbarch_data (gdbarch, dwarf2_frame_data);
812 ops->init_reg = init_reg;
815 /* Pre-initialize the register state REG for register REGNUM. */
818 dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
819 struct dwarf2_frame_state_reg *reg,
820 struct frame_info *this_frame)
822 struct dwarf2_frame_ops *ops = gdbarch_data (gdbarch, dwarf2_frame_data);
824 ops->init_reg (gdbarch, regnum, reg, this_frame);
827 /* Set the architecture-specific signal trampoline recognition
828 function for GDBARCH to SIGNAL_FRAME_P. */
831 dwarf2_frame_set_signal_frame_p (struct gdbarch *gdbarch,
832 int (*signal_frame_p) (struct gdbarch *,
833 struct frame_info *))
835 struct dwarf2_frame_ops *ops = gdbarch_data (gdbarch, dwarf2_frame_data);
837 ops->signal_frame_p = signal_frame_p;
840 /* Query the architecture-specific signal frame recognizer for
844 dwarf2_frame_signal_frame_p (struct gdbarch *gdbarch,
845 struct frame_info *this_frame)
847 struct dwarf2_frame_ops *ops = gdbarch_data (gdbarch, dwarf2_frame_data);
849 if (ops->signal_frame_p == NULL)
851 return ops->signal_frame_p (gdbarch, this_frame);
854 /* Set the architecture-specific adjustment of .eh_frame and .debug_frame
858 dwarf2_frame_set_adjust_regnum (struct gdbarch *gdbarch,
859 int (*adjust_regnum) (struct gdbarch *,
862 struct dwarf2_frame_ops *ops = gdbarch_data (gdbarch, dwarf2_frame_data);
864 ops->adjust_regnum = adjust_regnum;
867 /* Translate a .eh_frame register to DWARF register, or adjust a .debug_frame
871 dwarf2_frame_adjust_regnum (struct gdbarch *gdbarch,
872 int regnum, int eh_frame_p)
874 struct dwarf2_frame_ops *ops = gdbarch_data (gdbarch, dwarf2_frame_data);
876 if (ops->adjust_regnum == NULL)
878 return ops->adjust_regnum (gdbarch, regnum, eh_frame_p);
882 dwarf2_frame_find_quirks (struct dwarf2_frame_state *fs,
883 struct dwarf2_fde *fde)
887 s = find_pc_symtab (fs->pc);
891 if (producer_is_realview (s->producer))
893 if (fde->cie->version == 1)
894 fs->armcc_cfa_offsets_sf = 1;
896 if (fde->cie->version == 1)
897 fs->armcc_cfa_offsets_reversed = 1;
899 /* The reversed offset problem is present in some compilers
900 using DWARF3, but it was eventually fixed. Check the ARM
901 defined augmentations, which are in the format "armcc" followed
902 by a list of one-character options. The "+" option means
903 this problem is fixed (no quirk needed). If the armcc
904 augmentation is missing, the quirk is needed. */
905 if (fde->cie->version == 3
906 && (strncmp (fde->cie->augmentation, "armcc", 5) != 0
907 || strchr (fde->cie->augmentation + 5, '+') == NULL))
908 fs->armcc_cfa_offsets_reversed = 1;
916 dwarf2_compile_cfa_to_ax (struct agent_expr *expr, struct axs_value *loc,
917 struct gdbarch *gdbarch,
919 struct dwarf2_per_cu_data *data)
921 const int num_regs = gdbarch_num_regs (gdbarch)
922 + gdbarch_num_pseudo_regs (gdbarch);
923 struct dwarf2_fde *fde;
924 CORE_ADDR text_offset, cfa;
925 struct dwarf2_frame_state fs;
928 memset (&fs, 0, sizeof (struct dwarf2_frame_state));
932 /* Find the correct FDE. */
933 fde = dwarf2_frame_find_fde (&fs.pc, &text_offset);
935 error (_("Could not compute CFA; needed to translate this expression"));
937 /* Extract any interesting information from the CIE. */
938 fs.data_align = fde->cie->data_alignment_factor;
939 fs.code_align = fde->cie->code_alignment_factor;
940 fs.retaddr_column = fde->cie->return_address_register;
941 addr_size = fde->cie->addr_size;
943 /* Check for "quirks" - known bugs in producers. */
944 dwarf2_frame_find_quirks (&fs, fde);
946 /* First decode all the insns in the CIE. */
947 execute_cfa_program (fde, fde->cie->initial_instructions,
948 fde->cie->end, gdbarch, pc, &fs);
950 /* Save the initialized register set. */
951 fs.initial = fs.regs;
952 fs.initial.reg = dwarf2_frame_state_copy_regs (&fs.regs);
954 /* Then decode the insns in the FDE up to our target PC. */
955 execute_cfa_program (fde, fde->instructions, fde->end, gdbarch, pc, &fs);
957 /* Calculate the CFA. */
958 switch (fs.regs.cfa_how)
962 int regnum = gdbarch_dwarf2_reg_to_regnum (gdbarch, fs.regs.cfa_reg);
965 error (_("Unable to access DWARF register number %d"),
966 (int) fs.regs.cfa_reg); /* FIXME */
967 ax_reg (expr, regnum);
969 if (fs.regs.cfa_offset != 0)
971 if (fs.armcc_cfa_offsets_reversed)
972 ax_const_l (expr, -fs.regs.cfa_offset);
974 ax_const_l (expr, fs.regs.cfa_offset);
975 ax_simple (expr, aop_add);
981 ax_const_l (expr, text_offset);
982 dwarf2_compile_expr_to_ax (expr, loc, gdbarch, addr_size,
984 fs.regs.cfa_exp + fs.regs.cfa_exp_len,
989 internal_error (__FILE__, __LINE__, _("Unknown CFA rule."));
994 struct dwarf2_frame_cache
996 /* DWARF Call Frame Address. */
999 /* Set if the return address column was marked as unavailable
1000 (required non-collected memory or registers to compute). */
1001 int unavailable_retaddr;
1003 /* Set if the return address column was marked as undefined. */
1004 int undefined_retaddr;
1006 /* Saved registers, indexed by GDB register number, not by DWARF
1008 struct dwarf2_frame_state_reg *reg;
1010 /* Return address register. */
1011 struct dwarf2_frame_state_reg retaddr_reg;
1013 /* Target address size in bytes. */
1016 /* The .text offset. */
1017 CORE_ADDR text_offset;
1020 static struct dwarf2_frame_cache *
1021 dwarf2_frame_cache (struct frame_info *this_frame, void **this_cache)
1023 struct cleanup *old_chain;
1024 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1025 const int num_regs = gdbarch_num_regs (gdbarch)
1026 + gdbarch_num_pseudo_regs (gdbarch);
1027 struct dwarf2_frame_cache *cache;
1028 struct dwarf2_frame_state *fs;
1029 struct dwarf2_fde *fde;
1030 volatile struct gdb_exception ex;
1035 /* Allocate a new cache. */
1036 cache = FRAME_OBSTACK_ZALLOC (struct dwarf2_frame_cache);
1037 cache->reg = FRAME_OBSTACK_CALLOC (num_regs, struct dwarf2_frame_state_reg);
1038 *this_cache = cache;
1040 /* Allocate and initialize the frame state. */
1041 fs = XZALLOC (struct dwarf2_frame_state);
1042 old_chain = make_cleanup (dwarf2_frame_state_free, fs);
1046 Note that if the next frame is never supposed to return (i.e. a call
1047 to abort), the compiler might optimize away the instruction at
1048 its return address. As a result the return address will
1049 point at some random instruction, and the CFI for that
1050 instruction is probably worthless to us. GCC's unwinder solves
1051 this problem by substracting 1 from the return address to get an
1052 address in the middle of a presumed call instruction (or the
1053 instruction in the associated delay slot). This should only be
1054 done for "normal" frames and not for resume-type frames (signal
1055 handlers, sentinel frames, dummy frames). The function
1056 get_frame_address_in_block does just this. It's not clear how
1057 reliable the method is though; there is the potential for the
1058 register state pre-call being different to that on return. */
1059 fs->pc = get_frame_address_in_block (this_frame);
1061 /* Find the correct FDE. */
1062 fde = dwarf2_frame_find_fde (&fs->pc, &cache->text_offset);
1063 gdb_assert (fde != NULL);
1065 /* Extract any interesting information from the CIE. */
1066 fs->data_align = fde->cie->data_alignment_factor;
1067 fs->code_align = fde->cie->code_alignment_factor;
1068 fs->retaddr_column = fde->cie->return_address_register;
1069 cache->addr_size = fde->cie->addr_size;
1071 /* Check for "quirks" - known bugs in producers. */
1072 dwarf2_frame_find_quirks (fs, fde);
1074 /* First decode all the insns in the CIE. */
1075 execute_cfa_program (fde, fde->cie->initial_instructions,
1076 fde->cie->end, gdbarch, get_frame_pc (this_frame), fs);
1078 /* Save the initialized register set. */
1079 fs->initial = fs->regs;
1080 fs->initial.reg = dwarf2_frame_state_copy_regs (&fs->regs);
1082 /* Then decode the insns in the FDE up to our target PC. */
1083 execute_cfa_program (fde, fde->instructions, fde->end, gdbarch,
1084 get_frame_pc (this_frame), fs);
1086 TRY_CATCH (ex, RETURN_MASK_ERROR)
1088 /* Calculate the CFA. */
1089 switch (fs->regs.cfa_how)
1091 case CFA_REG_OFFSET:
1092 cache->cfa = read_reg (this_frame, fs->regs.cfa_reg);
1093 if (fs->armcc_cfa_offsets_reversed)
1094 cache->cfa -= fs->regs.cfa_offset;
1096 cache->cfa += fs->regs.cfa_offset;
1101 execute_stack_op (fs->regs.cfa_exp, fs->regs.cfa_exp_len,
1102 cache->addr_size, cache->text_offset,
1107 internal_error (__FILE__, __LINE__, _("Unknown CFA rule."));
1112 if (ex.error == NOT_AVAILABLE_ERROR)
1114 cache->unavailable_retaddr = 1;
1118 throw_exception (ex);
1121 /* Initialize the register state. */
1125 for (regnum = 0; regnum < num_regs; regnum++)
1126 dwarf2_frame_init_reg (gdbarch, regnum, &cache->reg[regnum], this_frame);
1129 /* Go through the DWARF2 CFI generated table and save its register
1130 location information in the cache. Note that we don't skip the
1131 return address column; it's perfectly all right for it to
1132 correspond to a real register. If it doesn't correspond to a
1133 real register, or if we shouldn't treat it as such,
1134 gdbarch_dwarf2_reg_to_regnum should be defined to return a number outside
1135 the range [0, gdbarch_num_regs). */
1137 int column; /* CFI speak for "register number". */
1139 for (column = 0; column < fs->regs.num_regs; column++)
1141 /* Use the GDB register number as the destination index. */
1142 int regnum = gdbarch_dwarf2_reg_to_regnum (gdbarch, column);
1144 /* If there's no corresponding GDB register, ignore it. */
1145 if (regnum < 0 || regnum >= num_regs)
1148 /* NOTE: cagney/2003-09-05: CFI should specify the disposition
1149 of all debug info registers. If it doesn't, complain (but
1150 not too loudly). It turns out that GCC assumes that an
1151 unspecified register implies "same value" when CFI (draft
1152 7) specifies nothing at all. Such a register could equally
1153 be interpreted as "undefined". Also note that this check
1154 isn't sufficient; it only checks that all registers in the
1155 range [0 .. max column] are specified, and won't detect
1156 problems when a debug info register falls outside of the
1157 table. We need a way of iterating through all the valid
1158 DWARF2 register numbers. */
1159 if (fs->regs.reg[column].how == DWARF2_FRAME_REG_UNSPECIFIED)
1161 if (cache->reg[regnum].how == DWARF2_FRAME_REG_UNSPECIFIED)
1162 complaint (&symfile_complaints, _("\
1163 incomplete CFI data; unspecified registers (e.g., %s) at %s"),
1164 gdbarch_register_name (gdbarch, regnum),
1165 paddress (gdbarch, fs->pc));
1168 cache->reg[regnum] = fs->regs.reg[column];
1172 /* Eliminate any DWARF2_FRAME_REG_RA rules, and save the information
1173 we need for evaluating DWARF2_FRAME_REG_RA_OFFSET rules. */
1177 for (regnum = 0; regnum < num_regs; regnum++)
1179 if (cache->reg[regnum].how == DWARF2_FRAME_REG_RA
1180 || cache->reg[regnum].how == DWARF2_FRAME_REG_RA_OFFSET)
1182 struct dwarf2_frame_state_reg *retaddr_reg =
1183 &fs->regs.reg[fs->retaddr_column];
1185 /* It seems rather bizarre to specify an "empty" column as
1186 the return adress column. However, this is exactly
1187 what GCC does on some targets. It turns out that GCC
1188 assumes that the return address can be found in the
1189 register corresponding to the return address column.
1190 Incidentally, that's how we should treat a return
1191 address column specifying "same value" too. */
1192 if (fs->retaddr_column < fs->regs.num_regs
1193 && retaddr_reg->how != DWARF2_FRAME_REG_UNSPECIFIED
1194 && retaddr_reg->how != DWARF2_FRAME_REG_SAME_VALUE)
1196 if (cache->reg[regnum].how == DWARF2_FRAME_REG_RA)
1197 cache->reg[regnum] = *retaddr_reg;
1199 cache->retaddr_reg = *retaddr_reg;
1203 if (cache->reg[regnum].how == DWARF2_FRAME_REG_RA)
1205 cache->reg[regnum].loc.reg = fs->retaddr_column;
1206 cache->reg[regnum].how = DWARF2_FRAME_REG_SAVED_REG;
1210 cache->retaddr_reg.loc.reg = fs->retaddr_column;
1211 cache->retaddr_reg.how = DWARF2_FRAME_REG_SAVED_REG;
1218 if (fs->retaddr_column < fs->regs.num_regs
1219 && fs->regs.reg[fs->retaddr_column].how == DWARF2_FRAME_REG_UNDEFINED)
1220 cache->undefined_retaddr = 1;
1222 do_cleanups (old_chain);
1227 static enum unwind_stop_reason
1228 dwarf2_frame_unwind_stop_reason (struct frame_info *this_frame,
1231 struct dwarf2_frame_cache *cache
1232 = dwarf2_frame_cache (this_frame, this_cache);
1234 if (cache->unavailable_retaddr)
1235 return UNWIND_UNAVAILABLE;
1237 if (cache->undefined_retaddr)
1238 return UNWIND_OUTERMOST;
1240 return UNWIND_NO_REASON;
1244 dwarf2_frame_this_id (struct frame_info *this_frame, void **this_cache,
1245 struct frame_id *this_id)
1247 struct dwarf2_frame_cache *cache =
1248 dwarf2_frame_cache (this_frame, this_cache);
1250 if (cache->unavailable_retaddr)
1253 if (cache->undefined_retaddr)
1256 (*this_id) = frame_id_build (cache->cfa, get_frame_func (this_frame));
1259 static struct value *
1260 dwarf2_frame_prev_register (struct frame_info *this_frame, void **this_cache,
1263 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1264 struct dwarf2_frame_cache *cache =
1265 dwarf2_frame_cache (this_frame, this_cache);
1269 switch (cache->reg[regnum].how)
1271 case DWARF2_FRAME_REG_UNDEFINED:
1272 /* If CFI explicitly specified that the value isn't defined,
1273 mark it as optimized away; the value isn't available. */
1274 return frame_unwind_got_optimized (this_frame, regnum);
1276 case DWARF2_FRAME_REG_SAVED_OFFSET:
1277 addr = cache->cfa + cache->reg[regnum].loc.offset;
1278 return frame_unwind_got_memory (this_frame, regnum, addr);
1280 case DWARF2_FRAME_REG_SAVED_REG:
1282 = gdbarch_dwarf2_reg_to_regnum (gdbarch, cache->reg[regnum].loc.reg);
1283 return frame_unwind_got_register (this_frame, regnum, realnum);
1285 case DWARF2_FRAME_REG_SAVED_EXP:
1286 addr = execute_stack_op (cache->reg[regnum].loc.exp,
1287 cache->reg[regnum].exp_len,
1288 cache->addr_size, cache->text_offset,
1289 this_frame, cache->cfa, 1);
1290 return frame_unwind_got_memory (this_frame, regnum, addr);
1292 case DWARF2_FRAME_REG_SAVED_VAL_OFFSET:
1293 addr = cache->cfa + cache->reg[regnum].loc.offset;
1294 return frame_unwind_got_constant (this_frame, regnum, addr);
1296 case DWARF2_FRAME_REG_SAVED_VAL_EXP:
1297 addr = execute_stack_op (cache->reg[regnum].loc.exp,
1298 cache->reg[regnum].exp_len,
1299 cache->addr_size, cache->text_offset,
1300 this_frame, cache->cfa, 1);
1301 return frame_unwind_got_constant (this_frame, regnum, addr);
1303 case DWARF2_FRAME_REG_UNSPECIFIED:
1304 /* GCC, in its infinite wisdom decided to not provide unwind
1305 information for registers that are "same value". Since
1306 DWARF2 (3 draft 7) doesn't define such behavior, said
1307 registers are actually undefined (which is different to CFI
1308 "undefined"). Code above issues a complaint about this.
1309 Here just fudge the books, assume GCC, and that the value is
1310 more inner on the stack. */
1311 return frame_unwind_got_register (this_frame, regnum, regnum);
1313 case DWARF2_FRAME_REG_SAME_VALUE:
1314 return frame_unwind_got_register (this_frame, regnum, regnum);
1316 case DWARF2_FRAME_REG_CFA:
1317 return frame_unwind_got_address (this_frame, regnum, cache->cfa);
1319 case DWARF2_FRAME_REG_CFA_OFFSET:
1320 addr = cache->cfa + cache->reg[regnum].loc.offset;
1321 return frame_unwind_got_address (this_frame, regnum, addr);
1323 case DWARF2_FRAME_REG_RA_OFFSET:
1324 addr = cache->reg[regnum].loc.offset;
1325 regnum = gdbarch_dwarf2_reg_to_regnum
1326 (gdbarch, cache->retaddr_reg.loc.reg);
1327 addr += get_frame_register_unsigned (this_frame, regnum);
1328 return frame_unwind_got_address (this_frame, regnum, addr);
1330 case DWARF2_FRAME_REG_FN:
1331 return cache->reg[regnum].loc.fn (this_frame, this_cache, regnum);
1334 internal_error (__FILE__, __LINE__, _("Unknown register rule."));
1339 dwarf2_frame_sniffer (const struct frame_unwind *self,
1340 struct frame_info *this_frame, void **this_cache)
1342 /* Grab an address that is guarenteed to reside somewhere within the
1343 function. get_frame_pc(), with a no-return next function, can
1344 end up returning something past the end of this function's body.
1345 If the frame we're sniffing for is a signal frame whose start
1346 address is placed on the stack by the OS, its FDE must
1347 extend one byte before its start address or we could potentially
1348 select the FDE of the previous function. */
1349 CORE_ADDR block_addr = get_frame_address_in_block (this_frame);
1350 struct dwarf2_fde *fde = dwarf2_frame_find_fde (&block_addr, NULL);
1355 /* On some targets, signal trampolines may have unwind information.
1356 We need to recognize them so that we set the frame type
1359 if (fde->cie->signal_frame
1360 || dwarf2_frame_signal_frame_p (get_frame_arch (this_frame),
1362 return self->type == SIGTRAMP_FRAME;
1364 return self->type != SIGTRAMP_FRAME;
1367 static const struct frame_unwind dwarf2_frame_unwind =
1370 dwarf2_frame_unwind_stop_reason,
1371 dwarf2_frame_this_id,
1372 dwarf2_frame_prev_register,
1374 dwarf2_frame_sniffer
1377 static const struct frame_unwind dwarf2_signal_frame_unwind =
1380 dwarf2_frame_unwind_stop_reason,
1381 dwarf2_frame_this_id,
1382 dwarf2_frame_prev_register,
1384 dwarf2_frame_sniffer
1387 /* Append the DWARF-2 frame unwinders to GDBARCH's list. */
1390 dwarf2_append_unwinders (struct gdbarch *gdbarch)
1392 frame_unwind_append_unwinder (gdbarch, &dwarf2_frame_unwind);
1393 frame_unwind_append_unwinder (gdbarch, &dwarf2_signal_frame_unwind);
1397 /* There is no explicitly defined relationship between the CFA and the
1398 location of frame's local variables and arguments/parameters.
1399 Therefore, frame base methods on this page should probably only be
1400 used as a last resort, just to avoid printing total garbage as a
1401 response to the "info frame" command. */
1404 dwarf2_frame_base_address (struct frame_info *this_frame, void **this_cache)
1406 struct dwarf2_frame_cache *cache =
1407 dwarf2_frame_cache (this_frame, this_cache);
1412 static const struct frame_base dwarf2_frame_base =
1414 &dwarf2_frame_unwind,
1415 dwarf2_frame_base_address,
1416 dwarf2_frame_base_address,
1417 dwarf2_frame_base_address
1420 const struct frame_base *
1421 dwarf2_frame_base_sniffer (struct frame_info *this_frame)
1423 CORE_ADDR block_addr = get_frame_address_in_block (this_frame);
1425 if (dwarf2_frame_find_fde (&block_addr, NULL))
1426 return &dwarf2_frame_base;
1431 /* Compute the CFA for THIS_FRAME, but only if THIS_FRAME came from
1432 the DWARF unwinder. This is used to implement
1433 DW_OP_call_frame_cfa. */
1436 dwarf2_frame_cfa (struct frame_info *this_frame)
1438 while (get_frame_type (this_frame) == INLINE_FRAME)
1439 this_frame = get_prev_frame (this_frame);
1440 /* This restriction could be lifted if other unwinders are known to
1441 compute the frame base in a way compatible with the DWARF
1443 if (! frame_unwinder_is (this_frame, &dwarf2_frame_unwind))
1444 error (_("can't compute CFA for this frame"));
1445 return get_frame_base (this_frame);
1448 const struct objfile_data *dwarf2_frame_objfile_data;
1451 read_1_byte (bfd *abfd, gdb_byte *buf)
1453 return bfd_get_8 (abfd, buf);
1457 read_4_bytes (bfd *abfd, gdb_byte *buf)
1459 return bfd_get_32 (abfd, buf);
1463 read_8_bytes (bfd *abfd, gdb_byte *buf)
1465 return bfd_get_64 (abfd, buf);
1469 read_unsigned_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
1472 unsigned int num_read;
1482 byte = bfd_get_8 (abfd, (bfd_byte *) buf);
1485 result |= ((byte & 0x7f) << shift);
1488 while (byte & 0x80);
1490 *bytes_read_ptr = num_read;
1496 read_signed_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
1500 unsigned int num_read;
1509 byte = bfd_get_8 (abfd, (bfd_byte *) buf);
1512 result |= ((byte & 0x7f) << shift);
1515 while (byte & 0x80);
1517 if (shift < 8 * sizeof (result) && (byte & 0x40))
1518 result |= -(((LONGEST)1) << shift);
1520 *bytes_read_ptr = num_read;
1526 read_initial_length (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
1530 result = bfd_get_32 (abfd, buf);
1531 if (result == 0xffffffff)
1533 result = bfd_get_64 (abfd, buf + 4);
1534 *bytes_read_ptr = 12;
1537 *bytes_read_ptr = 4;
1543 /* Pointer encoding helper functions. */
1545 /* GCC supports exception handling based on DWARF2 CFI. However, for
1546 technical reasons, it encodes addresses in its FDE's in a different
1547 way. Several "pointer encodings" are supported. The encoding
1548 that's used for a particular FDE is determined by the 'R'
1549 augmentation in the associated CIE. The argument of this
1550 augmentation is a single byte.
1552 The address can be encoded as 2 bytes, 4 bytes, 8 bytes, or as a
1553 LEB128. This is encoded in bits 0, 1 and 2. Bit 3 encodes whether
1554 the address is signed or unsigned. Bits 4, 5 and 6 encode how the
1555 address should be interpreted (absolute, relative to the current
1556 position in the FDE, ...). Bit 7, indicates that the address
1557 should be dereferenced. */
1560 encoding_for_size (unsigned int size)
1565 return DW_EH_PE_udata2;
1567 return DW_EH_PE_udata4;
1569 return DW_EH_PE_udata8;
1571 internal_error (__FILE__, __LINE__, _("Unsupported address size"));
1576 read_encoded_value (struct comp_unit *unit, gdb_byte encoding,
1577 int ptr_len, const gdb_byte *buf,
1578 unsigned int *bytes_read_ptr,
1579 CORE_ADDR func_base)
1584 /* GCC currently doesn't generate DW_EH_PE_indirect encodings for
1586 if (encoding & DW_EH_PE_indirect)
1587 internal_error (__FILE__, __LINE__,
1588 _("Unsupported encoding: DW_EH_PE_indirect"));
1590 *bytes_read_ptr = 0;
1592 switch (encoding & 0x70)
1594 case DW_EH_PE_absptr:
1597 case DW_EH_PE_pcrel:
1598 base = bfd_get_section_vma (unit->abfd, unit->dwarf_frame_section);
1599 base += (buf - unit->dwarf_frame_buffer);
1601 case DW_EH_PE_datarel:
1604 case DW_EH_PE_textrel:
1607 case DW_EH_PE_funcrel:
1610 case DW_EH_PE_aligned:
1612 offset = buf - unit->dwarf_frame_buffer;
1613 if ((offset % ptr_len) != 0)
1615 *bytes_read_ptr = ptr_len - (offset % ptr_len);
1616 buf += *bytes_read_ptr;
1620 internal_error (__FILE__, __LINE__,
1621 _("Invalid or unsupported encoding"));
1624 if ((encoding & 0x07) == 0x00)
1626 encoding |= encoding_for_size (ptr_len);
1627 if (bfd_get_sign_extend_vma (unit->abfd))
1628 encoding |= DW_EH_PE_signed;
1631 switch (encoding & 0x0f)
1633 case DW_EH_PE_uleb128:
1636 const gdb_byte *end_buf = buf + (sizeof (value) + 1) * 8 / 7;
1638 *bytes_read_ptr += read_uleb128 (buf, end_buf, &value) - buf;
1639 return base + value;
1641 case DW_EH_PE_udata2:
1642 *bytes_read_ptr += 2;
1643 return (base + bfd_get_16 (unit->abfd, (bfd_byte *) buf));
1644 case DW_EH_PE_udata4:
1645 *bytes_read_ptr += 4;
1646 return (base + bfd_get_32 (unit->abfd, (bfd_byte *) buf));
1647 case DW_EH_PE_udata8:
1648 *bytes_read_ptr += 8;
1649 return (base + bfd_get_64 (unit->abfd, (bfd_byte *) buf));
1650 case DW_EH_PE_sleb128:
1653 const gdb_byte *end_buf = buf + (sizeof (value) + 1) * 8 / 7;
1655 *bytes_read_ptr += read_sleb128 (buf, end_buf, &value) - buf;
1656 return base + value;
1658 case DW_EH_PE_sdata2:
1659 *bytes_read_ptr += 2;
1660 return (base + bfd_get_signed_16 (unit->abfd, (bfd_byte *) buf));
1661 case DW_EH_PE_sdata4:
1662 *bytes_read_ptr += 4;
1663 return (base + bfd_get_signed_32 (unit->abfd, (bfd_byte *) buf));
1664 case DW_EH_PE_sdata8:
1665 *bytes_read_ptr += 8;
1666 return (base + bfd_get_signed_64 (unit->abfd, (bfd_byte *) buf));
1668 internal_error (__FILE__, __LINE__,
1669 _("Invalid or unsupported encoding"));
1675 bsearch_cie_cmp (const void *key, const void *element)
1677 ULONGEST cie_pointer = *(ULONGEST *) key;
1678 struct dwarf2_cie *cie = *(struct dwarf2_cie **) element;
1680 if (cie_pointer == cie->cie_pointer)
1683 return (cie_pointer < cie->cie_pointer) ? -1 : 1;
1686 /* Find CIE with the given CIE_POINTER in CIE_TABLE. */
1687 static struct dwarf2_cie *
1688 find_cie (struct dwarf2_cie_table *cie_table, ULONGEST cie_pointer)
1690 struct dwarf2_cie **p_cie;
1692 /* The C standard (ISO/IEC 9899:TC2) requires the BASE argument to
1693 bsearch be non-NULL. */
1694 if (cie_table->entries == NULL)
1696 gdb_assert (cie_table->num_entries == 0);
1700 p_cie = bsearch (&cie_pointer, cie_table->entries, cie_table->num_entries,
1701 sizeof (cie_table->entries[0]), bsearch_cie_cmp);
1707 /* Add a pointer to new CIE to the CIE_TABLE, allocating space for it. */
1709 add_cie (struct dwarf2_cie_table *cie_table, struct dwarf2_cie *cie)
1711 const int n = cie_table->num_entries;
1714 || cie_table->entries[n - 1]->cie_pointer < cie->cie_pointer);
1716 cie_table->entries =
1717 xrealloc (cie_table->entries, (n + 1) * sizeof (cie_table->entries[0]));
1718 cie_table->entries[n] = cie;
1719 cie_table->num_entries = n + 1;
1723 bsearch_fde_cmp (const void *key, const void *element)
1725 CORE_ADDR seek_pc = *(CORE_ADDR *) key;
1726 struct dwarf2_fde *fde = *(struct dwarf2_fde **) element;
1728 if (seek_pc < fde->initial_location)
1730 if (seek_pc < fde->initial_location + fde->address_range)
1735 /* Find the FDE for *PC. Return a pointer to the FDE, and store the
1736 inital location associated with it into *PC. */
1738 static struct dwarf2_fde *
1739 dwarf2_frame_find_fde (CORE_ADDR *pc, CORE_ADDR *out_offset)
1741 struct objfile *objfile;
1743 ALL_OBJFILES (objfile)
1745 struct dwarf2_fde_table *fde_table;
1746 struct dwarf2_fde **p_fde;
1750 fde_table = objfile_data (objfile, dwarf2_frame_objfile_data);
1751 if (fde_table == NULL)
1753 dwarf2_build_frame_info (objfile);
1754 fde_table = objfile_data (objfile, dwarf2_frame_objfile_data);
1756 gdb_assert (fde_table != NULL);
1758 if (fde_table->num_entries == 0)
1761 gdb_assert (objfile->section_offsets);
1762 offset = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
1764 gdb_assert (fde_table->num_entries > 0);
1765 if (*pc < offset + fde_table->entries[0]->initial_location)
1768 seek_pc = *pc - offset;
1769 p_fde = bsearch (&seek_pc, fde_table->entries, fde_table->num_entries,
1770 sizeof (fde_table->entries[0]), bsearch_fde_cmp);
1773 *pc = (*p_fde)->initial_location + offset;
1775 *out_offset = offset;
1782 /* Add a pointer to new FDE to the FDE_TABLE, allocating space for it. */
1784 add_fde (struct dwarf2_fde_table *fde_table, struct dwarf2_fde *fde)
1786 if (fde->address_range == 0)
1787 /* Discard useless FDEs. */
1790 fde_table->num_entries += 1;
1791 fde_table->entries =
1792 xrealloc (fde_table->entries,
1793 fde_table->num_entries * sizeof (fde_table->entries[0]));
1794 fde_table->entries[fde_table->num_entries - 1] = fde;
1797 #ifdef CC_HAS_LONG_LONG
1798 #define DW64_CIE_ID 0xffffffffffffffffULL
1800 #define DW64_CIE_ID ~0
1803 static gdb_byte *decode_frame_entry (struct comp_unit *unit, gdb_byte *start,
1805 struct dwarf2_cie_table *cie_table,
1806 struct dwarf2_fde_table *fde_table);
1808 /* Decode the next CIE or FDE. Return NULL if invalid input, otherwise
1809 the next byte to be processed. */
1811 decode_frame_entry_1 (struct comp_unit *unit, gdb_byte *start, int eh_frame_p,
1812 struct dwarf2_cie_table *cie_table,
1813 struct dwarf2_fde_table *fde_table)
1815 struct gdbarch *gdbarch = get_objfile_arch (unit->objfile);
1816 gdb_byte *buf, *end;
1818 unsigned int bytes_read;
1821 ULONGEST cie_pointer;
1824 length = read_initial_length (unit->abfd, buf, &bytes_read);
1828 /* Are we still within the section? */
1829 if (end > unit->dwarf_frame_buffer + unit->dwarf_frame_size)
1835 /* Distinguish between 32 and 64-bit encoded frame info. */
1836 dwarf64_p = (bytes_read == 12);
1838 /* In a .eh_frame section, zero is used to distinguish CIEs from FDEs. */
1842 cie_id = DW64_CIE_ID;
1848 cie_pointer = read_8_bytes (unit->abfd, buf);
1853 cie_pointer = read_4_bytes (unit->abfd, buf);
1857 if (cie_pointer == cie_id)
1859 /* This is a CIE. */
1860 struct dwarf2_cie *cie;
1862 unsigned int cie_version;
1864 /* Record the offset into the .debug_frame section of this CIE. */
1865 cie_pointer = start - unit->dwarf_frame_buffer;
1867 /* Check whether we've already read it. */
1868 if (find_cie (cie_table, cie_pointer))
1871 cie = (struct dwarf2_cie *)
1872 obstack_alloc (&unit->objfile->objfile_obstack,
1873 sizeof (struct dwarf2_cie));
1874 cie->initial_instructions = NULL;
1875 cie->cie_pointer = cie_pointer;
1877 /* The encoding for FDE's in a normal .debug_frame section
1878 depends on the target address size. */
1879 cie->encoding = DW_EH_PE_absptr;
1881 /* We'll determine the final value later, but we need to
1882 initialize it conservatively. */
1883 cie->signal_frame = 0;
1885 /* Check version number. */
1886 cie_version = read_1_byte (unit->abfd, buf);
1887 if (cie_version != 1 && cie_version != 3 && cie_version != 4)
1889 cie->version = cie_version;
1892 /* Interpret the interesting bits of the augmentation. */
1893 cie->augmentation = augmentation = (char *) buf;
1894 buf += (strlen (augmentation) + 1);
1896 /* Ignore armcc augmentations. We only use them for quirks,
1897 and that doesn't happen until later. */
1898 if (strncmp (augmentation, "armcc", 5) == 0)
1899 augmentation += strlen (augmentation);
1901 /* The GCC 2.x "eh" augmentation has a pointer immediately
1902 following the augmentation string, so it must be handled
1904 if (augmentation[0] == 'e' && augmentation[1] == 'h')
1907 buf += gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT;
1911 if (cie->version >= 4)
1913 /* FIXME: check that this is the same as from the CU header. */
1914 cie->addr_size = read_1_byte (unit->abfd, buf);
1916 cie->segment_size = read_1_byte (unit->abfd, buf);
1921 cie->addr_size = gdbarch_dwarf2_addr_size (gdbarch);
1922 cie->segment_size = 0;
1924 /* Address values in .eh_frame sections are defined to have the
1925 target's pointer size. Watchout: This breaks frame info for
1926 targets with pointer size < address size, unless a .debug_frame
1927 section exists as well. */
1929 cie->ptr_size = gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT;
1931 cie->ptr_size = cie->addr_size;
1933 cie->code_alignment_factor =
1934 read_unsigned_leb128 (unit->abfd, buf, &bytes_read);
1937 cie->data_alignment_factor =
1938 read_signed_leb128 (unit->abfd, buf, &bytes_read);
1941 if (cie_version == 1)
1943 cie->return_address_register = read_1_byte (unit->abfd, buf);
1947 cie->return_address_register = read_unsigned_leb128 (unit->abfd, buf,
1949 cie->return_address_register
1950 = dwarf2_frame_adjust_regnum (gdbarch,
1951 cie->return_address_register,
1956 cie->saw_z_augmentation = (*augmentation == 'z');
1957 if (cie->saw_z_augmentation)
1961 length = read_unsigned_leb128 (unit->abfd, buf, &bytes_read);
1965 cie->initial_instructions = buf + length;
1969 while (*augmentation)
1971 /* "L" indicates a byte showing how the LSDA pointer is encoded. */
1972 if (*augmentation == 'L')
1979 /* "R" indicates a byte indicating how FDE addresses are encoded. */
1980 else if (*augmentation == 'R')
1982 cie->encoding = *buf++;
1986 /* "P" indicates a personality routine in the CIE augmentation. */
1987 else if (*augmentation == 'P')
1989 /* Skip. Avoid indirection since we throw away the result. */
1990 gdb_byte encoding = (*buf++) & ~DW_EH_PE_indirect;
1991 read_encoded_value (unit, encoding, cie->ptr_size,
1992 buf, &bytes_read, 0);
1997 /* "S" indicates a signal frame, such that the return
1998 address must not be decremented to locate the call frame
1999 info for the previous frame; it might even be the first
2000 instruction of a function, so decrementing it would take
2001 us to a different function. */
2002 else if (*augmentation == 'S')
2004 cie->signal_frame = 1;
2008 /* Otherwise we have an unknown augmentation. Assume that either
2009 there is no augmentation data, or we saw a 'z' prefix. */
2012 if (cie->initial_instructions)
2013 buf = cie->initial_instructions;
2018 cie->initial_instructions = buf;
2022 add_cie (cie_table, cie);
2026 /* This is a FDE. */
2027 struct dwarf2_fde *fde;
2029 /* In an .eh_frame section, the CIE pointer is the delta between the
2030 address within the FDE where the CIE pointer is stored and the
2031 address of the CIE. Convert it to an offset into the .eh_frame
2035 cie_pointer = buf - unit->dwarf_frame_buffer - cie_pointer;
2036 cie_pointer -= (dwarf64_p ? 8 : 4);
2039 /* In either case, validate the result is still within the section. */
2040 if (cie_pointer >= unit->dwarf_frame_size)
2043 fde = (struct dwarf2_fde *)
2044 obstack_alloc (&unit->objfile->objfile_obstack,
2045 sizeof (struct dwarf2_fde));
2046 fde->cie = find_cie (cie_table, cie_pointer);
2047 if (fde->cie == NULL)
2049 decode_frame_entry (unit, unit->dwarf_frame_buffer + cie_pointer,
2050 eh_frame_p, cie_table, fde_table);
2051 fde->cie = find_cie (cie_table, cie_pointer);
2054 gdb_assert (fde->cie != NULL);
2056 fde->initial_location =
2057 read_encoded_value (unit, fde->cie->encoding, fde->cie->ptr_size,
2058 buf, &bytes_read, 0);
2061 fde->address_range =
2062 read_encoded_value (unit, fde->cie->encoding & 0x0f,
2063 fde->cie->ptr_size, buf, &bytes_read, 0);
2066 /* A 'z' augmentation in the CIE implies the presence of an
2067 augmentation field in the FDE as well. The only thing known
2068 to be in here at present is the LSDA entry for EH. So we
2069 can skip the whole thing. */
2070 if (fde->cie->saw_z_augmentation)
2074 length = read_unsigned_leb128 (unit->abfd, buf, &bytes_read);
2075 buf += bytes_read + length;
2080 fde->instructions = buf;
2083 fde->eh_frame_p = eh_frame_p;
2085 add_fde (fde_table, fde);
2091 /* Read a CIE or FDE in BUF and decode it. */
2093 decode_frame_entry (struct comp_unit *unit, gdb_byte *start, int eh_frame_p,
2094 struct dwarf2_cie_table *cie_table,
2095 struct dwarf2_fde_table *fde_table)
2097 enum { NONE, ALIGN4, ALIGN8, FAIL } workaround = NONE;
2099 ptrdiff_t start_offset;
2103 ret = decode_frame_entry_1 (unit, start, eh_frame_p,
2104 cie_table, fde_table);
2108 /* We have corrupt input data of some form. */
2110 /* ??? Try, weakly, to work around compiler/assembler/linker bugs
2111 and mismatches wrt padding and alignment of debug sections. */
2112 /* Note that there is no requirement in the standard for any
2113 alignment at all in the frame unwind sections. Testing for
2114 alignment before trying to interpret data would be incorrect.
2116 However, GCC traditionally arranged for frame sections to be
2117 sized such that the FDE length and CIE fields happen to be
2118 aligned (in theory, for performance). This, unfortunately,
2119 was done with .align directives, which had the side effect of
2120 forcing the section to be aligned by the linker.
2122 This becomes a problem when you have some other producer that
2123 creates frame sections that are not as strictly aligned. That
2124 produces a hole in the frame info that gets filled by the
2127 The GCC behaviour is arguably a bug, but it's effectively now
2128 part of the ABI, so we're now stuck with it, at least at the
2129 object file level. A smart linker may decide, in the process
2130 of compressing duplicate CIE information, that it can rewrite
2131 the entire output section without this extra padding. */
2133 start_offset = start - unit->dwarf_frame_buffer;
2134 if (workaround < ALIGN4 && (start_offset & 3) != 0)
2136 start += 4 - (start_offset & 3);
2137 workaround = ALIGN4;
2140 if (workaround < ALIGN8 && (start_offset & 7) != 0)
2142 start += 8 - (start_offset & 7);
2143 workaround = ALIGN8;
2147 /* Nothing left to try. Arrange to return as if we've consumed
2148 the entire input section. Hopefully we'll get valid info from
2149 the other of .debug_frame/.eh_frame. */
2151 ret = unit->dwarf_frame_buffer + unit->dwarf_frame_size;
2161 complaint (&symfile_complaints, _("\
2162 Corrupt data in %s:%s; align 4 workaround apparently succeeded"),
2163 unit->dwarf_frame_section->owner->filename,
2164 unit->dwarf_frame_section->name);
2168 complaint (&symfile_complaints, _("\
2169 Corrupt data in %s:%s; align 8 workaround apparently succeeded"),
2170 unit->dwarf_frame_section->owner->filename,
2171 unit->dwarf_frame_section->name);
2175 complaint (&symfile_complaints,
2176 _("Corrupt data in %s:%s"),
2177 unit->dwarf_frame_section->owner->filename,
2178 unit->dwarf_frame_section->name);
2186 /* Imported from dwarf2read.c. */
2187 extern void dwarf2_get_section_info (struct objfile *, const char *,
2188 asection **, gdb_byte **,
2192 qsort_fde_cmp (const void *a, const void *b)
2194 struct dwarf2_fde *aa = *(struct dwarf2_fde **)a;
2195 struct dwarf2_fde *bb = *(struct dwarf2_fde **)b;
2197 if (aa->initial_location == bb->initial_location)
2199 if (aa->address_range != bb->address_range
2200 && aa->eh_frame_p == 0 && bb->eh_frame_p == 0)
2201 /* Linker bug, e.g. gold/10400.
2202 Work around it by keeping stable sort order. */
2203 return (a < b) ? -1 : 1;
2205 /* Put eh_frame entries after debug_frame ones. */
2206 return aa->eh_frame_p - bb->eh_frame_p;
2209 return (aa->initial_location < bb->initial_location) ? -1 : 1;
2213 dwarf2_build_frame_info (struct objfile *objfile)
2215 struct comp_unit *unit;
2216 gdb_byte *frame_ptr;
2217 struct dwarf2_cie_table cie_table;
2218 struct dwarf2_fde_table fde_table;
2219 struct dwarf2_fde_table *fde_table2;
2221 cie_table.num_entries = 0;
2222 cie_table.entries = NULL;
2224 fde_table.num_entries = 0;
2225 fde_table.entries = NULL;
2227 /* Build a minimal decoding of the DWARF2 compilation unit. */
2228 unit = (struct comp_unit *) obstack_alloc (&objfile->objfile_obstack,
2229 sizeof (struct comp_unit));
2230 unit->abfd = objfile->obfd;
2231 unit->objfile = objfile;
2235 dwarf2_get_section_info (objfile, ".eh_frame",
2236 &unit->dwarf_frame_section,
2237 &unit->dwarf_frame_buffer,
2238 &unit->dwarf_frame_size);
2239 if (unit->dwarf_frame_size)
2241 asection *got, *txt;
2243 /* FIXME: kettenis/20030602: This is the DW_EH_PE_datarel base
2244 that is used for the i386/amd64 target, which currently is
2245 the only target in GCC that supports/uses the
2246 DW_EH_PE_datarel encoding. */
2247 got = bfd_get_section_by_name (unit->abfd, ".got");
2249 unit->dbase = got->vma;
2251 /* GCC emits the DW_EH_PE_textrel encoding type on sh and ia64
2253 txt = bfd_get_section_by_name (unit->abfd, ".text");
2255 unit->tbase = txt->vma;
2257 frame_ptr = unit->dwarf_frame_buffer;
2258 while (frame_ptr < unit->dwarf_frame_buffer + unit->dwarf_frame_size)
2259 frame_ptr = decode_frame_entry (unit, frame_ptr, 1,
2260 &cie_table, &fde_table);
2262 if (cie_table.num_entries != 0)
2264 /* Reinit cie_table: debug_frame has different CIEs. */
2265 xfree (cie_table.entries);
2266 cie_table.num_entries = 0;
2267 cie_table.entries = NULL;
2271 dwarf2_get_section_info (objfile, ".debug_frame",
2272 &unit->dwarf_frame_section,
2273 &unit->dwarf_frame_buffer,
2274 &unit->dwarf_frame_size);
2275 if (unit->dwarf_frame_size)
2277 frame_ptr = unit->dwarf_frame_buffer;
2278 while (frame_ptr < unit->dwarf_frame_buffer + unit->dwarf_frame_size)
2279 frame_ptr = decode_frame_entry (unit, frame_ptr, 0,
2280 &cie_table, &fde_table);
2283 /* Discard the cie_table, it is no longer needed. */
2284 if (cie_table.num_entries != 0)
2286 xfree (cie_table.entries);
2287 cie_table.entries = NULL; /* Paranoia. */
2288 cie_table.num_entries = 0; /* Paranoia. */
2291 /* Copy fde_table to obstack: it is needed at runtime. */
2292 fde_table2 = (struct dwarf2_fde_table *)
2293 obstack_alloc (&objfile->objfile_obstack, sizeof (*fde_table2));
2295 if (fde_table.num_entries == 0)
2297 fde_table2->entries = NULL;
2298 fde_table2->num_entries = 0;
2302 struct dwarf2_fde *fde_prev = NULL;
2303 struct dwarf2_fde *first_non_zero_fde = NULL;
2306 /* Prepare FDE table for lookups. */
2307 qsort (fde_table.entries, fde_table.num_entries,
2308 sizeof (fde_table.entries[0]), qsort_fde_cmp);
2310 /* Check for leftovers from --gc-sections. The GNU linker sets
2311 the relevant symbols to zero, but doesn't zero the FDE *end*
2312 ranges because there's no relocation there. It's (offset,
2313 length), not (start, end). On targets where address zero is
2314 just another valid address this can be a problem, since the
2315 FDEs appear to be non-empty in the output --- we could pick
2316 out the wrong FDE. To work around this, when overlaps are
2317 detected, we prefer FDEs that do not start at zero.
2319 Start by finding the first FDE with non-zero start. Below
2320 we'll discard all FDEs that start at zero and overlap this
2322 for (i = 0; i < fde_table.num_entries; i++)
2324 struct dwarf2_fde *fde = fde_table.entries[i];
2326 if (fde->initial_location != 0)
2328 first_non_zero_fde = fde;
2333 /* Since we'll be doing bsearch, squeeze out identical (except
2334 for eh_frame_p) fde entries so bsearch result is predictable.
2335 Also discard leftovers from --gc-sections. */
2336 fde_table2->num_entries = 0;
2337 for (i = 0; i < fde_table.num_entries; i++)
2339 struct dwarf2_fde *fde = fde_table.entries[i];
2341 if (fde->initial_location == 0
2342 && first_non_zero_fde != NULL
2343 && (first_non_zero_fde->initial_location
2344 < fde->initial_location + fde->address_range))
2347 if (fde_prev != NULL
2348 && fde_prev->initial_location == fde->initial_location)
2351 obstack_grow (&objfile->objfile_obstack, &fde_table.entries[i],
2352 sizeof (fde_table.entries[0]));
2353 ++fde_table2->num_entries;
2356 fde_table2->entries = obstack_finish (&objfile->objfile_obstack);
2358 /* Discard the original fde_table. */
2359 xfree (fde_table.entries);
2362 set_objfile_data (objfile, dwarf2_frame_objfile_data, fde_table2);
2365 /* Provide a prototype to silence -Wmissing-prototypes. */
2366 void _initialize_dwarf2_frame (void);
2369 _initialize_dwarf2_frame (void)
2371 dwarf2_frame_data = gdbarch_data_register_pre_init (dwarf2_frame_init);
2372 dwarf2_frame_objfile_data = register_objfile_data ();