1 /* Cache and manage the values of registers for GDB, the GNU debugger.
3 Copyright 1986, 1987, 1989, 1991, 1994, 1995, 1996, 1998, 2000,
4 2001, 2002 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
29 #include "reggroups.h"
30 #include "gdb_assert.h"
31 #include "gdb_string.h"
32 #include "gdbcmd.h" /* For maintenanceprintlist. */
37 * Here is the actual register cache.
40 /* Per-architecture object describing the layout of a register cache.
41 Computed once when the architecture is created */
43 struct gdbarch_data *regcache_descr_handle;
47 /* The architecture this descriptor belongs to. */
48 struct gdbarch *gdbarch;
50 /* Is this a ``legacy'' register cache? Such caches reserve space
51 for raw and pseudo registers and allow access to both. */
54 /* The raw register cache. This should contain just [0
55 .. NUM_RAW_REGISTERS). However, for older targets, it contains
56 space for the full [0 .. NUM_RAW_REGISTERS +
57 NUM_PSEUDO_REGISTERS). */
59 long sizeof_raw_registers;
60 long sizeof_raw_register_valid_p;
62 /* The cooked register space. Each cooked register in the range
63 [0..NR_RAW_REGISTERS) is direct-mapped onto the corresponding raw
64 register. The remaining [NR_RAW_REGISTERS
65 .. NR_COOKED_REGISTERS) (a.k.a. pseudo regiters) are mapped onto
66 both raw registers and memory by the architecture methods
67 gdbarch_register_read and gdbarch_register_write. */
68 int nr_cooked_registers;
69 long sizeof_cooked_registers;
70 long sizeof_cooked_register_valid_p;
72 /* Offset and size (in 8 bit bytes), of reach register in the
73 register cache. All registers (including those in the range
74 [NR_RAW_REGISTERS .. NR_COOKED_REGISTERS) are given an offset.
75 Assigning all registers an offset makes it possible to keep
76 legacy code, such as that found in read_register_bytes() and
77 write_register_bytes() working. */
78 long *register_offset;
79 long *sizeof_register;
81 /* Useful constant. Largest of all the registers. */
82 long max_register_size;
84 /* Cached table containing the type of each register. */
85 struct type **register_type;
89 init_legacy_regcache_descr (struct gdbarch *gdbarch,
90 struct regcache_descr *descr)
93 /* FIXME: cagney/2002-05-11: gdbarch_data() should take that
94 ``gdbarch'' as a parameter. */
95 gdb_assert (gdbarch != NULL);
97 /* FIXME: cagney/2002-05-11: Shouldn't be including pseudo-registers
98 in the register cache. Unfortunatly some architectures still
99 rely on this and the pseudo_register_write() method. */
100 descr->nr_raw_registers = descr->nr_cooked_registers;
101 descr->sizeof_raw_register_valid_p = descr->sizeof_cooked_register_valid_p;
103 /* Compute the offset of each register. Legacy architectures define
104 REGISTER_BYTE() so use that. */
105 /* FIXME: cagney/2002-11-07: Instead of using REGISTER_BYTE() this
106 code should, as is done in init_regcache_descr(), compute the
107 offets at runtime. This currently isn't possible as some ISAs
108 define overlapping register regions - see the mess in
109 read_register_bytes() and write_register_bytes() registers. */
110 descr->sizeof_register = XCALLOC (descr->nr_cooked_registers, long);
111 descr->register_offset = XCALLOC (descr->nr_cooked_registers, long);
112 descr->max_register_size = 0;
113 for (i = 0; i < descr->nr_cooked_registers; i++)
115 /* FIXME: cagney/2001-12-04: This code shouldn't need to use
116 REGISTER_BYTE(). Unfortunatly, legacy code likes to lay the
117 buffer out so that certain registers just happen to overlap.
118 Ulgh! New targets use gdbarch's register read/write and
119 entirely avoid this uglyness. */
120 descr->register_offset[i] = REGISTER_BYTE (i);
121 descr->sizeof_register[i] = REGISTER_RAW_SIZE (i);
122 if (descr->max_register_size < REGISTER_RAW_SIZE (i))
123 descr->max_register_size = REGISTER_RAW_SIZE (i);
124 if (descr->max_register_size < REGISTER_VIRTUAL_SIZE (i))
125 descr->max_register_size = REGISTER_VIRTUAL_SIZE (i);
128 /* Compute the real size of the register buffer. Start out by
129 trusting REGISTER_BYTES, but then adjust it upwards should that
130 be found to not be sufficient. */
131 /* FIXME: cagney/2002-11-05: Instead of using REGISTER_BYTES, this
132 code should, as is done in init_regcache_descr(), compute the
133 total number of register bytes using the accumulated offsets. */
134 descr->sizeof_cooked_registers = REGISTER_BYTES; /* OK use. */
135 for (i = 0; i < descr->nr_cooked_registers; i++)
138 /* Keep extending the buffer so that there is always enough
139 space for all registers. The comparison is necessary since
140 legacy code is free to put registers in random places in the
141 buffer separated by holes. Once REGISTER_BYTE() is killed
142 this can be greatly simplified. */
143 regend = descr->register_offset[i] + descr->sizeof_register[i];
144 if (descr->sizeof_cooked_registers < regend)
145 descr->sizeof_cooked_registers = regend;
147 /* FIXME: cagney/2002-05-11: Shouldn't be including pseudo-registers
148 in the register cache. Unfortunatly some architectures still
149 rely on this and the pseudo_register_write() method. */
150 descr->sizeof_raw_registers = descr->sizeof_cooked_registers;
154 init_regcache_descr (struct gdbarch *gdbarch)
157 struct regcache_descr *descr;
158 gdb_assert (gdbarch != NULL);
160 /* Create an initial, zero filled, table. */
161 descr = XCALLOC (1, struct regcache_descr);
162 descr->gdbarch = gdbarch;
164 /* Total size of the register space. The raw registers are mapped
165 directly onto the raw register cache while the pseudo's are
166 either mapped onto raw-registers or memory. */
167 descr->nr_cooked_registers = NUM_REGS + NUM_PSEUDO_REGS;
168 descr->sizeof_cooked_register_valid_p = NUM_REGS + NUM_PSEUDO_REGS;
170 /* Fill in a table of register types. */
171 descr->register_type = XCALLOC (descr->nr_cooked_registers,
173 for (i = 0; i < descr->nr_cooked_registers; i++)
175 if (gdbarch_register_type_p (gdbarch))
177 gdb_assert (!REGISTER_VIRTUAL_TYPE_P ()); /* OK */
178 descr->register_type[i] = gdbarch_register_type (gdbarch, i);
181 descr->register_type[i] = REGISTER_VIRTUAL_TYPE (i); /* OK */
184 /* If an old style architecture, fill in the remainder of the
185 register cache descriptor using the register macros. */
186 if (!gdbarch_pseudo_register_read_p (gdbarch)
187 && !gdbarch_pseudo_register_write_p (gdbarch)
188 && !gdbarch_register_type_p (gdbarch))
191 init_legacy_regcache_descr (gdbarch, descr);
195 /* Construct a strictly RAW register cache. Don't allow pseudo's
196 into the register cache. */
197 descr->nr_raw_registers = NUM_REGS;
199 /* FIXME: cagney/2002-08-13: Overallocate the register_valid_p
200 array. This pretects GDB from erant code that accesses elements
201 of the global register_valid_p[] array in the range [NUM_REGS
202 .. NUM_REGS + NUM_PSEUDO_REGS). */
203 descr->sizeof_raw_register_valid_p = descr->sizeof_cooked_register_valid_p;
205 /* Lay out the register cache.
207 NOTE: cagney/2002-05-22: Only register_type() is used when
208 constructing the register cache. It is assumed that the
209 register's raw size, virtual size and type length are all the
214 descr->sizeof_register = XCALLOC (descr->nr_cooked_registers, long);
215 descr->register_offset = XCALLOC (descr->nr_cooked_registers, long);
216 descr->max_register_size = 0;
217 for (i = 0; i < descr->nr_cooked_registers; i++)
219 descr->sizeof_register[i] = TYPE_LENGTH (descr->register_type[i]);
220 descr->register_offset[i] = offset;
221 offset += descr->sizeof_register[i];
222 if (descr->max_register_size < descr->sizeof_register[i])
223 descr->max_register_size = descr->sizeof_register[i];
225 /* Set the real size of the register cache buffer. */
226 descr->sizeof_cooked_registers = offset;
229 /* FIXME: cagney/2002-05-22: Should only need to allocate space for
230 the raw registers. Unfortunatly some code still accesses the
231 register array directly using the global registers[]. Until that
232 code has been purged, play safe and over allocating the register
234 descr->sizeof_raw_registers = descr->sizeof_cooked_registers;
237 /* Sanity check. Confirm that the assumptions about gdbarch are
238 true. The REGCACHE_DESCR_HANDLE is set before doing the checks
239 so that targets using the generic methods supplied by regcache
240 don't go into infinite recursion trying to, again, create the
242 set_gdbarch_data (gdbarch, regcache_descr_handle, descr);
243 for (i = 0; i < descr->nr_cooked_registers; i++)
245 gdb_assert (descr->sizeof_register[i] == REGISTER_RAW_SIZE (i));
246 gdb_assert (descr->sizeof_register[i] == REGISTER_VIRTUAL_SIZE (i));
247 gdb_assert (descr->register_offset[i] == REGISTER_BYTE (i));
249 /* gdb_assert (descr->sizeof_raw_registers == REGISTER_BYTES (i)); */
255 static struct regcache_descr *
256 regcache_descr (struct gdbarch *gdbarch)
258 return gdbarch_data (gdbarch, regcache_descr_handle);
262 xfree_regcache_descr (struct gdbarch *gdbarch, void *ptr)
264 struct regcache_descr *descr = ptr;
267 xfree (descr->register_offset);
268 xfree (descr->sizeof_register);
269 descr->register_offset = NULL;
270 descr->sizeof_register = NULL;
274 /* Utility functions returning useful register attributes stored in
275 the regcache descr. */
278 register_type (struct gdbarch *gdbarch, int regnum)
280 struct regcache_descr *descr = regcache_descr (gdbarch);
281 gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
282 return descr->register_type[regnum];
285 /* Utility functions returning useful register attributes stored in
286 the regcache descr. */
289 max_register_size (struct gdbarch *gdbarch)
291 struct regcache_descr *descr = regcache_descr (gdbarch);
292 return descr->max_register_size;
296 register_size (struct gdbarch *gdbarch, int regnum)
298 struct regcache_descr *descr = regcache_descr (gdbarch);
300 gdb_assert (regnum >= 0 && regnum < (NUM_REGS + NUM_PSEUDO_REGS));
301 size = descr->sizeof_register[regnum];
302 gdb_assert (size == REGISTER_RAW_SIZE (regnum)); /* OK */
303 gdb_assert (size == REGISTER_RAW_SIZE (regnum)); /* OK */
307 /* The register cache for storing raw register values. */
311 struct regcache_descr *descr;
312 /* The register buffers. A read-only register cache can hold the
313 full [0 .. NUM_REGS + NUM_PSEUDO_REGS) while a read/write
314 register cache can only hold [0 .. NUM_REGS). */
316 char *register_valid_p;
317 /* Is this a read-only cache? A read-only cache is used for saving
318 the target's register state (e.g, across an inferior function
319 call or just before forcing a function return). A read-only
320 cache can only be updated via the methods regcache_dup() and
321 regcache_cpy(). The actual contents are determined by the
322 reggroup_save and reggroup_restore methods. */
327 regcache_xmalloc (struct gdbarch *gdbarch)
329 struct regcache_descr *descr;
330 struct regcache *regcache;
331 gdb_assert (gdbarch != NULL);
332 descr = regcache_descr (gdbarch);
333 regcache = XMALLOC (struct regcache);
334 regcache->descr = descr;
336 = XCALLOC (descr->sizeof_raw_registers, char);
337 regcache->register_valid_p
338 = XCALLOC (descr->sizeof_raw_register_valid_p, char);
339 regcache->readonly_p = 1;
344 regcache_xfree (struct regcache *regcache)
346 if (regcache == NULL)
348 xfree (regcache->registers);
349 xfree (regcache->register_valid_p);
354 do_regcache_xfree (void *data)
356 regcache_xfree (data);
360 make_cleanup_regcache_xfree (struct regcache *regcache)
362 return make_cleanup (do_regcache_xfree, regcache);
365 /* Return a pointer to register REGNUM's buffer cache. */
368 register_buffer (struct regcache *regcache, int regnum)
370 return regcache->registers + regcache->descr->register_offset[regnum];
374 regcache_save (struct regcache *dst, struct regcache *src)
376 struct gdbarch *gdbarch = dst->descr->gdbarch;
378 /* The SRC and DST register caches had better belong to the same
380 gdb_assert (src->descr->gdbarch == dst->descr->gdbarch);
381 /* The DST should be `read-only', if it wasn't then the save would
382 end up trying to write the register values out through to the
384 gdb_assert (!src->readonly_p);
385 gdb_assert (dst->readonly_p);
386 /* Clear the dest. */
387 memset (dst->registers, 0, dst->descr->sizeof_cooked_registers);
388 memset (dst->register_valid_p, 0, dst->descr->sizeof_cooked_register_valid_p);
389 /* Copy over any registers (identified by their membership in the
390 save_reggroup) and mark them as valid. The full [0
391 .. NUM_REGS+NUM_PSEUDO_REGS) range is checked since some
392 architectures need to save/restore `cooked' registers that live
394 for (regnum = 0; regnum < dst->descr->nr_cooked_registers; regnum++)
396 if (gdbarch_register_reggroup_p (gdbarch, regnum, save_reggroup))
398 regcache_cooked_read (src, regnum, register_buffer (dst, regnum));
399 dst->register_valid_p[regnum] = 1;
405 regcache_restore (struct regcache *dst, struct regcache *src)
407 struct gdbarch *gdbarch = dst->descr->gdbarch;
409 gdb_assert (src->descr->gdbarch == dst->descr->gdbarch);
410 gdb_assert (!dst->readonly_p);
411 gdb_assert (src->readonly_p);
412 /* Copy over any registers, being careful to only restore those that
413 were both saved and need to be restored. The full [0
414 .. NUM_REGS+NUM_PSEUDO_REGS) range is checked since some
415 architectures need to save/restore `cooked' registers that live
417 for (regnum = 0; regnum < src->descr->nr_cooked_registers; regnum++)
419 if (gdbarch_register_reggroup_p (gdbarch, regnum, restore_reggroup)
420 && src->register_valid_p[regnum])
422 regcache_cooked_write (dst, regnum, register_buffer (src, regnum));
428 regcache_cpy (struct regcache *dst, struct regcache *src)
432 gdb_assert (src != NULL && dst != NULL);
433 gdb_assert (src->descr->gdbarch == dst->descr->gdbarch);
434 gdb_assert (src != dst);
435 gdb_assert (src->readonly_p || dst->readonly_p);
436 if (!src->readonly_p)
437 regcache_save (dst, src);
438 else if (!dst->readonly_p)
439 regcache_restore (dst, src);
441 regcache_cpy_no_passthrough (dst, src);
445 regcache_cpy_no_passthrough (struct regcache *dst, struct regcache *src)
448 gdb_assert (src != NULL && dst != NULL);
449 gdb_assert (src->descr->gdbarch == dst->descr->gdbarch);
450 /* NOTE: cagney/2002-05-17: Don't let the caller do a no-passthrough
451 move of data into the current_regcache(). Doing this would be
452 silly - it would mean that valid_p would be completly invalid. */
453 gdb_assert (dst != current_regcache);
454 memcpy (dst->registers, src->registers, dst->descr->sizeof_raw_registers);
455 memcpy (dst->register_valid_p, src->register_valid_p,
456 dst->descr->sizeof_raw_register_valid_p);
460 regcache_dup (struct regcache *src)
462 struct regcache *newbuf;
463 gdb_assert (current_regcache != NULL);
464 newbuf = regcache_xmalloc (src->descr->gdbarch);
465 regcache_cpy (newbuf, src);
470 regcache_dup_no_passthrough (struct regcache *src)
472 struct regcache *newbuf;
473 gdb_assert (current_regcache != NULL);
474 newbuf = regcache_xmalloc (src->descr->gdbarch);
475 regcache_cpy_no_passthrough (newbuf, src);
480 regcache_valid_p (struct regcache *regcache, int regnum)
482 gdb_assert (regcache != NULL);
483 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
484 return regcache->register_valid_p[regnum];
488 deprecated_grub_regcache_for_registers (struct regcache *regcache)
490 return regcache->registers;
494 deprecated_grub_regcache_for_register_valid (struct regcache *regcache)
496 return regcache->register_valid_p;
499 /* Global structure containing the current regcache. */
500 /* FIXME: cagney/2002-05-11: The two global arrays registers[] and
501 deprecated_register_valid[] currently point into this structure. */
502 struct regcache *current_regcache;
504 /* NOTE: this is a write-through cache. There is no "dirty" bit for
505 recording if the register values have been changed (eg. by the
506 user). Therefore all registers must be written back to the
507 target when appropriate. */
509 /* REGISTERS contains the cached register values (in target byte order). */
511 char *deprecated_registers;
513 /* DEPRECATED_REGISTER_VALID is 0 if the register needs to be fetched,
514 1 if it has been fetched, and
515 -1 if the register value was not available.
517 "Not available" indicates that the target is not not able to supply
518 the register at this state. The register may become available at a
519 later time (after the next resume). This often occures when GDB is
520 manipulating a target that contains only a snapshot of the entire
521 system being debugged - some of the registers in such a system may
522 not have been saved. */
524 signed char *deprecated_register_valid;
526 /* The thread/process associated with the current set of registers. */
528 static ptid_t registers_ptid;
536 Returns 0 if the value is not in the cache (needs fetch).
537 >0 if the value is in the cache.
538 <0 if the value is permanently unavailable (don't ask again). */
541 register_cached (int regnum)
543 return deprecated_register_valid[regnum];
546 /* Record that REGNUM's value is cached if STATE is >0, uncached but
547 fetchable if STATE is 0, and uncached and unfetchable if STATE is <0. */
550 set_register_cached (int regnum, int state)
552 gdb_assert (regnum >= 0);
553 gdb_assert (regnum < current_regcache->descr->nr_raw_registers);
554 current_regcache->register_valid_p[regnum] = state;
557 /* Return whether register REGNUM is a real register. */
560 real_register (int regnum)
562 return regnum >= 0 && regnum < NUM_REGS;
565 /* Low level examining and depositing of registers.
567 The caller is responsible for making sure that the inferior is
568 stopped before calling the fetching routines, or it will get
569 garbage. (a change from GDB version 3, in which the caller got the
570 value from the last stop). */
572 /* REGISTERS_CHANGED ()
574 Indicate that registers may have changed, so invalidate the cache. */
577 registers_changed (void)
581 registers_ptid = pid_to_ptid (-1);
583 /* Force cleanup of any alloca areas if using C alloca instead of
584 a builtin alloca. This particular call is used to clean up
585 areas allocated by low level target code which may build up
586 during lengthy interactions between gdb and the target before
587 gdb gives control to the user (ie watchpoints). */
590 for (i = 0; i < current_regcache->descr->nr_raw_registers; i++)
591 set_register_cached (i, 0);
593 if (registers_changed_hook)
594 registers_changed_hook ();
597 /* DEPRECATED_REGISTERS_FETCHED ()
599 Indicate that all registers have been fetched, so mark them all valid. */
601 /* NOTE: cagney/2001-12-04: This function does not set valid on the
602 pseudo-register range since pseudo registers are always supplied
603 using supply_register(). */
604 /* FIXME: cagney/2001-12-04: This function is DEPRECATED. The target
605 code was blatting the registers[] array and then calling this.
606 Since targets should only be using supply_register() the need for
607 this function/hack is eliminated. */
610 deprecated_registers_fetched (void)
614 for (i = 0; i < NUM_REGS; i++)
615 set_register_cached (i, 1);
616 /* Do not assume that the pseudo-regs have also been fetched.
617 Fetching all real regs NEVER accounts for pseudo-regs. */
620 /* deprecated_read_register_bytes and deprecated_write_register_bytes
621 are generally a *BAD* idea. They are inefficient because they need
622 to check for partial updates, which can only be done by scanning
623 through all of the registers and seeing if the bytes that are being
624 read/written fall inside of an invalid register. [The main reason
625 this is necessary is that register sizes can vary, so a simple
626 index won't suffice.] It is far better to call read_register_gen
627 and write_register_gen if you want to get at the raw register
628 contents, as it only takes a regnum as an argument, and therefore
629 can't do a partial register update.
631 Prior to the recent fixes to check for partial updates, both read
632 and deprecated_write_register_bytes always checked to see if any
633 registers were stale, and then called target_fetch_registers (-1)
634 to update the whole set. This caused really slowed things down for
637 /* Copy INLEN bytes of consecutive data from registers
638 starting with the INREGBYTE'th byte of register data
639 into memory at MYADDR. */
642 deprecated_read_register_bytes (int in_start, char *in_buf, int in_len)
644 int in_end = in_start + in_len;
646 char *reg_buf = alloca (MAX_REGISTER_RAW_SIZE);
648 /* See if we are trying to read bytes from out-of-date registers. If so,
649 update just those registers. */
651 for (regnum = 0; regnum < NUM_REGS + NUM_PSEUDO_REGS; regnum++)
660 reg_start = REGISTER_BYTE (regnum);
661 reg_len = REGISTER_RAW_SIZE (regnum);
662 reg_end = reg_start + reg_len;
664 if (reg_end <= in_start || in_end <= reg_start)
665 /* The range the user wants to read doesn't overlap with regnum. */
668 if (REGISTER_NAME (regnum) != NULL && *REGISTER_NAME (regnum) != '\0')
669 /* Force the cache to fetch the entire register. */
670 deprecated_read_register_gen (regnum, reg_buf);
672 /* Legacy note: even though this register is ``invalid'' we
673 still need to return something. It would appear that some
674 code relies on apparent gaps in the register array also
676 /* FIXME: cagney/2001-08-18: This is just silly. It defeats
677 the entire register read/write flow of control. Must
678 resist temptation to return 0xdeadbeef. */
679 memcpy (reg_buf, &deprecated_registers[reg_start], reg_len);
681 /* Legacy note: This function, for some reason, allows a NULL
682 input buffer. If the buffer is NULL, the registers are still
683 fetched, just the final transfer is skipped. */
687 /* start = max (reg_start, in_start) */
688 if (reg_start > in_start)
693 /* end = min (reg_end, in_end) */
694 if (reg_end < in_end)
699 /* Transfer just the bytes common to both IN_BUF and REG_BUF */
700 for (byte = start; byte < end; byte++)
702 in_buf[byte - in_start] = reg_buf[byte - reg_start];
707 /* Read register REGNUM into memory at MYADDR, which must be large
708 enough for REGISTER_RAW_BYTES (REGNUM). Target byte-order. If the
709 register is known to be the size of a CORE_ADDR or smaller,
710 read_register can be used instead. */
713 legacy_read_register_gen (int regnum, char *myaddr)
715 gdb_assert (regnum >= 0 && regnum < (NUM_REGS + NUM_PSEUDO_REGS));
716 if (! ptid_equal (registers_ptid, inferior_ptid))
718 registers_changed ();
719 registers_ptid = inferior_ptid;
722 if (!register_cached (regnum))
723 target_fetch_registers (regnum);
725 memcpy (myaddr, register_buffer (current_regcache, regnum),
726 REGISTER_RAW_SIZE (regnum));
730 regcache_raw_read (struct regcache *regcache, int regnum, void *buf)
732 gdb_assert (regcache != NULL && buf != NULL);
733 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
734 if (regcache->descr->legacy_p
735 && !regcache->readonly_p)
737 gdb_assert (regcache == current_regcache);
738 /* For moment, just use underlying legacy code. Ulgh!!! This
739 silently and very indirectly updates the regcache's regcache
740 via the global deprecated_register_valid[]. */
741 legacy_read_register_gen (regnum, buf);
744 /* Make certain that the register cache is up-to-date with respect
745 to the current thread. This switching shouldn't be necessary
746 only there is still only one target side register cache. Sigh!
747 On the bright side, at least there is a regcache object. */
748 if (!regcache->readonly_p)
750 gdb_assert (regcache == current_regcache);
751 if (! ptid_equal (registers_ptid, inferior_ptid))
753 registers_changed ();
754 registers_ptid = inferior_ptid;
756 if (!register_cached (regnum))
757 target_fetch_registers (regnum);
759 /* Copy the value directly into the register cache. */
760 memcpy (buf, register_buffer (regcache, regnum),
761 regcache->descr->sizeof_register[regnum]);
765 regcache_raw_read_signed (struct regcache *regcache, int regnum, LONGEST *val)
768 gdb_assert (regcache != NULL);
769 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
770 buf = alloca (regcache->descr->sizeof_register[regnum]);
771 regcache_raw_read (regcache, regnum, buf);
772 (*val) = extract_signed_integer (buf,
773 regcache->descr->sizeof_register[regnum]);
777 regcache_raw_read_unsigned (struct regcache *regcache, int regnum,
781 gdb_assert (regcache != NULL);
782 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
783 buf = alloca (regcache->descr->sizeof_register[regnum]);
784 regcache_raw_read (regcache, regnum, buf);
785 (*val) = extract_unsigned_integer (buf,
786 regcache->descr->sizeof_register[regnum]);
790 regcache_raw_write_signed (struct regcache *regcache, int regnum, LONGEST val)
793 gdb_assert (regcache != NULL);
794 gdb_assert (regnum >=0 && regnum < regcache->descr->nr_raw_registers);
795 buf = alloca (regcache->descr->sizeof_register[regnum]);
796 store_signed_integer (buf, regcache->descr->sizeof_register[regnum], val);
797 regcache_raw_write (regcache, regnum, buf);
801 regcache_raw_write_unsigned (struct regcache *regcache, int regnum,
805 gdb_assert (regcache != NULL);
806 gdb_assert (regnum >=0 && regnum < regcache->descr->nr_raw_registers);
807 buf = alloca (regcache->descr->sizeof_register[regnum]);
808 store_unsigned_integer (buf, regcache->descr->sizeof_register[regnum], val);
809 regcache_raw_write (regcache, regnum, buf);
813 deprecated_read_register_gen (int regnum, char *buf)
815 gdb_assert (current_regcache != NULL);
816 gdb_assert (current_regcache->descr->gdbarch == current_gdbarch);
817 if (current_regcache->descr->legacy_p)
819 legacy_read_register_gen (regnum, buf);
822 regcache_cooked_read (current_regcache, regnum, buf);
826 regcache_cooked_read (struct regcache *regcache, int regnum, void *buf)
828 gdb_assert (regnum >= 0);
829 gdb_assert (regnum < regcache->descr->nr_cooked_registers);
830 if (regnum < regcache->descr->nr_raw_registers)
831 regcache_raw_read (regcache, regnum, buf);
832 else if (regcache->readonly_p
833 && regnum < regcache->descr->nr_cooked_registers
834 && regcache->register_valid_p[regnum])
835 /* Read-only register cache, perhaphs the cooked value was cached? */
836 memcpy (buf, register_buffer (regcache, regnum),
837 regcache->descr->sizeof_register[regnum]);
839 gdbarch_pseudo_register_read (regcache->descr->gdbarch, regcache,
844 regcache_cooked_read_signed (struct regcache *regcache, int regnum,
848 gdb_assert (regcache != NULL);
849 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
850 buf = alloca (regcache->descr->sizeof_register[regnum]);
851 regcache_cooked_read (regcache, regnum, buf);
852 (*val) = extract_signed_integer (buf,
853 regcache->descr->sizeof_register[regnum]);
857 regcache_cooked_read_unsigned (struct regcache *regcache, int regnum,
861 gdb_assert (regcache != NULL);
862 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
863 buf = alloca (regcache->descr->sizeof_register[regnum]);
864 regcache_cooked_read (regcache, regnum, buf);
865 (*val) = extract_unsigned_integer (buf,
866 regcache->descr->sizeof_register[regnum]);
869 /* Write register REGNUM at MYADDR to the target. MYADDR points at
870 REGISTER_RAW_BYTES(REGNUM), which must be in target byte-order. */
873 legacy_write_register_gen (int regnum, const void *myaddr)
876 gdb_assert (regnum >= 0 && regnum < (NUM_REGS + NUM_PSEUDO_REGS));
878 /* On the sparc, writing %g0 is a no-op, so we don't even want to
879 change the registers array if something writes to this register. */
880 if (CANNOT_STORE_REGISTER (regnum))
883 if (! ptid_equal (registers_ptid, inferior_ptid))
885 registers_changed ();
886 registers_ptid = inferior_ptid;
889 size = REGISTER_RAW_SIZE (regnum);
891 if (real_register (regnum))
893 /* If we have a valid copy of the register, and new value == old
894 value, then don't bother doing the actual store. */
895 if (register_cached (regnum)
896 && (memcmp (register_buffer (current_regcache, regnum), myaddr, size)
900 target_prepare_to_store ();
903 memcpy (register_buffer (current_regcache, regnum), myaddr, size);
905 set_register_cached (regnum, 1);
906 target_store_registers (regnum);
910 regcache_raw_write (struct regcache *regcache, int regnum, const void *buf)
912 gdb_assert (regcache != NULL && buf != NULL);
913 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
914 gdb_assert (!regcache->readonly_p);
916 if (regcache->descr->legacy_p)
918 /* For moment, just use underlying legacy code. Ulgh!!! This
919 silently and very indirectly updates the regcache's buffers
920 via the globals deprecated_register_valid[] and registers[]. */
921 gdb_assert (regcache == current_regcache);
922 legacy_write_register_gen (regnum, buf);
926 /* On the sparc, writing %g0 is a no-op, so we don't even want to
927 change the registers array if something writes to this register. */
928 if (CANNOT_STORE_REGISTER (regnum))
931 /* Make certain that the correct cache is selected. */
932 gdb_assert (regcache == current_regcache);
933 if (! ptid_equal (registers_ptid, inferior_ptid))
935 registers_changed ();
936 registers_ptid = inferior_ptid;
939 /* If we have a valid copy of the register, and new value == old
940 value, then don't bother doing the actual store. */
941 if (regcache_valid_p (regcache, regnum)
942 && (memcmp (register_buffer (regcache, regnum), buf,
943 regcache->descr->sizeof_register[regnum]) == 0))
946 target_prepare_to_store ();
947 memcpy (register_buffer (regcache, regnum), buf,
948 regcache->descr->sizeof_register[regnum]);
949 regcache->register_valid_p[regnum] = 1;
950 target_store_registers (regnum);
954 deprecated_write_register_gen (int regnum, char *buf)
956 gdb_assert (current_regcache != NULL);
957 gdb_assert (current_regcache->descr->gdbarch == current_gdbarch);
958 if (current_regcache->descr->legacy_p)
960 legacy_write_register_gen (regnum, buf);
963 regcache_cooked_write (current_regcache, regnum, buf);
967 regcache_cooked_write (struct regcache *regcache, int regnum, const void *buf)
969 gdb_assert (regnum >= 0);
970 gdb_assert (regnum < regcache->descr->nr_cooked_registers);
971 if (regnum < regcache->descr->nr_raw_registers)
972 regcache_raw_write (regcache, regnum, buf);
974 gdbarch_pseudo_register_write (regcache->descr->gdbarch, regcache,
978 /* Copy INLEN bytes of consecutive data from memory at MYADDR
979 into registers starting with the MYREGSTART'th byte of register data. */
982 deprecated_write_register_bytes (int myregstart, char *myaddr, int inlen)
984 int myregend = myregstart + inlen;
987 target_prepare_to_store ();
989 /* Scan through the registers updating any that are covered by the
990 range myregstart<=>myregend using write_register_gen, which does
991 nice things like handling threads, and avoiding updates when the
992 new and old contents are the same. */
994 for (regnum = 0; regnum < NUM_REGS + NUM_PSEUDO_REGS; regnum++)
996 int regstart, regend;
998 regstart = REGISTER_BYTE (regnum);
999 regend = regstart + REGISTER_RAW_SIZE (regnum);
1001 /* Is this register completely outside the range the user is writing? */
1002 if (myregend <= regstart || regend <= myregstart)
1005 /* Is this register completely within the range the user is writing? */
1006 else if (myregstart <= regstart && regend <= myregend)
1007 deprecated_write_register_gen (regnum, myaddr + (regstart - myregstart));
1009 /* The register partially overlaps the range being written. */
1012 char *regbuf = (char*) alloca (MAX_REGISTER_RAW_SIZE);
1013 /* What's the overlap between this register's bytes and
1014 those the caller wants to write? */
1015 int overlapstart = max (regstart, myregstart);
1016 int overlapend = min (regend, myregend);
1018 /* We may be doing a partial update of an invalid register.
1019 Update it from the target before scribbling on it. */
1020 deprecated_read_register_gen (regnum, regbuf);
1022 memcpy (&deprecated_registers[overlapstart],
1023 myaddr + (overlapstart - myregstart),
1024 overlapend - overlapstart);
1026 target_store_registers (regnum);
1031 /* Perform a partial register transfer using a read, modify, write
1034 typedef void (regcache_read_ftype) (struct regcache *regcache, int regnum,
1036 typedef void (regcache_write_ftype) (struct regcache *regcache, int regnum,
1040 regcache_xfer_part (struct regcache *regcache, int regnum,
1041 int offset, int len, void *in, const void *out,
1042 regcache_read_ftype *read, regcache_write_ftype *write)
1044 struct regcache_descr *descr = regcache->descr;
1045 bfd_byte *reg = alloca (descr->max_register_size);
1046 gdb_assert (offset >= 0 && offset <= descr->sizeof_register[regnum]);
1047 gdb_assert (len >= 0 && offset + len <= descr->sizeof_register[regnum]);
1048 /* Something to do? */
1049 if (offset + len == 0)
1051 /* Read (when needed) ... */
1054 || offset + len < descr->sizeof_register[regnum])
1056 gdb_assert (read != NULL);
1057 read (regcache, regnum, reg);
1059 /* ... modify ... */
1061 memcpy (in, reg + offset, len);
1063 memcpy (reg + offset, out, len);
1064 /* ... write (when needed). */
1067 gdb_assert (write != NULL);
1068 write (regcache, regnum, reg);
1073 regcache_raw_read_part (struct regcache *regcache, int regnum,
1074 int offset, int len, void *buf)
1076 struct regcache_descr *descr = regcache->descr;
1077 gdb_assert (regnum >= 0 && regnum < descr->nr_raw_registers);
1078 regcache_xfer_part (regcache, regnum, offset, len, buf, NULL,
1079 regcache_raw_read, regcache_raw_write);
1083 regcache_raw_write_part (struct regcache *regcache, int regnum,
1084 int offset, int len, const void *buf)
1086 struct regcache_descr *descr = regcache->descr;
1087 gdb_assert (regnum >= 0 && regnum < descr->nr_raw_registers);
1088 regcache_xfer_part (regcache, regnum, offset, len, NULL, buf,
1089 regcache_raw_read, regcache_raw_write);
1093 regcache_cooked_read_part (struct regcache *regcache, int regnum,
1094 int offset, int len, void *buf)
1096 struct regcache_descr *descr = regcache->descr;
1097 gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
1098 regcache_xfer_part (regcache, regnum, offset, len, buf, NULL,
1099 regcache_cooked_read, regcache_cooked_write);
1103 regcache_cooked_write_part (struct regcache *regcache, int regnum,
1104 int offset, int len, const void *buf)
1106 struct regcache_descr *descr = regcache->descr;
1107 gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
1108 regcache_xfer_part (regcache, regnum, offset, len, NULL, buf,
1109 regcache_cooked_read, regcache_cooked_write);
1112 /* Hack to keep code that view the register buffer as raw bytes
1116 register_offset_hack (struct gdbarch *gdbarch, int regnum)
1118 struct regcache_descr *descr = regcache_descr (gdbarch);
1119 gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
1120 return descr->register_offset[regnum];
1123 /* Return the contents of register REGNUM as an unsigned integer. */
1126 read_register (int regnum)
1128 char *buf = alloca (REGISTER_RAW_SIZE (regnum));
1129 deprecated_read_register_gen (regnum, buf);
1130 return (extract_unsigned_integer (buf, REGISTER_RAW_SIZE (regnum)));
1134 read_register_pid (int regnum, ptid_t ptid)
1140 if (ptid_equal (ptid, inferior_ptid))
1141 return read_register (regnum);
1143 save_ptid = inferior_ptid;
1145 inferior_ptid = ptid;
1147 retval = read_register (regnum);
1149 inferior_ptid = save_ptid;
1154 /* Return the contents of register REGNUM as a signed integer. */
1157 read_signed_register (int regnum)
1159 void *buf = alloca (REGISTER_RAW_SIZE (regnum));
1160 deprecated_read_register_gen (regnum, buf);
1161 return (extract_signed_integer (buf, REGISTER_RAW_SIZE (regnum)));
1165 read_signed_register_pid (int regnum, ptid_t ptid)
1170 if (ptid_equal (ptid, inferior_ptid))
1171 return read_signed_register (regnum);
1173 save_ptid = inferior_ptid;
1175 inferior_ptid = ptid;
1177 retval = read_signed_register (regnum);
1179 inferior_ptid = save_ptid;
1184 /* Store VALUE into the raw contents of register number REGNUM. */
1187 write_register (int regnum, LONGEST val)
1191 size = REGISTER_RAW_SIZE (regnum);
1192 buf = alloca (size);
1193 store_signed_integer (buf, size, (LONGEST) val);
1194 deprecated_write_register_gen (regnum, buf);
1198 write_register_pid (int regnum, CORE_ADDR val, ptid_t ptid)
1202 if (ptid_equal (ptid, inferior_ptid))
1204 write_register (regnum, val);
1208 save_ptid = inferior_ptid;
1210 inferior_ptid = ptid;
1212 write_register (regnum, val);
1214 inferior_ptid = save_ptid;
1217 /* SUPPLY_REGISTER()
1219 Record that register REGNUM contains VAL. This is used when the
1220 value is obtained from the inferior or core dump, so there is no
1221 need to store the value there.
1223 If VAL is a NULL pointer, then it's probably an unsupported register.
1224 We just set its value to all zeros. We might want to record this
1225 fact, and report it to the users of read_register and friends. */
1228 supply_register (int regnum, const void *val)
1231 if (! ptid_equal (registers_ptid, inferior_ptid))
1233 registers_changed ();
1234 registers_ptid = inferior_ptid;
1238 set_register_cached (regnum, 1);
1240 memcpy (register_buffer (current_regcache, regnum), val,
1241 REGISTER_RAW_SIZE (regnum));
1243 memset (register_buffer (current_regcache, regnum), '\000',
1244 REGISTER_RAW_SIZE (regnum));
1246 /* On some architectures, e.g. HPPA, there are a few stray bits in
1247 some registers, that the rest of the code would like to ignore. */
1249 /* NOTE: cagney/2001-03-16: The macro CLEAN_UP_REGISTER_VALUE is
1250 going to be deprecated. Instead architectures will leave the raw
1251 register value as is and instead clean things up as they pass
1252 through the method gdbarch_pseudo_register_read() clean up the
1255 #ifdef DEPRECATED_CLEAN_UP_REGISTER_VALUE
1256 DEPRECATED_CLEAN_UP_REGISTER_VALUE \
1257 (regnum, register_buffer (current_regcache, regnum));
1262 regcache_collect (int regnum, void *buf)
1264 memcpy (buf, register_buffer (current_regcache, regnum),
1265 REGISTER_RAW_SIZE (regnum));
1269 /* read_pc, write_pc, read_sp, write_sp, read_fp, etc. Special
1270 handling for registers PC, SP, and FP. */
1272 /* NOTE: cagney/2001-02-18: The functions generic_target_read_pc(),
1273 read_pc_pid(), read_pc(), generic_target_write_pc(),
1274 write_pc_pid(), write_pc(), generic_target_read_sp(), read_sp(),
1275 generic_target_write_sp(), write_sp(), generic_target_read_fp() and
1276 read_fp(), will eventually be moved out of the reg-cache into
1277 either frame.[hc] or to the multi-arch framework. The are not part
1278 of the raw register cache. */
1280 /* This routine is getting awfully cluttered with #if's. It's probably
1281 time to turn this into READ_PC and define it in the tm.h file.
1284 1999-06-08: The following were re-written so that it assumes the
1285 existence of a TARGET_READ_PC et.al. macro. A default generic
1286 version of that macro is made available where needed.
1288 Since the ``TARGET_READ_PC'' et.al. macro is going to be controlled
1289 by the multi-arch framework, it will eventually be possible to
1290 eliminate the intermediate read_pc_pid(). The client would call
1291 TARGET_READ_PC directly. (cagney). */
1294 generic_target_read_pc (ptid_t ptid)
1299 CORE_ADDR pc_val = ADDR_BITS_REMOVE ((CORE_ADDR) read_register_pid (PC_REGNUM, ptid));
1303 internal_error (__FILE__, __LINE__,
1304 "generic_target_read_pc");
1309 read_pc_pid (ptid_t ptid)
1311 ptid_t saved_inferior_ptid;
1314 /* In case ptid != inferior_ptid. */
1315 saved_inferior_ptid = inferior_ptid;
1316 inferior_ptid = ptid;
1318 pc_val = TARGET_READ_PC (ptid);
1320 inferior_ptid = saved_inferior_ptid;
1327 return read_pc_pid (inferior_ptid);
1331 generic_target_write_pc (CORE_ADDR pc, ptid_t ptid)
1335 write_register_pid (PC_REGNUM, pc, ptid);
1336 if (NPC_REGNUM >= 0)
1337 write_register_pid (NPC_REGNUM, pc + 4, ptid);
1339 internal_error (__FILE__, __LINE__,
1340 "generic_target_write_pc");
1345 write_pc_pid (CORE_ADDR pc, ptid_t ptid)
1347 ptid_t saved_inferior_ptid;
1349 /* In case ptid != inferior_ptid. */
1350 saved_inferior_ptid = inferior_ptid;
1351 inferior_ptid = ptid;
1353 TARGET_WRITE_PC (pc, ptid);
1355 inferior_ptid = saved_inferior_ptid;
1359 write_pc (CORE_ADDR pc)
1361 write_pc_pid (pc, inferior_ptid);
1364 /* Cope with strage ways of getting to the stack and frame pointers */
1367 generic_target_read_sp (void)
1371 return read_register (SP_REGNUM);
1373 internal_error (__FILE__, __LINE__,
1374 "generic_target_read_sp");
1380 return TARGET_READ_SP ();
1384 generic_target_write_sp (CORE_ADDR val)
1389 write_register (SP_REGNUM, val);
1393 internal_error (__FILE__, __LINE__,
1394 "generic_target_write_sp");
1398 write_sp (CORE_ADDR val)
1400 TARGET_WRITE_SP (val);
1404 generic_target_read_fp (void)
1408 return read_register (FP_REGNUM);
1410 internal_error (__FILE__, __LINE__,
1411 "generic_target_read_fp");
1417 return TARGET_READ_FP ();
1422 reg_flush_command (char *command, int from_tty)
1424 /* Force-flush the register cache. */
1425 registers_changed ();
1427 printf_filtered ("Register cache flushed.\n");
1431 build_regcache (void)
1433 current_regcache = regcache_xmalloc (current_gdbarch);
1434 current_regcache->readonly_p = 0;
1435 deprecated_registers = deprecated_grub_regcache_for_registers (current_regcache);
1436 deprecated_register_valid = deprecated_grub_regcache_for_register_valid (current_regcache);
1440 dump_endian_bytes (struct ui_file *file, enum bfd_endian endian,
1441 const unsigned char *buf, long len)
1446 case BFD_ENDIAN_BIG:
1447 for (i = 0; i < len; i++)
1448 fprintf_unfiltered (file, "%02x", buf[i]);
1450 case BFD_ENDIAN_LITTLE:
1451 for (i = len - 1; i >= 0; i--)
1452 fprintf_unfiltered (file, "%02x", buf[i]);
1455 internal_error (__FILE__, __LINE__, "Bad switch");
1459 enum regcache_dump_what
1461 regcache_dump_none, regcache_dump_raw, regcache_dump_cooked, regcache_dump_groups
1465 regcache_dump (struct regcache *regcache, struct ui_file *file,
1466 enum regcache_dump_what what_to_dump)
1468 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
1469 struct gdbarch *gdbarch = regcache->descr->gdbarch;
1470 struct reggroup *const *groups = reggroups (gdbarch);
1472 int footnote_nr = 0;
1473 int footnote_register_size = 0;
1474 int footnote_register_offset = 0;
1475 int footnote_register_type_name_null = 0;
1476 long register_offset = 0;
1477 unsigned char *buf = alloca (regcache->descr->max_register_size);
1480 fprintf_unfiltered (file, "legacy_p %d\n", regcache->descr->legacy_p);
1481 fprintf_unfiltered (file, "nr_raw_registers %d\n",
1482 regcache->descr->nr_raw_registers);
1483 fprintf_unfiltered (file, "nr_cooked_registers %d\n",
1484 regcache->descr->nr_cooked_registers);
1485 fprintf_unfiltered (file, "sizeof_raw_registers %ld\n",
1486 regcache->descr->sizeof_raw_registers);
1487 fprintf_unfiltered (file, "sizeof_raw_register_valid_p %ld\n",
1488 regcache->descr->sizeof_raw_register_valid_p);
1489 fprintf_unfiltered (file, "max_register_size %ld\n",
1490 regcache->descr->max_register_size);
1491 fprintf_unfiltered (file, "NUM_REGS %d\n", NUM_REGS);
1492 fprintf_unfiltered (file, "NUM_PSEUDO_REGS %d\n", NUM_PSEUDO_REGS);
1495 gdb_assert (regcache->descr->nr_cooked_registers
1496 == (NUM_REGS + NUM_PSEUDO_REGS));
1498 for (regnum = -1; regnum < regcache->descr->nr_cooked_registers; regnum++)
1502 fprintf_unfiltered (file, " %-10s", "Name");
1505 const char *p = REGISTER_NAME (regnum);
1508 else if (p[0] == '\0')
1510 fprintf_unfiltered (file, " %-10s", p);
1515 fprintf_unfiltered (file, " %4s", "Nr");
1517 fprintf_unfiltered (file, " %4d", regnum);
1519 /* Relative number. */
1521 fprintf_unfiltered (file, " %4s", "Rel");
1522 else if (regnum < NUM_REGS)
1523 fprintf_unfiltered (file, " %4d", regnum);
1525 fprintf_unfiltered (file, " %4d", (regnum - NUM_REGS));
1529 fprintf_unfiltered (file, " %6s ", "Offset");
1532 fprintf_unfiltered (file, " %6ld",
1533 regcache->descr->register_offset[regnum]);
1534 if (register_offset != regcache->descr->register_offset[regnum]
1535 || register_offset != REGISTER_BYTE (regnum)
1537 && (regcache->descr->register_offset[regnum]
1538 != (regcache->descr->register_offset[regnum - 1]
1539 + regcache->descr->sizeof_register[regnum - 1])))
1542 if (!footnote_register_offset)
1543 footnote_register_offset = ++footnote_nr;
1544 fprintf_unfiltered (file, "*%d", footnote_register_offset);
1547 fprintf_unfiltered (file, " ");
1548 register_offset = (regcache->descr->register_offset[regnum]
1549 + regcache->descr->sizeof_register[regnum]);
1554 fprintf_unfiltered (file, " %5s ", "Size");
1557 fprintf_unfiltered (file, " %5ld",
1558 regcache->descr->sizeof_register[regnum]);
1559 if ((regcache->descr->sizeof_register[regnum]
1560 != REGISTER_RAW_SIZE (regnum))
1561 || (regcache->descr->sizeof_register[regnum]
1562 != REGISTER_VIRTUAL_SIZE (regnum))
1563 || (regcache->descr->sizeof_register[regnum]
1564 != TYPE_LENGTH (register_type (regcache->descr->gdbarch,
1568 if (!footnote_register_size)
1569 footnote_register_size = ++footnote_nr;
1570 fprintf_unfiltered (file, "*%d", footnote_register_size);
1573 fprintf_unfiltered (file, " ");
1583 static const char blt[] = "builtin_type";
1584 t = TYPE_NAME (register_type (regcache->descr->gdbarch, regnum));
1588 if (!footnote_register_type_name_null)
1589 footnote_register_type_name_null = ++footnote_nr;
1590 xasprintf (&n, "*%d", footnote_register_type_name_null);
1591 make_cleanup (xfree, n);
1594 /* Chop a leading builtin_type. */
1595 if (strncmp (t, blt, strlen (blt)) == 0)
1598 fprintf_unfiltered (file, " %-15s", t);
1601 /* Leading space always present. */
1602 fprintf_unfiltered (file, " ");
1605 if (what_to_dump == regcache_dump_raw)
1608 fprintf_unfiltered (file, "Raw value");
1609 else if (regnum >= regcache->descr->nr_raw_registers)
1610 fprintf_unfiltered (file, "<cooked>");
1611 else if (!regcache_valid_p (regcache, regnum))
1612 fprintf_unfiltered (file, "<invalid>");
1615 regcache_raw_read (regcache, regnum, buf);
1616 fprintf_unfiltered (file, "0x");
1617 dump_endian_bytes (file, TARGET_BYTE_ORDER, buf,
1618 REGISTER_RAW_SIZE (regnum));
1622 /* Value, cooked. */
1623 if (what_to_dump == regcache_dump_cooked)
1626 fprintf_unfiltered (file, "Cooked value");
1629 regcache_cooked_read (regcache, regnum, buf);
1630 fprintf_unfiltered (file, "0x");
1631 dump_endian_bytes (file, TARGET_BYTE_ORDER, buf,
1632 REGISTER_VIRTUAL_SIZE (regnum));
1636 /* Group members. */
1637 if (what_to_dump == regcache_dump_groups)
1640 fprintf_unfiltered (file, "Groups");
1644 const char *sep = "";
1645 for (i = 0; groups[i] != NULL; i++)
1647 if (gdbarch_register_reggroup_p (gdbarch, regnum, groups[i]))
1649 fprintf_unfiltered (file, "%s%s", sep, reggroup_name (groups[i]));
1656 fprintf_unfiltered (file, "\n");
1659 if (footnote_register_size)
1660 fprintf_unfiltered (file, "*%d: Inconsistent register sizes.\n",
1661 footnote_register_size);
1662 if (footnote_register_offset)
1663 fprintf_unfiltered (file, "*%d: Inconsistent register offsets.\n",
1664 footnote_register_offset);
1665 if (footnote_register_type_name_null)
1666 fprintf_unfiltered (file,
1667 "*%d: Register type's name NULL.\n",
1668 footnote_register_type_name_null);
1669 do_cleanups (cleanups);
1673 regcache_print (char *args, enum regcache_dump_what what_to_dump)
1676 regcache_dump (current_regcache, gdb_stdout, what_to_dump);
1679 struct ui_file *file = gdb_fopen (args, "w");
1681 perror_with_name ("maintenance print architecture");
1682 regcache_dump (current_regcache, file, what_to_dump);
1683 ui_file_delete (file);
1688 maintenance_print_registers (char *args, int from_tty)
1690 regcache_print (args, regcache_dump_none);
1694 maintenance_print_raw_registers (char *args, int from_tty)
1696 regcache_print (args, regcache_dump_raw);
1700 maintenance_print_cooked_registers (char *args, int from_tty)
1702 regcache_print (args, regcache_dump_cooked);
1706 maintenance_print_register_groups (char *args, int from_tty)
1708 regcache_print (args, regcache_dump_groups);
1712 _initialize_regcache (void)
1714 regcache_descr_handle = register_gdbarch_data (init_regcache_descr,
1715 xfree_regcache_descr);
1716 REGISTER_GDBARCH_SWAP (current_regcache);
1717 register_gdbarch_swap (&deprecated_registers, sizeof (deprecated_registers), NULL);
1718 register_gdbarch_swap (&deprecated_register_valid, sizeof (deprecated_register_valid), NULL);
1719 register_gdbarch_swap (NULL, 0, build_regcache);
1721 add_com ("flushregs", class_maintenance, reg_flush_command,
1722 "Force gdb to flush its register cache (maintainer command)");
1724 /* Initialize the thread/process associated with the current set of
1725 registers. For now, -1 is special, and means `no current process'. */
1726 registers_ptid = pid_to_ptid (-1);
1728 add_cmd ("registers", class_maintenance,
1729 maintenance_print_registers,
1730 "Print the internal register configuration.\
1731 Takes an optional file parameter.",
1732 &maintenanceprintlist);
1733 add_cmd ("raw-registers", class_maintenance,
1734 maintenance_print_raw_registers,
1735 "Print the internal register configuration including raw values.\
1736 Takes an optional file parameter.",
1737 &maintenanceprintlist);
1738 add_cmd ("cooked-registers", class_maintenance,
1739 maintenance_print_cooked_registers,
1740 "Print the internal register configuration including cooked values.\
1741 Takes an optional file parameter.",
1742 &maintenanceprintlist);
1743 add_cmd ("register-groups", class_maintenance,
1744 maintenance_print_register_groups,
1745 "Print the internal register configuration including each register's group.\
1746 Takes an optional file parameter.",
1747 &maintenanceprintlist);