Commit | Line | Data |
---|---|---|
da62e633 AC |
1 | /* Definitions for frame address handler, for GDB, the GNU debugger. |
2 | ||
3 | Copyright 2003 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 "frame-base.h" | |
24 | #include "frame.h" | |
25 | ||
26 | /* A default frame base implementations. If it wasn't for the old | |
42efa47a AC |
27 | DEPRECATED_FRAME_LOCALS_ADDRESS and DEPRECATED_FRAME_ARGS_ADDRESS, |
28 | these could be combined into a single function. All architectures | |
29 | really need to override this. */ | |
da62e633 AC |
30 | |
31 | static CORE_ADDR | |
32 | default_frame_base_address (struct frame_info *next_frame, void **this_cache) | |
33 | { | |
34 | struct frame_info *this_frame = get_prev_frame (next_frame); | |
35 | return get_frame_base (this_frame); /* sigh! */ | |
36 | } | |
37 | ||
38 | static CORE_ADDR | |
39 | default_frame_locals_address (struct frame_info *next_frame, void **this_cache) | |
40 | { | |
42efa47a AC |
41 | if (DEPRECATED_FRAME_LOCALS_ADDRESS_P ()) |
42 | { | |
43 | /* This is bad. The computation of per-frame locals address | |
44 | should use a per-frame frame-base. */ | |
45 | struct frame_info *this_frame = get_prev_frame (next_frame); | |
46 | return DEPRECATED_FRAME_LOCALS_ADDRESS (this_frame); | |
47 | } | |
48 | return default_frame_base_address (next_frame, this_cache); | |
da62e633 AC |
49 | } |
50 | ||
51 | static CORE_ADDR | |
52 | default_frame_args_address (struct frame_info *next_frame, void **this_cache) | |
53 | { | |
42efa47a AC |
54 | if (DEPRECATED_FRAME_ARGS_ADDRESS_P ()) |
55 | { | |
56 | struct frame_info *this_frame = get_prev_frame (next_frame); | |
57 | return DEPRECATED_FRAME_ARGS_ADDRESS (this_frame); | |
58 | } | |
59 | return default_frame_base_address (next_frame, this_cache); | |
da62e633 AC |
60 | } |
61 | ||
62 | const struct frame_base default_frame_base = { | |
63 | NULL, /* No parent. */ | |
64 | default_frame_base_address, | |
65 | default_frame_locals_address, | |
66 | default_frame_args_address | |
67 | }; | |
68 | ||
69 | static struct gdbarch_data *frame_base_data; | |
70 | ||
71 | struct frame_base_table | |
72 | { | |
73 | frame_base_p_ftype **p; | |
e8a89fe2 | 74 | frame_base_sniffer_ftype **sniffer; |
da62e633 AC |
75 | const struct frame_base *default_base; |
76 | int nr; | |
77 | }; | |
78 | ||
79 | static void * | |
80 | frame_base_init (struct gdbarch *gdbarch) | |
81 | { | |
82 | struct frame_base_table *table = XCALLOC (1, struct frame_base_table); | |
83 | table->default_base = &default_frame_base; | |
84 | return table; | |
85 | } | |
86 | ||
87 | static void | |
88 | frame_base_free (struct gdbarch *gdbarch, void *data) | |
89 | { | |
90 | struct frame_base_table *table = | |
91 | gdbarch_data (gdbarch, frame_base_data); | |
92 | xfree (table->p); | |
e8a89fe2 | 93 | xfree (table->sniffer); |
da62e633 AC |
94 | xfree (table); |
95 | } | |
96 | ||
97 | static struct frame_base_table * | |
98 | frame_base_table (struct gdbarch *gdbarch) | |
99 | { | |
100 | struct frame_base_table *table = gdbarch_data (gdbarch, frame_base_data); | |
101 | if (table == NULL) | |
102 | { | |
103 | /* ULGH, called during architecture initialization. Patch | |
104 | things up. */ | |
105 | table = frame_base_init (gdbarch); | |
106 | set_gdbarch_data (gdbarch, frame_base_data, table); | |
107 | } | |
108 | return table; | |
109 | } | |
110 | ||
111 | /* Append a predicate to the end of the table. */ | |
112 | static void | |
e8a89fe2 AC |
113 | append_predicate (struct frame_base_table *table, frame_base_p_ftype *p, |
114 | frame_base_sniffer_ftype *sniffer) | |
da62e633 AC |
115 | { |
116 | table->p = xrealloc (table->p, ((table->nr + 1) | |
117 | * sizeof (frame_base_p_ftype *))); | |
e8a89fe2 AC |
118 | table->sniffer = xrealloc (table->sniffer, |
119 | ((table->nr + 1) | |
120 | * sizeof (frame_base_sniffer_ftype *))); | |
da62e633 | 121 | table->p[table->nr] = p; |
e8a89fe2 | 122 | table->sniffer[table->nr] = sniffer; |
da62e633 AC |
123 | table->nr++; |
124 | } | |
125 | ||
126 | void | |
127 | frame_base_append_predicate (struct gdbarch *gdbarch, | |
128 | frame_base_p_ftype *p) | |
129 | { | |
130 | struct frame_base_table *table = frame_base_table (gdbarch); | |
e8a89fe2 AC |
131 | append_predicate (table, p, NULL); |
132 | } | |
133 | ||
134 | void | |
135 | frame_base_append_sniffer (struct gdbarch *gdbarch, | |
136 | frame_base_sniffer_ftype *sniffer) | |
137 | { | |
138 | struct frame_base_table *table = frame_base_table (gdbarch); | |
139 | append_predicate (table, NULL, sniffer); | |
da62e633 AC |
140 | } |
141 | ||
142 | void | |
143 | frame_base_set_default (struct gdbarch *gdbarch, | |
144 | const struct frame_base *default_base) | |
145 | { | |
146 | struct frame_base_table *table = frame_base_table (gdbarch); | |
147 | table->default_base = default_base; | |
148 | } | |
149 | ||
150 | const struct frame_base * | |
e8a89fe2 | 151 | frame_base_find_by_frame (struct frame_info *next_frame) |
da62e633 | 152 | { |
e8a89fe2 | 153 | struct gdbarch *gdbarch = get_frame_arch (next_frame); |
da62e633 | 154 | struct frame_base_table *table = frame_base_table (gdbarch); |
e8a89fe2 | 155 | int i; |
da62e633 AC |
156 | for (i = 0; i < table->nr; i++) |
157 | { | |
e8a89fe2 AC |
158 | const struct frame_base *desc = NULL; |
159 | if (table->p[i] != NULL) | |
160 | desc = table->p[i] (frame_pc_unwind (next_frame)); | |
161 | else if (table->sniffer[i] != NULL) | |
162 | desc = table->sniffer[i] (next_frame); | |
da62e633 AC |
163 | if (desc != NULL) |
164 | return desc; | |
165 | } | |
166 | return table->default_base; | |
167 | } | |
168 | ||
a78f21af | 169 | extern initialize_file_ftype _initialize_frame_base; /* -Wmissing-prototypes */ |
b9362cc7 | 170 | |
da62e633 AC |
171 | void |
172 | _initialize_frame_base (void) | |
173 | { | |
174 | frame_base_data = register_gdbarch_data (frame_base_init, | |
175 | frame_base_free); | |
176 | } |