1 /* Frame unwinder for frames with DWARF Call Frame Information.
3 Copyright (C) 2003, 2004, 2005, 2007, 2008, 2009, 2010
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"
44 /* Call Frame Information (CFI). */
46 /* Common Information Entry (CIE). */
50 /* Computation Unit for this CIE. */
51 struct comp_unit
*unit
;
53 /* Offset into the .debug_frame section where this CIE was found.
54 Used to identify this CIE. */
57 /* Constant that is factored out of all advance location
59 ULONGEST code_alignment_factor
;
61 /* Constants that is factored out of all offset instructions. */
62 LONGEST data_alignment_factor
;
64 /* Return address column. */
65 ULONGEST return_address_register
;
67 /* Instruction sequence to initialize a register set. */
68 gdb_byte
*initial_instructions
;
71 /* Saved augmentation, in case it's needed later. */
74 /* Encoding of addresses. */
77 /* Target address size in bytes. */
80 /* True if a 'z' augmentation existed. */
81 unsigned char saw_z_augmentation
;
83 /* True if an 'S' augmentation existed. */
84 unsigned char signal_frame
;
86 /* The version recorded in the CIE. */
87 unsigned char version
;
89 /* The segment size. */
90 unsigned char segment_size
;
93 struct dwarf2_cie_table
96 struct dwarf2_cie
**entries
;
99 /* Frame Description Entry (FDE). */
103 /* CIE for this FDE. */
104 struct dwarf2_cie
*cie
;
106 /* First location associated with this FDE. */
107 CORE_ADDR initial_location
;
109 /* Number of bytes of program instructions described by this FDE. */
110 CORE_ADDR address_range
;
112 /* Instruction sequence. */
113 gdb_byte
*instructions
;
116 /* True if this FDE is read from a .eh_frame instead of a .debug_frame
118 unsigned char eh_frame_p
;
121 struct dwarf2_fde_table
124 struct dwarf2_fde
**entries
;
127 /* A minimal decoding of DWARF2 compilation units. We only decode
128 what's needed to get to the call frame information. */
132 /* Keep the bfd convenient. */
135 struct objfile
*objfile
;
137 /* Pointer to the .debug_frame section loaded into memory. */
138 gdb_byte
*dwarf_frame_buffer
;
140 /* Length of the loaded .debug_frame section. */
141 bfd_size_type dwarf_frame_size
;
143 /* Pointer to the .debug_frame section. */
144 asection
*dwarf_frame_section
;
146 /* Base for DW_EH_PE_datarel encodings. */
149 /* Base for DW_EH_PE_textrel encodings. */
153 static struct dwarf2_fde
*dwarf2_frame_find_fde (CORE_ADDR
*pc
);
155 static int dwarf2_frame_adjust_regnum (struct gdbarch
*gdbarch
, int regnum
,
158 static CORE_ADDR
read_encoded_value (struct comp_unit
*unit
, gdb_byte encoding
,
159 int ptr_len
, gdb_byte
*buf
,
160 unsigned int *bytes_read_ptr
,
161 CORE_ADDR func_base
);
164 /* Structure describing a frame state. */
166 struct dwarf2_frame_state
168 /* Each register save state can be described in terms of a CFA slot,
169 another register, or a location expression. */
170 struct dwarf2_frame_state_reg_info
172 struct dwarf2_frame_state_reg
*reg
;
184 /* Used to implement DW_CFA_remember_state. */
185 struct dwarf2_frame_state_reg_info
*prev
;
188 /* The PC described by the current frame state. */
191 /* Initial register set from the CIE.
192 Used to implement DW_CFA_restore. */
193 struct dwarf2_frame_state_reg_info initial
;
195 /* The information we care about from the CIE. */
198 ULONGEST retaddr_column
;
200 /* Flags for known producer quirks. */
202 /* The ARM compilers, in DWARF2 mode, assume that DW_CFA_def_cfa
203 and DW_CFA_def_cfa_offset takes a factored offset. */
204 int armcc_cfa_offsets_sf
;
206 /* The ARM compilers, in DWARF2 or DWARF3 mode, may assume that
207 the CFA is defined as REG - OFFSET rather than REG + OFFSET. */
208 int armcc_cfa_offsets_reversed
;
211 /* Store the length the expression for the CFA in the `cfa_reg' field,
212 which is unused in that case. */
213 #define cfa_exp_len cfa_reg
215 /* Assert that the register set RS is large enough to store gdbarch_num_regs
216 columns. If necessary, enlarge the register set. */
219 dwarf2_frame_state_alloc_regs (struct dwarf2_frame_state_reg_info
*rs
,
222 size_t size
= sizeof (struct dwarf2_frame_state_reg
);
224 if (num_regs
<= rs
->num_regs
)
227 rs
->reg
= (struct dwarf2_frame_state_reg
*)
228 xrealloc (rs
->reg
, num_regs
* size
);
230 /* Initialize newly allocated registers. */
231 memset (rs
->reg
+ rs
->num_regs
, 0, (num_regs
- rs
->num_regs
) * size
);
232 rs
->num_regs
= num_regs
;
235 /* Copy the register columns in register set RS into newly allocated
236 memory and return a pointer to this newly created copy. */
238 static struct dwarf2_frame_state_reg
*
239 dwarf2_frame_state_copy_regs (struct dwarf2_frame_state_reg_info
*rs
)
241 size_t size
= rs
->num_regs
* sizeof (struct dwarf2_frame_state_reg
);
242 struct dwarf2_frame_state_reg
*reg
;
244 reg
= (struct dwarf2_frame_state_reg
*) xmalloc (size
);
245 memcpy (reg
, rs
->reg
, size
);
250 /* Release the memory allocated to register set RS. */
253 dwarf2_frame_state_free_regs (struct dwarf2_frame_state_reg_info
*rs
)
257 dwarf2_frame_state_free_regs (rs
->prev
);
264 /* Release the memory allocated to the frame state FS. */
267 dwarf2_frame_state_free (void *p
)
269 struct dwarf2_frame_state
*fs
= p
;
271 dwarf2_frame_state_free_regs (fs
->initial
.prev
);
272 dwarf2_frame_state_free_regs (fs
->regs
.prev
);
273 xfree (fs
->initial
.reg
);
274 xfree (fs
->regs
.reg
);
279 /* Helper functions for execute_stack_op. */
282 read_reg (void *baton
, int reg
)
284 struct frame_info
*this_frame
= (struct frame_info
*) baton
;
285 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
289 regnum
= gdbarch_dwarf2_reg_to_regnum (gdbarch
, reg
);
291 buf
= alloca (register_size (gdbarch
, regnum
));
292 get_frame_register (this_frame
, regnum
, buf
);
294 /* Convert the register to an integer. This returns a LONGEST
295 rather than a CORE_ADDR, but unpack_pointer does the same thing
296 under the covers, and this makes more sense for non-pointer
297 registers. Maybe read_reg and the associated interfaces should
298 deal with "struct value" instead of CORE_ADDR. */
299 return unpack_long (register_type (gdbarch
, regnum
), buf
);
303 read_mem (void *baton
, gdb_byte
*buf
, CORE_ADDR addr
, size_t len
)
305 read_memory (addr
, buf
, len
);
309 no_get_frame_base (void *baton
, gdb_byte
**start
, size_t *length
)
311 internal_error (__FILE__
, __LINE__
,
312 _("Support for DW_OP_fbreg is unimplemented"));
315 /* Helper function for execute_stack_op. */
318 no_get_frame_cfa (void *baton
)
320 internal_error (__FILE__
, __LINE__
,
321 _("Support for DW_OP_call_frame_cfa is unimplemented"));
325 no_get_tls_address (void *baton
, CORE_ADDR offset
)
327 internal_error (__FILE__
, __LINE__
,
328 _("Support for DW_OP_GNU_push_tls_address is unimplemented"));
331 /* Execute the required actions for both the DW_CFA_restore and
332 DW_CFA_restore_extended instructions. */
334 dwarf2_restore_rule (struct gdbarch
*gdbarch
, ULONGEST reg_num
,
335 struct dwarf2_frame_state
*fs
, int eh_frame_p
)
339 gdb_assert (fs
->initial
.reg
);
340 reg
= dwarf2_frame_adjust_regnum (gdbarch
, reg_num
, eh_frame_p
);
341 dwarf2_frame_state_alloc_regs (&fs
->regs
, reg
+ 1);
343 /* Check if this register was explicitly initialized in the
344 CIE initial instructions. If not, default the rule to
346 if (reg
< fs
->initial
.num_regs
)
347 fs
->regs
.reg
[reg
] = fs
->initial
.reg
[reg
];
349 fs
->regs
.reg
[reg
].how
= DWARF2_FRAME_REG_UNSPECIFIED
;
351 if (fs
->regs
.reg
[reg
].how
== DWARF2_FRAME_REG_UNSPECIFIED
)
352 complaint (&symfile_complaints
, _("\
353 incomplete CFI data; DW_CFA_restore unspecified\n\
354 register %s (#%d) at %s"),
355 gdbarch_register_name
356 (gdbarch
, gdbarch_dwarf2_reg_to_regnum (gdbarch
, reg
)),
357 gdbarch_dwarf2_reg_to_regnum (gdbarch
, reg
),
358 paddress (gdbarch
, fs
->pc
));
362 execute_stack_op (gdb_byte
*exp
, ULONGEST len
, int addr_size
,
363 struct frame_info
*this_frame
, CORE_ADDR initial
,
364 int initial_in_stack_memory
)
366 struct dwarf_expr_context
*ctx
;
368 struct cleanup
*old_chain
;
370 ctx
= new_dwarf_expr_context ();
371 old_chain
= make_cleanup_free_dwarf_expr_context (ctx
);
373 ctx
->gdbarch
= get_frame_arch (this_frame
);
374 ctx
->addr_size
= addr_size
;
375 ctx
->baton
= this_frame
;
376 ctx
->read_reg
= read_reg
;
377 ctx
->read_mem
= read_mem
;
378 ctx
->get_frame_base
= no_get_frame_base
;
379 ctx
->get_frame_cfa
= no_get_frame_cfa
;
380 ctx
->get_tls_address
= no_get_tls_address
;
382 dwarf_expr_push (ctx
, initial
, initial_in_stack_memory
);
383 dwarf_expr_eval (ctx
, exp
, len
);
384 result
= dwarf_expr_fetch (ctx
, 0);
386 if (ctx
->location
== DWARF_VALUE_REGISTER
)
387 result
= read_reg (this_frame
, result
);
388 else if (ctx
->location
!= DWARF_VALUE_MEMORY
)
390 /* This is actually invalid DWARF, but if we ever do run across
391 it somehow, we might as well support it. So, instead, report
392 it as unimplemented. */
393 error (_("Not implemented: computing unwound register using explicit value operator"));
396 do_cleanups (old_chain
);
403 execute_cfa_program (struct dwarf2_fde
*fde
, gdb_byte
*insn_ptr
,
404 gdb_byte
*insn_end
, struct frame_info
*this_frame
,
405 struct dwarf2_frame_state
*fs
)
407 int eh_frame_p
= fde
->eh_frame_p
;
408 CORE_ADDR pc
= get_frame_pc (this_frame
);
410 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
411 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
413 while (insn_ptr
< insn_end
&& fs
->pc
<= pc
)
415 gdb_byte insn
= *insn_ptr
++;
419 if ((insn
& 0xc0) == DW_CFA_advance_loc
)
420 fs
->pc
+= (insn
& 0x3f) * fs
->code_align
;
421 else if ((insn
& 0xc0) == DW_CFA_offset
)
424 reg
= dwarf2_frame_adjust_regnum (gdbarch
, reg
, eh_frame_p
);
425 insn_ptr
= read_uleb128 (insn_ptr
, insn_end
, &utmp
);
426 offset
= utmp
* fs
->data_align
;
427 dwarf2_frame_state_alloc_regs (&fs
->regs
, reg
+ 1);
428 fs
->regs
.reg
[reg
].how
= DWARF2_FRAME_REG_SAVED_OFFSET
;
429 fs
->regs
.reg
[reg
].loc
.offset
= offset
;
431 else if ((insn
& 0xc0) == DW_CFA_restore
)
434 dwarf2_restore_rule (gdbarch
, reg
, fs
, eh_frame_p
);
441 fs
->pc
= read_encoded_value (fde
->cie
->unit
, fde
->cie
->encoding
,
442 fde
->cie
->addr_size
, insn_ptr
,
443 &bytes_read
, fde
->initial_location
);
444 /* Apply the objfile offset for relocatable objects. */
445 fs
->pc
+= ANOFFSET (fde
->cie
->unit
->objfile
->section_offsets
,
446 SECT_OFF_TEXT (fde
->cie
->unit
->objfile
));
447 insn_ptr
+= bytes_read
;
450 case DW_CFA_advance_loc1
:
451 utmp
= extract_unsigned_integer (insn_ptr
, 1, byte_order
);
452 fs
->pc
+= utmp
* fs
->code_align
;
455 case DW_CFA_advance_loc2
:
456 utmp
= extract_unsigned_integer (insn_ptr
, 2, byte_order
);
457 fs
->pc
+= utmp
* fs
->code_align
;
460 case DW_CFA_advance_loc4
:
461 utmp
= extract_unsigned_integer (insn_ptr
, 4, byte_order
);
462 fs
->pc
+= utmp
* fs
->code_align
;
466 case DW_CFA_offset_extended
:
467 insn_ptr
= read_uleb128 (insn_ptr
, insn_end
, ®
);
468 reg
= dwarf2_frame_adjust_regnum (gdbarch
, reg
, eh_frame_p
);
469 insn_ptr
= read_uleb128 (insn_ptr
, insn_end
, &utmp
);
470 offset
= utmp
* fs
->data_align
;
471 dwarf2_frame_state_alloc_regs (&fs
->regs
, reg
+ 1);
472 fs
->regs
.reg
[reg
].how
= DWARF2_FRAME_REG_SAVED_OFFSET
;
473 fs
->regs
.reg
[reg
].loc
.offset
= offset
;
476 case DW_CFA_restore_extended
:
477 insn_ptr
= read_uleb128 (insn_ptr
, insn_end
, ®
);
478 dwarf2_restore_rule (gdbarch
, reg
, fs
, eh_frame_p
);
481 case DW_CFA_undefined
:
482 insn_ptr
= read_uleb128 (insn_ptr
, insn_end
, ®
);
483 reg
= dwarf2_frame_adjust_regnum (gdbarch
, reg
, eh_frame_p
);
484 dwarf2_frame_state_alloc_regs (&fs
->regs
, reg
+ 1);
485 fs
->regs
.reg
[reg
].how
= DWARF2_FRAME_REG_UNDEFINED
;
488 case DW_CFA_same_value
:
489 insn_ptr
= read_uleb128 (insn_ptr
, insn_end
, ®
);
490 reg
= dwarf2_frame_adjust_regnum (gdbarch
, reg
, eh_frame_p
);
491 dwarf2_frame_state_alloc_regs (&fs
->regs
, reg
+ 1);
492 fs
->regs
.reg
[reg
].how
= DWARF2_FRAME_REG_SAME_VALUE
;
495 case DW_CFA_register
:
496 insn_ptr
= read_uleb128 (insn_ptr
, insn_end
, ®
);
497 reg
= dwarf2_frame_adjust_regnum (gdbarch
, reg
, eh_frame_p
);
498 insn_ptr
= read_uleb128 (insn_ptr
, insn_end
, &utmp
);
499 utmp
= dwarf2_frame_adjust_regnum (gdbarch
, utmp
, eh_frame_p
);
500 dwarf2_frame_state_alloc_regs (&fs
->regs
, reg
+ 1);
501 fs
->regs
.reg
[reg
].how
= DWARF2_FRAME_REG_SAVED_REG
;
502 fs
->regs
.reg
[reg
].loc
.reg
= utmp
;
505 case DW_CFA_remember_state
:
507 struct dwarf2_frame_state_reg_info
*new_rs
;
509 new_rs
= XMALLOC (struct dwarf2_frame_state_reg_info
);
511 fs
->regs
.reg
= dwarf2_frame_state_copy_regs (&fs
->regs
);
512 fs
->regs
.prev
= new_rs
;
516 case DW_CFA_restore_state
:
518 struct dwarf2_frame_state_reg_info
*old_rs
= fs
->regs
.prev
;
522 complaint (&symfile_complaints
, _("\
523 bad CFI data; mismatched DW_CFA_restore_state at %s"),
524 paddress (gdbarch
, fs
->pc
));
528 xfree (fs
->regs
.reg
);
536 insn_ptr
= read_uleb128 (insn_ptr
, insn_end
, &fs
->regs
.cfa_reg
);
537 insn_ptr
= read_uleb128 (insn_ptr
, insn_end
, &utmp
);
539 if (fs
->armcc_cfa_offsets_sf
)
540 utmp
*= fs
->data_align
;
542 fs
->regs
.cfa_offset
= utmp
;
543 fs
->regs
.cfa_how
= CFA_REG_OFFSET
;
546 case DW_CFA_def_cfa_register
:
547 insn_ptr
= read_uleb128 (insn_ptr
, insn_end
, &fs
->regs
.cfa_reg
);
548 fs
->regs
.cfa_reg
= dwarf2_frame_adjust_regnum (gdbarch
,
551 fs
->regs
.cfa_how
= CFA_REG_OFFSET
;
554 case DW_CFA_def_cfa_offset
:
555 insn_ptr
= read_uleb128 (insn_ptr
, insn_end
, &utmp
);
557 if (fs
->armcc_cfa_offsets_sf
)
558 utmp
*= fs
->data_align
;
560 fs
->regs
.cfa_offset
= utmp
;
561 /* cfa_how deliberately not set. */
567 case DW_CFA_def_cfa_expression
:
568 insn_ptr
= read_uleb128 (insn_ptr
, insn_end
,
569 &fs
->regs
.cfa_exp_len
);
570 fs
->regs
.cfa_exp
= insn_ptr
;
571 fs
->regs
.cfa_how
= CFA_EXP
;
572 insn_ptr
+= fs
->regs
.cfa_exp_len
;
575 case DW_CFA_expression
:
576 insn_ptr
= read_uleb128 (insn_ptr
, insn_end
, ®
);
577 reg
= dwarf2_frame_adjust_regnum (gdbarch
, reg
, eh_frame_p
);
578 dwarf2_frame_state_alloc_regs (&fs
->regs
, reg
+ 1);
579 insn_ptr
= read_uleb128 (insn_ptr
, insn_end
, &utmp
);
580 fs
->regs
.reg
[reg
].loc
.exp
= insn_ptr
;
581 fs
->regs
.reg
[reg
].exp_len
= utmp
;
582 fs
->regs
.reg
[reg
].how
= DWARF2_FRAME_REG_SAVED_EXP
;
586 case DW_CFA_offset_extended_sf
:
587 insn_ptr
= read_uleb128 (insn_ptr
, insn_end
, ®
);
588 reg
= dwarf2_frame_adjust_regnum (gdbarch
, reg
, eh_frame_p
);
589 insn_ptr
= read_sleb128 (insn_ptr
, insn_end
, &offset
);
590 offset
*= fs
->data_align
;
591 dwarf2_frame_state_alloc_regs (&fs
->regs
, reg
+ 1);
592 fs
->regs
.reg
[reg
].how
= DWARF2_FRAME_REG_SAVED_OFFSET
;
593 fs
->regs
.reg
[reg
].loc
.offset
= offset
;
596 case DW_CFA_val_offset
:
597 insn_ptr
= read_uleb128 (insn_ptr
, insn_end
, ®
);
598 dwarf2_frame_state_alloc_regs (&fs
->regs
, reg
+ 1);
599 insn_ptr
= read_uleb128 (insn_ptr
, insn_end
, &utmp
);
600 offset
= utmp
* fs
->data_align
;
601 fs
->regs
.reg
[reg
].how
= DWARF2_FRAME_REG_SAVED_VAL_OFFSET
;
602 fs
->regs
.reg
[reg
].loc
.offset
= offset
;
605 case DW_CFA_val_offset_sf
:
606 insn_ptr
= read_uleb128 (insn_ptr
, insn_end
, ®
);
607 dwarf2_frame_state_alloc_regs (&fs
->regs
, reg
+ 1);
608 insn_ptr
= read_sleb128 (insn_ptr
, insn_end
, &offset
);
609 offset
*= fs
->data_align
;
610 fs
->regs
.reg
[reg
].how
= DWARF2_FRAME_REG_SAVED_VAL_OFFSET
;
611 fs
->regs
.reg
[reg
].loc
.offset
= offset
;
614 case DW_CFA_val_expression
:
615 insn_ptr
= read_uleb128 (insn_ptr
, insn_end
, ®
);
616 dwarf2_frame_state_alloc_regs (&fs
->regs
, reg
+ 1);
617 insn_ptr
= read_uleb128 (insn_ptr
, insn_end
, &utmp
);
618 fs
->regs
.reg
[reg
].loc
.exp
= insn_ptr
;
619 fs
->regs
.reg
[reg
].exp_len
= utmp
;
620 fs
->regs
.reg
[reg
].how
= DWARF2_FRAME_REG_SAVED_VAL_EXP
;
624 case DW_CFA_def_cfa_sf
:
625 insn_ptr
= read_uleb128 (insn_ptr
, insn_end
, &fs
->regs
.cfa_reg
);
626 fs
->regs
.cfa_reg
= dwarf2_frame_adjust_regnum (gdbarch
,
629 insn_ptr
= read_sleb128 (insn_ptr
, insn_end
, &offset
);
630 fs
->regs
.cfa_offset
= offset
* fs
->data_align
;
631 fs
->regs
.cfa_how
= CFA_REG_OFFSET
;
634 case DW_CFA_def_cfa_offset_sf
:
635 insn_ptr
= read_sleb128 (insn_ptr
, insn_end
, &offset
);
636 fs
->regs
.cfa_offset
= offset
* fs
->data_align
;
637 /* cfa_how deliberately not set. */
640 case DW_CFA_GNU_window_save
:
641 /* This is SPARC-specific code, and contains hard-coded
642 constants for the register numbering scheme used by
643 GCC. Rather than having a architecture-specific
644 operation that's only ever used by a single
645 architecture, we provide the implementation here.
646 Incidentally that's what GCC does too in its
649 int size
= register_size (gdbarch
, 0);
650 dwarf2_frame_state_alloc_regs (&fs
->regs
, 32);
651 for (reg
= 8; reg
< 16; reg
++)
653 fs
->regs
.reg
[reg
].how
= DWARF2_FRAME_REG_SAVED_REG
;
654 fs
->regs
.reg
[reg
].loc
.reg
= reg
+ 16;
656 for (reg
= 16; reg
< 32; reg
++)
658 fs
->regs
.reg
[reg
].how
= DWARF2_FRAME_REG_SAVED_OFFSET
;
659 fs
->regs
.reg
[reg
].loc
.offset
= (reg
- 16) * size
;
664 case DW_CFA_GNU_args_size
:
666 insn_ptr
= read_uleb128 (insn_ptr
, insn_end
, &utmp
);
669 case DW_CFA_GNU_negative_offset_extended
:
670 insn_ptr
= read_uleb128 (insn_ptr
, insn_end
, ®
);
671 reg
= dwarf2_frame_adjust_regnum (gdbarch
, reg
, eh_frame_p
);
672 insn_ptr
= read_uleb128 (insn_ptr
, insn_end
, &offset
);
673 offset
*= fs
->data_align
;
674 dwarf2_frame_state_alloc_regs (&fs
->regs
, reg
+ 1);
675 fs
->regs
.reg
[reg
].how
= DWARF2_FRAME_REG_SAVED_OFFSET
;
676 fs
->regs
.reg
[reg
].loc
.offset
= -offset
;
680 internal_error (__FILE__
, __LINE__
, _("Unknown CFI encountered."));
685 /* Don't allow remember/restore between CIE and FDE programs. */
686 dwarf2_frame_state_free_regs (fs
->regs
.prev
);
687 fs
->regs
.prev
= NULL
;
691 /* Architecture-specific operations. */
693 /* Per-architecture data key. */
694 static struct gdbarch_data
*dwarf2_frame_data
;
696 struct dwarf2_frame_ops
698 /* Pre-initialize the register state REG for register REGNUM. */
699 void (*init_reg
) (struct gdbarch
*, int, struct dwarf2_frame_state_reg
*,
700 struct frame_info
*);
702 /* Check whether the THIS_FRAME is a signal trampoline. */
703 int (*signal_frame_p
) (struct gdbarch
*, struct frame_info
*);
705 /* Convert .eh_frame register number to DWARF register number, or
706 adjust .debug_frame register number. */
707 int (*adjust_regnum
) (struct gdbarch
*, int, int);
710 /* Default architecture-specific register state initialization
714 dwarf2_frame_default_init_reg (struct gdbarch
*gdbarch
, int regnum
,
715 struct dwarf2_frame_state_reg
*reg
,
716 struct frame_info
*this_frame
)
718 /* If we have a register that acts as a program counter, mark it as
719 a destination for the return address. If we have a register that
720 serves as the stack pointer, arrange for it to be filled with the
721 call frame address (CFA). The other registers are marked as
724 We copy the return address to the program counter, since many
725 parts in GDB assume that it is possible to get the return address
726 by unwinding the program counter register. However, on ISA's
727 with a dedicated return address register, the CFI usually only
728 contains information to unwind that return address register.
730 The reason we're treating the stack pointer special here is
731 because in many cases GCC doesn't emit CFI for the stack pointer
732 and implicitly assumes that it is equal to the CFA. This makes
733 some sense since the DWARF specification (version 3, draft 8,
736 "Typically, the CFA is defined to be the value of the stack
737 pointer at the call site in the previous frame (which may be
738 different from its value on entry to the current frame)."
740 However, this isn't true for all platforms supported by GCC
741 (e.g. IBM S/390 and zSeries). Those architectures should provide
742 their own architecture-specific initialization function. */
744 if (regnum
== gdbarch_pc_regnum (gdbarch
))
745 reg
->how
= DWARF2_FRAME_REG_RA
;
746 else if (regnum
== gdbarch_sp_regnum (gdbarch
))
747 reg
->how
= DWARF2_FRAME_REG_CFA
;
750 /* Return a default for the architecture-specific operations. */
753 dwarf2_frame_init (struct obstack
*obstack
)
755 struct dwarf2_frame_ops
*ops
;
757 ops
= OBSTACK_ZALLOC (obstack
, struct dwarf2_frame_ops
);
758 ops
->init_reg
= dwarf2_frame_default_init_reg
;
762 /* Set the architecture-specific register state initialization
763 function for GDBARCH to INIT_REG. */
766 dwarf2_frame_set_init_reg (struct gdbarch
*gdbarch
,
767 void (*init_reg
) (struct gdbarch
*, int,
768 struct dwarf2_frame_state_reg
*,
769 struct frame_info
*))
771 struct dwarf2_frame_ops
*ops
= gdbarch_data (gdbarch
, dwarf2_frame_data
);
773 ops
->init_reg
= init_reg
;
776 /* Pre-initialize the register state REG for register REGNUM. */
779 dwarf2_frame_init_reg (struct gdbarch
*gdbarch
, int regnum
,
780 struct dwarf2_frame_state_reg
*reg
,
781 struct frame_info
*this_frame
)
783 struct dwarf2_frame_ops
*ops
= gdbarch_data (gdbarch
, dwarf2_frame_data
);
785 ops
->init_reg (gdbarch
, regnum
, reg
, this_frame
);
788 /* Set the architecture-specific signal trampoline recognition
789 function for GDBARCH to SIGNAL_FRAME_P. */
792 dwarf2_frame_set_signal_frame_p (struct gdbarch
*gdbarch
,
793 int (*signal_frame_p
) (struct gdbarch
*,
794 struct frame_info
*))
796 struct dwarf2_frame_ops
*ops
= gdbarch_data (gdbarch
, dwarf2_frame_data
);
798 ops
->signal_frame_p
= signal_frame_p
;
801 /* Query the architecture-specific signal frame recognizer for
805 dwarf2_frame_signal_frame_p (struct gdbarch
*gdbarch
,
806 struct frame_info
*this_frame
)
808 struct dwarf2_frame_ops
*ops
= gdbarch_data (gdbarch
, dwarf2_frame_data
);
810 if (ops
->signal_frame_p
== NULL
)
812 return ops
->signal_frame_p (gdbarch
, this_frame
);
815 /* Set the architecture-specific adjustment of .eh_frame and .debug_frame
819 dwarf2_frame_set_adjust_regnum (struct gdbarch
*gdbarch
,
820 int (*adjust_regnum
) (struct gdbarch
*,
823 struct dwarf2_frame_ops
*ops
= gdbarch_data (gdbarch
, dwarf2_frame_data
);
825 ops
->adjust_regnum
= adjust_regnum
;
828 /* Translate a .eh_frame register to DWARF register, or adjust a .debug_frame
832 dwarf2_frame_adjust_regnum (struct gdbarch
*gdbarch
, int regnum
, int eh_frame_p
)
834 struct dwarf2_frame_ops
*ops
= gdbarch_data (gdbarch
, dwarf2_frame_data
);
836 if (ops
->adjust_regnum
== NULL
)
838 return ops
->adjust_regnum (gdbarch
, regnum
, eh_frame_p
);
842 dwarf2_frame_find_quirks (struct dwarf2_frame_state
*fs
,
843 struct dwarf2_fde
*fde
)
847 s
= find_pc_symtab (fs
->pc
);
851 if (producer_is_realview (s
->producer
))
853 if (fde
->cie
->version
== 1)
854 fs
->armcc_cfa_offsets_sf
= 1;
856 if (fde
->cie
->version
== 1)
857 fs
->armcc_cfa_offsets_reversed
= 1;
859 /* The reversed offset problem is present in some compilers
860 using DWARF3, but it was eventually fixed. Check the ARM
861 defined augmentations, which are in the format "armcc" followed
862 by a list of one-character options. The "+" option means
863 this problem is fixed (no quirk needed). If the armcc
864 augmentation is missing, the quirk is needed. */
865 if (fde
->cie
->version
== 3
866 && (strncmp (fde
->cie
->augmentation
, "armcc", 5) != 0
867 || strchr (fde
->cie
->augmentation
+ 5, '+') == NULL
))
868 fs
->armcc_cfa_offsets_reversed
= 1;
875 struct dwarf2_frame_cache
877 /* DWARF Call Frame Address. */
880 /* Set if the return address column was marked as undefined. */
881 int undefined_retaddr
;
883 /* Saved registers, indexed by GDB register number, not by DWARF
885 struct dwarf2_frame_state_reg
*reg
;
887 /* Return address register. */
888 struct dwarf2_frame_state_reg retaddr_reg
;
890 /* Target address size in bytes. */
894 static struct dwarf2_frame_cache
*
895 dwarf2_frame_cache (struct frame_info
*this_frame
, void **this_cache
)
897 struct cleanup
*old_chain
;
898 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
899 const int num_regs
= gdbarch_num_regs (gdbarch
)
900 + gdbarch_num_pseudo_regs (gdbarch
);
901 struct dwarf2_frame_cache
*cache
;
902 struct dwarf2_frame_state
*fs
;
903 struct dwarf2_fde
*fde
;
908 /* Allocate a new cache. */
909 cache
= FRAME_OBSTACK_ZALLOC (struct dwarf2_frame_cache
);
910 cache
->reg
= FRAME_OBSTACK_CALLOC (num_regs
, struct dwarf2_frame_state_reg
);
912 /* Allocate and initialize the frame state. */
913 fs
= XMALLOC (struct dwarf2_frame_state
);
914 memset (fs
, 0, sizeof (struct dwarf2_frame_state
));
915 old_chain
= make_cleanup (dwarf2_frame_state_free
, fs
);
919 Note that if the next frame is never supposed to return (i.e. a call
920 to abort), the compiler might optimize away the instruction at
921 its return address. As a result the return address will
922 point at some random instruction, and the CFI for that
923 instruction is probably worthless to us. GCC's unwinder solves
924 this problem by substracting 1 from the return address to get an
925 address in the middle of a presumed call instruction (or the
926 instruction in the associated delay slot). This should only be
927 done for "normal" frames and not for resume-type frames (signal
928 handlers, sentinel frames, dummy frames). The function
929 get_frame_address_in_block does just this. It's not clear how
930 reliable the method is though; there is the potential for the
931 register state pre-call being different to that on return. */
932 fs
->pc
= get_frame_address_in_block (this_frame
);
934 /* Find the correct FDE. */
935 fde
= dwarf2_frame_find_fde (&fs
->pc
);
936 gdb_assert (fde
!= NULL
);
938 /* Extract any interesting information from the CIE. */
939 fs
->data_align
= fde
->cie
->data_alignment_factor
;
940 fs
->code_align
= fde
->cie
->code_alignment_factor
;
941 fs
->retaddr_column
= fde
->cie
->return_address_register
;
942 cache
->addr_size
= fde
->cie
->addr_size
;
944 /* Check for "quirks" - known bugs in producers. */
945 dwarf2_frame_find_quirks (fs
, fde
);
947 /* First decode all the insns in the CIE. */
948 execute_cfa_program (fde
, fde
->cie
->initial_instructions
,
949 fde
->cie
->end
, this_frame
, fs
);
951 /* Save the initialized register set. */
952 fs
->initial
= fs
->regs
;
953 fs
->initial
.reg
= dwarf2_frame_state_copy_regs (&fs
->regs
);
955 /* Then decode the insns in the FDE up to our target PC. */
956 execute_cfa_program (fde
, fde
->instructions
, fde
->end
, this_frame
, fs
);
958 /* Calculate the CFA. */
959 switch (fs
->regs
.cfa_how
)
962 cache
->cfa
= read_reg (this_frame
, fs
->regs
.cfa_reg
);
963 if (fs
->armcc_cfa_offsets_reversed
)
964 cache
->cfa
-= fs
->regs
.cfa_offset
;
966 cache
->cfa
+= fs
->regs
.cfa_offset
;
971 execute_stack_op (fs
->regs
.cfa_exp
, fs
->regs
.cfa_exp_len
,
972 cache
->addr_size
, this_frame
, 0, 0);
976 internal_error (__FILE__
, __LINE__
, _("Unknown CFA rule."));
979 /* Initialize the register state. */
983 for (regnum
= 0; regnum
< num_regs
; regnum
++)
984 dwarf2_frame_init_reg (gdbarch
, regnum
, &cache
->reg
[regnum
], this_frame
);
987 /* Go through the DWARF2 CFI generated table and save its register
988 location information in the cache. Note that we don't skip the
989 return address column; it's perfectly all right for it to
990 correspond to a real register. If it doesn't correspond to a
991 real register, or if we shouldn't treat it as such,
992 gdbarch_dwarf2_reg_to_regnum should be defined to return a number outside
993 the range [0, gdbarch_num_regs). */
995 int column
; /* CFI speak for "register number". */
997 for (column
= 0; column
< fs
->regs
.num_regs
; column
++)
999 /* Use the GDB register number as the destination index. */
1000 int regnum
= gdbarch_dwarf2_reg_to_regnum (gdbarch
, column
);
1002 /* If there's no corresponding GDB register, ignore it. */
1003 if (regnum
< 0 || regnum
>= num_regs
)
1006 /* NOTE: cagney/2003-09-05: CFI should specify the disposition
1007 of all debug info registers. If it doesn't, complain (but
1008 not too loudly). It turns out that GCC assumes that an
1009 unspecified register implies "same value" when CFI (draft
1010 7) specifies nothing at all. Such a register could equally
1011 be interpreted as "undefined". Also note that this check
1012 isn't sufficient; it only checks that all registers in the
1013 range [0 .. max column] are specified, and won't detect
1014 problems when a debug info register falls outside of the
1015 table. We need a way of iterating through all the valid
1016 DWARF2 register numbers. */
1017 if (fs
->regs
.reg
[column
].how
== DWARF2_FRAME_REG_UNSPECIFIED
)
1019 if (cache
->reg
[regnum
].how
== DWARF2_FRAME_REG_UNSPECIFIED
)
1020 complaint (&symfile_complaints
, _("\
1021 incomplete CFI data; unspecified registers (e.g., %s) at %s"),
1022 gdbarch_register_name (gdbarch
, regnum
),
1023 paddress (gdbarch
, fs
->pc
));
1026 cache
->reg
[regnum
] = fs
->regs
.reg
[column
];
1030 /* Eliminate any DWARF2_FRAME_REG_RA rules, and save the information
1031 we need for evaluating DWARF2_FRAME_REG_RA_OFFSET rules. */
1035 for (regnum
= 0; regnum
< num_regs
; regnum
++)
1037 if (cache
->reg
[regnum
].how
== DWARF2_FRAME_REG_RA
1038 || cache
->reg
[regnum
].how
== DWARF2_FRAME_REG_RA_OFFSET
)
1040 struct dwarf2_frame_state_reg
*retaddr_reg
=
1041 &fs
->regs
.reg
[fs
->retaddr_column
];
1043 /* It seems rather bizarre to specify an "empty" column as
1044 the return adress column. However, this is exactly
1045 what GCC does on some targets. It turns out that GCC
1046 assumes that the return address can be found in the
1047 register corresponding to the return address column.
1048 Incidentally, that's how we should treat a return
1049 address column specifying "same value" too. */
1050 if (fs
->retaddr_column
< fs
->regs
.num_regs
1051 && retaddr_reg
->how
!= DWARF2_FRAME_REG_UNSPECIFIED
1052 && retaddr_reg
->how
!= DWARF2_FRAME_REG_SAME_VALUE
)
1054 if (cache
->reg
[regnum
].how
== DWARF2_FRAME_REG_RA
)
1055 cache
->reg
[regnum
] = *retaddr_reg
;
1057 cache
->retaddr_reg
= *retaddr_reg
;
1061 if (cache
->reg
[regnum
].how
== DWARF2_FRAME_REG_RA
)
1063 cache
->reg
[regnum
].loc
.reg
= fs
->retaddr_column
;
1064 cache
->reg
[regnum
].how
= DWARF2_FRAME_REG_SAVED_REG
;
1068 cache
->retaddr_reg
.loc
.reg
= fs
->retaddr_column
;
1069 cache
->retaddr_reg
.how
= DWARF2_FRAME_REG_SAVED_REG
;
1076 if (fs
->retaddr_column
< fs
->regs
.num_regs
1077 && fs
->regs
.reg
[fs
->retaddr_column
].how
== DWARF2_FRAME_REG_UNDEFINED
)
1078 cache
->undefined_retaddr
= 1;
1080 do_cleanups (old_chain
);
1082 *this_cache
= cache
;
1087 dwarf2_frame_this_id (struct frame_info
*this_frame
, void **this_cache
,
1088 struct frame_id
*this_id
)
1090 struct dwarf2_frame_cache
*cache
=
1091 dwarf2_frame_cache (this_frame
, this_cache
);
1093 if (cache
->undefined_retaddr
)
1096 (*this_id
) = frame_id_build (cache
->cfa
, get_frame_func (this_frame
));
1099 static struct value
*
1100 dwarf2_frame_prev_register (struct frame_info
*this_frame
, void **this_cache
,
1103 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
1104 struct dwarf2_frame_cache
*cache
=
1105 dwarf2_frame_cache (this_frame
, this_cache
);
1109 switch (cache
->reg
[regnum
].how
)
1111 case DWARF2_FRAME_REG_UNDEFINED
:
1112 /* If CFI explicitly specified that the value isn't defined,
1113 mark it as optimized away; the value isn't available. */
1114 return frame_unwind_got_optimized (this_frame
, regnum
);
1116 case DWARF2_FRAME_REG_SAVED_OFFSET
:
1117 addr
= cache
->cfa
+ cache
->reg
[regnum
].loc
.offset
;
1118 return frame_unwind_got_memory (this_frame
, regnum
, addr
);
1120 case DWARF2_FRAME_REG_SAVED_REG
:
1122 = gdbarch_dwarf2_reg_to_regnum (gdbarch
, cache
->reg
[regnum
].loc
.reg
);
1123 return frame_unwind_got_register (this_frame
, regnum
, realnum
);
1125 case DWARF2_FRAME_REG_SAVED_EXP
:
1126 addr
= execute_stack_op (cache
->reg
[regnum
].loc
.exp
,
1127 cache
->reg
[regnum
].exp_len
,
1128 cache
->addr_size
, this_frame
, cache
->cfa
, 1);
1129 return frame_unwind_got_memory (this_frame
, regnum
, addr
);
1131 case DWARF2_FRAME_REG_SAVED_VAL_OFFSET
:
1132 addr
= cache
->cfa
+ cache
->reg
[regnum
].loc
.offset
;
1133 return frame_unwind_got_constant (this_frame
, regnum
, addr
);
1135 case DWARF2_FRAME_REG_SAVED_VAL_EXP
:
1136 addr
= execute_stack_op (cache
->reg
[regnum
].loc
.exp
,
1137 cache
->reg
[regnum
].exp_len
,
1138 cache
->addr_size
, this_frame
, cache
->cfa
, 1);
1139 return frame_unwind_got_constant (this_frame
, regnum
, addr
);
1141 case DWARF2_FRAME_REG_UNSPECIFIED
:
1142 /* GCC, in its infinite wisdom decided to not provide unwind
1143 information for registers that are "same value". Since
1144 DWARF2 (3 draft 7) doesn't define such behavior, said
1145 registers are actually undefined (which is different to CFI
1146 "undefined"). Code above issues a complaint about this.
1147 Here just fudge the books, assume GCC, and that the value is
1148 more inner on the stack. */
1149 return frame_unwind_got_register (this_frame
, regnum
, regnum
);
1151 case DWARF2_FRAME_REG_SAME_VALUE
:
1152 return frame_unwind_got_register (this_frame
, regnum
, regnum
);
1154 case DWARF2_FRAME_REG_CFA
:
1155 return frame_unwind_got_address (this_frame
, regnum
, cache
->cfa
);
1157 case DWARF2_FRAME_REG_CFA_OFFSET
:
1158 addr
= cache
->cfa
+ cache
->reg
[regnum
].loc
.offset
;
1159 return frame_unwind_got_address (this_frame
, regnum
, addr
);
1161 case DWARF2_FRAME_REG_RA_OFFSET
:
1162 addr
= cache
->reg
[regnum
].loc
.offset
;
1163 regnum
= gdbarch_dwarf2_reg_to_regnum
1164 (gdbarch
, cache
->retaddr_reg
.loc
.reg
);
1165 addr
+= get_frame_register_unsigned (this_frame
, regnum
);
1166 return frame_unwind_got_address (this_frame
, regnum
, addr
);
1168 case DWARF2_FRAME_REG_FN
:
1169 return cache
->reg
[regnum
].loc
.fn (this_frame
, this_cache
, regnum
);
1172 internal_error (__FILE__
, __LINE__
, _("Unknown register rule."));
1177 dwarf2_frame_sniffer (const struct frame_unwind
*self
,
1178 struct frame_info
*this_frame
, void **this_cache
)
1180 /* Grab an address that is guarenteed to reside somewhere within the
1181 function. get_frame_pc(), with a no-return next function, can
1182 end up returning something past the end of this function's body.
1183 If the frame we're sniffing for is a signal frame whose start
1184 address is placed on the stack by the OS, its FDE must
1185 extend one byte before its start address or we could potentially
1186 select the FDE of the previous function. */
1187 CORE_ADDR block_addr
= get_frame_address_in_block (this_frame
);
1188 struct dwarf2_fde
*fde
= dwarf2_frame_find_fde (&block_addr
);
1192 /* On some targets, signal trampolines may have unwind information.
1193 We need to recognize them so that we set the frame type
1196 if (fde
->cie
->signal_frame
1197 || dwarf2_frame_signal_frame_p (get_frame_arch (this_frame
),
1199 return self
->type
== SIGTRAMP_FRAME
;
1201 return self
->type
!= SIGTRAMP_FRAME
;
1204 static const struct frame_unwind dwarf2_frame_unwind
=
1207 dwarf2_frame_this_id
,
1208 dwarf2_frame_prev_register
,
1210 dwarf2_frame_sniffer
1213 static const struct frame_unwind dwarf2_signal_frame_unwind
=
1216 dwarf2_frame_this_id
,
1217 dwarf2_frame_prev_register
,
1219 dwarf2_frame_sniffer
1222 /* Append the DWARF-2 frame unwinders to GDBARCH's list. */
1225 dwarf2_append_unwinders (struct gdbarch
*gdbarch
)
1227 frame_unwind_append_unwinder (gdbarch
, &dwarf2_frame_unwind
);
1228 frame_unwind_append_unwinder (gdbarch
, &dwarf2_signal_frame_unwind
);
1232 /* There is no explicitly defined relationship between the CFA and the
1233 location of frame's local variables and arguments/parameters.
1234 Therefore, frame base methods on this page should probably only be
1235 used as a last resort, just to avoid printing total garbage as a
1236 response to the "info frame" command. */
1239 dwarf2_frame_base_address (struct frame_info
*this_frame
, void **this_cache
)
1241 struct dwarf2_frame_cache
*cache
=
1242 dwarf2_frame_cache (this_frame
, this_cache
);
1247 static const struct frame_base dwarf2_frame_base
=
1249 &dwarf2_frame_unwind
,
1250 dwarf2_frame_base_address
,
1251 dwarf2_frame_base_address
,
1252 dwarf2_frame_base_address
1255 const struct frame_base
*
1256 dwarf2_frame_base_sniffer (struct frame_info
*this_frame
)
1258 CORE_ADDR block_addr
= get_frame_address_in_block (this_frame
);
1259 if (dwarf2_frame_find_fde (&block_addr
))
1260 return &dwarf2_frame_base
;
1265 /* Compute the CFA for THIS_FRAME, but only if THIS_FRAME came from
1266 the DWARF unwinder. This is used to implement
1267 DW_OP_call_frame_cfa. */
1270 dwarf2_frame_cfa (struct frame_info
*this_frame
)
1272 while (get_frame_type (this_frame
) == INLINE_FRAME
)
1273 this_frame
= get_prev_frame (this_frame
);
1274 /* This restriction could be lifted if other unwinders are known to
1275 compute the frame base in a way compatible with the DWARF
1277 if (! frame_unwinder_is (this_frame
, &dwarf2_frame_unwind
))
1278 error (_("can't compute CFA for this frame"));
1279 return get_frame_base (this_frame
);
1282 const struct objfile_data
*dwarf2_frame_objfile_data
;
1285 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
1287 return bfd_get_8 (abfd
, buf
);
1291 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
1293 return bfd_get_32 (abfd
, buf
);
1297 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
1299 return bfd_get_64 (abfd
, buf
);
1303 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
1306 unsigned int num_read
;
1316 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
1319 result
|= ((byte
& 0x7f) << shift
);
1322 while (byte
& 0x80);
1324 *bytes_read_ptr
= num_read
;
1330 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
1334 unsigned int num_read
;
1343 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
1346 result
|= ((byte
& 0x7f) << shift
);
1349 while (byte
& 0x80);
1351 if (shift
< 8 * sizeof (result
) && (byte
& 0x40))
1352 result
|= -(((LONGEST
)1) << shift
);
1354 *bytes_read_ptr
= num_read
;
1360 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
1364 result
= bfd_get_32 (abfd
, buf
);
1365 if (result
== 0xffffffff)
1367 result
= bfd_get_64 (abfd
, buf
+ 4);
1368 *bytes_read_ptr
= 12;
1371 *bytes_read_ptr
= 4;
1377 /* Pointer encoding helper functions. */
1379 /* GCC supports exception handling based on DWARF2 CFI. However, for
1380 technical reasons, it encodes addresses in its FDE's in a different
1381 way. Several "pointer encodings" are supported. The encoding
1382 that's used for a particular FDE is determined by the 'R'
1383 augmentation in the associated CIE. The argument of this
1384 augmentation is a single byte.
1386 The address can be encoded as 2 bytes, 4 bytes, 8 bytes, or as a
1387 LEB128. This is encoded in bits 0, 1 and 2. Bit 3 encodes whether
1388 the address is signed or unsigned. Bits 4, 5 and 6 encode how the
1389 address should be interpreted (absolute, relative to the current
1390 position in the FDE, ...). Bit 7, indicates that the address
1391 should be dereferenced. */
1394 encoding_for_size (unsigned int size
)
1399 return DW_EH_PE_udata2
;
1401 return DW_EH_PE_udata4
;
1403 return DW_EH_PE_udata8
;
1405 internal_error (__FILE__
, __LINE__
, _("Unsupported address size"));
1410 read_encoded_value (struct comp_unit
*unit
, gdb_byte encoding
,
1411 int ptr_len
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
,
1412 CORE_ADDR func_base
)
1417 /* GCC currently doesn't generate DW_EH_PE_indirect encodings for
1419 if (encoding
& DW_EH_PE_indirect
)
1420 internal_error (__FILE__
, __LINE__
,
1421 _("Unsupported encoding: DW_EH_PE_indirect"));
1423 *bytes_read_ptr
= 0;
1425 switch (encoding
& 0x70)
1427 case DW_EH_PE_absptr
:
1430 case DW_EH_PE_pcrel
:
1431 base
= bfd_get_section_vma (unit
->abfd
, unit
->dwarf_frame_section
);
1432 base
+= (buf
- unit
->dwarf_frame_buffer
);
1434 case DW_EH_PE_datarel
:
1437 case DW_EH_PE_textrel
:
1440 case DW_EH_PE_funcrel
:
1443 case DW_EH_PE_aligned
:
1445 offset
= buf
- unit
->dwarf_frame_buffer
;
1446 if ((offset
% ptr_len
) != 0)
1448 *bytes_read_ptr
= ptr_len
- (offset
% ptr_len
);
1449 buf
+= *bytes_read_ptr
;
1453 internal_error (__FILE__
, __LINE__
, _("Invalid or unsupported encoding"));
1456 if ((encoding
& 0x07) == 0x00)
1458 encoding
|= encoding_for_size (ptr_len
);
1459 if (bfd_get_sign_extend_vma (unit
->abfd
))
1460 encoding
|= DW_EH_PE_signed
;
1463 switch (encoding
& 0x0f)
1465 case DW_EH_PE_uleb128
:
1468 gdb_byte
*end_buf
= buf
+ (sizeof (value
) + 1) * 8 / 7;
1469 *bytes_read_ptr
+= read_uleb128 (buf
, end_buf
, &value
) - buf
;
1470 return base
+ value
;
1472 case DW_EH_PE_udata2
:
1473 *bytes_read_ptr
+= 2;
1474 return (base
+ bfd_get_16 (unit
->abfd
, (bfd_byte
*) buf
));
1475 case DW_EH_PE_udata4
:
1476 *bytes_read_ptr
+= 4;
1477 return (base
+ bfd_get_32 (unit
->abfd
, (bfd_byte
*) buf
));
1478 case DW_EH_PE_udata8
:
1479 *bytes_read_ptr
+= 8;
1480 return (base
+ bfd_get_64 (unit
->abfd
, (bfd_byte
*) buf
));
1481 case DW_EH_PE_sleb128
:
1484 gdb_byte
*end_buf
= buf
+ (sizeof (value
) + 1) * 8 / 7;
1485 *bytes_read_ptr
+= read_sleb128 (buf
, end_buf
, &value
) - buf
;
1486 return base
+ value
;
1488 case DW_EH_PE_sdata2
:
1489 *bytes_read_ptr
+= 2;
1490 return (base
+ bfd_get_signed_16 (unit
->abfd
, (bfd_byte
*) buf
));
1491 case DW_EH_PE_sdata4
:
1492 *bytes_read_ptr
+= 4;
1493 return (base
+ bfd_get_signed_32 (unit
->abfd
, (bfd_byte
*) buf
));
1494 case DW_EH_PE_sdata8
:
1495 *bytes_read_ptr
+= 8;
1496 return (base
+ bfd_get_signed_64 (unit
->abfd
, (bfd_byte
*) buf
));
1498 internal_error (__FILE__
, __LINE__
, _("Invalid or unsupported encoding"));
1504 bsearch_cie_cmp (const void *key
, const void *element
)
1506 ULONGEST cie_pointer
= *(ULONGEST
*) key
;
1507 struct dwarf2_cie
*cie
= *(struct dwarf2_cie
**) element
;
1509 if (cie_pointer
== cie
->cie_pointer
)
1512 return (cie_pointer
< cie
->cie_pointer
) ? -1 : 1;
1515 /* Find CIE with the given CIE_POINTER in CIE_TABLE. */
1516 static struct dwarf2_cie
*
1517 find_cie (struct dwarf2_cie_table
*cie_table
, ULONGEST cie_pointer
)
1519 struct dwarf2_cie
**p_cie
;
1521 /* The C standard (ISO/IEC 9899:TC2) requires the BASE argument to
1522 bsearch be non-NULL. */
1523 if (cie_table
->entries
== NULL
)
1525 gdb_assert (cie_table
->num_entries
== 0);
1529 p_cie
= bsearch (&cie_pointer
, cie_table
->entries
, cie_table
->num_entries
,
1530 sizeof (cie_table
->entries
[0]), bsearch_cie_cmp
);
1536 /* Add a pointer to new CIE to the CIE_TABLE, allocating space for it. */
1538 add_cie (struct dwarf2_cie_table
*cie_table
, struct dwarf2_cie
*cie
)
1540 const int n
= cie_table
->num_entries
;
1543 || cie_table
->entries
[n
- 1]->cie_pointer
< cie
->cie_pointer
);
1545 cie_table
->entries
=
1546 xrealloc (cie_table
->entries
, (n
+ 1) * sizeof (cie_table
->entries
[0]));
1547 cie_table
->entries
[n
] = cie
;
1548 cie_table
->num_entries
= n
+ 1;
1552 bsearch_fde_cmp (const void *key
, const void *element
)
1554 CORE_ADDR seek_pc
= *(CORE_ADDR
*) key
;
1555 struct dwarf2_fde
*fde
= *(struct dwarf2_fde
**) element
;
1556 if (seek_pc
< fde
->initial_location
)
1558 if (seek_pc
< fde
->initial_location
+ fde
->address_range
)
1563 /* Find the FDE for *PC. Return a pointer to the FDE, and store the
1564 inital location associated with it into *PC. */
1566 static struct dwarf2_fde
*
1567 dwarf2_frame_find_fde (CORE_ADDR
*pc
)
1569 struct objfile
*objfile
;
1571 ALL_OBJFILES (objfile
)
1573 struct dwarf2_fde_table
*fde_table
;
1574 struct dwarf2_fde
**p_fde
;
1578 fde_table
= objfile_data (objfile
, dwarf2_frame_objfile_data
);
1579 if (fde_table
== NULL
)
1581 dwarf2_build_frame_info (objfile
);
1582 fde_table
= objfile_data (objfile
, dwarf2_frame_objfile_data
);
1584 gdb_assert (fde_table
!= NULL
);
1586 if (fde_table
->num_entries
== 0)
1589 gdb_assert (objfile
->section_offsets
);
1590 offset
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1592 gdb_assert (fde_table
->num_entries
> 0);
1593 if (*pc
< offset
+ fde_table
->entries
[0]->initial_location
)
1596 seek_pc
= *pc
- offset
;
1597 p_fde
= bsearch (&seek_pc
, fde_table
->entries
, fde_table
->num_entries
,
1598 sizeof (fde_table
->entries
[0]), bsearch_fde_cmp
);
1601 *pc
= (*p_fde
)->initial_location
+ offset
;
1608 /* Add a pointer to new FDE to the FDE_TABLE, allocating space for it. */
1610 add_fde (struct dwarf2_fde_table
*fde_table
, struct dwarf2_fde
*fde
)
1612 if (fde
->address_range
== 0)
1613 /* Discard useless FDEs. */
1616 fde_table
->num_entries
+= 1;
1617 fde_table
->entries
=
1618 xrealloc (fde_table
->entries
,
1619 fde_table
->num_entries
* sizeof (fde_table
->entries
[0]));
1620 fde_table
->entries
[fde_table
->num_entries
- 1] = fde
;
1623 #ifdef CC_HAS_LONG_LONG
1624 #define DW64_CIE_ID 0xffffffffffffffffULL
1626 #define DW64_CIE_ID ~0
1629 static gdb_byte
*decode_frame_entry (struct comp_unit
*unit
, gdb_byte
*start
,
1631 struct dwarf2_cie_table
*cie_table
,
1632 struct dwarf2_fde_table
*fde_table
);
1634 /* Decode the next CIE or FDE. Return NULL if invalid input, otherwise
1635 the next byte to be processed. */
1637 decode_frame_entry_1 (struct comp_unit
*unit
, gdb_byte
*start
, int eh_frame_p
,
1638 struct dwarf2_cie_table
*cie_table
,
1639 struct dwarf2_fde_table
*fde_table
)
1641 struct gdbarch
*gdbarch
= get_objfile_arch (unit
->objfile
);
1642 gdb_byte
*buf
, *end
;
1644 unsigned int bytes_read
;
1647 ULONGEST cie_pointer
;
1650 length
= read_initial_length (unit
->abfd
, buf
, &bytes_read
);
1654 /* Are we still within the section? */
1655 if (end
> unit
->dwarf_frame_buffer
+ unit
->dwarf_frame_size
)
1661 /* Distinguish between 32 and 64-bit encoded frame info. */
1662 dwarf64_p
= (bytes_read
== 12);
1664 /* In a .eh_frame section, zero is used to distinguish CIEs from FDEs. */
1668 cie_id
= DW64_CIE_ID
;
1674 cie_pointer
= read_8_bytes (unit
->abfd
, buf
);
1679 cie_pointer
= read_4_bytes (unit
->abfd
, buf
);
1683 if (cie_pointer
== cie_id
)
1685 /* This is a CIE. */
1686 struct dwarf2_cie
*cie
;
1688 unsigned int cie_version
;
1690 /* Record the offset into the .debug_frame section of this CIE. */
1691 cie_pointer
= start
- unit
->dwarf_frame_buffer
;
1693 /* Check whether we've already read it. */
1694 if (find_cie (cie_table
, cie_pointer
))
1697 cie
= (struct dwarf2_cie
*)
1698 obstack_alloc (&unit
->objfile
->objfile_obstack
,
1699 sizeof (struct dwarf2_cie
));
1700 cie
->initial_instructions
= NULL
;
1701 cie
->cie_pointer
= cie_pointer
;
1703 /* The encoding for FDE's in a normal .debug_frame section
1704 depends on the target address size. */
1705 cie
->encoding
= DW_EH_PE_absptr
;
1707 /* The target address size. For .eh_frame FDEs this is considered
1708 equal to the size of a target pointer. For .dwarf_frame FDEs,
1709 this is supposed to be the target address size from the associated
1710 CU header. FIXME: We do not have a good way to determine the
1711 latter. Always use the target pointer size for now. */
1712 cie
->addr_size
= gdbarch_ptr_bit (gdbarch
) / TARGET_CHAR_BIT
;
1714 /* We'll determine the final value later, but we need to
1715 initialize it conservatively. */
1716 cie
->signal_frame
= 0;
1718 /* Check version number. */
1719 cie_version
= read_1_byte (unit
->abfd
, buf
);
1720 if (cie_version
!= 1 && cie_version
!= 3 && cie_version
!= 4)
1722 cie
->version
= cie_version
;
1725 /* Interpret the interesting bits of the augmentation. */
1726 cie
->augmentation
= augmentation
= (char *) buf
;
1727 buf
+= (strlen (augmentation
) + 1);
1729 /* Ignore armcc augmentations. We only use them for quirks,
1730 and that doesn't happen until later. */
1731 if (strncmp (augmentation
, "armcc", 5) == 0)
1732 augmentation
+= strlen (augmentation
);
1734 /* The GCC 2.x "eh" augmentation has a pointer immediately
1735 following the augmentation string, so it must be handled
1737 if (augmentation
[0] == 'e' && augmentation
[1] == 'h')
1740 buf
+= gdbarch_ptr_bit (gdbarch
) / TARGET_CHAR_BIT
;
1744 if (cie
->version
>= 4)
1746 /* FIXME: check that this is the same as from the CU header. */
1747 cie
->addr_size
= read_1_byte (unit
->abfd
, buf
);
1749 cie
->segment_size
= read_1_byte (unit
->abfd
, buf
);
1754 cie
->addr_size
= gdbarch_ptr_bit (gdbarch
) / TARGET_CHAR_BIT
;
1755 cie
->segment_size
= 0;
1758 cie
->code_alignment_factor
=
1759 read_unsigned_leb128 (unit
->abfd
, buf
, &bytes_read
);
1762 cie
->data_alignment_factor
=
1763 read_signed_leb128 (unit
->abfd
, buf
, &bytes_read
);
1766 if (cie_version
== 1)
1768 cie
->return_address_register
= read_1_byte (unit
->abfd
, buf
);
1772 cie
->return_address_register
= read_unsigned_leb128 (unit
->abfd
, buf
,
1774 cie
->return_address_register
1775 = dwarf2_frame_adjust_regnum (gdbarch
,
1776 cie
->return_address_register
,
1781 cie
->saw_z_augmentation
= (*augmentation
== 'z');
1782 if (cie
->saw_z_augmentation
)
1786 length
= read_unsigned_leb128 (unit
->abfd
, buf
, &bytes_read
);
1790 cie
->initial_instructions
= buf
+ length
;
1794 while (*augmentation
)
1796 /* "L" indicates a byte showing how the LSDA pointer is encoded. */
1797 if (*augmentation
== 'L')
1804 /* "R" indicates a byte indicating how FDE addresses are encoded. */
1805 else if (*augmentation
== 'R')
1807 cie
->encoding
= *buf
++;
1811 /* "P" indicates a personality routine in the CIE augmentation. */
1812 else if (*augmentation
== 'P')
1814 /* Skip. Avoid indirection since we throw away the result. */
1815 gdb_byte encoding
= (*buf
++) & ~DW_EH_PE_indirect
;
1816 read_encoded_value (unit
, encoding
, cie
->addr_size
,
1817 buf
, &bytes_read
, 0);
1822 /* "S" indicates a signal frame, such that the return
1823 address must not be decremented to locate the call frame
1824 info for the previous frame; it might even be the first
1825 instruction of a function, so decrementing it would take
1826 us to a different function. */
1827 else if (*augmentation
== 'S')
1829 cie
->signal_frame
= 1;
1833 /* Otherwise we have an unknown augmentation. Assume that either
1834 there is no augmentation data, or we saw a 'z' prefix. */
1837 if (cie
->initial_instructions
)
1838 buf
= cie
->initial_instructions
;
1843 cie
->initial_instructions
= buf
;
1847 add_cie (cie_table
, cie
);
1851 /* This is a FDE. */
1852 struct dwarf2_fde
*fde
;
1854 /* In an .eh_frame section, the CIE pointer is the delta between the
1855 address within the FDE where the CIE pointer is stored and the
1856 address of the CIE. Convert it to an offset into the .eh_frame
1860 cie_pointer
= buf
- unit
->dwarf_frame_buffer
- cie_pointer
;
1861 cie_pointer
-= (dwarf64_p
? 8 : 4);
1864 /* In either case, validate the result is still within the section. */
1865 if (cie_pointer
>= unit
->dwarf_frame_size
)
1868 fde
= (struct dwarf2_fde
*)
1869 obstack_alloc (&unit
->objfile
->objfile_obstack
,
1870 sizeof (struct dwarf2_fde
));
1871 fde
->cie
= find_cie (cie_table
, cie_pointer
);
1872 if (fde
->cie
== NULL
)
1874 decode_frame_entry (unit
, unit
->dwarf_frame_buffer
+ cie_pointer
,
1875 eh_frame_p
, cie_table
, fde_table
);
1876 fde
->cie
= find_cie (cie_table
, cie_pointer
);
1879 gdb_assert (fde
->cie
!= NULL
);
1881 fde
->initial_location
=
1882 read_encoded_value (unit
, fde
->cie
->encoding
, fde
->cie
->addr_size
,
1883 buf
, &bytes_read
, 0);
1886 fde
->address_range
=
1887 read_encoded_value (unit
, fde
->cie
->encoding
& 0x0f,
1888 fde
->cie
->addr_size
, buf
, &bytes_read
, 0);
1891 /* A 'z' augmentation in the CIE implies the presence of an
1892 augmentation field in the FDE as well. The only thing known
1893 to be in here at present is the LSDA entry for EH. So we
1894 can skip the whole thing. */
1895 if (fde
->cie
->saw_z_augmentation
)
1899 length
= read_unsigned_leb128 (unit
->abfd
, buf
, &bytes_read
);
1900 buf
+= bytes_read
+ length
;
1905 fde
->instructions
= buf
;
1908 fde
->eh_frame_p
= eh_frame_p
;
1910 add_fde (fde_table
, fde
);
1916 /* Read a CIE or FDE in BUF and decode it. */
1918 decode_frame_entry (struct comp_unit
*unit
, gdb_byte
*start
, int eh_frame_p
,
1919 struct dwarf2_cie_table
*cie_table
,
1920 struct dwarf2_fde_table
*fde_table
)
1922 enum { NONE
, ALIGN4
, ALIGN8
, FAIL
} workaround
= NONE
;
1924 ptrdiff_t start_offset
;
1928 ret
= decode_frame_entry_1 (unit
, start
, eh_frame_p
,
1929 cie_table
, fde_table
);
1933 /* We have corrupt input data of some form. */
1935 /* ??? Try, weakly, to work around compiler/assembler/linker bugs
1936 and mismatches wrt padding and alignment of debug sections. */
1937 /* Note that there is no requirement in the standard for any
1938 alignment at all in the frame unwind sections. Testing for
1939 alignment before trying to interpret data would be incorrect.
1941 However, GCC traditionally arranged for frame sections to be
1942 sized such that the FDE length and CIE fields happen to be
1943 aligned (in theory, for performance). This, unfortunately,
1944 was done with .align directives, which had the side effect of
1945 forcing the section to be aligned by the linker.
1947 This becomes a problem when you have some other producer that
1948 creates frame sections that are not as strictly aligned. That
1949 produces a hole in the frame info that gets filled by the
1952 The GCC behaviour is arguably a bug, but it's effectively now
1953 part of the ABI, so we're now stuck with it, at least at the
1954 object file level. A smart linker may decide, in the process
1955 of compressing duplicate CIE information, that it can rewrite
1956 the entire output section without this extra padding. */
1958 start_offset
= start
- unit
->dwarf_frame_buffer
;
1959 if (workaround
< ALIGN4
&& (start_offset
& 3) != 0)
1961 start
+= 4 - (start_offset
& 3);
1962 workaround
= ALIGN4
;
1965 if (workaround
< ALIGN8
&& (start_offset
& 7) != 0)
1967 start
+= 8 - (start_offset
& 7);
1968 workaround
= ALIGN8
;
1972 /* Nothing left to try. Arrange to return as if we've consumed
1973 the entire input section. Hopefully we'll get valid info from
1974 the other of .debug_frame/.eh_frame. */
1976 ret
= unit
->dwarf_frame_buffer
+ unit
->dwarf_frame_size
;
1986 complaint (&symfile_complaints
,
1987 _("Corrupt data in %s:%s; align 4 workaround apparently succeeded"),
1988 unit
->dwarf_frame_section
->owner
->filename
,
1989 unit
->dwarf_frame_section
->name
);
1993 complaint (&symfile_complaints
,
1994 _("Corrupt data in %s:%s; align 8 workaround apparently succeeded"),
1995 unit
->dwarf_frame_section
->owner
->filename
,
1996 unit
->dwarf_frame_section
->name
);
2000 complaint (&symfile_complaints
,
2001 _("Corrupt data in %s:%s"),
2002 unit
->dwarf_frame_section
->owner
->filename
,
2003 unit
->dwarf_frame_section
->name
);
2011 /* Imported from dwarf2read.c. */
2012 extern void dwarf2_get_section_info (struct objfile
*, const char *, asection
**,
2013 gdb_byte
**, bfd_size_type
*);
2016 qsort_fde_cmp (const void *a
, const void *b
)
2018 struct dwarf2_fde
*aa
= *(struct dwarf2_fde
**)a
;
2019 struct dwarf2_fde
*bb
= *(struct dwarf2_fde
**)b
;
2021 if (aa
->initial_location
== bb
->initial_location
)
2023 if (aa
->address_range
!= bb
->address_range
2024 && aa
->eh_frame_p
== 0 && bb
->eh_frame_p
== 0)
2025 /* Linker bug, e.g. gold/10400.
2026 Work around it by keeping stable sort order. */
2027 return (a
< b
) ? -1 : 1;
2029 /* Put eh_frame entries after debug_frame ones. */
2030 return aa
->eh_frame_p
- bb
->eh_frame_p
;
2033 return (aa
->initial_location
< bb
->initial_location
) ? -1 : 1;
2037 dwarf2_build_frame_info (struct objfile
*objfile
)
2039 struct comp_unit
*unit
;
2040 gdb_byte
*frame_ptr
;
2041 struct dwarf2_cie_table cie_table
;
2042 struct dwarf2_fde_table fde_table
;
2043 struct dwarf2_fde_table
*fde_table2
;
2045 cie_table
.num_entries
= 0;
2046 cie_table
.entries
= NULL
;
2048 fde_table
.num_entries
= 0;
2049 fde_table
.entries
= NULL
;
2051 /* Build a minimal decoding of the DWARF2 compilation unit. */
2052 unit
= (struct comp_unit
*) obstack_alloc (&objfile
->objfile_obstack
,
2053 sizeof (struct comp_unit
));
2054 unit
->abfd
= objfile
->obfd
;
2055 unit
->objfile
= objfile
;
2059 dwarf2_get_section_info (objfile
, ".eh_frame",
2060 &unit
->dwarf_frame_section
,
2061 &unit
->dwarf_frame_buffer
,
2062 &unit
->dwarf_frame_size
);
2063 if (unit
->dwarf_frame_size
)
2065 asection
*got
, *txt
;
2067 /* FIXME: kettenis/20030602: This is the DW_EH_PE_datarel base
2068 that is used for the i386/amd64 target, which currently is
2069 the only target in GCC that supports/uses the
2070 DW_EH_PE_datarel encoding. */
2071 got
= bfd_get_section_by_name (unit
->abfd
, ".got");
2073 unit
->dbase
= got
->vma
;
2075 /* GCC emits the DW_EH_PE_textrel encoding type on sh and ia64
2077 txt
= bfd_get_section_by_name (unit
->abfd
, ".text");
2079 unit
->tbase
= txt
->vma
;
2081 frame_ptr
= unit
->dwarf_frame_buffer
;
2082 while (frame_ptr
< unit
->dwarf_frame_buffer
+ unit
->dwarf_frame_size
)
2083 frame_ptr
= decode_frame_entry (unit
, frame_ptr
, 1,
2084 &cie_table
, &fde_table
);
2086 if (cie_table
.num_entries
!= 0)
2088 /* Reinit cie_table: debug_frame has different CIEs. */
2089 xfree (cie_table
.entries
);
2090 cie_table
.num_entries
= 0;
2091 cie_table
.entries
= NULL
;
2095 dwarf2_get_section_info (objfile
, ".debug_frame",
2096 &unit
->dwarf_frame_section
,
2097 &unit
->dwarf_frame_buffer
,
2098 &unit
->dwarf_frame_size
);
2099 if (unit
->dwarf_frame_size
)
2101 frame_ptr
= unit
->dwarf_frame_buffer
;
2102 while (frame_ptr
< unit
->dwarf_frame_buffer
+ unit
->dwarf_frame_size
)
2103 frame_ptr
= decode_frame_entry (unit
, frame_ptr
, 0,
2104 &cie_table
, &fde_table
);
2107 /* Discard the cie_table, it is no longer needed. */
2108 if (cie_table
.num_entries
!= 0)
2110 xfree (cie_table
.entries
);
2111 cie_table
.entries
= NULL
; /* Paranoia. */
2112 cie_table
.num_entries
= 0; /* Paranoia. */
2115 /* Copy fde_table to obstack: it is needed at runtime. */
2116 fde_table2
= (struct dwarf2_fde_table
*)
2117 obstack_alloc (&objfile
->objfile_obstack
, sizeof (*fde_table2
));
2119 if (fde_table
.num_entries
== 0)
2121 fde_table2
->entries
= NULL
;
2122 fde_table2
->num_entries
= 0;
2126 struct dwarf2_fde
*fde_prev
= NULL
;
2127 struct dwarf2_fde
*first_non_zero_fde
= NULL
;
2130 /* Prepare FDE table for lookups. */
2131 qsort (fde_table
.entries
, fde_table
.num_entries
,
2132 sizeof (fde_table
.entries
[0]), qsort_fde_cmp
);
2134 /* Check for leftovers from --gc-sections. The GNU linker sets
2135 the relevant symbols to zero, but doesn't zero the FDE *end*
2136 ranges because there's no relocation there. It's (offset,
2137 length), not (start, end). On targets where address zero is
2138 just another valid address this can be a problem, since the
2139 FDEs appear to be non-empty in the output --- we could pick
2140 out the wrong FDE. To work around this, when overlaps are
2141 detected, we prefer FDEs that do not start at zero.
2143 Start by finding the first FDE with non-zero start. Below
2144 we'll discard all FDEs that start at zero and overlap this
2146 for (i
= 0; i
< fde_table
.num_entries
; i
++)
2148 struct dwarf2_fde
*fde
= fde_table
.entries
[i
];
2150 if (fde
->initial_location
!= 0)
2152 first_non_zero_fde
= fde
;
2157 /* Since we'll be doing bsearch, squeeze out identical (except
2158 for eh_frame_p) fde entries so bsearch result is predictable.
2159 Also discard leftovers from --gc-sections. */
2160 fde_table2
->num_entries
= 0;
2161 for (i
= 0; i
< fde_table
.num_entries
; i
++)
2163 struct dwarf2_fde
*fde
= fde_table
.entries
[i
];
2165 if (fde
->initial_location
== 0
2166 && first_non_zero_fde
!= NULL
2167 && (first_non_zero_fde
->initial_location
2168 < fde
->initial_location
+ fde
->address_range
))
2171 if (fde_prev
!= NULL
2172 && fde_prev
->initial_location
== fde
->initial_location
)
2175 obstack_grow (&objfile
->objfile_obstack
, &fde_table
.entries
[i
],
2176 sizeof (fde_table
.entries
[0]));
2177 ++fde_table2
->num_entries
;
2180 fde_table2
->entries
= obstack_finish (&objfile
->objfile_obstack
);
2182 /* Discard the original fde_table. */
2183 xfree (fde_table
.entries
);
2186 set_objfile_data (objfile
, dwarf2_frame_objfile_data
, fde_table2
);
2189 /* Provide a prototype to silence -Wmissing-prototypes. */
2190 void _initialize_dwarf2_frame (void);
2193 _initialize_dwarf2_frame (void)
2195 dwarf2_frame_data
= gdbarch_data_register_pre_init (dwarf2_frame_init
);
2196 dwarf2_frame_objfile_data
= register_objfile_data ();