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))
190 /* NOTE: cagney/2003-05-02: Don't add a test for REGISTER_BYTE_P
191 to the above. Doing that would cause all the existing
192 architectures to revert back to the legacy regcache
193 mechanisms, and that is not a good thing. Instead just,
194 later, check that the register cache's layout is consistent
195 with REGISTER_BYTE. */
197 init_legacy_regcache_descr (gdbarch, descr);
201 /* Construct a strictly RAW register cache. Don't allow pseudo's
202 into the register cache. */
203 descr->nr_raw_registers = NUM_REGS;
205 /* FIXME: cagney/2002-08-13: Overallocate the register_valid_p
206 array. This pretects GDB from erant code that accesses elements
207 of the global register_valid_p[] array in the range [NUM_REGS
208 .. NUM_REGS + NUM_PSEUDO_REGS). */
209 descr->sizeof_raw_register_valid_p = descr->sizeof_cooked_register_valid_p;
211 /* Lay out the register cache.
213 NOTE: cagney/2002-05-22: Only register_type() is used when
214 constructing the register cache. It is assumed that the
215 register's raw size, virtual size and type length are all the
220 descr->sizeof_register = XCALLOC (descr->nr_cooked_registers, long);
221 descr->register_offset = XCALLOC (descr->nr_cooked_registers, long);
222 descr->max_register_size = 0;
223 for (i = 0; i < descr->nr_cooked_registers; i++)
225 descr->sizeof_register[i] = TYPE_LENGTH (descr->register_type[i]);
226 descr->register_offset[i] = offset;
227 offset += descr->sizeof_register[i];
228 if (descr->max_register_size < descr->sizeof_register[i])
229 descr->max_register_size = descr->sizeof_register[i];
231 /* Set the real size of the register cache buffer. */
232 descr->sizeof_cooked_registers = offset;
235 /* FIXME: cagney/2002-05-22: Should only need to allocate space for
236 the raw registers. Unfortunatly some code still accesses the
237 register array directly using the global registers[]. Until that
238 code has been purged, play safe and over allocating the register
240 descr->sizeof_raw_registers = descr->sizeof_cooked_registers;
242 /* Sanity check. Confirm that there is agreement between the
243 regcache and the target's redundant REGISTER_BYTE (new targets
244 should not even be defining it). */
245 for (i = 0; i < descr->nr_cooked_registers; i++)
247 if (REGISTER_BYTE_P ())
248 gdb_assert (descr->register_offset[i] == REGISTER_BYTE (i));
250 gdb_assert (descr->sizeof_register[i] == REGISTER_RAW_SIZE (i));
251 gdb_assert (descr->sizeof_register[i] == REGISTER_VIRTUAL_SIZE (i));
254 /* gdb_assert (descr->sizeof_raw_registers == REGISTER_BYTES (i)); */
259 static struct regcache_descr *
260 regcache_descr (struct gdbarch *gdbarch)
262 return gdbarch_data (gdbarch, regcache_descr_handle);
266 xfree_regcache_descr (struct gdbarch *gdbarch, void *ptr)
268 struct regcache_descr *descr = ptr;
271 xfree (descr->register_offset);
272 xfree (descr->sizeof_register);
273 descr->register_offset = NULL;
274 descr->sizeof_register = NULL;
278 /* Utility functions returning useful register attributes stored in
279 the regcache descr. */
282 register_type (struct gdbarch *gdbarch, int regnum)
284 struct regcache_descr *descr = regcache_descr (gdbarch);
285 gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
286 return descr->register_type[regnum];
289 /* Utility functions returning useful register attributes stored in
290 the regcache descr. */
293 max_register_size (struct gdbarch *gdbarch)
295 struct regcache_descr *descr = regcache_descr (gdbarch);
296 return descr->max_register_size;
300 legacy_max_register_raw_size (void)
302 if (DEPRECATED_MAX_REGISTER_RAW_SIZE_P ())
303 return DEPRECATED_MAX_REGISTER_RAW_SIZE;
305 return max_register_size (current_gdbarch);
309 register_size (struct gdbarch *gdbarch, int regnum)
311 struct regcache_descr *descr = regcache_descr (gdbarch);
313 gdb_assert (regnum >= 0 && regnum < (NUM_REGS + NUM_PSEUDO_REGS));
314 size = descr->sizeof_register[regnum];
315 gdb_assert (size == REGISTER_RAW_SIZE (regnum)); /* OK */
316 gdb_assert (size == REGISTER_RAW_SIZE (regnum)); /* OK */
320 /* The register cache for storing raw register values. */
324 struct regcache_descr *descr;
325 /* The register buffers. A read-only register cache can hold the
326 full [0 .. NUM_REGS + NUM_PSEUDO_REGS) while a read/write
327 register cache can only hold [0 .. NUM_REGS). */
329 char *register_valid_p;
330 /* Is this a read-only cache? A read-only cache is used for saving
331 the target's register state (e.g, across an inferior function
332 call or just before forcing a function return). A read-only
333 cache can only be updated via the methods regcache_dup() and
334 regcache_cpy(). The actual contents are determined by the
335 reggroup_save and reggroup_restore methods. */
340 regcache_xmalloc (struct gdbarch *gdbarch)
342 struct regcache_descr *descr;
343 struct regcache *regcache;
344 gdb_assert (gdbarch != NULL);
345 descr = regcache_descr (gdbarch);
346 regcache = XMALLOC (struct regcache);
347 regcache->descr = descr;
349 = XCALLOC (descr->sizeof_raw_registers, char);
350 regcache->register_valid_p
351 = XCALLOC (descr->sizeof_raw_register_valid_p, char);
352 regcache->readonly_p = 1;
357 regcache_xfree (struct regcache *regcache)
359 if (regcache == NULL)
361 xfree (regcache->registers);
362 xfree (regcache->register_valid_p);
367 do_regcache_xfree (void *data)
369 regcache_xfree (data);
373 make_cleanup_regcache_xfree (struct regcache *regcache)
375 return make_cleanup (do_regcache_xfree, regcache);
378 /* Return a pointer to register REGNUM's buffer cache. */
381 register_buffer (struct regcache *regcache, int regnum)
383 return regcache->registers + regcache->descr->register_offset[regnum];
387 regcache_save (struct regcache *dst, regcache_cooked_read_ftype *cooked_read,
390 struct gdbarch *gdbarch = dst->descr->gdbarch;
391 void *buf = alloca (max_register_size (gdbarch));
393 /* The DST should be `read-only', if it wasn't then the save would
394 end up trying to write the register values back out to the
396 gdb_assert (dst->readonly_p);
397 /* Clear the dest. */
398 memset (dst->registers, 0, dst->descr->sizeof_cooked_registers);
399 memset (dst->register_valid_p, 0, dst->descr->sizeof_cooked_register_valid_p);
400 /* Copy over any registers (identified by their membership in the
401 save_reggroup) and mark them as valid. The full [0 .. NUM_REGS +
402 NUM_PSEUDO_REGS) range is checked since some architectures need
403 to save/restore `cooked' registers that live in memory. */
404 for (regnum = 0; regnum < dst->descr->nr_cooked_registers; regnum++)
406 if (gdbarch_register_reggroup_p (gdbarch, regnum, save_reggroup))
408 int valid = cooked_read (src, regnum, buf);
411 memcpy (register_buffer (dst, regnum), buf,
412 register_size (gdbarch, regnum));
413 dst->register_valid_p[regnum] = 1;
420 regcache_restore (struct regcache *dst,
421 regcache_cooked_read_ftype *cooked_read,
424 struct gdbarch *gdbarch = dst->descr->gdbarch;
425 void *buf = alloca (max_register_size (gdbarch));
427 /* The dst had better not be read-only. If it is, the `restore'
428 doesn't make much sense. */
429 gdb_assert (!dst->readonly_p);
430 /* Copy over any registers, being careful to only restore those that
431 were both saved and need to be restored. The full [0 .. NUM_REGS
432 + NUM_PSEUDO_REGS) range is checked since some architectures need
433 to save/restore `cooked' registers that live in memory. */
434 for (regnum = 0; regnum < dst->descr->nr_cooked_registers; regnum++)
436 if (gdbarch_register_reggroup_p (gdbarch, regnum, restore_reggroup))
438 int valid = cooked_read (src, regnum, buf);
440 regcache_cooked_write (dst, regnum, buf);
446 do_cooked_read (void *src, int regnum, void *buf)
448 struct regcache *regcache = src;
449 if (!regcache_valid_p (regcache, regnum)
450 && regcache->readonly_p)
451 /* Don't even think about fetching a register from a read-only
452 cache when the register isn't yet valid. There isn't a target
453 from which the register value can be fetched. */
455 regcache_cooked_read (regcache, regnum, buf);
461 regcache_cpy (struct regcache *dst, struct regcache *src)
465 gdb_assert (src != NULL && dst != NULL);
466 gdb_assert (src->descr->gdbarch == dst->descr->gdbarch);
467 gdb_assert (src != dst);
468 gdb_assert (src->readonly_p || dst->readonly_p);
469 if (!src->readonly_p)
470 regcache_save (dst, do_cooked_read, src);
471 else if (!dst->readonly_p)
472 regcache_restore (dst, do_cooked_read, src);
474 regcache_cpy_no_passthrough (dst, src);
478 regcache_cpy_no_passthrough (struct regcache *dst, struct regcache *src)
481 gdb_assert (src != NULL && dst != NULL);
482 gdb_assert (src->descr->gdbarch == dst->descr->gdbarch);
483 /* NOTE: cagney/2002-05-17: Don't let the caller do a no-passthrough
484 move of data into the current_regcache(). Doing this would be
485 silly - it would mean that valid_p would be completly invalid. */
486 gdb_assert (dst != current_regcache);
487 memcpy (dst->registers, src->registers, dst->descr->sizeof_raw_registers);
488 memcpy (dst->register_valid_p, src->register_valid_p,
489 dst->descr->sizeof_raw_register_valid_p);
493 regcache_dup (struct regcache *src)
495 struct regcache *newbuf;
496 gdb_assert (current_regcache != NULL);
497 newbuf = regcache_xmalloc (src->descr->gdbarch);
498 regcache_cpy (newbuf, src);
503 regcache_dup_no_passthrough (struct regcache *src)
505 struct regcache *newbuf;
506 gdb_assert (current_regcache != NULL);
507 newbuf = regcache_xmalloc (src->descr->gdbarch);
508 regcache_cpy_no_passthrough (newbuf, src);
513 regcache_valid_p (struct regcache *regcache, int regnum)
515 gdb_assert (regcache != NULL);
516 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
517 return regcache->register_valid_p[regnum];
521 deprecated_grub_regcache_for_registers (struct regcache *regcache)
523 return regcache->registers;
527 deprecated_grub_regcache_for_register_valid (struct regcache *regcache)
529 return regcache->register_valid_p;
532 /* Global structure containing the current regcache. */
533 /* FIXME: cagney/2002-05-11: The two global arrays registers[] and
534 deprecated_register_valid[] currently point into this structure. */
535 struct regcache *current_regcache;
537 /* NOTE: this is a write-through cache. There is no "dirty" bit for
538 recording if the register values have been changed (eg. by the
539 user). Therefore all registers must be written back to the
540 target when appropriate. */
542 /* REGISTERS contains the cached register values (in target byte order). */
544 char *deprecated_registers;
546 /* DEPRECATED_REGISTER_VALID is 0 if the register needs to be fetched,
547 1 if it has been fetched, and
548 -1 if the register value was not available.
550 "Not available" indicates that the target is not not able to supply
551 the register at this state. The register may become available at a
552 later time (after the next resume). This often occures when GDB is
553 manipulating a target that contains only a snapshot of the entire
554 system being debugged - some of the registers in such a system may
555 not have been saved. */
557 signed char *deprecated_register_valid;
559 /* The thread/process associated with the current set of registers. */
561 static ptid_t registers_ptid;
569 Returns 0 if the value is not in the cache (needs fetch).
570 >0 if the value is in the cache.
571 <0 if the value is permanently unavailable (don't ask again). */
574 register_cached (int regnum)
576 return deprecated_register_valid[regnum];
579 /* Record that REGNUM's value is cached if STATE is >0, uncached but
580 fetchable if STATE is 0, and uncached and unfetchable if STATE is <0. */
583 set_register_cached (int regnum, int state)
585 gdb_assert (regnum >= 0);
586 gdb_assert (regnum < current_regcache->descr->nr_raw_registers);
587 current_regcache->register_valid_p[regnum] = state;
590 /* Return whether register REGNUM is a real register. */
593 real_register (int regnum)
595 return regnum >= 0 && regnum < NUM_REGS;
598 /* Low level examining and depositing of registers.
600 The caller is responsible for making sure that the inferior is
601 stopped before calling the fetching routines, or it will get
602 garbage. (a change from GDB version 3, in which the caller got the
603 value from the last stop). */
605 /* REGISTERS_CHANGED ()
607 Indicate that registers may have changed, so invalidate the cache. */
610 registers_changed (void)
614 registers_ptid = pid_to_ptid (-1);
616 /* Force cleanup of any alloca areas if using C alloca instead of
617 a builtin alloca. This particular call is used to clean up
618 areas allocated by low level target code which may build up
619 during lengthy interactions between gdb and the target before
620 gdb gives control to the user (ie watchpoints). */
623 for (i = 0; i < current_regcache->descr->nr_raw_registers; i++)
624 set_register_cached (i, 0);
626 if (registers_changed_hook)
627 registers_changed_hook ();
630 /* DEPRECATED_REGISTERS_FETCHED ()
632 Indicate that all registers have been fetched, so mark them all valid. */
634 /* NOTE: cagney/2001-12-04: This function does not set valid on the
635 pseudo-register range since pseudo registers are always supplied
636 using supply_register(). */
637 /* FIXME: cagney/2001-12-04: This function is DEPRECATED. The target
638 code was blatting the registers[] array and then calling this.
639 Since targets should only be using supply_register() the need for
640 this function/hack is eliminated. */
643 deprecated_registers_fetched (void)
647 for (i = 0; i < NUM_REGS; i++)
648 set_register_cached (i, 1);
649 /* Do not assume that the pseudo-regs have also been fetched.
650 Fetching all real regs NEVER accounts for pseudo-regs. */
653 /* deprecated_read_register_bytes and deprecated_write_register_bytes
654 are generally a *BAD* idea. They are inefficient because they need
655 to check for partial updates, which can only be done by scanning
656 through all of the registers and seeing if the bytes that are being
657 read/written fall inside of an invalid register. [The main reason
658 this is necessary is that register sizes can vary, so a simple
659 index won't suffice.] It is far better to call read_register_gen
660 and write_register_gen if you want to get at the raw register
661 contents, as it only takes a regnum as an argument, and therefore
662 can't do a partial register update.
664 Prior to the recent fixes to check for partial updates, both read
665 and deprecated_write_register_bytes always checked to see if any
666 registers were stale, and then called target_fetch_registers (-1)
667 to update the whole set. This caused really slowed things down for
670 /* Copy INLEN bytes of consecutive data from registers
671 starting with the INREGBYTE'th byte of register data
672 into memory at MYADDR. */
675 deprecated_read_register_bytes (int in_start, char *in_buf, int in_len)
677 int in_end = in_start + in_len;
679 char *reg_buf = alloca (MAX_REGISTER_RAW_SIZE);
681 /* See if we are trying to read bytes from out-of-date registers. If so,
682 update just those registers. */
684 for (regnum = 0; regnum < NUM_REGS + NUM_PSEUDO_REGS; regnum++)
693 reg_start = REGISTER_BYTE (regnum);
694 reg_len = REGISTER_RAW_SIZE (regnum);
695 reg_end = reg_start + reg_len;
697 if (reg_end <= in_start || in_end <= reg_start)
698 /* The range the user wants to read doesn't overlap with regnum. */
701 if (REGISTER_NAME (regnum) != NULL && *REGISTER_NAME (regnum) != '\0')
702 /* Force the cache to fetch the entire register. */
703 deprecated_read_register_gen (regnum, reg_buf);
705 /* Legacy note: even though this register is ``invalid'' we
706 still need to return something. It would appear that some
707 code relies on apparent gaps in the register array also
709 /* FIXME: cagney/2001-08-18: This is just silly. It defeats
710 the entire register read/write flow of control. Must
711 resist temptation to return 0xdeadbeef. */
712 memcpy (reg_buf, &deprecated_registers[reg_start], reg_len);
714 /* Legacy note: This function, for some reason, allows a NULL
715 input buffer. If the buffer is NULL, the registers are still
716 fetched, just the final transfer is skipped. */
720 /* start = max (reg_start, in_start) */
721 if (reg_start > in_start)
726 /* end = min (reg_end, in_end) */
727 if (reg_end < in_end)
732 /* Transfer just the bytes common to both IN_BUF and REG_BUF */
733 for (byte = start; byte < end; byte++)
735 in_buf[byte - in_start] = reg_buf[byte - reg_start];
740 /* Read register REGNUM into memory at MYADDR, which must be large
741 enough for REGISTER_RAW_BYTES (REGNUM). Target byte-order. If the
742 register is known to be the size of a CORE_ADDR or smaller,
743 read_register can be used instead. */
746 legacy_read_register_gen (int regnum, char *myaddr)
748 gdb_assert (regnum >= 0 && regnum < (NUM_REGS + NUM_PSEUDO_REGS));
749 if (! ptid_equal (registers_ptid, inferior_ptid))
751 registers_changed ();
752 registers_ptid = inferior_ptid;
755 if (!register_cached (regnum))
756 target_fetch_registers (regnum);
758 memcpy (myaddr, register_buffer (current_regcache, regnum),
759 REGISTER_RAW_SIZE (regnum));
763 regcache_raw_read (struct regcache *regcache, int regnum, void *buf)
765 gdb_assert (regcache != NULL && buf != NULL);
766 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
767 if (regcache->descr->legacy_p
768 && !regcache->readonly_p)
770 gdb_assert (regcache == current_regcache);
771 /* For moment, just use underlying legacy code. Ulgh!!! This
772 silently and very indirectly updates the regcache's regcache
773 via the global deprecated_register_valid[]. */
774 legacy_read_register_gen (regnum, buf);
777 /* Make certain that the register cache is up-to-date with respect
778 to the current thread. This switching shouldn't be necessary
779 only there is still only one target side register cache. Sigh!
780 On the bright side, at least there is a regcache object. */
781 if (!regcache->readonly_p)
783 gdb_assert (regcache == current_regcache);
784 if (! ptid_equal (registers_ptid, inferior_ptid))
786 registers_changed ();
787 registers_ptid = inferior_ptid;
789 if (!register_cached (regnum))
790 target_fetch_registers (regnum);
792 /* Copy the value directly into the register cache. */
793 memcpy (buf, register_buffer (regcache, regnum),
794 regcache->descr->sizeof_register[regnum]);
798 regcache_raw_read_signed (struct regcache *regcache, int regnum, LONGEST *val)
801 gdb_assert (regcache != NULL);
802 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
803 buf = alloca (regcache->descr->sizeof_register[regnum]);
804 regcache_raw_read (regcache, regnum, buf);
805 (*val) = extract_signed_integer (buf,
806 regcache->descr->sizeof_register[regnum]);
810 regcache_raw_read_unsigned (struct regcache *regcache, int regnum,
814 gdb_assert (regcache != NULL);
815 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
816 buf = alloca (regcache->descr->sizeof_register[regnum]);
817 regcache_raw_read (regcache, regnum, buf);
818 (*val) = extract_unsigned_integer (buf,
819 regcache->descr->sizeof_register[regnum]);
823 regcache_raw_write_signed (struct regcache *regcache, int regnum, LONGEST val)
826 gdb_assert (regcache != NULL);
827 gdb_assert (regnum >=0 && regnum < regcache->descr->nr_raw_registers);
828 buf = alloca (regcache->descr->sizeof_register[regnum]);
829 store_signed_integer (buf, regcache->descr->sizeof_register[regnum], val);
830 regcache_raw_write (regcache, regnum, buf);
834 regcache_raw_write_unsigned (struct regcache *regcache, int regnum,
838 gdb_assert (regcache != NULL);
839 gdb_assert (regnum >=0 && regnum < regcache->descr->nr_raw_registers);
840 buf = alloca (regcache->descr->sizeof_register[regnum]);
841 store_unsigned_integer (buf, regcache->descr->sizeof_register[regnum], val);
842 regcache_raw_write (regcache, regnum, buf);
846 deprecated_read_register_gen (int regnum, char *buf)
848 gdb_assert (current_regcache != NULL);
849 gdb_assert (current_regcache->descr->gdbarch == current_gdbarch);
850 if (current_regcache->descr->legacy_p)
852 legacy_read_register_gen (regnum, buf);
855 regcache_cooked_read (current_regcache, regnum, buf);
859 regcache_cooked_read (struct regcache *regcache, int regnum, void *buf)
861 gdb_assert (regnum >= 0);
862 gdb_assert (regnum < regcache->descr->nr_cooked_registers);
863 if (regnum < regcache->descr->nr_raw_registers)
864 regcache_raw_read (regcache, regnum, buf);
865 else if (regcache->readonly_p
866 && regnum < regcache->descr->nr_cooked_registers
867 && regcache->register_valid_p[regnum])
868 /* Read-only register cache, perhaphs the cooked value was cached? */
869 memcpy (buf, register_buffer (regcache, regnum),
870 regcache->descr->sizeof_register[regnum]);
872 gdbarch_pseudo_register_read (regcache->descr->gdbarch, regcache,
877 regcache_cooked_read_signed (struct regcache *regcache, int regnum,
881 gdb_assert (regcache != NULL);
882 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_cooked_registers);
883 buf = alloca (regcache->descr->sizeof_register[regnum]);
884 regcache_cooked_read (regcache, regnum, buf);
885 (*val) = extract_signed_integer (buf,
886 regcache->descr->sizeof_register[regnum]);
890 regcache_cooked_read_unsigned (struct regcache *regcache, int regnum,
894 gdb_assert (regcache != NULL);
895 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_cooked_registers);
896 buf = alloca (regcache->descr->sizeof_register[regnum]);
897 regcache_cooked_read (regcache, regnum, buf);
898 (*val) = extract_unsigned_integer (buf,
899 regcache->descr->sizeof_register[regnum]);
903 regcache_cooked_write_signed (struct regcache *regcache, int regnum,
907 gdb_assert (regcache != NULL);
908 gdb_assert (regnum >=0 && regnum < regcache->descr->nr_cooked_registers);
909 buf = alloca (regcache->descr->sizeof_register[regnum]);
910 store_signed_integer (buf, regcache->descr->sizeof_register[regnum], val);
911 regcache_cooked_write (regcache, regnum, buf);
915 regcache_cooked_write_unsigned (struct regcache *regcache, int regnum,
919 gdb_assert (regcache != NULL);
920 gdb_assert (regnum >=0 && regnum < regcache->descr->nr_cooked_registers);
921 buf = alloca (regcache->descr->sizeof_register[regnum]);
922 store_unsigned_integer (buf, regcache->descr->sizeof_register[regnum], val);
923 regcache_cooked_write (regcache, regnum, buf);
926 /* Write register REGNUM at MYADDR to the target. MYADDR points at
927 REGISTER_RAW_BYTES(REGNUM), which must be in target byte-order. */
930 legacy_write_register_gen (int regnum, const void *myaddr)
933 gdb_assert (regnum >= 0 && regnum < (NUM_REGS + NUM_PSEUDO_REGS));
935 /* On the sparc, writing %g0 is a no-op, so we don't even want to
936 change the registers array if something writes to this register. */
937 if (CANNOT_STORE_REGISTER (regnum))
940 if (! ptid_equal (registers_ptid, inferior_ptid))
942 registers_changed ();
943 registers_ptid = inferior_ptid;
946 size = REGISTER_RAW_SIZE (regnum);
948 if (real_register (regnum))
950 /* If we have a valid copy of the register, and new value == old
951 value, then don't bother doing the actual store. */
952 if (register_cached (regnum)
953 && (memcmp (register_buffer (current_regcache, regnum), myaddr, size)
957 target_prepare_to_store ();
960 memcpy (register_buffer (current_regcache, regnum), myaddr, size);
962 set_register_cached (regnum, 1);
963 target_store_registers (regnum);
967 regcache_raw_write (struct regcache *regcache, int regnum, const void *buf)
969 gdb_assert (regcache != NULL && buf != NULL);
970 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
971 gdb_assert (!regcache->readonly_p);
973 if (regcache->descr->legacy_p)
975 /* For moment, just use underlying legacy code. Ulgh!!! This
976 silently and very indirectly updates the regcache's buffers
977 via the globals deprecated_register_valid[] and registers[]. */
978 gdb_assert (regcache == current_regcache);
979 legacy_write_register_gen (regnum, buf);
983 /* On the sparc, writing %g0 is a no-op, so we don't even want to
984 change the registers array if something writes to this register. */
985 if (CANNOT_STORE_REGISTER (regnum))
988 /* Make certain that the correct cache is selected. */
989 gdb_assert (regcache == current_regcache);
990 if (! ptid_equal (registers_ptid, inferior_ptid))
992 registers_changed ();
993 registers_ptid = inferior_ptid;
996 /* If we have a valid copy of the register, and new value == old
997 value, then don't bother doing the actual store. */
998 if (regcache_valid_p (regcache, regnum)
999 && (memcmp (register_buffer (regcache, regnum), buf,
1000 regcache->descr->sizeof_register[regnum]) == 0))
1003 target_prepare_to_store ();
1004 memcpy (register_buffer (regcache, regnum), buf,
1005 regcache->descr->sizeof_register[regnum]);
1006 regcache->register_valid_p[regnum] = 1;
1007 target_store_registers (regnum);
1011 deprecated_write_register_gen (int regnum, char *buf)
1013 gdb_assert (current_regcache != NULL);
1014 gdb_assert (current_regcache->descr->gdbarch == current_gdbarch);
1015 if (current_regcache->descr->legacy_p)
1017 legacy_write_register_gen (regnum, buf);
1020 regcache_cooked_write (current_regcache, regnum, buf);
1024 regcache_cooked_write (struct regcache *regcache, int regnum, const void *buf)
1026 gdb_assert (regnum >= 0);
1027 gdb_assert (regnum < regcache->descr->nr_cooked_registers);
1028 if (regnum < regcache->descr->nr_raw_registers)
1029 regcache_raw_write (regcache, regnum, buf);
1031 gdbarch_pseudo_register_write (regcache->descr->gdbarch, regcache,
1035 /* Copy INLEN bytes of consecutive data from memory at MYADDR
1036 into registers starting with the MYREGSTART'th byte of register data. */
1039 deprecated_write_register_bytes (int myregstart, char *myaddr, int inlen)
1041 int myregend = myregstart + inlen;
1044 target_prepare_to_store ();
1046 /* Scan through the registers updating any that are covered by the
1047 range myregstart<=>myregend using write_register_gen, which does
1048 nice things like handling threads, and avoiding updates when the
1049 new and old contents are the same. */
1051 for (regnum = 0; regnum < NUM_REGS + NUM_PSEUDO_REGS; regnum++)
1053 int regstart, regend;
1055 regstart = REGISTER_BYTE (regnum);
1056 regend = regstart + REGISTER_RAW_SIZE (regnum);
1058 /* Is this register completely outside the range the user is writing? */
1059 if (myregend <= regstart || regend <= myregstart)
1062 /* Is this register completely within the range the user is writing? */
1063 else if (myregstart <= regstart && regend <= myregend)
1064 deprecated_write_register_gen (regnum, myaddr + (regstart - myregstart));
1066 /* The register partially overlaps the range being written. */
1069 char *regbuf = (char*) alloca (MAX_REGISTER_RAW_SIZE);
1070 /* What's the overlap between this register's bytes and
1071 those the caller wants to write? */
1072 int overlapstart = max (regstart, myregstart);
1073 int overlapend = min (regend, myregend);
1075 /* We may be doing a partial update of an invalid register.
1076 Update it from the target before scribbling on it. */
1077 deprecated_read_register_gen (regnum, regbuf);
1079 memcpy (&deprecated_registers[overlapstart],
1080 myaddr + (overlapstart - myregstart),
1081 overlapend - overlapstart);
1083 target_store_registers (regnum);
1088 /* Perform a partial register transfer using a read, modify, write
1091 typedef void (regcache_read_ftype) (struct regcache *regcache, int regnum,
1093 typedef void (regcache_write_ftype) (struct regcache *regcache, int regnum,
1097 regcache_xfer_part (struct regcache *regcache, int regnum,
1098 int offset, int len, void *in, const void *out,
1099 regcache_read_ftype *read, regcache_write_ftype *write)
1101 struct regcache_descr *descr = regcache->descr;
1102 bfd_byte *reg = alloca (descr->max_register_size);
1103 gdb_assert (offset >= 0 && offset <= descr->sizeof_register[regnum]);
1104 gdb_assert (len >= 0 && offset + len <= descr->sizeof_register[regnum]);
1105 /* Something to do? */
1106 if (offset + len == 0)
1108 /* Read (when needed) ... */
1111 || offset + len < descr->sizeof_register[regnum])
1113 gdb_assert (read != NULL);
1114 read (regcache, regnum, reg);
1116 /* ... modify ... */
1118 memcpy (in, reg + offset, len);
1120 memcpy (reg + offset, out, len);
1121 /* ... write (when needed). */
1124 gdb_assert (write != NULL);
1125 write (regcache, regnum, reg);
1130 regcache_raw_read_part (struct regcache *regcache, int regnum,
1131 int offset, int len, void *buf)
1133 struct regcache_descr *descr = regcache->descr;
1134 gdb_assert (regnum >= 0 && regnum < descr->nr_raw_registers);
1135 regcache_xfer_part (regcache, regnum, offset, len, buf, NULL,
1136 regcache_raw_read, regcache_raw_write);
1140 regcache_raw_write_part (struct regcache *regcache, int regnum,
1141 int offset, int len, const void *buf)
1143 struct regcache_descr *descr = regcache->descr;
1144 gdb_assert (regnum >= 0 && regnum < descr->nr_raw_registers);
1145 regcache_xfer_part (regcache, regnum, offset, len, NULL, buf,
1146 regcache_raw_read, regcache_raw_write);
1150 regcache_cooked_read_part (struct regcache *regcache, int regnum,
1151 int offset, int len, void *buf)
1153 struct regcache_descr *descr = regcache->descr;
1154 gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
1155 regcache_xfer_part (regcache, regnum, offset, len, buf, NULL,
1156 regcache_cooked_read, regcache_cooked_write);
1160 regcache_cooked_write_part (struct regcache *regcache, int regnum,
1161 int offset, int len, const void *buf)
1163 struct regcache_descr *descr = regcache->descr;
1164 gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
1165 regcache_xfer_part (regcache, regnum, offset, len, NULL, buf,
1166 regcache_cooked_read, regcache_cooked_write);
1169 /* Hack to keep code that view the register buffer as raw bytes
1173 register_offset_hack (struct gdbarch *gdbarch, int regnum)
1175 struct regcache_descr *descr = regcache_descr (gdbarch);
1176 gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
1177 return descr->register_offset[regnum];
1180 /* Return the contents of register REGNUM as an unsigned integer. */
1183 read_register (int regnum)
1185 char *buf = alloca (REGISTER_RAW_SIZE (regnum));
1186 deprecated_read_register_gen (regnum, buf);
1187 return (extract_unsigned_integer (buf, REGISTER_RAW_SIZE (regnum)));
1191 read_register_pid (int regnum, ptid_t ptid)
1197 if (ptid_equal (ptid, inferior_ptid))
1198 return read_register (regnum);
1200 save_ptid = inferior_ptid;
1202 inferior_ptid = ptid;
1204 retval = read_register (regnum);
1206 inferior_ptid = save_ptid;
1211 /* Store VALUE into the raw contents of register number REGNUM. */
1214 write_register (int regnum, LONGEST val)
1218 size = REGISTER_RAW_SIZE (regnum);
1219 buf = alloca (size);
1220 store_signed_integer (buf, size, (LONGEST) val);
1221 deprecated_write_register_gen (regnum, buf);
1225 write_register_pid (int regnum, CORE_ADDR val, ptid_t ptid)
1229 if (ptid_equal (ptid, inferior_ptid))
1231 write_register (regnum, val);
1235 save_ptid = inferior_ptid;
1237 inferior_ptid = ptid;
1239 write_register (regnum, val);
1241 inferior_ptid = save_ptid;
1244 /* SUPPLY_REGISTER()
1246 Record that register REGNUM contains VAL. This is used when the
1247 value is obtained from the inferior or core dump, so there is no
1248 need to store the value there.
1250 If VAL is a NULL pointer, then it's probably an unsupported register.
1251 We just set its value to all zeros. We might want to record this
1252 fact, and report it to the users of read_register and friends. */
1255 supply_register (int regnum, const void *val)
1258 if (! ptid_equal (registers_ptid, inferior_ptid))
1260 registers_changed ();
1261 registers_ptid = inferior_ptid;
1265 set_register_cached (regnum, 1);
1267 memcpy (register_buffer (current_regcache, regnum), val,
1268 REGISTER_RAW_SIZE (regnum));
1270 memset (register_buffer (current_regcache, regnum), '\000',
1271 REGISTER_RAW_SIZE (regnum));
1273 /* On some architectures, e.g. HPPA, there are a few stray bits in
1274 some registers, that the rest of the code would like to ignore. */
1276 /* NOTE: cagney/2001-03-16: The macro CLEAN_UP_REGISTER_VALUE is
1277 going to be deprecated. Instead architectures will leave the raw
1278 register value as is and instead clean things up as they pass
1279 through the method gdbarch_pseudo_register_read() clean up the
1282 #ifdef DEPRECATED_CLEAN_UP_REGISTER_VALUE
1283 DEPRECATED_CLEAN_UP_REGISTER_VALUE \
1284 (regnum, register_buffer (current_regcache, regnum));
1289 regcache_collect (int regnum, void *buf)
1291 memcpy (buf, register_buffer (current_regcache, regnum),
1292 REGISTER_RAW_SIZE (regnum));
1296 /* read_pc, write_pc, read_sp, deprecated_read_fp, etc. Special
1297 handling for registers PC, SP, and FP. */
1299 /* NOTE: cagney/2001-02-18: The functions generic_target_read_pc(),
1300 read_pc_pid(), read_pc(), generic_target_write_pc(),
1301 write_pc_pid(), write_pc(), generic_target_read_sp(), read_sp(),
1302 generic_target_write_sp(), and deprecated_read_fp(), will
1303 eventually be moved out of the reg-cache into either frame.[hc] or
1304 to the multi-arch framework. The are not part of the raw register
1307 /* This routine is getting awfully cluttered with #if's. It's probably
1308 time to turn this into READ_PC and define it in the tm.h file.
1311 1999-06-08: The following were re-written so that it assumes the
1312 existence of a TARGET_READ_PC et.al. macro. A default generic
1313 version of that macro is made available where needed.
1315 Since the ``TARGET_READ_PC'' et.al. macro is going to be controlled
1316 by the multi-arch framework, it will eventually be possible to
1317 eliminate the intermediate read_pc_pid(). The client would call
1318 TARGET_READ_PC directly. (cagney). */
1321 generic_target_read_pc (ptid_t ptid)
1326 CORE_ADDR pc_val = ADDR_BITS_REMOVE ((CORE_ADDR) read_register_pid (PC_REGNUM, ptid));
1330 internal_error (__FILE__, __LINE__,
1331 "generic_target_read_pc");
1336 read_pc_pid (ptid_t ptid)
1338 ptid_t saved_inferior_ptid;
1341 /* In case ptid != inferior_ptid. */
1342 saved_inferior_ptid = inferior_ptid;
1343 inferior_ptid = ptid;
1345 pc_val = TARGET_READ_PC (ptid);
1347 inferior_ptid = saved_inferior_ptid;
1354 return read_pc_pid (inferior_ptid);
1358 generic_target_write_pc (CORE_ADDR pc, ptid_t ptid)
1362 write_register_pid (PC_REGNUM, pc, ptid);
1363 if (NPC_REGNUM >= 0)
1364 write_register_pid (NPC_REGNUM, pc + 4, ptid);
1366 internal_error (__FILE__, __LINE__,
1367 "generic_target_write_pc");
1372 write_pc_pid (CORE_ADDR pc, ptid_t ptid)
1374 ptid_t saved_inferior_ptid;
1376 /* In case ptid != inferior_ptid. */
1377 saved_inferior_ptid = inferior_ptid;
1378 inferior_ptid = ptid;
1380 TARGET_WRITE_PC (pc, ptid);
1382 inferior_ptid = saved_inferior_ptid;
1386 write_pc (CORE_ADDR pc)
1388 write_pc_pid (pc, inferior_ptid);
1391 /* Cope with strage ways of getting to the stack and frame pointers */
1394 generic_target_read_sp (void)
1398 return read_register (SP_REGNUM);
1400 internal_error (__FILE__, __LINE__,
1401 "generic_target_read_sp");
1407 return TARGET_READ_SP ();
1411 generic_target_write_sp (CORE_ADDR val)
1416 write_register (SP_REGNUM, val);
1420 internal_error (__FILE__, __LINE__,
1421 "generic_target_write_sp");
1425 deprecated_read_fp (void)
1427 if (DEPRECATED_TARGET_READ_FP_P ())
1428 return DEPRECATED_TARGET_READ_FP ();
1429 else if (DEPRECATED_FP_REGNUM >= 0)
1430 return read_register (DEPRECATED_FP_REGNUM);
1432 internal_error (__FILE__, __LINE__, "deprecated_read_fp");
1437 reg_flush_command (char *command, int from_tty)
1439 /* Force-flush the register cache. */
1440 registers_changed ();
1442 printf_filtered ("Register cache flushed.\n");
1446 build_regcache (void)
1448 current_regcache = regcache_xmalloc (current_gdbarch);
1449 current_regcache->readonly_p = 0;
1450 deprecated_registers = deprecated_grub_regcache_for_registers (current_regcache);
1451 deprecated_register_valid = deprecated_grub_regcache_for_register_valid (current_regcache);
1455 dump_endian_bytes (struct ui_file *file, enum bfd_endian endian,
1456 const unsigned char *buf, long len)
1461 case BFD_ENDIAN_BIG:
1462 for (i = 0; i < len; i++)
1463 fprintf_unfiltered (file, "%02x", buf[i]);
1465 case BFD_ENDIAN_LITTLE:
1466 for (i = len - 1; i >= 0; i--)
1467 fprintf_unfiltered (file, "%02x", buf[i]);
1470 internal_error (__FILE__, __LINE__, "Bad switch");
1474 enum regcache_dump_what
1476 regcache_dump_none, regcache_dump_raw, regcache_dump_cooked, regcache_dump_groups
1480 regcache_dump (struct regcache *regcache, struct ui_file *file,
1481 enum regcache_dump_what what_to_dump)
1483 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
1484 struct gdbarch *gdbarch = regcache->descr->gdbarch;
1485 struct reggroup *const *groups = reggroups (gdbarch);
1487 int footnote_nr = 0;
1488 int footnote_register_size = 0;
1489 int footnote_register_offset = 0;
1490 int footnote_register_type_name_null = 0;
1491 long register_offset = 0;
1492 unsigned char *buf = alloca (regcache->descr->max_register_size);
1495 fprintf_unfiltered (file, "legacy_p %d\n", regcache->descr->legacy_p);
1496 fprintf_unfiltered (file, "nr_raw_registers %d\n",
1497 regcache->descr->nr_raw_registers);
1498 fprintf_unfiltered (file, "nr_cooked_registers %d\n",
1499 regcache->descr->nr_cooked_registers);
1500 fprintf_unfiltered (file, "sizeof_raw_registers %ld\n",
1501 regcache->descr->sizeof_raw_registers);
1502 fprintf_unfiltered (file, "sizeof_raw_register_valid_p %ld\n",
1503 regcache->descr->sizeof_raw_register_valid_p);
1504 fprintf_unfiltered (file, "max_register_size %ld\n",
1505 regcache->descr->max_register_size);
1506 fprintf_unfiltered (file, "NUM_REGS %d\n", NUM_REGS);
1507 fprintf_unfiltered (file, "NUM_PSEUDO_REGS %d\n", NUM_PSEUDO_REGS);
1510 gdb_assert (regcache->descr->nr_cooked_registers
1511 == (NUM_REGS + NUM_PSEUDO_REGS));
1513 for (regnum = -1; regnum < regcache->descr->nr_cooked_registers; regnum++)
1517 fprintf_unfiltered (file, " %-10s", "Name");
1520 const char *p = REGISTER_NAME (regnum);
1523 else if (p[0] == '\0')
1525 fprintf_unfiltered (file, " %-10s", p);
1530 fprintf_unfiltered (file, " %4s", "Nr");
1532 fprintf_unfiltered (file, " %4d", regnum);
1534 /* Relative number. */
1536 fprintf_unfiltered (file, " %4s", "Rel");
1537 else if (regnum < NUM_REGS)
1538 fprintf_unfiltered (file, " %4d", regnum);
1540 fprintf_unfiltered (file, " %4d", (regnum - NUM_REGS));
1544 fprintf_unfiltered (file, " %6s ", "Offset");
1547 fprintf_unfiltered (file, " %6ld",
1548 regcache->descr->register_offset[regnum]);
1549 if (register_offset != regcache->descr->register_offset[regnum]
1550 || register_offset != REGISTER_BYTE (regnum)
1552 && (regcache->descr->register_offset[regnum]
1553 != (regcache->descr->register_offset[regnum - 1]
1554 + regcache->descr->sizeof_register[regnum - 1])))
1557 if (!footnote_register_offset)
1558 footnote_register_offset = ++footnote_nr;
1559 fprintf_unfiltered (file, "*%d", footnote_register_offset);
1562 fprintf_unfiltered (file, " ");
1563 register_offset = (regcache->descr->register_offset[regnum]
1564 + regcache->descr->sizeof_register[regnum]);
1569 fprintf_unfiltered (file, " %5s ", "Size");
1572 fprintf_unfiltered (file, " %5ld",
1573 regcache->descr->sizeof_register[regnum]);
1574 if ((regcache->descr->sizeof_register[regnum]
1575 != REGISTER_RAW_SIZE (regnum))
1576 || (regcache->descr->sizeof_register[regnum]
1577 != REGISTER_VIRTUAL_SIZE (regnum))
1578 || (regcache->descr->sizeof_register[regnum]
1579 != TYPE_LENGTH (register_type (regcache->descr->gdbarch,
1583 if (!footnote_register_size)
1584 footnote_register_size = ++footnote_nr;
1585 fprintf_unfiltered (file, "*%d", footnote_register_size);
1588 fprintf_unfiltered (file, " ");
1598 static const char blt[] = "builtin_type";
1599 t = TYPE_NAME (register_type (regcache->descr->gdbarch, regnum));
1603 if (!footnote_register_type_name_null)
1604 footnote_register_type_name_null = ++footnote_nr;
1605 xasprintf (&n, "*%d", footnote_register_type_name_null);
1606 make_cleanup (xfree, n);
1609 /* Chop a leading builtin_type. */
1610 if (strncmp (t, blt, strlen (blt)) == 0)
1613 fprintf_unfiltered (file, " %-15s", t);
1616 /* Leading space always present. */
1617 fprintf_unfiltered (file, " ");
1620 if (what_to_dump == regcache_dump_raw)
1623 fprintf_unfiltered (file, "Raw value");
1624 else if (regnum >= regcache->descr->nr_raw_registers)
1625 fprintf_unfiltered (file, "<cooked>");
1626 else if (!regcache_valid_p (regcache, regnum))
1627 fprintf_unfiltered (file, "<invalid>");
1630 regcache_raw_read (regcache, regnum, buf);
1631 fprintf_unfiltered (file, "0x");
1632 dump_endian_bytes (file, TARGET_BYTE_ORDER, buf,
1633 REGISTER_RAW_SIZE (regnum));
1637 /* Value, cooked. */
1638 if (what_to_dump == regcache_dump_cooked)
1641 fprintf_unfiltered (file, "Cooked value");
1644 regcache_cooked_read (regcache, regnum, buf);
1645 fprintf_unfiltered (file, "0x");
1646 dump_endian_bytes (file, TARGET_BYTE_ORDER, buf,
1647 REGISTER_VIRTUAL_SIZE (regnum));
1651 /* Group members. */
1652 if (what_to_dump == regcache_dump_groups)
1655 fprintf_unfiltered (file, "Groups");
1659 const char *sep = "";
1660 for (i = 0; groups[i] != NULL; i++)
1662 if (gdbarch_register_reggroup_p (gdbarch, regnum, groups[i]))
1664 fprintf_unfiltered (file, "%s%s", sep, reggroup_name (groups[i]));
1671 fprintf_unfiltered (file, "\n");
1674 if (footnote_register_size)
1675 fprintf_unfiltered (file, "*%d: Inconsistent register sizes.\n",
1676 footnote_register_size);
1677 if (footnote_register_offset)
1678 fprintf_unfiltered (file, "*%d: Inconsistent register offsets.\n",
1679 footnote_register_offset);
1680 if (footnote_register_type_name_null)
1681 fprintf_unfiltered (file,
1682 "*%d: Register type's name NULL.\n",
1683 footnote_register_type_name_null);
1684 do_cleanups (cleanups);
1688 regcache_print (char *args, enum regcache_dump_what what_to_dump)
1691 regcache_dump (current_regcache, gdb_stdout, what_to_dump);
1694 struct ui_file *file = gdb_fopen (args, "w");
1696 perror_with_name ("maintenance print architecture");
1697 regcache_dump (current_regcache, file, what_to_dump);
1698 ui_file_delete (file);
1703 maintenance_print_registers (char *args, int from_tty)
1705 regcache_print (args, regcache_dump_none);
1709 maintenance_print_raw_registers (char *args, int from_tty)
1711 regcache_print (args, regcache_dump_raw);
1715 maintenance_print_cooked_registers (char *args, int from_tty)
1717 regcache_print (args, regcache_dump_cooked);
1721 maintenance_print_register_groups (char *args, int from_tty)
1723 regcache_print (args, regcache_dump_groups);
1727 _initialize_regcache (void)
1729 regcache_descr_handle = register_gdbarch_data (init_regcache_descr,
1730 xfree_regcache_descr);
1731 REGISTER_GDBARCH_SWAP (current_regcache);
1732 register_gdbarch_swap (&deprecated_registers, sizeof (deprecated_registers), NULL);
1733 register_gdbarch_swap (&deprecated_register_valid, sizeof (deprecated_register_valid), NULL);
1734 register_gdbarch_swap (NULL, 0, build_regcache);
1736 add_com ("flushregs", class_maintenance, reg_flush_command,
1737 "Force gdb to flush its register cache (maintainer command)");
1739 /* Initialize the thread/process associated with the current set of
1740 registers. For now, -1 is special, and means `no current process'. */
1741 registers_ptid = pid_to_ptid (-1);
1743 add_cmd ("registers", class_maintenance,
1744 maintenance_print_registers,
1745 "Print the internal register configuration.\
1746 Takes an optional file parameter.",
1747 &maintenanceprintlist);
1748 add_cmd ("raw-registers", class_maintenance,
1749 maintenance_print_raw_registers,
1750 "Print the internal register configuration including raw values.\
1751 Takes an optional file parameter.",
1752 &maintenanceprintlist);
1753 add_cmd ("cooked-registers", class_maintenance,
1754 maintenance_print_cooked_registers,
1755 "Print the internal register configuration including cooked values.\
1756 Takes an optional file parameter.",
1757 &maintenanceprintlist);
1758 add_cmd ("register-groups", class_maintenance,
1759 maintenance_print_register_groups,
1760 "Print the internal register configuration including each register's group.\
1761 Takes an optional file parameter.",
1762 &maintenanceprintlist);