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 register_size (struct gdbarch *gdbarch, int regnum)
302 struct regcache_descr *descr = regcache_descr (gdbarch);
304 gdb_assert (regnum >= 0 && regnum < (NUM_REGS + NUM_PSEUDO_REGS));
305 size = descr->sizeof_register[regnum];
306 gdb_assert (size == REGISTER_RAW_SIZE (regnum)); /* OK */
307 gdb_assert (size == REGISTER_RAW_SIZE (regnum)); /* OK */
311 /* The register cache for storing raw register values. */
315 struct regcache_descr *descr;
316 /* The register buffers. A read-only register cache can hold the
317 full [0 .. NUM_REGS + NUM_PSEUDO_REGS) while a read/write
318 register cache can only hold [0 .. NUM_REGS). */
320 char *register_valid_p;
321 /* Is this a read-only cache? A read-only cache is used for saving
322 the target's register state (e.g, across an inferior function
323 call or just before forcing a function return). A read-only
324 cache can only be updated via the methods regcache_dup() and
325 regcache_cpy(). The actual contents are determined by the
326 reggroup_save and reggroup_restore methods. */
331 regcache_xmalloc (struct gdbarch *gdbarch)
333 struct regcache_descr *descr;
334 struct regcache *regcache;
335 gdb_assert (gdbarch != NULL);
336 descr = regcache_descr (gdbarch);
337 regcache = XMALLOC (struct regcache);
338 regcache->descr = descr;
340 = XCALLOC (descr->sizeof_raw_registers, char);
341 regcache->register_valid_p
342 = XCALLOC (descr->sizeof_raw_register_valid_p, char);
343 regcache->readonly_p = 1;
348 regcache_xfree (struct regcache *regcache)
350 if (regcache == NULL)
352 xfree (regcache->registers);
353 xfree (regcache->register_valid_p);
358 do_regcache_xfree (void *data)
360 regcache_xfree (data);
364 make_cleanup_regcache_xfree (struct regcache *regcache)
366 return make_cleanup (do_regcache_xfree, regcache);
369 /* Return a pointer to register REGNUM's buffer cache. */
372 register_buffer (struct regcache *regcache, int regnum)
374 return regcache->registers + regcache->descr->register_offset[regnum];
378 regcache_save (struct regcache *dst, regcache_cooked_read_ftype *cooked_read,
381 struct gdbarch *gdbarch = dst->descr->gdbarch;
382 void *buf = alloca (max_register_size (gdbarch));
384 /* The DST should be `read-only', if it wasn't then the save would
385 end up trying to write the register values back out to the
387 gdb_assert (dst->readonly_p);
388 /* Clear the dest. */
389 memset (dst->registers, 0, dst->descr->sizeof_cooked_registers);
390 memset (dst->register_valid_p, 0, dst->descr->sizeof_cooked_register_valid_p);
391 /* Copy over any registers (identified by their membership in the
392 save_reggroup) and mark them as valid. The full [0 .. NUM_REGS +
393 NUM_PSEUDO_REGS) range is checked since some architectures need
394 to save/restore `cooked' registers that live in memory. */
395 for (regnum = 0; regnum < dst->descr->nr_cooked_registers; regnum++)
397 if (gdbarch_register_reggroup_p (gdbarch, regnum, save_reggroup))
399 int valid = cooked_read (src, regnum, buf);
402 memcpy (register_buffer (dst, regnum), buf,
403 register_size (gdbarch, regnum));
404 dst->register_valid_p[regnum] = 1;
411 regcache_restore (struct regcache *dst,
412 regcache_cooked_read_ftype *cooked_read,
415 struct gdbarch *gdbarch = dst->descr->gdbarch;
416 void *buf = alloca (max_register_size (gdbarch));
418 /* The dst had better not be read-only. If it is, the `restore'
419 doesn't make much sense. */
420 gdb_assert (!dst->readonly_p);
421 /* Copy over any registers, being careful to only restore those that
422 were both saved and need to be restored. The full [0 .. NUM_REGS
423 + NUM_PSEUDO_REGS) range is checked since some architectures need
424 to save/restore `cooked' registers that live in memory. */
425 for (regnum = 0; regnum < dst->descr->nr_cooked_registers; regnum++)
427 if (gdbarch_register_reggroup_p (gdbarch, regnum, restore_reggroup))
429 int valid = cooked_read (src, regnum, buf);
431 regcache_cooked_write (dst, regnum, buf);
437 do_cooked_read (void *src, int regnum, void *buf)
439 struct regcache *regcache = src;
440 if (!regcache_valid_p (regcache, regnum)
441 && regcache->readonly_p)
442 /* Don't even think about fetching a register from a read-only
443 cache when the register isn't yet valid. There isn't a target
444 from which the register value can be fetched. */
446 regcache_cooked_read (regcache, regnum, buf);
452 regcache_cpy (struct regcache *dst, struct regcache *src)
456 gdb_assert (src != NULL && dst != NULL);
457 gdb_assert (src->descr->gdbarch == dst->descr->gdbarch);
458 gdb_assert (src != dst);
459 gdb_assert (src->readonly_p || dst->readonly_p);
460 if (!src->readonly_p)
461 regcache_save (dst, do_cooked_read, src);
462 else if (!dst->readonly_p)
463 regcache_restore (dst, do_cooked_read, src);
465 regcache_cpy_no_passthrough (dst, src);
469 regcache_cpy_no_passthrough (struct regcache *dst, struct regcache *src)
472 gdb_assert (src != NULL && dst != NULL);
473 gdb_assert (src->descr->gdbarch == dst->descr->gdbarch);
474 /* NOTE: cagney/2002-05-17: Don't let the caller do a no-passthrough
475 move of data into the current_regcache(). Doing this would be
476 silly - it would mean that valid_p would be completly invalid. */
477 gdb_assert (dst != current_regcache);
478 memcpy (dst->registers, src->registers, dst->descr->sizeof_raw_registers);
479 memcpy (dst->register_valid_p, src->register_valid_p,
480 dst->descr->sizeof_raw_register_valid_p);
484 regcache_dup (struct regcache *src)
486 struct regcache *newbuf;
487 gdb_assert (current_regcache != NULL);
488 newbuf = regcache_xmalloc (src->descr->gdbarch);
489 regcache_cpy (newbuf, src);
494 regcache_dup_no_passthrough (struct regcache *src)
496 struct regcache *newbuf;
497 gdb_assert (current_regcache != NULL);
498 newbuf = regcache_xmalloc (src->descr->gdbarch);
499 regcache_cpy_no_passthrough (newbuf, src);
504 regcache_valid_p (struct regcache *regcache, int regnum)
506 gdb_assert (regcache != NULL);
507 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
508 return regcache->register_valid_p[regnum];
512 deprecated_grub_regcache_for_registers (struct regcache *regcache)
514 return regcache->registers;
518 deprecated_grub_regcache_for_register_valid (struct regcache *regcache)
520 return regcache->register_valid_p;
523 /* Global structure containing the current regcache. */
524 /* FIXME: cagney/2002-05-11: The two global arrays registers[] and
525 deprecated_register_valid[] currently point into this structure. */
526 struct regcache *current_regcache;
528 /* NOTE: this is a write-through cache. There is no "dirty" bit for
529 recording if the register values have been changed (eg. by the
530 user). Therefore all registers must be written back to the
531 target when appropriate. */
533 /* REGISTERS contains the cached register values (in target byte order). */
535 char *deprecated_registers;
537 /* DEPRECATED_REGISTER_VALID is 0 if the register needs to be fetched,
538 1 if it has been fetched, and
539 -1 if the register value was not available.
541 "Not available" indicates that the target is not not able to supply
542 the register at this state. The register may become available at a
543 later time (after the next resume). This often occures when GDB is
544 manipulating a target that contains only a snapshot of the entire
545 system being debugged - some of the registers in such a system may
546 not have been saved. */
548 signed char *deprecated_register_valid;
550 /* The thread/process associated with the current set of registers. */
552 static ptid_t registers_ptid;
560 Returns 0 if the value is not in the cache (needs fetch).
561 >0 if the value is in the cache.
562 <0 if the value is permanently unavailable (don't ask again). */
565 register_cached (int regnum)
567 return deprecated_register_valid[regnum];
570 /* Record that REGNUM's value is cached if STATE is >0, uncached but
571 fetchable if STATE is 0, and uncached and unfetchable if STATE is <0. */
574 set_register_cached (int regnum, int state)
576 gdb_assert (regnum >= 0);
577 gdb_assert (regnum < current_regcache->descr->nr_raw_registers);
578 current_regcache->register_valid_p[regnum] = state;
581 /* Return whether register REGNUM is a real register. */
584 real_register (int regnum)
586 return regnum >= 0 && regnum < NUM_REGS;
589 /* Low level examining and depositing of registers.
591 The caller is responsible for making sure that the inferior is
592 stopped before calling the fetching routines, or it will get
593 garbage. (a change from GDB version 3, in which the caller got the
594 value from the last stop). */
596 /* REGISTERS_CHANGED ()
598 Indicate that registers may have changed, so invalidate the cache. */
601 registers_changed (void)
605 registers_ptid = pid_to_ptid (-1);
607 /* Force cleanup of any alloca areas if using C alloca instead of
608 a builtin alloca. This particular call is used to clean up
609 areas allocated by low level target code which may build up
610 during lengthy interactions between gdb and the target before
611 gdb gives control to the user (ie watchpoints). */
614 for (i = 0; i < current_regcache->descr->nr_raw_registers; i++)
615 set_register_cached (i, 0);
617 if (registers_changed_hook)
618 registers_changed_hook ();
621 /* DEPRECATED_REGISTERS_FETCHED ()
623 Indicate that all registers have been fetched, so mark them all valid. */
625 /* NOTE: cagney/2001-12-04: This function does not set valid on the
626 pseudo-register range since pseudo registers are always supplied
627 using supply_register(). */
628 /* FIXME: cagney/2001-12-04: This function is DEPRECATED. The target
629 code was blatting the registers[] array and then calling this.
630 Since targets should only be using supply_register() the need for
631 this function/hack is eliminated. */
634 deprecated_registers_fetched (void)
638 for (i = 0; i < NUM_REGS; i++)
639 set_register_cached (i, 1);
640 /* Do not assume that the pseudo-regs have also been fetched.
641 Fetching all real regs NEVER accounts for pseudo-regs. */
644 /* deprecated_read_register_bytes and deprecated_write_register_bytes
645 are generally a *BAD* idea. They are inefficient because they need
646 to check for partial updates, which can only be done by scanning
647 through all of the registers and seeing if the bytes that are being
648 read/written fall inside of an invalid register. [The main reason
649 this is necessary is that register sizes can vary, so a simple
650 index won't suffice.] It is far better to call read_register_gen
651 and write_register_gen if you want to get at the raw register
652 contents, as it only takes a regnum as an argument, and therefore
653 can't do a partial register update.
655 Prior to the recent fixes to check for partial updates, both read
656 and deprecated_write_register_bytes always checked to see if any
657 registers were stale, and then called target_fetch_registers (-1)
658 to update the whole set. This caused really slowed things down for
661 /* Copy INLEN bytes of consecutive data from registers
662 starting with the INREGBYTE'th byte of register data
663 into memory at MYADDR. */
666 deprecated_read_register_bytes (int in_start, char *in_buf, int in_len)
668 int in_end = in_start + in_len;
670 char reg_buf[MAX_REGISTER_SIZE];
672 /* See if we are trying to read bytes from out-of-date registers. If so,
673 update just those registers. */
675 for (regnum = 0; regnum < NUM_REGS + NUM_PSEUDO_REGS; regnum++)
684 reg_start = REGISTER_BYTE (regnum);
685 reg_len = REGISTER_RAW_SIZE (regnum);
686 reg_end = reg_start + reg_len;
688 if (reg_end <= in_start || in_end <= reg_start)
689 /* The range the user wants to read doesn't overlap with regnum. */
692 if (REGISTER_NAME (regnum) != NULL && *REGISTER_NAME (regnum) != '\0')
693 /* Force the cache to fetch the entire register. */
694 deprecated_read_register_gen (regnum, reg_buf);
696 /* Legacy note: even though this register is ``invalid'' we
697 still need to return something. It would appear that some
698 code relies on apparent gaps in the register array also
700 /* FIXME: cagney/2001-08-18: This is just silly. It defeats
701 the entire register read/write flow of control. Must
702 resist temptation to return 0xdeadbeef. */
703 memcpy (reg_buf, &deprecated_registers[reg_start], reg_len);
705 /* Legacy note: This function, for some reason, allows a NULL
706 input buffer. If the buffer is NULL, the registers are still
707 fetched, just the final transfer is skipped. */
711 /* start = max (reg_start, in_start) */
712 if (reg_start > in_start)
717 /* end = min (reg_end, in_end) */
718 if (reg_end < in_end)
723 /* Transfer just the bytes common to both IN_BUF and REG_BUF */
724 for (byte = start; byte < end; byte++)
726 in_buf[byte - in_start] = reg_buf[byte - reg_start];
731 /* Read register REGNUM into memory at MYADDR, which must be large
732 enough for REGISTER_RAW_BYTES (REGNUM). Target byte-order. If the
733 register is known to be the size of a CORE_ADDR or smaller,
734 read_register can be used instead. */
737 legacy_read_register_gen (int regnum, char *myaddr)
739 gdb_assert (regnum >= 0 && regnum < (NUM_REGS + NUM_PSEUDO_REGS));
740 if (! ptid_equal (registers_ptid, inferior_ptid))
742 registers_changed ();
743 registers_ptid = inferior_ptid;
746 if (!register_cached (regnum))
747 target_fetch_registers (regnum);
749 memcpy (myaddr, register_buffer (current_regcache, regnum),
750 REGISTER_RAW_SIZE (regnum));
754 regcache_raw_read (struct regcache *regcache, int regnum, void *buf)
756 gdb_assert (regcache != NULL && buf != NULL);
757 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
758 if (regcache->descr->legacy_p
759 && !regcache->readonly_p)
761 gdb_assert (regcache == current_regcache);
762 /* For moment, just use underlying legacy code. Ulgh!!! This
763 silently and very indirectly updates the regcache's regcache
764 via the global deprecated_register_valid[]. */
765 legacy_read_register_gen (regnum, buf);
768 /* Make certain that the register cache is up-to-date with respect
769 to the current thread. This switching shouldn't be necessary
770 only there is still only one target side register cache. Sigh!
771 On the bright side, at least there is a regcache object. */
772 if (!regcache->readonly_p)
774 gdb_assert (regcache == current_regcache);
775 if (! ptid_equal (registers_ptid, inferior_ptid))
777 registers_changed ();
778 registers_ptid = inferior_ptid;
780 if (!register_cached (regnum))
781 target_fetch_registers (regnum);
783 /* Copy the value directly into the register cache. */
784 memcpy (buf, register_buffer (regcache, regnum),
785 regcache->descr->sizeof_register[regnum]);
789 regcache_raw_read_signed (struct regcache *regcache, int regnum, LONGEST *val)
792 gdb_assert (regcache != NULL);
793 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
794 buf = alloca (regcache->descr->sizeof_register[regnum]);
795 regcache_raw_read (regcache, regnum, buf);
796 (*val) = extract_signed_integer (buf,
797 regcache->descr->sizeof_register[regnum]);
801 regcache_raw_read_unsigned (struct regcache *regcache, int regnum,
805 gdb_assert (regcache != NULL);
806 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
807 buf = alloca (regcache->descr->sizeof_register[regnum]);
808 regcache_raw_read (regcache, regnum, buf);
809 (*val) = extract_unsigned_integer (buf,
810 regcache->descr->sizeof_register[regnum]);
814 regcache_raw_write_signed (struct regcache *regcache, int regnum, LONGEST val)
817 gdb_assert (regcache != NULL);
818 gdb_assert (regnum >=0 && regnum < regcache->descr->nr_raw_registers);
819 buf = alloca (regcache->descr->sizeof_register[regnum]);
820 store_signed_integer (buf, regcache->descr->sizeof_register[regnum], val);
821 regcache_raw_write (regcache, regnum, buf);
825 regcache_raw_write_unsigned (struct regcache *regcache, int regnum,
829 gdb_assert (regcache != NULL);
830 gdb_assert (regnum >=0 && regnum < regcache->descr->nr_raw_registers);
831 buf = alloca (regcache->descr->sizeof_register[regnum]);
832 store_unsigned_integer (buf, regcache->descr->sizeof_register[regnum], val);
833 regcache_raw_write (regcache, regnum, buf);
837 deprecated_read_register_gen (int regnum, char *buf)
839 gdb_assert (current_regcache != NULL);
840 gdb_assert (current_regcache->descr->gdbarch == current_gdbarch);
841 if (current_regcache->descr->legacy_p)
843 legacy_read_register_gen (regnum, buf);
846 regcache_cooked_read (current_regcache, regnum, buf);
850 regcache_cooked_read (struct regcache *regcache, int regnum, void *buf)
852 gdb_assert (regnum >= 0);
853 gdb_assert (regnum < regcache->descr->nr_cooked_registers);
854 if (regnum < regcache->descr->nr_raw_registers)
855 regcache_raw_read (regcache, regnum, buf);
856 else if (regcache->readonly_p
857 && regnum < regcache->descr->nr_cooked_registers
858 && regcache->register_valid_p[regnum])
859 /* Read-only register cache, perhaphs the cooked value was cached? */
860 memcpy (buf, register_buffer (regcache, regnum),
861 regcache->descr->sizeof_register[regnum]);
863 gdbarch_pseudo_register_read (regcache->descr->gdbarch, regcache,
868 regcache_cooked_read_signed (struct regcache *regcache, int regnum,
872 gdb_assert (regcache != NULL);
873 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_cooked_registers);
874 buf = alloca (regcache->descr->sizeof_register[regnum]);
875 regcache_cooked_read (regcache, regnum, buf);
876 (*val) = extract_signed_integer (buf,
877 regcache->descr->sizeof_register[regnum]);
881 regcache_cooked_read_unsigned (struct regcache *regcache, int regnum,
885 gdb_assert (regcache != NULL);
886 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_cooked_registers);
887 buf = alloca (regcache->descr->sizeof_register[regnum]);
888 regcache_cooked_read (regcache, regnum, buf);
889 (*val) = extract_unsigned_integer (buf,
890 regcache->descr->sizeof_register[regnum]);
894 regcache_cooked_write_signed (struct regcache *regcache, int regnum,
898 gdb_assert (regcache != NULL);
899 gdb_assert (regnum >=0 && regnum < regcache->descr->nr_cooked_registers);
900 buf = alloca (regcache->descr->sizeof_register[regnum]);
901 store_signed_integer (buf, regcache->descr->sizeof_register[regnum], val);
902 regcache_cooked_write (regcache, regnum, buf);
906 regcache_cooked_write_unsigned (struct regcache *regcache, int regnum,
910 gdb_assert (regcache != NULL);
911 gdb_assert (regnum >=0 && regnum < regcache->descr->nr_cooked_registers);
912 buf = alloca (regcache->descr->sizeof_register[regnum]);
913 store_unsigned_integer (buf, regcache->descr->sizeof_register[regnum], val);
914 regcache_cooked_write (regcache, regnum, buf);
917 /* Write register REGNUM at MYADDR to the target. MYADDR points at
918 REGISTER_RAW_BYTES(REGNUM), which must be in target byte-order. */
921 legacy_write_register_gen (int regnum, const void *myaddr)
924 gdb_assert (regnum >= 0 && regnum < (NUM_REGS + NUM_PSEUDO_REGS));
926 /* On the sparc, writing %g0 is a no-op, so we don't even want to
927 change the registers array if something writes to this register. */
928 if (CANNOT_STORE_REGISTER (regnum))
931 if (! ptid_equal (registers_ptid, inferior_ptid))
933 registers_changed ();
934 registers_ptid = inferior_ptid;
937 size = REGISTER_RAW_SIZE (regnum);
939 if (real_register (regnum))
941 /* If we have a valid copy of the register, and new value == old
942 value, then don't bother doing the actual store. */
943 if (register_cached (regnum)
944 && (memcmp (register_buffer (current_regcache, regnum), myaddr, size)
948 target_prepare_to_store ();
951 memcpy (register_buffer (current_regcache, regnum), myaddr, size);
953 set_register_cached (regnum, 1);
954 target_store_registers (regnum);
958 regcache_raw_write (struct regcache *regcache, int regnum, const void *buf)
960 gdb_assert (regcache != NULL && buf != NULL);
961 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
962 gdb_assert (!regcache->readonly_p);
964 if (regcache->descr->legacy_p)
966 /* For moment, just use underlying legacy code. Ulgh!!! This
967 silently and very indirectly updates the regcache's buffers
968 via the globals deprecated_register_valid[] and registers[]. */
969 gdb_assert (regcache == current_regcache);
970 legacy_write_register_gen (regnum, buf);
974 /* On the sparc, writing %g0 is a no-op, so we don't even want to
975 change the registers array if something writes to this register. */
976 if (CANNOT_STORE_REGISTER (regnum))
979 /* Make certain that the correct cache is selected. */
980 gdb_assert (regcache == current_regcache);
981 if (! ptid_equal (registers_ptid, inferior_ptid))
983 registers_changed ();
984 registers_ptid = inferior_ptid;
987 /* If we have a valid copy of the register, and new value == old
988 value, then don't bother doing the actual store. */
989 if (regcache_valid_p (regcache, regnum)
990 && (memcmp (register_buffer (regcache, regnum), buf,
991 regcache->descr->sizeof_register[regnum]) == 0))
994 target_prepare_to_store ();
995 memcpy (register_buffer (regcache, regnum), buf,
996 regcache->descr->sizeof_register[regnum]);
997 regcache->register_valid_p[regnum] = 1;
998 target_store_registers (regnum);
1002 deprecated_write_register_gen (int regnum, char *buf)
1004 gdb_assert (current_regcache != NULL);
1005 gdb_assert (current_regcache->descr->gdbarch == current_gdbarch);
1006 if (current_regcache->descr->legacy_p)
1008 legacy_write_register_gen (regnum, buf);
1011 regcache_cooked_write (current_regcache, regnum, buf);
1015 regcache_cooked_write (struct regcache *regcache, int regnum, const void *buf)
1017 gdb_assert (regnum >= 0);
1018 gdb_assert (regnum < regcache->descr->nr_cooked_registers);
1019 if (regnum < regcache->descr->nr_raw_registers)
1020 regcache_raw_write (regcache, regnum, buf);
1022 gdbarch_pseudo_register_write (regcache->descr->gdbarch, regcache,
1026 /* Copy INLEN bytes of consecutive data from memory at MYADDR
1027 into registers starting with the MYREGSTART'th byte of register data. */
1030 deprecated_write_register_bytes (int myregstart, char *myaddr, int inlen)
1032 int myregend = myregstart + inlen;
1035 target_prepare_to_store ();
1037 /* Scan through the registers updating any that are covered by the
1038 range myregstart<=>myregend using write_register_gen, which does
1039 nice things like handling threads, and avoiding updates when the
1040 new and old contents are the same. */
1042 for (regnum = 0; regnum < NUM_REGS + NUM_PSEUDO_REGS; regnum++)
1044 int regstart, regend;
1046 regstart = REGISTER_BYTE (regnum);
1047 regend = regstart + REGISTER_RAW_SIZE (regnum);
1049 /* Is this register completely outside the range the user is writing? */
1050 if (myregend <= regstart || regend <= myregstart)
1053 /* Is this register completely within the range the user is writing? */
1054 else if (myregstart <= regstart && regend <= myregend)
1055 deprecated_write_register_gen (regnum, myaddr + (regstart - myregstart));
1057 /* The register partially overlaps the range being written. */
1060 char regbuf[MAX_REGISTER_SIZE];
1061 /* What's the overlap between this register's bytes and
1062 those the caller wants to write? */
1063 int overlapstart = max (regstart, myregstart);
1064 int overlapend = min (regend, myregend);
1066 /* We may be doing a partial update of an invalid register.
1067 Update it from the target before scribbling on it. */
1068 deprecated_read_register_gen (regnum, regbuf);
1070 memcpy (&deprecated_registers[overlapstart],
1071 myaddr + (overlapstart - myregstart),
1072 overlapend - overlapstart);
1074 target_store_registers (regnum);
1079 /* Perform a partial register transfer using a read, modify, write
1082 typedef void (regcache_read_ftype) (struct regcache *regcache, int regnum,
1084 typedef void (regcache_write_ftype) (struct regcache *regcache, int regnum,
1088 regcache_xfer_part (struct regcache *regcache, int regnum,
1089 int offset, int len, void *in, const void *out,
1090 regcache_read_ftype *read, regcache_write_ftype *write)
1092 struct regcache_descr *descr = regcache->descr;
1093 bfd_byte *reg = alloca (descr->max_register_size);
1094 gdb_assert (offset >= 0 && offset <= descr->sizeof_register[regnum]);
1095 gdb_assert (len >= 0 && offset + len <= descr->sizeof_register[regnum]);
1096 /* Something to do? */
1097 if (offset + len == 0)
1099 /* Read (when needed) ... */
1102 || offset + len < descr->sizeof_register[regnum])
1104 gdb_assert (read != NULL);
1105 read (regcache, regnum, reg);
1107 /* ... modify ... */
1109 memcpy (in, reg + offset, len);
1111 memcpy (reg + offset, out, len);
1112 /* ... write (when needed). */
1115 gdb_assert (write != NULL);
1116 write (regcache, regnum, reg);
1121 regcache_raw_read_part (struct regcache *regcache, int regnum,
1122 int offset, int len, void *buf)
1124 struct regcache_descr *descr = regcache->descr;
1125 gdb_assert (regnum >= 0 && regnum < descr->nr_raw_registers);
1126 regcache_xfer_part (regcache, regnum, offset, len, buf, NULL,
1127 regcache_raw_read, regcache_raw_write);
1131 regcache_raw_write_part (struct regcache *regcache, int regnum,
1132 int offset, int len, const void *buf)
1134 struct regcache_descr *descr = regcache->descr;
1135 gdb_assert (regnum >= 0 && regnum < descr->nr_raw_registers);
1136 regcache_xfer_part (regcache, regnum, offset, len, NULL, buf,
1137 regcache_raw_read, regcache_raw_write);
1141 regcache_cooked_read_part (struct regcache *regcache, int regnum,
1142 int offset, int len, void *buf)
1144 struct regcache_descr *descr = regcache->descr;
1145 gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
1146 regcache_xfer_part (regcache, regnum, offset, len, buf, NULL,
1147 regcache_cooked_read, regcache_cooked_write);
1151 regcache_cooked_write_part (struct regcache *regcache, int regnum,
1152 int offset, int len, const void *buf)
1154 struct regcache_descr *descr = regcache->descr;
1155 gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
1156 regcache_xfer_part (regcache, regnum, offset, len, NULL, buf,
1157 regcache_cooked_read, regcache_cooked_write);
1160 /* Hack to keep code that view the register buffer as raw bytes
1164 register_offset_hack (struct gdbarch *gdbarch, int regnum)
1166 struct regcache_descr *descr = regcache_descr (gdbarch);
1167 gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
1168 return descr->register_offset[regnum];
1171 /* Return the contents of register REGNUM as an unsigned integer. */
1174 read_register (int regnum)
1176 char *buf = alloca (REGISTER_RAW_SIZE (regnum));
1177 deprecated_read_register_gen (regnum, buf);
1178 return (extract_unsigned_integer (buf, REGISTER_RAW_SIZE (regnum)));
1182 read_register_pid (int regnum, ptid_t ptid)
1188 if (ptid_equal (ptid, inferior_ptid))
1189 return read_register (regnum);
1191 save_ptid = inferior_ptid;
1193 inferior_ptid = ptid;
1195 retval = read_register (regnum);
1197 inferior_ptid = save_ptid;
1202 /* Store VALUE into the raw contents of register number REGNUM. */
1205 write_register (int regnum, LONGEST val)
1209 size = REGISTER_RAW_SIZE (regnum);
1210 buf = alloca (size);
1211 store_signed_integer (buf, size, (LONGEST) val);
1212 deprecated_write_register_gen (regnum, buf);
1216 write_register_pid (int regnum, CORE_ADDR val, ptid_t ptid)
1220 if (ptid_equal (ptid, inferior_ptid))
1222 write_register (regnum, val);
1226 save_ptid = inferior_ptid;
1228 inferior_ptid = ptid;
1230 write_register (regnum, val);
1232 inferior_ptid = save_ptid;
1235 /* SUPPLY_REGISTER()
1237 Record that register REGNUM contains VAL. This is used when the
1238 value is obtained from the inferior or core dump, so there is no
1239 need to store the value there.
1241 If VAL is a NULL pointer, then it's probably an unsupported register.
1242 We just set its value to all zeros. We might want to record this
1243 fact, and report it to the users of read_register and friends. */
1246 supply_register (int regnum, const void *val)
1249 if (! ptid_equal (registers_ptid, inferior_ptid))
1251 registers_changed ();
1252 registers_ptid = inferior_ptid;
1256 set_register_cached (regnum, 1);
1258 memcpy (register_buffer (current_regcache, regnum), val,
1259 REGISTER_RAW_SIZE (regnum));
1261 memset (register_buffer (current_regcache, regnum), '\000',
1262 REGISTER_RAW_SIZE (regnum));
1264 /* On some architectures, e.g. HPPA, there are a few stray bits in
1265 some registers, that the rest of the code would like to ignore. */
1267 /* NOTE: cagney/2001-03-16: The macro CLEAN_UP_REGISTER_VALUE is
1268 going to be deprecated. Instead architectures will leave the raw
1269 register value as is and instead clean things up as they pass
1270 through the method gdbarch_pseudo_register_read() clean up the
1273 #ifdef DEPRECATED_CLEAN_UP_REGISTER_VALUE
1274 DEPRECATED_CLEAN_UP_REGISTER_VALUE \
1275 (regnum, register_buffer (current_regcache, regnum));
1280 regcache_collect (int regnum, void *buf)
1282 memcpy (buf, register_buffer (current_regcache, regnum),
1283 REGISTER_RAW_SIZE (regnum));
1287 /* read_pc, write_pc, read_sp, deprecated_read_fp, etc. Special
1288 handling for registers PC, SP, and FP. */
1290 /* NOTE: cagney/2001-02-18: The functions generic_target_read_pc(),
1291 read_pc_pid(), read_pc(), generic_target_write_pc(),
1292 write_pc_pid(), write_pc(), generic_target_read_sp(), read_sp(),
1293 generic_target_write_sp(), and deprecated_read_fp(), will
1294 eventually be moved out of the reg-cache into either frame.[hc] or
1295 to the multi-arch framework. The are not part of the raw register
1298 /* This routine is getting awfully cluttered with #if's. It's probably
1299 time to turn this into READ_PC and define it in the tm.h file.
1302 1999-06-08: The following were re-written so that it assumes the
1303 existence of a TARGET_READ_PC et.al. macro. A default generic
1304 version of that macro is made available where needed.
1306 Since the ``TARGET_READ_PC'' et.al. macro is going to be controlled
1307 by the multi-arch framework, it will eventually be possible to
1308 eliminate the intermediate read_pc_pid(). The client would call
1309 TARGET_READ_PC directly. (cagney). */
1312 generic_target_read_pc (ptid_t ptid)
1317 CORE_ADDR pc_val = ADDR_BITS_REMOVE ((CORE_ADDR) read_register_pid (PC_REGNUM, ptid));
1321 internal_error (__FILE__, __LINE__,
1322 "generic_target_read_pc");
1327 read_pc_pid (ptid_t ptid)
1329 ptid_t saved_inferior_ptid;
1332 /* In case ptid != inferior_ptid. */
1333 saved_inferior_ptid = inferior_ptid;
1334 inferior_ptid = ptid;
1336 pc_val = TARGET_READ_PC (ptid);
1338 inferior_ptid = saved_inferior_ptid;
1345 return read_pc_pid (inferior_ptid);
1349 generic_target_write_pc (CORE_ADDR pc, ptid_t ptid)
1353 write_register_pid (PC_REGNUM, pc, ptid);
1354 if (NPC_REGNUM >= 0)
1355 write_register_pid (NPC_REGNUM, pc + 4, ptid);
1357 internal_error (__FILE__, __LINE__,
1358 "generic_target_write_pc");
1363 write_pc_pid (CORE_ADDR pc, ptid_t ptid)
1365 ptid_t saved_inferior_ptid;
1367 /* In case ptid != inferior_ptid. */
1368 saved_inferior_ptid = inferior_ptid;
1369 inferior_ptid = ptid;
1371 TARGET_WRITE_PC (pc, ptid);
1373 inferior_ptid = saved_inferior_ptid;
1377 write_pc (CORE_ADDR pc)
1379 write_pc_pid (pc, inferior_ptid);
1382 /* Cope with strage ways of getting to the stack and frame pointers */
1385 generic_target_read_sp (void)
1389 return read_register (SP_REGNUM);
1391 internal_error (__FILE__, __LINE__,
1392 "generic_target_read_sp");
1398 return TARGET_READ_SP ();
1402 generic_target_write_sp (CORE_ADDR val)
1407 write_register (SP_REGNUM, val);
1411 internal_error (__FILE__, __LINE__,
1412 "generic_target_write_sp");
1416 deprecated_read_fp (void)
1418 if (DEPRECATED_TARGET_READ_FP_P ())
1419 return DEPRECATED_TARGET_READ_FP ();
1420 else if (DEPRECATED_FP_REGNUM >= 0)
1421 return read_register (DEPRECATED_FP_REGNUM);
1423 internal_error (__FILE__, __LINE__, "deprecated_read_fp");
1428 reg_flush_command (char *command, int from_tty)
1430 /* Force-flush the register cache. */
1431 registers_changed ();
1433 printf_filtered ("Register cache flushed.\n");
1437 build_regcache (void)
1439 current_regcache = regcache_xmalloc (current_gdbarch);
1440 current_regcache->readonly_p = 0;
1441 deprecated_registers = deprecated_grub_regcache_for_registers (current_regcache);
1442 deprecated_register_valid = deprecated_grub_regcache_for_register_valid (current_regcache);
1446 dump_endian_bytes (struct ui_file *file, enum bfd_endian endian,
1447 const unsigned char *buf, long len)
1452 case BFD_ENDIAN_BIG:
1453 for (i = 0; i < len; i++)
1454 fprintf_unfiltered (file, "%02x", buf[i]);
1456 case BFD_ENDIAN_LITTLE:
1457 for (i = len - 1; i >= 0; i--)
1458 fprintf_unfiltered (file, "%02x", buf[i]);
1461 internal_error (__FILE__, __LINE__, "Bad switch");
1465 enum regcache_dump_what
1467 regcache_dump_none, regcache_dump_raw, regcache_dump_cooked, regcache_dump_groups
1471 regcache_dump (struct regcache *regcache, struct ui_file *file,
1472 enum regcache_dump_what what_to_dump)
1474 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
1475 struct gdbarch *gdbarch = regcache->descr->gdbarch;
1476 struct reggroup *const *groups = reggroups (gdbarch);
1478 int footnote_nr = 0;
1479 int footnote_register_size = 0;
1480 int footnote_register_offset = 0;
1481 int footnote_register_type_name_null = 0;
1482 long register_offset = 0;
1483 unsigned char *buf = alloca (regcache->descr->max_register_size);
1486 fprintf_unfiltered (file, "legacy_p %d\n", regcache->descr->legacy_p);
1487 fprintf_unfiltered (file, "nr_raw_registers %d\n",
1488 regcache->descr->nr_raw_registers);
1489 fprintf_unfiltered (file, "nr_cooked_registers %d\n",
1490 regcache->descr->nr_cooked_registers);
1491 fprintf_unfiltered (file, "sizeof_raw_registers %ld\n",
1492 regcache->descr->sizeof_raw_registers);
1493 fprintf_unfiltered (file, "sizeof_raw_register_valid_p %ld\n",
1494 regcache->descr->sizeof_raw_register_valid_p);
1495 fprintf_unfiltered (file, "max_register_size %ld\n",
1496 regcache->descr->max_register_size);
1497 fprintf_unfiltered (file, "NUM_REGS %d\n", NUM_REGS);
1498 fprintf_unfiltered (file, "NUM_PSEUDO_REGS %d\n", NUM_PSEUDO_REGS);
1501 gdb_assert (regcache->descr->nr_cooked_registers
1502 == (NUM_REGS + NUM_PSEUDO_REGS));
1504 for (regnum = -1; regnum < regcache->descr->nr_cooked_registers; regnum++)
1508 fprintf_unfiltered (file, " %-10s", "Name");
1511 const char *p = REGISTER_NAME (regnum);
1514 else if (p[0] == '\0')
1516 fprintf_unfiltered (file, " %-10s", p);
1521 fprintf_unfiltered (file, " %4s", "Nr");
1523 fprintf_unfiltered (file, " %4d", regnum);
1525 /* Relative number. */
1527 fprintf_unfiltered (file, " %4s", "Rel");
1528 else if (regnum < NUM_REGS)
1529 fprintf_unfiltered (file, " %4d", regnum);
1531 fprintf_unfiltered (file, " %4d", (regnum - NUM_REGS));
1535 fprintf_unfiltered (file, " %6s ", "Offset");
1538 fprintf_unfiltered (file, " %6ld",
1539 regcache->descr->register_offset[regnum]);
1540 if (register_offset != regcache->descr->register_offset[regnum]
1541 || register_offset != REGISTER_BYTE (regnum)
1543 && (regcache->descr->register_offset[regnum]
1544 != (regcache->descr->register_offset[regnum - 1]
1545 + regcache->descr->sizeof_register[regnum - 1])))
1548 if (!footnote_register_offset)
1549 footnote_register_offset = ++footnote_nr;
1550 fprintf_unfiltered (file, "*%d", footnote_register_offset);
1553 fprintf_unfiltered (file, " ");
1554 register_offset = (regcache->descr->register_offset[regnum]
1555 + regcache->descr->sizeof_register[regnum]);
1560 fprintf_unfiltered (file, " %5s ", "Size");
1563 fprintf_unfiltered (file, " %5ld",
1564 regcache->descr->sizeof_register[regnum]);
1565 if ((regcache->descr->sizeof_register[regnum]
1566 != REGISTER_RAW_SIZE (regnum))
1567 || (regcache->descr->sizeof_register[regnum]
1568 != REGISTER_VIRTUAL_SIZE (regnum))
1569 || (regcache->descr->sizeof_register[regnum]
1570 != TYPE_LENGTH (register_type (regcache->descr->gdbarch,
1574 if (!footnote_register_size)
1575 footnote_register_size = ++footnote_nr;
1576 fprintf_unfiltered (file, "*%d", footnote_register_size);
1579 fprintf_unfiltered (file, " ");
1589 static const char blt[] = "builtin_type";
1590 t = TYPE_NAME (register_type (regcache->descr->gdbarch, regnum));
1594 if (!footnote_register_type_name_null)
1595 footnote_register_type_name_null = ++footnote_nr;
1596 xasprintf (&n, "*%d", footnote_register_type_name_null);
1597 make_cleanup (xfree, n);
1600 /* Chop a leading builtin_type. */
1601 if (strncmp (t, blt, strlen (blt)) == 0)
1604 fprintf_unfiltered (file, " %-15s", t);
1607 /* Leading space always present. */
1608 fprintf_unfiltered (file, " ");
1611 if (what_to_dump == regcache_dump_raw)
1614 fprintf_unfiltered (file, "Raw value");
1615 else if (regnum >= regcache->descr->nr_raw_registers)
1616 fprintf_unfiltered (file, "<cooked>");
1617 else if (!regcache_valid_p (regcache, regnum))
1618 fprintf_unfiltered (file, "<invalid>");
1621 regcache_raw_read (regcache, regnum, buf);
1622 fprintf_unfiltered (file, "0x");
1623 dump_endian_bytes (file, TARGET_BYTE_ORDER, buf,
1624 REGISTER_RAW_SIZE (regnum));
1628 /* Value, cooked. */
1629 if (what_to_dump == regcache_dump_cooked)
1632 fprintf_unfiltered (file, "Cooked value");
1635 regcache_cooked_read (regcache, regnum, buf);
1636 fprintf_unfiltered (file, "0x");
1637 dump_endian_bytes (file, TARGET_BYTE_ORDER, buf,
1638 REGISTER_VIRTUAL_SIZE (regnum));
1642 /* Group members. */
1643 if (what_to_dump == regcache_dump_groups)
1646 fprintf_unfiltered (file, "Groups");
1650 const char *sep = "";
1651 for (i = 0; groups[i] != NULL; i++)
1653 if (gdbarch_register_reggroup_p (gdbarch, regnum, groups[i]))
1655 fprintf_unfiltered (file, "%s%s", sep, reggroup_name (groups[i]));
1662 fprintf_unfiltered (file, "\n");
1665 if (footnote_register_size)
1666 fprintf_unfiltered (file, "*%d: Inconsistent register sizes.\n",
1667 footnote_register_size);
1668 if (footnote_register_offset)
1669 fprintf_unfiltered (file, "*%d: Inconsistent register offsets.\n",
1670 footnote_register_offset);
1671 if (footnote_register_type_name_null)
1672 fprintf_unfiltered (file,
1673 "*%d: Register type's name NULL.\n",
1674 footnote_register_type_name_null);
1675 do_cleanups (cleanups);
1679 regcache_print (char *args, enum regcache_dump_what what_to_dump)
1682 regcache_dump (current_regcache, gdb_stdout, what_to_dump);
1685 struct ui_file *file = gdb_fopen (args, "w");
1687 perror_with_name ("maintenance print architecture");
1688 regcache_dump (current_regcache, file, what_to_dump);
1689 ui_file_delete (file);
1694 maintenance_print_registers (char *args, int from_tty)
1696 regcache_print (args, regcache_dump_none);
1700 maintenance_print_raw_registers (char *args, int from_tty)
1702 regcache_print (args, regcache_dump_raw);
1706 maintenance_print_cooked_registers (char *args, int from_tty)
1708 regcache_print (args, regcache_dump_cooked);
1712 maintenance_print_register_groups (char *args, int from_tty)
1714 regcache_print (args, regcache_dump_groups);
1718 _initialize_regcache (void)
1720 regcache_descr_handle = register_gdbarch_data (init_regcache_descr,
1721 xfree_regcache_descr);
1722 REGISTER_GDBARCH_SWAP (current_regcache);
1723 register_gdbarch_swap (&deprecated_registers, sizeof (deprecated_registers), NULL);
1724 register_gdbarch_swap (&deprecated_register_valid, sizeof (deprecated_register_valid), NULL);
1725 register_gdbarch_swap (NULL, 0, build_regcache);
1727 add_com ("flushregs", class_maintenance, reg_flush_command,
1728 "Force gdb to flush its register cache (maintainer command)");
1730 /* Initialize the thread/process associated with the current set of
1731 registers. For now, -1 is special, and means `no current process'. */
1732 registers_ptid = pid_to_ptid (-1);
1734 add_cmd ("registers", class_maintenance,
1735 maintenance_print_registers,
1736 "Print the internal register configuration.\
1737 Takes an optional file parameter.",
1738 &maintenanceprintlist);
1739 add_cmd ("raw-registers", class_maintenance,
1740 maintenance_print_raw_registers,
1741 "Print the internal register configuration including raw values.\
1742 Takes an optional file parameter.",
1743 &maintenanceprintlist);
1744 add_cmd ("cooked-registers", class_maintenance,
1745 maintenance_print_cooked_registers,
1746 "Print the internal register configuration including cooked values.\
1747 Takes an optional file parameter.",
1748 &maintenanceprintlist);
1749 add_cmd ("register-groups", class_maintenance,
1750 maintenance_print_register_groups,
1751 "Print the internal register configuration including each register's group.\
1752 Takes an optional file parameter.",
1753 &maintenanceprintlist);