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, 2004 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. */
38 * Here is the actual register cache.
41 /* Per-architecture object describing the layout of a register cache.
42 Computed once when the architecture is created */
44 struct gdbarch_data *regcache_descr_handle;
48 /* The architecture this descriptor belongs to. */
49 struct gdbarch *gdbarch;
51 /* Is this a ``legacy'' register cache? Such caches reserve space
52 for raw and pseudo registers and allow access to both. */
55 /* The raw register cache. Each raw (or hard) register is supplied
56 by the target interface. The raw cache should not contain
57 redundant information - if the PC is constructed from two
58 registers then those regigisters and not the PC lives in the raw
61 long sizeof_raw_registers;
62 long sizeof_raw_register_valid_p;
64 /* The cooked register space. Each cooked register in the range
65 [0..NR_RAW_REGISTERS) is direct-mapped onto the corresponding raw
66 register. The remaining [NR_RAW_REGISTERS
67 .. NR_COOKED_REGISTERS) (a.k.a. pseudo registers) are mapped onto
68 both raw registers and memory by the architecture methods
69 gdbarch_pseudo_register_read and gdbarch_pseudo_register_write. */
70 int nr_cooked_registers;
71 long sizeof_cooked_registers;
72 long sizeof_cooked_register_valid_p;
74 /* Offset and size (in 8 bit bytes), of reach register in the
75 register cache. All registers (including those in the range
76 [NR_RAW_REGISTERS .. NR_COOKED_REGISTERS) are given an offset.
77 Assigning all registers an offset makes it possible to keep
78 legacy code, such as that found in read_register_bytes() and
79 write_register_bytes() working. */
80 long *register_offset;
81 long *sizeof_register;
83 /* Cached table containing the type of each register. */
84 struct type **register_type;
88 init_legacy_regcache_descr (struct gdbarch *gdbarch,
89 struct regcache_descr *descr)
92 /* FIXME: cagney/2002-05-11: gdbarch_data() should take that
93 ``gdbarch'' as a parameter. */
94 gdb_assert (gdbarch != NULL);
96 /* Compute the offset of each register. Legacy architectures define
97 DEPRECATED_REGISTER_BYTE() so use that. */
98 /* FIXME: cagney/2002-11-07: Instead of using
99 DEPRECATED_REGISTER_BYTE() this code should, as is done in
100 init_regcache_descr(), compute the offets at runtime. This
101 currently isn't possible as some ISAs define overlapping register
102 regions - see the mess in read_register_bytes() and
103 write_register_bytes() registers. */
104 descr->sizeof_register
105 = GDBARCH_OBSTACK_CALLOC (gdbarch, descr->nr_cooked_registers, long);
106 descr->register_offset
107 = GDBARCH_OBSTACK_CALLOC (gdbarch, descr->nr_cooked_registers, long);
108 for (i = 0; i < descr->nr_cooked_registers; i++)
110 /* FIXME: cagney/2001-12-04: This code shouldn't need to use
111 DEPRECATED_REGISTER_BYTE(). Unfortunately, legacy code likes
112 to lay the buffer out so that certain registers just happen
113 to overlap. Ulgh! New targets use gdbarch's register
114 read/write and entirely avoid this uglyness. */
115 descr->register_offset[i] = DEPRECATED_REGISTER_BYTE (i);
116 descr->sizeof_register[i] = DEPRECATED_REGISTER_RAW_SIZE (i);
117 gdb_assert (MAX_REGISTER_SIZE >= DEPRECATED_REGISTER_RAW_SIZE (i));
118 gdb_assert (MAX_REGISTER_SIZE >= DEPRECATED_REGISTER_VIRTUAL_SIZE (i));
121 /* Compute the real size of the register buffer. Start out by
122 trusting DEPRECATED_REGISTER_BYTES, but then adjust it upwards
123 should that be found to not be sufficient. */
124 /* FIXME: cagney/2002-11-05: Instead of using the macro
125 DEPRECATED_REGISTER_BYTES, this code should, as is done in
126 init_regcache_descr(), compute the total number of register bytes
127 using the accumulated offsets. */
128 descr->sizeof_cooked_registers = DEPRECATED_REGISTER_BYTES; /* OK */
129 for (i = 0; i < descr->nr_cooked_registers; i++)
132 /* Keep extending the buffer so that there is always enough
133 space for all registers. The comparison is necessary since
134 legacy code is free to put registers in random places in the
135 buffer separated by holes. Once DEPRECATED_REGISTER_BYTE()
136 is killed this can be greatly simplified. */
137 regend = descr->register_offset[i] + descr->sizeof_register[i];
138 if (descr->sizeof_cooked_registers < regend)
139 descr->sizeof_cooked_registers = regend;
141 /* FIXME: cagney/2002-05-11: Shouldn't be including pseudo-registers
142 in the register cache. Unfortunately some architectures still
143 rely on this and the pseudo_register_write() method. */
144 descr->sizeof_raw_registers = descr->sizeof_cooked_registers;
148 init_regcache_descr (struct gdbarch *gdbarch)
151 struct regcache_descr *descr;
152 gdb_assert (gdbarch != NULL);
154 /* Create an initial, zero filled, table. */
155 descr = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct regcache_descr);
156 descr->gdbarch = gdbarch;
158 /* Total size of the register space. The raw registers are mapped
159 directly onto the raw register cache while the pseudo's are
160 either mapped onto raw-registers or memory. */
161 descr->nr_cooked_registers = NUM_REGS + NUM_PSEUDO_REGS;
162 descr->sizeof_cooked_register_valid_p = NUM_REGS + NUM_PSEUDO_REGS;
164 /* Fill in a table of register types. */
166 = GDBARCH_OBSTACK_CALLOC (gdbarch, descr->nr_cooked_registers, struct type *);
167 for (i = 0; i < descr->nr_cooked_registers; i++)
169 if (gdbarch_register_type_p (gdbarch))
171 gdb_assert (!DEPRECATED_REGISTER_VIRTUAL_TYPE_P ()); /* OK */
172 descr->register_type[i] = gdbarch_register_type (gdbarch, i);
175 descr->register_type[i] = DEPRECATED_REGISTER_VIRTUAL_TYPE (i); /* OK */
178 /* Construct a strictly RAW register cache. Don't allow pseudo's
179 into the register cache. */
180 descr->nr_raw_registers = NUM_REGS;
182 /* FIXME: cagney/2002-08-13: Overallocate the register_valid_p
183 array. This pretects GDB from erant code that accesses elements
184 of the global register_valid_p[] array in the range [NUM_REGS
185 .. NUM_REGS + NUM_PSEUDO_REGS). */
186 descr->sizeof_raw_register_valid_p = descr->sizeof_cooked_register_valid_p;
188 /* If an old style architecture, fill in the remainder of the
189 register cache descriptor using the register macros. */
190 /* NOTE: cagney/2003-06-29: If either of DEPRECATED_REGISTER_BYTE or
191 DEPRECATED_REGISTER_RAW_SIZE are still present, things are most likely
192 totally screwed. Ex: an architecture with raw register sizes
193 smaller than what DEPRECATED_REGISTER_BYTE indicates; non
194 monotonic DEPRECATED_REGISTER_BYTE values. For GDB 6 check for
195 these nasty methods and fall back to legacy code when present.
197 if ((!gdbarch_pseudo_register_read_p (gdbarch)
198 && !gdbarch_pseudo_register_write_p (gdbarch)
199 && !gdbarch_register_type_p (gdbarch))
200 || DEPRECATED_REGISTER_BYTE_P ()
201 || DEPRECATED_REGISTER_RAW_SIZE_P ())
204 init_legacy_regcache_descr (gdbarch, descr);
208 /* Lay out the register cache.
210 NOTE: cagney/2002-05-22: Only register_type() is used when
211 constructing the register cache. It is assumed that the
212 register's raw size, virtual size and type length are all the
217 descr->sizeof_register
218 = GDBARCH_OBSTACK_CALLOC (gdbarch, descr->nr_cooked_registers, long);
219 descr->register_offset
220 = GDBARCH_OBSTACK_CALLOC (gdbarch, descr->nr_cooked_registers, long);
221 for (i = 0; i < descr->nr_cooked_registers; i++)
223 descr->sizeof_register[i] = TYPE_LENGTH (descr->register_type[i]);
224 descr->register_offset[i] = offset;
225 offset += descr->sizeof_register[i];
226 gdb_assert (MAX_REGISTER_SIZE >= descr->sizeof_register[i]);
228 /* Set the real size of the register cache buffer. */
229 descr->sizeof_cooked_registers = offset;
232 /* FIXME: cagney/2002-05-22: Should only need to allocate space for
233 the raw registers. Unfortunately some code still accesses the
234 register array directly using the global registers[]. Until that
235 code has been purged, play safe and over allocating the register
237 descr->sizeof_raw_registers = descr->sizeof_cooked_registers;
239 /* Sanity check. Confirm that there is agreement between the
240 regcache and the target's redundant DEPRECATED_REGISTER_BYTE (new
241 targets should not even be defining it). */
242 for (i = 0; i < descr->nr_cooked_registers; i++)
244 if (DEPRECATED_REGISTER_BYTE_P ())
245 gdb_assert (descr->register_offset[i] == DEPRECATED_REGISTER_BYTE (i));
247 gdb_assert (descr->sizeof_register[i] == DEPRECATED_REGISTER_RAW_SIZE (i));
248 gdb_assert (descr->sizeof_register[i] == DEPRECATED_REGISTER_VIRTUAL_SIZE (i));
251 /* gdb_assert (descr->sizeof_raw_registers == DEPRECATED_REGISTER_BYTES (i)); */
256 static struct regcache_descr *
257 regcache_descr (struct gdbarch *gdbarch)
259 return gdbarch_data (gdbarch, regcache_descr_handle);
262 /* Utility functions returning useful register attributes stored in
263 the regcache descr. */
266 register_type (struct gdbarch *gdbarch, int regnum)
268 struct regcache_descr *descr = regcache_descr (gdbarch);
269 gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
270 return descr->register_type[regnum];
273 /* Utility functions returning useful register attributes stored in
274 the regcache descr. */
277 register_size (struct gdbarch *gdbarch, int regnum)
279 struct regcache_descr *descr = regcache_descr (gdbarch);
281 gdb_assert (regnum >= 0 && regnum < (NUM_REGS + NUM_PSEUDO_REGS));
282 size = descr->sizeof_register[regnum];
283 /* NB: The deprecated DEPRECATED_REGISTER_RAW_SIZE, if not provided, defaults
284 to the size of the register's type. */
285 gdb_assert (size == DEPRECATED_REGISTER_RAW_SIZE (regnum)); /* OK */
286 /* NB: Don't check the register's virtual size. It, in say the case
287 of the MIPS, may not match the raw size! */
291 /* The register cache for storing raw register values. */
295 struct regcache_descr *descr;
296 /* The register buffers. A read-only register cache can hold the
297 full [0 .. NUM_REGS + NUM_PSEUDO_REGS) while a read/write
298 register cache can only hold [0 .. NUM_REGS). */
300 char *register_valid_p;
301 /* Is this a read-only cache? A read-only cache is used for saving
302 the target's register state (e.g, across an inferior function
303 call or just before forcing a function return). A read-only
304 cache can only be updated via the methods regcache_dup() and
305 regcache_cpy(). The actual contents are determined by the
306 reggroup_save and reggroup_restore methods. */
311 regcache_xmalloc (struct gdbarch *gdbarch)
313 struct regcache_descr *descr;
314 struct regcache *regcache;
315 gdb_assert (gdbarch != NULL);
316 descr = regcache_descr (gdbarch);
317 regcache = XMALLOC (struct regcache);
318 regcache->descr = descr;
320 = XCALLOC (descr->sizeof_raw_registers, char);
321 regcache->register_valid_p
322 = XCALLOC (descr->sizeof_raw_register_valid_p, char);
323 regcache->readonly_p = 1;
328 regcache_xfree (struct regcache *regcache)
330 if (regcache == NULL)
332 xfree (regcache->registers);
333 xfree (regcache->register_valid_p);
338 do_regcache_xfree (void *data)
340 regcache_xfree (data);
344 make_cleanup_regcache_xfree (struct regcache *regcache)
346 return make_cleanup (do_regcache_xfree, regcache);
349 /* Return REGCACHE's architecture. */
352 get_regcache_arch (const struct regcache *regcache)
354 return regcache->descr->gdbarch;
357 /* Return a pointer to register REGNUM's buffer cache. */
360 register_buffer (const struct regcache *regcache, int regnum)
362 return regcache->registers + regcache->descr->register_offset[regnum];
366 regcache_save (struct regcache *dst, regcache_cooked_read_ftype *cooked_read,
369 struct gdbarch *gdbarch = dst->descr->gdbarch;
370 char buf[MAX_REGISTER_SIZE];
372 /* The DST should be `read-only', if it wasn't then the save would
373 end up trying to write the register values back out to the
375 gdb_assert (dst->readonly_p);
376 /* Clear the dest. */
377 memset (dst->registers, 0, dst->descr->sizeof_cooked_registers);
378 memset (dst->register_valid_p, 0, dst->descr->sizeof_cooked_register_valid_p);
379 /* Copy over any registers (identified by their membership in the
380 save_reggroup) and mark them as valid. The full [0 .. NUM_REGS +
381 NUM_PSEUDO_REGS) range is checked since some architectures need
382 to save/restore `cooked' registers that live in memory. */
383 for (regnum = 0; regnum < dst->descr->nr_cooked_registers; regnum++)
385 if (gdbarch_register_reggroup_p (gdbarch, regnum, save_reggroup))
387 int valid = cooked_read (src, regnum, buf);
390 memcpy (register_buffer (dst, regnum), buf,
391 register_size (gdbarch, regnum));
392 dst->register_valid_p[regnum] = 1;
399 regcache_restore (struct regcache *dst,
400 regcache_cooked_read_ftype *cooked_read,
403 struct gdbarch *gdbarch = dst->descr->gdbarch;
404 char buf[MAX_REGISTER_SIZE];
406 /* The dst had better not be read-only. If it is, the `restore'
407 doesn't make much sense. */
408 gdb_assert (!dst->readonly_p);
409 /* Copy over any registers, being careful to only restore those that
410 were both saved and need to be restored. The full [0 .. NUM_REGS
411 + NUM_PSEUDO_REGS) range is checked since some architectures need
412 to save/restore `cooked' registers that live in memory. */
413 for (regnum = 0; regnum < dst->descr->nr_cooked_registers; regnum++)
415 if (gdbarch_register_reggroup_p (gdbarch, regnum, restore_reggroup))
417 int valid = cooked_read (src, regnum, buf);
419 regcache_cooked_write (dst, regnum, buf);
425 do_cooked_read (void *src, int regnum, void *buf)
427 struct regcache *regcache = src;
428 if (!regcache->register_valid_p[regnum] && regcache->readonly_p)
429 /* Don't even think about fetching a register from a read-only
430 cache when the register isn't yet valid. There isn't a target
431 from which the register value can be fetched. */
433 regcache_cooked_read (regcache, regnum, buf);
439 regcache_cpy (struct regcache *dst, struct regcache *src)
443 gdb_assert (src != NULL && dst != NULL);
444 gdb_assert (src->descr->gdbarch == dst->descr->gdbarch);
445 gdb_assert (src != dst);
446 gdb_assert (src->readonly_p || dst->readonly_p);
447 if (!src->readonly_p)
448 regcache_save (dst, do_cooked_read, src);
449 else if (!dst->readonly_p)
450 regcache_restore (dst, do_cooked_read, src);
452 regcache_cpy_no_passthrough (dst, src);
456 regcache_cpy_no_passthrough (struct regcache *dst, struct regcache *src)
459 gdb_assert (src != NULL && dst != NULL);
460 gdb_assert (src->descr->gdbarch == dst->descr->gdbarch);
461 /* NOTE: cagney/2002-05-17: Don't let the caller do a no-passthrough
462 move of data into the current_regcache(). Doing this would be
463 silly - it would mean that valid_p would be completely invalid. */
464 gdb_assert (dst != current_regcache);
465 memcpy (dst->registers, src->registers, dst->descr->sizeof_raw_registers);
466 memcpy (dst->register_valid_p, src->register_valid_p,
467 dst->descr->sizeof_raw_register_valid_p);
471 regcache_dup (struct regcache *src)
473 struct regcache *newbuf;
474 gdb_assert (current_regcache != NULL);
475 newbuf = regcache_xmalloc (src->descr->gdbarch);
476 regcache_cpy (newbuf, src);
481 regcache_dup_no_passthrough (struct regcache *src)
483 struct regcache *newbuf;
484 gdb_assert (current_regcache != NULL);
485 newbuf = regcache_xmalloc (src->descr->gdbarch);
486 regcache_cpy_no_passthrough (newbuf, src);
491 regcache_valid_p (struct regcache *regcache, int regnum)
493 gdb_assert (regcache != NULL);
494 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
495 return regcache->register_valid_p[regnum];
499 deprecated_grub_regcache_for_registers (struct regcache *regcache)
501 return regcache->registers;
504 /* Global structure containing the current regcache. */
505 /* FIXME: cagney/2002-05-11: The two global arrays registers[] and
506 deprecated_register_valid[] currently point into this structure. */
507 struct regcache *current_regcache;
509 /* NOTE: this is a write-through cache. There is no "dirty" bit for
510 recording if the register values have been changed (eg. by the
511 user). Therefore all registers must be written back to the
512 target when appropriate. */
514 /* REGISTERS contains the cached register values (in target byte order). */
516 char *deprecated_registers;
518 /* DEPRECATED_REGISTER_VALID is 0 if the register needs to be fetched,
519 1 if it has been fetched, and
520 -1 if the register value was not available.
522 "Not available" indicates that the target is not not able to supply
523 the register at this state. The register may become available at a
524 later time (after the next resume). This often occures when GDB is
525 manipulating a target that contains only a snapshot of the entire
526 system being debugged - some of the registers in such a system may
527 not have been saved. */
529 signed char *deprecated_register_valid;
531 /* The thread/process associated with the current set of registers. */
533 static ptid_t registers_ptid;
541 Returns 0 if the value is not in the cache (needs fetch).
542 >0 if the value is in the cache.
543 <0 if the value is permanently unavailable (don't ask again). */
546 register_cached (int regnum)
548 return deprecated_register_valid[regnum];
551 /* Record that REGNUM's value is cached if STATE is >0, uncached but
552 fetchable if STATE is 0, and uncached and unfetchable if STATE is <0. */
555 set_register_cached (int regnum, int state)
557 gdb_assert (regnum >= 0);
558 gdb_assert (regnum < current_regcache->descr->nr_raw_registers);
559 current_regcache->register_valid_p[regnum] = state;
562 /* Return whether register REGNUM is a real register. */
565 real_register (int regnum)
567 return regnum >= 0 && regnum < NUM_REGS;
570 /* Observer for the target_changed event. */
573 regcache_observer_target_changed (struct target_ops *target)
575 registers_changed ();
578 /* Low level examining and depositing of registers.
580 The caller is responsible for making sure that the inferior is
581 stopped before calling the fetching routines, or it will get
582 garbage. (a change from GDB version 3, in which the caller got the
583 value from the last stop). */
585 /* REGISTERS_CHANGED ()
587 Indicate that registers may have changed, so invalidate the cache. */
590 registers_changed (void)
594 registers_ptid = pid_to_ptid (-1);
596 /* Force cleanup of any alloca areas if using C alloca instead of
597 a builtin alloca. This particular call is used to clean up
598 areas allocated by low level target code which may build up
599 during lengthy interactions between gdb and the target before
600 gdb gives control to the user (ie watchpoints). */
603 for (i = 0; i < current_regcache->descr->nr_raw_registers; i++)
604 set_register_cached (i, 0);
606 if (deprecated_registers_changed_hook)
607 deprecated_registers_changed_hook ();
610 /* DEPRECATED_REGISTERS_FETCHED ()
612 Indicate that all registers have been fetched, so mark them all valid. */
614 /* FIXME: cagney/2001-12-04: This function is DEPRECATED. The target
615 code was blatting the registers[] array and then calling this.
616 Since targets should only be using regcache_raw_supply() the need for
617 this function/hack is eliminated. */
620 deprecated_registers_fetched (void)
624 for (i = 0; i < NUM_REGS; i++)
625 set_register_cached (i, 1);
626 /* Do not assume that the pseudo-regs have also been fetched.
627 Fetching all real regs NEVER accounts for pseudo-regs. */
630 /* deprecated_read_register_bytes and deprecated_write_register_bytes
631 are generally a *BAD* idea. They are inefficient because they need
632 to check for partial updates, which can only be done by scanning
633 through all of the registers and seeing if the bytes that are being
634 read/written fall inside of an invalid register. [The main reason
635 this is necessary is that register sizes can vary, so a simple
636 index won't suffice.] It is far better to call read_register_gen
637 and write_register_gen if you want to get at the raw register
638 contents, as it only takes a regnum as an argument, and therefore
639 can't do a partial register update.
641 Prior to the recent fixes to check for partial updates, both read
642 and deprecated_write_register_bytes always checked to see if any
643 registers were stale, and then called target_fetch_registers (-1)
644 to update the whole set. This caused really slowed things down for
647 /* Copy INLEN bytes of consecutive data from registers
648 starting with the INREGBYTE'th byte of register data
649 into memory at MYADDR. */
652 deprecated_read_register_bytes (int in_start, char *in_buf, int in_len)
654 int in_end = in_start + in_len;
656 char reg_buf[MAX_REGISTER_SIZE];
658 /* See if we are trying to read bytes from out-of-date registers. If so,
659 update just those registers. */
661 for (regnum = 0; regnum < NUM_REGS + NUM_PSEUDO_REGS; regnum++)
670 reg_start = DEPRECATED_REGISTER_BYTE (regnum);
671 reg_len = DEPRECATED_REGISTER_RAW_SIZE (regnum);
672 reg_end = reg_start + reg_len;
674 if (reg_end <= in_start || in_end <= reg_start)
675 /* The range the user wants to read doesn't overlap with regnum. */
678 if (REGISTER_NAME (regnum) != NULL && *REGISTER_NAME (regnum) != '\0')
679 /* Force the cache to fetch the entire register. */
680 deprecated_read_register_gen (regnum, reg_buf);
682 /* Legacy note: even though this register is ``invalid'' we
683 still need to return something. It would appear that some
684 code relies on apparent gaps in the register array also
686 /* FIXME: cagney/2001-08-18: This is just silly. It defeats
687 the entire register read/write flow of control. Must
688 resist temptation to return 0xdeadbeef. */
689 memcpy (reg_buf, &deprecated_registers[reg_start], reg_len);
691 /* Legacy note: This function, for some reason, allows a NULL
692 input buffer. If the buffer is NULL, the registers are still
693 fetched, just the final transfer is skipped. */
697 /* start = max (reg_start, in_start) */
698 if (reg_start > in_start)
703 /* end = min (reg_end, in_end) */
704 if (reg_end < in_end)
709 /* Transfer just the bytes common to both IN_BUF and REG_BUF */
710 for (byte = start; byte < end; byte++)
712 in_buf[byte - in_start] = reg_buf[byte - reg_start];
717 /* Read register REGNUM into memory at MYADDR, which must be large
718 enough for REGISTER_RAW_BYTES (REGNUM). Target byte-order. If the
719 register is known to be the size of a CORE_ADDR or smaller,
720 read_register can be used instead. */
723 legacy_read_register_gen (int regnum, char *myaddr)
725 gdb_assert (regnum >= 0 && regnum < (NUM_REGS + NUM_PSEUDO_REGS));
726 if (! ptid_equal (registers_ptid, inferior_ptid))
728 registers_changed ();
729 registers_ptid = inferior_ptid;
732 if (!register_cached (regnum))
733 target_fetch_registers (regnum);
735 memcpy (myaddr, register_buffer (current_regcache, regnum),
736 DEPRECATED_REGISTER_RAW_SIZE (regnum));
740 regcache_raw_read (struct regcache *regcache, int regnum, void *buf)
742 gdb_assert (regcache != NULL && buf != NULL);
743 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
744 if (regcache->descr->legacy_p
745 && !regcache->readonly_p)
747 gdb_assert (regcache == current_regcache);
748 /* For moment, just use underlying legacy code. Ulgh!!! This
749 silently and very indirectly updates the regcache's regcache
750 via the global deprecated_register_valid[]. */
751 legacy_read_register_gen (regnum, buf);
754 /* Make certain that the register cache is up-to-date with respect
755 to the current thread. This switching shouldn't be necessary
756 only there is still only one target side register cache. Sigh!
757 On the bright side, at least there is a regcache object. */
758 if (!regcache->readonly_p)
760 gdb_assert (regcache == current_regcache);
761 if (! ptid_equal (registers_ptid, inferior_ptid))
763 registers_changed ();
764 registers_ptid = inferior_ptid;
766 if (!register_cached (regnum))
767 target_fetch_registers (regnum);
769 /* Copy the value directly into the register cache. */
770 memcpy (buf, register_buffer (regcache, regnum),
771 regcache->descr->sizeof_register[regnum]);
775 regcache_raw_read_signed (struct regcache *regcache, int regnum, LONGEST *val)
778 gdb_assert (regcache != NULL);
779 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
780 buf = alloca (regcache->descr->sizeof_register[regnum]);
781 regcache_raw_read (regcache, regnum, buf);
782 (*val) = extract_signed_integer (buf,
783 regcache->descr->sizeof_register[regnum]);
787 regcache_raw_read_unsigned (struct regcache *regcache, int regnum,
791 gdb_assert (regcache != NULL);
792 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
793 buf = alloca (regcache->descr->sizeof_register[regnum]);
794 regcache_raw_read (regcache, regnum, buf);
795 (*val) = extract_unsigned_integer (buf,
796 regcache->descr->sizeof_register[regnum]);
800 regcache_raw_write_signed (struct regcache *regcache, int regnum, LONGEST val)
803 gdb_assert (regcache != NULL);
804 gdb_assert (regnum >=0 && regnum < regcache->descr->nr_raw_registers);
805 buf = alloca (regcache->descr->sizeof_register[regnum]);
806 store_signed_integer (buf, regcache->descr->sizeof_register[regnum], val);
807 regcache_raw_write (regcache, regnum, buf);
811 regcache_raw_write_unsigned (struct regcache *regcache, int regnum,
815 gdb_assert (regcache != NULL);
816 gdb_assert (regnum >=0 && regnum < regcache->descr->nr_raw_registers);
817 buf = alloca (regcache->descr->sizeof_register[regnum]);
818 store_unsigned_integer (buf, regcache->descr->sizeof_register[regnum], val);
819 regcache_raw_write (regcache, regnum, buf);
823 deprecated_read_register_gen (int regnum, char *buf)
825 gdb_assert (current_regcache != NULL);
826 gdb_assert (current_regcache->descr->gdbarch == current_gdbarch);
827 if (current_regcache->descr->legacy_p)
829 legacy_read_register_gen (regnum, buf);
832 regcache_cooked_read (current_regcache, regnum, buf);
836 regcache_cooked_read (struct regcache *regcache, int regnum, void *buf)
838 gdb_assert (regnum >= 0);
839 gdb_assert (regnum < regcache->descr->nr_cooked_registers);
840 if (regnum < regcache->descr->nr_raw_registers)
841 regcache_raw_read (regcache, regnum, buf);
842 else if (regcache->readonly_p
843 && regnum < regcache->descr->nr_cooked_registers
844 && regcache->register_valid_p[regnum])
845 /* Read-only register cache, perhaps the cooked value was cached? */
846 memcpy (buf, register_buffer (regcache, regnum),
847 regcache->descr->sizeof_register[regnum]);
849 gdbarch_pseudo_register_read (regcache->descr->gdbarch, regcache,
854 regcache_cooked_read_signed (struct regcache *regcache, int regnum,
858 gdb_assert (regcache != NULL);
859 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_cooked_registers);
860 buf = alloca (regcache->descr->sizeof_register[regnum]);
861 regcache_cooked_read (regcache, regnum, buf);
862 (*val) = extract_signed_integer (buf,
863 regcache->descr->sizeof_register[regnum]);
867 regcache_cooked_read_unsigned (struct regcache *regcache, int regnum,
871 gdb_assert (regcache != NULL);
872 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_cooked_registers);
873 buf = alloca (regcache->descr->sizeof_register[regnum]);
874 regcache_cooked_read (regcache, regnum, buf);
875 (*val) = extract_unsigned_integer (buf,
876 regcache->descr->sizeof_register[regnum]);
880 regcache_cooked_write_signed (struct regcache *regcache, int regnum,
884 gdb_assert (regcache != NULL);
885 gdb_assert (regnum >=0 && regnum < regcache->descr->nr_cooked_registers);
886 buf = alloca (regcache->descr->sizeof_register[regnum]);
887 store_signed_integer (buf, regcache->descr->sizeof_register[regnum], val);
888 regcache_cooked_write (regcache, regnum, buf);
892 regcache_cooked_write_unsigned (struct regcache *regcache, int regnum,
896 gdb_assert (regcache != NULL);
897 gdb_assert (regnum >=0 && regnum < regcache->descr->nr_cooked_registers);
898 buf = alloca (regcache->descr->sizeof_register[regnum]);
899 store_unsigned_integer (buf, regcache->descr->sizeof_register[regnum], val);
900 regcache_cooked_write (regcache, regnum, buf);
903 /* Write register REGNUM at MYADDR to the target. MYADDR points at
904 REGISTER_RAW_BYTES(REGNUM), which must be in target byte-order. */
907 legacy_write_register_gen (int regnum, const void *myaddr)
910 gdb_assert (regnum >= 0 && regnum < (NUM_REGS + NUM_PSEUDO_REGS));
912 /* On the sparc, writing %g0 is a no-op, so we don't even want to
913 change the registers array if something writes to this register. */
914 if (CANNOT_STORE_REGISTER (regnum))
917 if (! ptid_equal (registers_ptid, inferior_ptid))
919 registers_changed ();
920 registers_ptid = inferior_ptid;
923 size = DEPRECATED_REGISTER_RAW_SIZE (regnum);
925 if (real_register (regnum))
927 /* If we have a valid copy of the register, and new value == old
928 value, then don't bother doing the actual store. */
929 if (register_cached (regnum)
930 && (memcmp (register_buffer (current_regcache, regnum), myaddr, size)
934 target_prepare_to_store ();
937 memcpy (register_buffer (current_regcache, regnum), myaddr, size);
939 set_register_cached (regnum, 1);
940 target_store_registers (regnum);
944 regcache_raw_write (struct regcache *regcache, int regnum, const void *buf)
946 gdb_assert (regcache != NULL && buf != NULL);
947 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
948 gdb_assert (!regcache->readonly_p);
950 if (regcache->descr->legacy_p)
952 /* For moment, just use underlying legacy code. Ulgh!!! This
953 silently and very indirectly updates the regcache's buffers
954 via the globals deprecated_register_valid[] and registers[]. */
955 gdb_assert (regcache == current_regcache);
956 legacy_write_register_gen (regnum, buf);
960 /* On the sparc, writing %g0 is a no-op, so we don't even want to
961 change the registers array if something writes to this register. */
962 if (CANNOT_STORE_REGISTER (regnum))
965 /* Make certain that the correct cache is selected. */
966 gdb_assert (regcache == current_regcache);
967 if (! ptid_equal (registers_ptid, inferior_ptid))
969 registers_changed ();
970 registers_ptid = inferior_ptid;
973 /* If we have a valid copy of the register, and new value == old
974 value, then don't bother doing the actual store. */
975 if (regcache_valid_p (regcache, regnum)
976 && (memcmp (register_buffer (regcache, regnum), buf,
977 regcache->descr->sizeof_register[regnum]) == 0))
980 target_prepare_to_store ();
981 memcpy (register_buffer (regcache, regnum), buf,
982 regcache->descr->sizeof_register[regnum]);
983 regcache->register_valid_p[regnum] = 1;
984 target_store_registers (regnum);
988 deprecated_write_register_gen (int regnum, char *buf)
990 gdb_assert (current_regcache != NULL);
991 gdb_assert (current_regcache->descr->gdbarch == current_gdbarch);
992 if (current_regcache->descr->legacy_p)
994 legacy_write_register_gen (regnum, buf);
997 regcache_cooked_write (current_regcache, regnum, buf);
1001 regcache_cooked_write (struct regcache *regcache, int regnum, const void *buf)
1003 gdb_assert (regnum >= 0);
1004 gdb_assert (regnum < regcache->descr->nr_cooked_registers);
1005 if (regnum < regcache->descr->nr_raw_registers)
1006 regcache_raw_write (regcache, regnum, buf);
1008 gdbarch_pseudo_register_write (regcache->descr->gdbarch, regcache,
1012 /* Copy INLEN bytes of consecutive data from memory at MYADDR
1013 into registers starting with the MYREGSTART'th byte of register data. */
1016 deprecated_write_register_bytes (int myregstart, char *myaddr, int inlen)
1018 int myregend = myregstart + inlen;
1021 target_prepare_to_store ();
1023 /* Scan through the registers updating any that are covered by the
1024 range myregstart<=>myregend using write_register_gen, which does
1025 nice things like handling threads, and avoiding updates when the
1026 new and old contents are the same. */
1028 for (regnum = 0; regnum < NUM_REGS + NUM_PSEUDO_REGS; regnum++)
1030 int regstart, regend;
1032 regstart = DEPRECATED_REGISTER_BYTE (regnum);
1033 regend = regstart + DEPRECATED_REGISTER_RAW_SIZE (regnum);
1035 /* Is this register completely outside the range the user is writing? */
1036 if (myregend <= regstart || regend <= myregstart)
1039 /* Is this register completely within the range the user is writing? */
1040 else if (myregstart <= regstart && regend <= myregend)
1041 deprecated_write_register_gen (regnum, myaddr + (regstart - myregstart));
1043 /* The register partially overlaps the range being written. */
1046 char regbuf[MAX_REGISTER_SIZE];
1047 /* What's the overlap between this register's bytes and
1048 those the caller wants to write? */
1049 int overlapstart = max (regstart, myregstart);
1050 int overlapend = min (regend, myregend);
1052 /* We may be doing a partial update of an invalid register.
1053 Update it from the target before scribbling on it. */
1054 deprecated_read_register_gen (regnum, regbuf);
1056 memcpy (&deprecated_registers[overlapstart],
1057 myaddr + (overlapstart - myregstart),
1058 overlapend - overlapstart);
1060 target_store_registers (regnum);
1065 /* Perform a partial register transfer using a read, modify, write
1068 typedef void (regcache_read_ftype) (struct regcache *regcache, int regnum,
1070 typedef void (regcache_write_ftype) (struct regcache *regcache, int regnum,
1074 regcache_xfer_part (struct regcache *regcache, int regnum,
1075 int offset, int len, void *in, const void *out,
1076 regcache_read_ftype *read, regcache_write_ftype *write)
1078 struct regcache_descr *descr = regcache->descr;
1079 bfd_byte reg[MAX_REGISTER_SIZE];
1080 gdb_assert (offset >= 0 && offset <= descr->sizeof_register[regnum]);
1081 gdb_assert (len >= 0 && offset + len <= descr->sizeof_register[regnum]);
1082 /* Something to do? */
1083 if (offset + len == 0)
1085 /* Read (when needed) ... */
1088 || offset + len < descr->sizeof_register[regnum])
1090 gdb_assert (read != NULL);
1091 read (regcache, regnum, reg);
1093 /* ... modify ... */
1095 memcpy (in, reg + offset, len);
1097 memcpy (reg + offset, out, len);
1098 /* ... write (when needed). */
1101 gdb_assert (write != NULL);
1102 write (regcache, regnum, reg);
1107 regcache_raw_read_part (struct regcache *regcache, int regnum,
1108 int offset, int len, void *buf)
1110 struct regcache_descr *descr = regcache->descr;
1111 gdb_assert (regnum >= 0 && regnum < descr->nr_raw_registers);
1112 regcache_xfer_part (regcache, regnum, offset, len, buf, NULL,
1113 regcache_raw_read, regcache_raw_write);
1117 regcache_raw_write_part (struct regcache *regcache, int regnum,
1118 int offset, int len, const void *buf)
1120 struct regcache_descr *descr = regcache->descr;
1121 gdb_assert (regnum >= 0 && regnum < descr->nr_raw_registers);
1122 regcache_xfer_part (regcache, regnum, offset, len, NULL, buf,
1123 regcache_raw_read, regcache_raw_write);
1127 regcache_cooked_read_part (struct regcache *regcache, int regnum,
1128 int offset, int len, void *buf)
1130 struct regcache_descr *descr = regcache->descr;
1131 gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
1132 regcache_xfer_part (regcache, regnum, offset, len, buf, NULL,
1133 regcache_cooked_read, regcache_cooked_write);
1137 regcache_cooked_write_part (struct regcache *regcache, int regnum,
1138 int offset, int len, const void *buf)
1140 struct regcache_descr *descr = regcache->descr;
1141 gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
1142 regcache_xfer_part (regcache, regnum, offset, len, NULL, buf,
1143 regcache_cooked_read, regcache_cooked_write);
1146 /* Hack to keep code that view the register buffer as raw bytes
1150 register_offset_hack (struct gdbarch *gdbarch, int regnum)
1152 struct regcache_descr *descr = regcache_descr (gdbarch);
1153 gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
1154 return descr->register_offset[regnum];
1157 /* Return the contents of register REGNUM as an unsigned integer. */
1160 read_register (int regnum)
1162 char *buf = alloca (DEPRECATED_REGISTER_RAW_SIZE (regnum));
1163 deprecated_read_register_gen (regnum, buf);
1164 return (extract_unsigned_integer (buf, DEPRECATED_REGISTER_RAW_SIZE (regnum)));
1168 read_register_pid (int regnum, ptid_t ptid)
1174 if (ptid_equal (ptid, inferior_ptid))
1175 return read_register (regnum);
1177 save_ptid = inferior_ptid;
1179 inferior_ptid = ptid;
1181 retval = read_register (regnum);
1183 inferior_ptid = save_ptid;
1188 /* Store VALUE into the raw contents of register number REGNUM. */
1191 write_register (int regnum, LONGEST val)
1195 size = DEPRECATED_REGISTER_RAW_SIZE (regnum);
1196 buf = alloca (size);
1197 store_signed_integer (buf, size, (LONGEST) val);
1198 deprecated_write_register_gen (regnum, buf);
1202 write_register_pid (int regnum, CORE_ADDR val, ptid_t ptid)
1206 if (ptid_equal (ptid, inferior_ptid))
1208 write_register (regnum, val);
1212 save_ptid = inferior_ptid;
1214 inferior_ptid = ptid;
1216 write_register (regnum, val);
1218 inferior_ptid = save_ptid;
1222 regcache_collect (int regnum, void *buf)
1224 regcache_raw_collect (current_regcache, regnum, buf);
1227 /* Supply register REGNUM, whose contents are stored in BUF, to REGCACHE. */
1230 regcache_raw_supply (struct regcache *regcache, int regnum, const void *buf)
1235 gdb_assert (regcache != NULL);
1236 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
1237 gdb_assert (!regcache->readonly_p);
1239 /* FIXME: kettenis/20030828: It shouldn't be necessary to handle
1240 CURRENT_REGCACHE specially here. */
1241 if (regcache == current_regcache
1242 && !ptid_equal (registers_ptid, inferior_ptid))
1244 registers_changed ();
1245 registers_ptid = inferior_ptid;
1248 regbuf = register_buffer (regcache, regnum);
1249 size = regcache->descr->sizeof_register[regnum];
1252 memcpy (regbuf, buf, size);
1254 memset (regbuf, 0, size);
1256 /* Mark the register as cached. */
1257 regcache->register_valid_p[regnum] = 1;
1260 /* Collect register REGNUM from REGCACHE and store its contents in BUF. */
1263 regcache_raw_collect (const struct regcache *regcache, int regnum, void *buf)
1268 gdb_assert (regcache != NULL && buf != NULL);
1269 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
1271 regbuf = register_buffer (regcache, regnum);
1272 size = regcache->descr->sizeof_register[regnum];
1273 memcpy (buf, regbuf, size);
1277 /* read_pc, write_pc, read_sp, deprecated_read_fp, etc. Special
1278 handling for registers PC, SP, and FP. */
1280 /* NOTE: cagney/2001-02-18: The functions read_pc_pid(), read_pc(),
1281 read_sp(), and deprecated_read_fp(), will eventually be replaced by
1282 per-frame methods. Instead of relying on the global INFERIOR_PTID,
1283 they will use the contextual information provided by the FRAME.
1284 These functions do not belong in the register cache. */
1286 /* NOTE: cagney/2003-06-07: The functions generic_target_write_pc(),
1287 write_pc_pid(), write_pc(), and deprecated_read_fp(), all need to
1288 be replaced by something that does not rely on global state. But
1292 read_pc_pid (ptid_t ptid)
1294 ptid_t saved_inferior_ptid;
1297 /* In case ptid != inferior_ptid. */
1298 saved_inferior_ptid = inferior_ptid;
1299 inferior_ptid = ptid;
1301 if (TARGET_READ_PC_P ())
1302 pc_val = TARGET_READ_PC (ptid);
1303 /* Else use per-frame method on get_current_frame. */
1304 else if (PC_REGNUM >= 0)
1306 CORE_ADDR raw_val = read_register_pid (PC_REGNUM, ptid);
1307 pc_val = ADDR_BITS_REMOVE (raw_val);
1310 internal_error (__FILE__, __LINE__, "read_pc_pid: Unable to find PC");
1312 inferior_ptid = saved_inferior_ptid;
1319 return read_pc_pid (inferior_ptid);
1323 generic_target_write_pc (CORE_ADDR pc, ptid_t ptid)
1326 write_register_pid (PC_REGNUM, pc, ptid);
1328 internal_error (__FILE__, __LINE__,
1329 "generic_target_write_pc");
1333 write_pc_pid (CORE_ADDR pc, ptid_t ptid)
1335 ptid_t saved_inferior_ptid;
1337 /* In case ptid != inferior_ptid. */
1338 saved_inferior_ptid = inferior_ptid;
1339 inferior_ptid = ptid;
1341 TARGET_WRITE_PC (pc, ptid);
1343 inferior_ptid = saved_inferior_ptid;
1347 write_pc (CORE_ADDR pc)
1349 write_pc_pid (pc, inferior_ptid);
1352 /* Cope with strage ways of getting to the stack and frame pointers */
1357 if (TARGET_READ_SP_P ())
1358 return TARGET_READ_SP ();
1359 else if (gdbarch_unwind_sp_p (current_gdbarch))
1360 return get_frame_sp (get_current_frame ());
1361 else if (SP_REGNUM >= 0)
1362 /* Try SP_REGNUM last: this makes all sorts of [wrong] assumptions
1363 about the architecture so put it at the end. */
1364 return read_register (SP_REGNUM);
1365 internal_error (__FILE__, __LINE__, "read_sp: Unable to find SP");
1369 deprecated_write_sp (CORE_ADDR val)
1371 gdb_assert (SP_REGNUM >= 0);
1372 write_register (SP_REGNUM, val);
1376 deprecated_read_fp (void)
1378 if (DEPRECATED_TARGET_READ_FP_P ())
1379 return DEPRECATED_TARGET_READ_FP ();
1380 else if (DEPRECATED_FP_REGNUM >= 0)
1381 return read_register (DEPRECATED_FP_REGNUM);
1383 internal_error (__FILE__, __LINE__, "deprecated_read_fp");
1387 reg_flush_command (char *command, int from_tty)
1389 /* Force-flush the register cache. */
1390 registers_changed ();
1392 printf_filtered ("Register cache flushed.\n");
1396 build_regcache (void)
1398 current_regcache = regcache_xmalloc (current_gdbarch);
1399 current_regcache->readonly_p = 0;
1400 deprecated_registers = deprecated_grub_regcache_for_registers (current_regcache);
1401 deprecated_register_valid = current_regcache->register_valid_p;
1405 dump_endian_bytes (struct ui_file *file, enum bfd_endian endian,
1406 const unsigned char *buf, long len)
1411 case BFD_ENDIAN_BIG:
1412 for (i = 0; i < len; i++)
1413 fprintf_unfiltered (file, "%02x", buf[i]);
1415 case BFD_ENDIAN_LITTLE:
1416 for (i = len - 1; i >= 0; i--)
1417 fprintf_unfiltered (file, "%02x", buf[i]);
1420 internal_error (__FILE__, __LINE__, "Bad switch");
1424 enum regcache_dump_what
1426 regcache_dump_none, regcache_dump_raw, regcache_dump_cooked, regcache_dump_groups
1430 regcache_dump (struct regcache *regcache, struct ui_file *file,
1431 enum regcache_dump_what what_to_dump)
1433 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
1434 struct gdbarch *gdbarch = regcache->descr->gdbarch;
1436 int footnote_nr = 0;
1437 int footnote_register_size = 0;
1438 int footnote_register_offset = 0;
1439 int footnote_register_type_name_null = 0;
1440 long register_offset = 0;
1441 unsigned char buf[MAX_REGISTER_SIZE];
1444 fprintf_unfiltered (file, "legacy_p %d\n", regcache->descr->legacy_p);
1445 fprintf_unfiltered (file, "nr_raw_registers %d\n",
1446 regcache->descr->nr_raw_registers);
1447 fprintf_unfiltered (file, "nr_cooked_registers %d\n",
1448 regcache->descr->nr_cooked_registers);
1449 fprintf_unfiltered (file, "sizeof_raw_registers %ld\n",
1450 regcache->descr->sizeof_raw_registers);
1451 fprintf_unfiltered (file, "sizeof_raw_register_valid_p %ld\n",
1452 regcache->descr->sizeof_raw_register_valid_p);
1453 fprintf_unfiltered (file, "NUM_REGS %d\n", NUM_REGS);
1454 fprintf_unfiltered (file, "NUM_PSEUDO_REGS %d\n", NUM_PSEUDO_REGS);
1457 gdb_assert (regcache->descr->nr_cooked_registers
1458 == (NUM_REGS + NUM_PSEUDO_REGS));
1460 for (regnum = -1; regnum < regcache->descr->nr_cooked_registers; regnum++)
1464 fprintf_unfiltered (file, " %-10s", "Name");
1467 const char *p = REGISTER_NAME (regnum);
1470 else if (p[0] == '\0')
1472 fprintf_unfiltered (file, " %-10s", p);
1477 fprintf_unfiltered (file, " %4s", "Nr");
1479 fprintf_unfiltered (file, " %4d", regnum);
1481 /* Relative number. */
1483 fprintf_unfiltered (file, " %4s", "Rel");
1484 else if (regnum < NUM_REGS)
1485 fprintf_unfiltered (file, " %4d", regnum);
1487 fprintf_unfiltered (file, " %4d", (regnum - NUM_REGS));
1491 fprintf_unfiltered (file, " %6s ", "Offset");
1494 fprintf_unfiltered (file, " %6ld",
1495 regcache->descr->register_offset[regnum]);
1496 if (register_offset != regcache->descr->register_offset[regnum]
1497 || register_offset != DEPRECATED_REGISTER_BYTE (regnum)
1499 && (regcache->descr->register_offset[regnum]
1500 != (regcache->descr->register_offset[regnum - 1]
1501 + regcache->descr->sizeof_register[regnum - 1])))
1504 if (!footnote_register_offset)
1505 footnote_register_offset = ++footnote_nr;
1506 fprintf_unfiltered (file, "*%d", footnote_register_offset);
1509 fprintf_unfiltered (file, " ");
1510 register_offset = (regcache->descr->register_offset[regnum]
1511 + regcache->descr->sizeof_register[regnum]);
1516 fprintf_unfiltered (file, " %5s ", "Size");
1519 fprintf_unfiltered (file, " %5ld",
1520 regcache->descr->sizeof_register[regnum]);
1521 if ((regcache->descr->sizeof_register[regnum]
1522 != DEPRECATED_REGISTER_RAW_SIZE (regnum))
1523 || (regcache->descr->sizeof_register[regnum]
1524 != DEPRECATED_REGISTER_VIRTUAL_SIZE (regnum))
1525 || (regcache->descr->sizeof_register[regnum]
1526 != TYPE_LENGTH (register_type (regcache->descr->gdbarch,
1530 if (!footnote_register_size)
1531 footnote_register_size = ++footnote_nr;
1532 fprintf_unfiltered (file, "*%d", footnote_register_size);
1535 fprintf_unfiltered (file, " ");
1545 static const char blt[] = "builtin_type";
1546 t = TYPE_NAME (register_type (regcache->descr->gdbarch, regnum));
1550 if (!footnote_register_type_name_null)
1551 footnote_register_type_name_null = ++footnote_nr;
1552 n = xstrprintf ("*%d", footnote_register_type_name_null);
1553 make_cleanup (xfree, n);
1556 /* Chop a leading builtin_type. */
1557 if (strncmp (t, blt, strlen (blt)) == 0)
1560 fprintf_unfiltered (file, " %-15s", t);
1563 /* Leading space always present. */
1564 fprintf_unfiltered (file, " ");
1567 if (what_to_dump == regcache_dump_raw)
1570 fprintf_unfiltered (file, "Raw value");
1571 else if (regnum >= regcache->descr->nr_raw_registers)
1572 fprintf_unfiltered (file, "<cooked>");
1573 else if (!regcache_valid_p (regcache, regnum))
1574 fprintf_unfiltered (file, "<invalid>");
1577 regcache_raw_read (regcache, regnum, buf);
1578 fprintf_unfiltered (file, "0x");
1579 dump_endian_bytes (file, TARGET_BYTE_ORDER, buf,
1580 DEPRECATED_REGISTER_RAW_SIZE (regnum));
1584 /* Value, cooked. */
1585 if (what_to_dump == regcache_dump_cooked)
1588 fprintf_unfiltered (file, "Cooked value");
1591 regcache_cooked_read (regcache, regnum, buf);
1592 fprintf_unfiltered (file, "0x");
1593 dump_endian_bytes (file, TARGET_BYTE_ORDER, buf,
1594 DEPRECATED_REGISTER_VIRTUAL_SIZE (regnum));
1598 /* Group members. */
1599 if (what_to_dump == regcache_dump_groups)
1602 fprintf_unfiltered (file, "Groups");
1605 const char *sep = "";
1606 struct reggroup *group;
1607 for (group = reggroup_next (gdbarch, NULL);
1609 group = reggroup_next (gdbarch, group))
1611 if (gdbarch_register_reggroup_p (gdbarch, regnum, group))
1613 fprintf_unfiltered (file, "%s%s", sep, reggroup_name (group));
1620 fprintf_unfiltered (file, "\n");
1623 if (footnote_register_size)
1624 fprintf_unfiltered (file, "*%d: Inconsistent register sizes.\n",
1625 footnote_register_size);
1626 if (footnote_register_offset)
1627 fprintf_unfiltered (file, "*%d: Inconsistent register offsets.\n",
1628 footnote_register_offset);
1629 if (footnote_register_type_name_null)
1630 fprintf_unfiltered (file,
1631 "*%d: Register type's name NULL.\n",
1632 footnote_register_type_name_null);
1633 do_cleanups (cleanups);
1637 regcache_print (char *args, enum regcache_dump_what what_to_dump)
1640 regcache_dump (current_regcache, gdb_stdout, what_to_dump);
1643 struct ui_file *file = gdb_fopen (args, "w");
1645 perror_with_name ("maintenance print architecture");
1646 regcache_dump (current_regcache, file, what_to_dump);
1647 ui_file_delete (file);
1652 maintenance_print_registers (char *args, int from_tty)
1654 regcache_print (args, regcache_dump_none);
1658 maintenance_print_raw_registers (char *args, int from_tty)
1660 regcache_print (args, regcache_dump_raw);
1664 maintenance_print_cooked_registers (char *args, int from_tty)
1666 regcache_print (args, regcache_dump_cooked);
1670 maintenance_print_register_groups (char *args, int from_tty)
1672 regcache_print (args, regcache_dump_groups);
1675 extern initialize_file_ftype _initialize_regcache; /* -Wmissing-prototype */
1678 _initialize_regcache (void)
1680 regcache_descr_handle = gdbarch_data_register_post_init (init_regcache_descr);
1681 DEPRECATED_REGISTER_GDBARCH_SWAP (current_regcache);
1682 DEPRECATED_REGISTER_GDBARCH_SWAP (deprecated_registers);
1683 DEPRECATED_REGISTER_GDBARCH_SWAP (deprecated_register_valid);
1684 deprecated_register_gdbarch_swap (NULL, 0, build_regcache);
1686 observer_attach_target_changed (regcache_observer_target_changed);
1688 add_com ("flushregs", class_maintenance, reg_flush_command,
1689 "Force gdb to flush its register cache (maintainer command)");
1691 /* Initialize the thread/process associated with the current set of
1692 registers. For now, -1 is special, and means `no current process'. */
1693 registers_ptid = pid_to_ptid (-1);
1695 add_cmd ("registers", class_maintenance,
1696 maintenance_print_registers,
1697 "Print the internal register configuration.\
1698 Takes an optional file parameter.",
1699 &maintenanceprintlist);
1700 add_cmd ("raw-registers", class_maintenance,
1701 maintenance_print_raw_registers,
1702 "Print the internal register configuration including raw values.\
1703 Takes an optional file parameter.",
1704 &maintenanceprintlist);
1705 add_cmd ("cooked-registers", class_maintenance,
1706 maintenance_print_cooked_registers,
1707 "Print the internal register configuration including cooked values.\
1708 Takes an optional file parameter.",
1709 &maintenanceprintlist);
1710 add_cmd ("register-groups", class_maintenance,
1711 maintenance_print_register_groups,
1712 "Print the internal register configuration including each register's group.\
1713 Takes an optional file parameter.",
1714 &maintenanceprintlist);