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"
31 /* Return a frame uniq ID that can be used to, later re-find the
35 get_frame_id (struct frame_info
*fi
, struct frame_id
*id
)
44 id
->base
= FRAME_FP (fi
);
50 frame_find_by_id (struct frame_id id
)
52 struct frame_info
*frame
;
54 /* ZERO denotes the null frame, let the caller decide what to do
55 about it. Should it instead return get_current_frame()? */
56 if (id
.base
== 0 && id
.pc
== 0)
59 for (frame
= get_current_frame ();
61 frame
= get_prev_frame (frame
))
63 if (INNER_THAN (FRAME_FP (frame
), id
.base
))
64 /* ``inner/current < frame < id.base''. Keep looking along
67 if (INNER_THAN (id
.base
, FRAME_FP (frame
)))
68 /* ``inner/current < id.base < frame''. Oops, gone past it.
71 /* FIXME: cagney/2002-04-21: This isn't sufficient. It should
72 use id.pc to check that the two frames belong to the same
73 function. Otherwise we'll do things like match dummy frames
74 or mis-match frameless functions. However, until someone
75 notices, stick with the existing behavour. */
81 /* FIND_SAVED_REGISTER ()
83 Return the address in which frame FRAME's value of register REGNUM
84 has been saved in memory. Or return zero if it has not been saved.
85 If REGNUM specifies the SP, the value we return is actually
86 the SP value, not an address where it was saved. */
89 find_saved_register (struct frame_info
*frame
, int regnum
)
91 register struct frame_info
*frame1
= NULL
;
92 register CORE_ADDR addr
= 0;
94 if (frame
== NULL
) /* No regs saved if want current frame */
97 /* Note that this next routine assumes that registers used in
98 frame x will be saved only in the frame that x calls and
99 frames interior to it. This is not true on the sparc, but the
100 above macro takes care of it, so we should be all right. */
104 frame1
= get_next_frame (frame
);
108 FRAME_INIT_SAVED_REGS (frame1
);
109 if (frame1
->saved_regs
[regnum
])
110 addr
= frame1
->saved_regs
[regnum
];
117 frame_register_unwind (struct frame_info
*frame
, int regnum
,
118 int *optimizedp
, enum lval_type
*lvalp
,
119 CORE_ADDR
*addrp
, int *realnump
, void *bufferp
)
121 struct frame_unwind_cache
*cache
;
123 /* Require all but BUFFERP to be valid. A NULL BUFFERP indicates
124 that the value proper does not need to be fetched. */
125 gdb_assert (optimizedp
!= NULL
);
126 gdb_assert (lvalp
!= NULL
);
127 gdb_assert (addrp
!= NULL
);
128 gdb_assert (realnump
!= NULL
);
129 /* gdb_assert (bufferp != NULL); */
131 /* NOTE: cagney/2002-04-14: It would be nice if, instead of a
132 special case, there was always an inner frame dedicated to the
133 hardware registers. Unfortunatly, there is too much unwind code
134 around that looks up/down the frame chain while making the
135 assumption that each frame level is using the same unwind code. */
139 /* We're in the inner-most frame, get the value direct from the
142 *lvalp
= lval_register
;
144 /* Should this code test ``register_cached (regnum) < 0'' and do
145 something like set realnum to -1 when the register isn't
149 read_register_gen (regnum
, bufferp
);
153 /* Ask this frame to unwind its register. */
154 frame
->register_unwind (frame
, &frame
->register_unwind_cache
, regnum
,
155 optimizedp
, lvalp
, addrp
, realnump
, bufferp
);
160 generic_unwind_get_saved_register (char *raw_buffer
,
163 struct frame_info
*frame
,
165 enum lval_type
*lvalp
)
170 enum lval_type lvalx
;
172 if (!target_has_registers
)
173 error ("No registers.");
175 /* Keep things simple, ensure that all the pointers (except valuep)
177 if (optimizedp
== NULL
)
178 optimizedp
= &optimizedx
;
184 /* Reached the the bottom (youngest, inner most) of the frame chain
185 (youngest, inner most) frame, go direct to the hardware register
186 cache (do not pass go, do not try to cache the value, ...). The
187 unwound value would have been cached in frame->next but that
188 doesn't exist. This doesn't matter as the hardware register
189 cache is stopping any unnecessary accesses to the target. */
191 /* NOTE: cagney/2002-04-14: It would be nice if, instead of a
192 special case, there was always an inner frame dedicated to the
193 hardware registers. Unfortunatly, there is too much unwind code
194 around that looks up/down the frame chain while making the
195 assumption that each frame level is using the same unwind code. */
198 frame_register_unwind (NULL
, regnum
, optimizedp
, lvalp
, addrp
, &realnumx
,
201 frame_register_unwind (frame
->next
, regnum
, optimizedp
, lvalp
, addrp
,
202 &realnumx
, raw_buffer
);
206 get_saved_register (char *raw_buffer
,
209 struct frame_info
*frame
,
211 enum lval_type
*lval
)
213 GET_SAVED_REGISTER (raw_buffer
, optimized
, addrp
, frame
, regnum
, lval
);
216 /* frame_register_read ()
218 Find and return the value of REGNUM for the specified stack frame.
219 The number of bytes copied is REGISTER_RAW_SIZE (REGNUM).
221 Returns 0 if the register value could not be found. */
224 frame_register_read (struct frame_info
*frame
, int regnum
, void *myaddr
)
227 get_saved_register (myaddr
, &optim
, (CORE_ADDR
*) NULL
, frame
,
228 regnum
, (enum lval_type
*) NULL
);
230 /* FIXME: cagney/2002-05-15: This test, is just bogus.
232 It indicates that the target failed to supply a value for a
233 register because it was "not available" at this time. Problem
234 is, the target still has the register and so get saved_register()
235 may be returning a value saved on the stack. */
237 if (register_cached (regnum
) < 0)
238 return 0; /* register value not available */
This page took 0.03427 seconds and 4 git commands to generate.