Commit | Line | Data |
---|---|---|
4f460812 | 1 | /* Cache and manage frames 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" |
4f460812 | 29 | #include "gdb_assert.h" |
d65fe839 | 30 | |
101dcfbe AC |
31 | /* Return a frame uniq ID that can be used to, later re-find the |
32 | frame. */ | |
33 | ||
34 | void | |
35 | get_frame_id (struct frame_info *fi, struct frame_id *id) | |
36 | { | |
37 | if (fi == NULL) | |
38 | { | |
39 | id->base = 0; | |
40 | id->pc = 0; | |
41 | } | |
42 | else | |
43 | { | |
44 | id->base = FRAME_FP (fi); | |
45 | id->pc = fi->pc; | |
46 | } | |
47 | } | |
48 | ||
49 | struct frame_info * | |
50 | frame_find_by_id (struct frame_id id) | |
51 | { | |
52 | struct frame_info *frame; | |
53 | ||
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) | |
57 | return NULL; | |
58 | ||
59 | for (frame = get_current_frame (); | |
60 | frame != NULL; | |
61 | frame = get_prev_frame (frame)) | |
62 | { | |
63 | if (INNER_THAN (FRAME_FP (frame), id.base)) | |
64 | /* ``inner/current < frame < id.base''. Keep looking along | |
65 | the frame chain. */ | |
66 | continue; | |
67 | if (INNER_THAN (id.base, FRAME_FP (frame))) | |
68 | /* ``inner/current < id.base < frame''. Oops, gone past it. | |
69 | Just give up. */ | |
70 | return NULL; | |
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. */ | |
76 | return frame; | |
77 | } | |
78 | return NULL; | |
79 | } | |
80 | ||
4f460812 AC |
81 | void |
82 | frame_register_unwind (struct frame_info *frame, int regnum, | |
83 | int *optimizedp, enum lval_type *lvalp, | |
84 | CORE_ADDR *addrp, int *realnump, void *bufferp) | |
85 | { | |
86 | struct frame_unwind_cache *cache; | |
87 | ||
88 | /* Require all but BUFFERP to be valid. A NULL BUFFERP indicates | |
89 | that the value proper does not need to be fetched. */ | |
90 | gdb_assert (optimizedp != NULL); | |
91 | gdb_assert (lvalp != NULL); | |
92 | gdb_assert (addrp != NULL); | |
93 | gdb_assert (realnump != NULL); | |
94 | /* gdb_assert (bufferp != NULL); */ | |
95 | ||
96 | /* NOTE: cagney/2002-04-14: It would be nice if, instead of a | |
97 | special case, there was always an inner frame dedicated to the | |
98 | hardware registers. Unfortunatly, there is too much unwind code | |
99 | around that looks up/down the frame chain while making the | |
100 | assumption that each frame level is using the same unwind code. */ | |
101 | ||
102 | if (frame == NULL) | |
103 | { | |
104 | /* We're in the inner-most frame, get the value direct from the | |
105 | register cache. */ | |
106 | *optimizedp = 0; | |
107 | *lvalp = lval_register; | |
fa5f27c7 AC |
108 | /* ULGH! Code uses the offset into the raw register byte array |
109 | as a way of identifying a register. */ | |
110 | *addrp = REGISTER_BYTE (regnum); | |
4f460812 AC |
111 | /* Should this code test ``register_cached (regnum) < 0'' and do |
112 | something like set realnum to -1 when the register isn't | |
113 | available? */ | |
114 | *realnump = regnum; | |
115 | if (bufferp) | |
116 | read_register_gen (regnum, bufferp); | |
117 | return; | |
118 | } | |
119 | ||
120 | /* Ask this frame to unwind its register. */ | |
121 | frame->register_unwind (frame, &frame->register_unwind_cache, regnum, | |
122 | optimizedp, lvalp, addrp, realnump, bufferp); | |
123 | } | |
124 | ||
125 | ||
126 | void | |
127 | generic_unwind_get_saved_register (char *raw_buffer, | |
128 | int *optimizedp, | |
129 | CORE_ADDR *addrp, | |
130 | struct frame_info *frame, | |
131 | int regnum, | |
132 | enum lval_type *lvalp) | |
133 | { | |
134 | int optimizedx; | |
135 | CORE_ADDR addrx; | |
136 | int realnumx; | |
137 | enum lval_type lvalx; | |
138 | ||
139 | if (!target_has_registers) | |
140 | error ("No registers."); | |
141 | ||
142 | /* Keep things simple, ensure that all the pointers (except valuep) | |
143 | are non NULL. */ | |
144 | if (optimizedp == NULL) | |
145 | optimizedp = &optimizedx; | |
146 | if (lvalp == NULL) | |
147 | lvalp = &lvalx; | |
148 | if (addrp == NULL) | |
149 | addrp = &addrx; | |
150 | ||
151 | /* Reached the the bottom (youngest, inner most) of the frame chain | |
152 | (youngest, inner most) frame, go direct to the hardware register | |
153 | cache (do not pass go, do not try to cache the value, ...). The | |
154 | unwound value would have been cached in frame->next but that | |
155 | doesn't exist. This doesn't matter as the hardware register | |
156 | cache is stopping any unnecessary accesses to the target. */ | |
157 | ||
158 | /* NOTE: cagney/2002-04-14: It would be nice if, instead of a | |
159 | special case, there was always an inner frame dedicated to the | |
160 | hardware registers. Unfortunatly, there is too much unwind code | |
161 | around that looks up/down the frame chain while making the | |
162 | assumption that each frame level is using the same unwind code. */ | |
163 | ||
164 | if (frame == NULL) | |
165 | frame_register_unwind (NULL, regnum, optimizedp, lvalp, addrp, &realnumx, | |
166 | raw_buffer); | |
167 | else | |
168 | frame_register_unwind (frame->next, regnum, optimizedp, lvalp, addrp, | |
169 | &realnumx, raw_buffer); | |
170 | } | |
171 | ||
d65fe839 AC |
172 | void |
173 | get_saved_register (char *raw_buffer, | |
174 | int *optimized, | |
175 | CORE_ADDR *addrp, | |
176 | struct frame_info *frame, | |
177 | int regnum, | |
178 | enum lval_type *lval) | |
179 | { | |
180 | GET_SAVED_REGISTER (raw_buffer, optimized, addrp, frame, regnum, lval); | |
181 | } | |
182 | ||
cda5a58a | 183 | /* frame_register_read () |
d65fe839 | 184 | |
cda5a58a | 185 | Find and return the value of REGNUM for the specified stack frame. |
d65fe839 AC |
186 | The number of bytes copied is REGISTER_RAW_SIZE (REGNUM). |
187 | ||
cda5a58a | 188 | Returns 0 if the register value could not be found. */ |
d65fe839 | 189 | |
cda5a58a AC |
190 | int |
191 | frame_register_read (struct frame_info *frame, int regnum, void *myaddr) | |
d65fe839 AC |
192 | { |
193 | int optim; | |
d65fe839 AC |
194 | get_saved_register (myaddr, &optim, (CORE_ADDR *) NULL, frame, |
195 | regnum, (enum lval_type *) NULL); | |
196 | ||
c97dcfc7 AC |
197 | /* FIXME: cagney/2002-05-15: This test, is just bogus. |
198 | ||
199 | It indicates that the target failed to supply a value for a | |
200 | register because it was "not available" at this time. Problem | |
201 | is, the target still has the register and so get saved_register() | |
202 | may be returning a value saved on the stack. */ | |
203 | ||
d65fe839 | 204 | if (register_cached (regnum) < 0) |
cda5a58a | 205 | return 0; /* register value not available */ |
d65fe839 | 206 | |
cda5a58a | 207 | return !optim; |
d65fe839 | 208 | } |