1 /* Cache and manage the values of registers for GDB, the GNU debugger.
3 Copyright 1986, 1987, 1989, 1991, 1994, 1995, 1996, 1998, 2000,
4 2001, 2002 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
29 #include "reggroups.h"
30 #include "gdb_assert.h"
31 #include "gdb_string.h"
32 #include "gdbcmd.h" /* For maintenanceprintlist. */
37 * Here is the actual register cache.
40 /* Per-architecture object describing the layout of a register cache.
41 Computed once when the architecture is created */
43 struct gdbarch_data *regcache_descr_handle;
47 /* The architecture this descriptor belongs to. */
48 struct gdbarch *gdbarch;
50 /* Is this a ``legacy'' register cache? Such caches reserve space
51 for raw and pseudo registers and allow access to both. */
54 /* The raw register cache. This should contain just [0
55 .. NUM_RAW_REGISTERS). However, for older targets, it contains
56 space for the full [0 .. NUM_RAW_REGISTERS +
57 NUM_PSEUDO_REGISTERS). */
59 long sizeof_raw_registers;
60 long sizeof_raw_register_valid_p;
62 /* The cooked register space. Each cooked register in the range
63 [0..NR_RAW_REGISTERS) is direct-mapped onto the corresponding raw
64 register. The remaining [NR_RAW_REGISTERS
65 .. NR_COOKED_REGISTERS) (a.k.a. pseudo regiters) are mapped onto
66 both raw registers and memory by the architecture methods
67 gdbarch_register_read and gdbarch_register_write. */
68 int nr_cooked_registers;
69 long sizeof_cooked_registers;
70 long sizeof_cooked_register_valid_p;
72 /* Offset and size (in 8 bit bytes), of reach register in the
73 register cache. All registers (including those in the range
74 [NR_RAW_REGISTERS .. NR_COOKED_REGISTERS) are given an offset.
75 Assigning all registers an offset makes it possible to keep
76 legacy code, such as that found in read_register_bytes() and
77 write_register_bytes() working. */
78 long *register_offset;
79 long *sizeof_register;
81 /* Useful constant. Largest of all the registers. */
82 long max_register_size;
84 /* Cached table containing the type of each register. */
85 struct type **register_type;
89 init_legacy_regcache_descr (struct gdbarch *gdbarch,
90 struct regcache_descr *descr)
93 /* FIXME: cagney/2002-05-11: gdbarch_data() should take that
94 ``gdbarch'' as a parameter. */
95 gdb_assert (gdbarch != NULL);
97 /* FIXME: cagney/2002-05-11: Shouldn't be including pseudo-registers
98 in the register cache. Unfortunatly some architectures still
99 rely on this and the pseudo_register_write() method. */
100 descr->nr_raw_registers = descr->nr_cooked_registers;
101 descr->sizeof_raw_register_valid_p = descr->sizeof_cooked_register_valid_p;
103 /* Compute the offset of each register. Legacy architectures define
104 REGISTER_BYTE() so use that. */
105 /* FIXME: cagney/2002-11-07: Instead of using REGISTER_BYTE() this
106 code should, as is done in init_regcache_descr(), compute the
107 offets at runtime. This currently isn't possible as some ISAs
108 define overlapping register regions - see the mess in
109 read_register_bytes() and write_register_bytes() registers. */
110 descr->sizeof_register = XCALLOC (descr->nr_cooked_registers, long);
111 descr->register_offset = XCALLOC (descr->nr_cooked_registers, long);
112 descr->max_register_size = 0;
113 for (i = 0; i < descr->nr_cooked_registers; i++)
115 /* FIXME: cagney/2001-12-04: This code shouldn't need to use
116 REGISTER_BYTE(). Unfortunatly, legacy code likes to lay the
117 buffer out so that certain registers just happen to overlap.
118 Ulgh! New targets use gdbarch's register read/write and
119 entirely avoid this uglyness. */
120 descr->register_offset[i] = REGISTER_BYTE (i);
121 descr->sizeof_register[i] = REGISTER_RAW_SIZE (i);
122 if (descr->max_register_size < REGISTER_RAW_SIZE (i))
123 descr->max_register_size = REGISTER_RAW_SIZE (i);
124 if (descr->max_register_size < REGISTER_VIRTUAL_SIZE (i))
125 descr->max_register_size = REGISTER_VIRTUAL_SIZE (i);
128 /* Compute the real size of the register buffer. Start out by
129 trusting REGISTER_BYTES, but then adjust it upwards should that
130 be found to not be sufficient. */
131 /* FIXME: cagney/2002-11-05: Instead of using REGISTER_BYTES, this
132 code should, as is done in init_regcache_descr(), compute the
133 total number of register bytes using the accumulated offsets. */
134 descr->sizeof_cooked_registers = REGISTER_BYTES; /* OK use. */
135 for (i = 0; i < descr->nr_cooked_registers; i++)
138 /* Keep extending the buffer so that there is always enough
139 space for all registers. The comparison is necessary since
140 legacy code is free to put registers in random places in the
141 buffer separated by holes. Once REGISTER_BYTE() is killed
142 this can be greatly simplified. */
143 regend = descr->register_offset[i] + descr->sizeof_register[i];
144 if (descr->sizeof_cooked_registers < regend)
145 descr->sizeof_cooked_registers = regend;
147 /* FIXME: cagney/2002-05-11: Shouldn't be including pseudo-registers
148 in the register cache. Unfortunatly some architectures still
149 rely on this and the pseudo_register_write() method. */
150 descr->sizeof_raw_registers = descr->sizeof_cooked_registers;
154 init_regcache_descr (struct gdbarch *gdbarch)
157 struct regcache_descr *descr;
158 gdb_assert (gdbarch != NULL);
160 /* Create an initial, zero filled, table. */
161 descr = XCALLOC (1, struct regcache_descr);
162 descr->gdbarch = gdbarch;
164 /* Total size of the register space. The raw registers are mapped
165 directly onto the raw register cache while the pseudo's are
166 either mapped onto raw-registers or memory. */
167 descr->nr_cooked_registers = NUM_REGS + NUM_PSEUDO_REGS;
168 descr->sizeof_cooked_register_valid_p = NUM_REGS + NUM_PSEUDO_REGS;
170 /* Fill in a table of register types. */
171 descr->register_type = XCALLOC (descr->nr_cooked_registers,
173 for (i = 0; i < descr->nr_cooked_registers; i++)
175 if (gdbarch_register_type_p (gdbarch))
177 gdb_assert (!REGISTER_VIRTUAL_TYPE_P ()); /* OK */
178 descr->register_type[i] = gdbarch_register_type (gdbarch, i);
181 descr->register_type[i] = REGISTER_VIRTUAL_TYPE (i); /* OK */
184 /* If an old style architecture, fill in the remainder of the
185 register cache descriptor using the register macros. */
186 if (!gdbarch_pseudo_register_read_p (gdbarch)
187 && !gdbarch_pseudo_register_write_p (gdbarch)
188 && !gdbarch_register_type_p (gdbarch))
191 init_legacy_regcache_descr (gdbarch, descr);
195 /* Construct a strictly RAW register cache. Don't allow pseudo's
196 into the register cache. */
197 descr->nr_raw_registers = NUM_REGS;
199 /* FIXME: cagney/2002-08-13: Overallocate the register_valid_p
200 array. This pretects GDB from erant code that accesses elements
201 of the global register_valid_p[] array in the range [NUM_REGS
202 .. NUM_REGS + NUM_PSEUDO_REGS). */
203 descr->sizeof_raw_register_valid_p = descr->sizeof_cooked_register_valid_p;
205 /* Lay out the register cache.
207 NOTE: cagney/2002-05-22: Only register_type() is used when
208 constructing the register cache. It is assumed that the
209 register's raw size, virtual size and type length are all the
214 descr->sizeof_register = XCALLOC (descr->nr_cooked_registers, long);
215 descr->register_offset = XCALLOC (descr->nr_cooked_registers, long);
216 descr->max_register_size = 0;
217 for (i = 0; i < descr->nr_cooked_registers; i++)
219 descr->sizeof_register[i] = TYPE_LENGTH (descr->register_type[i]);
220 descr->register_offset[i] = offset;
221 offset += descr->sizeof_register[i];
222 if (descr->max_register_size < descr->sizeof_register[i])
223 descr->max_register_size = descr->sizeof_register[i];
225 /* Set the real size of the register cache buffer. */
226 descr->sizeof_cooked_registers = offset;
229 /* FIXME: cagney/2002-05-22: Should only need to allocate space for
230 the raw registers. Unfortunatly some code still accesses the
231 register array directly using the global registers[]. Until that
232 code has been purged, play safe and over allocating the register
234 descr->sizeof_raw_registers = descr->sizeof_cooked_registers;
237 /* Sanity check. Confirm that the assumptions about gdbarch are
238 true. The REGCACHE_DESCR_HANDLE is set before doing the checks
239 so that targets using the generic methods supplied by regcache
240 don't go into infinite recursion trying to, again, create the
242 set_gdbarch_data (gdbarch, regcache_descr_handle, descr);
243 for (i = 0; i < descr->nr_cooked_registers; i++)
245 gdb_assert (descr->sizeof_register[i] == REGISTER_RAW_SIZE (i));
246 gdb_assert (descr->sizeof_register[i] == REGISTER_VIRTUAL_SIZE (i));
247 gdb_assert (descr->register_offset[i] == REGISTER_BYTE (i));
249 /* gdb_assert (descr->sizeof_raw_registers == REGISTER_BYTES (i)); */
255 static struct regcache_descr *
256 regcache_descr (struct gdbarch *gdbarch)
258 return gdbarch_data (gdbarch, regcache_descr_handle);
262 xfree_regcache_descr (struct gdbarch *gdbarch, void *ptr)
264 struct regcache_descr *descr = ptr;
267 xfree (descr->register_offset);
268 xfree (descr->sizeof_register);
269 descr->register_offset = NULL;
270 descr->sizeof_register = NULL;
274 /* Utility functions returning useful register attributes stored in
275 the regcache descr. */
278 register_type (struct gdbarch *gdbarch, int regnum)
280 struct regcache_descr *descr = regcache_descr (gdbarch);
281 gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
282 return descr->register_type[regnum];
285 /* Utility functions returning useful register attributes stored in
286 the regcache descr. */
289 max_register_size (struct gdbarch *gdbarch)
291 struct regcache_descr *descr = regcache_descr (gdbarch);
292 return descr->max_register_size;
296 legacy_max_register_raw_size (void)
298 if (DEPRECATED_MAX_REGISTER_RAW_SIZE_P ())
299 return DEPRECATED_MAX_REGISTER_RAW_SIZE;
301 return max_register_size (current_gdbarch);
305 legacy_max_register_virtual_size (void)
307 if (DEPRECATED_MAX_REGISTER_VIRTUAL_SIZE_P ())
308 return DEPRECATED_MAX_REGISTER_VIRTUAL_SIZE;
310 return max_register_size (current_gdbarch);
314 register_size (struct gdbarch *gdbarch, int regnum)
316 struct regcache_descr *descr = regcache_descr (gdbarch);
318 gdb_assert (regnum >= 0 && regnum < (NUM_REGS + NUM_PSEUDO_REGS));
319 size = descr->sizeof_register[regnum];
320 gdb_assert (size == REGISTER_RAW_SIZE (regnum)); /* OK */
321 gdb_assert (size == REGISTER_RAW_SIZE (regnum)); /* OK */
325 /* The register cache for storing raw register values. */
329 struct regcache_descr *descr;
330 /* The register buffers. A read-only register cache can hold the
331 full [0 .. NUM_REGS + NUM_PSEUDO_REGS) while a read/write
332 register cache can only hold [0 .. NUM_REGS). */
334 char *register_valid_p;
335 /* Is this a read-only cache? A read-only cache is used for saving
336 the target's register state (e.g, across an inferior function
337 call or just before forcing a function return). A read-only
338 cache can only be updated via the methods regcache_dup() and
339 regcache_cpy(). The actual contents are determined by the
340 reggroup_save and reggroup_restore methods. */
345 regcache_xmalloc (struct gdbarch *gdbarch)
347 struct regcache_descr *descr;
348 struct regcache *regcache;
349 gdb_assert (gdbarch != NULL);
350 descr = regcache_descr (gdbarch);
351 regcache = XMALLOC (struct regcache);
352 regcache->descr = descr;
354 = XCALLOC (descr->sizeof_raw_registers, char);
355 regcache->register_valid_p
356 = XCALLOC (descr->sizeof_raw_register_valid_p, char);
357 regcache->readonly_p = 1;
362 regcache_xfree (struct regcache *regcache)
364 if (regcache == NULL)
366 xfree (regcache->registers);
367 xfree (regcache->register_valid_p);
372 do_regcache_xfree (void *data)
374 regcache_xfree (data);
378 make_cleanup_regcache_xfree (struct regcache *regcache)
380 return make_cleanup (do_regcache_xfree, regcache);
383 /* Return a pointer to register REGNUM's buffer cache. */
386 register_buffer (struct regcache *regcache, int regnum)
388 return regcache->registers + regcache->descr->register_offset[regnum];
392 regcache_save (struct regcache *dst, regcache_cooked_read_ftype *cooked_read,
395 struct gdbarch *gdbarch = dst->descr->gdbarch;
396 void *buf = alloca (max_register_size (gdbarch));
398 /* The DST should be `read-only', if it wasn't then the save would
399 end up trying to write the register values back out to the
401 gdb_assert (dst->readonly_p);
402 /* Clear the dest. */
403 memset (dst->registers, 0, dst->descr->sizeof_cooked_registers);
404 memset (dst->register_valid_p, 0, dst->descr->sizeof_cooked_register_valid_p);
405 /* Copy over any registers (identified by their membership in the
406 save_reggroup) and mark them as valid. The full [0 .. NUM_REGS +
407 NUM_PSEUDO_REGS) range is checked since some architectures need
408 to save/restore `cooked' registers that live in memory. */
409 for (regnum = 0; regnum < dst->descr->nr_cooked_registers; regnum++)
411 if (gdbarch_register_reggroup_p (gdbarch, regnum, save_reggroup))
413 int valid = cooked_read (src, regnum, buf);
416 memcpy (register_buffer (dst, regnum), buf,
417 register_size (gdbarch, regnum));
418 dst->register_valid_p[regnum] = 1;
425 regcache_restore (struct regcache *dst,
426 regcache_cooked_read_ftype *cooked_read,
429 struct gdbarch *gdbarch = dst->descr->gdbarch;
430 void *buf = alloca (max_register_size (gdbarch));
432 /* The dst had better not be read-only. If it is, the `restore'
433 doesn't make much sense. */
434 gdb_assert (!dst->readonly_p);
435 /* Copy over any registers, being careful to only restore those that
436 were both saved and need to be restored. The full [0 .. NUM_REGS
437 + NUM_PSEUDO_REGS) range is checked since some architectures need
438 to save/restore `cooked' registers that live in memory. */
439 for (regnum = 0; regnum < dst->descr->nr_cooked_registers; regnum++)
441 if (gdbarch_register_reggroup_p (gdbarch, regnum, restore_reggroup))
443 int valid = cooked_read (src, regnum, buf);
445 regcache_cooked_write (dst, regnum, buf);
451 do_cooked_read (void *src, int regnum, void *buf)
453 struct regcache *regcache = src;
454 if (!regcache_valid_p (regcache, regnum)
455 && regcache->readonly_p)
456 /* Don't even think about fetching a register from a read-only
457 cache when the register isn't yet valid. There isn't a target
458 from which the register value can be fetched. */
460 regcache_cooked_read (regcache, regnum, buf);
466 regcache_cpy (struct regcache *dst, struct regcache *src)
470 gdb_assert (src != NULL && dst != NULL);
471 gdb_assert (src->descr->gdbarch == dst->descr->gdbarch);
472 gdb_assert (src != dst);
473 gdb_assert (src->readonly_p || dst->readonly_p);
474 if (!src->readonly_p)
475 regcache_save (dst, do_cooked_read, src);
476 else if (!dst->readonly_p)
477 regcache_restore (dst, do_cooked_read, src);
479 regcache_cpy_no_passthrough (dst, src);
483 regcache_cpy_no_passthrough (struct regcache *dst, struct regcache *src)
486 gdb_assert (src != NULL && dst != NULL);
487 gdb_assert (src->descr->gdbarch == dst->descr->gdbarch);
488 /* NOTE: cagney/2002-05-17: Don't let the caller do a no-passthrough
489 move of data into the current_regcache(). Doing this would be
490 silly - it would mean that valid_p would be completly invalid. */
491 gdb_assert (dst != current_regcache);
492 memcpy (dst->registers, src->registers, dst->descr->sizeof_raw_registers);
493 memcpy (dst->register_valid_p, src->register_valid_p,
494 dst->descr->sizeof_raw_register_valid_p);
498 regcache_dup (struct regcache *src)
500 struct regcache *newbuf;
501 gdb_assert (current_regcache != NULL);
502 newbuf = regcache_xmalloc (src->descr->gdbarch);
503 regcache_cpy (newbuf, src);
508 regcache_dup_no_passthrough (struct regcache *src)
510 struct regcache *newbuf;
511 gdb_assert (current_regcache != NULL);
512 newbuf = regcache_xmalloc (src->descr->gdbarch);
513 regcache_cpy_no_passthrough (newbuf, src);
518 regcache_valid_p (struct regcache *regcache, int regnum)
520 gdb_assert (regcache != NULL);
521 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
522 return regcache->register_valid_p[regnum];
526 deprecated_grub_regcache_for_registers (struct regcache *regcache)
528 return regcache->registers;
532 deprecated_grub_regcache_for_register_valid (struct regcache *regcache)
534 return regcache->register_valid_p;
537 /* Global structure containing the current regcache. */
538 /* FIXME: cagney/2002-05-11: The two global arrays registers[] and
539 deprecated_register_valid[] currently point into this structure. */
540 struct regcache *current_regcache;
542 /* NOTE: this is a write-through cache. There is no "dirty" bit for
543 recording if the register values have been changed (eg. by the
544 user). Therefore all registers must be written back to the
545 target when appropriate. */
547 /* REGISTERS contains the cached register values (in target byte order). */
549 char *deprecated_registers;
551 /* DEPRECATED_REGISTER_VALID is 0 if the register needs to be fetched,
552 1 if it has been fetched, and
553 -1 if the register value was not available.
555 "Not available" indicates that the target is not not able to supply
556 the register at this state. The register may become available at a
557 later time (after the next resume). This often occures when GDB is
558 manipulating a target that contains only a snapshot of the entire
559 system being debugged - some of the registers in such a system may
560 not have been saved. */
562 signed char *deprecated_register_valid;
564 /* The thread/process associated with the current set of registers. */
566 static ptid_t registers_ptid;
574 Returns 0 if the value is not in the cache (needs fetch).
575 >0 if the value is in the cache.
576 <0 if the value is permanently unavailable (don't ask again). */
579 register_cached (int regnum)
581 return deprecated_register_valid[regnum];
584 /* Record that REGNUM's value is cached if STATE is >0, uncached but
585 fetchable if STATE is 0, and uncached and unfetchable if STATE is <0. */
588 set_register_cached (int regnum, int state)
590 gdb_assert (regnum >= 0);
591 gdb_assert (regnum < current_regcache->descr->nr_raw_registers);
592 current_regcache->register_valid_p[regnum] = state;
595 /* Return whether register REGNUM is a real register. */
598 real_register (int regnum)
600 return regnum >= 0 && regnum < NUM_REGS;
603 /* Low level examining and depositing of registers.
605 The caller is responsible for making sure that the inferior is
606 stopped before calling the fetching routines, or it will get
607 garbage. (a change from GDB version 3, in which the caller got the
608 value from the last stop). */
610 /* REGISTERS_CHANGED ()
612 Indicate that registers may have changed, so invalidate the cache. */
615 registers_changed (void)
619 registers_ptid = pid_to_ptid (-1);
621 /* Force cleanup of any alloca areas if using C alloca instead of
622 a builtin alloca. This particular call is used to clean up
623 areas allocated by low level target code which may build up
624 during lengthy interactions between gdb and the target before
625 gdb gives control to the user (ie watchpoints). */
628 for (i = 0; i < current_regcache->descr->nr_raw_registers; i++)
629 set_register_cached (i, 0);
631 if (registers_changed_hook)
632 registers_changed_hook ();
635 /* DEPRECATED_REGISTERS_FETCHED ()
637 Indicate that all registers have been fetched, so mark them all valid. */
639 /* NOTE: cagney/2001-12-04: This function does not set valid on the
640 pseudo-register range since pseudo registers are always supplied
641 using supply_register(). */
642 /* FIXME: cagney/2001-12-04: This function is DEPRECATED. The target
643 code was blatting the registers[] array and then calling this.
644 Since targets should only be using supply_register() the need for
645 this function/hack is eliminated. */
648 deprecated_registers_fetched (void)
652 for (i = 0; i < NUM_REGS; i++)
653 set_register_cached (i, 1);
654 /* Do not assume that the pseudo-regs have also been fetched.
655 Fetching all real regs NEVER accounts for pseudo-regs. */
658 /* deprecated_read_register_bytes and deprecated_write_register_bytes
659 are generally a *BAD* idea. They are inefficient because they need
660 to check for partial updates, which can only be done by scanning
661 through all of the registers and seeing if the bytes that are being
662 read/written fall inside of an invalid register. [The main reason
663 this is necessary is that register sizes can vary, so a simple
664 index won't suffice.] It is far better to call read_register_gen
665 and write_register_gen if you want to get at the raw register
666 contents, as it only takes a regnum as an argument, and therefore
667 can't do a partial register update.
669 Prior to the recent fixes to check for partial updates, both read
670 and deprecated_write_register_bytes always checked to see if any
671 registers were stale, and then called target_fetch_registers (-1)
672 to update the whole set. This caused really slowed things down for
675 /* Copy INLEN bytes of consecutive data from registers
676 starting with the INREGBYTE'th byte of register data
677 into memory at MYADDR. */
680 deprecated_read_register_bytes (int in_start, char *in_buf, int in_len)
682 int in_end = in_start + in_len;
684 char *reg_buf = alloca (MAX_REGISTER_RAW_SIZE);
686 /* See if we are trying to read bytes from out-of-date registers. If so,
687 update just those registers. */
689 for (regnum = 0; regnum < NUM_REGS + NUM_PSEUDO_REGS; regnum++)
698 reg_start = REGISTER_BYTE (regnum);
699 reg_len = REGISTER_RAW_SIZE (regnum);
700 reg_end = reg_start + reg_len;
702 if (reg_end <= in_start || in_end <= reg_start)
703 /* The range the user wants to read doesn't overlap with regnum. */
706 if (REGISTER_NAME (regnum) != NULL && *REGISTER_NAME (regnum) != '\0')
707 /* Force the cache to fetch the entire register. */
708 deprecated_read_register_gen (regnum, reg_buf);
710 /* Legacy note: even though this register is ``invalid'' we
711 still need to return something. It would appear that some
712 code relies on apparent gaps in the register array also
714 /* FIXME: cagney/2001-08-18: This is just silly. It defeats
715 the entire register read/write flow of control. Must
716 resist temptation to return 0xdeadbeef. */
717 memcpy (reg_buf, &deprecated_registers[reg_start], reg_len);
719 /* Legacy note: This function, for some reason, allows a NULL
720 input buffer. If the buffer is NULL, the registers are still
721 fetched, just the final transfer is skipped. */
725 /* start = max (reg_start, in_start) */
726 if (reg_start > in_start)
731 /* end = min (reg_end, in_end) */
732 if (reg_end < in_end)
737 /* Transfer just the bytes common to both IN_BUF and REG_BUF */
738 for (byte = start; byte < end; byte++)
740 in_buf[byte - in_start] = reg_buf[byte - reg_start];
745 /* Read register REGNUM into memory at MYADDR, which must be large
746 enough for REGISTER_RAW_BYTES (REGNUM). Target byte-order. If the
747 register is known to be the size of a CORE_ADDR or smaller,
748 read_register can be used instead. */
751 legacy_read_register_gen (int regnum, char *myaddr)
753 gdb_assert (regnum >= 0 && regnum < (NUM_REGS + NUM_PSEUDO_REGS));
754 if (! ptid_equal (registers_ptid, inferior_ptid))
756 registers_changed ();
757 registers_ptid = inferior_ptid;
760 if (!register_cached (regnum))
761 target_fetch_registers (regnum);
763 memcpy (myaddr, register_buffer (current_regcache, regnum),
764 REGISTER_RAW_SIZE (regnum));
768 regcache_raw_read (struct regcache *regcache, int regnum, void *buf)
770 gdb_assert (regcache != NULL && buf != NULL);
771 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
772 if (regcache->descr->legacy_p
773 && !regcache->readonly_p)
775 gdb_assert (regcache == current_regcache);
776 /* For moment, just use underlying legacy code. Ulgh!!! This
777 silently and very indirectly updates the regcache's regcache
778 via the global deprecated_register_valid[]. */
779 legacy_read_register_gen (regnum, buf);
782 /* Make certain that the register cache is up-to-date with respect
783 to the current thread. This switching shouldn't be necessary
784 only there is still only one target side register cache. Sigh!
785 On the bright side, at least there is a regcache object. */
786 if (!regcache->readonly_p)
788 gdb_assert (regcache == current_regcache);
789 if (! ptid_equal (registers_ptid, inferior_ptid))
791 registers_changed ();
792 registers_ptid = inferior_ptid;
794 if (!register_cached (regnum))
795 target_fetch_registers (regnum);
797 /* Copy the value directly into the register cache. */
798 memcpy (buf, register_buffer (regcache, regnum),
799 regcache->descr->sizeof_register[regnum]);
803 regcache_raw_read_signed (struct regcache *regcache, int regnum, LONGEST *val)
806 gdb_assert (regcache != NULL);
807 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
808 buf = alloca (regcache->descr->sizeof_register[regnum]);
809 regcache_raw_read (regcache, regnum, buf);
810 (*val) = extract_signed_integer (buf,
811 regcache->descr->sizeof_register[regnum]);
815 regcache_raw_read_unsigned (struct regcache *regcache, int regnum,
819 gdb_assert (regcache != NULL);
820 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
821 buf = alloca (regcache->descr->sizeof_register[regnum]);
822 regcache_raw_read (regcache, regnum, buf);
823 (*val) = extract_unsigned_integer (buf,
824 regcache->descr->sizeof_register[regnum]);
828 regcache_raw_write_signed (struct regcache *regcache, int regnum, LONGEST val)
831 gdb_assert (regcache != NULL);
832 gdb_assert (regnum >=0 && regnum < regcache->descr->nr_raw_registers);
833 buf = alloca (regcache->descr->sizeof_register[regnum]);
834 store_signed_integer (buf, regcache->descr->sizeof_register[regnum], val);
835 regcache_raw_write (regcache, regnum, buf);
839 regcache_raw_write_unsigned (struct regcache *regcache, int regnum,
843 gdb_assert (regcache != NULL);
844 gdb_assert (regnum >=0 && regnum < regcache->descr->nr_raw_registers);
845 buf = alloca (regcache->descr->sizeof_register[regnum]);
846 store_unsigned_integer (buf, regcache->descr->sizeof_register[regnum], val);
847 regcache_raw_write (regcache, regnum, buf);
851 deprecated_read_register_gen (int regnum, char *buf)
853 gdb_assert (current_regcache != NULL);
854 gdb_assert (current_regcache->descr->gdbarch == current_gdbarch);
855 if (current_regcache->descr->legacy_p)
857 legacy_read_register_gen (regnum, buf);
860 regcache_cooked_read (current_regcache, regnum, buf);
864 regcache_cooked_read (struct regcache *regcache, int regnum, void *buf)
866 gdb_assert (regnum >= 0);
867 gdb_assert (regnum < regcache->descr->nr_cooked_registers);
868 if (regnum < regcache->descr->nr_raw_registers)
869 regcache_raw_read (regcache, regnum, buf);
870 else if (regcache->readonly_p
871 && regnum < regcache->descr->nr_cooked_registers
872 && regcache->register_valid_p[regnum])
873 /* Read-only register cache, perhaphs the cooked value was cached? */
874 memcpy (buf, register_buffer (regcache, regnum),
875 regcache->descr->sizeof_register[regnum]);
877 gdbarch_pseudo_register_read (regcache->descr->gdbarch, regcache,
882 regcache_cooked_read_signed (struct regcache *regcache, int regnum,
886 gdb_assert (regcache != NULL);
887 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_cooked_registers);
888 buf = alloca (regcache->descr->sizeof_register[regnum]);
889 regcache_cooked_read (regcache, regnum, buf);
890 (*val) = extract_signed_integer (buf,
891 regcache->descr->sizeof_register[regnum]);
895 regcache_cooked_read_unsigned (struct regcache *regcache, int regnum,
899 gdb_assert (regcache != NULL);
900 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_cooked_registers);
901 buf = alloca (regcache->descr->sizeof_register[regnum]);
902 regcache_cooked_read (regcache, regnum, buf);
903 (*val) = extract_unsigned_integer (buf,
904 regcache->descr->sizeof_register[regnum]);
908 regcache_cooked_write_signed (struct regcache *regcache, int regnum,
912 gdb_assert (regcache != NULL);
913 gdb_assert (regnum >=0 && regnum < regcache->descr->nr_cooked_registers);
914 buf = alloca (regcache->descr->sizeof_register[regnum]);
915 store_signed_integer (buf, regcache->descr->sizeof_register[regnum], val);
916 regcache_cooked_write (regcache, regnum, buf);
920 regcache_cooked_write_unsigned (struct regcache *regcache, int regnum,
924 gdb_assert (regcache != NULL);
925 gdb_assert (regnum >=0 && regnum < regcache->descr->nr_cooked_registers);
926 buf = alloca (regcache->descr->sizeof_register[regnum]);
927 store_unsigned_integer (buf, regcache->descr->sizeof_register[regnum], val);
928 regcache_cooked_write (regcache, regnum, buf);
931 /* Write register REGNUM at MYADDR to the target. MYADDR points at
932 REGISTER_RAW_BYTES(REGNUM), which must be in target byte-order. */
935 legacy_write_register_gen (int regnum, const void *myaddr)
938 gdb_assert (regnum >= 0 && regnum < (NUM_REGS + NUM_PSEUDO_REGS));
940 /* On the sparc, writing %g0 is a no-op, so we don't even want to
941 change the registers array if something writes to this register. */
942 if (CANNOT_STORE_REGISTER (regnum))
945 if (! ptid_equal (registers_ptid, inferior_ptid))
947 registers_changed ();
948 registers_ptid = inferior_ptid;
951 size = REGISTER_RAW_SIZE (regnum);
953 if (real_register (regnum))
955 /* If we have a valid copy of the register, and new value == old
956 value, then don't bother doing the actual store. */
957 if (register_cached (regnum)
958 && (memcmp (register_buffer (current_regcache, regnum), myaddr, size)
962 target_prepare_to_store ();
965 memcpy (register_buffer (current_regcache, regnum), myaddr, size);
967 set_register_cached (regnum, 1);
968 target_store_registers (regnum);
972 regcache_raw_write (struct regcache *regcache, int regnum, const void *buf)
974 gdb_assert (regcache != NULL && buf != NULL);
975 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
976 gdb_assert (!regcache->readonly_p);
978 if (regcache->descr->legacy_p)
980 /* For moment, just use underlying legacy code. Ulgh!!! This
981 silently and very indirectly updates the regcache's buffers
982 via the globals deprecated_register_valid[] and registers[]. */
983 gdb_assert (regcache == current_regcache);
984 legacy_write_register_gen (regnum, buf);
988 /* On the sparc, writing %g0 is a no-op, so we don't even want to
989 change the registers array if something writes to this register. */
990 if (CANNOT_STORE_REGISTER (regnum))
993 /* Make certain that the correct cache is selected. */
994 gdb_assert (regcache == current_regcache);
995 if (! ptid_equal (registers_ptid, inferior_ptid))
997 registers_changed ();
998 registers_ptid = inferior_ptid;
1001 /* If we have a valid copy of the register, and new value == old
1002 value, then don't bother doing the actual store. */
1003 if (regcache_valid_p (regcache, regnum)
1004 && (memcmp (register_buffer (regcache, regnum), buf,
1005 regcache->descr->sizeof_register[regnum]) == 0))
1008 target_prepare_to_store ();
1009 memcpy (register_buffer (regcache, regnum), buf,
1010 regcache->descr->sizeof_register[regnum]);
1011 regcache->register_valid_p[regnum] = 1;
1012 target_store_registers (regnum);
1016 deprecated_write_register_gen (int regnum, char *buf)
1018 gdb_assert (current_regcache != NULL);
1019 gdb_assert (current_regcache->descr->gdbarch == current_gdbarch);
1020 if (current_regcache->descr->legacy_p)
1022 legacy_write_register_gen (regnum, buf);
1025 regcache_cooked_write (current_regcache, regnum, buf);
1029 regcache_cooked_write (struct regcache *regcache, int regnum, const void *buf)
1031 gdb_assert (regnum >= 0);
1032 gdb_assert (regnum < regcache->descr->nr_cooked_registers);
1033 if (regnum < regcache->descr->nr_raw_registers)
1034 regcache_raw_write (regcache, regnum, buf);
1036 gdbarch_pseudo_register_write (regcache->descr->gdbarch, regcache,
1040 /* Copy INLEN bytes of consecutive data from memory at MYADDR
1041 into registers starting with the MYREGSTART'th byte of register data. */
1044 deprecated_write_register_bytes (int myregstart, char *myaddr, int inlen)
1046 int myregend = myregstart + inlen;
1049 target_prepare_to_store ();
1051 /* Scan through the registers updating any that are covered by the
1052 range myregstart<=>myregend using write_register_gen, which does
1053 nice things like handling threads, and avoiding updates when the
1054 new and old contents are the same. */
1056 for (regnum = 0; regnum < NUM_REGS + NUM_PSEUDO_REGS; regnum++)
1058 int regstart, regend;
1060 regstart = REGISTER_BYTE (regnum);
1061 regend = regstart + REGISTER_RAW_SIZE (regnum);
1063 /* Is this register completely outside the range the user is writing? */
1064 if (myregend <= regstart || regend <= myregstart)
1067 /* Is this register completely within the range the user is writing? */
1068 else if (myregstart <= regstart && regend <= myregend)
1069 deprecated_write_register_gen (regnum, myaddr + (regstart - myregstart));
1071 /* The register partially overlaps the range being written. */
1074 char *regbuf = (char*) alloca (MAX_REGISTER_RAW_SIZE);
1075 /* What's the overlap between this register's bytes and
1076 those the caller wants to write? */
1077 int overlapstart = max (regstart, myregstart);
1078 int overlapend = min (regend, myregend);
1080 /* We may be doing a partial update of an invalid register.
1081 Update it from the target before scribbling on it. */
1082 deprecated_read_register_gen (regnum, regbuf);
1084 memcpy (&deprecated_registers[overlapstart],
1085 myaddr + (overlapstart - myregstart),
1086 overlapend - overlapstart);
1088 target_store_registers (regnum);
1093 /* Perform a partial register transfer using a read, modify, write
1096 typedef void (regcache_read_ftype) (struct regcache *regcache, int regnum,
1098 typedef void (regcache_write_ftype) (struct regcache *regcache, int regnum,
1102 regcache_xfer_part (struct regcache *regcache, int regnum,
1103 int offset, int len, void *in, const void *out,
1104 regcache_read_ftype *read, regcache_write_ftype *write)
1106 struct regcache_descr *descr = regcache->descr;
1107 bfd_byte *reg = alloca (descr->max_register_size);
1108 gdb_assert (offset >= 0 && offset <= descr->sizeof_register[regnum]);
1109 gdb_assert (len >= 0 && offset + len <= descr->sizeof_register[regnum]);
1110 /* Something to do? */
1111 if (offset + len == 0)
1113 /* Read (when needed) ... */
1116 || offset + len < descr->sizeof_register[regnum])
1118 gdb_assert (read != NULL);
1119 read (regcache, regnum, reg);
1121 /* ... modify ... */
1123 memcpy (in, reg + offset, len);
1125 memcpy (reg + offset, out, len);
1126 /* ... write (when needed). */
1129 gdb_assert (write != NULL);
1130 write (regcache, regnum, reg);
1135 regcache_raw_read_part (struct regcache *regcache, int regnum,
1136 int offset, int len, void *buf)
1138 struct regcache_descr *descr = regcache->descr;
1139 gdb_assert (regnum >= 0 && regnum < descr->nr_raw_registers);
1140 regcache_xfer_part (regcache, regnum, offset, len, buf, NULL,
1141 regcache_raw_read, regcache_raw_write);
1145 regcache_raw_write_part (struct regcache *regcache, int regnum,
1146 int offset, int len, const void *buf)
1148 struct regcache_descr *descr = regcache->descr;
1149 gdb_assert (regnum >= 0 && regnum < descr->nr_raw_registers);
1150 regcache_xfer_part (regcache, regnum, offset, len, NULL, buf,
1151 regcache_raw_read, regcache_raw_write);
1155 regcache_cooked_read_part (struct regcache *regcache, int regnum,
1156 int offset, int len, void *buf)
1158 struct regcache_descr *descr = regcache->descr;
1159 gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
1160 regcache_xfer_part (regcache, regnum, offset, len, buf, NULL,
1161 regcache_cooked_read, regcache_cooked_write);
1165 regcache_cooked_write_part (struct regcache *regcache, int regnum,
1166 int offset, int len, const void *buf)
1168 struct regcache_descr *descr = regcache->descr;
1169 gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
1170 regcache_xfer_part (regcache, regnum, offset, len, NULL, buf,
1171 regcache_cooked_read, regcache_cooked_write);
1174 /* Hack to keep code that view the register buffer as raw bytes
1178 register_offset_hack (struct gdbarch *gdbarch, int regnum)
1180 struct regcache_descr *descr = regcache_descr (gdbarch);
1181 gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
1182 return descr->register_offset[regnum];
1185 /* Return the contents of register REGNUM as an unsigned integer. */
1188 read_register (int regnum)
1190 char *buf = alloca (REGISTER_RAW_SIZE (regnum));
1191 deprecated_read_register_gen (regnum, buf);
1192 return (extract_unsigned_integer (buf, REGISTER_RAW_SIZE (regnum)));
1196 read_register_pid (int regnum, ptid_t ptid)
1202 if (ptid_equal (ptid, inferior_ptid))
1203 return read_register (regnum);
1205 save_ptid = inferior_ptid;
1207 inferior_ptid = ptid;
1209 retval = read_register (regnum);
1211 inferior_ptid = save_ptid;
1216 /* Return the contents of register REGNUM as a signed integer. */
1219 read_signed_register (int regnum)
1221 void *buf = alloca (REGISTER_RAW_SIZE (regnum));
1222 deprecated_read_register_gen (regnum, buf);
1223 return (extract_signed_integer (buf, REGISTER_RAW_SIZE (regnum)));
1227 read_signed_register_pid (int regnum, ptid_t ptid)
1232 if (ptid_equal (ptid, inferior_ptid))
1233 return read_signed_register (regnum);
1235 save_ptid = inferior_ptid;
1237 inferior_ptid = ptid;
1239 retval = read_signed_register (regnum);
1241 inferior_ptid = save_ptid;
1246 /* Store VALUE into the raw contents of register number REGNUM. */
1249 write_register (int regnum, LONGEST val)
1253 size = REGISTER_RAW_SIZE (regnum);
1254 buf = alloca (size);
1255 store_signed_integer (buf, size, (LONGEST) val);
1256 deprecated_write_register_gen (regnum, buf);
1260 write_register_pid (int regnum, CORE_ADDR val, ptid_t ptid)
1264 if (ptid_equal (ptid, inferior_ptid))
1266 write_register (regnum, val);
1270 save_ptid = inferior_ptid;
1272 inferior_ptid = ptid;
1274 write_register (regnum, val);
1276 inferior_ptid = save_ptid;
1279 /* SUPPLY_REGISTER()
1281 Record that register REGNUM contains VAL. This is used when the
1282 value is obtained from the inferior or core dump, so there is no
1283 need to store the value there.
1285 If VAL is a NULL pointer, then it's probably an unsupported register.
1286 We just set its value to all zeros. We might want to record this
1287 fact, and report it to the users of read_register and friends. */
1290 supply_register (int regnum, const void *val)
1293 if (! ptid_equal (registers_ptid, inferior_ptid))
1295 registers_changed ();
1296 registers_ptid = inferior_ptid;
1300 set_register_cached (regnum, 1);
1302 memcpy (register_buffer (current_regcache, regnum), val,
1303 REGISTER_RAW_SIZE (regnum));
1305 memset (register_buffer (current_regcache, regnum), '\000',
1306 REGISTER_RAW_SIZE (regnum));
1308 /* On some architectures, e.g. HPPA, there are a few stray bits in
1309 some registers, that the rest of the code would like to ignore. */
1311 /* NOTE: cagney/2001-03-16: The macro CLEAN_UP_REGISTER_VALUE is
1312 going to be deprecated. Instead architectures will leave the raw
1313 register value as is and instead clean things up as they pass
1314 through the method gdbarch_pseudo_register_read() clean up the
1317 #ifdef DEPRECATED_CLEAN_UP_REGISTER_VALUE
1318 DEPRECATED_CLEAN_UP_REGISTER_VALUE \
1319 (regnum, register_buffer (current_regcache, regnum));
1324 regcache_collect (int regnum, void *buf)
1326 memcpy (buf, register_buffer (current_regcache, regnum),
1327 REGISTER_RAW_SIZE (regnum));
1331 /* read_pc, write_pc, read_sp, deprecated_read_fp, etc. Special
1332 handling for registers PC, SP, and FP. */
1334 /* NOTE: cagney/2001-02-18: The functions generic_target_read_pc(),
1335 read_pc_pid(), read_pc(), generic_target_write_pc(),
1336 write_pc_pid(), write_pc(), generic_target_read_sp(), read_sp(),
1337 generic_target_write_sp(), and deprecated_read_fp(), will
1338 eventually be moved out of the reg-cache into either frame.[hc] or
1339 to the multi-arch framework. The are not part of the raw register
1342 /* This routine is getting awfully cluttered with #if's. It's probably
1343 time to turn this into READ_PC and define it in the tm.h file.
1346 1999-06-08: The following were re-written so that it assumes the
1347 existence of a TARGET_READ_PC et.al. macro. A default generic
1348 version of that macro is made available where needed.
1350 Since the ``TARGET_READ_PC'' et.al. macro is going to be controlled
1351 by the multi-arch framework, it will eventually be possible to
1352 eliminate the intermediate read_pc_pid(). The client would call
1353 TARGET_READ_PC directly. (cagney). */
1356 generic_target_read_pc (ptid_t ptid)
1361 CORE_ADDR pc_val = ADDR_BITS_REMOVE ((CORE_ADDR) read_register_pid (PC_REGNUM, ptid));
1365 internal_error (__FILE__, __LINE__,
1366 "generic_target_read_pc");
1371 read_pc_pid (ptid_t ptid)
1373 ptid_t saved_inferior_ptid;
1376 /* In case ptid != inferior_ptid. */
1377 saved_inferior_ptid = inferior_ptid;
1378 inferior_ptid = ptid;
1380 pc_val = TARGET_READ_PC (ptid);
1382 inferior_ptid = saved_inferior_ptid;
1389 return read_pc_pid (inferior_ptid);
1393 generic_target_write_pc (CORE_ADDR pc, ptid_t ptid)
1397 write_register_pid (PC_REGNUM, pc, ptid);
1398 if (NPC_REGNUM >= 0)
1399 write_register_pid (NPC_REGNUM, pc + 4, ptid);
1401 internal_error (__FILE__, __LINE__,
1402 "generic_target_write_pc");
1407 write_pc_pid (CORE_ADDR pc, ptid_t ptid)
1409 ptid_t saved_inferior_ptid;
1411 /* In case ptid != inferior_ptid. */
1412 saved_inferior_ptid = inferior_ptid;
1413 inferior_ptid = ptid;
1415 TARGET_WRITE_PC (pc, ptid);
1417 inferior_ptid = saved_inferior_ptid;
1421 write_pc (CORE_ADDR pc)
1423 write_pc_pid (pc, inferior_ptid);
1426 /* Cope with strage ways of getting to the stack and frame pointers */
1429 generic_target_read_sp (void)
1433 return read_register (SP_REGNUM);
1435 internal_error (__FILE__, __LINE__,
1436 "generic_target_read_sp");
1442 return TARGET_READ_SP ();
1446 generic_target_write_sp (CORE_ADDR val)
1451 write_register (SP_REGNUM, val);
1455 internal_error (__FILE__, __LINE__,
1456 "generic_target_write_sp");
1460 deprecated_read_fp (void)
1462 if (DEPRECATED_TARGET_READ_FP_P ())
1463 return DEPRECATED_TARGET_READ_FP ();
1464 else if (DEPRECATED_FP_REGNUM >= 0)
1465 return read_register (DEPRECATED_FP_REGNUM);
1467 internal_error (__FILE__, __LINE__, "deprecated_read_fp");
1472 reg_flush_command (char *command, int from_tty)
1474 /* Force-flush the register cache. */
1475 registers_changed ();
1477 printf_filtered ("Register cache flushed.\n");
1481 build_regcache (void)
1483 current_regcache = regcache_xmalloc (current_gdbarch);
1484 current_regcache->readonly_p = 0;
1485 deprecated_registers = deprecated_grub_regcache_for_registers (current_regcache);
1486 deprecated_register_valid = deprecated_grub_regcache_for_register_valid (current_regcache);
1490 dump_endian_bytes (struct ui_file *file, enum bfd_endian endian,
1491 const unsigned char *buf, long len)
1496 case BFD_ENDIAN_BIG:
1497 for (i = 0; i < len; i++)
1498 fprintf_unfiltered (file, "%02x", buf[i]);
1500 case BFD_ENDIAN_LITTLE:
1501 for (i = len - 1; i >= 0; i--)
1502 fprintf_unfiltered (file, "%02x", buf[i]);
1505 internal_error (__FILE__, __LINE__, "Bad switch");
1509 enum regcache_dump_what
1511 regcache_dump_none, regcache_dump_raw, regcache_dump_cooked, regcache_dump_groups
1515 regcache_dump (struct regcache *regcache, struct ui_file *file,
1516 enum regcache_dump_what what_to_dump)
1518 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
1519 struct gdbarch *gdbarch = regcache->descr->gdbarch;
1520 struct reggroup *const *groups = reggroups (gdbarch);
1522 int footnote_nr = 0;
1523 int footnote_register_size = 0;
1524 int footnote_register_offset = 0;
1525 int footnote_register_type_name_null = 0;
1526 long register_offset = 0;
1527 unsigned char *buf = alloca (regcache->descr->max_register_size);
1530 fprintf_unfiltered (file, "legacy_p %d\n", regcache->descr->legacy_p);
1531 fprintf_unfiltered (file, "nr_raw_registers %d\n",
1532 regcache->descr->nr_raw_registers);
1533 fprintf_unfiltered (file, "nr_cooked_registers %d\n",
1534 regcache->descr->nr_cooked_registers);
1535 fprintf_unfiltered (file, "sizeof_raw_registers %ld\n",
1536 regcache->descr->sizeof_raw_registers);
1537 fprintf_unfiltered (file, "sizeof_raw_register_valid_p %ld\n",
1538 regcache->descr->sizeof_raw_register_valid_p);
1539 fprintf_unfiltered (file, "max_register_size %ld\n",
1540 regcache->descr->max_register_size);
1541 fprintf_unfiltered (file, "NUM_REGS %d\n", NUM_REGS);
1542 fprintf_unfiltered (file, "NUM_PSEUDO_REGS %d\n", NUM_PSEUDO_REGS);
1545 gdb_assert (regcache->descr->nr_cooked_registers
1546 == (NUM_REGS + NUM_PSEUDO_REGS));
1548 for (regnum = -1; regnum < regcache->descr->nr_cooked_registers; regnum++)
1552 fprintf_unfiltered (file, " %-10s", "Name");
1555 const char *p = REGISTER_NAME (regnum);
1558 else if (p[0] == '\0')
1560 fprintf_unfiltered (file, " %-10s", p);
1565 fprintf_unfiltered (file, " %4s", "Nr");
1567 fprintf_unfiltered (file, " %4d", regnum);
1569 /* Relative number. */
1571 fprintf_unfiltered (file, " %4s", "Rel");
1572 else if (regnum < NUM_REGS)
1573 fprintf_unfiltered (file, " %4d", regnum);
1575 fprintf_unfiltered (file, " %4d", (regnum - NUM_REGS));
1579 fprintf_unfiltered (file, " %6s ", "Offset");
1582 fprintf_unfiltered (file, " %6ld",
1583 regcache->descr->register_offset[regnum]);
1584 if (register_offset != regcache->descr->register_offset[regnum]
1585 || register_offset != REGISTER_BYTE (regnum)
1587 && (regcache->descr->register_offset[regnum]
1588 != (regcache->descr->register_offset[regnum - 1]
1589 + regcache->descr->sizeof_register[regnum - 1])))
1592 if (!footnote_register_offset)
1593 footnote_register_offset = ++footnote_nr;
1594 fprintf_unfiltered (file, "*%d", footnote_register_offset);
1597 fprintf_unfiltered (file, " ");
1598 register_offset = (regcache->descr->register_offset[regnum]
1599 + regcache->descr->sizeof_register[regnum]);
1604 fprintf_unfiltered (file, " %5s ", "Size");
1607 fprintf_unfiltered (file, " %5ld",
1608 regcache->descr->sizeof_register[regnum]);
1609 if ((regcache->descr->sizeof_register[regnum]
1610 != REGISTER_RAW_SIZE (regnum))
1611 || (regcache->descr->sizeof_register[regnum]
1612 != REGISTER_VIRTUAL_SIZE (regnum))
1613 || (regcache->descr->sizeof_register[regnum]
1614 != TYPE_LENGTH (register_type (regcache->descr->gdbarch,
1618 if (!footnote_register_size)
1619 footnote_register_size = ++footnote_nr;
1620 fprintf_unfiltered (file, "*%d", footnote_register_size);
1623 fprintf_unfiltered (file, " ");
1633 static const char blt[] = "builtin_type";
1634 t = TYPE_NAME (register_type (regcache->descr->gdbarch, regnum));
1638 if (!footnote_register_type_name_null)
1639 footnote_register_type_name_null = ++footnote_nr;
1640 xasprintf (&n, "*%d", footnote_register_type_name_null);
1641 make_cleanup (xfree, n);
1644 /* Chop a leading builtin_type. */
1645 if (strncmp (t, blt, strlen (blt)) == 0)
1648 fprintf_unfiltered (file, " %-15s", t);
1651 /* Leading space always present. */
1652 fprintf_unfiltered (file, " ");
1655 if (what_to_dump == regcache_dump_raw)
1658 fprintf_unfiltered (file, "Raw value");
1659 else if (regnum >= regcache->descr->nr_raw_registers)
1660 fprintf_unfiltered (file, "<cooked>");
1661 else if (!regcache_valid_p (regcache, regnum))
1662 fprintf_unfiltered (file, "<invalid>");
1665 regcache_raw_read (regcache, regnum, buf);
1666 fprintf_unfiltered (file, "0x");
1667 dump_endian_bytes (file, TARGET_BYTE_ORDER, buf,
1668 REGISTER_RAW_SIZE (regnum));
1672 /* Value, cooked. */
1673 if (what_to_dump == regcache_dump_cooked)
1676 fprintf_unfiltered (file, "Cooked value");
1679 regcache_cooked_read (regcache, regnum, buf);
1680 fprintf_unfiltered (file, "0x");
1681 dump_endian_bytes (file, TARGET_BYTE_ORDER, buf,
1682 REGISTER_VIRTUAL_SIZE (regnum));
1686 /* Group members. */
1687 if (what_to_dump == regcache_dump_groups)
1690 fprintf_unfiltered (file, "Groups");
1694 const char *sep = "";
1695 for (i = 0; groups[i] != NULL; i++)
1697 if (gdbarch_register_reggroup_p (gdbarch, regnum, groups[i]))
1699 fprintf_unfiltered (file, "%s%s", sep, reggroup_name (groups[i]));
1706 fprintf_unfiltered (file, "\n");
1709 if (footnote_register_size)
1710 fprintf_unfiltered (file, "*%d: Inconsistent register sizes.\n",
1711 footnote_register_size);
1712 if (footnote_register_offset)
1713 fprintf_unfiltered (file, "*%d: Inconsistent register offsets.\n",
1714 footnote_register_offset);
1715 if (footnote_register_type_name_null)
1716 fprintf_unfiltered (file,
1717 "*%d: Register type's name NULL.\n",
1718 footnote_register_type_name_null);
1719 do_cleanups (cleanups);
1723 regcache_print (char *args, enum regcache_dump_what what_to_dump)
1726 regcache_dump (current_regcache, gdb_stdout, what_to_dump);
1729 struct ui_file *file = gdb_fopen (args, "w");
1731 perror_with_name ("maintenance print architecture");
1732 regcache_dump (current_regcache, file, what_to_dump);
1733 ui_file_delete (file);
1738 maintenance_print_registers (char *args, int from_tty)
1740 regcache_print (args, regcache_dump_none);
1744 maintenance_print_raw_registers (char *args, int from_tty)
1746 regcache_print (args, regcache_dump_raw);
1750 maintenance_print_cooked_registers (char *args, int from_tty)
1752 regcache_print (args, regcache_dump_cooked);
1756 maintenance_print_register_groups (char *args, int from_tty)
1758 regcache_print (args, regcache_dump_groups);
1762 _initialize_regcache (void)
1764 regcache_descr_handle = register_gdbarch_data (init_regcache_descr,
1765 xfree_regcache_descr);
1766 REGISTER_GDBARCH_SWAP (current_regcache);
1767 register_gdbarch_swap (&deprecated_registers, sizeof (deprecated_registers), NULL);
1768 register_gdbarch_swap (&deprecated_register_valid, sizeof (deprecated_register_valid), NULL);
1769 register_gdbarch_swap (NULL, 0, build_regcache);
1771 add_com ("flushregs", class_maintenance, reg_flush_command,
1772 "Force gdb to flush its register cache (maintainer command)");
1774 /* Initialize the thread/process associated with the current set of
1775 registers. For now, -1 is special, and means `no current process'. */
1776 registers_ptid = pid_to_ptid (-1);
1778 add_cmd ("registers", class_maintenance,
1779 maintenance_print_registers,
1780 "Print the internal register configuration.\
1781 Takes an optional file parameter.",
1782 &maintenanceprintlist);
1783 add_cmd ("raw-registers", class_maintenance,
1784 maintenance_print_raw_registers,
1785 "Print the internal register configuration including raw values.\
1786 Takes an optional file parameter.",
1787 &maintenanceprintlist);
1788 add_cmd ("cooked-registers", class_maintenance,
1789 maintenance_print_cooked_registers,
1790 "Print the internal register configuration including cooked values.\
1791 Takes an optional file parameter.",
1792 &maintenanceprintlist);
1793 add_cmd ("register-groups", class_maintenance,
1794 maintenance_print_register_groups,
1795 "Print the internal register configuration including each register's group.\
1796 Takes an optional file parameter.",
1797 &maintenanceprintlist);