]>
Commit | Line | Data |
---|---|---|
32178cab | 1 | /* Cache and manage the values of registers for GDB, the GNU debugger. |
3fadccb3 AC |
2 | |
3 | Copyright 1986, 1987, 1989, 1991, 1994, 1995, 1996, 1998, 2000, | |
4 | 2001, 2002 Free Software Foundation, Inc. | |
32178cab MS |
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" | |
32178cab MS |
24 | #include "inferior.h" |
25 | #include "target.h" | |
26 | #include "gdbarch.h" | |
705152c5 | 27 | #include "gdbcmd.h" |
4e052eda | 28 | #include "regcache.h" |
b59ff9d5 | 29 | #include "reggroups.h" |
61a0eb5b | 30 | #include "gdb_assert.h" |
b66d6d2e | 31 | #include "gdb_string.h" |
af030b9a | 32 | #include "gdbcmd.h" /* For maintenanceprintlist. */ |
32178cab MS |
33 | |
34 | /* | |
35 | * DATA STRUCTURE | |
36 | * | |
37 | * Here is the actual register cache. | |
38 | */ | |
39 | ||
3fadccb3 AC |
40 | /* Per-architecture object describing the layout of a register cache. |
41 | Computed once when the architecture is created */ | |
42 | ||
43 | struct gdbarch_data *regcache_descr_handle; | |
44 | ||
45 | struct regcache_descr | |
46 | { | |
47 | /* The architecture this descriptor belongs to. */ | |
48 | struct gdbarch *gdbarch; | |
49 | ||
50 | /* Is this a ``legacy'' register cache? Such caches reserve space | |
51 | for raw and pseudo registers and allow access to both. */ | |
52 | int legacy_p; | |
53 | ||
bb1db049 AC |
54 | /* The raw register cache. Each raw (or hard) register is supplied |
55 | by the target interface. The raw cache should not contain | |
56 | redundant information - if the PC is constructed from two | |
57 | registers then those regigisters and not the PC lives in the raw | |
58 | cache. */ | |
3fadccb3 AC |
59 | int nr_raw_registers; |
60 | long sizeof_raw_registers; | |
61 | long sizeof_raw_register_valid_p; | |
62 | ||
d138e37a AC |
63 | /* The cooked register space. Each cooked register in the range |
64 | [0..NR_RAW_REGISTERS) is direct-mapped onto the corresponding raw | |
65 | register. The remaining [NR_RAW_REGISTERS | |
66 | .. NR_COOKED_REGISTERS) (a.k.a. pseudo regiters) are mapped onto | |
67 | both raw registers and memory by the architecture methods | |
68 | gdbarch_register_read and gdbarch_register_write. */ | |
69 | int nr_cooked_registers; | |
067df2e5 AC |
70 | long sizeof_cooked_registers; |
71 | long sizeof_cooked_register_valid_p; | |
d138e37a AC |
72 | |
73 | /* Offset and size (in 8 bit bytes), of reach register in the | |
74 | register cache. All registers (including those in the range | |
75 | [NR_RAW_REGISTERS .. NR_COOKED_REGISTERS) are given an offset. | |
76 | Assigning all registers an offset makes it possible to keep | |
77 | legacy code, such as that found in read_register_bytes() and | |
78 | write_register_bytes() working. */ | |
3fadccb3 | 79 | long *register_offset; |
3fadccb3 | 80 | long *sizeof_register; |
3fadccb3 | 81 | |
bb425013 AC |
82 | /* Cached table containing the type of each register. */ |
83 | struct type **register_type; | |
3fadccb3 AC |
84 | }; |
85 | ||
b9362cc7 | 86 | static void |
bb425013 AC |
87 | init_legacy_regcache_descr (struct gdbarch *gdbarch, |
88 | struct regcache_descr *descr) | |
3fadccb3 AC |
89 | { |
90 | int i; | |
3fadccb3 AC |
91 | /* FIXME: cagney/2002-05-11: gdbarch_data() should take that |
92 | ``gdbarch'' as a parameter. */ | |
93 | gdb_assert (gdbarch != NULL); | |
94 | ||
067df2e5 AC |
95 | /* Compute the offset of each register. Legacy architectures define |
96 | REGISTER_BYTE() so use that. */ | |
97 | /* FIXME: cagney/2002-11-07: Instead of using REGISTER_BYTE() this | |
98 | code should, as is done in init_regcache_descr(), compute the | |
99 | offets at runtime. This currently isn't possible as some ISAs | |
100 | define overlapping register regions - see the mess in | |
101 | read_register_bytes() and write_register_bytes() registers. */ | |
d138e37a AC |
102 | descr->sizeof_register = XCALLOC (descr->nr_cooked_registers, long); |
103 | descr->register_offset = XCALLOC (descr->nr_cooked_registers, long); | |
d138e37a | 104 | for (i = 0; i < descr->nr_cooked_registers; i++) |
3fadccb3 | 105 | { |
067df2e5 AC |
106 | /* FIXME: cagney/2001-12-04: This code shouldn't need to use |
107 | REGISTER_BYTE(). Unfortunatly, legacy code likes to lay the | |
108 | buffer out so that certain registers just happen to overlap. | |
109 | Ulgh! New targets use gdbarch's register read/write and | |
110 | entirely avoid this uglyness. */ | |
3fadccb3 AC |
111 | descr->register_offset[i] = REGISTER_BYTE (i); |
112 | descr->sizeof_register[i] = REGISTER_RAW_SIZE (i); | |
123a958e AC |
113 | gdb_assert (MAX_REGISTER_SIZE >= REGISTER_RAW_SIZE (i)); |
114 | gdb_assert (MAX_REGISTER_SIZE >= REGISTER_VIRTUAL_SIZE (i)); | |
3fadccb3 AC |
115 | } |
116 | ||
067df2e5 | 117 | /* Compute the real size of the register buffer. Start out by |
b8b527c5 AC |
118 | trusting DEPRECATED_REGISTER_BYTES, but then adjust it upwards |
119 | should that be found to not be sufficient. */ | |
120 | /* FIXME: cagney/2002-11-05: Instead of using the macro | |
121 | DEPRECATED_REGISTER_BYTES, this code should, as is done in | |
122 | init_regcache_descr(), compute the total number of register bytes | |
123 | using the accumulated offsets. */ | |
124 | descr->sizeof_cooked_registers = DEPRECATED_REGISTER_BYTES; /* OK */ | |
d138e37a | 125 | for (i = 0; i < descr->nr_cooked_registers; i++) |
3fadccb3 AC |
126 | { |
127 | long regend; | |
128 | /* Keep extending the buffer so that there is always enough | |
129 | space for all registers. The comparison is necessary since | |
130 | legacy code is free to put registers in random places in the | |
131 | buffer separated by holes. Once REGISTER_BYTE() is killed | |
132 | this can be greatly simplified. */ | |
3fadccb3 | 133 | regend = descr->register_offset[i] + descr->sizeof_register[i]; |
067df2e5 AC |
134 | if (descr->sizeof_cooked_registers < regend) |
135 | descr->sizeof_cooked_registers = regend; | |
3fadccb3 | 136 | } |
067df2e5 AC |
137 | /* FIXME: cagney/2002-05-11: Shouldn't be including pseudo-registers |
138 | in the register cache. Unfortunatly some architectures still | |
139 | rely on this and the pseudo_register_write() method. */ | |
140 | descr->sizeof_raw_registers = descr->sizeof_cooked_registers; | |
3fadccb3 AC |
141 | } |
142 | ||
143 | static void * | |
144 | init_regcache_descr (struct gdbarch *gdbarch) | |
145 | { | |
146 | int i; | |
147 | struct regcache_descr *descr; | |
148 | gdb_assert (gdbarch != NULL); | |
149 | ||
bb425013 AC |
150 | /* Create an initial, zero filled, table. */ |
151 | descr = XCALLOC (1, struct regcache_descr); | |
3fadccb3 | 152 | descr->gdbarch = gdbarch; |
3fadccb3 | 153 | |
d138e37a AC |
154 | /* Total size of the register space. The raw registers are mapped |
155 | directly onto the raw register cache while the pseudo's are | |
3fadccb3 | 156 | either mapped onto raw-registers or memory. */ |
d138e37a | 157 | descr->nr_cooked_registers = NUM_REGS + NUM_PSEUDO_REGS; |
067df2e5 | 158 | descr->sizeof_cooked_register_valid_p = NUM_REGS + NUM_PSEUDO_REGS; |
3fadccb3 | 159 | |
bb425013 AC |
160 | /* Fill in a table of register types. */ |
161 | descr->register_type = XCALLOC (descr->nr_cooked_registers, | |
162 | struct type *); | |
163 | for (i = 0; i < descr->nr_cooked_registers; i++) | |
164 | { | |
35cac7cf AC |
165 | if (gdbarch_register_type_p (gdbarch)) |
166 | { | |
167 | gdb_assert (!REGISTER_VIRTUAL_TYPE_P ()); /* OK */ | |
168 | descr->register_type[i] = gdbarch_register_type (gdbarch, i); | |
169 | } | |
170 | else | |
171 | descr->register_type[i] = REGISTER_VIRTUAL_TYPE (i); /* OK */ | |
bb425013 AC |
172 | } |
173 | ||
bb1db049 AC |
174 | /* Construct a strictly RAW register cache. Don't allow pseudo's |
175 | into the register cache. */ | |
176 | descr->nr_raw_registers = NUM_REGS; | |
177 | ||
178 | /* FIXME: cagney/2002-08-13: Overallocate the register_valid_p | |
179 | array. This pretects GDB from erant code that accesses elements | |
180 | of the global register_valid_p[] array in the range [NUM_REGS | |
181 | .. NUM_REGS + NUM_PSEUDO_REGS). */ | |
182 | descr->sizeof_raw_register_valid_p = descr->sizeof_cooked_register_valid_p; | |
183 | ||
bb425013 AC |
184 | /* If an old style architecture, fill in the remainder of the |
185 | register cache descriptor using the register macros. */ | |
dadd712e AC |
186 | /* NOTE: cagney/2003-06-29: If either of REGISTER_BYTE or |
187 | REGISTER_RAW_SIZE are still present, things are most likely | |
188 | totally screwed. Ex: an architecture with raw register sizes | |
189 | smaller than what REGISTER_BYTE indicates; non monotonic | |
190 | REGISTER_BYTE values. For GDB 6 check for these nasty methods | |
191 | and fall back to legacy code when present. Sigh! */ | |
192 | if ((!gdbarch_pseudo_register_read_p (gdbarch) | |
193 | && !gdbarch_pseudo_register_write_p (gdbarch) | |
194 | && !gdbarch_register_type_p (gdbarch)) | |
195 | || REGISTER_BYTE_P () || REGISTER_RAW_SIZE_P ()) | |
bb425013 AC |
196 | { |
197 | descr->legacy_p = 1; | |
198 | init_legacy_regcache_descr (gdbarch, descr); | |
199 | return descr; | |
200 | } | |
201 | ||
067df2e5 | 202 | /* Lay out the register cache. |
3fadccb3 | 203 | |
bb425013 AC |
204 | NOTE: cagney/2002-05-22: Only register_type() is used when |
205 | constructing the register cache. It is assumed that the | |
206 | register's raw size, virtual size and type length are all the | |
207 | same. */ | |
3fadccb3 AC |
208 | |
209 | { | |
210 | long offset = 0; | |
d138e37a AC |
211 | descr->sizeof_register = XCALLOC (descr->nr_cooked_registers, long); |
212 | descr->register_offset = XCALLOC (descr->nr_cooked_registers, long); | |
d138e37a | 213 | for (i = 0; i < descr->nr_cooked_registers; i++) |
3fadccb3 | 214 | { |
bb425013 | 215 | descr->sizeof_register[i] = TYPE_LENGTH (descr->register_type[i]); |
3fadccb3 AC |
216 | descr->register_offset[i] = offset; |
217 | offset += descr->sizeof_register[i]; | |
123a958e | 218 | gdb_assert (MAX_REGISTER_SIZE >= descr->sizeof_register[i]); |
3fadccb3 AC |
219 | } |
220 | /* Set the real size of the register cache buffer. */ | |
067df2e5 | 221 | descr->sizeof_cooked_registers = offset; |
3fadccb3 AC |
222 | } |
223 | ||
067df2e5 AC |
224 | /* FIXME: cagney/2002-05-22: Should only need to allocate space for |
225 | the raw registers. Unfortunatly some code still accesses the | |
226 | register array directly using the global registers[]. Until that | |
227 | code has been purged, play safe and over allocating the register | |
228 | buffer. Ulgh! */ | |
229 | descr->sizeof_raw_registers = descr->sizeof_cooked_registers; | |
230 | ||
46654a5b AC |
231 | /* Sanity check. Confirm that there is agreement between the |
232 | regcache and the target's redundant REGISTER_BYTE (new targets | |
233 | should not even be defining it). */ | |
d138e37a | 234 | for (i = 0; i < descr->nr_cooked_registers; i++) |
3fadccb3 | 235 | { |
46654a5b AC |
236 | if (REGISTER_BYTE_P ()) |
237 | gdb_assert (descr->register_offset[i] == REGISTER_BYTE (i)); | |
238 | #if 0 | |
3fadccb3 AC |
239 | gdb_assert (descr->sizeof_register[i] == REGISTER_RAW_SIZE (i)); |
240 | gdb_assert (descr->sizeof_register[i] == REGISTER_VIRTUAL_SIZE (i)); | |
46654a5b | 241 | #endif |
3fadccb3 | 242 | } |
b8b527c5 | 243 | /* gdb_assert (descr->sizeof_raw_registers == DEPRECATED_REGISTER_BYTES (i)); */ |
3fadccb3 AC |
244 | |
245 | return descr; | |
246 | } | |
247 | ||
248 | static struct regcache_descr * | |
249 | regcache_descr (struct gdbarch *gdbarch) | |
250 | { | |
251 | return gdbarch_data (gdbarch, regcache_descr_handle); | |
252 | } | |
253 | ||
254 | static void | |
255 | xfree_regcache_descr (struct gdbarch *gdbarch, void *ptr) | |
256 | { | |
257 | struct regcache_descr *descr = ptr; | |
258 | if (descr == NULL) | |
259 | return; | |
260 | xfree (descr->register_offset); | |
261 | xfree (descr->sizeof_register); | |
262 | descr->register_offset = NULL; | |
263 | descr->sizeof_register = NULL; | |
264 | xfree (descr); | |
265 | } | |
266 | ||
bb425013 AC |
267 | /* Utility functions returning useful register attributes stored in |
268 | the regcache descr. */ | |
269 | ||
270 | struct type * | |
271 | register_type (struct gdbarch *gdbarch, int regnum) | |
272 | { | |
273 | struct regcache_descr *descr = regcache_descr (gdbarch); | |
274 | gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers); | |
275 | return descr->register_type[regnum]; | |
276 | } | |
277 | ||
0ed04cce AC |
278 | /* Utility functions returning useful register attributes stored in |
279 | the regcache descr. */ | |
280 | ||
08a617da AC |
281 | int |
282 | register_size (struct gdbarch *gdbarch, int regnum) | |
283 | { | |
284 | struct regcache_descr *descr = regcache_descr (gdbarch); | |
285 | int size; | |
286 | gdb_assert (regnum >= 0 && regnum < (NUM_REGS + NUM_PSEUDO_REGS)); | |
287 | size = descr->sizeof_register[regnum]; | |
96a4ee76 AC |
288 | /* NB: The deprecated REGISTER_RAW_SIZE, if not provided, defaults |
289 | to the size of the register's type. */ | |
08a617da | 290 | gdb_assert (size == REGISTER_RAW_SIZE (regnum)); /* OK */ |
96a4ee76 AC |
291 | /* NB: Don't check the register's virtual size. It, in say the case |
292 | of the MIPS, may not match the raw size! */ | |
08a617da AC |
293 | return size; |
294 | } | |
295 | ||
3fadccb3 AC |
296 | /* The register cache for storing raw register values. */ |
297 | ||
298 | struct regcache | |
299 | { | |
300 | struct regcache_descr *descr; | |
51b1fe4e AC |
301 | /* The register buffers. A read-only register cache can hold the |
302 | full [0 .. NUM_REGS + NUM_PSEUDO_REGS) while a read/write | |
303 | register cache can only hold [0 .. NUM_REGS). */ | |
304 | char *registers; | |
305 | char *register_valid_p; | |
2d28509a AC |
306 | /* Is this a read-only cache? A read-only cache is used for saving |
307 | the target's register state (e.g, across an inferior function | |
308 | call or just before forcing a function return). A read-only | |
309 | cache can only be updated via the methods regcache_dup() and | |
310 | regcache_cpy(). The actual contents are determined by the | |
311 | reggroup_save and reggroup_restore methods. */ | |
312 | int readonly_p; | |
3fadccb3 AC |
313 | }; |
314 | ||
315 | struct regcache * | |
316 | regcache_xmalloc (struct gdbarch *gdbarch) | |
317 | { | |
318 | struct regcache_descr *descr; | |
319 | struct regcache *regcache; | |
320 | gdb_assert (gdbarch != NULL); | |
321 | descr = regcache_descr (gdbarch); | |
322 | regcache = XMALLOC (struct regcache); | |
323 | regcache->descr = descr; | |
51b1fe4e | 324 | regcache->registers |
3fadccb3 | 325 | = XCALLOC (descr->sizeof_raw_registers, char); |
51b1fe4e | 326 | regcache->register_valid_p |
3fadccb3 | 327 | = XCALLOC (descr->sizeof_raw_register_valid_p, char); |
2d28509a | 328 | regcache->readonly_p = 1; |
3fadccb3 AC |
329 | return regcache; |
330 | } | |
331 | ||
332 | void | |
333 | regcache_xfree (struct regcache *regcache) | |
334 | { | |
335 | if (regcache == NULL) | |
336 | return; | |
51b1fe4e AC |
337 | xfree (regcache->registers); |
338 | xfree (regcache->register_valid_p); | |
3fadccb3 AC |
339 | xfree (regcache); |
340 | } | |
341 | ||
b9362cc7 | 342 | static void |
36160dc4 AC |
343 | do_regcache_xfree (void *data) |
344 | { | |
345 | regcache_xfree (data); | |
346 | } | |
347 | ||
348 | struct cleanup * | |
349 | make_cleanup_regcache_xfree (struct regcache *regcache) | |
350 | { | |
351 | return make_cleanup (do_regcache_xfree, regcache); | |
352 | } | |
353 | ||
51b1fe4e AC |
354 | /* Return a pointer to register REGNUM's buffer cache. */ |
355 | ||
356 | static char * | |
357 | register_buffer (struct regcache *regcache, int regnum) | |
358 | { | |
359 | return regcache->registers + regcache->descr->register_offset[regnum]; | |
360 | } | |
361 | ||
2d28509a | 362 | void |
5602984a AC |
363 | regcache_save (struct regcache *dst, regcache_cooked_read_ftype *cooked_read, |
364 | void *src) | |
2d28509a AC |
365 | { |
366 | struct gdbarch *gdbarch = dst->descr->gdbarch; | |
123a958e | 367 | char buf[MAX_REGISTER_SIZE]; |
2d28509a | 368 | int regnum; |
2d28509a | 369 | /* The DST should be `read-only', if it wasn't then the save would |
5602984a | 370 | end up trying to write the register values back out to the |
2d28509a | 371 | target. */ |
2d28509a AC |
372 | gdb_assert (dst->readonly_p); |
373 | /* Clear the dest. */ | |
374 | memset (dst->registers, 0, dst->descr->sizeof_cooked_registers); | |
375 | memset (dst->register_valid_p, 0, dst->descr->sizeof_cooked_register_valid_p); | |
376 | /* Copy over any registers (identified by their membership in the | |
5602984a AC |
377 | save_reggroup) and mark them as valid. The full [0 .. NUM_REGS + |
378 | NUM_PSEUDO_REGS) range is checked since some architectures need | |
379 | to save/restore `cooked' registers that live in memory. */ | |
2d28509a AC |
380 | for (regnum = 0; regnum < dst->descr->nr_cooked_registers; regnum++) |
381 | { | |
382 | if (gdbarch_register_reggroup_p (gdbarch, regnum, save_reggroup)) | |
383 | { | |
5602984a AC |
384 | int valid = cooked_read (src, regnum, buf); |
385 | if (valid) | |
386 | { | |
387 | memcpy (register_buffer (dst, regnum), buf, | |
388 | register_size (gdbarch, regnum)); | |
389 | dst->register_valid_p[regnum] = 1; | |
390 | } | |
2d28509a AC |
391 | } |
392 | } | |
393 | } | |
394 | ||
395 | void | |
5602984a AC |
396 | regcache_restore (struct regcache *dst, |
397 | regcache_cooked_read_ftype *cooked_read, | |
398 | void *src) | |
2d28509a AC |
399 | { |
400 | struct gdbarch *gdbarch = dst->descr->gdbarch; | |
123a958e | 401 | char buf[MAX_REGISTER_SIZE]; |
2d28509a | 402 | int regnum; |
5602984a AC |
403 | /* The dst had better not be read-only. If it is, the `restore' |
404 | doesn't make much sense. */ | |
2d28509a | 405 | gdb_assert (!dst->readonly_p); |
2d28509a | 406 | /* Copy over any registers, being careful to only restore those that |
5602984a AC |
407 | were both saved and need to be restored. The full [0 .. NUM_REGS |
408 | + NUM_PSEUDO_REGS) range is checked since some architectures need | |
409 | to save/restore `cooked' registers that live in memory. */ | |
410 | for (regnum = 0; regnum < dst->descr->nr_cooked_registers; regnum++) | |
2d28509a | 411 | { |
5602984a | 412 | if (gdbarch_register_reggroup_p (gdbarch, regnum, restore_reggroup)) |
2d28509a | 413 | { |
5602984a AC |
414 | int valid = cooked_read (src, regnum, buf); |
415 | if (valid) | |
416 | regcache_cooked_write (dst, regnum, buf); | |
2d28509a AC |
417 | } |
418 | } | |
419 | } | |
420 | ||
5602984a AC |
421 | static int |
422 | do_cooked_read (void *src, int regnum, void *buf) | |
423 | { | |
424 | struct regcache *regcache = src; | |
6f4e5a41 | 425 | if (!regcache->register_valid_p[regnum] && regcache->readonly_p) |
5602984a AC |
426 | /* Don't even think about fetching a register from a read-only |
427 | cache when the register isn't yet valid. There isn't a target | |
428 | from which the register value can be fetched. */ | |
429 | return 0; | |
430 | regcache_cooked_read (regcache, regnum, buf); | |
431 | return 1; | |
432 | } | |
433 | ||
434 | ||
3fadccb3 AC |
435 | void |
436 | regcache_cpy (struct regcache *dst, struct regcache *src) | |
437 | { | |
438 | int i; | |
439 | char *buf; | |
440 | gdb_assert (src != NULL && dst != NULL); | |
441 | gdb_assert (src->descr->gdbarch == dst->descr->gdbarch); | |
442 | gdb_assert (src != dst); | |
2d28509a AC |
443 | gdb_assert (src->readonly_p || dst->readonly_p); |
444 | if (!src->readonly_p) | |
5602984a | 445 | regcache_save (dst, do_cooked_read, src); |
2d28509a | 446 | else if (!dst->readonly_p) |
5602984a | 447 | regcache_restore (dst, do_cooked_read, src); |
2d28509a AC |
448 | else |
449 | regcache_cpy_no_passthrough (dst, src); | |
3fadccb3 AC |
450 | } |
451 | ||
452 | void | |
453 | regcache_cpy_no_passthrough (struct regcache *dst, struct regcache *src) | |
454 | { | |
455 | int i; | |
456 | gdb_assert (src != NULL && dst != NULL); | |
457 | gdb_assert (src->descr->gdbarch == dst->descr->gdbarch); | |
458 | /* NOTE: cagney/2002-05-17: Don't let the caller do a no-passthrough | |
459 | move of data into the current_regcache(). Doing this would be | |
460 | silly - it would mean that valid_p would be completly invalid. */ | |
461 | gdb_assert (dst != current_regcache); | |
51b1fe4e AC |
462 | memcpy (dst->registers, src->registers, dst->descr->sizeof_raw_registers); |
463 | memcpy (dst->register_valid_p, src->register_valid_p, | |
3fadccb3 AC |
464 | dst->descr->sizeof_raw_register_valid_p); |
465 | } | |
466 | ||
467 | struct regcache * | |
468 | regcache_dup (struct regcache *src) | |
469 | { | |
470 | struct regcache *newbuf; | |
471 | gdb_assert (current_regcache != NULL); | |
472 | newbuf = regcache_xmalloc (src->descr->gdbarch); | |
473 | regcache_cpy (newbuf, src); | |
474 | return newbuf; | |
475 | } | |
476 | ||
477 | struct regcache * | |
478 | regcache_dup_no_passthrough (struct regcache *src) | |
479 | { | |
480 | struct regcache *newbuf; | |
481 | gdb_assert (current_regcache != NULL); | |
482 | newbuf = regcache_xmalloc (src->descr->gdbarch); | |
483 | regcache_cpy_no_passthrough (newbuf, src); | |
484 | return newbuf; | |
485 | } | |
486 | ||
487 | int | |
488 | regcache_valid_p (struct regcache *regcache, int regnum) | |
489 | { | |
490 | gdb_assert (regcache != NULL); | |
491 | gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers); | |
51b1fe4e | 492 | return regcache->register_valid_p[regnum]; |
3fadccb3 AC |
493 | } |
494 | ||
3fadccb3 AC |
495 | char * |
496 | deprecated_grub_regcache_for_registers (struct regcache *regcache) | |
497 | { | |
51b1fe4e | 498 | return regcache->registers; |
3fadccb3 AC |
499 | } |
500 | ||
3fadccb3 AC |
501 | /* Global structure containing the current regcache. */ |
502 | /* FIXME: cagney/2002-05-11: The two global arrays registers[] and | |
8262ee23 | 503 | deprecated_register_valid[] currently point into this structure. */ |
3fadccb3 AC |
504 | struct regcache *current_regcache; |
505 | ||
5ebd2499 | 506 | /* NOTE: this is a write-through cache. There is no "dirty" bit for |
32178cab MS |
507 | recording if the register values have been changed (eg. by the |
508 | user). Therefore all registers must be written back to the | |
509 | target when appropriate. */ | |
510 | ||
511 | /* REGISTERS contains the cached register values (in target byte order). */ | |
512 | ||
524d7c18 | 513 | char *deprecated_registers; |
32178cab | 514 | |
8262ee23 | 515 | /* DEPRECATED_REGISTER_VALID is 0 if the register needs to be fetched, |
32178cab MS |
516 | 1 if it has been fetched, and |
517 | -1 if the register value was not available. | |
c97dcfc7 AC |
518 | |
519 | "Not available" indicates that the target is not not able to supply | |
520 | the register at this state. The register may become available at a | |
521 | later time (after the next resume). This often occures when GDB is | |
522 | manipulating a target that contains only a snapshot of the entire | |
523 | system being debugged - some of the registers in such a system may | |
524 | not have been saved. */ | |
32178cab | 525 | |
8262ee23 | 526 | signed char *deprecated_register_valid; |
32178cab | 527 | |
39f77062 | 528 | /* The thread/process associated with the current set of registers. */ |
32178cab | 529 | |
39f77062 | 530 | static ptid_t registers_ptid; |
32178cab MS |
531 | |
532 | /* | |
533 | * FUNCTIONS: | |
534 | */ | |
535 | ||
536 | /* REGISTER_CACHED() | |
537 | ||
538 | Returns 0 if the value is not in the cache (needs fetch). | |
539 | >0 if the value is in the cache. | |
540 | <0 if the value is permanently unavailable (don't ask again). */ | |
541 | ||
542 | int | |
543 | register_cached (int regnum) | |
544 | { | |
8262ee23 | 545 | return deprecated_register_valid[regnum]; |
32178cab MS |
546 | } |
547 | ||
7302a204 ND |
548 | /* Record that REGNUM's value is cached if STATE is >0, uncached but |
549 | fetchable if STATE is 0, and uncached and unfetchable if STATE is <0. */ | |
550 | ||
551 | void | |
552 | set_register_cached (int regnum, int state) | |
553 | { | |
53826de9 AC |
554 | gdb_assert (regnum >= 0); |
555 | gdb_assert (regnum < current_regcache->descr->nr_raw_registers); | |
51b1fe4e | 556 | current_regcache->register_valid_p[regnum] = state; |
7302a204 ND |
557 | } |
558 | ||
559 | /* Return whether register REGNUM is a real register. */ | |
560 | ||
561 | static int | |
562 | real_register (int regnum) | |
563 | { | |
564 | return regnum >= 0 && regnum < NUM_REGS; | |
565 | } | |
566 | ||
32178cab MS |
567 | /* Low level examining and depositing of registers. |
568 | ||
569 | The caller is responsible for making sure that the inferior is | |
570 | stopped before calling the fetching routines, or it will get | |
571 | garbage. (a change from GDB version 3, in which the caller got the | |
572 | value from the last stop). */ | |
573 | ||
574 | /* REGISTERS_CHANGED () | |
575 | ||
576 | Indicate that registers may have changed, so invalidate the cache. */ | |
577 | ||
578 | void | |
579 | registers_changed (void) | |
580 | { | |
581 | int i; | |
32178cab | 582 | |
39f77062 | 583 | registers_ptid = pid_to_ptid (-1); |
32178cab MS |
584 | |
585 | /* Force cleanup of any alloca areas if using C alloca instead of | |
586 | a builtin alloca. This particular call is used to clean up | |
587 | areas allocated by low level target code which may build up | |
588 | during lengthy interactions between gdb and the target before | |
589 | gdb gives control to the user (ie watchpoints). */ | |
590 | alloca (0); | |
591 | ||
53826de9 | 592 | for (i = 0; i < current_regcache->descr->nr_raw_registers; i++) |
7302a204 | 593 | set_register_cached (i, 0); |
32178cab MS |
594 | |
595 | if (registers_changed_hook) | |
596 | registers_changed_hook (); | |
597 | } | |
598 | ||
2b9e5f3f | 599 | /* DEPRECATED_REGISTERS_FETCHED () |
32178cab MS |
600 | |
601 | Indicate that all registers have been fetched, so mark them all valid. */ | |
602 | ||
31e9866e AC |
603 | /* NOTE: cagney/2001-12-04: This function does not set valid on the |
604 | pseudo-register range since pseudo registers are always supplied | |
605 | using supply_register(). */ | |
606 | /* FIXME: cagney/2001-12-04: This function is DEPRECATED. The target | |
607 | code was blatting the registers[] array and then calling this. | |
608 | Since targets should only be using supply_register() the need for | |
609 | this function/hack is eliminated. */ | |
32178cab MS |
610 | |
611 | void | |
2b9e5f3f | 612 | deprecated_registers_fetched (void) |
32178cab MS |
613 | { |
614 | int i; | |
32178cab | 615 | |
a728f042 | 616 | for (i = 0; i < NUM_REGS; i++) |
7302a204 | 617 | set_register_cached (i, 1); |
fcdc5976 | 618 | /* Do not assume that the pseudo-regs have also been fetched. |
31e9866e | 619 | Fetching all real regs NEVER accounts for pseudo-regs. */ |
32178cab MS |
620 | } |
621 | ||
73937e03 AC |
622 | /* deprecated_read_register_bytes and deprecated_write_register_bytes |
623 | are generally a *BAD* idea. They are inefficient because they need | |
624 | to check for partial updates, which can only be done by scanning | |
625 | through all of the registers and seeing if the bytes that are being | |
626 | read/written fall inside of an invalid register. [The main reason | |
627 | this is necessary is that register sizes can vary, so a simple | |
628 | index won't suffice.] It is far better to call read_register_gen | |
629 | and write_register_gen if you want to get at the raw register | |
630 | contents, as it only takes a regnum as an argument, and therefore | |
631 | can't do a partial register update. | |
32178cab MS |
632 | |
633 | Prior to the recent fixes to check for partial updates, both read | |
73937e03 AC |
634 | and deprecated_write_register_bytes always checked to see if any |
635 | registers were stale, and then called target_fetch_registers (-1) | |
636 | to update the whole set. This caused really slowed things down for | |
637 | remote targets. */ | |
32178cab MS |
638 | |
639 | /* Copy INLEN bytes of consecutive data from registers | |
640 | starting with the INREGBYTE'th byte of register data | |
641 | into memory at MYADDR. */ | |
642 | ||
643 | void | |
73937e03 | 644 | deprecated_read_register_bytes (int in_start, char *in_buf, int in_len) |
32178cab | 645 | { |
61a0eb5b | 646 | int in_end = in_start + in_len; |
5ebd2499 | 647 | int regnum; |
d9d9c31f | 648 | char reg_buf[MAX_REGISTER_SIZE]; |
32178cab MS |
649 | |
650 | /* See if we are trying to read bytes from out-of-date registers. If so, | |
651 | update just those registers. */ | |
652 | ||
5ebd2499 | 653 | for (regnum = 0; regnum < NUM_REGS + NUM_PSEUDO_REGS; regnum++) |
32178cab | 654 | { |
61a0eb5b AC |
655 | int reg_start; |
656 | int reg_end; | |
657 | int reg_len; | |
658 | int start; | |
659 | int end; | |
660 | int byte; | |
32178cab | 661 | |
61a0eb5b AC |
662 | reg_start = REGISTER_BYTE (regnum); |
663 | reg_len = REGISTER_RAW_SIZE (regnum); | |
664 | reg_end = reg_start + reg_len; | |
32178cab | 665 | |
61a0eb5b | 666 | if (reg_end <= in_start || in_end <= reg_start) |
5ebd2499 | 667 | /* The range the user wants to read doesn't overlap with regnum. */ |
32178cab MS |
668 | continue; |
669 | ||
275f450c AC |
670 | if (REGISTER_NAME (regnum) != NULL && *REGISTER_NAME (regnum) != '\0') |
671 | /* Force the cache to fetch the entire register. */ | |
4caf0990 | 672 | deprecated_read_register_gen (regnum, reg_buf); |
275f450c AC |
673 | else |
674 | /* Legacy note: even though this register is ``invalid'' we | |
675 | still need to return something. It would appear that some | |
676 | code relies on apparent gaps in the register array also | |
677 | being returned. */ | |
678 | /* FIXME: cagney/2001-08-18: This is just silly. It defeats | |
679 | the entire register read/write flow of control. Must | |
680 | resist temptation to return 0xdeadbeef. */ | |
524d7c18 | 681 | memcpy (reg_buf, &deprecated_registers[reg_start], reg_len); |
32178cab | 682 | |
61a0eb5b AC |
683 | /* Legacy note: This function, for some reason, allows a NULL |
684 | input buffer. If the buffer is NULL, the registers are still | |
685 | fetched, just the final transfer is skipped. */ | |
686 | if (in_buf == NULL) | |
687 | continue; | |
688 | ||
689 | /* start = max (reg_start, in_start) */ | |
690 | if (reg_start > in_start) | |
691 | start = reg_start; | |
692 | else | |
693 | start = in_start; | |
694 | ||
695 | /* end = min (reg_end, in_end) */ | |
696 | if (reg_end < in_end) | |
697 | end = reg_end; | |
698 | else | |
699 | end = in_end; | |
700 | ||
701 | /* Transfer just the bytes common to both IN_BUF and REG_BUF */ | |
702 | for (byte = start; byte < end; byte++) | |
165cd47f | 703 | { |
61a0eb5b | 704 | in_buf[byte - in_start] = reg_buf[byte - reg_start]; |
165cd47f | 705 | } |
32178cab | 706 | } |
32178cab MS |
707 | } |
708 | ||
5ebd2499 ND |
709 | /* Read register REGNUM into memory at MYADDR, which must be large |
710 | enough for REGISTER_RAW_BYTES (REGNUM). Target byte-order. If the | |
32178cab MS |
711 | register is known to be the size of a CORE_ADDR or smaller, |
712 | read_register can be used instead. */ | |
713 | ||
61a0eb5b AC |
714 | static void |
715 | legacy_read_register_gen (int regnum, char *myaddr) | |
32178cab | 716 | { |
61a0eb5b | 717 | gdb_assert (regnum >= 0 && regnum < (NUM_REGS + NUM_PSEUDO_REGS)); |
39f77062 | 718 | if (! ptid_equal (registers_ptid, inferior_ptid)) |
32178cab MS |
719 | { |
720 | registers_changed (); | |
39f77062 | 721 | registers_ptid = inferior_ptid; |
32178cab MS |
722 | } |
723 | ||
7302a204 | 724 | if (!register_cached (regnum)) |
5c27f28a | 725 | target_fetch_registers (regnum); |
7302a204 | 726 | |
3fadccb3 | 727 | memcpy (myaddr, register_buffer (current_regcache, regnum), |
5ebd2499 | 728 | REGISTER_RAW_SIZE (regnum)); |
32178cab MS |
729 | } |
730 | ||
61a0eb5b | 731 | void |
1aaa5f99 | 732 | regcache_raw_read (struct regcache *regcache, int regnum, void *buf) |
61a0eb5b | 733 | { |
3fadccb3 AC |
734 | gdb_assert (regcache != NULL && buf != NULL); |
735 | gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers); | |
736 | if (regcache->descr->legacy_p | |
2d28509a | 737 | && !regcache->readonly_p) |
3fadccb3 AC |
738 | { |
739 | gdb_assert (regcache == current_regcache); | |
740 | /* For moment, just use underlying legacy code. Ulgh!!! This | |
741 | silently and very indirectly updates the regcache's regcache | |
8262ee23 | 742 | via the global deprecated_register_valid[]. */ |
3fadccb3 AC |
743 | legacy_read_register_gen (regnum, buf); |
744 | return; | |
745 | } | |
746 | /* Make certain that the register cache is up-to-date with respect | |
747 | to the current thread. This switching shouldn't be necessary | |
748 | only there is still only one target side register cache. Sigh! | |
749 | On the bright side, at least there is a regcache object. */ | |
2d28509a | 750 | if (!regcache->readonly_p) |
3fadccb3 AC |
751 | { |
752 | gdb_assert (regcache == current_regcache); | |
753 | if (! ptid_equal (registers_ptid, inferior_ptid)) | |
754 | { | |
755 | registers_changed (); | |
756 | registers_ptid = inferior_ptid; | |
757 | } | |
758 | if (!register_cached (regnum)) | |
5c27f28a | 759 | target_fetch_registers (regnum); |
3fadccb3 AC |
760 | } |
761 | /* Copy the value directly into the register cache. */ | |
51b1fe4e | 762 | memcpy (buf, register_buffer (regcache, regnum), |
3fadccb3 | 763 | regcache->descr->sizeof_register[regnum]); |
61a0eb5b AC |
764 | } |
765 | ||
28fc6740 AC |
766 | void |
767 | regcache_raw_read_signed (struct regcache *regcache, int regnum, LONGEST *val) | |
768 | { | |
769 | char *buf; | |
770 | gdb_assert (regcache != NULL); | |
771 | gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers); | |
772 | buf = alloca (regcache->descr->sizeof_register[regnum]); | |
773 | regcache_raw_read (regcache, regnum, buf); | |
774 | (*val) = extract_signed_integer (buf, | |
775 | regcache->descr->sizeof_register[regnum]); | |
776 | } | |
777 | ||
778 | void | |
779 | regcache_raw_read_unsigned (struct regcache *regcache, int regnum, | |
780 | ULONGEST *val) | |
781 | { | |
782 | char *buf; | |
783 | gdb_assert (regcache != NULL); | |
784 | gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers); | |
785 | buf = alloca (regcache->descr->sizeof_register[regnum]); | |
786 | regcache_raw_read (regcache, regnum, buf); | |
787 | (*val) = extract_unsigned_integer (buf, | |
788 | regcache->descr->sizeof_register[regnum]); | |
789 | } | |
790 | ||
c00dcbe9 MK |
791 | void |
792 | regcache_raw_write_signed (struct regcache *regcache, int regnum, LONGEST val) | |
793 | { | |
794 | void *buf; | |
795 | gdb_assert (regcache != NULL); | |
796 | gdb_assert (regnum >=0 && regnum < regcache->descr->nr_raw_registers); | |
797 | buf = alloca (regcache->descr->sizeof_register[regnum]); | |
798 | store_signed_integer (buf, regcache->descr->sizeof_register[regnum], val); | |
799 | regcache_raw_write (regcache, regnum, buf); | |
800 | } | |
801 | ||
802 | void | |
803 | regcache_raw_write_unsigned (struct regcache *regcache, int regnum, | |
804 | ULONGEST val) | |
805 | { | |
806 | void *buf; | |
807 | gdb_assert (regcache != NULL); | |
808 | gdb_assert (regnum >=0 && regnum < regcache->descr->nr_raw_registers); | |
809 | buf = alloca (regcache->descr->sizeof_register[regnum]); | |
810 | store_unsigned_integer (buf, regcache->descr->sizeof_register[regnum], val); | |
811 | regcache_raw_write (regcache, regnum, buf); | |
812 | } | |
813 | ||
61a0eb5b | 814 | void |
4caf0990 | 815 | deprecated_read_register_gen (int regnum, char *buf) |
61a0eb5b | 816 | { |
3fadccb3 AC |
817 | gdb_assert (current_regcache != NULL); |
818 | gdb_assert (current_regcache->descr->gdbarch == current_gdbarch); | |
819 | if (current_regcache->descr->legacy_p) | |
61a0eb5b AC |
820 | { |
821 | legacy_read_register_gen (regnum, buf); | |
822 | return; | |
823 | } | |
68365089 AC |
824 | regcache_cooked_read (current_regcache, regnum, buf); |
825 | } | |
826 | ||
827 | void | |
29e1842b | 828 | regcache_cooked_read (struct regcache *regcache, int regnum, void *buf) |
68365089 | 829 | { |
d138e37a | 830 | gdb_assert (regnum >= 0); |
68365089 AC |
831 | gdb_assert (regnum < regcache->descr->nr_cooked_registers); |
832 | if (regnum < regcache->descr->nr_raw_registers) | |
833 | regcache_raw_read (regcache, regnum, buf); | |
2d28509a AC |
834 | else if (regcache->readonly_p |
835 | && regnum < regcache->descr->nr_cooked_registers | |
836 | && regcache->register_valid_p[regnum]) | |
837 | /* Read-only register cache, perhaphs the cooked value was cached? */ | |
838 | memcpy (buf, register_buffer (regcache, regnum), | |
839 | regcache->descr->sizeof_register[regnum]); | |
d138e37a | 840 | else |
68365089 AC |
841 | gdbarch_pseudo_register_read (regcache->descr->gdbarch, regcache, |
842 | regnum, buf); | |
61a0eb5b AC |
843 | } |
844 | ||
a378f419 AC |
845 | void |
846 | regcache_cooked_read_signed (struct regcache *regcache, int regnum, | |
847 | LONGEST *val) | |
848 | { | |
849 | char *buf; | |
850 | gdb_assert (regcache != NULL); | |
a66a9c23 | 851 | gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_cooked_registers); |
a378f419 AC |
852 | buf = alloca (regcache->descr->sizeof_register[regnum]); |
853 | regcache_cooked_read (regcache, regnum, buf); | |
854 | (*val) = extract_signed_integer (buf, | |
855 | regcache->descr->sizeof_register[regnum]); | |
856 | } | |
857 | ||
858 | void | |
859 | regcache_cooked_read_unsigned (struct regcache *regcache, int regnum, | |
860 | ULONGEST *val) | |
861 | { | |
862 | char *buf; | |
863 | gdb_assert (regcache != NULL); | |
a66a9c23 | 864 | gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_cooked_registers); |
a378f419 AC |
865 | buf = alloca (regcache->descr->sizeof_register[regnum]); |
866 | regcache_cooked_read (regcache, regnum, buf); | |
867 | (*val) = extract_unsigned_integer (buf, | |
868 | regcache->descr->sizeof_register[regnum]); | |
869 | } | |
870 | ||
a66a9c23 AC |
871 | void |
872 | regcache_cooked_write_signed (struct regcache *regcache, int regnum, | |
873 | LONGEST val) | |
874 | { | |
875 | void *buf; | |
876 | gdb_assert (regcache != NULL); | |
877 | gdb_assert (regnum >=0 && regnum < regcache->descr->nr_cooked_registers); | |
878 | buf = alloca (regcache->descr->sizeof_register[regnum]); | |
879 | store_signed_integer (buf, regcache->descr->sizeof_register[regnum], val); | |
880 | regcache_cooked_write (regcache, regnum, buf); | |
881 | } | |
882 | ||
883 | void | |
884 | regcache_cooked_write_unsigned (struct regcache *regcache, int regnum, | |
885 | ULONGEST val) | |
886 | { | |
887 | void *buf; | |
888 | gdb_assert (regcache != NULL); | |
889 | gdb_assert (regnum >=0 && regnum < regcache->descr->nr_cooked_registers); | |
890 | buf = alloca (regcache->descr->sizeof_register[regnum]); | |
891 | store_unsigned_integer (buf, regcache->descr->sizeof_register[regnum], val); | |
892 | regcache_cooked_write (regcache, regnum, buf); | |
893 | } | |
894 | ||
5ebd2499 ND |
895 | /* Write register REGNUM at MYADDR to the target. MYADDR points at |
896 | REGISTER_RAW_BYTES(REGNUM), which must be in target byte-order. */ | |
32178cab | 897 | |
61a0eb5b | 898 | static void |
1aaa5f99 | 899 | legacy_write_register_gen (int regnum, const void *myaddr) |
32178cab MS |
900 | { |
901 | int size; | |
61a0eb5b | 902 | gdb_assert (regnum >= 0 && regnum < (NUM_REGS + NUM_PSEUDO_REGS)); |
32178cab MS |
903 | |
904 | /* On the sparc, writing %g0 is a no-op, so we don't even want to | |
905 | change the registers array if something writes to this register. */ | |
5ebd2499 | 906 | if (CANNOT_STORE_REGISTER (regnum)) |
32178cab MS |
907 | return; |
908 | ||
39f77062 | 909 | if (! ptid_equal (registers_ptid, inferior_ptid)) |
32178cab MS |
910 | { |
911 | registers_changed (); | |
39f77062 | 912 | registers_ptid = inferior_ptid; |
32178cab MS |
913 | } |
914 | ||
5ebd2499 | 915 | size = REGISTER_RAW_SIZE (regnum); |
32178cab | 916 | |
7302a204 | 917 | if (real_register (regnum)) |
1297a2f0 MS |
918 | { |
919 | /* If we have a valid copy of the register, and new value == old | |
920 | value, then don't bother doing the actual store. */ | |
921 | if (register_cached (regnum) | |
3fadccb3 AC |
922 | && (memcmp (register_buffer (current_regcache, regnum), myaddr, size) |
923 | == 0)) | |
1297a2f0 MS |
924 | return; |
925 | else | |
926 | target_prepare_to_store (); | |
927 | } | |
32178cab | 928 | |
3fadccb3 | 929 | memcpy (register_buffer (current_regcache, regnum), myaddr, size); |
32178cab | 930 | |
7302a204 | 931 | set_register_cached (regnum, 1); |
5c27f28a | 932 | target_store_registers (regnum); |
32178cab MS |
933 | } |
934 | ||
61a0eb5b | 935 | void |
1aaa5f99 | 936 | regcache_raw_write (struct regcache *regcache, int regnum, const void *buf) |
61a0eb5b | 937 | { |
3fadccb3 AC |
938 | gdb_assert (regcache != NULL && buf != NULL); |
939 | gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers); | |
2d28509a | 940 | gdb_assert (!regcache->readonly_p); |
3fadccb3 | 941 | |
2d28509a | 942 | if (regcache->descr->legacy_p) |
3fadccb3 AC |
943 | { |
944 | /* For moment, just use underlying legacy code. Ulgh!!! This | |
945 | silently and very indirectly updates the regcache's buffers | |
8262ee23 | 946 | via the globals deprecated_register_valid[] and registers[]. */ |
3fadccb3 AC |
947 | gdb_assert (regcache == current_regcache); |
948 | legacy_write_register_gen (regnum, buf); | |
949 | return; | |
950 | } | |
951 | ||
952 | /* On the sparc, writing %g0 is a no-op, so we don't even want to | |
953 | change the registers array if something writes to this register. */ | |
954 | if (CANNOT_STORE_REGISTER (regnum)) | |
955 | return; | |
956 | ||
3fadccb3 AC |
957 | /* Make certain that the correct cache is selected. */ |
958 | gdb_assert (regcache == current_regcache); | |
959 | if (! ptid_equal (registers_ptid, inferior_ptid)) | |
960 | { | |
961 | registers_changed (); | |
962 | registers_ptid = inferior_ptid; | |
963 | } | |
964 | ||
965 | /* If we have a valid copy of the register, and new value == old | |
966 | value, then don't bother doing the actual store. */ | |
967 | if (regcache_valid_p (regcache, regnum) | |
968 | && (memcmp (register_buffer (regcache, regnum), buf, | |
969 | regcache->descr->sizeof_register[regnum]) == 0)) | |
970 | return; | |
971 | ||
972 | target_prepare_to_store (); | |
973 | memcpy (register_buffer (regcache, regnum), buf, | |
974 | regcache->descr->sizeof_register[regnum]); | |
51b1fe4e | 975 | regcache->register_valid_p[regnum] = 1; |
5c27f28a | 976 | target_store_registers (regnum); |
61a0eb5b AC |
977 | } |
978 | ||
979 | void | |
4caf0990 | 980 | deprecated_write_register_gen (int regnum, char *buf) |
61a0eb5b | 981 | { |
3fadccb3 AC |
982 | gdb_assert (current_regcache != NULL); |
983 | gdb_assert (current_regcache->descr->gdbarch == current_gdbarch); | |
984 | if (current_regcache->descr->legacy_p) | |
61a0eb5b AC |
985 | { |
986 | legacy_write_register_gen (regnum, buf); | |
987 | return; | |
988 | } | |
68365089 AC |
989 | regcache_cooked_write (current_regcache, regnum, buf); |
990 | } | |
991 | ||
992 | void | |
29e1842b | 993 | regcache_cooked_write (struct regcache *regcache, int regnum, const void *buf) |
68365089 | 994 | { |
d138e37a | 995 | gdb_assert (regnum >= 0); |
68365089 AC |
996 | gdb_assert (regnum < regcache->descr->nr_cooked_registers); |
997 | if (regnum < regcache->descr->nr_raw_registers) | |
998 | regcache_raw_write (regcache, regnum, buf); | |
d138e37a | 999 | else |
68365089 | 1000 | gdbarch_pseudo_register_write (regcache->descr->gdbarch, regcache, |
d8124050 | 1001 | regnum, buf); |
61a0eb5b AC |
1002 | } |
1003 | ||
32178cab MS |
1004 | /* Copy INLEN bytes of consecutive data from memory at MYADDR |
1005 | into registers starting with the MYREGSTART'th byte of register data. */ | |
1006 | ||
1007 | void | |
73937e03 | 1008 | deprecated_write_register_bytes (int myregstart, char *myaddr, int inlen) |
32178cab MS |
1009 | { |
1010 | int myregend = myregstart + inlen; | |
5ebd2499 | 1011 | int regnum; |
32178cab MS |
1012 | |
1013 | target_prepare_to_store (); | |
1014 | ||
1015 | /* Scan through the registers updating any that are covered by the | |
1016 | range myregstart<=>myregend using write_register_gen, which does | |
1017 | nice things like handling threads, and avoiding updates when the | |
1018 | new and old contents are the same. */ | |
1019 | ||
5ebd2499 | 1020 | for (regnum = 0; regnum < NUM_REGS + NUM_PSEUDO_REGS; regnum++) |
32178cab MS |
1021 | { |
1022 | int regstart, regend; | |
1023 | ||
5ebd2499 ND |
1024 | regstart = REGISTER_BYTE (regnum); |
1025 | regend = regstart + REGISTER_RAW_SIZE (regnum); | |
32178cab MS |
1026 | |
1027 | /* Is this register completely outside the range the user is writing? */ | |
1028 | if (myregend <= regstart || regend <= myregstart) | |
1029 | /* do nothing */ ; | |
1030 | ||
1031 | /* Is this register completely within the range the user is writing? */ | |
1032 | else if (myregstart <= regstart && regend <= myregend) | |
4caf0990 | 1033 | deprecated_write_register_gen (regnum, myaddr + (regstart - myregstart)); |
32178cab MS |
1034 | |
1035 | /* The register partially overlaps the range being written. */ | |
1036 | else | |
1037 | { | |
d9d9c31f | 1038 | char regbuf[MAX_REGISTER_SIZE]; |
32178cab MS |
1039 | /* What's the overlap between this register's bytes and |
1040 | those the caller wants to write? */ | |
1041 | int overlapstart = max (regstart, myregstart); | |
1042 | int overlapend = min (regend, myregend); | |
1043 | ||
1044 | /* We may be doing a partial update of an invalid register. | |
1045 | Update it from the target before scribbling on it. */ | |
4caf0990 | 1046 | deprecated_read_register_gen (regnum, regbuf); |
32178cab | 1047 | |
524d7c18 | 1048 | memcpy (&deprecated_registers[overlapstart], |
32178cab MS |
1049 | myaddr + (overlapstart - myregstart), |
1050 | overlapend - overlapstart); | |
1051 | ||
5c27f28a | 1052 | target_store_registers (regnum); |
32178cab MS |
1053 | } |
1054 | } | |
1055 | } | |
1056 | ||
06c0b04e AC |
1057 | /* Perform a partial register transfer using a read, modify, write |
1058 | operation. */ | |
1059 | ||
1060 | typedef void (regcache_read_ftype) (struct regcache *regcache, int regnum, | |
1061 | void *buf); | |
1062 | typedef void (regcache_write_ftype) (struct regcache *regcache, int regnum, | |
1063 | const void *buf); | |
1064 | ||
b9362cc7 | 1065 | static void |
06c0b04e AC |
1066 | regcache_xfer_part (struct regcache *regcache, int regnum, |
1067 | int offset, int len, void *in, const void *out, | |
1068 | regcache_read_ftype *read, regcache_write_ftype *write) | |
1069 | { | |
1070 | struct regcache_descr *descr = regcache->descr; | |
123a958e | 1071 | bfd_byte reg[MAX_REGISTER_SIZE]; |
06c0b04e AC |
1072 | gdb_assert (offset >= 0 && offset <= descr->sizeof_register[regnum]); |
1073 | gdb_assert (len >= 0 && offset + len <= descr->sizeof_register[regnum]); | |
1074 | /* Something to do? */ | |
1075 | if (offset + len == 0) | |
1076 | return; | |
1077 | /* Read (when needed) ... */ | |
1078 | if (in != NULL | |
1079 | || offset > 0 | |
1080 | || offset + len < descr->sizeof_register[regnum]) | |
1081 | { | |
1082 | gdb_assert (read != NULL); | |
1083 | read (regcache, regnum, reg); | |
1084 | } | |
1085 | /* ... modify ... */ | |
1086 | if (in != NULL) | |
1087 | memcpy (in, reg + offset, len); | |
1088 | if (out != NULL) | |
1089 | memcpy (reg + offset, out, len); | |
1090 | /* ... write (when needed). */ | |
1091 | if (out != NULL) | |
1092 | { | |
1093 | gdb_assert (write != NULL); | |
1094 | write (regcache, regnum, reg); | |
1095 | } | |
1096 | } | |
1097 | ||
1098 | void | |
1099 | regcache_raw_read_part (struct regcache *regcache, int regnum, | |
1100 | int offset, int len, void *buf) | |
1101 | { | |
1102 | struct regcache_descr *descr = regcache->descr; | |
1103 | gdb_assert (regnum >= 0 && regnum < descr->nr_raw_registers); | |
1104 | regcache_xfer_part (regcache, regnum, offset, len, buf, NULL, | |
1105 | regcache_raw_read, regcache_raw_write); | |
1106 | } | |
1107 | ||
1108 | void | |
1109 | regcache_raw_write_part (struct regcache *regcache, int regnum, | |
1110 | int offset, int len, const void *buf) | |
1111 | { | |
1112 | struct regcache_descr *descr = regcache->descr; | |
1113 | gdb_assert (regnum >= 0 && regnum < descr->nr_raw_registers); | |
1114 | regcache_xfer_part (regcache, regnum, offset, len, NULL, buf, | |
1115 | regcache_raw_read, regcache_raw_write); | |
1116 | } | |
1117 | ||
1118 | void | |
1119 | regcache_cooked_read_part (struct regcache *regcache, int regnum, | |
1120 | int offset, int len, void *buf) | |
1121 | { | |
1122 | struct regcache_descr *descr = regcache->descr; | |
1123 | gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers); | |
1124 | regcache_xfer_part (regcache, regnum, offset, len, buf, NULL, | |
1125 | regcache_cooked_read, regcache_cooked_write); | |
1126 | } | |
1127 | ||
1128 | void | |
1129 | regcache_cooked_write_part (struct regcache *regcache, int regnum, | |
1130 | int offset, int len, const void *buf) | |
1131 | { | |
1132 | struct regcache_descr *descr = regcache->descr; | |
1133 | gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers); | |
1134 | regcache_xfer_part (regcache, regnum, offset, len, NULL, buf, | |
1135 | regcache_cooked_read, regcache_cooked_write); | |
1136 | } | |
32178cab | 1137 | |
d3b22ed5 AC |
1138 | /* Hack to keep code that view the register buffer as raw bytes |
1139 | working. */ | |
1140 | ||
1141 | int | |
1142 | register_offset_hack (struct gdbarch *gdbarch, int regnum) | |
1143 | { | |
1144 | struct regcache_descr *descr = regcache_descr (gdbarch); | |
1145 | gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers); | |
1146 | return descr->register_offset[regnum]; | |
1147 | } | |
1148 | ||
5ebd2499 | 1149 | /* Return the contents of register REGNUM as an unsigned integer. */ |
32178cab | 1150 | |
173155e8 | 1151 | ULONGEST |
5ebd2499 | 1152 | read_register (int regnum) |
32178cab | 1153 | { |
61a0eb5b | 1154 | char *buf = alloca (REGISTER_RAW_SIZE (regnum)); |
4caf0990 | 1155 | deprecated_read_register_gen (regnum, buf); |
61a0eb5b | 1156 | return (extract_unsigned_integer (buf, REGISTER_RAW_SIZE (regnum))); |
32178cab MS |
1157 | } |
1158 | ||
173155e8 | 1159 | ULONGEST |
39f77062 | 1160 | read_register_pid (int regnum, ptid_t ptid) |
32178cab | 1161 | { |
39f77062 | 1162 | ptid_t save_ptid; |
32178cab MS |
1163 | int save_pid; |
1164 | CORE_ADDR retval; | |
1165 | ||
39f77062 | 1166 | if (ptid_equal (ptid, inferior_ptid)) |
5ebd2499 | 1167 | return read_register (regnum); |
32178cab | 1168 | |
39f77062 | 1169 | save_ptid = inferior_ptid; |
32178cab | 1170 | |
39f77062 | 1171 | inferior_ptid = ptid; |
32178cab | 1172 | |
5ebd2499 | 1173 | retval = read_register (regnum); |
32178cab | 1174 | |
39f77062 | 1175 | inferior_ptid = save_ptid; |
32178cab MS |
1176 | |
1177 | return retval; | |
1178 | } | |
1179 | ||
5ebd2499 | 1180 | /* Store VALUE into the raw contents of register number REGNUM. */ |
32178cab MS |
1181 | |
1182 | void | |
5ebd2499 | 1183 | write_register (int regnum, LONGEST val) |
32178cab | 1184 | { |
61a0eb5b | 1185 | void *buf; |
32178cab | 1186 | int size; |
5ebd2499 | 1187 | size = REGISTER_RAW_SIZE (regnum); |
32178cab MS |
1188 | buf = alloca (size); |
1189 | store_signed_integer (buf, size, (LONGEST) val); | |
4caf0990 | 1190 | deprecated_write_register_gen (regnum, buf); |
32178cab MS |
1191 | } |
1192 | ||
1193 | void | |
39f77062 | 1194 | write_register_pid (int regnum, CORE_ADDR val, ptid_t ptid) |
32178cab | 1195 | { |
39f77062 | 1196 | ptid_t save_ptid; |
32178cab | 1197 | |
39f77062 | 1198 | if (ptid_equal (ptid, inferior_ptid)) |
32178cab | 1199 | { |
5ebd2499 | 1200 | write_register (regnum, val); |
32178cab MS |
1201 | return; |
1202 | } | |
1203 | ||
39f77062 | 1204 | save_ptid = inferior_ptid; |
32178cab | 1205 | |
39f77062 | 1206 | inferior_ptid = ptid; |
32178cab | 1207 | |
5ebd2499 | 1208 | write_register (regnum, val); |
32178cab | 1209 | |
39f77062 | 1210 | inferior_ptid = save_ptid; |
32178cab MS |
1211 | } |
1212 | ||
1213 | /* SUPPLY_REGISTER() | |
1214 | ||
5ebd2499 | 1215 | Record that register REGNUM contains VAL. This is used when the |
32178cab MS |
1216 | value is obtained from the inferior or core dump, so there is no |
1217 | need to store the value there. | |
1218 | ||
1219 | If VAL is a NULL pointer, then it's probably an unsupported register. | |
5ebd2499 | 1220 | We just set its value to all zeros. We might want to record this |
32178cab MS |
1221 | fact, and report it to the users of read_register and friends. */ |
1222 | ||
1223 | void | |
1aaa5f99 | 1224 | supply_register (int regnum, const void *val) |
32178cab MS |
1225 | { |
1226 | #if 1 | |
39f77062 | 1227 | if (! ptid_equal (registers_ptid, inferior_ptid)) |
32178cab MS |
1228 | { |
1229 | registers_changed (); | |
39f77062 | 1230 | registers_ptid = inferior_ptid; |
32178cab MS |
1231 | } |
1232 | #endif | |
1233 | ||
7302a204 | 1234 | set_register_cached (regnum, 1); |
32178cab | 1235 | if (val) |
3fadccb3 | 1236 | memcpy (register_buffer (current_regcache, regnum), val, |
5ebd2499 | 1237 | REGISTER_RAW_SIZE (regnum)); |
32178cab | 1238 | else |
3fadccb3 | 1239 | memset (register_buffer (current_regcache, regnum), '\000', |
5ebd2499 | 1240 | REGISTER_RAW_SIZE (regnum)); |
32178cab MS |
1241 | |
1242 | /* On some architectures, e.g. HPPA, there are a few stray bits in | |
1243 | some registers, that the rest of the code would like to ignore. */ | |
1244 | ||
61a0eb5b AC |
1245 | /* NOTE: cagney/2001-03-16: The macro CLEAN_UP_REGISTER_VALUE is |
1246 | going to be deprecated. Instead architectures will leave the raw | |
1247 | register value as is and instead clean things up as they pass | |
d8124050 | 1248 | through the method gdbarch_pseudo_register_read() clean up the |
61a0eb5b AC |
1249 | values. */ |
1250 | ||
4ee3352d | 1251 | #ifdef DEPRECATED_CLEAN_UP_REGISTER_VALUE |
0b434a00 AC |
1252 | DEPRECATED_CLEAN_UP_REGISTER_VALUE \ |
1253 | (regnum, register_buffer (current_regcache, regnum)); | |
32178cab MS |
1254 | #endif |
1255 | } | |
1256 | ||
193cb69f AC |
1257 | void |
1258 | regcache_collect (int regnum, void *buf) | |
1259 | { | |
3fadccb3 AC |
1260 | memcpy (buf, register_buffer (current_regcache, regnum), |
1261 | REGISTER_RAW_SIZE (regnum)); | |
193cb69f AC |
1262 | } |
1263 | ||
1264 | ||
0ba6dca9 AC |
1265 | /* read_pc, write_pc, read_sp, deprecated_read_fp, etc. Special |
1266 | handling for registers PC, SP, and FP. */ | |
32178cab | 1267 | |
cde9ea48 AC |
1268 | /* NOTE: cagney/2001-02-18: The functions read_pc_pid(), read_pc(), |
1269 | read_sp(), and deprecated_read_fp(), will eventually be replaced by | |
1270 | per-frame methods. Instead of relying on the global INFERIOR_PTID, | |
1271 | they will use the contextual information provided by the FRAME. | |
1272 | These functions do not belong in the register cache. */ | |
32178cab | 1273 | |
cde9ea48 AC |
1274 | /* NOTE: cagney/2003-06-07: The functions generic_target_write_pc(), |
1275 | write_pc_pid(), write_pc(), and deprecated_read_fp(), all need to | |
1276 | be replaced by something that does not rely on global state. But | |
1277 | what? */ | |
32178cab MS |
1278 | |
1279 | CORE_ADDR | |
39f77062 | 1280 | read_pc_pid (ptid_t ptid) |
32178cab | 1281 | { |
39f77062 | 1282 | ptid_t saved_inferior_ptid; |
32178cab MS |
1283 | CORE_ADDR pc_val; |
1284 | ||
39f77062 KB |
1285 | /* In case ptid != inferior_ptid. */ |
1286 | saved_inferior_ptid = inferior_ptid; | |
1287 | inferior_ptid = ptid; | |
32178cab | 1288 | |
cde9ea48 AC |
1289 | if (TARGET_READ_PC_P ()) |
1290 | pc_val = TARGET_READ_PC (ptid); | |
1291 | /* Else use per-frame method on get_current_frame. */ | |
1292 | else if (PC_REGNUM >= 0) | |
1293 | { | |
1294 | CORE_ADDR raw_val = read_register_pid (PC_REGNUM, ptid); | |
1295 | CORE_ADDR pc_val = ADDR_BITS_REMOVE (raw_val); | |
1296 | return pc_val; | |
1297 | } | |
1298 | else | |
1299 | internal_error (__FILE__, __LINE__, "read_pc_pid: Unable to find PC"); | |
32178cab | 1300 | |
39f77062 | 1301 | inferior_ptid = saved_inferior_ptid; |
32178cab MS |
1302 | return pc_val; |
1303 | } | |
1304 | ||
1305 | CORE_ADDR | |
1306 | read_pc (void) | |
1307 | { | |
39f77062 | 1308 | return read_pc_pid (inferior_ptid); |
32178cab MS |
1309 | } |
1310 | ||
32178cab | 1311 | void |
39f77062 | 1312 | generic_target_write_pc (CORE_ADDR pc, ptid_t ptid) |
32178cab MS |
1313 | { |
1314 | #ifdef PC_REGNUM | |
1315 | if (PC_REGNUM >= 0) | |
39f77062 | 1316 | write_register_pid (PC_REGNUM, pc, ptid); |
32178cab | 1317 | if (NPC_REGNUM >= 0) |
39f77062 | 1318 | write_register_pid (NPC_REGNUM, pc + 4, ptid); |
32178cab | 1319 | #else |
8e65ff28 AC |
1320 | internal_error (__FILE__, __LINE__, |
1321 | "generic_target_write_pc"); | |
32178cab MS |
1322 | #endif |
1323 | } | |
1324 | ||
1325 | void | |
39f77062 | 1326 | write_pc_pid (CORE_ADDR pc, ptid_t ptid) |
32178cab | 1327 | { |
39f77062 | 1328 | ptid_t saved_inferior_ptid; |
32178cab | 1329 | |
39f77062 KB |
1330 | /* In case ptid != inferior_ptid. */ |
1331 | saved_inferior_ptid = inferior_ptid; | |
1332 | inferior_ptid = ptid; | |
32178cab | 1333 | |
39f77062 | 1334 | TARGET_WRITE_PC (pc, ptid); |
32178cab | 1335 | |
39f77062 | 1336 | inferior_ptid = saved_inferior_ptid; |
32178cab MS |
1337 | } |
1338 | ||
1339 | void | |
1340 | write_pc (CORE_ADDR pc) | |
1341 | { | |
39f77062 | 1342 | write_pc_pid (pc, inferior_ptid); |
32178cab MS |
1343 | } |
1344 | ||
1345 | /* Cope with strage ways of getting to the stack and frame pointers */ | |
1346 | ||
32178cab MS |
1347 | CORE_ADDR |
1348 | read_sp (void) | |
1349 | { | |
bd1ce8ba AC |
1350 | if (TARGET_READ_SP_P ()) |
1351 | return TARGET_READ_SP (); | |
a9e5fdc2 AC |
1352 | else if (gdbarch_unwind_sp_p (current_gdbarch)) |
1353 | return get_frame_sp (get_current_frame ()); | |
bd1ce8ba | 1354 | else if (SP_REGNUM >= 0) |
a9e5fdc2 AC |
1355 | /* Try SP_REGNUM last: this makes all sorts of [wrong] assumptions |
1356 | about the architecture so put it at the end. */ | |
bd1ce8ba AC |
1357 | return read_register (SP_REGNUM); |
1358 | internal_error (__FILE__, __LINE__, "read_sp: Unable to find SP"); | |
32178cab MS |
1359 | } |
1360 | ||
32178cab | 1361 | void |
b46e02f6 | 1362 | deprecated_write_sp (CORE_ADDR val) |
32178cab | 1363 | { |
b46e02f6 AC |
1364 | gdb_assert (SP_REGNUM >= 0); |
1365 | write_register (SP_REGNUM, val); | |
32178cab MS |
1366 | } |
1367 | ||
32178cab | 1368 | CORE_ADDR |
0ba6dca9 | 1369 | deprecated_read_fp (void) |
32178cab | 1370 | { |
0ba6dca9 AC |
1371 | if (DEPRECATED_TARGET_READ_FP_P ()) |
1372 | return DEPRECATED_TARGET_READ_FP (); | |
1373 | else if (DEPRECATED_FP_REGNUM >= 0) | |
1374 | return read_register (DEPRECATED_FP_REGNUM); | |
1375 | else | |
1376 | internal_error (__FILE__, __LINE__, "deprecated_read_fp"); | |
32178cab MS |
1377 | } |
1378 | ||
705152c5 MS |
1379 | /* ARGSUSED */ |
1380 | static void | |
1381 | reg_flush_command (char *command, int from_tty) | |
1382 | { | |
1383 | /* Force-flush the register cache. */ | |
1384 | registers_changed (); | |
1385 | if (from_tty) | |
1386 | printf_filtered ("Register cache flushed.\n"); | |
1387 | } | |
1388 | ||
32178cab MS |
1389 | static void |
1390 | build_regcache (void) | |
3fadccb3 AC |
1391 | { |
1392 | current_regcache = regcache_xmalloc (current_gdbarch); | |
2d28509a | 1393 | current_regcache->readonly_p = 0; |
524d7c18 | 1394 | deprecated_registers = deprecated_grub_regcache_for_registers (current_regcache); |
b923b08d | 1395 | deprecated_register_valid = current_regcache->register_valid_p; |
3fadccb3 AC |
1396 | } |
1397 | ||
af030b9a AC |
1398 | static void |
1399 | dump_endian_bytes (struct ui_file *file, enum bfd_endian endian, | |
1400 | const unsigned char *buf, long len) | |
1401 | { | |
1402 | int i; | |
1403 | switch (endian) | |
1404 | { | |
1405 | case BFD_ENDIAN_BIG: | |
1406 | for (i = 0; i < len; i++) | |
1407 | fprintf_unfiltered (file, "%02x", buf[i]); | |
1408 | break; | |
1409 | case BFD_ENDIAN_LITTLE: | |
1410 | for (i = len - 1; i >= 0; i--) | |
1411 | fprintf_unfiltered (file, "%02x", buf[i]); | |
1412 | break; | |
1413 | default: | |
1414 | internal_error (__FILE__, __LINE__, "Bad switch"); | |
1415 | } | |
1416 | } | |
1417 | ||
1418 | enum regcache_dump_what | |
1419 | { | |
b59ff9d5 | 1420 | regcache_dump_none, regcache_dump_raw, regcache_dump_cooked, regcache_dump_groups |
af030b9a AC |
1421 | }; |
1422 | ||
1423 | static void | |
1424 | regcache_dump (struct regcache *regcache, struct ui_file *file, | |
1425 | enum regcache_dump_what what_to_dump) | |
1426 | { | |
1427 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); | |
b59ff9d5 | 1428 | struct gdbarch *gdbarch = regcache->descr->gdbarch; |
af030b9a AC |
1429 | int regnum; |
1430 | int footnote_nr = 0; | |
1431 | int footnote_register_size = 0; | |
1432 | int footnote_register_offset = 0; | |
1433 | int footnote_register_type_name_null = 0; | |
1434 | long register_offset = 0; | |
123a958e | 1435 | unsigned char buf[MAX_REGISTER_SIZE]; |
af030b9a AC |
1436 | |
1437 | #if 0 | |
1438 | fprintf_unfiltered (file, "legacy_p %d\n", regcache->descr->legacy_p); | |
1439 | fprintf_unfiltered (file, "nr_raw_registers %d\n", | |
1440 | regcache->descr->nr_raw_registers); | |
1441 | fprintf_unfiltered (file, "nr_cooked_registers %d\n", | |
1442 | regcache->descr->nr_cooked_registers); | |
1443 | fprintf_unfiltered (file, "sizeof_raw_registers %ld\n", | |
1444 | regcache->descr->sizeof_raw_registers); | |
1445 | fprintf_unfiltered (file, "sizeof_raw_register_valid_p %ld\n", | |
1446 | regcache->descr->sizeof_raw_register_valid_p); | |
af030b9a AC |
1447 | fprintf_unfiltered (file, "NUM_REGS %d\n", NUM_REGS); |
1448 | fprintf_unfiltered (file, "NUM_PSEUDO_REGS %d\n", NUM_PSEUDO_REGS); | |
1449 | #endif | |
1450 | ||
1451 | gdb_assert (regcache->descr->nr_cooked_registers | |
1452 | == (NUM_REGS + NUM_PSEUDO_REGS)); | |
1453 | ||
1454 | for (regnum = -1; regnum < regcache->descr->nr_cooked_registers; regnum++) | |
1455 | { | |
1456 | /* Name. */ | |
1457 | if (regnum < 0) | |
1458 | fprintf_unfiltered (file, " %-10s", "Name"); | |
1459 | else | |
1460 | { | |
1461 | const char *p = REGISTER_NAME (regnum); | |
1462 | if (p == NULL) | |
1463 | p = ""; | |
1464 | else if (p[0] == '\0') | |
1465 | p = "''"; | |
1466 | fprintf_unfiltered (file, " %-10s", p); | |
1467 | } | |
1468 | ||
1469 | /* Number. */ | |
1470 | if (regnum < 0) | |
1471 | fprintf_unfiltered (file, " %4s", "Nr"); | |
1472 | else | |
1473 | fprintf_unfiltered (file, " %4d", regnum); | |
1474 | ||
1475 | /* Relative number. */ | |
1476 | if (regnum < 0) | |
1477 | fprintf_unfiltered (file, " %4s", "Rel"); | |
1478 | else if (regnum < NUM_REGS) | |
1479 | fprintf_unfiltered (file, " %4d", regnum); | |
1480 | else | |
1481 | fprintf_unfiltered (file, " %4d", (regnum - NUM_REGS)); | |
1482 | ||
1483 | /* Offset. */ | |
1484 | if (regnum < 0) | |
1485 | fprintf_unfiltered (file, " %6s ", "Offset"); | |
1486 | else | |
1487 | { | |
1488 | fprintf_unfiltered (file, " %6ld", | |
1489 | regcache->descr->register_offset[regnum]); | |
a7e3c2ad | 1490 | if (register_offset != regcache->descr->register_offset[regnum] |
d3b22ed5 AC |
1491 | || register_offset != REGISTER_BYTE (regnum) |
1492 | || (regnum > 0 | |
1493 | && (regcache->descr->register_offset[regnum] | |
1494 | != (regcache->descr->register_offset[regnum - 1] | |
1495 | + regcache->descr->sizeof_register[regnum - 1]))) | |
1496 | ) | |
af030b9a AC |
1497 | { |
1498 | if (!footnote_register_offset) | |
1499 | footnote_register_offset = ++footnote_nr; | |
1500 | fprintf_unfiltered (file, "*%d", footnote_register_offset); | |
1501 | } | |
1502 | else | |
1503 | fprintf_unfiltered (file, " "); | |
1504 | register_offset = (regcache->descr->register_offset[regnum] | |
1505 | + regcache->descr->sizeof_register[regnum]); | |
1506 | } | |
1507 | ||
1508 | /* Size. */ | |
1509 | if (regnum < 0) | |
1510 | fprintf_unfiltered (file, " %5s ", "Size"); | |
1511 | else | |
1512 | { | |
1513 | fprintf_unfiltered (file, " %5ld", | |
1514 | regcache->descr->sizeof_register[regnum]); | |
1515 | if ((regcache->descr->sizeof_register[regnum] | |
1516 | != REGISTER_RAW_SIZE (regnum)) | |
1517 | || (regcache->descr->sizeof_register[regnum] | |
1518 | != REGISTER_VIRTUAL_SIZE (regnum)) | |
1519 | || (regcache->descr->sizeof_register[regnum] | |
bb425013 AC |
1520 | != TYPE_LENGTH (register_type (regcache->descr->gdbarch, |
1521 | regnum))) | |
af030b9a AC |
1522 | ) |
1523 | { | |
1524 | if (!footnote_register_size) | |
1525 | footnote_register_size = ++footnote_nr; | |
1526 | fprintf_unfiltered (file, "*%d", footnote_register_size); | |
1527 | } | |
1528 | else | |
1529 | fprintf_unfiltered (file, " "); | |
1530 | } | |
1531 | ||
1532 | /* Type. */ | |
b59ff9d5 AC |
1533 | { |
1534 | const char *t; | |
1535 | if (regnum < 0) | |
1536 | t = "Type"; | |
1537 | else | |
1538 | { | |
1539 | static const char blt[] = "builtin_type"; | |
1540 | t = TYPE_NAME (register_type (regcache->descr->gdbarch, regnum)); | |
1541 | if (t == NULL) | |
1542 | { | |
1543 | char *n; | |
1544 | if (!footnote_register_type_name_null) | |
1545 | footnote_register_type_name_null = ++footnote_nr; | |
1546 | xasprintf (&n, "*%d", footnote_register_type_name_null); | |
1547 | make_cleanup (xfree, n); | |
1548 | t = n; | |
1549 | } | |
1550 | /* Chop a leading builtin_type. */ | |
1551 | if (strncmp (t, blt, strlen (blt)) == 0) | |
1552 | t += strlen (blt); | |
1553 | } | |
1554 | fprintf_unfiltered (file, " %-15s", t); | |
1555 | } | |
1556 | ||
1557 | /* Leading space always present. */ | |
1558 | fprintf_unfiltered (file, " "); | |
af030b9a AC |
1559 | |
1560 | /* Value, raw. */ | |
1561 | if (what_to_dump == regcache_dump_raw) | |
1562 | { | |
1563 | if (regnum < 0) | |
1564 | fprintf_unfiltered (file, "Raw value"); | |
1565 | else if (regnum >= regcache->descr->nr_raw_registers) | |
1566 | fprintf_unfiltered (file, "<cooked>"); | |
1567 | else if (!regcache_valid_p (regcache, regnum)) | |
1568 | fprintf_unfiltered (file, "<invalid>"); | |
1569 | else | |
1570 | { | |
1571 | regcache_raw_read (regcache, regnum, buf); | |
1572 | fprintf_unfiltered (file, "0x"); | |
1573 | dump_endian_bytes (file, TARGET_BYTE_ORDER, buf, | |
1574 | REGISTER_RAW_SIZE (regnum)); | |
1575 | } | |
1576 | } | |
1577 | ||
1578 | /* Value, cooked. */ | |
1579 | if (what_to_dump == regcache_dump_cooked) | |
1580 | { | |
1581 | if (regnum < 0) | |
1582 | fprintf_unfiltered (file, "Cooked value"); | |
1583 | else | |
1584 | { | |
1585 | regcache_cooked_read (regcache, regnum, buf); | |
1586 | fprintf_unfiltered (file, "0x"); | |
1587 | dump_endian_bytes (file, TARGET_BYTE_ORDER, buf, | |
1588 | REGISTER_VIRTUAL_SIZE (regnum)); | |
1589 | } | |
1590 | } | |
1591 | ||
b59ff9d5 AC |
1592 | /* Group members. */ |
1593 | if (what_to_dump == regcache_dump_groups) | |
1594 | { | |
1595 | if (regnum < 0) | |
1596 | fprintf_unfiltered (file, "Groups"); | |
1597 | else | |
1598 | { | |
b59ff9d5 | 1599 | const char *sep = ""; |
6c7d17ba AC |
1600 | struct reggroup *group; |
1601 | for (group = reggroup_next (gdbarch, NULL); | |
1602 | group != NULL; | |
1603 | group = reggroup_next (gdbarch, group)) | |
b59ff9d5 | 1604 | { |
6c7d17ba | 1605 | if (gdbarch_register_reggroup_p (gdbarch, regnum, group)) |
b59ff9d5 | 1606 | { |
6c7d17ba | 1607 | fprintf_unfiltered (file, "%s%s", sep, reggroup_name (group)); |
b59ff9d5 AC |
1608 | sep = ","; |
1609 | } | |
1610 | } | |
1611 | } | |
1612 | } | |
1613 | ||
af030b9a AC |
1614 | fprintf_unfiltered (file, "\n"); |
1615 | } | |
1616 | ||
1617 | if (footnote_register_size) | |
1618 | fprintf_unfiltered (file, "*%d: Inconsistent register sizes.\n", | |
1619 | footnote_register_size); | |
1620 | if (footnote_register_offset) | |
1621 | fprintf_unfiltered (file, "*%d: Inconsistent register offsets.\n", | |
1622 | footnote_register_offset); | |
1623 | if (footnote_register_type_name_null) | |
1624 | fprintf_unfiltered (file, | |
1625 | "*%d: Register type's name NULL.\n", | |
1626 | footnote_register_type_name_null); | |
1627 | do_cleanups (cleanups); | |
1628 | } | |
1629 | ||
1630 | static void | |
1631 | regcache_print (char *args, enum regcache_dump_what what_to_dump) | |
1632 | { | |
1633 | if (args == NULL) | |
1634 | regcache_dump (current_regcache, gdb_stdout, what_to_dump); | |
1635 | else | |
1636 | { | |
1637 | struct ui_file *file = gdb_fopen (args, "w"); | |
1638 | if (file == NULL) | |
1639 | perror_with_name ("maintenance print architecture"); | |
1640 | regcache_dump (current_regcache, file, what_to_dump); | |
1641 | ui_file_delete (file); | |
1642 | } | |
1643 | } | |
1644 | ||
1645 | static void | |
1646 | maintenance_print_registers (char *args, int from_tty) | |
1647 | { | |
1648 | regcache_print (args, regcache_dump_none); | |
1649 | } | |
1650 | ||
1651 | static void | |
1652 | maintenance_print_raw_registers (char *args, int from_tty) | |
1653 | { | |
1654 | regcache_print (args, regcache_dump_raw); | |
1655 | } | |
1656 | ||
1657 | static void | |
1658 | maintenance_print_cooked_registers (char *args, int from_tty) | |
1659 | { | |
1660 | regcache_print (args, regcache_dump_cooked); | |
1661 | } | |
1662 | ||
b59ff9d5 AC |
1663 | static void |
1664 | maintenance_print_register_groups (char *args, int from_tty) | |
1665 | { | |
1666 | regcache_print (args, regcache_dump_groups); | |
1667 | } | |
1668 | ||
b9362cc7 AC |
1669 | extern initialize_file_ftype _initialize_regcache; /* -Wmissing-prototype */ |
1670 | ||
32178cab MS |
1671 | void |
1672 | _initialize_regcache (void) | |
1673 | { | |
3fadccb3 AC |
1674 | regcache_descr_handle = register_gdbarch_data (init_regcache_descr, |
1675 | xfree_regcache_descr); | |
1676 | REGISTER_GDBARCH_SWAP (current_regcache); | |
524d7c18 | 1677 | register_gdbarch_swap (&deprecated_registers, sizeof (deprecated_registers), NULL); |
8262ee23 | 1678 | register_gdbarch_swap (&deprecated_register_valid, sizeof (deprecated_register_valid), NULL); |
32178cab | 1679 | register_gdbarch_swap (NULL, 0, build_regcache); |
705152c5 MS |
1680 | |
1681 | add_com ("flushregs", class_maintenance, reg_flush_command, | |
1682 | "Force gdb to flush its register cache (maintainer command)"); | |
39f77062 KB |
1683 | |
1684 | /* Initialize the thread/process associated with the current set of | |
1685 | registers. For now, -1 is special, and means `no current process'. */ | |
1686 | registers_ptid = pid_to_ptid (-1); | |
af030b9a AC |
1687 | |
1688 | add_cmd ("registers", class_maintenance, | |
1689 | maintenance_print_registers, | |
1690 | "Print the internal register configuration.\ | |
1691 | Takes an optional file parameter.", | |
1692 | &maintenanceprintlist); | |
1693 | add_cmd ("raw-registers", class_maintenance, | |
1694 | maintenance_print_raw_registers, | |
1695 | "Print the internal register configuration including raw values.\ | |
1696 | Takes an optional file parameter.", | |
1697 | &maintenanceprintlist); | |
1698 | add_cmd ("cooked-registers", class_maintenance, | |
1699 | maintenance_print_cooked_registers, | |
1700 | "Print the internal register configuration including cooked values.\ | |
b59ff9d5 AC |
1701 | Takes an optional file parameter.", |
1702 | &maintenanceprintlist); | |
1703 | add_cmd ("register-groups", class_maintenance, | |
1704 | maintenance_print_register_groups, | |
1705 | "Print the internal register configuration including each register's group.\ | |
af030b9a AC |
1706 | Takes an optional file parameter.", |
1707 | &maintenanceprintlist); | |
1708 | ||
32178cab | 1709 | } |