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