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