Correct last mispasted entry
[deliverable/binutils-gdb.git] / gdb / tramp-frame.c
CommitLineData
d2259dd3
AC
1/* Signal trampoline unwinder, for GDB the GNU Debugger.
2
3 Copyright 2004 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
21
22#include "defs.h"
23#include "tramp-frame.h"
24#include "frame-unwind.h"
25#include "gdbcore.h"
26#include "symtab.h"
27#include "objfiles.h"
28#include "target.h"
29#include "trad-frame.h"
30#include "frame-base.h"
1196bfda 31#include "gdb_assert.h"
d2259dd3
AC
32
33struct frame_data
34{
35 const struct tramp_frame *tramp_frame;
36};
37
38struct tramp_frame_cache
39{
40 CORE_ADDR func;
41 const struct tramp_frame *tramp_frame;
42 struct trad_frame_cache *trad_cache;
43};
44
45static struct trad_frame_cache *
46tramp_frame_cache (struct frame_info *next_frame,
47 void **this_cache)
48{
49 CORE_ADDR pc = frame_pc_unwind (next_frame);
50 struct tramp_frame_cache *tramp_cache = (*this_cache);
51 if (tramp_cache->trad_cache == NULL)
52 {
53 tramp_cache->trad_cache = trad_frame_cache_zalloc (next_frame);
54 tramp_cache->tramp_frame->init (tramp_cache->tramp_frame,
55 next_frame,
56 tramp_cache->trad_cache,
57 tramp_cache->func);
58 }
59 return tramp_cache->trad_cache;
60}
61
62static void
63tramp_frame_this_id (struct frame_info *next_frame,
64 void **this_cache,
65 struct frame_id *this_id)
66{
67 struct trad_frame_cache *trad_cache
68 = tramp_frame_cache (next_frame, this_cache);
69 trad_frame_get_id (trad_cache, this_id);
70}
71
72static void
73tramp_frame_prev_register (struct frame_info *next_frame,
74 void **this_cache,
75 int prev_regnum,
76 int *optimizedp,
77 enum lval_type * lvalp,
78 CORE_ADDR *addrp,
79 int *realnump, void *valuep)
80{
81 struct trad_frame_cache *trad_cache
82 = tramp_frame_cache (next_frame, this_cache);
83 trad_frame_get_register (trad_cache, next_frame, prev_regnum, optimizedp,
84 lvalp, addrp, realnump, valuep);
85}
86
87static CORE_ADDR
304396fb
AC
88tramp_frame_start (const struct tramp_frame *tramp,
89 struct frame_info *next_frame, CORE_ADDR pc)
d2259dd3
AC
90{
91 int ti;
92 /* Search through the trampoline for one that matches the
93 instruction sequence around PC. */
2cd8546d 94 for (ti = 0; tramp->insn[ti].bytes != TRAMP_SENTINEL_INSN; ti++)
d2259dd3
AC
95 {
96 CORE_ADDR func = pc - tramp->insn_size * ti;
97 int i;
98 for (i = 0; 1; i++)
99 {
1196bfda
AC
100 bfd_byte buf[sizeof (tramp->insn[0])];
101 ULONGEST insn;
2cd8546d 102 if (tramp->insn[i].bytes == TRAMP_SENTINEL_INSN)
d2259dd3 103 return func;
304396fb
AC
104 if (!safe_frame_unwind_memory (next_frame,
105 func + i * tramp->insn_size,
106 buf, tramp->insn_size))
d2259dd3
AC
107 break;
108 insn = extract_unsigned_integer (buf, tramp->insn_size);
2cd8546d 109 if (tramp->insn[i].bytes != (insn & tramp->insn[i].mask))
d2259dd3
AC
110 break;
111 }
112 }
113 /* Trampoline doesn't match. */
114 return 0;
115}
116
117static int
118tramp_frame_sniffer (const struct frame_unwind *self,
119 struct frame_info *next_frame,
120 void **this_cache)
121{
122 const struct tramp_frame *tramp = self->unwind_data->tramp_frame;
123 CORE_ADDR pc = frame_pc_unwind (next_frame);
124 CORE_ADDR func;
125 char *name;
126 struct tramp_frame_cache *tramp_cache;
127
128 /* If the function has a valid symbol name, it isn't a
129 trampoline. */
130 find_pc_partial_function (pc, &name, NULL, NULL);
131 if (name != NULL)
132 return 0;
133 /* If the function lives in a valid section (even without a starting
134 point) it isn't a trampoline. */
135 if (find_pc_section (pc) != NULL)
136 return 0;
137 /* Finally, check that the trampoline matches at PC. */
304396fb 138 func = tramp_frame_start (tramp, next_frame, pc);
d2259dd3
AC
139 if (func == 0)
140 return 0;
141 tramp_cache = FRAME_OBSTACK_ZALLOC (struct tramp_frame_cache);
142 tramp_cache->func = func;
143 tramp_cache->tramp_frame = tramp;
144 (*this_cache) = tramp_cache;
145 return 1;
146}
147
148void
fb2be677
AC
149tramp_frame_prepend_unwinder (struct gdbarch *gdbarch,
150 const struct tramp_frame *tramp_frame)
d2259dd3
AC
151{
152 struct frame_data *data;
153 struct frame_unwind *unwinder;
1196bfda
AC
154 int i;
155
156 /* Check that the instruction sequence contains a sentinel. */
157 for (i = 0; i < ARRAY_SIZE (tramp_frame->insn); i++)
158 {
2cd8546d 159 if (tramp_frame->insn[i].bytes == TRAMP_SENTINEL_INSN)
1196bfda
AC
160 break;
161 }
162 gdb_assert (i < ARRAY_SIZE (tramp_frame->insn));
2cd8546d 163 gdb_assert (tramp_frame->insn_size <= sizeof (tramp_frame->insn[0].bytes));
d2259dd3
AC
164
165 data = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct frame_data);
166 unwinder = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct frame_unwind);
167
168 data->tramp_frame = tramp_frame;
1f586765 169 unwinder->type = tramp_frame->frame_type;
d2259dd3
AC
170 unwinder->unwind_data = data;
171 unwinder->sniffer = tramp_frame_sniffer;
172 unwinder->this_id = tramp_frame_this_id;
173 unwinder->prev_register = tramp_frame_prev_register;
fb2be677 174 frame_unwind_prepend_unwinder (gdbarch, unwinder);
d2259dd3 175}
This page took 0.137705 seconds and 4 git commands to generate.