1 /* Cache and manage the values of registers for GDB, the GNU debugger.
3 Copyright 1986, 1987, 1989, 1991, 1994, 1995, 1996, 1998, 2000,
4 2001, 2002 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
29 #include "reggroups.h"
30 #include "gdb_assert.h"
31 #include "gdb_string.h"
32 #include "gdbcmd.h" /* For maintenanceprintlist. */
37 * Here is the actual register cache.
40 /* Per-architecture object describing the layout of a register cache.
41 Computed once when the architecture is created */
43 struct gdbarch_data *regcache_descr_handle;
47 /* The architecture this descriptor belongs to. */
48 struct gdbarch *gdbarch;
50 /* Is this a ``legacy'' register cache? Such caches reserve space
51 for raw and pseudo registers and allow access to both. */
54 /* The raw register cache. This should contain just [0
55 .. NUM_RAW_REGISTERS). However, for older targets, it contains
56 space for the full [0 .. NUM_RAW_REGISTERS +
57 NUM_PSEUDO_REGISTERS). */
59 long sizeof_raw_registers;
60 long sizeof_raw_register_valid_p;
62 /* The cooked register space. Each cooked register in the range
63 [0..NR_RAW_REGISTERS) is direct-mapped onto the corresponding raw
64 register. The remaining [NR_RAW_REGISTERS
65 .. NR_COOKED_REGISTERS) (a.k.a. pseudo regiters) are mapped onto
66 both raw registers and memory by the architecture methods
67 gdbarch_register_read and gdbarch_register_write. */
68 int nr_cooked_registers;
69 long sizeof_cooked_registers;
70 long sizeof_cooked_register_valid_p;
72 /* Offset and size (in 8 bit bytes), of reach register in the
73 register cache. All registers (including those in the range
74 [NR_RAW_REGISTERS .. NR_COOKED_REGISTERS) are given an offset.
75 Assigning all registers an offset makes it possible to keep
76 legacy code, such as that found in read_register_bytes() and
77 write_register_bytes() working. */
78 long *register_offset;
79 long *sizeof_register;
81 /* Useful constant. Largest of all the registers. */
82 long max_register_size;
84 /* Cached table containing the type of each register. */
85 struct type **register_type;
89 init_legacy_regcache_descr (struct gdbarch *gdbarch,
90 struct regcache_descr *descr)
93 /* FIXME: cagney/2002-05-11: gdbarch_data() should take that
94 ``gdbarch'' as a parameter. */
95 gdb_assert (gdbarch != NULL);
97 /* FIXME: cagney/2002-05-11: Shouldn't be including pseudo-registers
98 in the register cache. Unfortunatly some architectures still
99 rely on this and the pseudo_register_write() method. */
100 descr->nr_raw_registers = descr->nr_cooked_registers;
101 descr->sizeof_raw_register_valid_p = descr->sizeof_cooked_register_valid_p;
103 /* Compute the offset of each register. Legacy architectures define
104 REGISTER_BYTE() so use that. */
105 /* FIXME: cagney/2002-11-07: Instead of using REGISTER_BYTE() this
106 code should, as is done in init_regcache_descr(), compute the
107 offets at runtime. This currently isn't possible as some ISAs
108 define overlapping register regions - see the mess in
109 read_register_bytes() and write_register_bytes() registers. */
110 descr->sizeof_register = XCALLOC (descr->nr_cooked_registers, long);
111 descr->register_offset = XCALLOC (descr->nr_cooked_registers, long);
112 descr->max_register_size = 0;
113 for (i = 0; i < descr->nr_cooked_registers; i++)
115 /* FIXME: cagney/2001-12-04: This code shouldn't need to use
116 REGISTER_BYTE(). Unfortunatly, legacy code likes to lay the
117 buffer out so that certain registers just happen to overlap.
118 Ulgh! New targets use gdbarch's register read/write and
119 entirely avoid this uglyness. */
120 descr->register_offset[i] = REGISTER_BYTE (i);
121 descr->sizeof_register[i] = REGISTER_RAW_SIZE (i);
122 if (descr->max_register_size < REGISTER_RAW_SIZE (i))
123 descr->max_register_size = REGISTER_RAW_SIZE (i);
124 if (descr->max_register_size < REGISTER_VIRTUAL_SIZE (i))
125 descr->max_register_size = REGISTER_VIRTUAL_SIZE (i);
128 /* Compute the real size of the register buffer. Start out by
129 trusting REGISTER_BYTES, but then adjust it upwards should that
130 be found to not be sufficient. */
131 /* FIXME: cagney/2002-11-05: Instead of using REGISTER_BYTES, this
132 code should, as is done in init_regcache_descr(), compute the
133 total number of register bytes using the accumulated offsets. */
134 descr->sizeof_cooked_registers = REGISTER_BYTES; /* OK use. */
135 for (i = 0; i < descr->nr_cooked_registers; i++)
138 /* Keep extending the buffer so that there is always enough
139 space for all registers. The comparison is necessary since
140 legacy code is free to put registers in random places in the
141 buffer separated by holes. Once REGISTER_BYTE() is killed
142 this can be greatly simplified. */
143 regend = descr->register_offset[i] + descr->sizeof_register[i];
144 if (descr->sizeof_cooked_registers < regend)
145 descr->sizeof_cooked_registers = regend;
147 /* FIXME: cagney/2002-05-11: Shouldn't be including pseudo-registers
148 in the register cache. Unfortunatly some architectures still
149 rely on this and the pseudo_register_write() method. */
150 descr->sizeof_raw_registers = descr->sizeof_cooked_registers;
154 init_regcache_descr (struct gdbarch *gdbarch)
157 struct regcache_descr *descr;
158 gdb_assert (gdbarch != NULL);
160 /* Create an initial, zero filled, table. */
161 descr = XCALLOC (1, struct regcache_descr);
162 descr->gdbarch = gdbarch;
164 /* Total size of the register space. The raw registers are mapped
165 directly onto the raw register cache while the pseudo's are
166 either mapped onto raw-registers or memory. */
167 descr->nr_cooked_registers = NUM_REGS + NUM_PSEUDO_REGS;
168 descr->sizeof_cooked_register_valid_p = NUM_REGS + NUM_PSEUDO_REGS;
170 /* Fill in a table of register types. */
171 descr->register_type = XCALLOC (descr->nr_cooked_registers,
173 for (i = 0; i < descr->nr_cooked_registers; i++)
175 descr->register_type[i] = REGISTER_VIRTUAL_TYPE (i);
178 /* If an old style architecture, fill in the remainder of the
179 register cache descriptor using the register macros. */
180 if (!gdbarch_pseudo_register_read_p (gdbarch)
181 && !gdbarch_pseudo_register_write_p (gdbarch))
184 init_legacy_regcache_descr (gdbarch, descr);
188 /* Construct a strictly RAW register cache. Don't allow pseudo's
189 into the register cache. */
190 descr->nr_raw_registers = NUM_REGS;
192 /* FIXME: cagney/2002-08-13: Overallocate the register_valid_p
193 array. This pretects GDB from erant code that accesses elements
194 of the global register_valid_p[] array in the range [NUM_REGS
195 .. NUM_REGS + NUM_PSEUDO_REGS). */
196 descr->sizeof_raw_register_valid_p = descr->sizeof_cooked_register_valid_p;
198 /* Lay out the register cache.
200 NOTE: cagney/2002-05-22: Only register_type() is used when
201 constructing the register cache. It is assumed that the
202 register's raw size, virtual size and type length are all the
207 descr->sizeof_register = XCALLOC (descr->nr_cooked_registers, long);
208 descr->register_offset = XCALLOC (descr->nr_cooked_registers, long);
209 descr->max_register_size = 0;
210 for (i = 0; i < descr->nr_cooked_registers; i++)
212 descr->sizeof_register[i] = TYPE_LENGTH (descr->register_type[i]);
213 descr->register_offset[i] = offset;
214 offset += descr->sizeof_register[i];
215 if (descr->max_register_size < descr->sizeof_register[i])
216 descr->max_register_size = descr->sizeof_register[i];
218 /* Set the real size of the register cache buffer. */
219 descr->sizeof_cooked_registers = offset;
222 /* FIXME: cagney/2002-05-22: Should only need to allocate space for
223 the raw registers. Unfortunatly some code still accesses the
224 register array directly using the global registers[]. Until that
225 code has been purged, play safe and over allocating the register
227 descr->sizeof_raw_registers = descr->sizeof_cooked_registers;
230 /* Sanity check. Confirm that the assumptions about gdbarch are
231 true. The REGCACHE_DESCR_HANDLE is set before doing the checks
232 so that targets using the generic methods supplied by regcache
233 don't go into infinite recursion trying to, again, create the
235 set_gdbarch_data (gdbarch, regcache_descr_handle, descr);
236 for (i = 0; i < descr->nr_cooked_registers; i++)
238 gdb_assert (descr->sizeof_register[i] == REGISTER_RAW_SIZE (i));
239 gdb_assert (descr->sizeof_register[i] == REGISTER_VIRTUAL_SIZE (i));
240 gdb_assert (descr->register_offset[i] == REGISTER_BYTE (i));
242 /* gdb_assert (descr->sizeof_raw_registers == 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 max_register_size (struct gdbarch *gdbarch)
284 struct regcache_descr *descr = regcache_descr (gdbarch);
285 return descr->max_register_size;
288 /* The register cache for storing raw register values. */
292 struct regcache_descr *descr;
293 /* The register buffers. A read-only register cache can hold the
294 full [0 .. NUM_REGS + NUM_PSEUDO_REGS) while a read/write
295 register cache can only hold [0 .. NUM_REGS). */
297 char *register_valid_p;
298 /* If a value isn't in the cache should the corresponding target be
299 queried for a value. */
304 regcache_xmalloc (struct gdbarch *gdbarch)
306 struct regcache_descr *descr;
307 struct regcache *regcache;
308 gdb_assert (gdbarch != NULL);
309 descr = regcache_descr (gdbarch);
310 regcache = XMALLOC (struct regcache);
311 regcache->descr = descr;
313 = XCALLOC (descr->sizeof_raw_registers, char);
314 regcache->register_valid_p
315 = XCALLOC (descr->sizeof_raw_register_valid_p, char);
316 regcache->passthrough_p = 0;
321 regcache_xfree (struct regcache *regcache)
323 if (regcache == NULL)
325 xfree (regcache->registers);
326 xfree (regcache->register_valid_p);
331 do_regcache_xfree (void *data)
333 regcache_xfree (data);
337 make_cleanup_regcache_xfree (struct regcache *regcache)
339 return make_cleanup (do_regcache_xfree, regcache);
342 /* Return a pointer to register REGNUM's buffer cache. */
345 register_buffer (struct regcache *regcache, int regnum)
347 return regcache->registers + regcache->descr->register_offset[regnum];
351 regcache_cpy (struct regcache *dst, struct regcache *src)
355 gdb_assert (src != NULL && dst != NULL);
356 gdb_assert (src->descr->gdbarch == dst->descr->gdbarch);
357 gdb_assert (src != dst);
358 /* FIXME: cagney/2002-05-17: To say this bit is bad is being polite.
359 It keeps the existing code working where things rely on going
360 through to the register cache. */
361 if (src == current_regcache && src->descr->legacy_p)
363 /* ULGH!!!! Old way. Use REGISTER bytes and let code below
365 read_register_bytes (0, dst->registers, REGISTER_BYTES);
368 /* FIXME: cagney/2002-05-17: To say this bit is bad is being polite.
369 It keeps the existing code working where things rely on going
370 through to the register cache. */
371 if (dst == current_regcache && dst->descr->legacy_p)
373 /* ULGH!!!! Old way. Use REGISTER bytes and let code below
375 write_register_bytes (0, src->registers, REGISTER_BYTES);
378 buf = alloca (src->descr->max_register_size);
379 for (i = 0; i < src->descr->nr_raw_registers; i++)
381 /* Should we worry about the valid bit here? */
382 regcache_raw_read (src, i, buf);
383 regcache_raw_write (dst, i, buf);
388 regcache_cpy_no_passthrough (struct regcache *dst, struct regcache *src)
391 gdb_assert (src != NULL && dst != NULL);
392 gdb_assert (src->descr->gdbarch == dst->descr->gdbarch);
393 /* NOTE: cagney/2002-05-17: Don't let the caller do a no-passthrough
394 move of data into the current_regcache(). Doing this would be
395 silly - it would mean that valid_p would be completly invalid. */
396 gdb_assert (dst != current_regcache);
397 memcpy (dst->registers, src->registers, dst->descr->sizeof_raw_registers);
398 memcpy (dst->register_valid_p, src->register_valid_p,
399 dst->descr->sizeof_raw_register_valid_p);
403 regcache_dup (struct regcache *src)
405 struct regcache *newbuf;
406 gdb_assert (current_regcache != NULL);
407 newbuf = regcache_xmalloc (src->descr->gdbarch);
408 regcache_cpy (newbuf, src);
413 regcache_dup_no_passthrough (struct regcache *src)
415 struct regcache *newbuf;
416 gdb_assert (current_regcache != NULL);
417 newbuf = regcache_xmalloc (src->descr->gdbarch);
418 regcache_cpy_no_passthrough (newbuf, src);
423 regcache_valid_p (struct regcache *regcache, int regnum)
425 gdb_assert (regcache != NULL);
426 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
427 return regcache->register_valid_p[regnum];
431 deprecated_grub_regcache_for_registers (struct regcache *regcache)
433 return regcache->registers;
437 deprecated_grub_regcache_for_register_valid (struct regcache *regcache)
439 return regcache->register_valid_p;
442 /* Global structure containing the current regcache. */
443 /* FIXME: cagney/2002-05-11: The two global arrays registers[] and
444 deprecated_register_valid[] currently point into this structure. */
445 struct regcache *current_regcache;
447 /* NOTE: this is a write-through cache. There is no "dirty" bit for
448 recording if the register values have been changed (eg. by the
449 user). Therefore all registers must be written back to the
450 target when appropriate. */
452 /* REGISTERS contains the cached register values (in target byte order). */
456 /* DEPRECATED_REGISTER_VALID is 0 if the register needs to be fetched,
457 1 if it has been fetched, and
458 -1 if the register value was not available.
460 "Not available" indicates that the target is not not able to supply
461 the register at this state. The register may become available at a
462 later time (after the next resume). This often occures when GDB is
463 manipulating a target that contains only a snapshot of the entire
464 system being debugged - some of the registers in such a system may
465 not have been saved. */
467 signed char *deprecated_register_valid;
469 /* The thread/process associated with the current set of registers. */
471 static ptid_t registers_ptid;
479 Returns 0 if the value is not in the cache (needs fetch).
480 >0 if the value is in the cache.
481 <0 if the value is permanently unavailable (don't ask again). */
484 register_cached (int regnum)
486 return deprecated_register_valid[regnum];
489 /* Record that REGNUM's value is cached if STATE is >0, uncached but
490 fetchable if STATE is 0, and uncached and unfetchable if STATE is <0. */
493 set_register_cached (int regnum, int state)
495 gdb_assert (regnum >= 0);
496 gdb_assert (regnum < current_regcache->descr->nr_raw_registers);
497 current_regcache->register_valid_p[regnum] = state;
500 /* Return whether register REGNUM is a real register. */
503 real_register (int regnum)
505 return regnum >= 0 && regnum < NUM_REGS;
508 /* Low level examining and depositing of registers.
510 The caller is responsible for making sure that the inferior is
511 stopped before calling the fetching routines, or it will get
512 garbage. (a change from GDB version 3, in which the caller got the
513 value from the last stop). */
515 /* REGISTERS_CHANGED ()
517 Indicate that registers may have changed, so invalidate the cache. */
520 registers_changed (void)
524 registers_ptid = pid_to_ptid (-1);
526 /* Force cleanup of any alloca areas if using C alloca instead of
527 a builtin alloca. This particular call is used to clean up
528 areas allocated by low level target code which may build up
529 during lengthy interactions between gdb and the target before
530 gdb gives control to the user (ie watchpoints). */
533 for (i = 0; i < current_regcache->descr->nr_raw_registers; i++)
534 set_register_cached (i, 0);
536 if (registers_changed_hook)
537 registers_changed_hook ();
540 /* DEPRECATED_REGISTERS_FETCHED ()
542 Indicate that all registers have been fetched, so mark them all valid. */
544 /* NOTE: cagney/2001-12-04: This function does not set valid on the
545 pseudo-register range since pseudo registers are always supplied
546 using supply_register(). */
547 /* FIXME: cagney/2001-12-04: This function is DEPRECATED. The target
548 code was blatting the registers[] array and then calling this.
549 Since targets should only be using supply_register() the need for
550 this function/hack is eliminated. */
553 deprecated_registers_fetched (void)
557 for (i = 0; i < NUM_REGS; i++)
558 set_register_cached (i, 1);
559 /* Do not assume that the pseudo-regs have also been fetched.
560 Fetching all real regs NEVER accounts for pseudo-regs. */
563 /* read_register_bytes and write_register_bytes are generally a *BAD*
564 idea. They are inefficient because they need to check for partial
565 updates, which can only be done by scanning through all of the
566 registers and seeing if the bytes that are being read/written fall
567 inside of an invalid register. [The main reason this is necessary
568 is that register sizes can vary, so a simple index won't suffice.]
569 It is far better to call read_register_gen and write_register_gen
570 if you want to get at the raw register contents, as it only takes a
571 regnum as an argument, and therefore can't do a partial register
574 Prior to the recent fixes to check for partial updates, both read
575 and write_register_bytes always checked to see if any registers
576 were stale, and then called target_fetch_registers (-1) to update
577 the whole set. This caused really slowed things down for remote
580 /* Copy INLEN bytes of consecutive data from registers
581 starting with the INREGBYTE'th byte of register data
582 into memory at MYADDR. */
585 read_register_bytes (int in_start, char *in_buf, int in_len)
587 int in_end = in_start + in_len;
589 char *reg_buf = alloca (MAX_REGISTER_RAW_SIZE);
591 /* See if we are trying to read bytes from out-of-date registers. If so,
592 update just those registers. */
594 for (regnum = 0; regnum < NUM_REGS + NUM_PSEUDO_REGS; regnum++)
603 reg_start = REGISTER_BYTE (regnum);
604 reg_len = REGISTER_RAW_SIZE (regnum);
605 reg_end = reg_start + reg_len;
607 if (reg_end <= in_start || in_end <= reg_start)
608 /* The range the user wants to read doesn't overlap with regnum. */
611 if (REGISTER_NAME (regnum) != NULL && *REGISTER_NAME (regnum) != '\0')
612 /* Force the cache to fetch the entire register. */
613 deprecated_read_register_gen (regnum, reg_buf);
615 /* Legacy note: even though this register is ``invalid'' we
616 still need to return something. It would appear that some
617 code relies on apparent gaps in the register array also
619 /* FIXME: cagney/2001-08-18: This is just silly. It defeats
620 the entire register read/write flow of control. Must
621 resist temptation to return 0xdeadbeef. */
622 memcpy (reg_buf, registers + reg_start, reg_len);
624 /* Legacy note: This function, for some reason, allows a NULL
625 input buffer. If the buffer is NULL, the registers are still
626 fetched, just the final transfer is skipped. */
630 /* start = max (reg_start, in_start) */
631 if (reg_start > in_start)
636 /* end = min (reg_end, in_end) */
637 if (reg_end < in_end)
642 /* Transfer just the bytes common to both IN_BUF and REG_BUF */
643 for (byte = start; byte < end; byte++)
645 in_buf[byte - in_start] = reg_buf[byte - reg_start];
650 /* Read register REGNUM into memory at MYADDR, which must be large
651 enough for REGISTER_RAW_BYTES (REGNUM). Target byte-order. If the
652 register is known to be the size of a CORE_ADDR or smaller,
653 read_register can be used instead. */
656 legacy_read_register_gen (int regnum, char *myaddr)
658 gdb_assert (regnum >= 0 && regnum < (NUM_REGS + NUM_PSEUDO_REGS));
659 if (! ptid_equal (registers_ptid, inferior_ptid))
661 registers_changed ();
662 registers_ptid = inferior_ptid;
665 if (!register_cached (regnum))
666 target_fetch_registers (regnum);
668 memcpy (myaddr, register_buffer (current_regcache, regnum),
669 REGISTER_RAW_SIZE (regnum));
673 regcache_raw_read (struct regcache *regcache, int regnum, void *buf)
675 gdb_assert (regcache != NULL && buf != NULL);
676 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
677 if (regcache->descr->legacy_p
678 && regcache->passthrough_p)
680 gdb_assert (regcache == current_regcache);
681 /* For moment, just use underlying legacy code. Ulgh!!! This
682 silently and very indirectly updates the regcache's regcache
683 via the global deprecated_register_valid[]. */
684 legacy_read_register_gen (regnum, buf);
687 /* Make certain that the register cache is up-to-date with respect
688 to the current thread. This switching shouldn't be necessary
689 only there is still only one target side register cache. Sigh!
690 On the bright side, at least there is a regcache object. */
691 if (regcache->passthrough_p)
693 gdb_assert (regcache == current_regcache);
694 if (! ptid_equal (registers_ptid, inferior_ptid))
696 registers_changed ();
697 registers_ptid = inferior_ptid;
699 if (!register_cached (regnum))
700 target_fetch_registers (regnum);
702 /* Copy the value directly into the register cache. */
703 memcpy (buf, register_buffer (regcache, regnum),
704 regcache->descr->sizeof_register[regnum]);
708 regcache_raw_read_signed (struct regcache *regcache, int regnum, LONGEST *val)
711 gdb_assert (regcache != NULL);
712 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
713 buf = alloca (regcache->descr->sizeof_register[regnum]);
714 regcache_raw_read (regcache, regnum, buf);
715 (*val) = extract_signed_integer (buf,
716 regcache->descr->sizeof_register[regnum]);
720 regcache_raw_read_unsigned (struct regcache *regcache, int regnum,
724 gdb_assert (regcache != NULL);
725 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
726 buf = alloca (regcache->descr->sizeof_register[regnum]);
727 regcache_raw_read (regcache, regnum, buf);
728 (*val) = extract_unsigned_integer (buf,
729 regcache->descr->sizeof_register[regnum]);
733 regcache_raw_write_signed (struct regcache *regcache, int regnum, LONGEST val)
736 gdb_assert (regcache != NULL);
737 gdb_assert (regnum >=0 && regnum < regcache->descr->nr_raw_registers);
738 buf = alloca (regcache->descr->sizeof_register[regnum]);
739 store_signed_integer (buf, regcache->descr->sizeof_register[regnum], val);
740 regcache_raw_write (regcache, regnum, buf);
744 regcache_raw_write_unsigned (struct regcache *regcache, int regnum,
748 gdb_assert (regcache != NULL);
749 gdb_assert (regnum >=0 && regnum < regcache->descr->nr_raw_registers);
750 buf = alloca (regcache->descr->sizeof_register[regnum]);
751 store_unsigned_integer (buf, regcache->descr->sizeof_register[regnum], val);
752 regcache_raw_write (regcache, regnum, buf);
756 deprecated_read_register_gen (int regnum, char *buf)
758 gdb_assert (current_regcache != NULL);
759 gdb_assert (current_regcache->descr->gdbarch == current_gdbarch);
760 if (current_regcache->descr->legacy_p)
762 legacy_read_register_gen (regnum, buf);
765 regcache_cooked_read (current_regcache, regnum, buf);
769 regcache_cooked_read (struct regcache *regcache, int regnum, void *buf)
771 gdb_assert (regnum >= 0);
772 gdb_assert (regnum < regcache->descr->nr_cooked_registers);
773 if (regnum < regcache->descr->nr_raw_registers)
774 regcache_raw_read (regcache, regnum, buf);
776 gdbarch_pseudo_register_read (regcache->descr->gdbarch, regcache,
781 regcache_cooked_read_signed (struct regcache *regcache, int regnum,
785 gdb_assert (regcache != NULL);
786 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
787 buf = alloca (regcache->descr->sizeof_register[regnum]);
788 regcache_cooked_read (regcache, regnum, buf);
789 (*val) = extract_signed_integer (buf,
790 regcache->descr->sizeof_register[regnum]);
794 regcache_cooked_read_unsigned (struct regcache *regcache, int regnum,
798 gdb_assert (regcache != NULL);
799 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
800 buf = alloca (regcache->descr->sizeof_register[regnum]);
801 regcache_cooked_read (regcache, regnum, buf);
802 (*val) = extract_unsigned_integer (buf,
803 regcache->descr->sizeof_register[regnum]);
806 /* Write register REGNUM at MYADDR to the target. MYADDR points at
807 REGISTER_RAW_BYTES(REGNUM), which must be in target byte-order. */
810 legacy_write_register_gen (int regnum, const void *myaddr)
813 gdb_assert (regnum >= 0 && regnum < (NUM_REGS + NUM_PSEUDO_REGS));
815 /* On the sparc, writing %g0 is a no-op, so we don't even want to
816 change the registers array if something writes to this register. */
817 if (CANNOT_STORE_REGISTER (regnum))
820 if (! ptid_equal (registers_ptid, inferior_ptid))
822 registers_changed ();
823 registers_ptid = inferior_ptid;
826 size = REGISTER_RAW_SIZE (regnum);
828 if (real_register (regnum))
830 /* If we have a valid copy of the register, and new value == old
831 value, then don't bother doing the actual store. */
832 if (register_cached (regnum)
833 && (memcmp (register_buffer (current_regcache, regnum), myaddr, size)
837 target_prepare_to_store ();
840 memcpy (register_buffer (current_regcache, regnum), myaddr, size);
842 set_register_cached (regnum, 1);
843 target_store_registers (regnum);
847 regcache_raw_write (struct regcache *regcache, int regnum, const void *buf)
849 gdb_assert (regcache != NULL && buf != NULL);
850 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
852 if (regcache->passthrough_p
853 && regcache->descr->legacy_p)
855 /* For moment, just use underlying legacy code. Ulgh!!! This
856 silently and very indirectly updates the regcache's buffers
857 via the globals deprecated_register_valid[] and registers[]. */
858 gdb_assert (regcache == current_regcache);
859 legacy_write_register_gen (regnum, buf);
863 /* On the sparc, writing %g0 is a no-op, so we don't even want to
864 change the registers array if something writes to this register. */
865 if (CANNOT_STORE_REGISTER (regnum))
868 /* Handle the simple case first -> not write through so just store
870 if (!regcache->passthrough_p)
872 memcpy (register_buffer (regcache, regnum), buf,
873 regcache->descr->sizeof_register[regnum]);
874 regcache->register_valid_p[regnum] = 1;
878 /* Make certain that the correct cache is selected. */
879 gdb_assert (regcache == current_regcache);
880 if (! ptid_equal (registers_ptid, inferior_ptid))
882 registers_changed ();
883 registers_ptid = inferior_ptid;
886 /* If we have a valid copy of the register, and new value == old
887 value, then don't bother doing the actual store. */
888 if (regcache_valid_p (regcache, regnum)
889 && (memcmp (register_buffer (regcache, regnum), buf,
890 regcache->descr->sizeof_register[regnum]) == 0))
893 target_prepare_to_store ();
894 memcpy (register_buffer (regcache, regnum), buf,
895 regcache->descr->sizeof_register[regnum]);
896 regcache->register_valid_p[regnum] = 1;
897 target_store_registers (regnum);
901 deprecated_write_register_gen (int regnum, char *buf)
903 gdb_assert (current_regcache != NULL);
904 gdb_assert (current_regcache->descr->gdbarch == current_gdbarch);
905 if (current_regcache->descr->legacy_p)
907 legacy_write_register_gen (regnum, buf);
910 regcache_cooked_write (current_regcache, regnum, buf);
914 regcache_cooked_write (struct regcache *regcache, int regnum, const void *buf)
916 gdb_assert (regnum >= 0);
917 gdb_assert (regnum < regcache->descr->nr_cooked_registers);
918 if (regnum < regcache->descr->nr_raw_registers)
919 regcache_raw_write (regcache, regnum, buf);
921 gdbarch_pseudo_register_write (regcache->descr->gdbarch, regcache,
925 /* Copy INLEN bytes of consecutive data from memory at MYADDR
926 into registers starting with the MYREGSTART'th byte of register data. */
929 write_register_bytes (int myregstart, char *myaddr, int inlen)
931 int myregend = myregstart + inlen;
934 target_prepare_to_store ();
936 /* Scan through the registers updating any that are covered by the
937 range myregstart<=>myregend using write_register_gen, which does
938 nice things like handling threads, and avoiding updates when the
939 new and old contents are the same. */
941 for (regnum = 0; regnum < NUM_REGS + NUM_PSEUDO_REGS; regnum++)
943 int regstart, regend;
945 regstart = REGISTER_BYTE (regnum);
946 regend = regstart + REGISTER_RAW_SIZE (regnum);
948 /* Is this register completely outside the range the user is writing? */
949 if (myregend <= regstart || regend <= myregstart)
952 /* Is this register completely within the range the user is writing? */
953 else if (myregstart <= regstart && regend <= myregend)
954 deprecated_write_register_gen (regnum, myaddr + (regstart - myregstart));
956 /* The register partially overlaps the range being written. */
959 char *regbuf = (char*) alloca (MAX_REGISTER_RAW_SIZE);
960 /* What's the overlap between this register's bytes and
961 those the caller wants to write? */
962 int overlapstart = max (regstart, myregstart);
963 int overlapend = min (regend, myregend);
965 /* We may be doing a partial update of an invalid register.
966 Update it from the target before scribbling on it. */
967 deprecated_read_register_gen (regnum, regbuf);
969 memcpy (registers + overlapstart,
970 myaddr + (overlapstart - myregstart),
971 overlapend - overlapstart);
973 target_store_registers (regnum);
978 /* Perform a partial register transfer using a read, modify, write
981 typedef void (regcache_read_ftype) (struct regcache *regcache, int regnum,
983 typedef void (regcache_write_ftype) (struct regcache *regcache, int regnum,
987 regcache_xfer_part (struct regcache *regcache, int regnum,
988 int offset, int len, void *in, const void *out,
989 regcache_read_ftype *read, regcache_write_ftype *write)
991 struct regcache_descr *descr = regcache->descr;
992 bfd_byte *reg = alloca (descr->max_register_size);
993 gdb_assert (offset >= 0 && offset <= descr->sizeof_register[regnum]);
994 gdb_assert (len >= 0 && offset + len <= descr->sizeof_register[regnum]);
995 /* Something to do? */
996 if (offset + len == 0)
998 /* Read (when needed) ... */
1001 || offset + len < descr->sizeof_register[regnum])
1003 gdb_assert (read != NULL);
1004 read (regcache, regnum, reg);
1006 /* ... modify ... */
1008 memcpy (in, reg + offset, len);
1010 memcpy (reg + offset, out, len);
1011 /* ... write (when needed). */
1014 gdb_assert (write != NULL);
1015 write (regcache, regnum, reg);
1020 regcache_raw_read_part (struct regcache *regcache, int regnum,
1021 int offset, int len, void *buf)
1023 struct regcache_descr *descr = regcache->descr;
1024 gdb_assert (regnum >= 0 && regnum < descr->nr_raw_registers);
1025 regcache_xfer_part (regcache, regnum, offset, len, buf, NULL,
1026 regcache_raw_read, regcache_raw_write);
1030 regcache_raw_write_part (struct regcache *regcache, int regnum,
1031 int offset, int len, const void *buf)
1033 struct regcache_descr *descr = regcache->descr;
1034 gdb_assert (regnum >= 0 && regnum < descr->nr_raw_registers);
1035 regcache_xfer_part (regcache, regnum, offset, len, NULL, buf,
1036 regcache_raw_read, regcache_raw_write);
1040 regcache_cooked_read_part (struct regcache *regcache, int regnum,
1041 int offset, int len, void *buf)
1043 struct regcache_descr *descr = regcache->descr;
1044 gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
1045 regcache_xfer_part (regcache, regnum, offset, len, buf, NULL,
1046 regcache_cooked_read, regcache_cooked_write);
1050 regcache_cooked_write_part (struct regcache *regcache, int regnum,
1051 int offset, int len, const void *buf)
1053 struct regcache_descr *descr = regcache->descr;
1054 gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
1055 regcache_xfer_part (regcache, regnum, offset, len, NULL, buf,
1056 regcache_cooked_read, regcache_cooked_write);
1059 /* Hack to keep code that view the register buffer as raw bytes
1063 register_offset_hack (struct gdbarch *gdbarch, int regnum)
1065 struct regcache_descr *descr = regcache_descr (gdbarch);
1066 gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
1067 return descr->register_offset[regnum];
1070 /* Return the contents of register REGNUM as an unsigned integer. */
1073 read_register (int regnum)
1075 char *buf = alloca (REGISTER_RAW_SIZE (regnum));
1076 deprecated_read_register_gen (regnum, buf);
1077 return (extract_unsigned_integer (buf, REGISTER_RAW_SIZE (regnum)));
1081 read_register_pid (int regnum, ptid_t ptid)
1087 if (ptid_equal (ptid, inferior_ptid))
1088 return read_register (regnum);
1090 save_ptid = inferior_ptid;
1092 inferior_ptid = ptid;
1094 retval = read_register (regnum);
1096 inferior_ptid = save_ptid;
1101 /* Return the contents of register REGNUM as a signed integer. */
1104 read_signed_register (int regnum)
1106 void *buf = alloca (REGISTER_RAW_SIZE (regnum));
1107 deprecated_read_register_gen (regnum, buf);
1108 return (extract_signed_integer (buf, REGISTER_RAW_SIZE (regnum)));
1112 read_signed_register_pid (int regnum, ptid_t ptid)
1117 if (ptid_equal (ptid, inferior_ptid))
1118 return read_signed_register (regnum);
1120 save_ptid = inferior_ptid;
1122 inferior_ptid = ptid;
1124 retval = read_signed_register (regnum);
1126 inferior_ptid = save_ptid;
1131 /* Store VALUE into the raw contents of register number REGNUM. */
1134 write_register (int regnum, LONGEST val)
1138 size = REGISTER_RAW_SIZE (regnum);
1139 buf = alloca (size);
1140 store_signed_integer (buf, size, (LONGEST) val);
1141 deprecated_write_register_gen (regnum, buf);
1145 write_register_pid (int regnum, CORE_ADDR val, ptid_t ptid)
1149 if (ptid_equal (ptid, inferior_ptid))
1151 write_register (regnum, val);
1155 save_ptid = inferior_ptid;
1157 inferior_ptid = ptid;
1159 write_register (regnum, val);
1161 inferior_ptid = save_ptid;
1164 /* SUPPLY_REGISTER()
1166 Record that register REGNUM contains VAL. This is used when the
1167 value is obtained from the inferior or core dump, so there is no
1168 need to store the value there.
1170 If VAL is a NULL pointer, then it's probably an unsupported register.
1171 We just set its value to all zeros. We might want to record this
1172 fact, and report it to the users of read_register and friends. */
1175 supply_register (int regnum, const void *val)
1178 if (! ptid_equal (registers_ptid, inferior_ptid))
1180 registers_changed ();
1181 registers_ptid = inferior_ptid;
1185 set_register_cached (regnum, 1);
1187 memcpy (register_buffer (current_regcache, regnum), val,
1188 REGISTER_RAW_SIZE (regnum));
1190 memset (register_buffer (current_regcache, regnum), '\000',
1191 REGISTER_RAW_SIZE (regnum));
1193 /* On some architectures, e.g. HPPA, there are a few stray bits in
1194 some registers, that the rest of the code would like to ignore. */
1196 /* NOTE: cagney/2001-03-16: The macro CLEAN_UP_REGISTER_VALUE is
1197 going to be deprecated. Instead architectures will leave the raw
1198 register value as is and instead clean things up as they pass
1199 through the method gdbarch_pseudo_register_read() clean up the
1202 #ifdef DEPRECATED_CLEAN_UP_REGISTER_VALUE
1203 DEPRECATED_CLEAN_UP_REGISTER_VALUE \
1204 (regnum, register_buffer (current_regcache, regnum));
1209 regcache_collect (int regnum, void *buf)
1211 memcpy (buf, register_buffer (current_regcache, regnum),
1212 REGISTER_RAW_SIZE (regnum));
1216 /* read_pc, write_pc, read_sp, write_sp, read_fp, etc. Special
1217 handling for registers PC, SP, and FP. */
1219 /* NOTE: cagney/2001-02-18: The functions generic_target_read_pc(),
1220 read_pc_pid(), read_pc(), generic_target_write_pc(),
1221 write_pc_pid(), write_pc(), generic_target_read_sp(), read_sp(),
1222 generic_target_write_sp(), write_sp(), generic_target_read_fp() and
1223 read_fp(), will eventually be moved out of the reg-cache into
1224 either frame.[hc] or to the multi-arch framework. The are not part
1225 of the raw register cache. */
1227 /* This routine is getting awfully cluttered with #if's. It's probably
1228 time to turn this into READ_PC and define it in the tm.h file.
1231 1999-06-08: The following were re-written so that it assumes the
1232 existence of a TARGET_READ_PC et.al. macro. A default generic
1233 version of that macro is made available where needed.
1235 Since the ``TARGET_READ_PC'' et.al. macro is going to be controlled
1236 by the multi-arch framework, it will eventually be possible to
1237 eliminate the intermediate read_pc_pid(). The client would call
1238 TARGET_READ_PC directly. (cagney). */
1241 generic_target_read_pc (ptid_t ptid)
1246 CORE_ADDR pc_val = ADDR_BITS_REMOVE ((CORE_ADDR) read_register_pid (PC_REGNUM, ptid));
1250 internal_error (__FILE__, __LINE__,
1251 "generic_target_read_pc");
1256 read_pc_pid (ptid_t ptid)
1258 ptid_t saved_inferior_ptid;
1261 /* In case ptid != inferior_ptid. */
1262 saved_inferior_ptid = inferior_ptid;
1263 inferior_ptid = ptid;
1265 pc_val = TARGET_READ_PC (ptid);
1267 inferior_ptid = saved_inferior_ptid;
1274 return read_pc_pid (inferior_ptid);
1278 generic_target_write_pc (CORE_ADDR pc, ptid_t ptid)
1282 write_register_pid (PC_REGNUM, pc, ptid);
1283 if (NPC_REGNUM >= 0)
1284 write_register_pid (NPC_REGNUM, pc + 4, ptid);
1286 internal_error (__FILE__, __LINE__,
1287 "generic_target_write_pc");
1292 write_pc_pid (CORE_ADDR pc, ptid_t ptid)
1294 ptid_t saved_inferior_ptid;
1296 /* In case ptid != inferior_ptid. */
1297 saved_inferior_ptid = inferior_ptid;
1298 inferior_ptid = ptid;
1300 TARGET_WRITE_PC (pc, ptid);
1302 inferior_ptid = saved_inferior_ptid;
1306 write_pc (CORE_ADDR pc)
1308 write_pc_pid (pc, inferior_ptid);
1311 /* Cope with strage ways of getting to the stack and frame pointers */
1314 generic_target_read_sp (void)
1318 return read_register (SP_REGNUM);
1320 internal_error (__FILE__, __LINE__,
1321 "generic_target_read_sp");
1327 return TARGET_READ_SP ();
1331 generic_target_write_sp (CORE_ADDR val)
1336 write_register (SP_REGNUM, val);
1340 internal_error (__FILE__, __LINE__,
1341 "generic_target_write_sp");
1345 write_sp (CORE_ADDR val)
1347 TARGET_WRITE_SP (val);
1351 generic_target_read_fp (void)
1355 return read_register (FP_REGNUM);
1357 internal_error (__FILE__, __LINE__,
1358 "generic_target_read_fp");
1364 return TARGET_READ_FP ();
1369 reg_flush_command (char *command, int from_tty)
1371 /* Force-flush the register cache. */
1372 registers_changed ();
1374 printf_filtered ("Register cache flushed.\n");
1378 build_regcache (void)
1380 current_regcache = regcache_xmalloc (current_gdbarch);
1381 current_regcache->passthrough_p = 1;
1382 registers = deprecated_grub_regcache_for_registers (current_regcache);
1383 deprecated_register_valid = deprecated_grub_regcache_for_register_valid (current_regcache);
1387 dump_endian_bytes (struct ui_file *file, enum bfd_endian endian,
1388 const unsigned char *buf, long len)
1393 case BFD_ENDIAN_BIG:
1394 for (i = 0; i < len; i++)
1395 fprintf_unfiltered (file, "%02x", buf[i]);
1397 case BFD_ENDIAN_LITTLE:
1398 for (i = len - 1; i >= 0; i--)
1399 fprintf_unfiltered (file, "%02x", buf[i]);
1402 internal_error (__FILE__, __LINE__, "Bad switch");
1406 enum regcache_dump_what
1408 regcache_dump_none, regcache_dump_raw, regcache_dump_cooked, regcache_dump_groups
1412 regcache_dump (struct regcache *regcache, struct ui_file *file,
1413 enum regcache_dump_what what_to_dump)
1415 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
1416 struct gdbarch *gdbarch = regcache->descr->gdbarch;
1417 struct reggroup *const *groups = reggroups (gdbarch);
1419 int footnote_nr = 0;
1420 int footnote_register_size = 0;
1421 int footnote_register_offset = 0;
1422 int footnote_register_type_name_null = 0;
1423 long register_offset = 0;
1424 unsigned char *buf = alloca (regcache->descr->max_register_size);
1427 fprintf_unfiltered (file, "legacy_p %d\n", regcache->descr->legacy_p);
1428 fprintf_unfiltered (file, "nr_raw_registers %d\n",
1429 regcache->descr->nr_raw_registers);
1430 fprintf_unfiltered (file, "nr_cooked_registers %d\n",
1431 regcache->descr->nr_cooked_registers);
1432 fprintf_unfiltered (file, "sizeof_raw_registers %ld\n",
1433 regcache->descr->sizeof_raw_registers);
1434 fprintf_unfiltered (file, "sizeof_raw_register_valid_p %ld\n",
1435 regcache->descr->sizeof_raw_register_valid_p);
1436 fprintf_unfiltered (file, "max_register_size %ld\n",
1437 regcache->descr->max_register_size);
1438 fprintf_unfiltered (file, "NUM_REGS %d\n", NUM_REGS);
1439 fprintf_unfiltered (file, "NUM_PSEUDO_REGS %d\n", NUM_PSEUDO_REGS);
1442 gdb_assert (regcache->descr->nr_cooked_registers
1443 == (NUM_REGS + NUM_PSEUDO_REGS));
1445 for (regnum = -1; regnum < regcache->descr->nr_cooked_registers; regnum++)
1449 fprintf_unfiltered (file, " %-10s", "Name");
1452 const char *p = REGISTER_NAME (regnum);
1455 else if (p[0] == '\0')
1457 fprintf_unfiltered (file, " %-10s", p);
1462 fprintf_unfiltered (file, " %4s", "Nr");
1464 fprintf_unfiltered (file, " %4d", regnum);
1466 /* Relative number. */
1468 fprintf_unfiltered (file, " %4s", "Rel");
1469 else if (regnum < NUM_REGS)
1470 fprintf_unfiltered (file, " %4d", regnum);
1472 fprintf_unfiltered (file, " %4d", (regnum - NUM_REGS));
1476 fprintf_unfiltered (file, " %6s ", "Offset");
1479 fprintf_unfiltered (file, " %6ld",
1480 regcache->descr->register_offset[regnum]);
1481 if (register_offset != regcache->descr->register_offset[regnum]
1482 || register_offset != REGISTER_BYTE (regnum)
1484 && (regcache->descr->register_offset[regnum]
1485 != (regcache->descr->register_offset[regnum - 1]
1486 + regcache->descr->sizeof_register[regnum - 1])))
1489 if (!footnote_register_offset)
1490 footnote_register_offset = ++footnote_nr;
1491 fprintf_unfiltered (file, "*%d", footnote_register_offset);
1494 fprintf_unfiltered (file, " ");
1495 register_offset = (regcache->descr->register_offset[regnum]
1496 + regcache->descr->sizeof_register[regnum]);
1501 fprintf_unfiltered (file, " %5s ", "Size");
1504 fprintf_unfiltered (file, " %5ld",
1505 regcache->descr->sizeof_register[regnum]);
1506 if ((regcache->descr->sizeof_register[regnum]
1507 != REGISTER_RAW_SIZE (regnum))
1508 || (regcache->descr->sizeof_register[regnum]
1509 != REGISTER_VIRTUAL_SIZE (regnum))
1510 || (regcache->descr->sizeof_register[regnum]
1511 != TYPE_LENGTH (register_type (regcache->descr->gdbarch,
1515 if (!footnote_register_size)
1516 footnote_register_size = ++footnote_nr;
1517 fprintf_unfiltered (file, "*%d", footnote_register_size);
1520 fprintf_unfiltered (file, " ");
1530 static const char blt[] = "builtin_type";
1531 t = TYPE_NAME (register_type (regcache->descr->gdbarch, regnum));
1535 if (!footnote_register_type_name_null)
1536 footnote_register_type_name_null = ++footnote_nr;
1537 xasprintf (&n, "*%d", footnote_register_type_name_null);
1538 make_cleanup (xfree, n);
1541 /* Chop a leading builtin_type. */
1542 if (strncmp (t, blt, strlen (blt)) == 0)
1545 fprintf_unfiltered (file, " %-15s", t);
1548 /* Leading space always present. */
1549 fprintf_unfiltered (file, " ");
1552 if (what_to_dump == regcache_dump_raw)
1555 fprintf_unfiltered (file, "Raw value");
1556 else if (regnum >= regcache->descr->nr_raw_registers)
1557 fprintf_unfiltered (file, "<cooked>");
1558 else if (!regcache_valid_p (regcache, regnum))
1559 fprintf_unfiltered (file, "<invalid>");
1562 regcache_raw_read (regcache, regnum, buf);
1563 fprintf_unfiltered (file, "0x");
1564 dump_endian_bytes (file, TARGET_BYTE_ORDER, buf,
1565 REGISTER_RAW_SIZE (regnum));
1569 /* Value, cooked. */
1570 if (what_to_dump == regcache_dump_cooked)
1573 fprintf_unfiltered (file, "Cooked value");
1576 regcache_cooked_read (regcache, regnum, buf);
1577 fprintf_unfiltered (file, "0x");
1578 dump_endian_bytes (file, TARGET_BYTE_ORDER, buf,
1579 REGISTER_VIRTUAL_SIZE (regnum));
1583 /* Group members. */
1584 if (what_to_dump == regcache_dump_groups)
1587 fprintf_unfiltered (file, "Groups");
1591 const char *sep = "";
1592 for (i = 0; groups[i] != NULL; i++)
1594 if (gdbarch_register_reggroup_p (gdbarch, regnum, groups[i]))
1596 fprintf_unfiltered (file, "%s%s", sep, reggroup_name (groups[i]));
1603 fprintf_unfiltered (file, "\n");
1606 if (footnote_register_size)
1607 fprintf_unfiltered (file, "*%d: Inconsistent register sizes.\n",
1608 footnote_register_size);
1609 if (footnote_register_offset)
1610 fprintf_unfiltered (file, "*%d: Inconsistent register offsets.\n",
1611 footnote_register_offset);
1612 if (footnote_register_type_name_null)
1613 fprintf_unfiltered (file,
1614 "*%d: Register type's name NULL.\n",
1615 footnote_register_type_name_null);
1616 do_cleanups (cleanups);
1620 regcache_print (char *args, enum regcache_dump_what what_to_dump)
1623 regcache_dump (current_regcache, gdb_stdout, what_to_dump);
1626 struct ui_file *file = gdb_fopen (args, "w");
1628 perror_with_name ("maintenance print architecture");
1629 regcache_dump (current_regcache, file, what_to_dump);
1630 ui_file_delete (file);
1635 maintenance_print_registers (char *args, int from_tty)
1637 regcache_print (args, regcache_dump_none);
1641 maintenance_print_raw_registers (char *args, int from_tty)
1643 regcache_print (args, regcache_dump_raw);
1647 maintenance_print_cooked_registers (char *args, int from_tty)
1649 regcache_print (args, regcache_dump_cooked);
1653 maintenance_print_register_groups (char *args, int from_tty)
1655 regcache_print (args, regcache_dump_groups);
1659 _initialize_regcache (void)
1661 regcache_descr_handle = register_gdbarch_data (init_regcache_descr,
1662 xfree_regcache_descr);
1663 REGISTER_GDBARCH_SWAP (current_regcache);
1664 register_gdbarch_swap (®isters, sizeof (registers), NULL);
1665 register_gdbarch_swap (&deprecated_register_valid, sizeof (deprecated_register_valid), NULL);
1666 register_gdbarch_swap (NULL, 0, build_regcache);
1668 add_com ("flushregs", class_maintenance, reg_flush_command,
1669 "Force gdb to flush its register cache (maintainer command)");
1671 /* Initialize the thread/process associated with the current set of
1672 registers. For now, -1 is special, and means `no current process'. */
1673 registers_ptid = pid_to_ptid (-1);
1675 add_cmd ("registers", class_maintenance,
1676 maintenance_print_registers,
1677 "Print the internal register configuration.\
1678 Takes an optional file parameter.",
1679 &maintenanceprintlist);
1680 add_cmd ("raw-registers", class_maintenance,
1681 maintenance_print_raw_registers,
1682 "Print the internal register configuration including raw values.\
1683 Takes an optional file parameter.",
1684 &maintenanceprintlist);
1685 add_cmd ("cooked-registers", class_maintenance,
1686 maintenance_print_cooked_registers,
1687 "Print the internal register configuration including cooked values.\
1688 Takes an optional file parameter.",
1689 &maintenanceprintlist);
1690 add_cmd ("register-groups", class_maintenance,
1691 maintenance_print_register_groups,
1692 "Print the internal register configuration including each register's group.\
1693 Takes an optional file parameter.",
1694 &maintenanceprintlist);