GDB (xrefs)

/tmp/gdb-8.1/gdb/tramp-frame.c
Go to the documentation of this file.
1 /* Signal trampoline unwinder, for GDB the GNU Debugger.
2
3 Copyright (C) 2004-2018 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
30 struct frame_data
31 {
32 const struct tramp_frame *tramp_frame;
33 };
34
35 struct tramp_frame_cache
36 {
37 CORE_ADDR func;
38 const struct tramp_frame *tramp_frame;
39 struct trad_frame_cache *trad_cache;
40 };
41
42 static struct trad_frame_cache *
43 tramp_frame_cache (struct frame_info *this_frame,
44 void **this_cache)
45 {
46 struct tramp_frame_cache *tramp_cache
47 = (struct tramp_frame_cache *) *this_cache;
48
49 if (tramp_cache->trad_cache == NULL)
50 {
51 tramp_cache->trad_cache = trad_frame_cache_zalloc (this_frame);
52 tramp_cache->tramp_frame->init (tramp_cache->tramp_frame,
53 this_frame,
54 tramp_cache->trad_cache,
55 tramp_cache->func);
56 }
57 return tramp_cache->trad_cache;
58 }
59
60 static void
61 tramp_frame_this_id (struct frame_info *this_frame,
62 void **this_cache,
63 struct frame_id *this_id)
64 {
65 struct trad_frame_cache *trad_cache
66 = tramp_frame_cache (this_frame, this_cache);
67
68 trad_frame_get_id (trad_cache, this_id);
69 }
70
71 static struct value *
72 tramp_frame_prev_register (struct frame_info *this_frame,
73 void **this_cache,
74 int prev_regnum)
75 {
76 struct trad_frame_cache *trad_cache
77 = tramp_frame_cache (this_frame, this_cache);
78
79 return trad_frame_get_register (trad_cache, this_frame, prev_regnum);
80 }
81
82 static CORE_ADDR
83 tramp_frame_start (const struct tramp_frame *tramp,
84 struct frame_info *this_frame, CORE_ADDR pc)
85 {
86 struct gdbarch *gdbarch = get_frame_arch (this_frame);
87 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
88 int ti;
89
90 /* Check if we can use this trampoline. */
91 if (tramp->validate && !tramp->validate (tramp, this_frame, &pc))
92 return 0;
93
94 /* Search through the trampoline for one that matches the
95 instruction sequence around PC. */
96 for (ti = 0; tramp->insn[ti].bytes != TRAMP_SENTINEL_INSN; ti++)
97 {
98 CORE_ADDR func = pc - tramp->insn_size * ti;
99 int i;
100
101 for (i = 0; 1; i++)
102 {
103 gdb_byte buf[sizeof (tramp->insn[0])];
104 ULONGEST insn;
105
106 if (tramp->insn[i].bytes == TRAMP_SENTINEL_INSN)
107 return func;
108 if (!safe_frame_unwind_memory (this_frame,
109 func + i * tramp->insn_size,
110 buf, tramp->insn_size))
111 break;
112 insn = extract_unsigned_integer (buf, tramp->insn_size, byte_order);
113 if (tramp->insn[i].bytes != (insn & tramp->insn[i].mask))
114 break;
115 }
116 }
117 /* Trampoline doesn't match. */
118 return 0;
119 }
120
121 static int
122 tramp_frame_sniffer (const struct frame_unwind *self,
123 struct frame_info *this_frame,
124 void **this_cache)
125 {
126 const struct tramp_frame *tramp = self->unwind_data->tramp_frame;
127 CORE_ADDR pc = get_frame_pc (this_frame);
128 CORE_ADDR func;
129 struct tramp_frame_cache *tramp_cache;
130
131 /* tausq/2004-12-12: We used to assume if pc has a name or is in a valid
132 section, then this is not a trampoline. However, this assumption is
133 false on HPUX which has a signal trampoline that has a name; it can
134 also be false when using an alternative signal stack. */
135 func = tramp_frame_start (tramp, this_frame, pc);
136 if (func == 0)
137 return 0;
138 tramp_cache = FRAME_OBSTACK_ZALLOC (struct tramp_frame_cache);
139 tramp_cache->func = func;
140 tramp_cache->tramp_frame = tramp;
141 (*this_cache) = tramp_cache;
142 return 1;
143 }
144
145 void
146 tramp_frame_prepend_unwinder (struct gdbarch *gdbarch,
147 const struct tramp_frame *tramp_frame)
148 {
149 struct frame_data *data;
150 struct frame_unwind *unwinder;
151 int i;
152
153 /* Check that the instruction sequence contains a sentinel. */
154 for (i = 0; i < ARRAY_SIZE (tramp_frame->insn); i++)
155 {
156 if (tramp_frame->insn[i].bytes == TRAMP_SENTINEL_INSN)
157 break;
158 }
159 gdb_assert (i < ARRAY_SIZE (tramp_frame->insn));
160 gdb_assert (tramp_frame->insn_size <= sizeof (tramp_frame->insn[0].bytes));
161
162 data = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct frame_data);
163 unwinder = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct frame_unwind);
164
165 data->tramp_frame = tramp_frame;
166 unwinder->type = tramp_frame->frame_type;
167 unwinder->unwind_data = data;
168 unwinder->sniffer = tramp_frame_sniffer;
169 unwinder->stop_reason = default_frame_unwind_stop_reason;
170 unwinder->this_id = tramp_frame_this_id;
171 unwinder->prev_register = tramp_frame_prev_register;
172 frame_unwind_prepend_unwinder (gdbarch, unwinder);
173 }
gdbarch
Definition: gdbarch.c:127
tramp_frame_start
static CORE_ADDR tramp_frame_start(const struct tramp_frame *tramp, struct frame_info *this_frame, CORE_ADDR pc)
Definition: tramp-frame.c:83
frame_data
Definition: tramp-frame.c:30
get_frame_pc
CORE_ADDR get_frame_pc(struct frame_info *frame)
Definition: frame.c:2376
CORE_ADDR
bfd_vma CORE_ADDR
Definition: common-types.h:41
frame_unwind::type
enum frame_type type
Definition: frame-unwind.h:148
TRAMP_SENTINEL_INSN
#define TRAMP_SENTINEL_INSN
Definition: tramp-frame.h:44
tramp_frame::bytes
ULONGEST bytes
Definition: tramp-frame.h:63
func
void(* func)(char *)
Definition: remote-fileio.c:1104
tramp_frame_sniffer
static int tramp_frame_sniffer(const struct frame_unwind *self, struct frame_info *this_frame, void **this_cache)
Definition: tramp-frame.c:122
frame_unwind::prev_register
frame_prev_register_ftype * prev_register
Definition: frame-unwind.h:153
frame_unwind::sniffer
frame_sniffer_ftype * sniffer
Definition: frame-unwind.h:155
frame_info
Definition: frame.c:85
defs.h
frame_unwind_prepend_unwinder
void frame_unwind_prepend_unwinder(struct gdbarch *gdbarch, const struct frame_unwind *unwinder)
Definition: frame-unwind.c:64
FRAME_OBSTACK_ZALLOC
#define FRAME_OBSTACK_ZALLOC(TYPE)
Definition: frame.h:678
tramp_frame_cache::trad_cache
struct trad_frame_cache * trad_cache
Definition: tramp-frame.c:39
GDBARCH_OBSTACK_ZALLOC
#define GDBARCH_OBSTACK_ZALLOC(GDBARCH, TYPE)
Definition: gdbarch.h:1709
objfiles.h
tramp_frame_this_id
static void tramp_frame_this_id(struct frame_info *this_frame, void **this_cache, struct frame_id *this_id)
Definition: tramp-frame.c:61
symtab.h
trad_frame_get_id
void trad_frame_get_id(struct trad_frame_cache *this_trad_cache, struct frame_id *this_id)
Definition: trad-frame.c:178
trad-frame.h
tramp_frame_cache
static struct trad_frame_cache * tramp_frame_cache(struct frame_info *this_frame, void **this_cache)
Definition: tramp-frame.c:43
extract_unsigned_integer
static ULONGEST extract_unsigned_integer(const gdb_byte *addr, int len, enum bfd_endian byte_order)
Definition: defs.h:577
safe_frame_unwind_memory
int safe_frame_unwind_memory(struct frame_info *this_frame, CORE_ADDR addr, gdb_byte *buf, int len)
Definition: frame.c:2681
trad_frame_cache
Definition: trad-frame.c:27
frame_unwind::stop_reason
frame_unwind_stop_reason_ftype * stop_reason
Definition: frame-unwind.h:151
gdbarch_byte_order
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
Definition: gdbarch.c:1509
tramp_frame_prev_register
static struct value * tramp_frame_prev_register(struct frame_info *this_frame, void **this_cache, int prev_regnum)
Definition: tramp-frame.c:72
tramp_frame_cache::tramp_frame
const struct tramp_frame * tramp_frame
Definition: tramp-frame.c:38
frame-unwind.h
trad_frame_cache_zalloc
struct trad_frame_cache * trad_frame_cache_zalloc(struct frame_info *this_frame)
Definition: trad-frame.c:36
tramp_frame::frame_type
enum frame_type frame_type
Definition: tramp-frame.h:50
frame-base.h
trad_frame_cache::this_frame
struct frame_info * this_frame
Definition: trad-frame.c:29
tramp_frame::mask
ULONGEST mask
Definition: tramp-frame.h:64
gdb_assert
#define gdb_assert(expr)
Definition: gdb_assert.h:32
value
Definition: value.c:169
frame_data::tramp_frame
const struct tramp_frame * tramp_frame
Definition: tramp-frame.c:32
tramp-frame.h
trad_frame_cache::this_id
struct frame_id this_id
Definition: trad-frame.c:32
tramp_frame::insn_size
int insn_size
Definition: tramp-frame.h:60
gdb_byte
bfd_byte gdb_byte
Definition: common-types.h:38
gdbcore.h
tramp_frame_cache
Definition: tramp-frame.c:35
tramp_frame_prepend_unwinder
void tramp_frame_prepend_unwinder(struct gdbarch *gdbarch, const struct tramp_frame *tramp_frame)
Definition: tramp-frame.c:146
target.h
tramp_frame::init
void(* init)(const struct tramp_frame *self, struct frame_info *this_frame, struct trad_frame_cache *this_cache, CORE_ADDR func)
Definition: tramp-frame.h:68
frame_unwind
Definition: frame-unwind.h:144
tramp_frame_cache::func
CORE_ADDR func
Definition: tramp-frame.c:37
tramp_frame::insn
struct tramp_frame::@180 insn[48]
ULONGEST
unsigned long long ULONGEST
Definition: common-types.h:53
default_frame_unwind_stop_reason
enum unwind_stop_reason default_frame_unwind_stop_reason(struct frame_info *this_frame, void **this_cache)
Definition: frame-unwind.c:184
frame_unwind::this_id
frame_this_id_ftype * this_id
Definition: frame-unwind.h:152
frame_unwind::unwind_data
const struct frame_data * unwind_data
Definition: frame-unwind.h:154
tramp_frame
Definition: tramp-frame.h:46
gdbarch::byte_order
enum bfd_endian byte_order
Definition: gdbarch.c:137
trad_frame_get_register
struct value * trad_frame_get_register(struct trad_frame_cache *this_trad_cache, struct frame_info *this_frame, int regnum)
Definition: trad-frame.c:162
tramp_frame::validate
int(* validate)(const struct tramp_frame *self, struct frame_info *this_frame, CORE_ADDR *pc)
Definition: tramp-frame.h:76
frame_id
Definition: frame.h:111
get_frame_arch
struct gdbarch * get_frame_arch(struct frame_info *this_frame)
Definition: frame.c:2691