From Jimi X <jimix@watson.ibm.com>:
[deliverable/binutils-gdb.git] / gdb / frame.c
CommitLineData
d65fe839 1/* Cache and manage the values of registers for GDB, the GNU debugger.
96cb11df
AC
2
3 Copyright 1986, 1987, 1989, 1991, 1994, 1995, 1996, 1998, 2000,
4 2001, 2002 Free Software Foundation, Inc.
d65fe839
AC
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"
39f77062 27#include "inferior.h" /* for inferior_ptid */
4e052eda 28#include "regcache.h"
d65fe839
AC
29
30/* FIND_SAVED_REGISTER ()
31
32 Return the address in which frame FRAME's value of register REGNUM
33 has been saved in memory. Or return zero if it has not been saved.
34 If REGNUM specifies the SP, the value we return is actually
35 the SP value, not an address where it was saved. */
36
37CORE_ADDR
38find_saved_register (struct frame_info *frame, int regnum)
39{
40 register struct frame_info *frame1 = NULL;
41 register CORE_ADDR addr = 0;
42
43 if (frame == NULL) /* No regs saved if want current frame */
44 return 0;
45
46#ifdef HAVE_REGISTER_WINDOWS
47 /* We assume that a register in a register window will only be saved
48 in one place (since the name changes and/or disappears as you go
49 towards inner frames), so we only call get_frame_saved_regs on
50 the current frame. This is directly in contradiction to the
51 usage below, which assumes that registers used in a frame must be
52 saved in a lower (more interior) frame. This change is a result
53 of working on a register window machine; get_frame_saved_regs
54 always returns the registers saved within a frame, within the
55 context (register namespace) of that frame. */
56
57 /* However, note that we don't want this to return anything if
58 nothing is saved (if there's a frame inside of this one). Also,
59 callers to this routine asking for the stack pointer want the
60 stack pointer saved for *this* frame; this is returned from the
61 next frame. */
62
63 if (REGISTER_IN_WINDOW_P (regnum))
64 {
65 frame1 = get_next_frame (frame);
66 if (!frame1)
67 return 0; /* Registers of this frame are active. */
68
69 /* Get the SP from the next frame in; it will be this
70 current frame. */
71 if (regnum != SP_REGNUM)
72 frame1 = frame;
73
74 FRAME_INIT_SAVED_REGS (frame1);
75 return frame1->saved_regs[regnum]; /* ... which might be zero */
76 }
77#endif /* HAVE_REGISTER_WINDOWS */
78
79 /* Note that this next routine assumes that registers used in
80 frame x will be saved only in the frame that x calls and
81 frames interior to it. This is not true on the sparc, but the
82 above macro takes care of it, so we should be all right. */
83 while (1)
84 {
85 QUIT;
86 frame1 = get_prev_frame (frame1);
87 if (frame1 == 0 || frame1 == frame)
88 break;
89 FRAME_INIT_SAVED_REGS (frame1);
90 if (frame1->saved_regs[regnum])
91 addr = frame1->saved_regs[regnum];
92 }
93
94 return addr;
95}
96
97/* DEFAULT_GET_SAVED_REGISTER ()
98
99 Find register number REGNUM relative to FRAME and put its (raw,
100 target format) contents in *RAW_BUFFER. Set *OPTIMIZED if the
101 variable was optimized out (and thus can't be fetched). Set *LVAL
102 to lval_memory, lval_register, or not_lval, depending on whether
103 the value was fetched from memory, from a register, or in a strange
104 and non-modifiable way (e.g. a frame pointer which was calculated
105 rather than fetched). Set *ADDRP to the address, either in memory
106 on as a REGISTER_BYTE offset into the registers array.
107
108 Note that this implementation never sets *LVAL to not_lval. But
109 it can be replaced by defining GET_SAVED_REGISTER and supplying
110 your own.
111
112 The argument RAW_BUFFER must point to aligned memory. */
113
114static void
115default_get_saved_register (char *raw_buffer,
116 int *optimized,
117 CORE_ADDR *addrp,
118 struct frame_info *frame,
119 int regnum,
120 enum lval_type *lval)
121{
122 CORE_ADDR addr;
123
124 if (!target_has_registers)
125 error ("No registers.");
126
127 /* Normal systems don't optimize out things with register numbers. */
128 if (optimized != NULL)
129 *optimized = 0;
130 addr = find_saved_register (frame, regnum);
131 if (addr != 0)
132 {
133 if (lval != NULL)
134 *lval = lval_memory;
135 if (regnum == SP_REGNUM)
136 {
137 if (raw_buffer != NULL)
138 {
139 /* Put it back in target format. */
140 store_address (raw_buffer, REGISTER_RAW_SIZE (regnum),
141 (LONGEST) addr);
142 }
143 if (addrp != NULL)
144 *addrp = 0;
145 return;
146 }
147 if (raw_buffer != NULL)
148 target_read_memory (addr, raw_buffer, REGISTER_RAW_SIZE (regnum));
149 }
150 else
151 {
152 if (lval != NULL)
153 *lval = lval_register;
154 addr = REGISTER_BYTE (regnum);
155 if (raw_buffer != NULL)
156 read_register_gen (regnum, raw_buffer);
157 }
158 if (addrp != NULL)
159 *addrp = addr;
160}
161
162#if !defined (GET_SAVED_REGISTER)
163#define GET_SAVED_REGISTER(raw_buffer, optimized, addrp, frame, regnum, lval) \
164 default_get_saved_register(raw_buffer, optimized, addrp, frame, regnum, lval)
165#endif
166
167void
168get_saved_register (char *raw_buffer,
169 int *optimized,
170 CORE_ADDR *addrp,
171 struct frame_info *frame,
172 int regnum,
173 enum lval_type *lval)
174{
175 GET_SAVED_REGISTER (raw_buffer, optimized, addrp, frame, regnum, lval);
176}
177
178/* READ_RELATIVE_REGISTER_RAW_BYTES_FOR_FRAME
179
180 Copy the bytes of register REGNUM, relative to the input stack frame,
181 into our memory at MYADDR, in target byte order.
182 The number of bytes copied is REGISTER_RAW_SIZE (REGNUM).
183
184 Returns 1 if could not be read, 0 if could. */
185
d65fe839
AC
186static int
187read_relative_register_raw_bytes_for_frame (int regnum,
188 char *myaddr,
189 struct frame_info *frame)
190{
191 int optim;
d65fe839
AC
192 get_saved_register (myaddr, &optim, (CORE_ADDR *) NULL, frame,
193 regnum, (enum lval_type *) NULL);
194
195 if (register_cached (regnum) < 0)
196 return 1; /* register value not available */
197
198 return optim;
199}
200
201/* READ_RELATIVE_REGISTER_RAW_BYTES
202
203 Copy the bytes of register REGNUM, relative to the current stack
204 frame, into our memory at MYADDR, in target byte order.
205 The number of bytes copied is REGISTER_RAW_SIZE (REGNUM).
206
207 Returns 1 if could not be read, 0 if could. */
208
209int
210read_relative_register_raw_bytes (int regnum, char *myaddr)
211{
212 return read_relative_register_raw_bytes_for_frame (regnum, myaddr,
213 selected_frame);
214}
This page took 0.101389 seconds and 4 git commands to generate.