1 |
1181 |
sfurman |
/* Cache and manage frames for GDB, the GNU debugger.
|
2 |
|
|
|
3 |
|
|
Copyright 1986, 1987, 1989, 1991, 1994, 1995, 1996, 1998, 2000,
|
4 |
|
|
2001, 2002 Free Software Foundation, Inc.
|
5 |
|
|
|
6 |
|
|
This file is part of GDB.
|
7 |
|
|
|
8 |
|
|
This program is free software; you can redistribute it and/or modify
|
9 |
|
|
it under the terms of the GNU General Public License as published by
|
10 |
|
|
the Free Software Foundation; either version 2 of the License, or
|
11 |
|
|
(at your option) any later version.
|
12 |
|
|
|
13 |
|
|
This program is distributed in the hope that it will be useful,
|
14 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
|
|
GNU General Public License for more details.
|
17 |
|
|
|
18 |
|
|
You should have received a copy of the GNU General Public License
|
19 |
|
|
along with this program; if not, write to the Free Software
|
20 |
|
|
Foundation, Inc., 59 Temple Place - Suite 330,
|
21 |
|
|
Boston, MA 02111-1307, USA. */
|
22 |
|
|
|
23 |
|
|
#include "defs.h"
|
24 |
|
|
#include "frame.h"
|
25 |
|
|
#include "target.h"
|
26 |
|
|
#include "value.h"
|
27 |
|
|
#include "inferior.h" /* for inferior_ptid */
|
28 |
|
|
#include "regcache.h"
|
29 |
|
|
#include "gdb_assert.h"
|
30 |
|
|
#include "gdb_string.h"
|
31 |
|
|
#include "builtin-regs.h"
|
32 |
|
|
|
33 |
|
|
/* Return a frame uniq ID that can be used to, later re-find the
|
34 |
|
|
frame. */
|
35 |
|
|
|
36 |
|
|
void
|
37 |
|
|
get_frame_id (struct frame_info *fi, struct frame_id *id)
|
38 |
|
|
{
|
39 |
|
|
if (fi == NULL)
|
40 |
|
|
{
|
41 |
|
|
id->base = 0;
|
42 |
|
|
id->pc = 0;
|
43 |
|
|
}
|
44 |
|
|
else
|
45 |
|
|
{
|
46 |
|
|
id->base = FRAME_FP (fi);
|
47 |
|
|
id->pc = fi->pc;
|
48 |
|
|
}
|
49 |
|
|
}
|
50 |
|
|
|
51 |
|
|
struct frame_info *
|
52 |
|
|
frame_find_by_id (struct frame_id id)
|
53 |
|
|
{
|
54 |
|
|
struct frame_info *frame;
|
55 |
|
|
|
56 |
|
|
/* ZERO denotes the null frame, let the caller decide what to do
|
57 |
|
|
about it. Should it instead return get_current_frame()? */
|
58 |
|
|
if (id.base == 0 && id.pc == 0)
|
59 |
|
|
return NULL;
|
60 |
|
|
|
61 |
|
|
for (frame = get_current_frame ();
|
62 |
|
|
frame != NULL;
|
63 |
|
|
frame = get_prev_frame (frame))
|
64 |
|
|
{
|
65 |
|
|
if (INNER_THAN (FRAME_FP (frame), id.base))
|
66 |
|
|
/* ``inner/current < frame < id.base''. Keep looking along
|
67 |
|
|
the frame chain. */
|
68 |
|
|
continue;
|
69 |
|
|
if (INNER_THAN (id.base, FRAME_FP (frame)))
|
70 |
|
|
/* ``inner/current < id.base < frame''. Oops, gone past it.
|
71 |
|
|
Just give up. */
|
72 |
|
|
return NULL;
|
73 |
|
|
/* FIXME: cagney/2002-04-21: This isn't sufficient. It should
|
74 |
|
|
use id.pc to check that the two frames belong to the same
|
75 |
|
|
function. Otherwise we'll do things like match dummy frames
|
76 |
|
|
or mis-match frameless functions. However, until someone
|
77 |
|
|
notices, stick with the existing behavour. */
|
78 |
|
|
return frame;
|
79 |
|
|
}
|
80 |
|
|
return NULL;
|
81 |
|
|
}
|
82 |
|
|
|
83 |
|
|
/* FIND_SAVED_REGISTER ()
|
84 |
|
|
|
85 |
|
|
Return the address in which frame FRAME's value of register REGNUM
|
86 |
|
|
has been saved in memory. Or return zero if it has not been saved.
|
87 |
|
|
If REGNUM specifies the SP, the value we return is actually
|
88 |
|
|
the SP value, not an address where it was saved. */
|
89 |
|
|
|
90 |
|
|
CORE_ADDR
|
91 |
|
|
find_saved_register (struct frame_info *frame, int regnum)
|
92 |
|
|
{
|
93 |
|
|
register struct frame_info *frame1 = NULL;
|
94 |
|
|
register CORE_ADDR addr = 0;
|
95 |
|
|
|
96 |
|
|
if (frame == NULL) /* No regs saved if want current frame */
|
97 |
|
|
return 0;
|
98 |
|
|
|
99 |
|
|
/* Note that the following loop assumes that registers used in
|
100 |
|
|
frame x will be saved only in the frame that x calls and frames
|
101 |
|
|
interior to it. */
|
102 |
|
|
while (1)
|
103 |
|
|
{
|
104 |
|
|
QUIT;
|
105 |
|
|
frame1 = get_next_frame (frame);
|
106 |
|
|
if (frame1 == 0)
|
107 |
|
|
break;
|
108 |
|
|
frame = frame1;
|
109 |
|
|
FRAME_INIT_SAVED_REGS (frame1);
|
110 |
|
|
if (frame1->saved_regs[regnum])
|
111 |
|
|
{
|
112 |
|
|
addr = frame1->saved_regs[regnum];
|
113 |
|
|
break;
|
114 |
|
|
}
|
115 |
|
|
}
|
116 |
|
|
|
117 |
|
|
return addr;
|
118 |
|
|
}
|
119 |
|
|
|
120 |
|
|
void
|
121 |
|
|
frame_register_unwind (struct frame_info *frame, int regnum,
|
122 |
|
|
int *optimizedp, enum lval_type *lvalp,
|
123 |
|
|
CORE_ADDR *addrp, int *realnump, void *bufferp)
|
124 |
|
|
{
|
125 |
|
|
struct frame_unwind_cache *cache;
|
126 |
|
|
|
127 |
|
|
/* Require all but BUFFERP to be valid. A NULL BUFFERP indicates
|
128 |
|
|
that the value proper does not need to be fetched. */
|
129 |
|
|
gdb_assert (optimizedp != NULL);
|
130 |
|
|
gdb_assert (lvalp != NULL);
|
131 |
|
|
gdb_assert (addrp != NULL);
|
132 |
|
|
gdb_assert (realnump != NULL);
|
133 |
|
|
/* gdb_assert (bufferp != NULL); */
|
134 |
|
|
|
135 |
|
|
/* NOTE: cagney/2002-04-14: It would be nice if, instead of a
|
136 |
|
|
special case, there was always an inner frame dedicated to the
|
137 |
|
|
hardware registers. Unfortunatly, there is too much unwind code
|
138 |
|
|
around that looks up/down the frame chain while making the
|
139 |
|
|
assumption that each frame level is using the same unwind code. */
|
140 |
|
|
|
141 |
|
|
if (frame == NULL)
|
142 |
|
|
{
|
143 |
|
|
/* We're in the inner-most frame, get the value direct from the
|
144 |
|
|
register cache. */
|
145 |
|
|
*optimizedp = 0;
|
146 |
|
|
*lvalp = lval_register;
|
147 |
|
|
/* ULGH! Code uses the offset into the raw register byte array
|
148 |
|
|
as a way of identifying a register. */
|
149 |
|
|
*addrp = REGISTER_BYTE (regnum);
|
150 |
|
|
/* Should this code test ``register_cached (regnum) < 0'' and do
|
151 |
|
|
something like set realnum to -1 when the register isn't
|
152 |
|
|
available? */
|
153 |
|
|
*realnump = regnum;
|
154 |
|
|
if (bufferp)
|
155 |
|
|
read_register_gen (regnum, bufferp);
|
156 |
|
|
return;
|
157 |
|
|
}
|
158 |
|
|
|
159 |
|
|
/* Ask this frame to unwind its register. */
|
160 |
|
|
frame->register_unwind (frame, &frame->register_unwind_cache, regnum,
|
161 |
|
|
optimizedp, lvalp, addrp, realnump, bufferp);
|
162 |
|
|
}
|
163 |
|
|
|
164 |
|
|
|
165 |
|
|
void
|
166 |
|
|
generic_unwind_get_saved_register (char *raw_buffer,
|
167 |
|
|
int *optimizedp,
|
168 |
|
|
CORE_ADDR *addrp,
|
169 |
|
|
struct frame_info *frame,
|
170 |
|
|
int regnum,
|
171 |
|
|
enum lval_type *lvalp)
|
172 |
|
|
{
|
173 |
|
|
int optimizedx;
|
174 |
|
|
CORE_ADDR addrx;
|
175 |
|
|
int realnumx;
|
176 |
|
|
enum lval_type lvalx;
|
177 |
|
|
|
178 |
|
|
if (!target_has_registers)
|
179 |
|
|
error ("No registers.");
|
180 |
|
|
|
181 |
|
|
/* Keep things simple, ensure that all the pointers (except valuep)
|
182 |
|
|
are non NULL. */
|
183 |
|
|
if (optimizedp == NULL)
|
184 |
|
|
optimizedp = &optimizedx;
|
185 |
|
|
if (lvalp == NULL)
|
186 |
|
|
lvalp = &lvalx;
|
187 |
|
|
if (addrp == NULL)
|
188 |
|
|
addrp = &addrx;
|
189 |
|
|
|
190 |
|
|
/* Reached the the bottom (youngest, inner most) of the frame chain
|
191 |
|
|
(youngest, inner most) frame, go direct to the hardware register
|
192 |
|
|
cache (do not pass go, do not try to cache the value, ...). The
|
193 |
|
|
unwound value would have been cached in frame->next but that
|
194 |
|
|
doesn't exist. This doesn't matter as the hardware register
|
195 |
|
|
cache is stopping any unnecessary accesses to the target. */
|
196 |
|
|
|
197 |
|
|
/* NOTE: cagney/2002-04-14: It would be nice if, instead of a
|
198 |
|
|
special case, there was always an inner frame dedicated to the
|
199 |
|
|
hardware registers. Unfortunatly, there is too much unwind code
|
200 |
|
|
around that looks up/down the frame chain while making the
|
201 |
|
|
assumption that each frame level is using the same unwind code. */
|
202 |
|
|
|
203 |
|
|
if (frame == NULL)
|
204 |
|
|
frame_register_unwind (NULL, regnum, optimizedp, lvalp, addrp, &realnumx,
|
205 |
|
|
raw_buffer);
|
206 |
|
|
else
|
207 |
|
|
frame_register_unwind (frame->next, regnum, optimizedp, lvalp, addrp,
|
208 |
|
|
&realnumx, raw_buffer);
|
209 |
|
|
}
|
210 |
|
|
|
211 |
|
|
void
|
212 |
|
|
get_saved_register (char *raw_buffer,
|
213 |
|
|
int *optimized,
|
214 |
|
|
CORE_ADDR *addrp,
|
215 |
|
|
struct frame_info *frame,
|
216 |
|
|
int regnum,
|
217 |
|
|
enum lval_type *lval)
|
218 |
|
|
{
|
219 |
|
|
GET_SAVED_REGISTER (raw_buffer, optimized, addrp, frame, regnum, lval);
|
220 |
|
|
}
|
221 |
|
|
|
222 |
|
|
/* frame_register_read ()
|
223 |
|
|
|
224 |
|
|
Find and return the value of REGNUM for the specified stack frame.
|
225 |
|
|
The number of bytes copied is REGISTER_RAW_SIZE (REGNUM).
|
226 |
|
|
|
227 |
|
|
Returns 0 if the register value could not be found. */
|
228 |
|
|
|
229 |
|
|
int
|
230 |
|
|
frame_register_read (struct frame_info *frame, int regnum, void *myaddr)
|
231 |
|
|
{
|
232 |
|
|
int optim;
|
233 |
|
|
get_saved_register (myaddr, &optim, (CORE_ADDR *) NULL, frame,
|
234 |
|
|
regnum, (enum lval_type *) NULL);
|
235 |
|
|
|
236 |
|
|
/* FIXME: cagney/2002-05-15: This test, is just bogus.
|
237 |
|
|
|
238 |
|
|
It indicates that the target failed to supply a value for a
|
239 |
|
|
register because it was "not available" at this time. Problem
|
240 |
|
|
is, the target still has the register and so get saved_register()
|
241 |
|
|
may be returning a value saved on the stack. */
|
242 |
|
|
|
243 |
|
|
if (register_cached (regnum) < 0)
|
244 |
|
|
return 0; /* register value not available */
|
245 |
|
|
|
246 |
|
|
return !optim;
|
247 |
|
|
}
|
248 |
|
|
|
249 |
|
|
|
250 |
|
|
/* Map between a frame register number and its name. A frame register
|
251 |
|
|
space is a superset of the cooked register space --- it also
|
252 |
|
|
includes builtin registers. */
|
253 |
|
|
|
254 |
|
|
int
|
255 |
|
|
frame_map_name_to_regnum (const char *name, int len)
|
256 |
|
|
{
|
257 |
|
|
int i;
|
258 |
|
|
|
259 |
|
|
/* Search register name space. */
|
260 |
|
|
for (i = 0; i < NUM_REGS + NUM_PSEUDO_REGS; i++)
|
261 |
|
|
if (REGISTER_NAME (i) && len == strlen (REGISTER_NAME (i))
|
262 |
|
|
&& strncmp (name, REGISTER_NAME (i), len) == 0)
|
263 |
|
|
{
|
264 |
|
|
return i;
|
265 |
|
|
}
|
266 |
|
|
|
267 |
|
|
/* Try builtin registers. */
|
268 |
|
|
i = builtin_reg_map_name_to_regnum (name, len);
|
269 |
|
|
if (i >= 0)
|
270 |
|
|
{
|
271 |
|
|
/* A builtin register doesn't fall into the architecture's
|
272 |
|
|
register range. */
|
273 |
|
|
gdb_assert (i >= NUM_REGS + NUM_PSEUDO_REGS);
|
274 |
|
|
return i;
|
275 |
|
|
}
|
276 |
|
|
|
277 |
|
|
return -1;
|
278 |
|
|
}
|
279 |
|
|
|
280 |
|
|
const char *
|
281 |
|
|
frame_map_regnum_to_name (int regnum)
|
282 |
|
|
{
|
283 |
|
|
if (regnum < 0)
|
284 |
|
|
return NULL;
|
285 |
|
|
if (regnum < NUM_REGS + NUM_PSEUDO_REGS)
|
286 |
|
|
return REGISTER_NAME (regnum);
|
287 |
|
|
return builtin_reg_map_regnum_to_name (regnum);
|
288 |
|
|
}
|