* frame.c (GET_SAVED_REGISTER): Delete macro definition.
[deliverable/binutils-gdb.git] / gdb / frame.c
1 /* 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
31 /* FIND_SAVED_REGISTER ()
32
33 Return the address in which frame FRAME's value of register REGNUM
34 has been saved in memory. Or return zero if it has not been saved.
35 If REGNUM specifies the SP, the value we return is actually
36 the SP value, not an address where it was saved. */
37
38 CORE_ADDR
39 find_saved_register (struct frame_info *frame, int regnum)
40 {
41 register struct frame_info *frame1 = NULL;
42 register CORE_ADDR addr = 0;
43
44 if (frame == NULL) /* No regs saved if want current frame */
45 return 0;
46
47 /* Note that this next routine assumes that registers used in
48 frame x will be saved only in the frame that x calls and
49 frames interior to it. This is not true on the sparc, but the
50 above macro takes care of it, so we should be all right. */
51 while (1)
52 {
53 QUIT;
54 frame1 = get_next_frame (frame);
55 if (frame1 == 0)
56 break;
57 frame = frame1;
58 FRAME_INIT_SAVED_REGS (frame1);
59 if (frame1->saved_regs[regnum])
60 addr = frame1->saved_regs[regnum];
61 }
62
63 return addr;
64 }
65
66 void
67 frame_register_unwind (struct frame_info *frame, int regnum,
68 int *optimizedp, enum lval_type *lvalp,
69 CORE_ADDR *addrp, int *realnump, void *bufferp)
70 {
71 struct frame_unwind_cache *cache;
72
73 /* Require all but BUFFERP to be valid. A NULL BUFFERP indicates
74 that the value proper does not need to be fetched. */
75 gdb_assert (optimizedp != NULL);
76 gdb_assert (lvalp != NULL);
77 gdb_assert (addrp != NULL);
78 gdb_assert (realnump != NULL);
79 /* gdb_assert (bufferp != NULL); */
80
81 /* NOTE: cagney/2002-04-14: It would be nice if, instead of a
82 special case, there was always an inner frame dedicated to the
83 hardware registers. Unfortunatly, there is too much unwind code
84 around that looks up/down the frame chain while making the
85 assumption that each frame level is using the same unwind code. */
86
87 if (frame == NULL)
88 {
89 /* We're in the inner-most frame, get the value direct from the
90 register cache. */
91 *optimizedp = 0;
92 *lvalp = lval_register;
93 *addrp = 0;
94 /* Should this code test ``register_cached (regnum) < 0'' and do
95 something like set realnum to -1 when the register isn't
96 available? */
97 *realnump = regnum;
98 if (bufferp)
99 read_register_gen (regnum, bufferp);
100 return;
101 }
102
103 /* Ask this frame to unwind its register. */
104 frame->register_unwind (frame, &frame->register_unwind_cache, regnum,
105 optimizedp, lvalp, addrp, realnump, bufferp);
106 }
107
108
109 void
110 generic_unwind_get_saved_register (char *raw_buffer,
111 int *optimizedp,
112 CORE_ADDR *addrp,
113 struct frame_info *frame,
114 int regnum,
115 enum lval_type *lvalp)
116 {
117 int optimizedx;
118 CORE_ADDR addrx;
119 int realnumx;
120 enum lval_type lvalx;
121
122 if (!target_has_registers)
123 error ("No registers.");
124
125 /* Keep things simple, ensure that all the pointers (except valuep)
126 are non NULL. */
127 if (optimizedp == NULL)
128 optimizedp = &optimizedx;
129 if (lvalp == NULL)
130 lvalp = &lvalx;
131 if (addrp == NULL)
132 addrp = &addrx;
133
134 /* Reached the the bottom (youngest, inner most) of the frame chain
135 (youngest, inner most) frame, go direct to the hardware register
136 cache (do not pass go, do not try to cache the value, ...). The
137 unwound value would have been cached in frame->next but that
138 doesn't exist. This doesn't matter as the hardware register
139 cache is stopping any unnecessary accesses to the target. */
140
141 /* NOTE: cagney/2002-04-14: It would be nice if, instead of a
142 special case, there was always an inner frame dedicated to the
143 hardware registers. Unfortunatly, there is too much unwind code
144 around that looks up/down the frame chain while making the
145 assumption that each frame level is using the same unwind code. */
146
147 if (frame == NULL)
148 frame_register_unwind (NULL, regnum, optimizedp, lvalp, addrp, &realnumx,
149 raw_buffer);
150 else
151 frame_register_unwind (frame->next, regnum, optimizedp, lvalp, addrp,
152 &realnumx, raw_buffer);
153 }
154
155 void
156 get_saved_register (char *raw_buffer,
157 int *optimized,
158 CORE_ADDR *addrp,
159 struct frame_info *frame,
160 int regnum,
161 enum lval_type *lval)
162 {
163 GET_SAVED_REGISTER (raw_buffer, optimized, addrp, frame, regnum, lval);
164 }
165
166 /* frame_register_read ()
167
168 Find and return the value of REGNUM for the specified stack frame.
169 The number of bytes copied is REGISTER_RAW_SIZE (REGNUM).
170
171 Returns 0 if the register value could not be found. */
172
173 int
174 frame_register_read (struct frame_info *frame, int regnum, void *myaddr)
175 {
176 int optim;
177 get_saved_register (myaddr, &optim, (CORE_ADDR *) NULL, frame,
178 regnum, (enum lval_type *) NULL);
179
180 /* FIXME: cagney/2002-05-15: This test, is just bogus.
181
182 It indicates that the target failed to supply a value for a
183 register because it was "not available" at this time. Problem
184 is, the target still has the register and so get saved_register()
185 may be returning a value saved on the stack. */
186
187 if (register_cached (regnum) < 0)
188 return 0; /* register value not available */
189
190 return !optim;
191 }
This page took 0.037948 seconds and 5 git commands to generate.