1 /* Cache and manage frames for GDB, the GNU debugger.
3 Copyright 1986, 1987, 1989, 1991, 1994, 1995, 1996, 1998, 2000,
4 2001, 2002 Free Software Foundation, Inc.
6 This file is part of GDB.
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.
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.
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. */
27 #include "inferior.h" /* for inferior_ptid */
29 #include "gdb_assert.h"
30 #include "gdb_string.h"
31 #include "builtin-regs.h"
33 /* Return a frame uniq ID that can be used to, later re-find the
37 get_frame_id (struct frame_info
*fi
, struct frame_id
*id
)
46 id
->base
= FRAME_FP (fi
);
52 frame_find_by_id (struct frame_id id
)
54 struct frame_info
*frame
;
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)
61 for (frame
= get_current_frame ();
63 frame
= get_prev_frame (frame
))
65 if (INNER_THAN (FRAME_FP (frame
), id
.base
))
66 /* ``inner/current < frame < id.base''. Keep looking along
69 if (INNER_THAN (id
.base
, FRAME_FP (frame
)))
70 /* ``inner/current < id.base < frame''. Oops, gone past it.
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. */
84 frame_register_unwind (struct frame_info
*frame
, int regnum
,
85 int *optimizedp
, enum lval_type
*lvalp
,
86 CORE_ADDR
*addrp
, int *realnump
, void *bufferp
)
88 struct frame_unwind_cache
*cache
;
90 /* Require all but BUFFERP to be valid. A NULL BUFFERP indicates
91 that the value proper does not need to be fetched. */
92 gdb_assert (optimizedp
!= NULL
);
93 gdb_assert (lvalp
!= NULL
);
94 gdb_assert (addrp
!= NULL
);
95 gdb_assert (realnump
!= NULL
);
96 /* gdb_assert (bufferp != NULL); */
98 /* NOTE: cagney/2002-04-14: It would be nice if, instead of a
99 special case, there was always an inner frame dedicated to the
100 hardware registers. Unfortunatly, there is too much unwind code
101 around that looks up/down the frame chain while making the
102 assumption that each frame level is using the same unwind code. */
106 /* We're in the inner-most frame, get the value direct from the
109 *lvalp
= lval_register
;
110 /* ULGH! Code uses the offset into the raw register byte array
111 as a way of identifying a register. */
112 *addrp
= REGISTER_BYTE (regnum
);
113 /* Should this code test ``register_cached (regnum) < 0'' and do
114 something like set realnum to -1 when the register isn't
118 read_register_gen (regnum
, bufferp
);
122 /* Ask this frame to unwind its register. */
123 frame
->register_unwind (frame
, &frame
->register_unwind_cache
, regnum
,
124 optimizedp
, lvalp
, addrp
, realnump
, bufferp
);
128 frame_unwind_signed_register (struct frame_info
*frame
, int regnum
,
135 void *buf
= alloca (MAX_REGISTER_RAW_SIZE
);
136 frame_register_unwind (frame
, regnum
, &optimized
, &lval
, &addr
,
138 (*val
) = extract_signed_integer (buf
, REGISTER_VIRTUAL_SIZE (regnum
));
142 frame_unwind_unsigned_register (struct frame_info
*frame
, int regnum
,
149 void *buf
= alloca (MAX_REGISTER_RAW_SIZE
);
150 frame_register_unwind (frame
, regnum
, &optimized
, &lval
, &addr
,
152 (*val
) = extract_unsigned_integer (buf
, REGISTER_VIRTUAL_SIZE (regnum
));
156 generic_unwind_get_saved_register (char *raw_buffer
,
159 struct frame_info
*frame
,
161 enum lval_type
*lvalp
)
166 enum lval_type lvalx
;
168 if (!target_has_registers
)
169 error ("No registers.");
171 /* Keep things simple, ensure that all the pointers (except valuep)
173 if (optimizedp
== NULL
)
174 optimizedp
= &optimizedx
;
180 /* Reached the the bottom (youngest, inner most) of the frame chain
181 (youngest, inner most) frame, go direct to the hardware register
182 cache (do not pass go, do not try to cache the value, ...). The
183 unwound value would have been cached in frame->next but that
184 doesn't exist. This doesn't matter as the hardware register
185 cache is stopping any unnecessary accesses to the target. */
187 /* NOTE: cagney/2002-04-14: It would be nice if, instead of a
188 special case, there was always an inner frame dedicated to the
189 hardware registers. Unfortunatly, there is too much unwind code
190 around that looks up/down the frame chain while making the
191 assumption that each frame level is using the same unwind code. */
194 frame_register_unwind (NULL
, regnum
, optimizedp
, lvalp
, addrp
, &realnumx
,
197 frame_register_unwind (frame
->next
, regnum
, optimizedp
, lvalp
, addrp
,
198 &realnumx
, raw_buffer
);
202 get_saved_register (char *raw_buffer
,
205 struct frame_info
*frame
,
207 enum lval_type
*lval
)
209 GET_SAVED_REGISTER (raw_buffer
, optimized
, addrp
, frame
, regnum
, lval
);
212 /* frame_register_read ()
214 Find and return the value of REGNUM for the specified stack frame.
215 The number of bytes copied is REGISTER_RAW_SIZE (REGNUM).
217 Returns 0 if the register value could not be found. */
220 frame_register_read (struct frame_info
*frame
, int regnum
, void *myaddr
)
223 get_saved_register (myaddr
, &optim
, (CORE_ADDR
*) NULL
, frame
,
224 regnum
, (enum lval_type
*) NULL
);
226 /* FIXME: cagney/2002-05-15: This test, is just bogus.
228 It indicates that the target failed to supply a value for a
229 register because it was "not available" at this time. Problem
230 is, the target still has the register and so get saved_register()
231 may be returning a value saved on the stack. */
233 if (register_cached (regnum
) < 0)
234 return 0; /* register value not available */
240 /* Map between a frame register number and its name. A frame register
241 space is a superset of the cooked register space --- it also
242 includes builtin registers. */
245 frame_map_name_to_regnum (const char *name
, int len
)
249 /* Search register name space. */
250 for (i
= 0; i
< NUM_REGS
+ NUM_PSEUDO_REGS
; i
++)
251 if (REGISTER_NAME (i
) && len
== strlen (REGISTER_NAME (i
))
252 && strncmp (name
, REGISTER_NAME (i
), len
) == 0)
257 /* Try builtin registers. */
258 i
= builtin_reg_map_name_to_regnum (name
, len
);
261 /* A builtin register doesn't fall into the architecture's
263 gdb_assert (i
>= NUM_REGS
+ NUM_PSEUDO_REGS
);
271 frame_map_regnum_to_name (int regnum
)
275 if (regnum
< NUM_REGS
+ NUM_PSEUDO_REGS
)
276 return REGISTER_NAME (regnum
);
277 return builtin_reg_map_regnum_to_name (regnum
);
This page took 0.033969 seconds and 4 git commands to generate.