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. 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
60 long sizeof_raw_registers;
61 long sizeof_raw_register_valid_p;
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;
70 long sizeof_cooked_registers;
71 long sizeof_cooked_register_valid_p;
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. */
79 long *register_offset;
80 long *sizeof_register;
82 /* Cached table containing the type of each register. */
83 struct type **register_type;
87 init_legacy_regcache_descr (struct gdbarch *gdbarch,
88 struct regcache_descr *descr)
91 /* FIXME: cagney/2002-05-11: gdbarch_data() should take that
92 ``gdbarch'' as a parameter. */
93 gdb_assert (gdbarch != NULL);
95 /* Compute the offset of each register. Legacy architectures define
96 DEPRECATED_REGISTER_BYTE() so use that. */
97 /* FIXME: cagney/2002-11-07: Instead of using
98 DEPRECATED_REGISTER_BYTE() this code should, as is done in
99 init_regcache_descr(), compute the offets at runtime. This
100 currently isn't possible as some ISAs define overlapping register
101 regions - see the mess in read_register_bytes() and
102 write_register_bytes() registers. */
103 descr->sizeof_register
104 = GDBARCH_OBSTACK_CALLOC (gdbarch, descr->nr_cooked_registers, long);
105 descr->register_offset
106 = GDBARCH_OBSTACK_CALLOC (gdbarch, descr->nr_cooked_registers, long);
107 for (i = 0; i < descr->nr_cooked_registers; i++)
109 /* FIXME: cagney/2001-12-04: This code shouldn't need to use
110 DEPRECATED_REGISTER_BYTE(). Unfortunatly, legacy code likes
111 to lay the buffer out so that certain registers just happen
112 to overlap. Ulgh! New targets use gdbarch's register
113 read/write and entirely avoid this uglyness. */
114 descr->register_offset[i] = DEPRECATED_REGISTER_BYTE (i);
115 descr->sizeof_register[i] = REGISTER_RAW_SIZE (i);
116 gdb_assert (MAX_REGISTER_SIZE >= REGISTER_RAW_SIZE (i));
117 gdb_assert (MAX_REGISTER_SIZE >= REGISTER_VIRTUAL_SIZE (i));
120 /* Compute the real size of the register buffer. Start out by
121 trusting DEPRECATED_REGISTER_BYTES, but then adjust it upwards
122 should that be found to not be sufficient. */
123 /* FIXME: cagney/2002-11-05: Instead of using the macro
124 DEPRECATED_REGISTER_BYTES, this code should, as is done in
125 init_regcache_descr(), compute the total number of register bytes
126 using the accumulated offsets. */
127 descr->sizeof_cooked_registers = DEPRECATED_REGISTER_BYTES; /* OK */
128 for (i = 0; i < descr->nr_cooked_registers; i++)
131 /* Keep extending the buffer so that there is always enough
132 space for all registers. The comparison is necessary since
133 legacy code is free to put registers in random places in the
134 buffer separated by holes. Once DEPRECATED_REGISTER_BYTE()
135 is killed this can be greatly simplified. */
136 regend = descr->register_offset[i] + descr->sizeof_register[i];
137 if (descr->sizeof_cooked_registers < regend)
138 descr->sizeof_cooked_registers = regend;
140 /* FIXME: cagney/2002-05-11: Shouldn't be including pseudo-registers
141 in the register cache. Unfortunatly some architectures still
142 rely on this and the pseudo_register_write() method. */
143 descr->sizeof_raw_registers = descr->sizeof_cooked_registers;
147 init_regcache_descr (struct gdbarch *gdbarch)
150 struct regcache_descr *descr;
151 gdb_assert (gdbarch != NULL);
153 /* Create an initial, zero filled, table. */
154 descr = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct regcache_descr);
155 descr->gdbarch = gdbarch;
157 /* Total size of the register space. The raw registers are mapped
158 directly onto the raw register cache while the pseudo's are
159 either mapped onto raw-registers or memory. */
160 descr->nr_cooked_registers = NUM_REGS + NUM_PSEUDO_REGS;
161 descr->sizeof_cooked_register_valid_p = NUM_REGS + NUM_PSEUDO_REGS;
163 /* Fill in a table of register types. */
165 = GDBARCH_OBSTACK_CALLOC (gdbarch, descr->nr_cooked_registers, struct type *);
166 for (i = 0; i < descr->nr_cooked_registers; i++)
168 if (gdbarch_register_type_p (gdbarch))
170 gdb_assert (!REGISTER_VIRTUAL_TYPE_P ()); /* OK */
171 descr->register_type[i] = gdbarch_register_type (gdbarch, i);
174 descr->register_type[i] = REGISTER_VIRTUAL_TYPE (i); /* OK */
177 /* Construct a strictly RAW register cache. Don't allow pseudo's
178 into the register cache. */
179 descr->nr_raw_registers = NUM_REGS;
181 /* FIXME: cagney/2002-08-13: Overallocate the register_valid_p
182 array. This pretects GDB from erant code that accesses elements
183 of the global register_valid_p[] array in the range [NUM_REGS
184 .. NUM_REGS + NUM_PSEUDO_REGS). */
185 descr->sizeof_raw_register_valid_p = descr->sizeof_cooked_register_valid_p;
187 /* If an old style architecture, fill in the remainder of the
188 register cache descriptor using the register macros. */
189 /* NOTE: cagney/2003-06-29: If either of DEPRECATED_REGISTER_BYTE or
190 REGISTER_RAW_SIZE are still present, things are most likely
191 totally screwed. Ex: an architecture with raw register sizes
192 smaller than what DEPRECATED_REGISTER_BYTE indicates; non
193 monotonic DEPRECATED_REGISTER_BYTE values. For GDB 6 check for
194 these nasty methods and fall back to legacy code when present.
196 if ((!gdbarch_pseudo_register_read_p (gdbarch)
197 && !gdbarch_pseudo_register_write_p (gdbarch)
198 && !gdbarch_register_type_p (gdbarch))
199 || DEPRECATED_REGISTER_BYTE_P () || REGISTER_RAW_SIZE_P ())
202 init_legacy_regcache_descr (gdbarch, descr);
206 /* Lay out the register cache.
208 NOTE: cagney/2002-05-22: Only register_type() is used when
209 constructing the register cache. It is assumed that the
210 register's raw size, virtual size and type length are all the
215 descr->sizeof_register
216 = GDBARCH_OBSTACK_CALLOC (gdbarch, descr->nr_cooked_registers, long);
217 descr->register_offset
218 = GDBARCH_OBSTACK_CALLOC (gdbarch, descr->nr_cooked_registers, long);
219 for (i = 0; i < descr->nr_cooked_registers; i++)
221 descr->sizeof_register[i] = TYPE_LENGTH (descr->register_type[i]);
222 descr->register_offset[i] = offset;
223 offset += descr->sizeof_register[i];
224 gdb_assert (MAX_REGISTER_SIZE >= descr->sizeof_register[i]);
226 /* Set the real size of the register cache buffer. */
227 descr->sizeof_cooked_registers = offset;
230 /* FIXME: cagney/2002-05-22: Should only need to allocate space for
231 the raw registers. Unfortunatly some code still accesses the
232 register array directly using the global registers[]. Until that
233 code has been purged, play safe and over allocating the register
235 descr->sizeof_raw_registers = descr->sizeof_cooked_registers;
237 /* Sanity check. Confirm that there is agreement between the
238 regcache and the target's redundant DEPRECATED_REGISTER_BYTE (new
239 targets should not even be defining it). */
240 for (i = 0; i < descr->nr_cooked_registers; i++)
242 if (DEPRECATED_REGISTER_BYTE_P ())
243 gdb_assert (descr->register_offset[i] == DEPRECATED_REGISTER_BYTE (i));
245 gdb_assert (descr->sizeof_register[i] == REGISTER_RAW_SIZE (i));
246 gdb_assert (descr->sizeof_register[i] == REGISTER_VIRTUAL_SIZE (i));
249 /* gdb_assert (descr->sizeof_raw_registers == DEPRECATED_REGISTER_BYTES (i)); */
254 static struct regcache_descr *
255 regcache_descr (struct gdbarch *gdbarch)
257 return gdbarch_data (gdbarch, regcache_descr_handle);
260 /* Utility functions returning useful register attributes stored in
261 the regcache descr. */
264 register_type (struct gdbarch *gdbarch, int regnum)
266 struct regcache_descr *descr = regcache_descr (gdbarch);
267 gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
268 return descr->register_type[regnum];
271 /* Utility functions returning useful register attributes stored in
272 the regcache descr. */
275 register_size (struct gdbarch *gdbarch, int regnum)
277 struct regcache_descr *descr = regcache_descr (gdbarch);
279 gdb_assert (regnum >= 0 && regnum < (NUM_REGS + NUM_PSEUDO_REGS));
280 size = descr->sizeof_register[regnum];
281 /* NB: The deprecated REGISTER_RAW_SIZE, if not provided, defaults
282 to the size of the register's type. */
283 gdb_assert (size == REGISTER_RAW_SIZE (regnum)); /* OK */
284 /* NB: Don't check the register's virtual size. It, in say the case
285 of the MIPS, may not match the raw size! */
289 /* The register cache for storing raw register values. */
293 struct regcache_descr *descr;
294 /* The register buffers. A read-only register cache can hold the
295 full [0 .. NUM_REGS + NUM_PSEUDO_REGS) while a read/write
296 register cache can only hold [0 .. NUM_REGS). */
298 char *register_valid_p;
299 /* Is this a read-only cache? A read-only cache is used for saving
300 the target's register state (e.g, across an inferior function
301 call or just before forcing a function return). A read-only
302 cache can only be updated via the methods regcache_dup() and
303 regcache_cpy(). The actual contents are determined by the
304 reggroup_save and reggroup_restore methods. */
309 regcache_xmalloc (struct gdbarch *gdbarch)
311 struct regcache_descr *descr;
312 struct regcache *regcache;
313 gdb_assert (gdbarch != NULL);
314 descr = regcache_descr (gdbarch);
315 regcache = XMALLOC (struct regcache);
316 regcache->descr = descr;
318 = XCALLOC (descr->sizeof_raw_registers, char);
319 regcache->register_valid_p
320 = XCALLOC (descr->sizeof_raw_register_valid_p, char);
321 regcache->readonly_p = 1;
326 regcache_xfree (struct regcache *regcache)
328 if (regcache == NULL)
330 xfree (regcache->registers);
331 xfree (regcache->register_valid_p);
336 do_regcache_xfree (void *data)
338 regcache_xfree (data);
342 make_cleanup_regcache_xfree (struct regcache *regcache)
344 return make_cleanup (do_regcache_xfree, regcache);
347 /* Return a pointer to register REGNUM's buffer cache. */
350 register_buffer (const struct regcache *regcache, int regnum)
352 return regcache->registers + regcache->descr->register_offset[regnum];
356 regcache_save (struct regcache *dst, regcache_cooked_read_ftype *cooked_read,
359 struct gdbarch *gdbarch = dst->descr->gdbarch;
360 char buf[MAX_REGISTER_SIZE];
362 /* The DST should be `read-only', if it wasn't then the save would
363 end up trying to write the register values back out to the
365 gdb_assert (dst->readonly_p);
366 /* Clear the dest. */
367 memset (dst->registers, 0, dst->descr->sizeof_cooked_registers);
368 memset (dst->register_valid_p, 0, dst->descr->sizeof_cooked_register_valid_p);
369 /* Copy over any registers (identified by their membership in the
370 save_reggroup) and mark them as valid. The full [0 .. NUM_REGS +
371 NUM_PSEUDO_REGS) range is checked since some architectures need
372 to save/restore `cooked' registers that live in memory. */
373 for (regnum = 0; regnum < dst->descr->nr_cooked_registers; regnum++)
375 if (gdbarch_register_reggroup_p (gdbarch, regnum, save_reggroup))
377 int valid = cooked_read (src, regnum, buf);
380 memcpy (register_buffer (dst, regnum), buf,
381 register_size (gdbarch, regnum));
382 dst->register_valid_p[regnum] = 1;
389 regcache_restore (struct regcache *dst,
390 regcache_cooked_read_ftype *cooked_read,
393 struct gdbarch *gdbarch = dst->descr->gdbarch;
394 char buf[MAX_REGISTER_SIZE];
396 /* The dst had better not be read-only. If it is, the `restore'
397 doesn't make much sense. */
398 gdb_assert (!dst->readonly_p);
399 /* Copy over any registers, being careful to only restore those that
400 were both saved and need to be restored. The full [0 .. NUM_REGS
401 + NUM_PSEUDO_REGS) range is checked since some architectures need
402 to save/restore `cooked' registers that live in memory. */
403 for (regnum = 0; regnum < dst->descr->nr_cooked_registers; regnum++)
405 if (gdbarch_register_reggroup_p (gdbarch, regnum, restore_reggroup))
407 int valid = cooked_read (src, regnum, buf);
409 regcache_cooked_write (dst, regnum, buf);
415 do_cooked_read (void *src, int regnum, void *buf)
417 struct regcache *regcache = src;
418 if (!regcache->register_valid_p[regnum] && regcache->readonly_p)
419 /* Don't even think about fetching a register from a read-only
420 cache when the register isn't yet valid. There isn't a target
421 from which the register value can be fetched. */
423 regcache_cooked_read (regcache, regnum, buf);
429 regcache_cpy (struct regcache *dst, struct regcache *src)
433 gdb_assert (src != NULL && dst != NULL);
434 gdb_assert (src->descr->gdbarch == dst->descr->gdbarch);
435 gdb_assert (src != dst);
436 gdb_assert (src->readonly_p || dst->readonly_p);
437 if (!src->readonly_p)
438 regcache_save (dst, do_cooked_read, src);
439 else if (!dst->readonly_p)
440 regcache_restore (dst, do_cooked_read, src);
442 regcache_cpy_no_passthrough (dst, src);
446 regcache_cpy_no_passthrough (struct regcache *dst, struct regcache *src)
449 gdb_assert (src != NULL && dst != NULL);
450 gdb_assert (src->descr->gdbarch == dst->descr->gdbarch);
451 /* NOTE: cagney/2002-05-17: Don't let the caller do a no-passthrough
452 move of data into the current_regcache(). Doing this would be
453 silly - it would mean that valid_p would be completly invalid. */
454 gdb_assert (dst != current_regcache);
455 memcpy (dst->registers, src->registers, dst->descr->sizeof_raw_registers);
456 memcpy (dst->register_valid_p, src->register_valid_p,
457 dst->descr->sizeof_raw_register_valid_p);
461 regcache_dup (struct regcache *src)
463 struct regcache *newbuf;
464 gdb_assert (current_regcache != NULL);
465 newbuf = regcache_xmalloc (src->descr->gdbarch);
466 regcache_cpy (newbuf, src);
471 regcache_dup_no_passthrough (struct regcache *src)
473 struct regcache *newbuf;
474 gdb_assert (current_regcache != NULL);
475 newbuf = regcache_xmalloc (src->descr->gdbarch);
476 regcache_cpy_no_passthrough (newbuf, src);
481 regcache_valid_p (struct regcache *regcache, int regnum)
483 gdb_assert (regcache != NULL);
484 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
485 return regcache->register_valid_p[regnum];
489 deprecated_grub_regcache_for_registers (struct regcache *regcache)
491 return regcache->registers;
494 /* Global structure containing the current regcache. */
495 /* FIXME: cagney/2002-05-11: The two global arrays registers[] and
496 deprecated_register_valid[] currently point into this structure. */
497 struct regcache *current_regcache;
499 /* NOTE: this is a write-through cache. There is no "dirty" bit for
500 recording if the register values have been changed (eg. by the
501 user). Therefore all registers must be written back to the
502 target when appropriate. */
504 /* REGISTERS contains the cached register values (in target byte order). */
506 char *deprecated_registers;
508 /* DEPRECATED_REGISTER_VALID is 0 if the register needs to be fetched,
509 1 if it has been fetched, and
510 -1 if the register value was not available.
512 "Not available" indicates that the target is not not able to supply
513 the register at this state. The register may become available at a
514 later time (after the next resume). This often occures when GDB is
515 manipulating a target that contains only a snapshot of the entire
516 system being debugged - some of the registers in such a system may
517 not have been saved. */
519 signed char *deprecated_register_valid;
521 /* The thread/process associated with the current set of registers. */
523 static ptid_t registers_ptid;
531 Returns 0 if the value is not in the cache (needs fetch).
532 >0 if the value is in the cache.
533 <0 if the value is permanently unavailable (don't ask again). */
536 register_cached (int regnum)
538 return deprecated_register_valid[regnum];
541 /* Record that REGNUM's value is cached if STATE is >0, uncached but
542 fetchable if STATE is 0, and uncached and unfetchable if STATE is <0. */
545 set_register_cached (int regnum, int state)
547 gdb_assert (regnum >= 0);
548 gdb_assert (regnum < current_regcache->descr->nr_raw_registers);
549 current_regcache->register_valid_p[regnum] = state;
552 /* Return whether register REGNUM is a real register. */
555 real_register (int regnum)
557 return regnum >= 0 && regnum < NUM_REGS;
560 /* Low level examining and depositing of registers.
562 The caller is responsible for making sure that the inferior is
563 stopped before calling the fetching routines, or it will get
564 garbage. (a change from GDB version 3, in which the caller got the
565 value from the last stop). */
567 /* REGISTERS_CHANGED ()
569 Indicate that registers may have changed, so invalidate the cache. */
572 registers_changed (void)
576 registers_ptid = pid_to_ptid (-1);
578 /* Force cleanup of any alloca areas if using C alloca instead of
579 a builtin alloca. This particular call is used to clean up
580 areas allocated by low level target code which may build up
581 during lengthy interactions between gdb and the target before
582 gdb gives control to the user (ie watchpoints). */
585 for (i = 0; i < current_regcache->descr->nr_raw_registers; i++)
586 set_register_cached (i, 0);
588 if (registers_changed_hook)
589 registers_changed_hook ();
592 /* DEPRECATED_REGISTERS_FETCHED ()
594 Indicate that all registers have been fetched, so mark them all valid. */
596 /* NOTE: cagney/2001-12-04: This function does not set valid on the
597 pseudo-register range since pseudo registers are always supplied
598 using supply_register(). */
599 /* FIXME: cagney/2001-12-04: This function is DEPRECATED. The target
600 code was blatting the registers[] array and then calling this.
601 Since targets should only be using supply_register() the need for
602 this function/hack is eliminated. */
605 deprecated_registers_fetched (void)
609 for (i = 0; i < NUM_REGS; i++)
610 set_register_cached (i, 1);
611 /* Do not assume that the pseudo-regs have also been fetched.
612 Fetching all real regs NEVER accounts for pseudo-regs. */
615 /* deprecated_read_register_bytes and deprecated_write_register_bytes
616 are generally a *BAD* idea. They are inefficient because they need
617 to check for partial updates, which can only be done by scanning
618 through all of the registers and seeing if the bytes that are being
619 read/written fall inside of an invalid register. [The main reason
620 this is necessary is that register sizes can vary, so a simple
621 index won't suffice.] It is far better to call read_register_gen
622 and write_register_gen if you want to get at the raw register
623 contents, as it only takes a regnum as an argument, and therefore
624 can't do a partial register update.
626 Prior to the recent fixes to check for partial updates, both read
627 and deprecated_write_register_bytes always checked to see if any
628 registers were stale, and then called target_fetch_registers (-1)
629 to update the whole set. This caused really slowed things down for
632 /* Copy INLEN bytes of consecutive data from registers
633 starting with the INREGBYTE'th byte of register data
634 into memory at MYADDR. */
637 deprecated_read_register_bytes (int in_start, char *in_buf, int in_len)
639 int in_end = in_start + in_len;
641 char reg_buf[MAX_REGISTER_SIZE];
643 /* See if we are trying to read bytes from out-of-date registers. If so,
644 update just those registers. */
646 for (regnum = 0; regnum < NUM_REGS + NUM_PSEUDO_REGS; regnum++)
655 reg_start = DEPRECATED_REGISTER_BYTE (regnum);
656 reg_len = REGISTER_RAW_SIZE (regnum);
657 reg_end = reg_start + reg_len;
659 if (reg_end <= in_start || in_end <= reg_start)
660 /* The range the user wants to read doesn't overlap with regnum. */
663 if (REGISTER_NAME (regnum) != NULL && *REGISTER_NAME (regnum) != '\0')
664 /* Force the cache to fetch the entire register. */
665 deprecated_read_register_gen (regnum, reg_buf);
667 /* Legacy note: even though this register is ``invalid'' we
668 still need to return something. It would appear that some
669 code relies on apparent gaps in the register array also
671 /* FIXME: cagney/2001-08-18: This is just silly. It defeats
672 the entire register read/write flow of control. Must
673 resist temptation to return 0xdeadbeef. */
674 memcpy (reg_buf, &deprecated_registers[reg_start], reg_len);
676 /* Legacy note: This function, for some reason, allows a NULL
677 input buffer. If the buffer is NULL, the registers are still
678 fetched, just the final transfer is skipped. */
682 /* start = max (reg_start, in_start) */
683 if (reg_start > in_start)
688 /* end = min (reg_end, in_end) */
689 if (reg_end < in_end)
694 /* Transfer just the bytes common to both IN_BUF and REG_BUF */
695 for (byte = start; byte < end; byte++)
697 in_buf[byte - in_start] = reg_buf[byte - reg_start];
702 /* Read register REGNUM into memory at MYADDR, which must be large
703 enough for REGISTER_RAW_BYTES (REGNUM). Target byte-order. If the
704 register is known to be the size of a CORE_ADDR or smaller,
705 read_register can be used instead. */
708 legacy_read_register_gen (int regnum, char *myaddr)
710 gdb_assert (regnum >= 0 && regnum < (NUM_REGS + NUM_PSEUDO_REGS));
711 if (! ptid_equal (registers_ptid, inferior_ptid))
713 registers_changed ();
714 registers_ptid = inferior_ptid;
717 if (!register_cached (regnum))
718 target_fetch_registers (regnum);
720 memcpy (myaddr, register_buffer (current_regcache, regnum),
721 REGISTER_RAW_SIZE (regnum));
725 regcache_raw_read (struct regcache *regcache, int regnum, void *buf)
727 gdb_assert (regcache != NULL && buf != NULL);
728 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
729 if (regcache->descr->legacy_p
730 && !regcache->readonly_p)
732 gdb_assert (regcache == current_regcache);
733 /* For moment, just use underlying legacy code. Ulgh!!! This
734 silently and very indirectly updates the regcache's regcache
735 via the global deprecated_register_valid[]. */
736 legacy_read_register_gen (regnum, buf);
739 /* Make certain that the register cache is up-to-date with respect
740 to the current thread. This switching shouldn't be necessary
741 only there is still only one target side register cache. Sigh!
742 On the bright side, at least there is a regcache object. */
743 if (!regcache->readonly_p)
745 gdb_assert (regcache == current_regcache);
746 if (! ptid_equal (registers_ptid, inferior_ptid))
748 registers_changed ();
749 registers_ptid = inferior_ptid;
751 if (!register_cached (regnum))
752 target_fetch_registers (regnum);
754 /* Copy the value directly into the register cache. */
755 memcpy (buf, register_buffer (regcache, regnum),
756 regcache->descr->sizeof_register[regnum]);
760 regcache_raw_read_signed (struct regcache *regcache, int regnum, LONGEST *val)
763 gdb_assert (regcache != NULL);
764 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
765 buf = alloca (regcache->descr->sizeof_register[regnum]);
766 regcache_raw_read (regcache, regnum, buf);
767 (*val) = extract_signed_integer (buf,
768 regcache->descr->sizeof_register[regnum]);
772 regcache_raw_read_unsigned (struct regcache *regcache, int regnum,
776 gdb_assert (regcache != NULL);
777 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
778 buf = alloca (regcache->descr->sizeof_register[regnum]);
779 regcache_raw_read (regcache, regnum, buf);
780 (*val) = extract_unsigned_integer (buf,
781 regcache->descr->sizeof_register[regnum]);
785 regcache_raw_write_signed (struct regcache *regcache, int regnum, LONGEST val)
788 gdb_assert (regcache != NULL);
789 gdb_assert (regnum >=0 && regnum < regcache->descr->nr_raw_registers);
790 buf = alloca (regcache->descr->sizeof_register[regnum]);
791 store_signed_integer (buf, regcache->descr->sizeof_register[regnum], val);
792 regcache_raw_write (regcache, regnum, buf);
796 regcache_raw_write_unsigned (struct regcache *regcache, int regnum,
800 gdb_assert (regcache != NULL);
801 gdb_assert (regnum >=0 && regnum < regcache->descr->nr_raw_registers);
802 buf = alloca (regcache->descr->sizeof_register[regnum]);
803 store_unsigned_integer (buf, regcache->descr->sizeof_register[regnum], val);
804 regcache_raw_write (regcache, regnum, buf);
808 deprecated_read_register_gen (int regnum, char *buf)
810 gdb_assert (current_regcache != NULL);
811 gdb_assert (current_regcache->descr->gdbarch == current_gdbarch);
812 if (current_regcache->descr->legacy_p)
814 legacy_read_register_gen (regnum, buf);
817 regcache_cooked_read (current_regcache, regnum, buf);
821 regcache_cooked_read (struct regcache *regcache, int regnum, void *buf)
823 gdb_assert (regnum >= 0);
824 gdb_assert (regnum < regcache->descr->nr_cooked_registers);
825 if (regnum < regcache->descr->nr_raw_registers)
826 regcache_raw_read (regcache, regnum, buf);
827 else if (regcache->readonly_p
828 && regnum < regcache->descr->nr_cooked_registers
829 && regcache->register_valid_p[regnum])
830 /* Read-only register cache, perhaphs the cooked value was cached? */
831 memcpy (buf, register_buffer (regcache, regnum),
832 regcache->descr->sizeof_register[regnum]);
834 gdbarch_pseudo_register_read (regcache->descr->gdbarch, regcache,
839 regcache_cooked_read_signed (struct regcache *regcache, int regnum,
843 gdb_assert (regcache != NULL);
844 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_cooked_registers);
845 buf = alloca (regcache->descr->sizeof_register[regnum]);
846 regcache_cooked_read (regcache, regnum, buf);
847 (*val) = extract_signed_integer (buf,
848 regcache->descr->sizeof_register[regnum]);
852 regcache_cooked_read_unsigned (struct regcache *regcache, int regnum,
856 gdb_assert (regcache != NULL);
857 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_cooked_registers);
858 buf = alloca (regcache->descr->sizeof_register[regnum]);
859 regcache_cooked_read (regcache, regnum, buf);
860 (*val) = extract_unsigned_integer (buf,
861 regcache->descr->sizeof_register[regnum]);
865 regcache_cooked_write_signed (struct regcache *regcache, int regnum,
869 gdb_assert (regcache != NULL);
870 gdb_assert (regnum >=0 && regnum < regcache->descr->nr_cooked_registers);
871 buf = alloca (regcache->descr->sizeof_register[regnum]);
872 store_signed_integer (buf, regcache->descr->sizeof_register[regnum], val);
873 regcache_cooked_write (regcache, regnum, buf);
877 regcache_cooked_write_unsigned (struct regcache *regcache, int regnum,
881 gdb_assert (regcache != NULL);
882 gdb_assert (regnum >=0 && regnum < regcache->descr->nr_cooked_registers);
883 buf = alloca (regcache->descr->sizeof_register[regnum]);
884 store_unsigned_integer (buf, regcache->descr->sizeof_register[regnum], val);
885 regcache_cooked_write (regcache, regnum, buf);
888 /* Write register REGNUM at MYADDR to the target. MYADDR points at
889 REGISTER_RAW_BYTES(REGNUM), which must be in target byte-order. */
892 legacy_write_register_gen (int regnum, const void *myaddr)
895 gdb_assert (regnum >= 0 && regnum < (NUM_REGS + NUM_PSEUDO_REGS));
897 /* On the sparc, writing %g0 is a no-op, so we don't even want to
898 change the registers array if something writes to this register. */
899 if (CANNOT_STORE_REGISTER (regnum))
902 if (! ptid_equal (registers_ptid, inferior_ptid))
904 registers_changed ();
905 registers_ptid = inferior_ptid;
908 size = REGISTER_RAW_SIZE (regnum);
910 if (real_register (regnum))
912 /* If we have a valid copy of the register, and new value == old
913 value, then don't bother doing the actual store. */
914 if (register_cached (regnum)
915 && (memcmp (register_buffer (current_regcache, regnum), myaddr, size)
919 target_prepare_to_store ();
922 memcpy (register_buffer (current_regcache, regnum), myaddr, size);
924 set_register_cached (regnum, 1);
925 target_store_registers (regnum);
929 regcache_raw_write (struct regcache *regcache, int regnum, const void *buf)
931 gdb_assert (regcache != NULL && buf != NULL);
932 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
933 gdb_assert (!regcache->readonly_p);
935 if (regcache->descr->legacy_p)
937 /* For moment, just use underlying legacy code. Ulgh!!! This
938 silently and very indirectly updates the regcache's buffers
939 via the globals deprecated_register_valid[] and registers[]. */
940 gdb_assert (regcache == current_regcache);
941 legacy_write_register_gen (regnum, buf);
945 /* On the sparc, writing %g0 is a no-op, so we don't even want to
946 change the registers array if something writes to this register. */
947 if (CANNOT_STORE_REGISTER (regnum))
950 /* Make certain that the correct cache is selected. */
951 gdb_assert (regcache == current_regcache);
952 if (! ptid_equal (registers_ptid, inferior_ptid))
954 registers_changed ();
955 registers_ptid = inferior_ptid;
958 /* If we have a valid copy of the register, and new value == old
959 value, then don't bother doing the actual store. */
960 if (regcache_valid_p (regcache, regnum)
961 && (memcmp (register_buffer (regcache, regnum), buf,
962 regcache->descr->sizeof_register[regnum]) == 0))
965 target_prepare_to_store ();
966 memcpy (register_buffer (regcache, regnum), buf,
967 regcache->descr->sizeof_register[regnum]);
968 regcache->register_valid_p[regnum] = 1;
969 target_store_registers (regnum);
973 deprecated_write_register_gen (int regnum, char *buf)
975 gdb_assert (current_regcache != NULL);
976 gdb_assert (current_regcache->descr->gdbarch == current_gdbarch);
977 if (current_regcache->descr->legacy_p)
979 legacy_write_register_gen (regnum, buf);
982 regcache_cooked_write (current_regcache, regnum, buf);
986 regcache_cooked_write (struct regcache *regcache, int regnum, const void *buf)
988 gdb_assert (regnum >= 0);
989 gdb_assert (regnum < regcache->descr->nr_cooked_registers);
990 if (regnum < regcache->descr->nr_raw_registers)
991 regcache_raw_write (regcache, regnum, buf);
993 gdbarch_pseudo_register_write (regcache->descr->gdbarch, regcache,
997 /* Copy INLEN bytes of consecutive data from memory at MYADDR
998 into registers starting with the MYREGSTART'th byte of register data. */
1001 deprecated_write_register_bytes (int myregstart, char *myaddr, int inlen)
1003 int myregend = myregstart + inlen;
1006 target_prepare_to_store ();
1008 /* Scan through the registers updating any that are covered by the
1009 range myregstart<=>myregend using write_register_gen, which does
1010 nice things like handling threads, and avoiding updates when the
1011 new and old contents are the same. */
1013 for (regnum = 0; regnum < NUM_REGS + NUM_PSEUDO_REGS; regnum++)
1015 int regstart, regend;
1017 regstart = DEPRECATED_REGISTER_BYTE (regnum);
1018 regend = regstart + REGISTER_RAW_SIZE (regnum);
1020 /* Is this register completely outside the range the user is writing? */
1021 if (myregend <= regstart || regend <= myregstart)
1024 /* Is this register completely within the range the user is writing? */
1025 else if (myregstart <= regstart && regend <= myregend)
1026 deprecated_write_register_gen (regnum, myaddr + (regstart - myregstart));
1028 /* The register partially overlaps the range being written. */
1031 char regbuf[MAX_REGISTER_SIZE];
1032 /* What's the overlap between this register's bytes and
1033 those the caller wants to write? */
1034 int overlapstart = max (regstart, myregstart);
1035 int overlapend = min (regend, myregend);
1037 /* We may be doing a partial update of an invalid register.
1038 Update it from the target before scribbling on it. */
1039 deprecated_read_register_gen (regnum, regbuf);
1041 memcpy (&deprecated_registers[overlapstart],
1042 myaddr + (overlapstart - myregstart),
1043 overlapend - overlapstart);
1045 target_store_registers (regnum);
1050 /* Perform a partial register transfer using a read, modify, write
1053 typedef void (regcache_read_ftype) (struct regcache *regcache, int regnum,
1055 typedef void (regcache_write_ftype) (struct regcache *regcache, int regnum,
1059 regcache_xfer_part (struct regcache *regcache, int regnum,
1060 int offset, int len, void *in, const void *out,
1061 regcache_read_ftype *read, regcache_write_ftype *write)
1063 struct regcache_descr *descr = regcache->descr;
1064 bfd_byte reg[MAX_REGISTER_SIZE];
1065 gdb_assert (offset >= 0 && offset <= descr->sizeof_register[regnum]);
1066 gdb_assert (len >= 0 && offset + len <= descr->sizeof_register[regnum]);
1067 /* Something to do? */
1068 if (offset + len == 0)
1070 /* Read (when needed) ... */
1073 || offset + len < descr->sizeof_register[regnum])
1075 gdb_assert (read != NULL);
1076 read (regcache, regnum, reg);
1078 /* ... modify ... */
1080 memcpy (in, reg + offset, len);
1082 memcpy (reg + offset, out, len);
1083 /* ... write (when needed). */
1086 gdb_assert (write != NULL);
1087 write (regcache, regnum, reg);
1092 regcache_raw_read_part (struct regcache *regcache, int regnum,
1093 int offset, int len, void *buf)
1095 struct regcache_descr *descr = regcache->descr;
1096 gdb_assert (regnum >= 0 && regnum < descr->nr_raw_registers);
1097 regcache_xfer_part (regcache, regnum, offset, len, buf, NULL,
1098 regcache_raw_read, regcache_raw_write);
1102 regcache_raw_write_part (struct regcache *regcache, int regnum,
1103 int offset, int len, const void *buf)
1105 struct regcache_descr *descr = regcache->descr;
1106 gdb_assert (regnum >= 0 && regnum < descr->nr_raw_registers);
1107 regcache_xfer_part (regcache, regnum, offset, len, NULL, buf,
1108 regcache_raw_read, regcache_raw_write);
1112 regcache_cooked_read_part (struct regcache *regcache, int regnum,
1113 int offset, int len, void *buf)
1115 struct regcache_descr *descr = regcache->descr;
1116 gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
1117 regcache_xfer_part (regcache, regnum, offset, len, buf, NULL,
1118 regcache_cooked_read, regcache_cooked_write);
1122 regcache_cooked_write_part (struct regcache *regcache, int regnum,
1123 int offset, int len, const void *buf)
1125 struct regcache_descr *descr = regcache->descr;
1126 gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
1127 regcache_xfer_part (regcache, regnum, offset, len, NULL, buf,
1128 regcache_cooked_read, regcache_cooked_write);
1131 /* Hack to keep code that view the register buffer as raw bytes
1135 register_offset_hack (struct gdbarch *gdbarch, int regnum)
1137 struct regcache_descr *descr = regcache_descr (gdbarch);
1138 gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
1139 return descr->register_offset[regnum];
1142 /* Return the contents of register REGNUM as an unsigned integer. */
1145 read_register (int regnum)
1147 char *buf = alloca (REGISTER_RAW_SIZE (regnum));
1148 deprecated_read_register_gen (regnum, buf);
1149 return (extract_unsigned_integer (buf, REGISTER_RAW_SIZE (regnum)));
1153 read_register_pid (int regnum, ptid_t ptid)
1159 if (ptid_equal (ptid, inferior_ptid))
1160 return read_register (regnum);
1162 save_ptid = inferior_ptid;
1164 inferior_ptid = ptid;
1166 retval = read_register (regnum);
1168 inferior_ptid = save_ptid;
1173 /* Store VALUE into the raw contents of register number REGNUM. */
1176 write_register (int regnum, LONGEST val)
1180 size = REGISTER_RAW_SIZE (regnum);
1181 buf = alloca (size);
1182 store_signed_integer (buf, size, (LONGEST) val);
1183 deprecated_write_register_gen (regnum, buf);
1187 write_register_pid (int regnum, CORE_ADDR val, ptid_t ptid)
1191 if (ptid_equal (ptid, inferior_ptid))
1193 write_register (regnum, val);
1197 save_ptid = inferior_ptid;
1199 inferior_ptid = ptid;
1201 write_register (regnum, val);
1203 inferior_ptid = save_ptid;
1206 /* FIXME: kettenis/20030828: We should get rid of supply_register and
1207 regcache_collect in favour of regcache_raw_supply and
1208 regcache_raw_collect. */
1210 /* SUPPLY_REGISTER()
1212 Record that register REGNUM contains VAL. This is used when the
1213 value is obtained from the inferior or core dump, so there is no
1214 need to store the value there.
1216 If VAL is a NULL pointer, then it's probably an unsupported register.
1217 We just set its value to all zeros. We might want to record this
1218 fact, and report it to the users of read_register and friends. */
1221 supply_register (int regnum, const void *val)
1223 regcache_raw_supply (current_regcache, regnum, val);
1225 /* On some architectures, e.g. HPPA, there are a few stray bits in
1226 some registers, that the rest of the code would like to ignore. */
1228 /* NOTE: cagney/2001-03-16: The macro CLEAN_UP_REGISTER_VALUE is
1229 going to be deprecated. Instead architectures will leave the raw
1230 register value as is and instead clean things up as they pass
1231 through the method gdbarch_pseudo_register_read() clean up the
1234 #ifdef DEPRECATED_CLEAN_UP_REGISTER_VALUE
1235 DEPRECATED_CLEAN_UP_REGISTER_VALUE \
1236 (regnum, register_buffer (current_regcache, regnum));
1241 regcache_collect (int regnum, void *buf)
1243 regcache_raw_collect (current_regcache, regnum, buf);
1246 /* Supply register REGNUM, whose contents are stored in BUF, to REGCACHE. */
1249 regcache_raw_supply (struct regcache *regcache, int regnum, const void *buf)
1254 gdb_assert (regcache != NULL);
1255 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
1256 gdb_assert (!regcache->readonly_p);
1258 /* FIXME: kettenis/20030828: It shouldn't be necessary to handle
1259 CURRENT_REGCACHE specially here. */
1260 if (regcache == current_regcache
1261 && !ptid_equal (registers_ptid, inferior_ptid))
1263 registers_changed ();
1264 registers_ptid = inferior_ptid;
1267 regbuf = register_buffer (regcache, regnum);
1268 size = regcache->descr->sizeof_register[regnum];
1271 memcpy (regbuf, buf, size);
1273 memset (regbuf, 0, size);
1275 /* Mark the register as cached. */
1276 regcache->register_valid_p[regnum] = 1;
1279 /* Collect register REGNUM from REGCACHE and store its contents in BUF. */
1282 regcache_raw_collect (const struct regcache *regcache, int regnum, void *buf)
1287 gdb_assert (regcache != NULL && buf != NULL);
1288 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
1290 regbuf = register_buffer (regcache, regnum);
1291 size = regcache->descr->sizeof_register[regnum];
1292 memcpy (buf, regbuf, size);
1296 /* read_pc, write_pc, read_sp, deprecated_read_fp, etc. Special
1297 handling for registers PC, SP, and FP. */
1299 /* NOTE: cagney/2001-02-18: The functions read_pc_pid(), read_pc(),
1300 read_sp(), and deprecated_read_fp(), will eventually be replaced by
1301 per-frame methods. Instead of relying on the global INFERIOR_PTID,
1302 they will use the contextual information provided by the FRAME.
1303 These functions do not belong in the register cache. */
1305 /* NOTE: cagney/2003-06-07: The functions generic_target_write_pc(),
1306 write_pc_pid(), write_pc(), and deprecated_read_fp(), all need to
1307 be replaced by something that does not rely on global state. But
1311 read_pc_pid (ptid_t ptid)
1313 ptid_t saved_inferior_ptid;
1316 /* In case ptid != inferior_ptid. */
1317 saved_inferior_ptid = inferior_ptid;
1318 inferior_ptid = ptid;
1320 if (TARGET_READ_PC_P ())
1321 pc_val = TARGET_READ_PC (ptid);
1322 /* Else use per-frame method on get_current_frame. */
1323 else if (PC_REGNUM >= 0)
1325 CORE_ADDR raw_val = read_register_pid (PC_REGNUM, ptid);
1326 CORE_ADDR pc_val = ADDR_BITS_REMOVE (raw_val);
1330 internal_error (__FILE__, __LINE__, "read_pc_pid: Unable to find PC");
1332 inferior_ptid = saved_inferior_ptid;
1339 return read_pc_pid (inferior_ptid);
1343 generic_target_write_pc (CORE_ADDR pc, ptid_t ptid)
1347 write_register_pid (PC_REGNUM, pc, ptid);
1348 if (DEPRECATED_NPC_REGNUM >= 0)
1349 write_register_pid (DEPRECATED_NPC_REGNUM, pc + 4, ptid);
1351 internal_error (__FILE__, __LINE__,
1352 "generic_target_write_pc");
1357 write_pc_pid (CORE_ADDR pc, ptid_t ptid)
1359 ptid_t saved_inferior_ptid;
1361 /* In case ptid != inferior_ptid. */
1362 saved_inferior_ptid = inferior_ptid;
1363 inferior_ptid = ptid;
1365 TARGET_WRITE_PC (pc, ptid);
1367 inferior_ptid = saved_inferior_ptid;
1371 write_pc (CORE_ADDR pc)
1373 write_pc_pid (pc, inferior_ptid);
1376 /* Cope with strage ways of getting to the stack and frame pointers */
1381 if (TARGET_READ_SP_P ())
1382 return TARGET_READ_SP ();
1383 else if (gdbarch_unwind_sp_p (current_gdbarch))
1384 return get_frame_sp (get_current_frame ());
1385 else if (SP_REGNUM >= 0)
1386 /* Try SP_REGNUM last: this makes all sorts of [wrong] assumptions
1387 about the architecture so put it at the end. */
1388 return read_register (SP_REGNUM);
1389 internal_error (__FILE__, __LINE__, "read_sp: Unable to find SP");
1393 deprecated_write_sp (CORE_ADDR val)
1395 gdb_assert (SP_REGNUM >= 0);
1396 write_register (SP_REGNUM, val);
1400 deprecated_read_fp (void)
1402 if (DEPRECATED_TARGET_READ_FP_P ())
1403 return DEPRECATED_TARGET_READ_FP ();
1404 else if (DEPRECATED_FP_REGNUM >= 0)
1405 return read_register (DEPRECATED_FP_REGNUM);
1407 internal_error (__FILE__, __LINE__, "deprecated_read_fp");
1412 reg_flush_command (char *command, int from_tty)
1414 /* Force-flush the register cache. */
1415 registers_changed ();
1417 printf_filtered ("Register cache flushed.\n");
1421 build_regcache (void)
1423 current_regcache = regcache_xmalloc (current_gdbarch);
1424 current_regcache->readonly_p = 0;
1425 deprecated_registers = deprecated_grub_regcache_for_registers (current_regcache);
1426 deprecated_register_valid = current_regcache->register_valid_p;
1430 dump_endian_bytes (struct ui_file *file, enum bfd_endian endian,
1431 const unsigned char *buf, long len)
1436 case BFD_ENDIAN_BIG:
1437 for (i = 0; i < len; i++)
1438 fprintf_unfiltered (file, "%02x", buf[i]);
1440 case BFD_ENDIAN_LITTLE:
1441 for (i = len - 1; i >= 0; i--)
1442 fprintf_unfiltered (file, "%02x", buf[i]);
1445 internal_error (__FILE__, __LINE__, "Bad switch");
1449 enum regcache_dump_what
1451 regcache_dump_none, regcache_dump_raw, regcache_dump_cooked, regcache_dump_groups
1455 regcache_dump (struct regcache *regcache, struct ui_file *file,
1456 enum regcache_dump_what what_to_dump)
1458 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
1459 struct gdbarch *gdbarch = regcache->descr->gdbarch;
1461 int footnote_nr = 0;
1462 int footnote_register_size = 0;
1463 int footnote_register_offset = 0;
1464 int footnote_register_type_name_null = 0;
1465 long register_offset = 0;
1466 unsigned char buf[MAX_REGISTER_SIZE];
1469 fprintf_unfiltered (file, "legacy_p %d\n", regcache->descr->legacy_p);
1470 fprintf_unfiltered (file, "nr_raw_registers %d\n",
1471 regcache->descr->nr_raw_registers);
1472 fprintf_unfiltered (file, "nr_cooked_registers %d\n",
1473 regcache->descr->nr_cooked_registers);
1474 fprintf_unfiltered (file, "sizeof_raw_registers %ld\n",
1475 regcache->descr->sizeof_raw_registers);
1476 fprintf_unfiltered (file, "sizeof_raw_register_valid_p %ld\n",
1477 regcache->descr->sizeof_raw_register_valid_p);
1478 fprintf_unfiltered (file, "NUM_REGS %d\n", NUM_REGS);
1479 fprintf_unfiltered (file, "NUM_PSEUDO_REGS %d\n", NUM_PSEUDO_REGS);
1482 gdb_assert (regcache->descr->nr_cooked_registers
1483 == (NUM_REGS + NUM_PSEUDO_REGS));
1485 for (regnum = -1; regnum < regcache->descr->nr_cooked_registers; regnum++)
1489 fprintf_unfiltered (file, " %-10s", "Name");
1492 const char *p = REGISTER_NAME (regnum);
1495 else if (p[0] == '\0')
1497 fprintf_unfiltered (file, " %-10s", p);
1502 fprintf_unfiltered (file, " %4s", "Nr");
1504 fprintf_unfiltered (file, " %4d", regnum);
1506 /* Relative number. */
1508 fprintf_unfiltered (file, " %4s", "Rel");
1509 else if (regnum < NUM_REGS)
1510 fprintf_unfiltered (file, " %4d", regnum);
1512 fprintf_unfiltered (file, " %4d", (regnum - NUM_REGS));
1516 fprintf_unfiltered (file, " %6s ", "Offset");
1519 fprintf_unfiltered (file, " %6ld",
1520 regcache->descr->register_offset[regnum]);
1521 if (register_offset != regcache->descr->register_offset[regnum]
1522 || register_offset != DEPRECATED_REGISTER_BYTE (regnum)
1524 && (regcache->descr->register_offset[regnum]
1525 != (regcache->descr->register_offset[regnum - 1]
1526 + regcache->descr->sizeof_register[regnum - 1])))
1529 if (!footnote_register_offset)
1530 footnote_register_offset = ++footnote_nr;
1531 fprintf_unfiltered (file, "*%d", footnote_register_offset);
1534 fprintf_unfiltered (file, " ");
1535 register_offset = (regcache->descr->register_offset[regnum]
1536 + regcache->descr->sizeof_register[regnum]);
1541 fprintf_unfiltered (file, " %5s ", "Size");
1544 fprintf_unfiltered (file, " %5ld",
1545 regcache->descr->sizeof_register[regnum]);
1546 if ((regcache->descr->sizeof_register[regnum]
1547 != REGISTER_RAW_SIZE (regnum))
1548 || (regcache->descr->sizeof_register[regnum]
1549 != REGISTER_VIRTUAL_SIZE (regnum))
1550 || (regcache->descr->sizeof_register[regnum]
1551 != TYPE_LENGTH (register_type (regcache->descr->gdbarch,
1555 if (!footnote_register_size)
1556 footnote_register_size = ++footnote_nr;
1557 fprintf_unfiltered (file, "*%d", footnote_register_size);
1560 fprintf_unfiltered (file, " ");
1570 static const char blt[] = "builtin_type";
1571 t = TYPE_NAME (register_type (regcache->descr->gdbarch, regnum));
1575 if (!footnote_register_type_name_null)
1576 footnote_register_type_name_null = ++footnote_nr;
1577 xasprintf (&n, "*%d", footnote_register_type_name_null);
1578 make_cleanup (xfree, n);
1581 /* Chop a leading builtin_type. */
1582 if (strncmp (t, blt, strlen (blt)) == 0)
1585 fprintf_unfiltered (file, " %-15s", t);
1588 /* Leading space always present. */
1589 fprintf_unfiltered (file, " ");
1592 if (what_to_dump == regcache_dump_raw)
1595 fprintf_unfiltered (file, "Raw value");
1596 else if (regnum >= regcache->descr->nr_raw_registers)
1597 fprintf_unfiltered (file, "<cooked>");
1598 else if (!regcache_valid_p (regcache, regnum))
1599 fprintf_unfiltered (file, "<invalid>");
1602 regcache_raw_read (regcache, regnum, buf);
1603 fprintf_unfiltered (file, "0x");
1604 dump_endian_bytes (file, TARGET_BYTE_ORDER, buf,
1605 REGISTER_RAW_SIZE (regnum));
1609 /* Value, cooked. */
1610 if (what_to_dump == regcache_dump_cooked)
1613 fprintf_unfiltered (file, "Cooked value");
1616 regcache_cooked_read (regcache, regnum, buf);
1617 fprintf_unfiltered (file, "0x");
1618 dump_endian_bytes (file, TARGET_BYTE_ORDER, buf,
1619 REGISTER_VIRTUAL_SIZE (regnum));
1623 /* Group members. */
1624 if (what_to_dump == regcache_dump_groups)
1627 fprintf_unfiltered (file, "Groups");
1630 const char *sep = "";
1631 struct reggroup *group;
1632 for (group = reggroup_next (gdbarch, NULL);
1634 group = reggroup_next (gdbarch, group))
1636 if (gdbarch_register_reggroup_p (gdbarch, regnum, group))
1638 fprintf_unfiltered (file, "%s%s", sep, reggroup_name (group));
1645 fprintf_unfiltered (file, "\n");
1648 if (footnote_register_size)
1649 fprintf_unfiltered (file, "*%d: Inconsistent register sizes.\n",
1650 footnote_register_size);
1651 if (footnote_register_offset)
1652 fprintf_unfiltered (file, "*%d: Inconsistent register offsets.\n",
1653 footnote_register_offset);
1654 if (footnote_register_type_name_null)
1655 fprintf_unfiltered (file,
1656 "*%d: Register type's name NULL.\n",
1657 footnote_register_type_name_null);
1658 do_cleanups (cleanups);
1662 regcache_print (char *args, enum regcache_dump_what what_to_dump)
1665 regcache_dump (current_regcache, gdb_stdout, what_to_dump);
1668 struct ui_file *file = gdb_fopen (args, "w");
1670 perror_with_name ("maintenance print architecture");
1671 regcache_dump (current_regcache, file, what_to_dump);
1672 ui_file_delete (file);
1677 maintenance_print_registers (char *args, int from_tty)
1679 regcache_print (args, regcache_dump_none);
1683 maintenance_print_raw_registers (char *args, int from_tty)
1685 regcache_print (args, regcache_dump_raw);
1689 maintenance_print_cooked_registers (char *args, int from_tty)
1691 regcache_print (args, regcache_dump_cooked);
1695 maintenance_print_register_groups (char *args, int from_tty)
1697 regcache_print (args, regcache_dump_groups);
1700 extern initialize_file_ftype _initialize_regcache; /* -Wmissing-prototype */
1703 _initialize_regcache (void)
1705 regcache_descr_handle = register_gdbarch_data (init_regcache_descr);
1706 REGISTER_GDBARCH_SWAP (current_regcache);
1707 register_gdbarch_swap (&deprecated_registers, sizeof (deprecated_registers), NULL);
1708 register_gdbarch_swap (&deprecated_register_valid, sizeof (deprecated_register_valid), NULL);
1709 register_gdbarch_swap (NULL, 0, build_regcache);
1711 add_com ("flushregs", class_maintenance, reg_flush_command,
1712 "Force gdb to flush its register cache (maintainer command)");
1714 /* Initialize the thread/process associated with the current set of
1715 registers. For now, -1 is special, and means `no current process'. */
1716 registers_ptid = pid_to_ptid (-1);
1718 add_cmd ("registers", class_maintenance,
1719 maintenance_print_registers,
1720 "Print the internal register configuration.\
1721 Takes an optional file parameter.",
1722 &maintenanceprintlist);
1723 add_cmd ("raw-registers", class_maintenance,
1724 maintenance_print_raw_registers,
1725 "Print the internal register configuration including raw values.\
1726 Takes an optional file parameter.",
1727 &maintenanceprintlist);
1728 add_cmd ("cooked-registers", class_maintenance,
1729 maintenance_print_cooked_registers,
1730 "Print the internal register configuration including cooked values.\
1731 Takes an optional file parameter.",
1732 &maintenanceprintlist);
1733 add_cmd ("register-groups", class_maintenance,
1734 maintenance_print_register_groups,
1735 "Print the internal register configuration including each register's group.\
1736 Takes an optional file parameter.",
1737 &maintenanceprintlist);