* coffcode.h (coff_write_object_contents): Enclose all occurrences
[deliverable/binutils-gdb.git] / gdb / tramp-frame.c
1 /* Signal trampoline unwinder, for GDB the GNU Debugger.
2
3 Copyright (C) 2004, 2007, 2008, 2009, 2010 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 3 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, see <http://www.gnu.org/licenses/>. */
19
20 #include "defs.h"
21 #include "tramp-frame.h"
22 #include "frame-unwind.h"
23 #include "gdbcore.h"
24 #include "symtab.h"
25 #include "objfiles.h"
26 #include "target.h"
27 #include "trad-frame.h"
28 #include "frame-base.h"
29 #include "gdb_assert.h"
30
31 struct frame_data
32 {
33 const struct tramp_frame *tramp_frame;
34 };
35
36 struct tramp_frame_cache
37 {
38 CORE_ADDR func;
39 const struct tramp_frame *tramp_frame;
40 struct trad_frame_cache *trad_cache;
41 };
42
43 static struct trad_frame_cache *
44 tramp_frame_cache (struct frame_info *this_frame,
45 void **this_cache)
46 {
47 struct tramp_frame_cache *tramp_cache = (*this_cache);
48 if (tramp_cache->trad_cache == NULL)
49 {
50 tramp_cache->trad_cache = trad_frame_cache_zalloc (this_frame);
51 tramp_cache->tramp_frame->init (tramp_cache->tramp_frame,
52 this_frame,
53 tramp_cache->trad_cache,
54 tramp_cache->func);
55 }
56 return tramp_cache->trad_cache;
57 }
58
59 static void
60 tramp_frame_this_id (struct frame_info *this_frame,
61 void **this_cache,
62 struct frame_id *this_id)
63 {
64 struct trad_frame_cache *trad_cache
65 = tramp_frame_cache (this_frame, this_cache);
66 trad_frame_get_id (trad_cache, this_id);
67 }
68
69 static struct value *
70 tramp_frame_prev_register (struct frame_info *this_frame,
71 void **this_cache,
72 int prev_regnum)
73 {
74 struct trad_frame_cache *trad_cache
75 = tramp_frame_cache (this_frame, this_cache);
76 return trad_frame_get_register (trad_cache, this_frame, prev_regnum);
77 }
78
79 static CORE_ADDR
80 tramp_frame_start (const struct tramp_frame *tramp,
81 struct frame_info *this_frame, CORE_ADDR pc)
82 {
83 struct gdbarch *gdbarch = get_frame_arch (this_frame);
84 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
85 int ti;
86 /* Search through the trampoline for one that matches the
87 instruction sequence around PC. */
88 for (ti = 0; tramp->insn[ti].bytes != TRAMP_SENTINEL_INSN; ti++)
89 {
90 CORE_ADDR func = pc - tramp->insn_size * ti;
91 int i;
92 for (i = 0; 1; i++)
93 {
94 gdb_byte buf[sizeof (tramp->insn[0])];
95 ULONGEST insn;
96 if (tramp->insn[i].bytes == TRAMP_SENTINEL_INSN)
97 return func;
98 if (!safe_frame_unwind_memory (this_frame,
99 func + i * tramp->insn_size,
100 buf, tramp->insn_size))
101 break;
102 insn = extract_unsigned_integer (buf, tramp->insn_size, byte_order);
103 if (tramp->insn[i].bytes != (insn & tramp->insn[i].mask))
104 break;
105 }
106 }
107 /* Trampoline doesn't match. */
108 return 0;
109 }
110
111 static int
112 tramp_frame_sniffer (const struct frame_unwind *self,
113 struct frame_info *this_frame,
114 void **this_cache)
115 {
116 const struct tramp_frame *tramp = self->unwind_data->tramp_frame;
117 CORE_ADDR pc = get_frame_pc (this_frame);
118 CORE_ADDR func;
119 struct tramp_frame_cache *tramp_cache;
120
121 /* tausq/2004-12-12: We used to assume if pc has a name or is in a valid
122 section, then this is not a trampoline. However, this assumption is
123 false on HPUX which has a signal trampoline that has a name; it can
124 also be false when using an alternative signal stack. */
125 func = tramp_frame_start (tramp, this_frame, pc);
126 if (func == 0)
127 return 0;
128 tramp_cache = FRAME_OBSTACK_ZALLOC (struct tramp_frame_cache);
129 tramp_cache->func = func;
130 tramp_cache->tramp_frame = tramp;
131 (*this_cache) = tramp_cache;
132 return 1;
133 }
134
135 void
136 tramp_frame_prepend_unwinder (struct gdbarch *gdbarch,
137 const struct tramp_frame *tramp_frame)
138 {
139 struct frame_data *data;
140 struct frame_unwind *unwinder;
141 int i;
142
143 /* Check that the instruction sequence contains a sentinel. */
144 for (i = 0; i < ARRAY_SIZE (tramp_frame->insn); i++)
145 {
146 if (tramp_frame->insn[i].bytes == TRAMP_SENTINEL_INSN)
147 break;
148 }
149 gdb_assert (i < ARRAY_SIZE (tramp_frame->insn));
150 gdb_assert (tramp_frame->insn_size <= sizeof (tramp_frame->insn[0].bytes));
151
152 data = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct frame_data);
153 unwinder = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct frame_unwind);
154
155 data->tramp_frame = tramp_frame;
156 unwinder->type = tramp_frame->frame_type;
157 unwinder->unwind_data = data;
158 unwinder->sniffer = tramp_frame_sniffer;
159 unwinder->this_id = tramp_frame_this_id;
160 unwinder->prev_register = tramp_frame_prev_register;
161 frame_unwind_prepend_unwinder (gdbarch, unwinder);
162 }
This page took 0.032632 seconds and 4 git commands to generate.