1 /* Signal trampoline unwinder, for GDB the GNU Debugger.
3 Copyright (C) 2004 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 2 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, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
23 #include "tramp-frame.h"
24 #include "frame-unwind.h"
29 #include "trad-frame.h"
30 #include "frame-base.h"
31 #include "gdb_assert.h"
35 const struct tramp_frame
*tramp_frame
;
38 struct tramp_frame_cache
41 const struct tramp_frame
*tramp_frame
;
42 struct trad_frame_cache
*trad_cache
;
45 static struct trad_frame_cache
*
46 tramp_frame_cache (struct frame_info
*next_frame
,
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
)
53 tramp_cache
->trad_cache
= trad_frame_cache_zalloc (next_frame
);
54 tramp_cache
->tramp_frame
->init (tramp_cache
->tramp_frame
,
56 tramp_cache
->trad_cache
,
59 return tramp_cache
->trad_cache
;
63 tramp_frame_this_id (struct frame_info
*next_frame
,
65 struct frame_id
*this_id
)
67 struct trad_frame_cache
*trad_cache
68 = tramp_frame_cache (next_frame
, this_cache
);
69 trad_frame_get_id (trad_cache
, this_id
);
73 tramp_frame_prev_register (struct frame_info
*next_frame
,
77 enum lval_type
* lvalp
,
79 int *realnump
, gdb_byte
*valuep
)
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
);
88 tramp_frame_start (const struct tramp_frame
*tramp
,
89 struct frame_info
*next_frame
, CORE_ADDR pc
)
92 /* Search through the trampoline for one that matches the
93 instruction sequence around PC. */
94 for (ti
= 0; tramp
->insn
[ti
].bytes
!= TRAMP_SENTINEL_INSN
; ti
++)
96 CORE_ADDR func
= pc
- tramp
->insn_size
* ti
;
100 gdb_byte buf
[sizeof (tramp
->insn
[0])];
102 if (tramp
->insn
[i
].bytes
== TRAMP_SENTINEL_INSN
)
104 if (!safe_frame_unwind_memory (next_frame
,
105 func
+ i
* tramp
->insn_size
,
106 buf
, tramp
->insn_size
))
108 insn
= extract_unsigned_integer (buf
, tramp
->insn_size
);
109 if (tramp
->insn
[i
].bytes
!= (insn
& tramp
->insn
[i
].mask
))
113 /* Trampoline doesn't match. */
118 tramp_frame_sniffer (const struct frame_unwind
*self
,
119 struct frame_info
*next_frame
,
122 const struct tramp_frame
*tramp
= self
->unwind_data
->tramp_frame
;
123 CORE_ADDR pc
= frame_pc_unwind (next_frame
);
125 struct tramp_frame_cache
*tramp_cache
;
127 /* tausq/2004-12-12: We used to assume if pc has a name or is in a valid
128 section, then this is not a trampoline. However, this assumption is
129 false on HPUX which has a signal trampoline that has a name; it can
130 also be false when using an alternative signal stack. */
131 func
= tramp_frame_start (tramp
, next_frame
, pc
);
134 tramp_cache
= FRAME_OBSTACK_ZALLOC (struct tramp_frame_cache
);
135 tramp_cache
->func
= func
;
136 tramp_cache
->tramp_frame
= tramp
;
137 (*this_cache
) = tramp_cache
;
142 tramp_frame_prepend_unwinder (struct gdbarch
*gdbarch
,
143 const struct tramp_frame
*tramp_frame
)
145 struct frame_data
*data
;
146 struct frame_unwind
*unwinder
;
149 /* Check that the instruction sequence contains a sentinel. */
150 for (i
= 0; i
< ARRAY_SIZE (tramp_frame
->insn
); i
++)
152 if (tramp_frame
->insn
[i
].bytes
== TRAMP_SENTINEL_INSN
)
155 gdb_assert (i
< ARRAY_SIZE (tramp_frame
->insn
));
156 gdb_assert (tramp_frame
->insn_size
<= sizeof (tramp_frame
->insn
[0].bytes
));
158 data
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct frame_data
);
159 unwinder
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct frame_unwind
);
161 data
->tramp_frame
= tramp_frame
;
162 unwinder
->type
= tramp_frame
->frame_type
;
163 unwinder
->unwind_data
= data
;
164 unwinder
->sniffer
= tramp_frame_sniffer
;
165 unwinder
->this_id
= tramp_frame_this_id
;
166 unwinder
->prev_register
= tramp_frame_prev_register
;
167 frame_unwind_prepend_unwinder (gdbarch
, unwinder
);