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