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 /* Cached table containing the type of each register. */
82 struct type
**register_type
;
86 init_legacy_regcache_descr (struct gdbarch
*gdbarch
,
87 struct regcache_descr
*descr
)
90 /* FIXME: cagney/2002-05-11: gdbarch_data() should take that
91 ``gdbarch'' as a parameter. */
92 gdb_assert (gdbarch
!= NULL
);
94 /* FIXME: cagney/2002-05-11: Shouldn't be including pseudo-registers
95 in the register cache. Unfortunatly some architectures still
96 rely on this and the pseudo_register_write() method. */
97 descr
->nr_raw_registers
= descr
->nr_cooked_registers
;
98 descr
->sizeof_raw_register_valid_p
= descr
->sizeof_cooked_register_valid_p
;
100 /* Compute the offset of each register. Legacy architectures define
101 REGISTER_BYTE() so use that. */
102 /* FIXME: cagney/2002-11-07: Instead of using REGISTER_BYTE() this
103 code should, as is done in init_regcache_descr(), compute the
104 offets at runtime. This currently isn't possible as some ISAs
105 define overlapping register regions - see the mess in
106 read_register_bytes() and write_register_bytes() registers. */
107 descr
->sizeof_register
= XCALLOC (descr
->nr_cooked_registers
, long);
108 descr
->register_offset
= XCALLOC (descr
->nr_cooked_registers
, long);
109 for (i
= 0; i
< descr
->nr_cooked_registers
; i
++)
111 /* FIXME: cagney/2001-12-04: This code shouldn't need to use
112 REGISTER_BYTE(). Unfortunatly, legacy code likes to lay the
113 buffer out so that certain registers just happen to overlap.
114 Ulgh! New targets use gdbarch's register read/write and
115 entirely avoid this uglyness. */
116 descr
->register_offset
[i
] = REGISTER_BYTE (i
);
117 descr
->sizeof_register
[i
] = REGISTER_RAW_SIZE (i
);
118 gdb_assert (MAX_REGISTER_SIZE
>= REGISTER_RAW_SIZE (i
));
119 gdb_assert (MAX_REGISTER_SIZE
>= REGISTER_VIRTUAL_SIZE (i
));
122 /* Compute the real size of the register buffer. Start out by
123 trusting DEPRECATED_REGISTER_BYTES, but then adjust it upwards
124 should that be found to not be sufficient. */
125 /* FIXME: cagney/2002-11-05: Instead of using the macro
126 DEPRECATED_REGISTER_BYTES, this code should, as is done in
127 init_regcache_descr(), compute the total number of register bytes
128 using the accumulated offsets. */
129 descr
->sizeof_cooked_registers
= DEPRECATED_REGISTER_BYTES
; /* OK */
130 for (i
= 0; i
< descr
->nr_cooked_registers
; i
++)
133 /* Keep extending the buffer so that there is always enough
134 space for all registers. The comparison is necessary since
135 legacy code is free to put registers in random places in the
136 buffer separated by holes. Once REGISTER_BYTE() is killed
137 this can be greatly simplified. */
138 regend
= descr
->register_offset
[i
] + descr
->sizeof_register
[i
];
139 if (descr
->sizeof_cooked_registers
< regend
)
140 descr
->sizeof_cooked_registers
= regend
;
142 /* FIXME: cagney/2002-05-11: Shouldn't be including pseudo-registers
143 in the register cache. Unfortunatly some architectures still
144 rely on this and the pseudo_register_write() method. */
145 descr
->sizeof_raw_registers
= descr
->sizeof_cooked_registers
;
149 init_regcache_descr (struct gdbarch
*gdbarch
)
152 struct regcache_descr
*descr
;
153 gdb_assert (gdbarch
!= NULL
);
155 /* Create an initial, zero filled, table. */
156 descr
= XCALLOC (1, struct regcache_descr
);
157 descr
->gdbarch
= gdbarch
;
159 /* Total size of the register space. The raw registers are mapped
160 directly onto the raw register cache while the pseudo's are
161 either mapped onto raw-registers or memory. */
162 descr
->nr_cooked_registers
= NUM_REGS
+ NUM_PSEUDO_REGS
;
163 descr
->sizeof_cooked_register_valid_p
= NUM_REGS
+ NUM_PSEUDO_REGS
;
165 /* Fill in a table of register types. */
166 descr
->register_type
= XCALLOC (descr
->nr_cooked_registers
,
168 for (i
= 0; i
< descr
->nr_cooked_registers
; i
++)
170 if (gdbarch_register_type_p (gdbarch
))
172 gdb_assert (!REGISTER_VIRTUAL_TYPE_P ()); /* OK */
173 descr
->register_type
[i
] = gdbarch_register_type (gdbarch
, i
);
176 descr
->register_type
[i
] = REGISTER_VIRTUAL_TYPE (i
); /* OK */
179 /* If an old style architecture, fill in the remainder of the
180 register cache descriptor using the register macros. */
181 if (!gdbarch_pseudo_register_read_p (gdbarch
)
182 && !gdbarch_pseudo_register_write_p (gdbarch
)
183 && !gdbarch_register_type_p (gdbarch
))
185 /* NOTE: cagney/2003-05-02: Don't add a test for REGISTER_BYTE_P
186 to the above. Doing that would cause all the existing
187 architectures to revert back to the legacy regcache
188 mechanisms, and that is not a good thing. Instead just,
189 later, check that the register cache's layout is consistent
190 with REGISTER_BYTE. */
192 init_legacy_regcache_descr (gdbarch
, descr
);
196 /* Construct a strictly RAW register cache. Don't allow pseudo's
197 into the register cache. */
198 descr
->nr_raw_registers
= NUM_REGS
;
200 /* FIXME: cagney/2002-08-13: Overallocate the register_valid_p
201 array. This pretects GDB from erant code that accesses elements
202 of the global register_valid_p[] array in the range [NUM_REGS
203 .. NUM_REGS + NUM_PSEUDO_REGS). */
204 descr
->sizeof_raw_register_valid_p
= descr
->sizeof_cooked_register_valid_p
;
206 /* Lay out the register cache.
208 NOTE: cagney/2002-05-22: Only register_type() is used when
209 constructing the register cache. It is assumed that the
210 register's raw size, virtual size and type length are all the
215 descr
->sizeof_register
= XCALLOC (descr
->nr_cooked_registers
, long);
216 descr
->register_offset
= XCALLOC (descr
->nr_cooked_registers
, long);
217 for (i
= 0; i
< descr
->nr_cooked_registers
; i
++)
219 descr
->sizeof_register
[i
] = TYPE_LENGTH (descr
->register_type
[i
]);
220 descr
->register_offset
[i
] = offset
;
221 offset
+= descr
->sizeof_register
[i
];
222 gdb_assert (MAX_REGISTER_SIZE
>= descr
->sizeof_register
[i
]);
224 /* Set the real size of the register cache buffer. */
225 descr
->sizeof_cooked_registers
= offset
;
228 /* FIXME: cagney/2002-05-22: Should only need to allocate space for
229 the raw registers. Unfortunatly some code still accesses the
230 register array directly using the global registers[]. Until that
231 code has been purged, play safe and over allocating the register
233 descr
->sizeof_raw_registers
= descr
->sizeof_cooked_registers
;
235 /* Sanity check. Confirm that there is agreement between the
236 regcache and the target's redundant REGISTER_BYTE (new targets
237 should not even be defining it). */
238 for (i
= 0; i
< descr
->nr_cooked_registers
; i
++)
240 if (REGISTER_BYTE_P ())
241 gdb_assert (descr
->register_offset
[i
] == REGISTER_BYTE (i
));
243 gdb_assert (descr
->sizeof_register
[i
] == REGISTER_RAW_SIZE (i
));
244 gdb_assert (descr
->sizeof_register
[i
] == REGISTER_VIRTUAL_SIZE (i
));
247 /* gdb_assert (descr->sizeof_raw_registers == DEPRECATED_REGISTER_BYTES (i)); */
252 static struct regcache_descr
*
253 regcache_descr (struct gdbarch
*gdbarch
)
255 return gdbarch_data (gdbarch
, regcache_descr_handle
);
259 xfree_regcache_descr (struct gdbarch
*gdbarch
, void *ptr
)
261 struct regcache_descr
*descr
= ptr
;
264 xfree (descr
->register_offset
);
265 xfree (descr
->sizeof_register
);
266 descr
->register_offset
= NULL
;
267 descr
->sizeof_register
= NULL
;
271 /* Utility functions returning useful register attributes stored in
272 the regcache descr. */
275 register_type (struct gdbarch
*gdbarch
, int regnum
)
277 struct regcache_descr
*descr
= regcache_descr (gdbarch
);
278 gdb_assert (regnum
>= 0 && regnum
< descr
->nr_cooked_registers
);
279 return descr
->register_type
[regnum
];
282 /* Utility functions returning useful register attributes stored in
283 the regcache descr. */
286 register_size (struct gdbarch
*gdbarch
, int regnum
)
288 struct regcache_descr
*descr
= regcache_descr (gdbarch
);
290 gdb_assert (regnum
>= 0 && regnum
< (NUM_REGS
+ NUM_PSEUDO_REGS
));
291 size
= descr
->sizeof_register
[regnum
];
292 gdb_assert (size
== REGISTER_RAW_SIZE (regnum
)); /* OK */
293 gdb_assert (size
== REGISTER_RAW_SIZE (regnum
)); /* OK */
297 /* The register cache for storing raw register values. */
301 struct regcache_descr
*descr
;
302 /* The register buffers. A read-only register cache can hold the
303 full [0 .. NUM_REGS + NUM_PSEUDO_REGS) while a read/write
304 register cache can only hold [0 .. NUM_REGS). */
306 char *register_valid_p
;
307 /* Is this a read-only cache? A read-only cache is used for saving
308 the target's register state (e.g, across an inferior function
309 call or just before forcing a function return). A read-only
310 cache can only be updated via the methods regcache_dup() and
311 regcache_cpy(). The actual contents are determined by the
312 reggroup_save and reggroup_restore methods. */
317 regcache_xmalloc (struct gdbarch
*gdbarch
)
319 struct regcache_descr
*descr
;
320 struct regcache
*regcache
;
321 gdb_assert (gdbarch
!= NULL
);
322 descr
= regcache_descr (gdbarch
);
323 regcache
= XMALLOC (struct regcache
);
324 regcache
->descr
= descr
;
326 = XCALLOC (descr
->sizeof_raw_registers
, char);
327 regcache
->register_valid_p
328 = XCALLOC (descr
->sizeof_raw_register_valid_p
, char);
329 regcache
->readonly_p
= 1;
334 regcache_xfree (struct regcache
*regcache
)
336 if (regcache
== NULL
)
338 xfree (regcache
->registers
);
339 xfree (regcache
->register_valid_p
);
344 do_regcache_xfree (void *data
)
346 regcache_xfree (data
);
350 make_cleanup_regcache_xfree (struct regcache
*regcache
)
352 return make_cleanup (do_regcache_xfree
, regcache
);
355 /* Return a pointer to register REGNUM's buffer cache. */
358 register_buffer (struct regcache
*regcache
, int regnum
)
360 return regcache
->registers
+ regcache
->descr
->register_offset
[regnum
];
364 regcache_save (struct regcache
*dst
, regcache_cooked_read_ftype
*cooked_read
,
367 struct gdbarch
*gdbarch
= dst
->descr
->gdbarch
;
368 char buf
[MAX_REGISTER_SIZE
];
370 /* The DST should be `read-only', if it wasn't then the save would
371 end up trying to write the register values back out to the
373 gdb_assert (dst
->readonly_p
);
374 /* Clear the dest. */
375 memset (dst
->registers
, 0, dst
->descr
->sizeof_cooked_registers
);
376 memset (dst
->register_valid_p
, 0, dst
->descr
->sizeof_cooked_register_valid_p
);
377 /* Copy over any registers (identified by their membership in the
378 save_reggroup) and mark them as valid. The full [0 .. NUM_REGS +
379 NUM_PSEUDO_REGS) range is checked since some architectures need
380 to save/restore `cooked' registers that live in memory. */
381 for (regnum
= 0; regnum
< dst
->descr
->nr_cooked_registers
; regnum
++)
383 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, save_reggroup
))
385 int valid
= cooked_read (src
, regnum
, buf
);
388 memcpy (register_buffer (dst
, regnum
), buf
,
389 register_size (gdbarch
, regnum
));
390 dst
->register_valid_p
[regnum
] = 1;
397 regcache_restore (struct regcache
*dst
,
398 regcache_cooked_read_ftype
*cooked_read
,
401 struct gdbarch
*gdbarch
= dst
->descr
->gdbarch
;
402 char buf
[MAX_REGISTER_SIZE
];
404 /* The dst had better not be read-only. If it is, the `restore'
405 doesn't make much sense. */
406 gdb_assert (!dst
->readonly_p
);
407 /* Copy over any registers, being careful to only restore those that
408 were both saved and need to be restored. The full [0 .. NUM_REGS
409 + NUM_PSEUDO_REGS) range is checked since some architectures need
410 to save/restore `cooked' registers that live in memory. */
411 for (regnum
= 0; regnum
< dst
->descr
->nr_cooked_registers
; regnum
++)
413 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, restore_reggroup
))
415 int valid
= cooked_read (src
, regnum
, buf
);
417 regcache_cooked_write (dst
, regnum
, buf
);
423 do_cooked_read (void *src
, int regnum
, void *buf
)
425 struct regcache
*regcache
= src
;
426 if (!regcache_valid_p (regcache
, regnum
)
427 && regcache
->readonly_p
)
428 /* Don't even think about fetching a register from a read-only
429 cache when the register isn't yet valid. There isn't a target
430 from which the register value can be fetched. */
432 regcache_cooked_read (regcache
, regnum
, buf
);
438 regcache_cpy (struct regcache
*dst
, struct regcache
*src
)
442 gdb_assert (src
!= NULL
&& dst
!= NULL
);
443 gdb_assert (src
->descr
->gdbarch
== dst
->descr
->gdbarch
);
444 gdb_assert (src
!= dst
);
445 gdb_assert (src
->readonly_p
|| dst
->readonly_p
);
446 if (!src
->readonly_p
)
447 regcache_save (dst
, do_cooked_read
, src
);
448 else if (!dst
->readonly_p
)
449 regcache_restore (dst
, do_cooked_read
, src
);
451 regcache_cpy_no_passthrough (dst
, src
);
455 regcache_cpy_no_passthrough (struct regcache
*dst
, struct regcache
*src
)
458 gdb_assert (src
!= NULL
&& dst
!= NULL
);
459 gdb_assert (src
->descr
->gdbarch
== dst
->descr
->gdbarch
);
460 /* NOTE: cagney/2002-05-17: Don't let the caller do a no-passthrough
461 move of data into the current_regcache(). Doing this would be
462 silly - it would mean that valid_p would be completly invalid. */
463 gdb_assert (dst
!= current_regcache
);
464 memcpy (dst
->registers
, src
->registers
, dst
->descr
->sizeof_raw_registers
);
465 memcpy (dst
->register_valid_p
, src
->register_valid_p
,
466 dst
->descr
->sizeof_raw_register_valid_p
);
470 regcache_dup (struct regcache
*src
)
472 struct regcache
*newbuf
;
473 gdb_assert (current_regcache
!= NULL
);
474 newbuf
= regcache_xmalloc (src
->descr
->gdbarch
);
475 regcache_cpy (newbuf
, src
);
480 regcache_dup_no_passthrough (struct regcache
*src
)
482 struct regcache
*newbuf
;
483 gdb_assert (current_regcache
!= NULL
);
484 newbuf
= regcache_xmalloc (src
->descr
->gdbarch
);
485 regcache_cpy_no_passthrough (newbuf
, src
);
490 regcache_valid_p (struct regcache
*regcache
, int regnum
)
492 gdb_assert (regcache
!= NULL
);
493 gdb_assert (regnum
>= 0 && regnum
< regcache
->descr
->nr_raw_registers
);
494 return regcache
->register_valid_p
[regnum
];
498 deprecated_grub_regcache_for_registers (struct regcache
*regcache
)
500 return regcache
->registers
;
503 /* Global structure containing the current regcache. */
504 /* FIXME: cagney/2002-05-11: The two global arrays registers[] and
505 deprecated_register_valid[] currently point into this structure. */
506 struct regcache
*current_regcache
;
508 /* NOTE: this is a write-through cache. There is no "dirty" bit for
509 recording if the register values have been changed (eg. by the
510 user). Therefore all registers must be written back to the
511 target when appropriate. */
513 /* REGISTERS contains the cached register values (in target byte order). */
515 char *deprecated_registers
;
517 /* DEPRECATED_REGISTER_VALID is 0 if the register needs to be fetched,
518 1 if it has been fetched, and
519 -1 if the register value was not available.
521 "Not available" indicates that the target is not not able to supply
522 the register at this state. The register may become available at a
523 later time (after the next resume). This often occures when GDB is
524 manipulating a target that contains only a snapshot of the entire
525 system being debugged - some of the registers in such a system may
526 not have been saved. */
528 signed char *deprecated_register_valid
;
530 /* The thread/process associated with the current set of registers. */
532 static ptid_t registers_ptid
;
540 Returns 0 if the value is not in the cache (needs fetch).
541 >0 if the value is in the cache.
542 <0 if the value is permanently unavailable (don't ask again). */
545 register_cached (int regnum
)
547 return deprecated_register_valid
[regnum
];
550 /* Record that REGNUM's value is cached if STATE is >0, uncached but
551 fetchable if STATE is 0, and uncached and unfetchable if STATE is <0. */
554 set_register_cached (int regnum
, int state
)
556 gdb_assert (regnum
>= 0);
557 gdb_assert (regnum
< current_regcache
->descr
->nr_raw_registers
);
558 current_regcache
->register_valid_p
[regnum
] = state
;
561 /* Return whether register REGNUM is a real register. */
564 real_register (int regnum
)
566 return regnum
>= 0 && regnum
< NUM_REGS
;
569 /* Low level examining and depositing of registers.
571 The caller is responsible for making sure that the inferior is
572 stopped before calling the fetching routines, or it will get
573 garbage. (a change from GDB version 3, in which the caller got the
574 value from the last stop). */
576 /* REGISTERS_CHANGED ()
578 Indicate that registers may have changed, so invalidate the cache. */
581 registers_changed (void)
585 registers_ptid
= pid_to_ptid (-1);
587 /* Force cleanup of any alloca areas if using C alloca instead of
588 a builtin alloca. This particular call is used to clean up
589 areas allocated by low level target code which may build up
590 during lengthy interactions between gdb and the target before
591 gdb gives control to the user (ie watchpoints). */
594 for (i
= 0; i
< current_regcache
->descr
->nr_raw_registers
; i
++)
595 set_register_cached (i
, 0);
597 if (registers_changed_hook
)
598 registers_changed_hook ();
601 /* DEPRECATED_REGISTERS_FETCHED ()
603 Indicate that all registers have been fetched, so mark them all valid. */
605 /* NOTE: cagney/2001-12-04: This function does not set valid on the
606 pseudo-register range since pseudo registers are always supplied
607 using supply_register(). */
608 /* FIXME: cagney/2001-12-04: This function is DEPRECATED. The target
609 code was blatting the registers[] array and then calling this.
610 Since targets should only be using supply_register() the need for
611 this function/hack is eliminated. */
614 deprecated_registers_fetched (void)
618 for (i
= 0; i
< NUM_REGS
; i
++)
619 set_register_cached (i
, 1);
620 /* Do not assume that the pseudo-regs have also been fetched.
621 Fetching all real regs NEVER accounts for pseudo-regs. */
624 /* deprecated_read_register_bytes and deprecated_write_register_bytes
625 are generally a *BAD* idea. They are inefficient because they need
626 to check for partial updates, which can only be done by scanning
627 through all of the registers and seeing if the bytes that are being
628 read/written fall inside of an invalid register. [The main reason
629 this is necessary is that register sizes can vary, so a simple
630 index won't suffice.] It is far better to call read_register_gen
631 and write_register_gen if you want to get at the raw register
632 contents, as it only takes a regnum as an argument, and therefore
633 can't do a partial register update.
635 Prior to the recent fixes to check for partial updates, both read
636 and deprecated_write_register_bytes always checked to see if any
637 registers were stale, and then called target_fetch_registers (-1)
638 to update the whole set. This caused really slowed things down for
641 /* Copy INLEN bytes of consecutive data from registers
642 starting with the INREGBYTE'th byte of register data
643 into memory at MYADDR. */
646 deprecated_read_register_bytes (int in_start
, char *in_buf
, int in_len
)
648 int in_end
= in_start
+ in_len
;
650 char reg_buf
[MAX_REGISTER_SIZE
];
652 /* See if we are trying to read bytes from out-of-date registers. If so,
653 update just those registers. */
655 for (regnum
= 0; regnum
< NUM_REGS
+ NUM_PSEUDO_REGS
; regnum
++)
664 reg_start
= REGISTER_BYTE (regnum
);
665 reg_len
= REGISTER_RAW_SIZE (regnum
);
666 reg_end
= reg_start
+ reg_len
;
668 if (reg_end
<= in_start
|| in_end
<= reg_start
)
669 /* The range the user wants to read doesn't overlap with regnum. */
672 if (REGISTER_NAME (regnum
) != NULL
&& *REGISTER_NAME (regnum
) != '\0')
673 /* Force the cache to fetch the entire register. */
674 deprecated_read_register_gen (regnum
, reg_buf
);
676 /* Legacy note: even though this register is ``invalid'' we
677 still need to return something. It would appear that some
678 code relies on apparent gaps in the register array also
680 /* FIXME: cagney/2001-08-18: This is just silly. It defeats
681 the entire register read/write flow of control. Must
682 resist temptation to return 0xdeadbeef. */
683 memcpy (reg_buf
, &deprecated_registers
[reg_start
], reg_len
);
685 /* Legacy note: This function, for some reason, allows a NULL
686 input buffer. If the buffer is NULL, the registers are still
687 fetched, just the final transfer is skipped. */
691 /* start = max (reg_start, in_start) */
692 if (reg_start
> in_start
)
697 /* end = min (reg_end, in_end) */
698 if (reg_end
< in_end
)
703 /* Transfer just the bytes common to both IN_BUF and REG_BUF */
704 for (byte
= start
; byte
< end
; byte
++)
706 in_buf
[byte
- in_start
] = reg_buf
[byte
- reg_start
];
711 /* Read register REGNUM into memory at MYADDR, which must be large
712 enough for REGISTER_RAW_BYTES (REGNUM). Target byte-order. If the
713 register is known to be the size of a CORE_ADDR or smaller,
714 read_register can be used instead. */
717 legacy_read_register_gen (int regnum
, char *myaddr
)
719 gdb_assert (regnum
>= 0 && regnum
< (NUM_REGS
+ NUM_PSEUDO_REGS
));
720 if (! ptid_equal (registers_ptid
, inferior_ptid
))
722 registers_changed ();
723 registers_ptid
= inferior_ptid
;
726 if (!register_cached (regnum
))
727 target_fetch_registers (regnum
);
729 memcpy (myaddr
, register_buffer (current_regcache
, regnum
),
730 REGISTER_RAW_SIZE (regnum
));
734 regcache_raw_read (struct regcache
*regcache
, int regnum
, void *buf
)
736 gdb_assert (regcache
!= NULL
&& buf
!= NULL
);
737 gdb_assert (regnum
>= 0 && regnum
< regcache
->descr
->nr_raw_registers
);
738 if (regcache
->descr
->legacy_p
739 && !regcache
->readonly_p
)
741 gdb_assert (regcache
== current_regcache
);
742 /* For moment, just use underlying legacy code. Ulgh!!! This
743 silently and very indirectly updates the regcache's regcache
744 via the global deprecated_register_valid[]. */
745 legacy_read_register_gen (regnum
, buf
);
748 /* Make certain that the register cache is up-to-date with respect
749 to the current thread. This switching shouldn't be necessary
750 only there is still only one target side register cache. Sigh!
751 On the bright side, at least there is a regcache object. */
752 if (!regcache
->readonly_p
)
754 gdb_assert (regcache
== current_regcache
);
755 if (! ptid_equal (registers_ptid
, inferior_ptid
))
757 registers_changed ();
758 registers_ptid
= inferior_ptid
;
760 if (!register_cached (regnum
))
761 target_fetch_registers (regnum
);
763 /* Copy the value directly into the register cache. */
764 memcpy (buf
, register_buffer (regcache
, regnum
),
765 regcache
->descr
->sizeof_register
[regnum
]);
769 regcache_raw_read_signed (struct regcache
*regcache
, int regnum
, LONGEST
*val
)
772 gdb_assert (regcache
!= NULL
);
773 gdb_assert (regnum
>= 0 && regnum
< regcache
->descr
->nr_raw_registers
);
774 buf
= alloca (regcache
->descr
->sizeof_register
[regnum
]);
775 regcache_raw_read (regcache
, regnum
, buf
);
776 (*val
) = extract_signed_integer (buf
,
777 regcache
->descr
->sizeof_register
[regnum
]);
781 regcache_raw_read_unsigned (struct regcache
*regcache
, int regnum
,
785 gdb_assert (regcache
!= NULL
);
786 gdb_assert (regnum
>= 0 && regnum
< regcache
->descr
->nr_raw_registers
);
787 buf
= alloca (regcache
->descr
->sizeof_register
[regnum
]);
788 regcache_raw_read (regcache
, regnum
, buf
);
789 (*val
) = extract_unsigned_integer (buf
,
790 regcache
->descr
->sizeof_register
[regnum
]);
794 regcache_raw_write_signed (struct regcache
*regcache
, int regnum
, LONGEST val
)
797 gdb_assert (regcache
!= NULL
);
798 gdb_assert (regnum
>=0 && regnum
< regcache
->descr
->nr_raw_registers
);
799 buf
= alloca (regcache
->descr
->sizeof_register
[regnum
]);
800 store_signed_integer (buf
, regcache
->descr
->sizeof_register
[regnum
], val
);
801 regcache_raw_write (regcache
, regnum
, buf
);
805 regcache_raw_write_unsigned (struct regcache
*regcache
, int regnum
,
809 gdb_assert (regcache
!= NULL
);
810 gdb_assert (regnum
>=0 && regnum
< regcache
->descr
->nr_raw_registers
);
811 buf
= alloca (regcache
->descr
->sizeof_register
[regnum
]);
812 store_unsigned_integer (buf
, regcache
->descr
->sizeof_register
[regnum
], val
);
813 regcache_raw_write (regcache
, regnum
, buf
);
817 deprecated_read_register_gen (int regnum
, char *buf
)
819 gdb_assert (current_regcache
!= NULL
);
820 gdb_assert (current_regcache
->descr
->gdbarch
== current_gdbarch
);
821 if (current_regcache
->descr
->legacy_p
)
823 legacy_read_register_gen (regnum
, buf
);
826 regcache_cooked_read (current_regcache
, regnum
, buf
);
830 regcache_cooked_read (struct regcache
*regcache
, int regnum
, void *buf
)
832 gdb_assert (regnum
>= 0);
833 gdb_assert (regnum
< regcache
->descr
->nr_cooked_registers
);
834 if (regnum
< regcache
->descr
->nr_raw_registers
)
835 regcache_raw_read (regcache
, regnum
, buf
);
836 else if (regcache
->readonly_p
837 && regnum
< regcache
->descr
->nr_cooked_registers
838 && regcache
->register_valid_p
[regnum
])
839 /* Read-only register cache, perhaphs the cooked value was cached? */
840 memcpy (buf
, register_buffer (regcache
, regnum
),
841 regcache
->descr
->sizeof_register
[regnum
]);
843 gdbarch_pseudo_register_read (regcache
->descr
->gdbarch
, regcache
,
848 regcache_cooked_read_signed (struct regcache
*regcache
, int regnum
,
852 gdb_assert (regcache
!= NULL
);
853 gdb_assert (regnum
>= 0 && regnum
< regcache
->descr
->nr_cooked_registers
);
854 buf
= alloca (regcache
->descr
->sizeof_register
[regnum
]);
855 regcache_cooked_read (regcache
, regnum
, buf
);
856 (*val
) = extract_signed_integer (buf
,
857 regcache
->descr
->sizeof_register
[regnum
]);
861 regcache_cooked_read_unsigned (struct regcache
*regcache
, int regnum
,
865 gdb_assert (regcache
!= NULL
);
866 gdb_assert (regnum
>= 0 && regnum
< regcache
->descr
->nr_cooked_registers
);
867 buf
= alloca (regcache
->descr
->sizeof_register
[regnum
]);
868 regcache_cooked_read (regcache
, regnum
, buf
);
869 (*val
) = extract_unsigned_integer (buf
,
870 regcache
->descr
->sizeof_register
[regnum
]);
874 regcache_cooked_write_signed (struct regcache
*regcache
, int regnum
,
878 gdb_assert (regcache
!= NULL
);
879 gdb_assert (regnum
>=0 && regnum
< regcache
->descr
->nr_cooked_registers
);
880 buf
= alloca (regcache
->descr
->sizeof_register
[regnum
]);
881 store_signed_integer (buf
, regcache
->descr
->sizeof_register
[regnum
], val
);
882 regcache_cooked_write (regcache
, regnum
, buf
);
886 regcache_cooked_write_unsigned (struct regcache
*regcache
, int regnum
,
890 gdb_assert (regcache
!= NULL
);
891 gdb_assert (regnum
>=0 && regnum
< regcache
->descr
->nr_cooked_registers
);
892 buf
= alloca (regcache
->descr
->sizeof_register
[regnum
]);
893 store_unsigned_integer (buf
, regcache
->descr
->sizeof_register
[regnum
], val
);
894 regcache_cooked_write (regcache
, regnum
, buf
);
897 /* Write register REGNUM at MYADDR to the target. MYADDR points at
898 REGISTER_RAW_BYTES(REGNUM), which must be in target byte-order. */
901 legacy_write_register_gen (int regnum
, const void *myaddr
)
904 gdb_assert (regnum
>= 0 && regnum
< (NUM_REGS
+ NUM_PSEUDO_REGS
));
906 /* On the sparc, writing %g0 is a no-op, so we don't even want to
907 change the registers array if something writes to this register. */
908 if (CANNOT_STORE_REGISTER (regnum
))
911 if (! ptid_equal (registers_ptid
, inferior_ptid
))
913 registers_changed ();
914 registers_ptid
= inferior_ptid
;
917 size
= REGISTER_RAW_SIZE (regnum
);
919 if (real_register (regnum
))
921 /* If we have a valid copy of the register, and new value == old
922 value, then don't bother doing the actual store. */
923 if (register_cached (regnum
)
924 && (memcmp (register_buffer (current_regcache
, regnum
), myaddr
, size
)
928 target_prepare_to_store ();
931 memcpy (register_buffer (current_regcache
, regnum
), myaddr
, size
);
933 set_register_cached (regnum
, 1);
934 target_store_registers (regnum
);
938 regcache_raw_write (struct regcache
*regcache
, int regnum
, const void *buf
)
940 gdb_assert (regcache
!= NULL
&& buf
!= NULL
);
941 gdb_assert (regnum
>= 0 && regnum
< regcache
->descr
->nr_raw_registers
);
942 gdb_assert (!regcache
->readonly_p
);
944 if (regcache
->descr
->legacy_p
)
946 /* For moment, just use underlying legacy code. Ulgh!!! This
947 silently and very indirectly updates the regcache's buffers
948 via the globals deprecated_register_valid[] and registers[]. */
949 gdb_assert (regcache
== current_regcache
);
950 legacy_write_register_gen (regnum
, buf
);
954 /* On the sparc, writing %g0 is a no-op, so we don't even want to
955 change the registers array if something writes to this register. */
956 if (CANNOT_STORE_REGISTER (regnum
))
959 /* Make certain that the correct cache is selected. */
960 gdb_assert (regcache
== current_regcache
);
961 if (! ptid_equal (registers_ptid
, inferior_ptid
))
963 registers_changed ();
964 registers_ptid
= inferior_ptid
;
967 /* If we have a valid copy of the register, and new value == old
968 value, then don't bother doing the actual store. */
969 if (regcache_valid_p (regcache
, regnum
)
970 && (memcmp (register_buffer (regcache
, regnum
), buf
,
971 regcache
->descr
->sizeof_register
[regnum
]) == 0))
974 target_prepare_to_store ();
975 memcpy (register_buffer (regcache
, regnum
), buf
,
976 regcache
->descr
->sizeof_register
[regnum
]);
977 regcache
->register_valid_p
[regnum
] = 1;
978 target_store_registers (regnum
);
982 deprecated_write_register_gen (int regnum
, char *buf
)
984 gdb_assert (current_regcache
!= NULL
);
985 gdb_assert (current_regcache
->descr
->gdbarch
== current_gdbarch
);
986 if (current_regcache
->descr
->legacy_p
)
988 legacy_write_register_gen (regnum
, buf
);
991 regcache_cooked_write (current_regcache
, regnum
, buf
);
995 regcache_cooked_write (struct regcache
*regcache
, int regnum
, const void *buf
)
997 gdb_assert (regnum
>= 0);
998 gdb_assert (regnum
< regcache
->descr
->nr_cooked_registers
);
999 if (regnum
< regcache
->descr
->nr_raw_registers
)
1000 regcache_raw_write (regcache
, regnum
, buf
);
1002 gdbarch_pseudo_register_write (regcache
->descr
->gdbarch
, regcache
,
1006 /* Copy INLEN bytes of consecutive data from memory at MYADDR
1007 into registers starting with the MYREGSTART'th byte of register data. */
1010 deprecated_write_register_bytes (int myregstart
, char *myaddr
, int inlen
)
1012 int myregend
= myregstart
+ inlen
;
1015 target_prepare_to_store ();
1017 /* Scan through the registers updating any that are covered by the
1018 range myregstart<=>myregend using write_register_gen, which does
1019 nice things like handling threads, and avoiding updates when the
1020 new and old contents are the same. */
1022 for (regnum
= 0; regnum
< NUM_REGS
+ NUM_PSEUDO_REGS
; regnum
++)
1024 int regstart
, regend
;
1026 regstart
= REGISTER_BYTE (regnum
);
1027 regend
= regstart
+ REGISTER_RAW_SIZE (regnum
);
1029 /* Is this register completely outside the range the user is writing? */
1030 if (myregend
<= regstart
|| regend
<= myregstart
)
1033 /* Is this register completely within the range the user is writing? */
1034 else if (myregstart
<= regstart
&& regend
<= myregend
)
1035 deprecated_write_register_gen (regnum
, myaddr
+ (regstart
- myregstart
));
1037 /* The register partially overlaps the range being written. */
1040 char regbuf
[MAX_REGISTER_SIZE
];
1041 /* What's the overlap between this register's bytes and
1042 those the caller wants to write? */
1043 int overlapstart
= max (regstart
, myregstart
);
1044 int overlapend
= min (regend
, myregend
);
1046 /* We may be doing a partial update of an invalid register.
1047 Update it from the target before scribbling on it. */
1048 deprecated_read_register_gen (regnum
, regbuf
);
1050 memcpy (&deprecated_registers
[overlapstart
],
1051 myaddr
+ (overlapstart
- myregstart
),
1052 overlapend
- overlapstart
);
1054 target_store_registers (regnum
);
1059 /* Perform a partial register transfer using a read, modify, write
1062 typedef void (regcache_read_ftype
) (struct regcache
*regcache
, int regnum
,
1064 typedef void (regcache_write_ftype
) (struct regcache
*regcache
, int regnum
,
1068 regcache_xfer_part (struct regcache
*regcache
, int regnum
,
1069 int offset
, int len
, void *in
, const void *out
,
1070 regcache_read_ftype
*read
, regcache_write_ftype
*write
)
1072 struct regcache_descr
*descr
= regcache
->descr
;
1073 bfd_byte reg
[MAX_REGISTER_SIZE
];
1074 gdb_assert (offset
>= 0 && offset
<= descr
->sizeof_register
[regnum
]);
1075 gdb_assert (len
>= 0 && offset
+ len
<= descr
->sizeof_register
[regnum
]);
1076 /* Something to do? */
1077 if (offset
+ len
== 0)
1079 /* Read (when needed) ... */
1082 || offset
+ len
< descr
->sizeof_register
[regnum
])
1084 gdb_assert (read
!= NULL
);
1085 read (regcache
, regnum
, reg
);
1087 /* ... modify ... */
1089 memcpy (in
, reg
+ offset
, len
);
1091 memcpy (reg
+ offset
, out
, len
);
1092 /* ... write (when needed). */
1095 gdb_assert (write
!= NULL
);
1096 write (regcache
, regnum
, reg
);
1101 regcache_raw_read_part (struct regcache
*regcache
, int regnum
,
1102 int offset
, int len
, void *buf
)
1104 struct regcache_descr
*descr
= regcache
->descr
;
1105 gdb_assert (regnum
>= 0 && regnum
< descr
->nr_raw_registers
);
1106 regcache_xfer_part (regcache
, regnum
, offset
, len
, buf
, NULL
,
1107 regcache_raw_read
, regcache_raw_write
);
1111 regcache_raw_write_part (struct regcache
*regcache
, int regnum
,
1112 int offset
, int len
, const void *buf
)
1114 struct regcache_descr
*descr
= regcache
->descr
;
1115 gdb_assert (regnum
>= 0 && regnum
< descr
->nr_raw_registers
);
1116 regcache_xfer_part (regcache
, regnum
, offset
, len
, NULL
, buf
,
1117 regcache_raw_read
, regcache_raw_write
);
1121 regcache_cooked_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_cooked_registers
);
1126 regcache_xfer_part (regcache
, regnum
, offset
, len
, buf
, NULL
,
1127 regcache_cooked_read
, regcache_cooked_write
);
1131 regcache_cooked_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_cooked_registers
);
1136 regcache_xfer_part (regcache
, regnum
, offset
, len
, NULL
, buf
,
1137 regcache_cooked_read
, regcache_cooked_write
);
1140 /* Hack to keep code that view the register buffer as raw bytes
1144 register_offset_hack (struct gdbarch
*gdbarch
, int regnum
)
1146 struct regcache_descr
*descr
= regcache_descr (gdbarch
);
1147 gdb_assert (regnum
>= 0 && regnum
< descr
->nr_cooked_registers
);
1148 return descr
->register_offset
[regnum
];
1151 /* Return the contents of register REGNUM as an unsigned integer. */
1154 read_register (int regnum
)
1156 char *buf
= alloca (REGISTER_RAW_SIZE (regnum
));
1157 deprecated_read_register_gen (regnum
, buf
);
1158 return (extract_unsigned_integer (buf
, REGISTER_RAW_SIZE (regnum
)));
1162 read_register_pid (int regnum
, ptid_t ptid
)
1168 if (ptid_equal (ptid
, inferior_ptid
))
1169 return read_register (regnum
);
1171 save_ptid
= inferior_ptid
;
1173 inferior_ptid
= ptid
;
1175 retval
= read_register (regnum
);
1177 inferior_ptid
= save_ptid
;
1182 /* Store VALUE into the raw contents of register number REGNUM. */
1185 write_register (int regnum
, LONGEST val
)
1189 size
= REGISTER_RAW_SIZE (regnum
);
1190 buf
= alloca (size
);
1191 store_signed_integer (buf
, size
, (LONGEST
) val
);
1192 deprecated_write_register_gen (regnum
, buf
);
1196 write_register_pid (int regnum
, CORE_ADDR val
, ptid_t ptid
)
1200 if (ptid_equal (ptid
, inferior_ptid
))
1202 write_register (regnum
, val
);
1206 save_ptid
= inferior_ptid
;
1208 inferior_ptid
= ptid
;
1210 write_register (regnum
, val
);
1212 inferior_ptid
= save_ptid
;
1215 /* SUPPLY_REGISTER()
1217 Record that register REGNUM contains VAL. This is used when the
1218 value is obtained from the inferior or core dump, so there is no
1219 need to store the value there.
1221 If VAL is a NULL pointer, then it's probably an unsupported register.
1222 We just set its value to all zeros. We might want to record this
1223 fact, and report it to the users of read_register and friends. */
1226 supply_register (int regnum
, const void *val
)
1229 if (! ptid_equal (registers_ptid
, inferior_ptid
))
1231 registers_changed ();
1232 registers_ptid
= inferior_ptid
;
1236 set_register_cached (regnum
, 1);
1238 memcpy (register_buffer (current_regcache
, regnum
), val
,
1239 REGISTER_RAW_SIZE (regnum
));
1241 memset (register_buffer (current_regcache
, regnum
), '\000',
1242 REGISTER_RAW_SIZE (regnum
));
1244 /* On some architectures, e.g. HPPA, there are a few stray bits in
1245 some registers, that the rest of the code would like to ignore. */
1247 /* NOTE: cagney/2001-03-16: The macro CLEAN_UP_REGISTER_VALUE is
1248 going to be deprecated. Instead architectures will leave the raw
1249 register value as is and instead clean things up as they pass
1250 through the method gdbarch_pseudo_register_read() clean up the
1253 #ifdef DEPRECATED_CLEAN_UP_REGISTER_VALUE
1254 DEPRECATED_CLEAN_UP_REGISTER_VALUE \
1255 (regnum
, register_buffer (current_regcache
, regnum
));
1260 regcache_collect (int regnum
, void *buf
)
1262 memcpy (buf
, register_buffer (current_regcache
, regnum
),
1263 REGISTER_RAW_SIZE (regnum
));
1267 /* read_pc, write_pc, read_sp, deprecated_read_fp, etc. Special
1268 handling for registers PC, SP, and FP. */
1270 /* NOTE: cagney/2001-02-18: The functions read_pc_pid(), read_pc(),
1271 read_sp(), and deprecated_read_fp(), will eventually be replaced by
1272 per-frame methods. Instead of relying on the global INFERIOR_PTID,
1273 they will use the contextual information provided by the FRAME.
1274 These functions do not belong in the register cache. */
1276 /* NOTE: cagney/2003-06-07: The functions generic_target_write_pc(),
1277 write_pc_pid(), write_pc(), and deprecated_read_fp(), all need to
1278 be replaced by something that does not rely on global state. But
1282 read_pc_pid (ptid_t ptid
)
1284 ptid_t saved_inferior_ptid
;
1287 /* In case ptid != inferior_ptid. */
1288 saved_inferior_ptid
= inferior_ptid
;
1289 inferior_ptid
= ptid
;
1291 if (TARGET_READ_PC_P ())
1292 pc_val
= TARGET_READ_PC (ptid
);
1293 /* Else use per-frame method on get_current_frame. */
1294 else if (PC_REGNUM
>= 0)
1296 CORE_ADDR raw_val
= read_register_pid (PC_REGNUM
, ptid
);
1297 CORE_ADDR pc_val
= ADDR_BITS_REMOVE (raw_val
);
1301 internal_error (__FILE__
, __LINE__
, "read_pc_pid: Unable to find PC");
1303 inferior_ptid
= saved_inferior_ptid
;
1310 return read_pc_pid (inferior_ptid
);
1314 generic_target_write_pc (CORE_ADDR pc
, ptid_t ptid
)
1318 write_register_pid (PC_REGNUM
, pc
, ptid
);
1319 if (NPC_REGNUM
>= 0)
1320 write_register_pid (NPC_REGNUM
, pc
+ 4, ptid
);
1322 internal_error (__FILE__
, __LINE__
,
1323 "generic_target_write_pc");
1328 write_pc_pid (CORE_ADDR pc
, ptid_t ptid
)
1330 ptid_t saved_inferior_ptid
;
1332 /* In case ptid != inferior_ptid. */
1333 saved_inferior_ptid
= inferior_ptid
;
1334 inferior_ptid
= ptid
;
1336 TARGET_WRITE_PC (pc
, ptid
);
1338 inferior_ptid
= saved_inferior_ptid
;
1342 write_pc (CORE_ADDR pc
)
1344 write_pc_pid (pc
, inferior_ptid
);
1347 /* Cope with strage ways of getting to the stack and frame pointers */
1352 if (TARGET_READ_SP_P ())
1353 return TARGET_READ_SP ();
1354 /* Else return SP from get_current_frame. */
1355 else if (SP_REGNUM
>= 0)
1356 return read_register (SP_REGNUM
);
1357 internal_error (__FILE__
, __LINE__
, "read_sp: Unable to find SP");
1361 deprecated_write_sp (CORE_ADDR val
)
1363 gdb_assert (SP_REGNUM
>= 0);
1364 write_register (SP_REGNUM
, val
);
1368 deprecated_read_fp (void)
1370 if (DEPRECATED_TARGET_READ_FP_P ())
1371 return DEPRECATED_TARGET_READ_FP ();
1372 else if (DEPRECATED_FP_REGNUM
>= 0)
1373 return read_register (DEPRECATED_FP_REGNUM
);
1375 internal_error (__FILE__
, __LINE__
, "deprecated_read_fp");
1380 reg_flush_command (char *command
, int from_tty
)
1382 /* Force-flush the register cache. */
1383 registers_changed ();
1385 printf_filtered ("Register cache flushed.\n");
1389 build_regcache (void)
1391 current_regcache
= regcache_xmalloc (current_gdbarch
);
1392 current_regcache
->readonly_p
= 0;
1393 deprecated_registers
= deprecated_grub_regcache_for_registers (current_regcache
);
1394 deprecated_register_valid
= current_regcache
->register_valid_p
;
1398 dump_endian_bytes (struct ui_file
*file
, enum bfd_endian endian
,
1399 const unsigned char *buf
, long len
)
1404 case BFD_ENDIAN_BIG
:
1405 for (i
= 0; i
< len
; i
++)
1406 fprintf_unfiltered (file
, "%02x", buf
[i
]);
1408 case BFD_ENDIAN_LITTLE
:
1409 for (i
= len
- 1; i
>= 0; i
--)
1410 fprintf_unfiltered (file
, "%02x", buf
[i
]);
1413 internal_error (__FILE__
, __LINE__
, "Bad switch");
1417 enum regcache_dump_what
1419 regcache_dump_none
, regcache_dump_raw
, regcache_dump_cooked
, regcache_dump_groups
1423 regcache_dump (struct regcache
*regcache
, struct ui_file
*file
,
1424 enum regcache_dump_what what_to_dump
)
1426 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
1427 struct gdbarch
*gdbarch
= regcache
->descr
->gdbarch
;
1428 struct reggroup
*const *groups
= reggroups (gdbarch
);
1430 int footnote_nr
= 0;
1431 int footnote_register_size
= 0;
1432 int footnote_register_offset
= 0;
1433 int footnote_register_type_name_null
= 0;
1434 long register_offset
= 0;
1435 unsigned char buf
[MAX_REGISTER_SIZE
];
1438 fprintf_unfiltered (file
, "legacy_p %d\n", regcache
->descr
->legacy_p
);
1439 fprintf_unfiltered (file
, "nr_raw_registers %d\n",
1440 regcache
->descr
->nr_raw_registers
);
1441 fprintf_unfiltered (file
, "nr_cooked_registers %d\n",
1442 regcache
->descr
->nr_cooked_registers
);
1443 fprintf_unfiltered (file
, "sizeof_raw_registers %ld\n",
1444 regcache
->descr
->sizeof_raw_registers
);
1445 fprintf_unfiltered (file
, "sizeof_raw_register_valid_p %ld\n",
1446 regcache
->descr
->sizeof_raw_register_valid_p
);
1447 fprintf_unfiltered (file
, "NUM_REGS %d\n", NUM_REGS
);
1448 fprintf_unfiltered (file
, "NUM_PSEUDO_REGS %d\n", NUM_PSEUDO_REGS
);
1451 gdb_assert (regcache
->descr
->nr_cooked_registers
1452 == (NUM_REGS
+ NUM_PSEUDO_REGS
));
1454 for (regnum
= -1; regnum
< regcache
->descr
->nr_cooked_registers
; regnum
++)
1458 fprintf_unfiltered (file
, " %-10s", "Name");
1461 const char *p
= REGISTER_NAME (regnum
);
1464 else if (p
[0] == '\0')
1466 fprintf_unfiltered (file
, " %-10s", p
);
1471 fprintf_unfiltered (file
, " %4s", "Nr");
1473 fprintf_unfiltered (file
, " %4d", regnum
);
1475 /* Relative number. */
1477 fprintf_unfiltered (file
, " %4s", "Rel");
1478 else if (regnum
< NUM_REGS
)
1479 fprintf_unfiltered (file
, " %4d", regnum
);
1481 fprintf_unfiltered (file
, " %4d", (regnum
- NUM_REGS
));
1485 fprintf_unfiltered (file
, " %6s ", "Offset");
1488 fprintf_unfiltered (file
, " %6ld",
1489 regcache
->descr
->register_offset
[regnum
]);
1490 if (register_offset
!= regcache
->descr
->register_offset
[regnum
]
1491 || register_offset
!= REGISTER_BYTE (regnum
)
1493 && (regcache
->descr
->register_offset
[regnum
]
1494 != (regcache
->descr
->register_offset
[regnum
- 1]
1495 + regcache
->descr
->sizeof_register
[regnum
- 1])))
1498 if (!footnote_register_offset
)
1499 footnote_register_offset
= ++footnote_nr
;
1500 fprintf_unfiltered (file
, "*%d", footnote_register_offset
);
1503 fprintf_unfiltered (file
, " ");
1504 register_offset
= (regcache
->descr
->register_offset
[regnum
]
1505 + regcache
->descr
->sizeof_register
[regnum
]);
1510 fprintf_unfiltered (file
, " %5s ", "Size");
1513 fprintf_unfiltered (file
, " %5ld",
1514 regcache
->descr
->sizeof_register
[regnum
]);
1515 if ((regcache
->descr
->sizeof_register
[regnum
]
1516 != REGISTER_RAW_SIZE (regnum
))
1517 || (regcache
->descr
->sizeof_register
[regnum
]
1518 != REGISTER_VIRTUAL_SIZE (regnum
))
1519 || (regcache
->descr
->sizeof_register
[regnum
]
1520 != TYPE_LENGTH (register_type (regcache
->descr
->gdbarch
,
1524 if (!footnote_register_size
)
1525 footnote_register_size
= ++footnote_nr
;
1526 fprintf_unfiltered (file
, "*%d", footnote_register_size
);
1529 fprintf_unfiltered (file
, " ");
1539 static const char blt
[] = "builtin_type";
1540 t
= TYPE_NAME (register_type (regcache
->descr
->gdbarch
, regnum
));
1544 if (!footnote_register_type_name_null
)
1545 footnote_register_type_name_null
= ++footnote_nr
;
1546 xasprintf (&n
, "*%d", footnote_register_type_name_null
);
1547 make_cleanup (xfree
, n
);
1550 /* Chop a leading builtin_type. */
1551 if (strncmp (t
, blt
, strlen (blt
)) == 0)
1554 fprintf_unfiltered (file
, " %-15s", t
);
1557 /* Leading space always present. */
1558 fprintf_unfiltered (file
, " ");
1561 if (what_to_dump
== regcache_dump_raw
)
1564 fprintf_unfiltered (file
, "Raw value");
1565 else if (regnum
>= regcache
->descr
->nr_raw_registers
)
1566 fprintf_unfiltered (file
, "<cooked>");
1567 else if (!regcache_valid_p (regcache
, regnum
))
1568 fprintf_unfiltered (file
, "<invalid>");
1571 regcache_raw_read (regcache
, regnum
, buf
);
1572 fprintf_unfiltered (file
, "0x");
1573 dump_endian_bytes (file
, TARGET_BYTE_ORDER
, buf
,
1574 REGISTER_RAW_SIZE (regnum
));
1578 /* Value, cooked. */
1579 if (what_to_dump
== regcache_dump_cooked
)
1582 fprintf_unfiltered (file
, "Cooked value");
1585 regcache_cooked_read (regcache
, regnum
, buf
);
1586 fprintf_unfiltered (file
, "0x");
1587 dump_endian_bytes (file
, TARGET_BYTE_ORDER
, buf
,
1588 REGISTER_VIRTUAL_SIZE (regnum
));
1592 /* Group members. */
1593 if (what_to_dump
== regcache_dump_groups
)
1596 fprintf_unfiltered (file
, "Groups");
1600 const char *sep
= "";
1601 for (i
= 0; groups
[i
] != NULL
; i
++)
1603 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, groups
[i
]))
1605 fprintf_unfiltered (file
, "%s%s", sep
, reggroup_name (groups
[i
]));
1612 fprintf_unfiltered (file
, "\n");
1615 if (footnote_register_size
)
1616 fprintf_unfiltered (file
, "*%d: Inconsistent register sizes.\n",
1617 footnote_register_size
);
1618 if (footnote_register_offset
)
1619 fprintf_unfiltered (file
, "*%d: Inconsistent register offsets.\n",
1620 footnote_register_offset
);
1621 if (footnote_register_type_name_null
)
1622 fprintf_unfiltered (file
,
1623 "*%d: Register type's name NULL.\n",
1624 footnote_register_type_name_null
);
1625 do_cleanups (cleanups
);
1629 regcache_print (char *args
, enum regcache_dump_what what_to_dump
)
1632 regcache_dump (current_regcache
, gdb_stdout
, what_to_dump
);
1635 struct ui_file
*file
= gdb_fopen (args
, "w");
1637 perror_with_name ("maintenance print architecture");
1638 regcache_dump (current_regcache
, file
, what_to_dump
);
1639 ui_file_delete (file
);
1644 maintenance_print_registers (char *args
, int from_tty
)
1646 regcache_print (args
, regcache_dump_none
);
1650 maintenance_print_raw_registers (char *args
, int from_tty
)
1652 regcache_print (args
, regcache_dump_raw
);
1656 maintenance_print_cooked_registers (char *args
, int from_tty
)
1658 regcache_print (args
, regcache_dump_cooked
);
1662 maintenance_print_register_groups (char *args
, int from_tty
)
1664 regcache_print (args
, regcache_dump_groups
);
1667 extern initialize_file_ftype _initialize_regcache
; /* -Wmissing-prototype */
1670 _initialize_regcache (void)
1672 regcache_descr_handle
= register_gdbarch_data (init_regcache_descr
,
1673 xfree_regcache_descr
);
1674 REGISTER_GDBARCH_SWAP (current_regcache
);
1675 register_gdbarch_swap (&deprecated_registers
, sizeof (deprecated_registers
), NULL
);
1676 register_gdbarch_swap (&deprecated_register_valid
, sizeof (deprecated_register_valid
), NULL
);
1677 register_gdbarch_swap (NULL
, 0, build_regcache
);
1679 add_com ("flushregs", class_maintenance
, reg_flush_command
,
1680 "Force gdb to flush its register cache (maintainer command)");
1682 /* Initialize the thread/process associated with the current set of
1683 registers. For now, -1 is special, and means `no current process'. */
1684 registers_ptid
= pid_to_ptid (-1);
1686 add_cmd ("registers", class_maintenance
,
1687 maintenance_print_registers
,
1688 "Print the internal register configuration.\
1689 Takes an optional file parameter.",
1690 &maintenanceprintlist
);
1691 add_cmd ("raw-registers", class_maintenance
,
1692 maintenance_print_raw_registers
,
1693 "Print the internal register configuration including raw values.\
1694 Takes an optional file parameter.",
1695 &maintenanceprintlist
);
1696 add_cmd ("cooked-registers", class_maintenance
,
1697 maintenance_print_cooked_registers
,
1698 "Print the internal register configuration including cooked values.\
1699 Takes an optional file parameter.",
1700 &maintenanceprintlist
);
1701 add_cmd ("register-groups", class_maintenance
,
1702 maintenance_print_register_groups
,
1703 "Print the internal register configuration including each register's group.\
1704 Takes an optional file parameter.",
1705 &maintenanceprintlist
);