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 REGISTER_BYTE() so use that. */
97 /* FIXME: cagney/2002-11-07: Instead of using REGISTER_BYTE() this
98 code should, as is done in init_regcache_descr(), compute the
99 offets at runtime. This currently isn't possible as some ISAs
100 define overlapping register regions - see the mess in
101 read_register_bytes() and write_register_bytes() registers. */
102 descr->sizeof_register = XCALLOC (descr->nr_cooked_registers, long);
103 descr->register_offset = XCALLOC (descr->nr_cooked_registers, long);
104 for (i = 0; i < descr->nr_cooked_registers; i++)
106 /* FIXME: cagney/2001-12-04: This code shouldn't need to use
107 REGISTER_BYTE(). Unfortunatly, legacy code likes to lay the
108 buffer out so that certain registers just happen to overlap.
109 Ulgh! New targets use gdbarch's register read/write and
110 entirely avoid this uglyness. */
111 descr->register_offset[i] = REGISTER_BYTE (i);
112 descr->sizeof_register[i] = REGISTER_RAW_SIZE (i);
113 gdb_assert (MAX_REGISTER_SIZE >= REGISTER_RAW_SIZE (i));
114 gdb_assert (MAX_REGISTER_SIZE >= REGISTER_VIRTUAL_SIZE (i));
117 /* Compute the real size of the register buffer. Start out by
118 trusting DEPRECATED_REGISTER_BYTES, but then adjust it upwards
119 should that be found to not be sufficient. */
120 /* FIXME: cagney/2002-11-05: Instead of using the macro
121 DEPRECATED_REGISTER_BYTES, this code should, as is done in
122 init_regcache_descr(), compute the total number of register bytes
123 using the accumulated offsets. */
124 descr->sizeof_cooked_registers = DEPRECATED_REGISTER_BYTES; /* OK */
125 for (i = 0; i < descr->nr_cooked_registers; i++)
128 /* Keep extending the buffer so that there is always enough
129 space for all registers. The comparison is necessary since
130 legacy code is free to put registers in random places in the
131 buffer separated by holes. Once REGISTER_BYTE() is killed
132 this can be greatly simplified. */
133 regend = descr->register_offset[i] + descr->sizeof_register[i];
134 if (descr->sizeof_cooked_registers < regend)
135 descr->sizeof_cooked_registers = regend;
137 /* FIXME: cagney/2002-05-11: Shouldn't be including pseudo-registers
138 in the register cache. Unfortunatly some architectures still
139 rely on this and the pseudo_register_write() method. */
140 descr->sizeof_raw_registers = descr->sizeof_cooked_registers;
144 init_regcache_descr (struct gdbarch *gdbarch)
147 struct regcache_descr *descr;
148 gdb_assert (gdbarch != NULL);
150 /* Create an initial, zero filled, table. */
151 descr = XCALLOC (1, struct regcache_descr);
152 descr->gdbarch = gdbarch;
154 /* Total size of the register space. The raw registers are mapped
155 directly onto the raw register cache while the pseudo's are
156 either mapped onto raw-registers or memory. */
157 descr->nr_cooked_registers = NUM_REGS + NUM_PSEUDO_REGS;
158 descr->sizeof_cooked_register_valid_p = NUM_REGS + NUM_PSEUDO_REGS;
160 /* Fill in a table of register types. */
161 descr->register_type = XCALLOC (descr->nr_cooked_registers,
163 for (i = 0; i < descr->nr_cooked_registers; i++)
165 if (gdbarch_register_type_p (gdbarch))
167 gdb_assert (!REGISTER_VIRTUAL_TYPE_P ()); /* OK */
168 descr->register_type[i] = gdbarch_register_type (gdbarch, i);
171 descr->register_type[i] = REGISTER_VIRTUAL_TYPE (i); /* OK */
174 /* Construct a strictly RAW register cache. Don't allow pseudo's
175 into the register cache. */
176 descr->nr_raw_registers = NUM_REGS;
178 /* FIXME: cagney/2002-08-13: Overallocate the register_valid_p
179 array. This pretects GDB from erant code that accesses elements
180 of the global register_valid_p[] array in the range [NUM_REGS
181 .. NUM_REGS + NUM_PSEUDO_REGS). */
182 descr->sizeof_raw_register_valid_p = descr->sizeof_cooked_register_valid_p;
184 /* If an old style architecture, fill in the remainder of the
185 register cache descriptor using the register macros. */
186 /* NOTE: cagney/2003-06-29: If either of REGISTER_BYTE or
187 REGISTER_RAW_SIZE are still present, things are most likely
188 totally screwed. Ex: an architecture with raw register sizes
189 smaller than what REGISTER_BYTE indicates; non monotonic
190 REGISTER_BYTE values. For GDB 6 check for these nasty methods
191 and fall back to legacy code when present. Sigh! */
192 if ((!gdbarch_pseudo_register_read_p (gdbarch)
193 && !gdbarch_pseudo_register_write_p (gdbarch)
194 && !gdbarch_register_type_p (gdbarch))
195 || REGISTER_BYTE_P () || REGISTER_RAW_SIZE_P ())
198 init_legacy_regcache_descr (gdbarch, descr);
202 /* Lay out the register cache.
204 NOTE: cagney/2002-05-22: Only register_type() is used when
205 constructing the register cache. It is assumed that the
206 register's raw size, virtual size and type length are all the
211 descr->sizeof_register = XCALLOC (descr->nr_cooked_registers, long);
212 descr->register_offset = XCALLOC (descr->nr_cooked_registers, long);
213 for (i = 0; i < descr->nr_cooked_registers; i++)
215 descr->sizeof_register[i] = TYPE_LENGTH (descr->register_type[i]);
216 descr->register_offset[i] = offset;
217 offset += descr->sizeof_register[i];
218 gdb_assert (MAX_REGISTER_SIZE >= descr->sizeof_register[i]);
220 /* Set the real size of the register cache buffer. */
221 descr->sizeof_cooked_registers = offset;
224 /* FIXME: cagney/2002-05-22: Should only need to allocate space for
225 the raw registers. Unfortunatly some code still accesses the
226 register array directly using the global registers[]. Until that
227 code has been purged, play safe and over allocating the register
229 descr->sizeof_raw_registers = descr->sizeof_cooked_registers;
231 /* Sanity check. Confirm that there is agreement between the
232 regcache and the target's redundant REGISTER_BYTE (new targets
233 should not even be defining it). */
234 for (i = 0; i < descr->nr_cooked_registers; i++)
236 if (REGISTER_BYTE_P ())
237 gdb_assert (descr->register_offset[i] == REGISTER_BYTE (i));
239 gdb_assert (descr->sizeof_register[i] == REGISTER_RAW_SIZE (i));
240 gdb_assert (descr->sizeof_register[i] == REGISTER_VIRTUAL_SIZE (i));
243 /* gdb_assert (descr->sizeof_raw_registers == DEPRECATED_REGISTER_BYTES (i)); */
248 static struct regcache_descr *
249 regcache_descr (struct gdbarch *gdbarch)
251 return gdbarch_data (gdbarch, regcache_descr_handle);
255 xfree_regcache_descr (struct gdbarch *gdbarch, void *ptr)
257 struct regcache_descr *descr = ptr;
260 xfree (descr->register_offset);
261 xfree (descr->sizeof_register);
262 descr->register_offset = NULL;
263 descr->sizeof_register = NULL;
267 /* Utility functions returning useful register attributes stored in
268 the regcache descr. */
271 register_type (struct gdbarch *gdbarch, int regnum)
273 struct regcache_descr *descr = regcache_descr (gdbarch);
274 gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
275 return descr->register_type[regnum];
278 /* Utility functions returning useful register attributes stored in
279 the regcache descr. */
282 register_size (struct gdbarch *gdbarch, int regnum)
284 struct regcache_descr *descr = regcache_descr (gdbarch);
286 gdb_assert (regnum >= 0 && regnum < (NUM_REGS + NUM_PSEUDO_REGS));
287 size = descr->sizeof_register[regnum];
288 /* NB: The deprecated REGISTER_RAW_SIZE, if not provided, defaults
289 to the size of the register's type. */
290 gdb_assert (size == REGISTER_RAW_SIZE (regnum)); /* OK */
291 /* NB: Don't check the register's virtual size. It, in say the case
292 of the MIPS, may not match the raw size! */
296 /* The register cache for storing raw register values. */
300 struct regcache_descr *descr;
301 /* The register buffers. A read-only register cache can hold the
302 full [0 .. NUM_REGS + NUM_PSEUDO_REGS) while a read/write
303 register cache can only hold [0 .. NUM_REGS). */
305 char *register_valid_p;
306 /* Is this a read-only cache? A read-only cache is used for saving
307 the target's register state (e.g, across an inferior function
308 call or just before forcing a function return). A read-only
309 cache can only be updated via the methods regcache_dup() and
310 regcache_cpy(). The actual contents are determined by the
311 reggroup_save and reggroup_restore methods. */
316 regcache_xmalloc (struct gdbarch *gdbarch)
318 struct regcache_descr *descr;
319 struct regcache *regcache;
320 gdb_assert (gdbarch != NULL);
321 descr = regcache_descr (gdbarch);
322 regcache = XMALLOC (struct regcache);
323 regcache->descr = descr;
325 = XCALLOC (descr->sizeof_raw_registers, char);
326 regcache->register_valid_p
327 = XCALLOC (descr->sizeof_raw_register_valid_p, char);
328 regcache->readonly_p = 1;
333 regcache_xfree (struct regcache *regcache)
335 if (regcache == NULL)
337 xfree (regcache->registers);
338 xfree (regcache->register_valid_p);
343 do_regcache_xfree (void *data)
345 regcache_xfree (data);
349 make_cleanup_regcache_xfree (struct regcache *regcache)
351 return make_cleanup (do_regcache_xfree, regcache);
354 /* Return a pointer to register REGNUM's buffer cache. */
357 register_buffer (struct regcache *regcache, int regnum)
359 return regcache->registers + regcache->descr->register_offset[regnum];
363 regcache_save (struct regcache *dst, regcache_cooked_read_ftype *cooked_read,
366 struct gdbarch *gdbarch = dst->descr->gdbarch;
367 char buf[MAX_REGISTER_SIZE];
369 /* The DST should be `read-only', if it wasn't then the save would
370 end up trying to write the register values back out to the
372 gdb_assert (dst->readonly_p);
373 /* Clear the dest. */
374 memset (dst->registers, 0, dst->descr->sizeof_cooked_registers);
375 memset (dst->register_valid_p, 0, dst->descr->sizeof_cooked_register_valid_p);
376 /* Copy over any registers (identified by their membership in the
377 save_reggroup) and mark them as valid. The full [0 .. NUM_REGS +
378 NUM_PSEUDO_REGS) range is checked since some architectures need
379 to save/restore `cooked' registers that live in memory. */
380 for (regnum = 0; regnum < dst->descr->nr_cooked_registers; regnum++)
382 if (gdbarch_register_reggroup_p (gdbarch, regnum, save_reggroup))
384 int valid = cooked_read (src, regnum, buf);
387 memcpy (register_buffer (dst, regnum), buf,
388 register_size (gdbarch, regnum));
389 dst->register_valid_p[regnum] = 1;
396 regcache_restore (struct regcache *dst,
397 regcache_cooked_read_ftype *cooked_read,
400 struct gdbarch *gdbarch = dst->descr->gdbarch;
401 char buf[MAX_REGISTER_SIZE];
403 /* The dst had better not be read-only. If it is, the `restore'
404 doesn't make much sense. */
405 gdb_assert (!dst->readonly_p);
406 /* Copy over any registers, being careful to only restore those that
407 were both saved and need to be restored. The full [0 .. NUM_REGS
408 + NUM_PSEUDO_REGS) range is checked since some architectures need
409 to save/restore `cooked' registers that live in memory. */
410 for (regnum = 0; regnum < dst->descr->nr_cooked_registers; regnum++)
412 if (gdbarch_register_reggroup_p (gdbarch, regnum, restore_reggroup))
414 int valid = cooked_read (src, regnum, buf);
416 regcache_cooked_write (dst, regnum, buf);
422 do_cooked_read (void *src, int regnum, void *buf)
424 struct regcache *regcache = src;
425 if (!regcache->register_valid_p[regnum] && regcache->readonly_p)
426 /* Don't even think about fetching a register from a read-only
427 cache when the register isn't yet valid. There isn't a target
428 from which the register value can be fetched. */
430 regcache_cooked_read (regcache, regnum, buf);
436 regcache_cpy (struct regcache *dst, struct regcache *src)
440 gdb_assert (src != NULL && dst != NULL);
441 gdb_assert (src->descr->gdbarch == dst->descr->gdbarch);
442 gdb_assert (src != dst);
443 gdb_assert (src->readonly_p || dst->readonly_p);
444 if (!src->readonly_p)
445 regcache_save (dst, do_cooked_read, src);
446 else if (!dst->readonly_p)
447 regcache_restore (dst, do_cooked_read, src);
449 regcache_cpy_no_passthrough (dst, src);
453 regcache_cpy_no_passthrough (struct regcache *dst, struct regcache *src)
456 gdb_assert (src != NULL && dst != NULL);
457 gdb_assert (src->descr->gdbarch == dst->descr->gdbarch);
458 /* NOTE: cagney/2002-05-17: Don't let the caller do a no-passthrough
459 move of data into the current_regcache(). Doing this would be
460 silly - it would mean that valid_p would be completly invalid. */
461 gdb_assert (dst != current_regcache);
462 memcpy (dst->registers, src->registers, dst->descr->sizeof_raw_registers);
463 memcpy (dst->register_valid_p, src->register_valid_p,
464 dst->descr->sizeof_raw_register_valid_p);
468 regcache_dup (struct regcache *src)
470 struct regcache *newbuf;
471 gdb_assert (current_regcache != NULL);
472 newbuf = regcache_xmalloc (src->descr->gdbarch);
473 regcache_cpy (newbuf, src);
478 regcache_dup_no_passthrough (struct regcache *src)
480 struct regcache *newbuf;
481 gdb_assert (current_regcache != NULL);
482 newbuf = regcache_xmalloc (src->descr->gdbarch);
483 regcache_cpy_no_passthrough (newbuf, src);
488 regcache_valid_p (struct regcache *regcache, int regnum)
490 gdb_assert (regcache != NULL);
491 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
492 return regcache->register_valid_p[regnum];
496 deprecated_grub_regcache_for_registers (struct regcache *regcache)
498 return regcache->registers;
501 /* Global structure containing the current regcache. */
502 /* FIXME: cagney/2002-05-11: The two global arrays registers[] and
503 deprecated_register_valid[] currently point into this structure. */
504 struct regcache *current_regcache;
506 /* NOTE: this is a write-through cache. There is no "dirty" bit for
507 recording if the register values have been changed (eg. by the
508 user). Therefore all registers must be written back to the
509 target when appropriate. */
511 /* REGISTERS contains the cached register values (in target byte order). */
513 char *deprecated_registers;
515 /* DEPRECATED_REGISTER_VALID is 0 if the register needs to be fetched,
516 1 if it has been fetched, and
517 -1 if the register value was not available.
519 "Not available" indicates that the target is not not able to supply
520 the register at this state. The register may become available at a
521 later time (after the next resume). This often occures when GDB is
522 manipulating a target that contains only a snapshot of the entire
523 system being debugged - some of the registers in such a system may
524 not have been saved. */
526 signed char *deprecated_register_valid;
528 /* The thread/process associated with the current set of registers. */
530 static ptid_t registers_ptid;
538 Returns 0 if the value is not in the cache (needs fetch).
539 >0 if the value is in the cache.
540 <0 if the value is permanently unavailable (don't ask again). */
543 register_cached (int regnum)
545 return deprecated_register_valid[regnum];
548 /* Record that REGNUM's value is cached if STATE is >0, uncached but
549 fetchable if STATE is 0, and uncached and unfetchable if STATE is <0. */
552 set_register_cached (int regnum, int state)
554 gdb_assert (regnum >= 0);
555 gdb_assert (regnum < current_regcache->descr->nr_raw_registers);
556 current_regcache->register_valid_p[regnum] = state;
559 /* Return whether register REGNUM is a real register. */
562 real_register (int regnum)
564 return regnum >= 0 && regnum < NUM_REGS;
567 /* Low level examining and depositing of registers.
569 The caller is responsible for making sure that the inferior is
570 stopped before calling the fetching routines, or it will get
571 garbage. (a change from GDB version 3, in which the caller got the
572 value from the last stop). */
574 /* REGISTERS_CHANGED ()
576 Indicate that registers may have changed, so invalidate the cache. */
579 registers_changed (void)
583 registers_ptid = pid_to_ptid (-1);
585 /* Force cleanup of any alloca areas if using C alloca instead of
586 a builtin alloca. This particular call is used to clean up
587 areas allocated by low level target code which may build up
588 during lengthy interactions between gdb and the target before
589 gdb gives control to the user (ie watchpoints). */
592 for (i = 0; i < current_regcache->descr->nr_raw_registers; i++)
593 set_register_cached (i, 0);
595 if (registers_changed_hook)
596 registers_changed_hook ();
599 /* DEPRECATED_REGISTERS_FETCHED ()
601 Indicate that all registers have been fetched, so mark them all valid. */
603 /* NOTE: cagney/2001-12-04: This function does not set valid on the
604 pseudo-register range since pseudo registers are always supplied
605 using supply_register(). */
606 /* FIXME: cagney/2001-12-04: This function is DEPRECATED. The target
607 code was blatting the registers[] array and then calling this.
608 Since targets should only be using supply_register() the need for
609 this function/hack is eliminated. */
612 deprecated_registers_fetched (void)
616 for (i = 0; i < NUM_REGS; i++)
617 set_register_cached (i, 1);
618 /* Do not assume that the pseudo-regs have also been fetched.
619 Fetching all real regs NEVER accounts for pseudo-regs. */
622 /* deprecated_read_register_bytes and deprecated_write_register_bytes
623 are generally a *BAD* idea. They are inefficient because they need
624 to check for partial updates, which can only be done by scanning
625 through all of the registers and seeing if the bytes that are being
626 read/written fall inside of an invalid register. [The main reason
627 this is necessary is that register sizes can vary, so a simple
628 index won't suffice.] It is far better to call read_register_gen
629 and write_register_gen if you want to get at the raw register
630 contents, as it only takes a regnum as an argument, and therefore
631 can't do a partial register update.
633 Prior to the recent fixes to check for partial updates, both read
634 and deprecated_write_register_bytes always checked to see if any
635 registers were stale, and then called target_fetch_registers (-1)
636 to update the whole set. This caused really slowed things down for
639 /* Copy INLEN bytes of consecutive data from registers
640 starting with the INREGBYTE'th byte of register data
641 into memory at MYADDR. */
644 deprecated_read_register_bytes (int in_start, char *in_buf, int in_len)
646 int in_end = in_start + in_len;
648 char reg_buf[MAX_REGISTER_SIZE];
650 /* See if we are trying to read bytes from out-of-date registers. If so,
651 update just those registers. */
653 for (regnum = 0; regnum < NUM_REGS + NUM_PSEUDO_REGS; regnum++)
662 reg_start = REGISTER_BYTE (regnum);
663 reg_len = REGISTER_RAW_SIZE (regnum);
664 reg_end = reg_start + reg_len;
666 if (reg_end <= in_start || in_end <= reg_start)
667 /* The range the user wants to read doesn't overlap with regnum. */
670 if (REGISTER_NAME (regnum) != NULL && *REGISTER_NAME (regnum) != '\0')
671 /* Force the cache to fetch the entire register. */
672 deprecated_read_register_gen (regnum, reg_buf);
674 /* Legacy note: even though this register is ``invalid'' we
675 still need to return something. It would appear that some
676 code relies on apparent gaps in the register array also
678 /* FIXME: cagney/2001-08-18: This is just silly. It defeats
679 the entire register read/write flow of control. Must
680 resist temptation to return 0xdeadbeef. */
681 memcpy (reg_buf, &deprecated_registers[reg_start], reg_len);
683 /* Legacy note: This function, for some reason, allows a NULL
684 input buffer. If the buffer is NULL, the registers are still
685 fetched, just the final transfer is skipped. */
689 /* start = max (reg_start, in_start) */
690 if (reg_start > in_start)
695 /* end = min (reg_end, in_end) */
696 if (reg_end < in_end)
701 /* Transfer just the bytes common to both IN_BUF and REG_BUF */
702 for (byte = start; byte < end; byte++)
704 in_buf[byte - in_start] = reg_buf[byte - reg_start];
709 /* Read register REGNUM into memory at MYADDR, which must be large
710 enough for REGISTER_RAW_BYTES (REGNUM). Target byte-order. If the
711 register is known to be the size of a CORE_ADDR or smaller,
712 read_register can be used instead. */
715 legacy_read_register_gen (int regnum, char *myaddr)
717 gdb_assert (regnum >= 0 && regnum < (NUM_REGS + NUM_PSEUDO_REGS));
718 if (! ptid_equal (registers_ptid, inferior_ptid))
720 registers_changed ();
721 registers_ptid = inferior_ptid;
724 if (!register_cached (regnum))
725 target_fetch_registers (regnum);
727 memcpy (myaddr, register_buffer (current_regcache, regnum),
728 REGISTER_RAW_SIZE (regnum));
732 regcache_raw_read (struct regcache *regcache, int regnum, void *buf)
734 gdb_assert (regcache != NULL && buf != NULL);
735 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
736 if (regcache->descr->legacy_p
737 && !regcache->readonly_p)
739 gdb_assert (regcache == current_regcache);
740 /* For moment, just use underlying legacy code. Ulgh!!! This
741 silently and very indirectly updates the regcache's regcache
742 via the global deprecated_register_valid[]. */
743 legacy_read_register_gen (regnum, buf);
746 /* Make certain that the register cache is up-to-date with respect
747 to the current thread. This switching shouldn't be necessary
748 only there is still only one target side register cache. Sigh!
749 On the bright side, at least there is a regcache object. */
750 if (!regcache->readonly_p)
752 gdb_assert (regcache == current_regcache);
753 if (! ptid_equal (registers_ptid, inferior_ptid))
755 registers_changed ();
756 registers_ptid = inferior_ptid;
758 if (!register_cached (regnum))
759 target_fetch_registers (regnum);
761 /* Copy the value directly into the register cache. */
762 memcpy (buf, register_buffer (regcache, regnum),
763 regcache->descr->sizeof_register[regnum]);
767 regcache_raw_read_signed (struct regcache *regcache, int regnum, LONGEST *val)
770 gdb_assert (regcache != NULL);
771 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
772 buf = alloca (regcache->descr->sizeof_register[regnum]);
773 regcache_raw_read (regcache, regnum, buf);
774 (*val) = extract_signed_integer (buf,
775 regcache->descr->sizeof_register[regnum]);
779 regcache_raw_read_unsigned (struct regcache *regcache, int regnum,
783 gdb_assert (regcache != NULL);
784 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
785 buf = alloca (regcache->descr->sizeof_register[regnum]);
786 regcache_raw_read (regcache, regnum, buf);
787 (*val) = extract_unsigned_integer (buf,
788 regcache->descr->sizeof_register[regnum]);
792 regcache_raw_write_signed (struct regcache *regcache, int regnum, LONGEST val)
795 gdb_assert (regcache != NULL);
796 gdb_assert (regnum >=0 && regnum < regcache->descr->nr_raw_registers);
797 buf = alloca (regcache->descr->sizeof_register[regnum]);
798 store_signed_integer (buf, regcache->descr->sizeof_register[regnum], val);
799 regcache_raw_write (regcache, regnum, buf);
803 regcache_raw_write_unsigned (struct regcache *regcache, int regnum,
807 gdb_assert (regcache != NULL);
808 gdb_assert (regnum >=0 && regnum < regcache->descr->nr_raw_registers);
809 buf = alloca (regcache->descr->sizeof_register[regnum]);
810 store_unsigned_integer (buf, regcache->descr->sizeof_register[regnum], val);
811 regcache_raw_write (regcache, regnum, buf);
815 deprecated_read_register_gen (int regnum, char *buf)
817 gdb_assert (current_regcache != NULL);
818 gdb_assert (current_regcache->descr->gdbarch == current_gdbarch);
819 if (current_regcache->descr->legacy_p)
821 legacy_read_register_gen (regnum, buf);
824 regcache_cooked_read (current_regcache, regnum, buf);
828 regcache_cooked_read (struct regcache *regcache, int regnum, void *buf)
830 gdb_assert (regnum >= 0);
831 gdb_assert (regnum < regcache->descr->nr_cooked_registers);
832 if (regnum < regcache->descr->nr_raw_registers)
833 regcache_raw_read (regcache, regnum, buf);
834 else if (regcache->readonly_p
835 && regnum < regcache->descr->nr_cooked_registers
836 && regcache->register_valid_p[regnum])
837 /* Read-only register cache, perhaphs the cooked value was cached? */
838 memcpy (buf, register_buffer (regcache, regnum),
839 regcache->descr->sizeof_register[regnum]);
841 gdbarch_pseudo_register_read (regcache->descr->gdbarch, regcache,
846 regcache_cooked_read_signed (struct regcache *regcache, int regnum,
850 gdb_assert (regcache != NULL);
851 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_cooked_registers);
852 buf = alloca (regcache->descr->sizeof_register[regnum]);
853 regcache_cooked_read (regcache, regnum, buf);
854 (*val) = extract_signed_integer (buf,
855 regcache->descr->sizeof_register[regnum]);
859 regcache_cooked_read_unsigned (struct regcache *regcache, int regnum,
863 gdb_assert (regcache != NULL);
864 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_cooked_registers);
865 buf = alloca (regcache->descr->sizeof_register[regnum]);
866 regcache_cooked_read (regcache, regnum, buf);
867 (*val) = extract_unsigned_integer (buf,
868 regcache->descr->sizeof_register[regnum]);
872 regcache_cooked_write_signed (struct regcache *regcache, int regnum,
876 gdb_assert (regcache != NULL);
877 gdb_assert (regnum >=0 && regnum < regcache->descr->nr_cooked_registers);
878 buf = alloca (regcache->descr->sizeof_register[regnum]);
879 store_signed_integer (buf, regcache->descr->sizeof_register[regnum], val);
880 regcache_cooked_write (regcache, regnum, buf);
884 regcache_cooked_write_unsigned (struct regcache *regcache, int regnum,
888 gdb_assert (regcache != NULL);
889 gdb_assert (regnum >=0 && regnum < regcache->descr->nr_cooked_registers);
890 buf = alloca (regcache->descr->sizeof_register[regnum]);
891 store_unsigned_integer (buf, regcache->descr->sizeof_register[regnum], val);
892 regcache_cooked_write (regcache, regnum, buf);
895 /* Write register REGNUM at MYADDR to the target. MYADDR points at
896 REGISTER_RAW_BYTES(REGNUM), which must be in target byte-order. */
899 legacy_write_register_gen (int regnum, const void *myaddr)
902 gdb_assert (regnum >= 0 && regnum < (NUM_REGS + NUM_PSEUDO_REGS));
904 /* On the sparc, writing %g0 is a no-op, so we don't even want to
905 change the registers array if something writes to this register. */
906 if (CANNOT_STORE_REGISTER (regnum))
909 if (! ptid_equal (registers_ptid, inferior_ptid))
911 registers_changed ();
912 registers_ptid = inferior_ptid;
915 size = REGISTER_RAW_SIZE (regnum);
917 if (real_register (regnum))
919 /* If we have a valid copy of the register, and new value == old
920 value, then don't bother doing the actual store. */
921 if (register_cached (regnum)
922 && (memcmp (register_buffer (current_regcache, regnum), myaddr, size)
926 target_prepare_to_store ();
929 memcpy (register_buffer (current_regcache, regnum), myaddr, size);
931 set_register_cached (regnum, 1);
932 target_store_registers (regnum);
936 regcache_raw_write (struct regcache *regcache, int regnum, const void *buf)
938 gdb_assert (regcache != NULL && buf != NULL);
939 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
940 gdb_assert (!regcache->readonly_p);
942 if (regcache->descr->legacy_p)
944 /* For moment, just use underlying legacy code. Ulgh!!! This
945 silently and very indirectly updates the regcache's buffers
946 via the globals deprecated_register_valid[] and registers[]. */
947 gdb_assert (regcache == current_regcache);
948 legacy_write_register_gen (regnum, buf);
952 /* On the sparc, writing %g0 is a no-op, so we don't even want to
953 change the registers array if something writes to this register. */
954 if (CANNOT_STORE_REGISTER (regnum))
957 /* Make certain that the correct cache is selected. */
958 gdb_assert (regcache == current_regcache);
959 if (! ptid_equal (registers_ptid, inferior_ptid))
961 registers_changed ();
962 registers_ptid = inferior_ptid;
965 /* If we have a valid copy of the register, and new value == old
966 value, then don't bother doing the actual store. */
967 if (regcache_valid_p (regcache, regnum)
968 && (memcmp (register_buffer (regcache, regnum), buf,
969 regcache->descr->sizeof_register[regnum]) == 0))
972 target_prepare_to_store ();
973 memcpy (register_buffer (regcache, regnum), buf,
974 regcache->descr->sizeof_register[regnum]);
975 regcache->register_valid_p[regnum] = 1;
976 target_store_registers (regnum);
980 deprecated_write_register_gen (int regnum, char *buf)
982 gdb_assert (current_regcache != NULL);
983 gdb_assert (current_regcache->descr->gdbarch == current_gdbarch);
984 if (current_regcache->descr->legacy_p)
986 legacy_write_register_gen (regnum, buf);
989 regcache_cooked_write (current_regcache, regnum, buf);
993 regcache_cooked_write (struct regcache *regcache, int regnum, const void *buf)
995 gdb_assert (regnum >= 0);
996 gdb_assert (regnum < regcache->descr->nr_cooked_registers);
997 if (regnum < regcache->descr->nr_raw_registers)
998 regcache_raw_write (regcache, regnum, buf);
1000 gdbarch_pseudo_register_write (regcache->descr->gdbarch, regcache,
1004 /* Copy INLEN bytes of consecutive data from memory at MYADDR
1005 into registers starting with the MYREGSTART'th byte of register data. */
1008 deprecated_write_register_bytes (int myregstart, char *myaddr, int inlen)
1010 int myregend = myregstart + inlen;
1013 target_prepare_to_store ();
1015 /* Scan through the registers updating any that are covered by the
1016 range myregstart<=>myregend using write_register_gen, which does
1017 nice things like handling threads, and avoiding updates when the
1018 new and old contents are the same. */
1020 for (regnum = 0; regnum < NUM_REGS + NUM_PSEUDO_REGS; regnum++)
1022 int regstart, regend;
1024 regstart = REGISTER_BYTE (regnum);
1025 regend = regstart + REGISTER_RAW_SIZE (regnum);
1027 /* Is this register completely outside the range the user is writing? */
1028 if (myregend <= regstart || regend <= myregstart)
1031 /* Is this register completely within the range the user is writing? */
1032 else if (myregstart <= regstart && regend <= myregend)
1033 deprecated_write_register_gen (regnum, myaddr + (regstart - myregstart));
1035 /* The register partially overlaps the range being written. */
1038 char regbuf[MAX_REGISTER_SIZE];
1039 /* What's the overlap between this register's bytes and
1040 those the caller wants to write? */
1041 int overlapstart = max (regstart, myregstart);
1042 int overlapend = min (regend, myregend);
1044 /* We may be doing a partial update of an invalid register.
1045 Update it from the target before scribbling on it. */
1046 deprecated_read_register_gen (regnum, regbuf);
1048 memcpy (&deprecated_registers[overlapstart],
1049 myaddr + (overlapstart - myregstart),
1050 overlapend - overlapstart);
1052 target_store_registers (regnum);
1057 /* Perform a partial register transfer using a read, modify, write
1060 typedef void (regcache_read_ftype) (struct regcache *regcache, int regnum,
1062 typedef void (regcache_write_ftype) (struct regcache *regcache, int regnum,
1066 regcache_xfer_part (struct regcache *regcache, int regnum,
1067 int offset, int len, void *in, const void *out,
1068 regcache_read_ftype *read, regcache_write_ftype *write)
1070 struct regcache_descr *descr = regcache->descr;
1071 bfd_byte reg[MAX_REGISTER_SIZE];
1072 gdb_assert (offset >= 0 && offset <= descr->sizeof_register[regnum]);
1073 gdb_assert (len >= 0 && offset + len <= descr->sizeof_register[regnum]);
1074 /* Something to do? */
1075 if (offset + len == 0)
1077 /* Read (when needed) ... */
1080 || offset + len < descr->sizeof_register[regnum])
1082 gdb_assert (read != NULL);
1083 read (regcache, regnum, reg);
1085 /* ... modify ... */
1087 memcpy (in, reg + offset, len);
1089 memcpy (reg + offset, out, len);
1090 /* ... write (when needed). */
1093 gdb_assert (write != NULL);
1094 write (regcache, regnum, reg);
1099 regcache_raw_read_part (struct regcache *regcache, int regnum,
1100 int offset, int len, void *buf)
1102 struct regcache_descr *descr = regcache->descr;
1103 gdb_assert (regnum >= 0 && regnum < descr->nr_raw_registers);
1104 regcache_xfer_part (regcache, regnum, offset, len, buf, NULL,
1105 regcache_raw_read, regcache_raw_write);
1109 regcache_raw_write_part (struct regcache *regcache, int regnum,
1110 int offset, int len, const void *buf)
1112 struct regcache_descr *descr = regcache->descr;
1113 gdb_assert (regnum >= 0 && regnum < descr->nr_raw_registers);
1114 regcache_xfer_part (regcache, regnum, offset, len, NULL, buf,
1115 regcache_raw_read, regcache_raw_write);
1119 regcache_cooked_read_part (struct regcache *regcache, int regnum,
1120 int offset, int len, void *buf)
1122 struct regcache_descr *descr = regcache->descr;
1123 gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
1124 regcache_xfer_part (regcache, regnum, offset, len, buf, NULL,
1125 regcache_cooked_read, regcache_cooked_write);
1129 regcache_cooked_write_part (struct regcache *regcache, int regnum,
1130 int offset, int len, const void *buf)
1132 struct regcache_descr *descr = regcache->descr;
1133 gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
1134 regcache_xfer_part (regcache, regnum, offset, len, NULL, buf,
1135 regcache_cooked_read, regcache_cooked_write);
1138 /* Hack to keep code that view the register buffer as raw bytes
1142 register_offset_hack (struct gdbarch *gdbarch, int regnum)
1144 struct regcache_descr *descr = regcache_descr (gdbarch);
1145 gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
1146 return descr->register_offset[regnum];
1149 /* Return the contents of register REGNUM as an unsigned integer. */
1152 read_register (int regnum)
1154 char *buf = alloca (REGISTER_RAW_SIZE (regnum));
1155 deprecated_read_register_gen (regnum, buf);
1156 return (extract_unsigned_integer (buf, REGISTER_RAW_SIZE (regnum)));
1160 read_register_pid (int regnum, ptid_t ptid)
1166 if (ptid_equal (ptid, inferior_ptid))
1167 return read_register (regnum);
1169 save_ptid = inferior_ptid;
1171 inferior_ptid = ptid;
1173 retval = read_register (regnum);
1175 inferior_ptid = save_ptid;
1180 /* Store VALUE into the raw contents of register number REGNUM. */
1183 write_register (int regnum, LONGEST val)
1187 size = REGISTER_RAW_SIZE (regnum);
1188 buf = alloca (size);
1189 store_signed_integer (buf, size, (LONGEST) val);
1190 deprecated_write_register_gen (regnum, buf);
1194 write_register_pid (int regnum, CORE_ADDR val, ptid_t ptid)
1198 if (ptid_equal (ptid, inferior_ptid))
1200 write_register (regnum, val);
1204 save_ptid = inferior_ptid;
1206 inferior_ptid = ptid;
1208 write_register (regnum, val);
1210 inferior_ptid = save_ptid;
1213 /* SUPPLY_REGISTER()
1215 Record that register REGNUM contains VAL. This is used when the
1216 value is obtained from the inferior or core dump, so there is no
1217 need to store the value there.
1219 If VAL is a NULL pointer, then it's probably an unsupported register.
1220 We just set its value to all zeros. We might want to record this
1221 fact, and report it to the users of read_register and friends. */
1224 supply_register (int regnum, const void *val)
1227 if (! ptid_equal (registers_ptid, inferior_ptid))
1229 registers_changed ();
1230 registers_ptid = inferior_ptid;
1234 set_register_cached (regnum, 1);
1236 memcpy (register_buffer (current_regcache, regnum), val,
1237 REGISTER_RAW_SIZE (regnum));
1239 memset (register_buffer (current_regcache, regnum), '\000',
1240 REGISTER_RAW_SIZE (regnum));
1242 /* On some architectures, e.g. HPPA, there are a few stray bits in
1243 some registers, that the rest of the code would like to ignore. */
1245 /* NOTE: cagney/2001-03-16: The macro CLEAN_UP_REGISTER_VALUE is
1246 going to be deprecated. Instead architectures will leave the raw
1247 register value as is and instead clean things up as they pass
1248 through the method gdbarch_pseudo_register_read() clean up the
1251 #ifdef DEPRECATED_CLEAN_UP_REGISTER_VALUE
1252 DEPRECATED_CLEAN_UP_REGISTER_VALUE \
1253 (regnum, register_buffer (current_regcache, regnum));
1258 regcache_collect (int regnum, void *buf)
1260 memcpy (buf, register_buffer (current_regcache, regnum),
1261 REGISTER_RAW_SIZE (regnum));
1265 /* read_pc, write_pc, read_sp, deprecated_read_fp, etc. Special
1266 handling for registers PC, SP, and FP. */
1268 /* NOTE: cagney/2001-02-18: The functions read_pc_pid(), read_pc(),
1269 read_sp(), and deprecated_read_fp(), will eventually be replaced by
1270 per-frame methods. Instead of relying on the global INFERIOR_PTID,
1271 they will use the contextual information provided by the FRAME.
1272 These functions do not belong in the register cache. */
1274 /* NOTE: cagney/2003-06-07: The functions generic_target_write_pc(),
1275 write_pc_pid(), write_pc(), and deprecated_read_fp(), all need to
1276 be replaced by something that does not rely on global state. But
1280 read_pc_pid (ptid_t ptid)
1282 ptid_t saved_inferior_ptid;
1285 /* In case ptid != inferior_ptid. */
1286 saved_inferior_ptid = inferior_ptid;
1287 inferior_ptid = ptid;
1289 if (TARGET_READ_PC_P ())
1290 pc_val = TARGET_READ_PC (ptid);
1291 /* Else use per-frame method on get_current_frame. */
1292 else if (PC_REGNUM >= 0)
1294 CORE_ADDR raw_val = read_register_pid (PC_REGNUM, ptid);
1295 CORE_ADDR pc_val = ADDR_BITS_REMOVE (raw_val);
1299 internal_error (__FILE__, __LINE__, "read_pc_pid: Unable to find PC");
1301 inferior_ptid = saved_inferior_ptid;
1308 return read_pc_pid (inferior_ptid);
1312 generic_target_write_pc (CORE_ADDR pc, ptid_t ptid)
1316 write_register_pid (PC_REGNUM, pc, ptid);
1317 if (NPC_REGNUM >= 0)
1318 write_register_pid (NPC_REGNUM, pc + 4, ptid);
1320 internal_error (__FILE__, __LINE__,
1321 "generic_target_write_pc");
1326 write_pc_pid (CORE_ADDR pc, ptid_t ptid)
1328 ptid_t saved_inferior_ptid;
1330 /* In case ptid != inferior_ptid. */
1331 saved_inferior_ptid = inferior_ptid;
1332 inferior_ptid = ptid;
1334 TARGET_WRITE_PC (pc, ptid);
1336 inferior_ptid = saved_inferior_ptid;
1340 write_pc (CORE_ADDR pc)
1342 write_pc_pid (pc, inferior_ptid);
1345 /* Cope with strage ways of getting to the stack and frame pointers */
1350 if (TARGET_READ_SP_P ())
1351 return TARGET_READ_SP ();
1352 else if (gdbarch_unwind_sp_p (current_gdbarch))
1353 return get_frame_sp (get_current_frame ());
1354 else if (SP_REGNUM >= 0)
1355 /* Try SP_REGNUM last: this makes all sorts of [wrong] assumptions
1356 about the architecture so put it at the end. */
1357 return read_register (SP_REGNUM);
1358 internal_error (__FILE__, __LINE__, "read_sp: Unable to find SP");
1362 deprecated_write_sp (CORE_ADDR val)
1364 gdb_assert (SP_REGNUM >= 0);
1365 write_register (SP_REGNUM, val);
1369 deprecated_read_fp (void)
1371 if (DEPRECATED_TARGET_READ_FP_P ())
1372 return DEPRECATED_TARGET_READ_FP ();
1373 else if (DEPRECATED_FP_REGNUM >= 0)
1374 return read_register (DEPRECATED_FP_REGNUM);
1376 internal_error (__FILE__, __LINE__, "deprecated_read_fp");
1381 reg_flush_command (char *command, int from_tty)
1383 /* Force-flush the register cache. */
1384 registers_changed ();
1386 printf_filtered ("Register cache flushed.\n");
1390 build_regcache (void)
1392 current_regcache = regcache_xmalloc (current_gdbarch);
1393 current_regcache->readonly_p = 0;
1394 deprecated_registers = deprecated_grub_regcache_for_registers (current_regcache);
1395 deprecated_register_valid = current_regcache->register_valid_p;
1399 dump_endian_bytes (struct ui_file *file, enum bfd_endian endian,
1400 const unsigned char *buf, long len)
1405 case BFD_ENDIAN_BIG:
1406 for (i = 0; i < len; i++)
1407 fprintf_unfiltered (file, "%02x", buf[i]);
1409 case BFD_ENDIAN_LITTLE:
1410 for (i = len - 1; i >= 0; i--)
1411 fprintf_unfiltered (file, "%02x", buf[i]);
1414 internal_error (__FILE__, __LINE__, "Bad switch");
1418 enum regcache_dump_what
1420 regcache_dump_none, regcache_dump_raw, regcache_dump_cooked, regcache_dump_groups
1424 regcache_dump (struct regcache *regcache, struct ui_file *file,
1425 enum regcache_dump_what what_to_dump)
1427 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
1428 struct gdbarch *gdbarch = regcache->descr->gdbarch;
1429 struct reggroup *const *groups = reggroups (gdbarch);
1431 int footnote_nr = 0;
1432 int footnote_register_size = 0;
1433 int footnote_register_offset = 0;
1434 int footnote_register_type_name_null = 0;
1435 long register_offset = 0;
1436 unsigned char buf[MAX_REGISTER_SIZE];
1439 fprintf_unfiltered (file, "legacy_p %d\n", regcache->descr->legacy_p);
1440 fprintf_unfiltered (file, "nr_raw_registers %d\n",
1441 regcache->descr->nr_raw_registers);
1442 fprintf_unfiltered (file, "nr_cooked_registers %d\n",
1443 regcache->descr->nr_cooked_registers);
1444 fprintf_unfiltered (file, "sizeof_raw_registers %ld\n",
1445 regcache->descr->sizeof_raw_registers);
1446 fprintf_unfiltered (file, "sizeof_raw_register_valid_p %ld\n",
1447 regcache->descr->sizeof_raw_register_valid_p);
1448 fprintf_unfiltered (file, "NUM_REGS %d\n", NUM_REGS);
1449 fprintf_unfiltered (file, "NUM_PSEUDO_REGS %d\n", NUM_PSEUDO_REGS);
1452 gdb_assert (regcache->descr->nr_cooked_registers
1453 == (NUM_REGS + NUM_PSEUDO_REGS));
1455 for (regnum = -1; regnum < regcache->descr->nr_cooked_registers; regnum++)
1459 fprintf_unfiltered (file, " %-10s", "Name");
1462 const char *p = REGISTER_NAME (regnum);
1465 else if (p[0] == '\0')
1467 fprintf_unfiltered (file, " %-10s", p);
1472 fprintf_unfiltered (file, " %4s", "Nr");
1474 fprintf_unfiltered (file, " %4d", regnum);
1476 /* Relative number. */
1478 fprintf_unfiltered (file, " %4s", "Rel");
1479 else if (regnum < NUM_REGS)
1480 fprintf_unfiltered (file, " %4d", regnum);
1482 fprintf_unfiltered (file, " %4d", (regnum - NUM_REGS));
1486 fprintf_unfiltered (file, " %6s ", "Offset");
1489 fprintf_unfiltered (file, " %6ld",
1490 regcache->descr->register_offset[regnum]);
1491 if (register_offset != regcache->descr->register_offset[regnum]
1492 || register_offset != REGISTER_BYTE (regnum)
1494 && (regcache->descr->register_offset[regnum]
1495 != (regcache->descr->register_offset[regnum - 1]
1496 + regcache->descr->sizeof_register[regnum - 1])))
1499 if (!footnote_register_offset)
1500 footnote_register_offset = ++footnote_nr;
1501 fprintf_unfiltered (file, "*%d", footnote_register_offset);
1504 fprintf_unfiltered (file, " ");
1505 register_offset = (regcache->descr->register_offset[regnum]
1506 + regcache->descr->sizeof_register[regnum]);
1511 fprintf_unfiltered (file, " %5s ", "Size");
1514 fprintf_unfiltered (file, " %5ld",
1515 regcache->descr->sizeof_register[regnum]);
1516 if ((regcache->descr->sizeof_register[regnum]
1517 != REGISTER_RAW_SIZE (regnum))
1518 || (regcache->descr->sizeof_register[regnum]
1519 != REGISTER_VIRTUAL_SIZE (regnum))
1520 || (regcache->descr->sizeof_register[regnum]
1521 != TYPE_LENGTH (register_type (regcache->descr->gdbarch,
1525 if (!footnote_register_size)
1526 footnote_register_size = ++footnote_nr;
1527 fprintf_unfiltered (file, "*%d", footnote_register_size);
1530 fprintf_unfiltered (file, " ");
1540 static const char blt[] = "builtin_type";
1541 t = TYPE_NAME (register_type (regcache->descr->gdbarch, regnum));
1545 if (!footnote_register_type_name_null)
1546 footnote_register_type_name_null = ++footnote_nr;
1547 xasprintf (&n, "*%d", footnote_register_type_name_null);
1548 make_cleanup (xfree, n);
1551 /* Chop a leading builtin_type. */
1552 if (strncmp (t, blt, strlen (blt)) == 0)
1555 fprintf_unfiltered (file, " %-15s", t);
1558 /* Leading space always present. */
1559 fprintf_unfiltered (file, " ");
1562 if (what_to_dump == regcache_dump_raw)
1565 fprintf_unfiltered (file, "Raw value");
1566 else if (regnum >= regcache->descr->nr_raw_registers)
1567 fprintf_unfiltered (file, "<cooked>");
1568 else if (!regcache_valid_p (regcache, regnum))
1569 fprintf_unfiltered (file, "<invalid>");
1572 regcache_raw_read (regcache, regnum, buf);
1573 fprintf_unfiltered (file, "0x");
1574 dump_endian_bytes (file, TARGET_BYTE_ORDER, buf,
1575 REGISTER_RAW_SIZE (regnum));
1579 /* Value, cooked. */
1580 if (what_to_dump == regcache_dump_cooked)
1583 fprintf_unfiltered (file, "Cooked value");
1586 regcache_cooked_read (regcache, regnum, buf);
1587 fprintf_unfiltered (file, "0x");
1588 dump_endian_bytes (file, TARGET_BYTE_ORDER, buf,
1589 REGISTER_VIRTUAL_SIZE (regnum));
1593 /* Group members. */
1594 if (what_to_dump == regcache_dump_groups)
1597 fprintf_unfiltered (file, "Groups");
1601 const char *sep = "";
1602 for (i = 0; groups[i] != NULL; i++)
1604 if (gdbarch_register_reggroup_p (gdbarch, regnum, groups[i]))
1606 fprintf_unfiltered (file, "%s%s", sep, reggroup_name (groups[i]));
1613 fprintf_unfiltered (file, "\n");
1616 if (footnote_register_size)
1617 fprintf_unfiltered (file, "*%d: Inconsistent register sizes.\n",
1618 footnote_register_size);
1619 if (footnote_register_offset)
1620 fprintf_unfiltered (file, "*%d: Inconsistent register offsets.\n",
1621 footnote_register_offset);
1622 if (footnote_register_type_name_null)
1623 fprintf_unfiltered (file,
1624 "*%d: Register type's name NULL.\n",
1625 footnote_register_type_name_null);
1626 do_cleanups (cleanups);
1630 regcache_print (char *args, enum regcache_dump_what what_to_dump)
1633 regcache_dump (current_regcache, gdb_stdout, what_to_dump);
1636 struct ui_file *file = gdb_fopen (args, "w");
1638 perror_with_name ("maintenance print architecture");
1639 regcache_dump (current_regcache, file, what_to_dump);
1640 ui_file_delete (file);
1645 maintenance_print_registers (char *args, int from_tty)
1647 regcache_print (args, regcache_dump_none);
1651 maintenance_print_raw_registers (char *args, int from_tty)
1653 regcache_print (args, regcache_dump_raw);
1657 maintenance_print_cooked_registers (char *args, int from_tty)
1659 regcache_print (args, regcache_dump_cooked);
1663 maintenance_print_register_groups (char *args, int from_tty)
1665 regcache_print (args, regcache_dump_groups);
1668 extern initialize_file_ftype _initialize_regcache; /* -Wmissing-prototype */
1671 _initialize_regcache (void)
1673 regcache_descr_handle = register_gdbarch_data (init_regcache_descr,
1674 xfree_regcache_descr);
1675 REGISTER_GDBARCH_SWAP (current_regcache);
1676 register_gdbarch_swap (&deprecated_registers, sizeof (deprecated_registers), NULL);
1677 register_gdbarch_swap (&deprecated_register_valid, sizeof (deprecated_register_valid), NULL);
1678 register_gdbarch_swap (NULL, 0, build_regcache);
1680 add_com ("flushregs", class_maintenance, reg_flush_command,
1681 "Force gdb to flush its register cache (maintainer command)");
1683 /* Initialize the thread/process associated with the current set of
1684 registers. For now, -1 is special, and means `no current process'. */
1685 registers_ptid = pid_to_ptid (-1);
1687 add_cmd ("registers", class_maintenance,
1688 maintenance_print_registers,
1689 "Print the internal register configuration.\
1690 Takes an optional file parameter.",
1691 &maintenanceprintlist);
1692 add_cmd ("raw-registers", class_maintenance,
1693 maintenance_print_raw_registers,
1694 "Print the internal register configuration including raw values.\
1695 Takes an optional file parameter.",
1696 &maintenanceprintlist);
1697 add_cmd ("cooked-registers", class_maintenance,
1698 maintenance_print_cooked_registers,
1699 "Print the internal register configuration including cooked values.\
1700 Takes an optional file parameter.",
1701 &maintenanceprintlist);
1702 add_cmd ("register-groups", class_maintenance,
1703 maintenance_print_register_groups,
1704 "Print the internal register configuration including each register's group.\
1705 Takes an optional file parameter.",
1706 &maintenanceprintlist);