2003-07-18 Andrew Cagney <cagney@redhat.com>
[deliverable/binutils-gdb.git] / gdb / dwarf2-frame.c
CommitLineData
cfc14b3a
MK
1/* Frame unwinder for frames with DWARF Call Frame Information.
2
3 Copyright 2003 Free Software Foundation, Inc.
4
5 Contributed by Mark Kettenis.
6
7 This file is part of GDB.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
23
24#include "defs.h"
25#include "dwarf2expr.h"
26#include "elf/dwarf2.h"
27#include "frame.h"
28#include "frame-base.h"
29#include "frame-unwind.h"
30#include "gdbcore.h"
31#include "gdbtypes.h"
32#include "symtab.h"
33#include "objfiles.h"
34#include "regcache.h"
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
42/* Call Frame Information (CFI). */
43
44/* Common Information Entry (CIE). */
45
46struct dwarf2_cie
47{
48 /* Offset into the .debug_frame section where this CIE was found.
49 Used to identify this CIE. */
50 ULONGEST cie_pointer;
51
52 /* Constant that is factored out of all advance location
53 instructions. */
54 ULONGEST code_alignment_factor;
55
56 /* Constants that is factored out of all offset instructions. */
57 LONGEST data_alignment_factor;
58
59 /* Return address column. */
60 ULONGEST return_address_register;
61
62 /* Instruction sequence to initialize a register set. */
63 unsigned char *initial_instructions;
64 unsigned char *end;
65
66 /* Encoding of addresses. */
67 unsigned char encoding;
68
7131cb6e
RH
69 /* True if a 'z' augmentation existed. */
70 unsigned char saw_z_augmentation;
71
cfc14b3a
MK
72 struct dwarf2_cie *next;
73};
74
75/* Frame Description Entry (FDE). */
76
77struct dwarf2_fde
78{
79 /* CIE for this FDE. */
80 struct dwarf2_cie *cie;
81
82 /* First location associated with this FDE. */
83 CORE_ADDR initial_location;
84
85 /* Number of bytes of program instructions described by this FDE. */
86 CORE_ADDR address_range;
87
88 /* Instruction sequence. */
89 unsigned char *instructions;
90 unsigned char *end;
91
92 struct dwarf2_fde *next;
93};
94
95static struct dwarf2_fde *dwarf2_frame_find_fde (CORE_ADDR *pc);
96\f
97
98/* Structure describing a frame state. */
99
100struct dwarf2_frame_state
101{
102 /* Each register save state can be described in terms of a CFA slot,
103 another register, or a location expression. */
104 struct dwarf2_frame_state_reg_info
105 {
106 struct dwarf2_frame_state_reg
107 {
108 union {
109 LONGEST offset;
110 ULONGEST reg;
111 unsigned char *exp;
112 } loc;
113 ULONGEST exp_len;
114 enum {
115 REG_UNSAVED,
116 REG_SAVED_OFFSET,
117 REG_SAVED_REG,
118 REG_SAVED_EXP,
119 REG_UNMODIFIED
120 } how;
121 } *reg;
122 int num_regs;
123
124 /* Used to implement DW_CFA_remember_state. */
125 struct dwarf2_frame_state_reg_info *prev;
126 } regs;
127
128 LONGEST cfa_offset;
129 ULONGEST cfa_reg;
130 unsigned char *cfa_exp;
131 enum {
132 CFA_UNSET,
133 CFA_REG_OFFSET,
134 CFA_EXP
135 } cfa_how;
136
137 /* The PC described by the current frame state. */
138 CORE_ADDR pc;
139
140 /* Initial register set from the CIE.
141 Used to implement DW_CFA_restore. */
142 struct dwarf2_frame_state_reg_info initial;
143
144 /* The information we care about from the CIE. */
145 LONGEST data_align;
146 ULONGEST code_align;
147 ULONGEST retaddr_column;
148};
149
150/* Store the length the expression for the CFA in the `cfa_reg' field,
151 which is unused in that case. */
152#define cfa_exp_len cfa_reg
153
154/* Assert that the register set RS is large enough to store NUM_REGS
155 columns. If necessary, enlarge the register set. */
156
157static void
158dwarf2_frame_state_alloc_regs (struct dwarf2_frame_state_reg_info *rs,
159 int num_regs)
160{
161 size_t size = sizeof (struct dwarf2_frame_state_reg);
162
163 if (num_regs <= rs->num_regs)
164 return;
165
166 rs->reg = (struct dwarf2_frame_state_reg *)
167 xrealloc (rs->reg, num_regs * size);
168
169 /* Initialize newly allocated registers. */
2473a4a9 170 memset (rs->reg + rs->num_regs, 0, (num_regs - rs->num_regs) * size);
cfc14b3a
MK
171 rs->num_regs = num_regs;
172}
173
174/* Copy the register columns in register set RS into newly allocated
175 memory and return a pointer to this newly created copy. */
176
177static struct dwarf2_frame_state_reg *
178dwarf2_frame_state_copy_regs (struct dwarf2_frame_state_reg_info *rs)
179{
180 size_t size = rs->num_regs * sizeof (struct dwarf2_frame_state_reg_info);
181 struct dwarf2_frame_state_reg *reg;
182
183 reg = (struct dwarf2_frame_state_reg *) xmalloc (size);
184 memcpy (reg, rs->reg, size);
185
186 return reg;
187}
188
189/* Release the memory allocated to register set RS. */
190
191static void
192dwarf2_frame_state_free_regs (struct dwarf2_frame_state_reg_info *rs)
193{
194 if (rs)
195 {
196 dwarf2_frame_state_free_regs (rs->prev);
197
198 xfree (rs->reg);
199 xfree (rs);
200 }
201}
202
203/* Release the memory allocated to the frame state FS. */
204
205static void
206dwarf2_frame_state_free (void *p)
207{
208 struct dwarf2_frame_state *fs = p;
209
210 dwarf2_frame_state_free_regs (fs->initial.prev);
211 dwarf2_frame_state_free_regs (fs->regs.prev);
212 xfree (fs->initial.reg);
213 xfree (fs->regs.reg);
214 xfree (fs);
215}
216\f
217
218/* Helper functions for execute_stack_op. */
219
220static CORE_ADDR
221read_reg (void *baton, int reg)
222{
223 struct frame_info *next_frame = (struct frame_info *) baton;
224 int regnum;
225 char *buf;
226
227 regnum = DWARF2_REG_TO_REGNUM (reg);
228
229 buf = (char *) alloca (register_size (current_gdbarch, regnum));
230 frame_unwind_register (next_frame, regnum, buf);
231 return extract_typed_address (buf, builtin_type_void_data_ptr);
232}
233
234static void
235read_mem (void *baton, char *buf, CORE_ADDR addr, size_t len)
236{
237 read_memory (addr, buf, len);
238}
239
240static void
241no_get_frame_base (void *baton, unsigned char **start, size_t *length)
242{
243 internal_error (__FILE__, __LINE__,
244 "Support for DW_OP_fbreg is unimplemented");
245}
246
247static CORE_ADDR
248no_get_tls_address (void *baton, CORE_ADDR offset)
249{
250 internal_error (__FILE__, __LINE__,
251 "Support for DW_OP_GNU_push_tls_address is unimplemented");
252}
253
254static CORE_ADDR
255execute_stack_op (unsigned char *exp, ULONGEST len,
256 struct frame_info *next_frame, CORE_ADDR initial)
257{
258 struct dwarf_expr_context *ctx;
259 CORE_ADDR result;
260
261 ctx = new_dwarf_expr_context ();
262 ctx->baton = next_frame;
263 ctx->read_reg = read_reg;
264 ctx->read_mem = read_mem;
265 ctx->get_frame_base = no_get_frame_base;
266 ctx->get_tls_address = no_get_tls_address;
267
268 dwarf_expr_push (ctx, initial);
269 dwarf_expr_eval (ctx, exp, len);
270 result = dwarf_expr_fetch (ctx, 0);
271
272 if (ctx->in_reg)
273 result = read_reg (next_frame, result);
274
275 free_dwarf_expr_context (ctx);
276
277 return result;
278}
279\f
280
281static void
282execute_cfa_program (unsigned char *insn_ptr, unsigned char *insn_end,
283 struct frame_info *next_frame,
284 struct dwarf2_frame_state *fs)
285{
286 CORE_ADDR pc = frame_pc_unwind (next_frame);
287 int bytes_read;
288
289 while (insn_ptr < insn_end && fs->pc <= pc)
290 {
291 unsigned char insn = *insn_ptr++;
292 ULONGEST utmp, reg;
293 LONGEST offset;
294
295 if ((insn & 0xc0) == DW_CFA_advance_loc)
296 fs->pc += (insn & 0x3f) * fs->code_align;
297 else if ((insn & 0xc0) == DW_CFA_offset)
298 {
299 reg = insn & 0x3f;
300 insn_ptr = read_uleb128 (insn_ptr, insn_end, &utmp);
301 offset = utmp * fs->data_align;
302 dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1);
303 fs->regs.reg[reg].how = REG_SAVED_OFFSET;
304 fs->regs.reg[reg].loc.offset = offset;
305 }
306 else if ((insn & 0xc0) == DW_CFA_restore)
307 {
308 gdb_assert (fs->initial.reg);
309 reg = insn & 0x3f;
310 dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1);
311 fs->regs.reg[reg] = fs->initial.reg[reg];
312 }
313 else
314 {
315 switch (insn)
316 {
317 case DW_CFA_set_loc:
318 fs->pc = dwarf2_read_address (insn_ptr, insn_end, &bytes_read);
319 insn_ptr += bytes_read;
320 break;
321
322 case DW_CFA_advance_loc1:
323 utmp = extract_unsigned_integer (insn_ptr, 1);
324 fs->pc += utmp * fs->code_align;
325 insn_ptr++;
326 break;
327 case DW_CFA_advance_loc2:
328 utmp = extract_unsigned_integer (insn_ptr, 2);
329 fs->pc += utmp * fs->code_align;
330 insn_ptr += 2;
331 break;
332 case DW_CFA_advance_loc4:
333 utmp = extract_unsigned_integer (insn_ptr, 4);
334 fs->pc += utmp * fs->code_align;
335 insn_ptr += 4;
336 break;
337
338 case DW_CFA_offset_extended:
339 insn_ptr = read_uleb128 (insn_ptr, insn_end, &reg);
340 insn_ptr = read_uleb128 (insn_ptr, insn_end, &utmp);
341 offset = utmp * fs->data_align;
342 dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1);
343 fs->regs.reg[reg].how = REG_SAVED_OFFSET;
344 fs->regs.reg[reg].loc.offset = offset;
345 break;
346
347 case DW_CFA_restore_extended:
348 gdb_assert (fs->initial.reg);
349 insn_ptr = read_uleb128 (insn_ptr, insn_end, &reg);
350 dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1);
351 fs->regs.reg[reg] = fs->initial.reg[reg];
352 break;
353
354 case DW_CFA_undefined:
355 insn_ptr = read_uleb128 (insn_ptr, insn_end, &reg);
356 dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1);
357 fs->regs.reg[reg].how = REG_UNSAVED;
358 break;
359
360 case DW_CFA_same_value:
361 insn_ptr = read_uleb128 (insn_ptr, insn_end, &reg);
362 dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1);
363 fs->regs.reg[reg].how = REG_UNMODIFIED;
364 break;
365
366 case DW_CFA_register:
367 insn_ptr = read_uleb128 (insn_ptr, insn_end, &reg);
368 insn_ptr = read_uleb128 (insn_ptr, insn_end, &utmp);
369 dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1);
370 fs->regs.reg[reg].loc.reg = utmp;
371 break;
372
373 case DW_CFA_remember_state:
374 {
375 struct dwarf2_frame_state_reg_info *new_rs;
376
377 new_rs = XMALLOC (struct dwarf2_frame_state_reg_info);
378 *new_rs = fs->regs;
379 fs->regs.reg = dwarf2_frame_state_copy_regs (&fs->regs);
380 fs->regs.prev = new_rs;
381 }
382 break;
383
384 case DW_CFA_restore_state:
385 {
386 struct dwarf2_frame_state_reg_info *old_rs = fs->regs.prev;
387
388 gdb_assert (old_rs);
389
390 xfree (fs->regs.reg);
391 fs->regs = *old_rs;
392 xfree (old_rs);
393 }
394 break;
395
396 case DW_CFA_def_cfa:
397 insn_ptr = read_uleb128 (insn_ptr, insn_end, &fs->cfa_reg);
398 insn_ptr = read_uleb128 (insn_ptr, insn_end, &utmp);
399 fs->cfa_offset = utmp;
400 fs->cfa_how = CFA_REG_OFFSET;
401 break;
402
403 case DW_CFA_def_cfa_register:
404 insn_ptr = read_uleb128 (insn_ptr, insn_end, &fs->cfa_reg);
405 fs->cfa_how = CFA_REG_OFFSET;
406 break;
407
408 case DW_CFA_def_cfa_offset:
409 insn_ptr = read_uleb128 (insn_ptr, insn_end, &fs->cfa_offset);
410 /* cfa_how deliberately not set. */
411 break;
412
413 case DW_CFA_def_cfa_expression:
414 insn_ptr = read_uleb128 (insn_ptr, insn_end, &fs->cfa_exp_len);
415 fs->cfa_exp = insn_ptr;
416 fs->cfa_how = CFA_EXP;
417 insn_ptr += fs->cfa_exp_len;
418 break;
419
420 case DW_CFA_expression:
421 insn_ptr = read_uleb128 (insn_ptr, insn_end, &reg);
422 dwarf2_frame_state_alloc_regs (&fs->regs, reg + 1);
423 insn_ptr = read_uleb128 (insn_ptr, insn_end, &utmp);
424 fs->regs.reg[reg].loc.exp = insn_ptr;
425 fs->regs.reg[reg].exp_len = utmp;
426 fs->regs.reg[reg].how = REG_SAVED_EXP;
427 insn_ptr += utmp;
428 break;
429
430 case DW_CFA_nop:
431 break;
432
433 case DW_CFA_GNU_args_size:
434 /* Ignored. */
435 insn_ptr = read_uleb128 (insn_ptr, insn_end, &utmp);
436 break;
437
438 default:
439 internal_error (__FILE__, __LINE__, "Unknown CFI encountered.");
440 }
441 }
442 }
443
444 /* Don't allow remember/restore between CIE and FDE programs. */
445 dwarf2_frame_state_free_regs (fs->regs.prev);
446 fs->regs.prev = NULL;
447}
448
449struct dwarf2_frame_cache
450{
451 /* DWARF Call Frame Address. */
452 CORE_ADDR cfa;
453
454 /* Saved registers, indexed by GDB register number, not by DWARF
455 register number. */
456 struct dwarf2_frame_state_reg *reg;
457};
458
b9362cc7 459static struct dwarf2_frame_cache *
cfc14b3a
MK
460dwarf2_frame_cache (struct frame_info *next_frame, void **this_cache)
461{
462 struct cleanup *old_chain;
463 int num_regs = NUM_REGS + NUM_PSEUDO_REGS;
464 struct dwarf2_frame_cache *cache;
465 struct dwarf2_frame_state *fs;
466 struct dwarf2_fde *fde;
467 int reg;
468
469 if (*this_cache)
470 return *this_cache;
471
472 /* Allocate a new cache. */
473 cache = FRAME_OBSTACK_ZALLOC (struct dwarf2_frame_cache);
474 cache->reg = FRAME_OBSTACK_CALLOC (num_regs, struct dwarf2_frame_state_reg);
475
476 /* Allocate and initialize the frame state. */
477 fs = XMALLOC (struct dwarf2_frame_state);
478 memset (fs, 0, sizeof (struct dwarf2_frame_state));
479 old_chain = make_cleanup (dwarf2_frame_state_free, fs);
480
481 /* Unwind the PC.
482
483 Note that if NEXT_FRAME is never supposed to return (i.e. a call
484 to abort), the compiler might optimize away the instruction at
485 NEXT_FRAME's return address. As a result the return address will
486 point at some random instruction, and the CFI for that
487 instruction is probably wortless to us. GCC's unwinder solves
488 this problem by substracting 1 from the return address to get an
489 address in the middle of a presumed call instruction (or the
490 instruction in the associated delay slot). This should only be
491 done for "normal" frames and not for resume-type frames (signal
492 handlers, sentinel frames, dummy frames).
493
494 We don't do what GCC's does here (yet). It's not clear how
495 reliable the method is. There's also a problem with finding the
496 right FDE; see the comment in dwarf_frame_p. If dwarf_frame_p
497 selected this frame unwinder because it found the FDE for the
498 next function, using the adjusted return address might not yield
499 a FDE at all. The problem isn't specific to DWARF CFI; other
500 unwinders loose in similar ways. Therefore it's probably
501 acceptable to leave things slightly broken for now. */
502 fs->pc = frame_pc_unwind (next_frame);
503
504 /* Find the correct FDE. */
505 fde = dwarf2_frame_find_fde (&fs->pc);
506 gdb_assert (fde != NULL);
507
508 /* Extract any interesting information from the CIE. */
509 fs->data_align = fde->cie->data_alignment_factor;
510 fs->code_align = fde->cie->code_alignment_factor;
511 fs->retaddr_column = fde->cie->return_address_register;
512
513 /* First decode all the insns in the CIE. */
514 execute_cfa_program (fde->cie->initial_instructions,
515 fde->cie->end, next_frame, fs);
516
517 /* Save the initialized register set. */
518 fs->initial = fs->regs;
519 fs->initial.reg = dwarf2_frame_state_copy_regs (&fs->regs);
520
521 /* Then decode the insns in the FDE up to our target PC. */
522 execute_cfa_program (fde->instructions, fde->end, next_frame, fs);
523
524 /* Caclulate the CFA. */
525 switch (fs->cfa_how)
526 {
527 case CFA_REG_OFFSET:
528 cache->cfa = read_reg (next_frame, fs->cfa_reg);
529 cache->cfa += fs->cfa_offset;
530 break;
531
532 case CFA_EXP:
533 cache->cfa =
534 execute_stack_op (fs->cfa_exp, fs->cfa_exp_len, next_frame, 0);
535 break;
536
537 default:
538 internal_error (__FILE__, __LINE__, "Unknown CFA rule.");
539 }
540
541 /* Save the register info in the cache. */
542 for (reg = 0; reg < fs->regs.num_regs; reg++)
543 {
544 int regnum;
545
546 /* Skip the return address column. */
547 if (reg == fs->retaddr_column)
a42e117c
AC
548 /* NOTE: cagney/2003-06-07: Is this right? What if the
549 RETADDR_COLUM corresponds to a real register (and, worse,
550 that isn't the PC_REGNUM)? I'm guessing that the PC_REGNUM
551 further down is trying to handle this. That can't be right
552 though - PC_REGNUM may not be valid (it can be -ve). I
553 think, instead when RETADDR_COLUM isn't a real register, it
554 should map itself onto frame_pc_unwind. */
cfc14b3a
MK
555 continue;
556
557 /* Use the GDB register number as index. */
558 regnum = DWARF2_REG_TO_REGNUM (reg);
559
560 if (regnum >= 0 && regnum < num_regs)
561 cache->reg[regnum] = fs->regs.reg[reg];
562 }
563
f3e0f90b
RH
564 /* Store the location of the return addess. If the return address
565 column (adjusted) is not the same as gdb's PC_REGNUM, then this
566 implies a copy from the ra column register. */
567 if (fs->retaddr_column < fs->regs.num_regs
568 && fs->regs.reg[fs->retaddr_column].how != REG_UNSAVED)
a42e117c
AC
569 {
570 /* See comment above about a possibly -ve PC_REGNUM. If this
571 assertion fails, it's a problem with this code and not the
572 architecture. */
573 gdb_assert (PC_REGNUM >= 0);
574 cache->reg[PC_REGNUM] = fs->regs.reg[fs->retaddr_column];
575 }
f3e0f90b
RH
576 else
577 {
578 reg = DWARF2_REG_TO_REGNUM (fs->retaddr_column);
579 if (reg != PC_REGNUM)
580 {
a42e117c
AC
581 /* See comment above about PC_REGNUM being -ve. If this
582 assertion fails, it's a problem with this code and not
583 the architecture. */
584 gdb_assert (PC_REGNUM >= 0);
f3e0f90b
RH
585 cache->reg[PC_REGNUM].loc.reg = reg;
586 cache->reg[PC_REGNUM].how = REG_SAVED_REG;
587 }
588 }
cfc14b3a
MK
589
590 do_cleanups (old_chain);
591
592 *this_cache = cache;
593 return cache;
594}
595
596static void
597dwarf2_frame_this_id (struct frame_info *next_frame, void **this_cache,
598 struct frame_id *this_id)
599{
600 struct dwarf2_frame_cache *cache =
601 dwarf2_frame_cache (next_frame, this_cache);
602
603 (*this_id) = frame_id_build (cache->cfa, frame_func_unwind (next_frame));
604}
605
606static void
607dwarf2_frame_prev_register (struct frame_info *next_frame, void **this_cache,
608 int regnum, int *optimizedp,
609 enum lval_type *lvalp, CORE_ADDR *addrp,
610 int *realnump, void *valuep)
611{
612 struct dwarf2_frame_cache *cache =
613 dwarf2_frame_cache (next_frame, this_cache);
614
615 switch (cache->reg[regnum].how)
616 {
617 case REG_UNSAVED:
618 *optimizedp = 1;
619 *lvalp = not_lval;
620 *addrp = 0;
621 *realnump = -1;
622 if (regnum == SP_REGNUM)
623 {
624 /* GCC defines the CFA as the value of the stack pointer
625 just before the call instruction is executed. Do other
626 compilers use the same definition? */
a42e117c
AC
627 /* DWARF V3 Draft 7 p102: Typically, the CFA is defined to
628 be the value of the stack pointer at the call site in the
629 previous frame (which may be different from its value on
630 entry to the current frame). */
631 /* DWARF V3 Draft 7 p103: The first column of the rules
632 defines the rule which computes the CFA value; it may be
633 either a register and a signed offset that are added
634 together or a DWARF expression that is evaluated. */
635 /* FIXME: cagney/2003-07-07: I don't understand this. The
636 CFI info should have provided unwind information for the
637 SP register and then pointed ->cfa_reg at it, not the
638 reverse. Assuming that SP_REGNUM is !-ve, there is a
639 very real posibility that CFA is an offset from some
640 other register, having nothing to do with the unwound SP
641 value. */
cfc14b3a
MK
642 *optimizedp = 0;
643 if (valuep)
644 {
645 /* Store the value. */
646 store_typed_address (valuep, builtin_type_void_data_ptr,
647 cache->cfa);
648 }
649 }
650 else if (valuep)
651 {
652 /* In some cases, for example %eflags on the i386, we have
653 to provide a sane value, even though this register wasn't
654 saved. Assume we can get it from NEXT_FRAME. */
655 frame_unwind_register (next_frame, regnum, valuep);
656 }
657 break;
658
659 case REG_SAVED_OFFSET:
660 *optimizedp = 0;
661 *lvalp = lval_memory;
662 *addrp = cache->cfa + cache->reg[regnum].loc.offset;
663 *realnump = -1;
664 if (valuep)
665 {
666 /* Read the value in from memory. */
667 read_memory (*addrp, valuep,
668 register_size (current_gdbarch, regnum));
669 }
670 break;
671
672 case REG_SAVED_REG:
673 regnum = DWARF2_REG_TO_REGNUM (cache->reg[regnum].loc.reg);
674 frame_register_unwind (next_frame, regnum,
675 optimizedp, lvalp, addrp, realnump, valuep);
676 break;
677
678 case REG_SAVED_EXP:
679 *optimizedp = 0;
680 *lvalp = lval_memory;
681 *addrp = execute_stack_op (cache->reg[regnum].loc.exp,
682 cache->reg[regnum].exp_len,
683 next_frame, cache->cfa);
684 *realnump = -1;
685 if (valuep)
686 {
687 /* Read the value in from memory. */
688 read_memory (*addrp, valuep,
689 register_size (current_gdbarch, regnum));
690 }
691 break;
692
693 case REG_UNMODIFIED:
694 frame_register_unwind (next_frame, regnum,
695 optimizedp, lvalp, addrp, realnump, valuep);
696 break;
697
698 default:
699 internal_error (__FILE__, __LINE__, "Unknown register rule.");
700 }
701}
702
703static const struct frame_unwind dwarf2_frame_unwind =
704{
705 NORMAL_FRAME,
706 dwarf2_frame_this_id,
707 dwarf2_frame_prev_register
708};
709
710const struct frame_unwind *
336d1bba 711dwarf2_frame_sniffer (struct frame_info *next_frame)
cfc14b3a 712{
336d1bba 713 CORE_ADDR pc = frame_pc_unwind (next_frame);
cfc14b3a
MK
714 /* The way GDB works, this function can be called with PC just after
715 the last instruction of the function we're supposed to return the
716 unwind methods for. In that case we won't find the correct FDE;
717 instead we find the FDE for the next function, or we won't find
718 an FDE at all. There is a possible solution (see the comment in
719 dwarf2_frame_cache), GDB doesn't pass us enough information to
720 implement it. */
721 if (dwarf2_frame_find_fde (&pc))
722 return &dwarf2_frame_unwind;
723
724 return NULL;
725}
726\f
727
728/* There is no explicitly defined relationship between the CFA and the
729 location of frame's local variables and arguments/parameters.
730 Therefore, frame base methods on this page should probably only be
731 used as a last resort, just to avoid printing total garbage as a
732 response to the "info frame" command. */
733
734static CORE_ADDR
735dwarf2_frame_base_address (struct frame_info *next_frame, void **this_cache)
736{
737 struct dwarf2_frame_cache *cache =
738 dwarf2_frame_cache (next_frame, this_cache);
739
740 return cache->cfa;
741}
742
743static const struct frame_base dwarf2_frame_base =
744{
745 &dwarf2_frame_unwind,
746 dwarf2_frame_base_address,
747 dwarf2_frame_base_address,
748 dwarf2_frame_base_address
749};
750
751const struct frame_base *
336d1bba 752dwarf2_frame_base_sniffer (struct frame_info *next_frame)
cfc14b3a 753{
336d1bba 754 CORE_ADDR pc = frame_pc_unwind (next_frame);
cfc14b3a
MK
755 if (dwarf2_frame_find_fde (&pc))
756 return &dwarf2_frame_base;
757
758 return NULL;
759}
760\f
761/* A minimal decoding of DWARF2 compilation units. We only decode
762 what's needed to get to the call frame information. */
763
764struct comp_unit
765{
766 /* Keep the bfd convenient. */
767 bfd *abfd;
768
769 struct objfile *objfile;
770
771 /* Linked list of CIEs for this object. */
772 struct dwarf2_cie *cie;
773
774 /* Address size for this unit - from unit header. */
775 unsigned char addr_size;
776
777 /* Pointer to the .debug_frame section loaded into memory. */
778 char *dwarf_frame_buffer;
779
780 /* Length of the loaded .debug_frame section. */
781 unsigned long dwarf_frame_size;
782
783 /* Pointer to the .debug_frame section. */
784 asection *dwarf_frame_section;
0912c7f2
MK
785
786 /* Base for DW_EH_PE_datarel encodings. */
787 bfd_vma dbase;
cfc14b3a
MK
788};
789
790static unsigned int
791read_1_byte (bfd *bfd, char *buf)
792{
793 return bfd_get_8 (abfd, (bfd_byte *) buf);
794}
795
796static unsigned int
797read_4_bytes (bfd *abfd, char *buf)
798{
799 return bfd_get_32 (abfd, (bfd_byte *) buf);
800}
801
802static ULONGEST
803read_8_bytes (bfd *abfd, char *buf)
804{
805 return bfd_get_64 (abfd, (bfd_byte *) buf);
806}
807
808static ULONGEST
809read_unsigned_leb128 (bfd *abfd, char *buf, unsigned int *bytes_read_ptr)
810{
811 ULONGEST result;
812 unsigned int num_read;
813 int shift;
814 unsigned char byte;
815
816 result = 0;
817 shift = 0;
818 num_read = 0;
819
820 do
821 {
822 byte = bfd_get_8 (abfd, (bfd_byte *) buf);
823 buf++;
824 num_read++;
825 result |= ((byte & 0x7f) << shift);
826 shift += 7;
827 }
828 while (byte & 0x80);
829
830 *bytes_read_ptr = num_read;
831
832 return result;
833}
834
835static LONGEST
836read_signed_leb128 (bfd *abfd, char *buf, unsigned int *bytes_read_ptr)
837{
838 LONGEST result;
839 int shift;
840 unsigned int num_read;
841 unsigned char byte;
842
843 result = 0;
844 shift = 0;
845 num_read = 0;
846
847 do
848 {
849 byte = bfd_get_8 (abfd, (bfd_byte *) buf);
850 buf++;
851 num_read++;
852 result |= ((byte & 0x7f) << shift);
853 shift += 7;
854 }
855 while (byte & 0x80);
856
857 if ((shift < 32) && (byte & 0x40))
858 result |= -(1 << shift);
859
860 *bytes_read_ptr = num_read;
861
862 return result;
863}
864
865static ULONGEST
866read_initial_length (bfd *abfd, char *buf, unsigned int *bytes_read_ptr)
867{
868 LONGEST result;
869
870 result = bfd_get_32 (abfd, (bfd_byte *) buf);
871 if (result == 0xffffffff)
872 {
873 result = bfd_get_64 (abfd, (bfd_byte *) buf + 4);
874 *bytes_read_ptr = 12;
875 }
876 else
877 *bytes_read_ptr = 4;
878
879 return result;
880}
881\f
882
883/* Pointer encoding helper functions. */
884
885/* GCC supports exception handling based on DWARF2 CFI. However, for
886 technical reasons, it encodes addresses in its FDE's in a different
887 way. Several "pointer encodings" are supported. The encoding
888 that's used for a particular FDE is determined by the 'R'
889 augmentation in the associated CIE. The argument of this
890 augmentation is a single byte.
891
892 The address can be encoded as 2 bytes, 4 bytes, 8 bytes, or as a
893 LEB128. This is encoded in bits 0, 1 and 2. Bit 3 encodes whether
894 the address is signed or unsigned. Bits 4, 5 and 6 encode how the
895 address should be interpreted (absolute, relative to the current
896 position in the FDE, ...). Bit 7, indicates that the address
897 should be dereferenced. */
898
899static unsigned char
900encoding_for_size (unsigned int size)
901{
902 switch (size)
903 {
904 case 2:
905 return DW_EH_PE_udata2;
906 case 4:
907 return DW_EH_PE_udata4;
908 case 8:
909 return DW_EH_PE_udata8;
910 default:
911 internal_error (__FILE__, __LINE__, "Unsupported address size");
912 }
913}
914
915static unsigned int
916size_of_encoded_value (unsigned char encoding)
917{
918 if (encoding == DW_EH_PE_omit)
919 return 0;
920
921 switch (encoding & 0x07)
922 {
923 case DW_EH_PE_absptr:
924 return TYPE_LENGTH (builtin_type_void_data_ptr);
925 case DW_EH_PE_udata2:
926 return 2;
927 case DW_EH_PE_udata4:
928 return 4;
929 case DW_EH_PE_udata8:
930 return 8;
931 default:
932 internal_error (__FILE__, __LINE__, "Invalid or unsupported encoding");
933 }
934}
935
936static CORE_ADDR
937read_encoded_value (struct comp_unit *unit, unsigned char encoding,
938 char *buf, unsigned int *bytes_read_ptr)
939{
940 CORE_ADDR base;
941
942 /* GCC currently doesn't generate DW_EH_PE_indirect encodings for
943 FDE's. */
944 if (encoding & DW_EH_PE_indirect)
945 internal_error (__FILE__, __LINE__,
946 "Unsupported encoding: DW_EH_PE_indirect");
947
948 switch (encoding & 0x70)
949 {
950 case DW_EH_PE_absptr:
951 base = 0;
952 break;
953 case DW_EH_PE_pcrel:
954 base = bfd_get_section_vma (unit->bfd, unit->dwarf_frame_section);
955 base += (buf - unit->dwarf_frame_buffer);
956 break;
0912c7f2
MK
957 case DW_EH_PE_datarel:
958 base = unit->dbase;
959 break;
cfc14b3a
MK
960 default:
961 internal_error (__FILE__, __LINE__, "Invalid or unsupported encoding");
962 }
963
964 if ((encoding & 0x0f) == 0x00)
965 encoding |= encoding_for_size (TYPE_LENGTH(builtin_type_void_data_ptr));
966
967 switch (encoding & 0x0f)
968 {
969 case DW_EH_PE_udata2:
970 *bytes_read_ptr = 2;
971 return (base + bfd_get_16 (unit->abfd, (bfd_byte *) buf));
972 case DW_EH_PE_udata4:
973 *bytes_read_ptr = 4;
974 return (base + bfd_get_32 (unit->abfd, (bfd_byte *) buf));
975 case DW_EH_PE_udata8:
976 *bytes_read_ptr = 8;
977 return (base + bfd_get_64 (unit->abfd, (bfd_byte *) buf));
978 case DW_EH_PE_sdata2:
979 *bytes_read_ptr = 2;
980 return (base + bfd_get_signed_16 (unit->abfd, (bfd_byte *) buf));
981 case DW_EH_PE_sdata4:
982 *bytes_read_ptr = 4;
983 return (base + bfd_get_signed_32 (unit->abfd, (bfd_byte *) buf));
984 case DW_EH_PE_sdata8:
985 *bytes_read_ptr = 8;
986 return (base + bfd_get_signed_64 (unit->abfd, (bfd_byte *) buf));
987 default:
988 internal_error (__FILE__, __LINE__, "Invalid or unsupported encoding");
989 }
990}
991\f
992
993/* GCC uses a single CIE for all FDEs in a .debug_frame section.
994 That's why we use a simple linked list here. */
995
996static struct dwarf2_cie *
997find_cie (struct comp_unit *unit, ULONGEST cie_pointer)
998{
999 struct dwarf2_cie *cie = unit->cie;
1000
1001 while (cie)
1002 {
1003 if (cie->cie_pointer == cie_pointer)
1004 return cie;
1005
1006 cie = cie->next;
1007 }
1008
1009 return NULL;
1010}
1011
1012static void
1013add_cie (struct comp_unit *unit, struct dwarf2_cie *cie)
1014{
1015 cie->next = unit->cie;
1016 unit->cie = cie;
1017}
1018
1019/* Find the FDE for *PC. Return a pointer to the FDE, and store the
1020 inital location associated with it into *PC. */
1021
1022static struct dwarf2_fde *
1023dwarf2_frame_find_fde (CORE_ADDR *pc)
1024{
1025 struct objfile *objfile;
1026
1027 ALL_OBJFILES (objfile)
1028 {
1029 struct dwarf2_fde *fde;
1030 CORE_ADDR offset;
1031
1032 offset = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
1033
1034 fde = objfile->sym_private;
1035 while (fde)
1036 {
1037 if (*pc >= fde->initial_location + offset
1038 && *pc < fde->initial_location + offset + fde->address_range)
1039 {
1040 *pc = fde->initial_location + offset;
1041 return fde;
1042 }
1043
1044 fde = fde->next;
1045 }
1046 }
1047
1048 return NULL;
1049}
1050
1051static void
1052add_fde (struct comp_unit *unit, struct dwarf2_fde *fde)
1053{
1054 fde->next = unit->objfile->sym_private;
1055 unit->objfile->sym_private = fde;
1056}
1057
1058#ifdef CC_HAS_LONG_LONG
1059#define DW64_CIE_ID 0xffffffffffffffffULL
1060#else
1061#define DW64_CIE_ID ~0
1062#endif
1063
6896c0c7
RH
1064static char *decode_frame_entry (struct comp_unit *unit, char *start,
1065 int eh_frame_p);
cfc14b3a 1066
6896c0c7
RH
1067/* Decode the next CIE or FDE. Return NULL if invalid input, otherwise
1068 the next byte to be processed. */
cfc14b3a 1069static char *
6896c0c7 1070decode_frame_entry_1 (struct comp_unit *unit, char *start, int eh_frame_p)
cfc14b3a 1071{
6896c0c7 1072 char *buf;
cfc14b3a
MK
1073 LONGEST length;
1074 unsigned int bytes_read;
6896c0c7
RH
1075 int dwarf64_p;
1076 ULONGEST cie_id;
cfc14b3a 1077 ULONGEST cie_pointer;
cfc14b3a
MK
1078 char *end;
1079
6896c0c7 1080 buf = start;
cfc14b3a
MK
1081 length = read_initial_length (unit->abfd, buf, &bytes_read);
1082 buf += bytes_read;
1083 end = buf + length;
1084
6896c0c7
RH
1085 /* Are we still within the section? */
1086 if (end > unit->dwarf_frame_buffer + unit->dwarf_frame_size)
1087 return NULL;
1088
cfc14b3a
MK
1089 if (length == 0)
1090 return end;
1091
6896c0c7
RH
1092 /* Distinguish between 32 and 64-bit encoded frame info. */
1093 dwarf64_p = (bytes_read == 12);
cfc14b3a 1094
6896c0c7 1095 /* In a .eh_frame section, zero is used to distinguish CIEs from FDEs. */
cfc14b3a
MK
1096 if (eh_frame_p)
1097 cie_id = 0;
1098 else if (dwarf64_p)
1099 cie_id = DW64_CIE_ID;
6896c0c7
RH
1100 else
1101 cie_id = DW_CIE_ID;
cfc14b3a
MK
1102
1103 if (dwarf64_p)
1104 {
1105 cie_pointer = read_8_bytes (unit->abfd, buf);
1106 buf += 8;
1107 }
1108 else
1109 {
1110 cie_pointer = read_4_bytes (unit->abfd, buf);
1111 buf += 4;
1112 }
1113
1114 if (cie_pointer == cie_id)
1115 {
1116 /* This is a CIE. */
1117 struct dwarf2_cie *cie;
1118 char *augmentation;
1119
1120 /* Record the offset into the .debug_frame section of this CIE. */
1121 cie_pointer = start - unit->dwarf_frame_buffer;
1122
1123 /* Check whether we've already read it. */
1124 if (find_cie (unit, cie_pointer))
1125 return end;
1126
1127 cie = (struct dwarf2_cie *)
1128 obstack_alloc (&unit->objfile->psymbol_obstack,
1129 sizeof (struct dwarf2_cie));
1130 cie->initial_instructions = NULL;
1131 cie->cie_pointer = cie_pointer;
1132
1133 /* The encoding for FDE's in a normal .debug_frame section
1134 depends on the target address size as specified in the
1135 Compilation Unit Header. */
1136 cie->encoding = encoding_for_size (unit->addr_size);
1137
1138 /* Check version number. */
6896c0c7
RH
1139 if (read_1_byte (unit->abfd, buf) != DW_CIE_VERSION)
1140 return NULL;
cfc14b3a
MK
1141 buf += 1;
1142
1143 /* Interpret the interesting bits of the augmentation. */
1144 augmentation = buf;
1145 buf = augmentation + strlen (augmentation) + 1;
1146
1147 /* The GCC 2.x "eh" augmentation has a pointer immediately
1148 following the augmentation string, so it must be handled
1149 first. */
1150 if (augmentation[0] == 'e' && augmentation[1] == 'h')
1151 {
1152 /* Skip. */
1153 buf += TYPE_LENGTH (builtin_type_void_data_ptr);
1154 augmentation += 2;
1155 }
1156
1157 cie->code_alignment_factor =
1158 read_unsigned_leb128 (unit->abfd, buf, &bytes_read);
1159 buf += bytes_read;
1160
1161 cie->data_alignment_factor =
1162 read_signed_leb128 (unit->abfd, buf, &bytes_read);
1163 buf += bytes_read;
1164
1165 cie->return_address_register = read_1_byte (unit->abfd, buf);
1166 buf += 1;
1167
7131cb6e
RH
1168 cie->saw_z_augmentation = (*augmentation == 'z');
1169 if (cie->saw_z_augmentation)
cfc14b3a
MK
1170 {
1171 ULONGEST length;
1172
1173 length = read_unsigned_leb128 (unit->abfd, buf, &bytes_read);
1174 buf += bytes_read;
6896c0c7
RH
1175 if (buf > end)
1176 return NULL;
cfc14b3a
MK
1177 cie->initial_instructions = buf + length;
1178 augmentation++;
1179 }
1180
1181 while (*augmentation)
1182 {
1183 /* "L" indicates a byte showing how the LSDA pointer is encoded. */
1184 if (*augmentation == 'L')
1185 {
1186 /* Skip. */
1187 buf++;
1188 augmentation++;
1189 }
1190
1191 /* "R" indicates a byte indicating how FDE addresses are encoded. */
1192 else if (*augmentation == 'R')
1193 {
1194 cie->encoding = *buf++;
1195 augmentation++;
1196 }
1197
1198 /* "P" indicates a personality routine in the CIE augmentation. */
1199 else if (*augmentation == 'P')
1200 {
1201 /* Skip. */
1202 buf += size_of_encoded_value (*buf++);
1203 augmentation++;
1204 }
1205
1206 /* Otherwise we have an unknown augmentation.
1207 Bail out unless we saw a 'z' prefix. */
1208 else
1209 {
1210 if (cie->initial_instructions == NULL)
1211 return end;
1212
1213 /* Skip unknown augmentations. */
1214 buf = cie->initial_instructions;
1215 break;
1216 }
1217 }
1218
1219 cie->initial_instructions = buf;
1220 cie->end = end;
1221
1222 add_cie (unit, cie);
1223 }
1224 else
1225 {
1226 /* This is a FDE. */
1227 struct dwarf2_fde *fde;
1228
6896c0c7
RH
1229 /* In an .eh_frame section, the CIE pointer is the delta between the
1230 address within the FDE where the CIE pointer is stored and the
1231 address of the CIE. Convert it to an offset into the .eh_frame
1232 section. */
cfc14b3a
MK
1233 if (eh_frame_p)
1234 {
cfc14b3a
MK
1235 cie_pointer = buf - unit->dwarf_frame_buffer - cie_pointer;
1236 cie_pointer -= (dwarf64_p ? 8 : 4);
1237 }
1238
6896c0c7
RH
1239 /* In either case, validate the result is still within the section. */
1240 if (cie_pointer >= unit->dwarf_frame_size)
1241 return NULL;
1242
cfc14b3a
MK
1243 fde = (struct dwarf2_fde *)
1244 obstack_alloc (&unit->objfile->psymbol_obstack,
1245 sizeof (struct dwarf2_fde));
1246 fde->cie = find_cie (unit, cie_pointer);
1247 if (fde->cie == NULL)
1248 {
1249 decode_frame_entry (unit, unit->dwarf_frame_buffer + cie_pointer,
1250 eh_frame_p);
1251 fde->cie = find_cie (unit, cie_pointer);
1252 }
1253
1254 gdb_assert (fde->cie != NULL);
1255
1256 fde->initial_location =
1257 read_encoded_value (unit, fde->cie->encoding, buf, &bytes_read);
1258 buf += bytes_read;
1259
1260 fde->address_range =
1261 read_encoded_value (unit, fde->cie->encoding & 0x0f, buf, &bytes_read);
1262 buf += bytes_read;
1263
7131cb6e
RH
1264 /* A 'z' augmentation in the CIE implies the presence of an
1265 augmentation field in the FDE as well. The only thing known
1266 to be in here at present is the LSDA entry for EH. So we
1267 can skip the whole thing. */
1268 if (fde->cie->saw_z_augmentation)
1269 {
1270 ULONGEST length;
1271
1272 length = read_unsigned_leb128 (unit->abfd, buf, &bytes_read);
1273 buf += bytes_read + length;
6896c0c7
RH
1274 if (buf > end)
1275 return NULL;
7131cb6e
RH
1276 }
1277
cfc14b3a
MK
1278 fde->instructions = buf;
1279 fde->end = end;
1280
1281 add_fde (unit, fde);
1282 }
1283
1284 return end;
1285}
6896c0c7
RH
1286
1287/* Read a CIE or FDE in BUF and decode it. */
1288static char *
1289decode_frame_entry (struct comp_unit *unit, char *start, int eh_frame_p)
1290{
1291 enum { NONE, ALIGN4, ALIGN8, FAIL } workaround = NONE;
1292 char *ret;
1293 const char *msg;
1294 ptrdiff_t start_offset;
1295
1296 while (1)
1297 {
1298 ret = decode_frame_entry_1 (unit, start, eh_frame_p);
1299 if (ret != NULL)
1300 break;
1301
1302 /* We have corrupt input data of some form. */
1303
1304 /* ??? Try, weakly, to work around compiler/assembler/linker bugs
1305 and mismatches wrt padding and alignment of debug sections. */
1306 /* Note that there is no requirement in the standard for any
1307 alignment at all in the frame unwind sections. Testing for
1308 alignment before trying to interpret data would be incorrect.
1309
1310 However, GCC traditionally arranged for frame sections to be
1311 sized such that the FDE length and CIE fields happen to be
1312 aligned (in theory, for performance). This, unfortunately,
1313 was done with .align directives, which had the side effect of
1314 forcing the section to be aligned by the linker.
1315
1316 This becomes a problem when you have some other producer that
1317 creates frame sections that are not as strictly aligned. That
1318 produces a hole in the frame info that gets filled by the
1319 linker with zeros.
1320
1321 The GCC behaviour is arguably a bug, but it's effectively now
1322 part of the ABI, so we're now stuck with it, at least at the
1323 object file level. A smart linker may decide, in the process
1324 of compressing duplicate CIE information, that it can rewrite
1325 the entire output section without this extra padding. */
1326
1327 start_offset = start - unit->dwarf_frame_buffer;
1328 if (workaround < ALIGN4 && (start_offset & 3) != 0)
1329 {
1330 start += 4 - (start_offset & 3);
1331 workaround = ALIGN4;
1332 continue;
1333 }
1334 if (workaround < ALIGN8 && (start_offset & 7) != 0)
1335 {
1336 start += 8 - (start_offset & 7);
1337 workaround = ALIGN8;
1338 continue;
1339 }
1340
1341 /* Nothing left to try. Arrange to return as if we've consumed
1342 the entire input section. Hopefully we'll get valid info from
1343 the other of .debug_frame/.eh_frame. */
1344 workaround = FAIL;
1345 ret = unit->dwarf_frame_buffer + unit->dwarf_frame_size;
1346 break;
1347 }
1348
1349 switch (workaround)
1350 {
1351 case NONE:
1352 break;
1353
1354 case ALIGN4:
1355 complaint (&symfile_complaints,
1356 "Corrupt data in %s:%s; align 4 workaround apparently succeeded",
1357 unit->dwarf_frame_section->owner->filename,
1358 unit->dwarf_frame_section->name);
1359 break;
1360
1361 case ALIGN8:
1362 complaint (&symfile_complaints,
1363 "Corrupt data in %s:%s; align 8 workaround apparently succeeded",
1364 unit->dwarf_frame_section->owner->filename,
1365 unit->dwarf_frame_section->name);
1366 break;
1367
1368 default:
1369 complaint (&symfile_complaints,
1370 "Corrupt data in %s:%s",
1371 unit->dwarf_frame_section->owner->filename,
1372 unit->dwarf_frame_section->name);
1373 break;
1374 }
1375
1376 return ret;
1377}
1378
cfc14b3a
MK
1379\f
1380
1381/* FIXME: kettenis/20030504: This still needs to be integrated with
1382 dwarf2read.c in a better way. */
1383
1384/* Imported from dwarf2read.c. */
1385extern file_ptr dwarf_frame_offset;
1386extern unsigned int dwarf_frame_size;
1387extern asection *dwarf_frame_section;
1388extern file_ptr dwarf_eh_frame_offset;
1389extern unsigned int dwarf_eh_frame_size;
1390extern asection *dwarf_eh_frame_section;
1391
1392/* Imported from dwarf2read.c. */
1393extern char *dwarf2_read_section (struct objfile *objfile, file_ptr offset,
1394 unsigned int size, asection *sectp);
1395
1396void
1397dwarf2_build_frame_info (struct objfile *objfile)
1398{
1399 struct comp_unit unit;
1400 char *frame_ptr;
1401
1402 /* Build a minimal decoding of the DWARF2 compilation unit. */
1403 unit.abfd = objfile->obfd;
1404 unit.objfile = objfile;
1405 unit.addr_size = objfile->obfd->arch_info->bits_per_address / 8;
0912c7f2 1406 unit.dbase = 0;
cfc14b3a
MK
1407
1408 /* First add the information from the .eh_frame section. That way,
1409 the FDEs from that section are searched last. */
1410 if (dwarf_eh_frame_offset)
1411 {
0912c7f2
MK
1412 asection *got;
1413
cfc14b3a
MK
1414 unit.cie = NULL;
1415 unit.dwarf_frame_buffer = dwarf2_read_section (objfile,
1416 dwarf_eh_frame_offset,
1417 dwarf_eh_frame_size,
1418 dwarf_eh_frame_section);
1419
1420 unit.dwarf_frame_size = dwarf_eh_frame_size;
1421 unit.dwarf_frame_section = dwarf_eh_frame_section;
1422
0912c7f2 1423 /* FIXME: kettenis/20030602: This is the DW_EH_PE_datarel base
6896c0c7
RH
1424 that for the i386/amd64 target, which currently is the only
1425 target in GCC that supports/uses the DW_EH_PE_datarel
1426 encoding. */
0912c7f2
MK
1427 got = bfd_get_section_by_name (unit.abfd, ".got");
1428 if (got)
1429 unit.dbase = got->vma;
1430
cfc14b3a
MK
1431 frame_ptr = unit.dwarf_frame_buffer;
1432 while (frame_ptr < unit.dwarf_frame_buffer + unit.dwarf_frame_size)
1433 frame_ptr = decode_frame_entry (&unit, frame_ptr, 1);
1434 }
1435
1436 if (dwarf_frame_offset)
1437 {
1438 unit.cie = NULL;
1439 unit.dwarf_frame_buffer = dwarf2_read_section (objfile,
1440 dwarf_frame_offset,
1441 dwarf_frame_size,
1442 dwarf_frame_section);
1443 unit.dwarf_frame_size = dwarf_frame_size;
1444 unit.dwarf_frame_section = dwarf_frame_section;
1445
1446 frame_ptr = unit.dwarf_frame_buffer;
1447 while (frame_ptr < unit.dwarf_frame_buffer + unit.dwarf_frame_size)
1448 frame_ptr = decode_frame_entry (&unit, frame_ptr, 0);
1449 }
1450}
This page took 0.095431 seconds and 4 git commands to generate.