1 /* Signal trampoline unwinder, for GDB the GNU Debugger.
3 Copyright (C) 2004-2014 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
21 #include "tramp-frame.h"
22 #include "frame-unwind.h"
27 #include "trad-frame.h"
28 #include "frame-base.h"
32 const struct tramp_frame
*tramp_frame
;
35 struct tramp_frame_cache
38 const struct tramp_frame
*tramp_frame
;
39 struct trad_frame_cache
*trad_cache
;
42 static struct trad_frame_cache
*
43 tramp_frame_cache (struct frame_info
*this_frame
,
46 struct tramp_frame_cache
*tramp_cache
= (*this_cache
);
48 if (tramp_cache
->trad_cache
== NULL
)
50 tramp_cache
->trad_cache
= trad_frame_cache_zalloc (this_frame
);
51 tramp_cache
->tramp_frame
->init (tramp_cache
->tramp_frame
,
53 tramp_cache
->trad_cache
,
56 return tramp_cache
->trad_cache
;
60 tramp_frame_this_id (struct frame_info
*this_frame
,
62 struct frame_id
*this_id
)
64 struct trad_frame_cache
*trad_cache
65 = tramp_frame_cache (this_frame
, this_cache
);
67 trad_frame_get_id (trad_cache
, this_id
);
71 tramp_frame_prev_register (struct frame_info
*this_frame
,
75 struct trad_frame_cache
*trad_cache
76 = tramp_frame_cache (this_frame
, this_cache
);
78 return trad_frame_get_register (trad_cache
, this_frame
, prev_regnum
);
82 tramp_frame_start (const struct tramp_frame
*tramp
,
83 struct frame_info
*this_frame
, CORE_ADDR pc
)
85 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
86 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
89 /* Search through the trampoline for one that matches the
90 instruction sequence around PC. */
91 for (ti
= 0; tramp
->insn
[ti
].bytes
!= TRAMP_SENTINEL_INSN
; ti
++)
93 CORE_ADDR func
= pc
- tramp
->insn_size
* ti
;
98 gdb_byte buf
[sizeof (tramp
->insn
[0])];
101 if (tramp
->insn
[i
].bytes
== TRAMP_SENTINEL_INSN
)
103 if (!safe_frame_unwind_memory (this_frame
,
104 func
+ i
* tramp
->insn_size
,
105 buf
, tramp
->insn_size
))
107 insn
= extract_unsigned_integer (buf
, tramp
->insn_size
, byte_order
);
108 if (tramp
->insn
[i
].bytes
!= (insn
& tramp
->insn
[i
].mask
))
112 /* Trampoline doesn't match. */
117 tramp_frame_sniffer (const struct frame_unwind
*self
,
118 struct frame_info
*this_frame
,
121 const struct tramp_frame
*tramp
= self
->unwind_data
->tramp_frame
;
122 CORE_ADDR pc
= get_frame_pc (this_frame
);
124 struct tramp_frame_cache
*tramp_cache
;
126 /* tausq/2004-12-12: We used to assume if pc has a name or is in a valid
127 section, then this is not a trampoline. However, this assumption is
128 false on HPUX which has a signal trampoline that has a name; it can
129 also be false when using an alternative signal stack. */
130 func
= tramp_frame_start (tramp
, this_frame
, pc
);
133 tramp_cache
= FRAME_OBSTACK_ZALLOC (struct tramp_frame_cache
);
134 tramp_cache
->func
= func
;
135 tramp_cache
->tramp_frame
= tramp
;
136 (*this_cache
) = tramp_cache
;
141 tramp_frame_prepend_unwinder (struct gdbarch
*gdbarch
,
142 const struct tramp_frame
*tramp_frame
)
144 struct frame_data
*data
;
145 struct frame_unwind
*unwinder
;
148 /* Check that the instruction sequence contains a sentinel. */
149 for (i
= 0; i
< ARRAY_SIZE (tramp_frame
->insn
); i
++)
151 if (tramp_frame
->insn
[i
].bytes
== TRAMP_SENTINEL_INSN
)
154 gdb_assert (i
< ARRAY_SIZE (tramp_frame
->insn
));
155 gdb_assert (tramp_frame
->insn_size
<= sizeof (tramp_frame
->insn
[0].bytes
));
157 data
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct frame_data
);
158 unwinder
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct frame_unwind
);
160 data
->tramp_frame
= tramp_frame
;
161 unwinder
->type
= tramp_frame
->frame_type
;
162 unwinder
->unwind_data
= data
;
163 unwinder
->sniffer
= tramp_frame_sniffer
;
164 unwinder
->stop_reason
= default_frame_unwind_stop_reason
;
165 unwinder
->this_id
= tramp_frame_this_id
;
166 unwinder
->prev_register
= tramp_frame_prev_register
;
167 frame_unwind_prepend_unwinder (gdbarch
, unwinder
);