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
;
70 /* Offset and size (in 8 bit bytes), of reach register in the
71 register cache. All registers (including those in the range
72 [NR_RAW_REGISTERS .. NR_COOKED_REGISTERS) are given an offset.
73 Assigning all registers an offset makes it possible to keep
74 legacy code, such as that found in read_register_bytes() and
75 write_register_bytes() working. */
76 long *register_offset
;
77 long *sizeof_register
;
79 /* Useful constant. Largest of all the registers. */
80 long max_register_size
;
82 /* Cached table containing the type of each register. */
83 struct type
**register_type
;
87 init_legacy_regcache_descr (struct gdbarch
*gdbarch
,
88 struct regcache_descr
*descr
)
91 /* FIXME: cagney/2002-05-11: gdbarch_data() should take that
92 ``gdbarch'' as a parameter. */
93 gdb_assert (gdbarch
!= NULL
);
95 /* FIXME: cagney/2002-05-11: Shouldn't be including pseudo-registers
96 in the register buffer. Unfortunatly some architectures do. */
97 descr
->nr_raw_registers
= descr
->nr_cooked_registers
;
98 descr
->sizeof_raw_register_valid_p
= descr
->nr_cooked_registers
;
100 /* FIXME: cagney/2002-05-11: Instead of using REGISTER_BYTE() this
101 code should compute the offets et.al. at runtime. This currently
102 isn't possible because some targets overlap register locations -
103 see the mess in read_register_bytes() and write_register_bytes()
105 descr
->sizeof_register
= XCALLOC (descr
->nr_cooked_registers
, long);
106 descr
->register_offset
= XCALLOC (descr
->nr_cooked_registers
, long);
107 descr
->max_register_size
= 0;
108 for (i
= 0; i
< descr
->nr_cooked_registers
; i
++)
110 descr
->register_offset
[i
] = REGISTER_BYTE (i
);
111 descr
->sizeof_register
[i
] = REGISTER_RAW_SIZE (i
);
112 if (descr
->max_register_size
< REGISTER_RAW_SIZE (i
))
113 descr
->max_register_size
= REGISTER_RAW_SIZE (i
);
114 if (descr
->max_register_size
< REGISTER_VIRTUAL_SIZE (i
))
115 descr
->max_register_size
= REGISTER_VIRTUAL_SIZE (i
);
118 /* Come up with the real size of the registers buffer. */
119 descr
->sizeof_raw_registers
= REGISTER_BYTES
; /* OK use. */
120 for (i
= 0; i
< descr
->nr_cooked_registers
; i
++)
123 /* Keep extending the buffer so that there is always enough
124 space for all registers. The comparison is necessary since
125 legacy code is free to put registers in random places in the
126 buffer separated by holes. Once REGISTER_BYTE() is killed
127 this can be greatly simplified. */
128 /* FIXME: cagney/2001-12-04: This code shouldn't need to use
129 REGISTER_BYTE(). Unfortunatly, legacy code likes to lay the
130 buffer out so that certain registers just happen to overlap.
131 Ulgh! New targets use gdbarch's register read/write and
132 entirely avoid this uglyness. */
133 regend
= descr
->register_offset
[i
] + descr
->sizeof_register
[i
];
134 if (descr
->sizeof_raw_registers
< regend
)
135 descr
->sizeof_raw_registers
= regend
;
140 init_regcache_descr (struct gdbarch
*gdbarch
)
143 struct regcache_descr
*descr
;
144 gdb_assert (gdbarch
!= NULL
);
146 /* Create an initial, zero filled, table. */
147 descr
= XCALLOC (1, struct regcache_descr
);
148 descr
->gdbarch
= gdbarch
;
150 /* Total size of the register space. The raw registers are mapped
151 directly onto the raw register cache while the pseudo's are
152 either mapped onto raw-registers or memory. */
153 descr
->nr_cooked_registers
= NUM_REGS
+ NUM_PSEUDO_REGS
;
155 /* Fill in a table of register types. */
156 descr
->register_type
= XCALLOC (descr
->nr_cooked_registers
,
158 for (i
= 0; i
< descr
->nr_cooked_registers
; i
++)
160 descr
->register_type
[i
] = REGISTER_VIRTUAL_TYPE (i
);
163 /* If an old style architecture, fill in the remainder of the
164 register cache descriptor using the register macros. */
165 if (!gdbarch_pseudo_register_read_p (gdbarch
)
166 && !gdbarch_pseudo_register_write_p (gdbarch
))
169 init_legacy_regcache_descr (gdbarch
, descr
);
173 /* Construct a strictly RAW register cache. Don't allow pseudo's
174 into the register cache. */
175 descr
->nr_raw_registers
= NUM_REGS
;
177 /* FIXME: cagney/2002-08-13: Overallocate the register_valid_p
178 array. This pretects GDB from erant code that accesses elements
179 of the global register_valid_p[] array in the range [NUM_REGS
180 .. NUM_REGS + NUM_PSEUDO_REGS). */
181 descr
->sizeof_raw_register_valid_p
= NUM_REGS
+ NUM_PSEUDO_REGS
;
183 /* Lay out the register cache. The pseud-registers are included in
184 the layout even though their value isn't stored in the register
185 cache. Some code, via read_register_bytes() access a register
186 using an offset/length rather than a register number.
188 NOTE: cagney/2002-05-22: Only register_type() is used when
189 constructing the register cache. It is assumed that the
190 register's raw size, virtual size and type length are all the
195 descr
->sizeof_register
= XCALLOC (descr
->nr_cooked_registers
, long);
196 descr
->register_offset
= XCALLOC (descr
->nr_cooked_registers
, long);
197 descr
->max_register_size
= 0;
198 for (i
= 0; i
< descr
->nr_cooked_registers
; i
++)
200 descr
->sizeof_register
[i
] = TYPE_LENGTH (descr
->register_type
[i
]);
201 descr
->register_offset
[i
] = offset
;
202 offset
+= descr
->sizeof_register
[i
];
203 if (descr
->max_register_size
< descr
->sizeof_register
[i
])
204 descr
->max_register_size
= descr
->sizeof_register
[i
];
206 /* Set the real size of the register cache buffer. */
207 /* FIXME: cagney/2002-05-22: Should only need to allocate space
208 for the raw registers. Unfortunatly some code still accesses
209 the register array directly using the global registers[].
210 Until that code has been purged, play safe and over allocating
211 the register buffer. Ulgh! */
212 descr
->sizeof_raw_registers
= offset
;
213 /* = descr->register_offset[descr->nr_raw_registers]; */
217 /* Sanity check. Confirm that the assumptions about gdbarch are
218 true. The REGCACHE_DESCR_HANDLE is set before doing the checks
219 so that targets using the generic methods supplied by regcache
220 don't go into infinite recursion trying to, again, create the
222 set_gdbarch_data (gdbarch
, regcache_descr_handle
, descr
);
223 for (i
= 0; i
< descr
->nr_cooked_registers
; i
++)
225 gdb_assert (descr
->sizeof_register
[i
] == REGISTER_RAW_SIZE (i
));
226 gdb_assert (descr
->sizeof_register
[i
] == REGISTER_VIRTUAL_SIZE (i
));
227 gdb_assert (descr
->register_offset
[i
] == REGISTER_BYTE (i
));
229 /* gdb_assert (descr->sizeof_raw_registers == REGISTER_BYTES (i)); */
235 static struct regcache_descr
*
236 regcache_descr (struct gdbarch
*gdbarch
)
238 return gdbarch_data (gdbarch
, regcache_descr_handle
);
242 xfree_regcache_descr (struct gdbarch
*gdbarch
, void *ptr
)
244 struct regcache_descr
*descr
= ptr
;
247 xfree (descr
->register_offset
);
248 xfree (descr
->sizeof_register
);
249 descr
->register_offset
= NULL
;
250 descr
->sizeof_register
= NULL
;
254 /* Utility functions returning useful register attributes stored in
255 the regcache descr. */
258 register_type (struct gdbarch
*gdbarch
, int regnum
)
260 struct regcache_descr
*descr
= regcache_descr (gdbarch
);
261 gdb_assert (regnum
>= 0 && regnum
< descr
->nr_cooked_registers
);
262 return descr
->register_type
[regnum
];
265 /* Utility functions returning useful register attributes stored in
266 the regcache descr. */
269 max_register_size (struct gdbarch
*gdbarch
)
271 struct regcache_descr
*descr
= regcache_descr (gdbarch
);
272 return descr
->max_register_size
;
275 /* The register cache for storing raw register values. */
279 struct regcache_descr
*descr
;
281 char *raw_register_valid_p
;
282 /* If a value isn't in the cache should the corresponding target be
283 queried for a value. */
288 regcache_xmalloc (struct gdbarch
*gdbarch
)
290 struct regcache_descr
*descr
;
291 struct regcache
*regcache
;
292 gdb_assert (gdbarch
!= NULL
);
293 descr
= regcache_descr (gdbarch
);
294 regcache
= XMALLOC (struct regcache
);
295 regcache
->descr
= descr
;
296 regcache
->raw_registers
297 = XCALLOC (descr
->sizeof_raw_registers
, char);
298 regcache
->raw_register_valid_p
299 = XCALLOC (descr
->sizeof_raw_register_valid_p
, char);
300 regcache
->passthrough_p
= 0;
305 regcache_xfree (struct regcache
*regcache
)
307 if (regcache
== NULL
)
309 xfree (regcache
->raw_registers
);
310 xfree (regcache
->raw_register_valid_p
);
315 do_regcache_xfree (void *data
)
317 regcache_xfree (data
);
321 make_cleanup_regcache_xfree (struct regcache
*regcache
)
323 return make_cleanup (do_regcache_xfree
, regcache
);
327 regcache_cpy (struct regcache
*dst
, struct regcache
*src
)
331 gdb_assert (src
!= NULL
&& dst
!= NULL
);
332 gdb_assert (src
->descr
->gdbarch
== dst
->descr
->gdbarch
);
333 gdb_assert (src
!= dst
);
334 /* FIXME: cagney/2002-05-17: To say this bit is bad is being polite.
335 It keeps the existing code working where things rely on going
336 through to the register cache. */
337 if (src
== current_regcache
&& src
->descr
->legacy_p
)
339 /* ULGH!!!! Old way. Use REGISTER bytes and let code below
341 read_register_bytes (0, dst
->raw_registers
, REGISTER_BYTES
);
344 /* FIXME: cagney/2002-05-17: To say this bit is bad is being polite.
345 It keeps the existing code working where things rely on going
346 through to the register cache. */
347 if (dst
== current_regcache
&& dst
->descr
->legacy_p
)
349 /* ULGH!!!! Old way. Use REGISTER bytes and let code below
351 write_register_bytes (0, src
->raw_registers
, REGISTER_BYTES
);
354 buf
= alloca (src
->descr
->max_register_size
);
355 for (i
= 0; i
< src
->descr
->nr_raw_registers
; i
++)
357 /* Should we worry about the valid bit here? */
358 regcache_raw_read (src
, i
, buf
);
359 regcache_raw_write (dst
, i
, buf
);
364 regcache_cpy_no_passthrough (struct regcache
*dst
, struct regcache
*src
)
367 gdb_assert (src
!= NULL
&& dst
!= NULL
);
368 gdb_assert (src
->descr
->gdbarch
== dst
->descr
->gdbarch
);
369 /* NOTE: cagney/2002-05-17: Don't let the caller do a no-passthrough
370 move of data into the current_regcache(). Doing this would be
371 silly - it would mean that valid_p would be completly invalid. */
372 gdb_assert (dst
!= current_regcache
);
373 memcpy (dst
->raw_registers
, src
->raw_registers
,
374 dst
->descr
->sizeof_raw_registers
);
375 memcpy (dst
->raw_register_valid_p
, src
->raw_register_valid_p
,
376 dst
->descr
->sizeof_raw_register_valid_p
);
380 regcache_dup (struct regcache
*src
)
382 struct regcache
*newbuf
;
383 gdb_assert (current_regcache
!= NULL
);
384 newbuf
= regcache_xmalloc (src
->descr
->gdbarch
);
385 regcache_cpy (newbuf
, src
);
390 regcache_dup_no_passthrough (struct regcache
*src
)
392 struct regcache
*newbuf
;
393 gdb_assert (current_regcache
!= NULL
);
394 newbuf
= regcache_xmalloc (src
->descr
->gdbarch
);
395 regcache_cpy_no_passthrough (newbuf
, src
);
400 regcache_valid_p (struct regcache
*regcache
, int regnum
)
402 gdb_assert (regcache
!= NULL
);
403 gdb_assert (regnum
>= 0 && regnum
< regcache
->descr
->nr_raw_registers
);
404 return regcache
->raw_register_valid_p
[regnum
];
408 deprecated_grub_regcache_for_registers (struct regcache
*regcache
)
410 return regcache
->raw_registers
;
414 deprecated_grub_regcache_for_register_valid (struct regcache
*regcache
)
416 return regcache
->raw_register_valid_p
;
419 /* Global structure containing the current regcache. */
420 /* FIXME: cagney/2002-05-11: The two global arrays registers[] and
421 deprecated_register_valid[] currently point into this structure. */
422 struct regcache
*current_regcache
;
424 /* NOTE: this is a write-through cache. There is no "dirty" bit for
425 recording if the register values have been changed (eg. by the
426 user). Therefore all registers must be written back to the
427 target when appropriate. */
429 /* REGISTERS contains the cached register values (in target byte order). */
433 /* DEPRECATED_REGISTER_VALID is 0 if the register needs to be fetched,
434 1 if it has been fetched, and
435 -1 if the register value was not available.
437 "Not available" indicates that the target is not not able to supply
438 the register at this state. The register may become available at a
439 later time (after the next resume). This often occures when GDB is
440 manipulating a target that contains only a snapshot of the entire
441 system being debugged - some of the registers in such a system may
442 not have been saved. */
444 signed char *deprecated_register_valid
;
446 /* The thread/process associated with the current set of registers. */
448 static ptid_t registers_ptid
;
456 Returns 0 if the value is not in the cache (needs fetch).
457 >0 if the value is in the cache.
458 <0 if the value is permanently unavailable (don't ask again). */
461 register_cached (int regnum
)
463 return deprecated_register_valid
[regnum
];
466 /* Record that REGNUM's value is cached if STATE is >0, uncached but
467 fetchable if STATE is 0, and uncached and unfetchable if STATE is <0. */
470 set_register_cached (int regnum
, int state
)
472 gdb_assert (regnum
>= 0);
473 gdb_assert (regnum
< current_regcache
->descr
->nr_raw_registers
);
474 current_regcache
->raw_register_valid_p
[regnum
] = state
;
477 /* If REGNUM >= 0, return a pointer to register REGNUM's cache buffer area,
478 else return a pointer to the start of the cache buffer. */
481 register_buffer (struct regcache
*regcache
, int regnum
)
483 return regcache
->raw_registers
+ regcache
->descr
->register_offset
[regnum
];
486 /* Return whether register REGNUM is a real register. */
489 real_register (int regnum
)
491 return regnum
>= 0 && regnum
< NUM_REGS
;
494 /* Low level examining and depositing of registers.
496 The caller is responsible for making sure that the inferior is
497 stopped before calling the fetching routines, or it will get
498 garbage. (a change from GDB version 3, in which the caller got the
499 value from the last stop). */
501 /* REGISTERS_CHANGED ()
503 Indicate that registers may have changed, so invalidate the cache. */
506 registers_changed (void)
510 registers_ptid
= pid_to_ptid (-1);
512 /* Force cleanup of any alloca areas if using C alloca instead of
513 a builtin alloca. This particular call is used to clean up
514 areas allocated by low level target code which may build up
515 during lengthy interactions between gdb and the target before
516 gdb gives control to the user (ie watchpoints). */
519 for (i
= 0; i
< current_regcache
->descr
->nr_raw_registers
; i
++)
520 set_register_cached (i
, 0);
522 if (registers_changed_hook
)
523 registers_changed_hook ();
526 /* DEPRECATED_REGISTERS_FETCHED ()
528 Indicate that all registers have been fetched, so mark them all valid. */
530 /* NOTE: cagney/2001-12-04: This function does not set valid on the
531 pseudo-register range since pseudo registers are always supplied
532 using supply_register(). */
533 /* FIXME: cagney/2001-12-04: This function is DEPRECATED. The target
534 code was blatting the registers[] array and then calling this.
535 Since targets should only be using supply_register() the need for
536 this function/hack is eliminated. */
539 deprecated_registers_fetched (void)
543 for (i
= 0; i
< NUM_REGS
; i
++)
544 set_register_cached (i
, 1);
545 /* Do not assume that the pseudo-regs have also been fetched.
546 Fetching all real regs NEVER accounts for pseudo-regs. */
549 /* read_register_bytes and write_register_bytes are generally a *BAD*
550 idea. They are inefficient because they need to check for partial
551 updates, which can only be done by scanning through all of the
552 registers and seeing if the bytes that are being read/written fall
553 inside of an invalid register. [The main reason this is necessary
554 is that register sizes can vary, so a simple index won't suffice.]
555 It is far better to call read_register_gen and write_register_gen
556 if you want to get at the raw register contents, as it only takes a
557 regnum as an argument, and therefore can't do a partial register
560 Prior to the recent fixes to check for partial updates, both read
561 and write_register_bytes always checked to see if any registers
562 were stale, and then called target_fetch_registers (-1) to update
563 the whole set. This caused really slowed things down for remote
566 /* Copy INLEN bytes of consecutive data from registers
567 starting with the INREGBYTE'th byte of register data
568 into memory at MYADDR. */
571 read_register_bytes (int in_start
, char *in_buf
, int in_len
)
573 int in_end
= in_start
+ in_len
;
575 char *reg_buf
= alloca (MAX_REGISTER_RAW_SIZE
);
577 /* See if we are trying to read bytes from out-of-date registers. If so,
578 update just those registers. */
580 for (regnum
= 0; regnum
< NUM_REGS
+ NUM_PSEUDO_REGS
; regnum
++)
589 reg_start
= REGISTER_BYTE (regnum
);
590 reg_len
= REGISTER_RAW_SIZE (regnum
);
591 reg_end
= reg_start
+ reg_len
;
593 if (reg_end
<= in_start
|| in_end
<= reg_start
)
594 /* The range the user wants to read doesn't overlap with regnum. */
597 if (REGISTER_NAME (regnum
) != NULL
&& *REGISTER_NAME (regnum
) != '\0')
598 /* Force the cache to fetch the entire register. */
599 deprecated_read_register_gen (regnum
, reg_buf
);
601 /* Legacy note: even though this register is ``invalid'' we
602 still need to return something. It would appear that some
603 code relies on apparent gaps in the register array also
605 /* FIXME: cagney/2001-08-18: This is just silly. It defeats
606 the entire register read/write flow of control. Must
607 resist temptation to return 0xdeadbeef. */
608 memcpy (reg_buf
, registers
+ reg_start
, reg_len
);
610 /* Legacy note: This function, for some reason, allows a NULL
611 input buffer. If the buffer is NULL, the registers are still
612 fetched, just the final transfer is skipped. */
616 /* start = max (reg_start, in_start) */
617 if (reg_start
> in_start
)
622 /* end = min (reg_end, in_end) */
623 if (reg_end
< in_end
)
628 /* Transfer just the bytes common to both IN_BUF and REG_BUF */
629 for (byte
= start
; byte
< end
; byte
++)
631 in_buf
[byte
- in_start
] = reg_buf
[byte
- reg_start
];
636 /* Read register REGNUM into memory at MYADDR, which must be large
637 enough for REGISTER_RAW_BYTES (REGNUM). Target byte-order. If the
638 register is known to be the size of a CORE_ADDR or smaller,
639 read_register can be used instead. */
642 legacy_read_register_gen (int regnum
, char *myaddr
)
644 gdb_assert (regnum
>= 0 && regnum
< (NUM_REGS
+ NUM_PSEUDO_REGS
));
645 if (! ptid_equal (registers_ptid
, inferior_ptid
))
647 registers_changed ();
648 registers_ptid
= inferior_ptid
;
651 if (!register_cached (regnum
))
652 target_fetch_registers (regnum
);
654 memcpy (myaddr
, register_buffer (current_regcache
, regnum
),
655 REGISTER_RAW_SIZE (regnum
));
659 regcache_raw_read (struct regcache
*regcache
, int regnum
, void *buf
)
661 gdb_assert (regcache
!= NULL
&& buf
!= NULL
);
662 gdb_assert (regnum
>= 0 && regnum
< regcache
->descr
->nr_raw_registers
);
663 if (regcache
->descr
->legacy_p
664 && regcache
->passthrough_p
)
666 gdb_assert (regcache
== current_regcache
);
667 /* For moment, just use underlying legacy code. Ulgh!!! This
668 silently and very indirectly updates the regcache's regcache
669 via the global deprecated_register_valid[]. */
670 legacy_read_register_gen (regnum
, buf
);
673 /* Make certain that the register cache is up-to-date with respect
674 to the current thread. This switching shouldn't be necessary
675 only there is still only one target side register cache. Sigh!
676 On the bright side, at least there is a regcache object. */
677 if (regcache
->passthrough_p
)
679 gdb_assert (regcache
== current_regcache
);
680 if (! ptid_equal (registers_ptid
, inferior_ptid
))
682 registers_changed ();
683 registers_ptid
= inferior_ptid
;
685 if (!register_cached (regnum
))
686 target_fetch_registers (regnum
);
688 /* Copy the value directly into the register cache. */
689 memcpy (buf
, (regcache
->raw_registers
690 + regcache
->descr
->register_offset
[regnum
]),
691 regcache
->descr
->sizeof_register
[regnum
]);
695 regcache_raw_read_signed (struct regcache
*regcache
, int regnum
, LONGEST
*val
)
698 gdb_assert (regcache
!= NULL
);
699 gdb_assert (regnum
>= 0 && regnum
< regcache
->descr
->nr_raw_registers
);
700 buf
= alloca (regcache
->descr
->sizeof_register
[regnum
]);
701 regcache_raw_read (regcache
, regnum
, buf
);
702 (*val
) = extract_signed_integer (buf
,
703 regcache
->descr
->sizeof_register
[regnum
]);
707 regcache_raw_read_unsigned (struct regcache
*regcache
, int regnum
,
711 gdb_assert (regcache
!= NULL
);
712 gdb_assert (regnum
>= 0 && regnum
< regcache
->descr
->nr_raw_registers
);
713 buf
= alloca (regcache
->descr
->sizeof_register
[regnum
]);
714 regcache_raw_read (regcache
, regnum
, buf
);
715 (*val
) = extract_unsigned_integer (buf
,
716 regcache
->descr
->sizeof_register
[regnum
]);
720 regcache_raw_write_signed (struct regcache
*regcache
, int regnum
, LONGEST val
)
723 gdb_assert (regcache
!= NULL
);
724 gdb_assert (regnum
>=0 && regnum
< regcache
->descr
->nr_raw_registers
);
725 buf
= alloca (regcache
->descr
->sizeof_register
[regnum
]);
726 store_signed_integer (buf
, regcache
->descr
->sizeof_register
[regnum
], val
);
727 regcache_raw_write (regcache
, regnum
, buf
);
731 regcache_raw_write_unsigned (struct regcache
*regcache
, int regnum
,
735 gdb_assert (regcache
!= NULL
);
736 gdb_assert (regnum
>=0 && regnum
< regcache
->descr
->nr_raw_registers
);
737 buf
= alloca (regcache
->descr
->sizeof_register
[regnum
]);
738 store_unsigned_integer (buf
, regcache
->descr
->sizeof_register
[regnum
], val
);
739 regcache_raw_write (regcache
, regnum
, buf
);
743 deprecated_read_register_gen (int regnum
, char *buf
)
745 gdb_assert (current_regcache
!= NULL
);
746 gdb_assert (current_regcache
->descr
->gdbarch
== current_gdbarch
);
747 if (current_regcache
->descr
->legacy_p
)
749 legacy_read_register_gen (regnum
, buf
);
752 regcache_cooked_read (current_regcache
, regnum
, buf
);
756 regcache_cooked_read (struct regcache
*regcache
, int regnum
, void *buf
)
758 gdb_assert (regnum
>= 0);
759 gdb_assert (regnum
< regcache
->descr
->nr_cooked_registers
);
760 if (regnum
< regcache
->descr
->nr_raw_registers
)
761 regcache_raw_read (regcache
, regnum
, buf
);
763 gdbarch_pseudo_register_read (regcache
->descr
->gdbarch
, regcache
,
768 regcache_cooked_read_signed (struct regcache
*regcache
, int regnum
,
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_cooked_read (regcache
, regnum
, buf
);
776 (*val
) = extract_signed_integer (buf
,
777 regcache
->descr
->sizeof_register
[regnum
]);
781 regcache_cooked_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_cooked_read (regcache
, regnum
, buf
);
789 (*val
) = extract_unsigned_integer (buf
,
790 regcache
->descr
->sizeof_register
[regnum
]);
793 /* Write register REGNUM at MYADDR to the target. MYADDR points at
794 REGISTER_RAW_BYTES(REGNUM), which must be in target byte-order. */
797 legacy_write_register_gen (int regnum
, const void *myaddr
)
800 gdb_assert (regnum
>= 0 && regnum
< (NUM_REGS
+ NUM_PSEUDO_REGS
));
802 /* On the sparc, writing %g0 is a no-op, so we don't even want to
803 change the registers array if something writes to this register. */
804 if (CANNOT_STORE_REGISTER (regnum
))
807 if (! ptid_equal (registers_ptid
, inferior_ptid
))
809 registers_changed ();
810 registers_ptid
= inferior_ptid
;
813 size
= REGISTER_RAW_SIZE (regnum
);
815 if (real_register (regnum
))
817 /* If we have a valid copy of the register, and new value == old
818 value, then don't bother doing the actual store. */
819 if (register_cached (regnum
)
820 && (memcmp (register_buffer (current_regcache
, regnum
), myaddr
, size
)
824 target_prepare_to_store ();
827 memcpy (register_buffer (current_regcache
, regnum
), myaddr
, size
);
829 set_register_cached (regnum
, 1);
830 target_store_registers (regnum
);
834 regcache_raw_write (struct regcache
*regcache
, int regnum
, const void *buf
)
836 gdb_assert (regcache
!= NULL
&& buf
!= NULL
);
837 gdb_assert (regnum
>= 0 && regnum
< regcache
->descr
->nr_raw_registers
);
839 if (regcache
->passthrough_p
840 && regcache
->descr
->legacy_p
)
842 /* For moment, just use underlying legacy code. Ulgh!!! This
843 silently and very indirectly updates the regcache's buffers
844 via the globals deprecated_register_valid[] and registers[]. */
845 gdb_assert (regcache
== current_regcache
);
846 legacy_write_register_gen (regnum
, buf
);
850 /* On the sparc, writing %g0 is a no-op, so we don't even want to
851 change the registers array if something writes to this register. */
852 if (CANNOT_STORE_REGISTER (regnum
))
855 /* Handle the simple case first -> not write through so just store
857 if (!regcache
->passthrough_p
)
859 memcpy ((regcache
->raw_registers
860 + regcache
->descr
->register_offset
[regnum
]), buf
,
861 regcache
->descr
->sizeof_register
[regnum
]);
862 regcache
->raw_register_valid_p
[regnum
] = 1;
866 /* Make certain that the correct cache is selected. */
867 gdb_assert (regcache
== current_regcache
);
868 if (! ptid_equal (registers_ptid
, inferior_ptid
))
870 registers_changed ();
871 registers_ptid
= inferior_ptid
;
874 /* If we have a valid copy of the register, and new value == old
875 value, then don't bother doing the actual store. */
876 if (regcache_valid_p (regcache
, regnum
)
877 && (memcmp (register_buffer (regcache
, regnum
), buf
,
878 regcache
->descr
->sizeof_register
[regnum
]) == 0))
881 target_prepare_to_store ();
882 memcpy (register_buffer (regcache
, regnum
), buf
,
883 regcache
->descr
->sizeof_register
[regnum
]);
884 regcache
->raw_register_valid_p
[regnum
] = 1;
885 target_store_registers (regnum
);
889 deprecated_write_register_gen (int regnum
, char *buf
)
891 gdb_assert (current_regcache
!= NULL
);
892 gdb_assert (current_regcache
->descr
->gdbarch
== current_gdbarch
);
893 if (current_regcache
->descr
->legacy_p
)
895 legacy_write_register_gen (regnum
, buf
);
898 regcache_cooked_write (current_regcache
, regnum
, buf
);
902 regcache_cooked_write (struct regcache
*regcache
, int regnum
, const void *buf
)
904 gdb_assert (regnum
>= 0);
905 gdb_assert (regnum
< regcache
->descr
->nr_cooked_registers
);
906 if (regnum
< regcache
->descr
->nr_raw_registers
)
907 regcache_raw_write (regcache
, regnum
, buf
);
909 gdbarch_pseudo_register_write (regcache
->descr
->gdbarch
, regcache
,
913 /* Copy INLEN bytes of consecutive data from memory at MYADDR
914 into registers starting with the MYREGSTART'th byte of register data. */
917 write_register_bytes (int myregstart
, char *myaddr
, int inlen
)
919 int myregend
= myregstart
+ inlen
;
922 target_prepare_to_store ();
924 /* Scan through the registers updating any that are covered by the
925 range myregstart<=>myregend using write_register_gen, which does
926 nice things like handling threads, and avoiding updates when the
927 new and old contents are the same. */
929 for (regnum
= 0; regnum
< NUM_REGS
+ NUM_PSEUDO_REGS
; regnum
++)
931 int regstart
, regend
;
933 regstart
= REGISTER_BYTE (regnum
);
934 regend
= regstart
+ REGISTER_RAW_SIZE (regnum
);
936 /* Is this register completely outside the range the user is writing? */
937 if (myregend
<= regstart
|| regend
<= myregstart
)
940 /* Is this register completely within the range the user is writing? */
941 else if (myregstart
<= regstart
&& regend
<= myregend
)
942 deprecated_write_register_gen (regnum
, myaddr
+ (regstart
- myregstart
));
944 /* The register partially overlaps the range being written. */
947 char *regbuf
= (char*) alloca (MAX_REGISTER_RAW_SIZE
);
948 /* What's the overlap between this register's bytes and
949 those the caller wants to write? */
950 int overlapstart
= max (regstart
, myregstart
);
951 int overlapend
= min (regend
, myregend
);
953 /* We may be doing a partial update of an invalid register.
954 Update it from the target before scribbling on it. */
955 deprecated_read_register_gen (regnum
, regbuf
);
957 memcpy (registers
+ overlapstart
,
958 myaddr
+ (overlapstart
- myregstart
),
959 overlapend
- overlapstart
);
961 target_store_registers (regnum
);
966 /* Perform a partial register transfer using a read, modify, write
969 typedef void (regcache_read_ftype
) (struct regcache
*regcache
, int regnum
,
971 typedef void (regcache_write_ftype
) (struct regcache
*regcache
, int regnum
,
975 regcache_xfer_part (struct regcache
*regcache
, int regnum
,
976 int offset
, int len
, void *in
, const void *out
,
977 regcache_read_ftype
*read
, regcache_write_ftype
*write
)
979 struct regcache_descr
*descr
= regcache
->descr
;
980 bfd_byte
*reg
= alloca (descr
->max_register_size
);
981 gdb_assert (offset
>= 0 && offset
<= descr
->sizeof_register
[regnum
]);
982 gdb_assert (len
>= 0 && offset
+ len
<= descr
->sizeof_register
[regnum
]);
983 /* Something to do? */
984 if (offset
+ len
== 0)
986 /* Read (when needed) ... */
989 || offset
+ len
< descr
->sizeof_register
[regnum
])
991 gdb_assert (read
!= NULL
);
992 read (regcache
, regnum
, reg
);
996 memcpy (in
, reg
+ offset
, len
);
998 memcpy (reg
+ offset
, out
, len
);
999 /* ... write (when needed). */
1002 gdb_assert (write
!= NULL
);
1003 write (regcache
, regnum
, reg
);
1008 regcache_raw_read_part (struct regcache
*regcache
, int regnum
,
1009 int offset
, int len
, void *buf
)
1011 struct regcache_descr
*descr
= regcache
->descr
;
1012 gdb_assert (regnum
>= 0 && regnum
< descr
->nr_raw_registers
);
1013 regcache_xfer_part (regcache
, regnum
, offset
, len
, buf
, NULL
,
1014 regcache_raw_read
, regcache_raw_write
);
1018 regcache_raw_write_part (struct regcache
*regcache
, int regnum
,
1019 int offset
, int len
, const void *buf
)
1021 struct regcache_descr
*descr
= regcache
->descr
;
1022 gdb_assert (regnum
>= 0 && regnum
< descr
->nr_raw_registers
);
1023 regcache_xfer_part (regcache
, regnum
, offset
, len
, NULL
, buf
,
1024 regcache_raw_read
, regcache_raw_write
);
1028 regcache_cooked_read_part (struct regcache
*regcache
, int regnum
,
1029 int offset
, int len
, void *buf
)
1031 struct regcache_descr
*descr
= regcache
->descr
;
1032 gdb_assert (regnum
>= 0 && regnum
< descr
->nr_cooked_registers
);
1033 regcache_xfer_part (regcache
, regnum
, offset
, len
, buf
, NULL
,
1034 regcache_cooked_read
, regcache_cooked_write
);
1038 regcache_cooked_write_part (struct regcache
*regcache
, int regnum
,
1039 int offset
, int len
, const void *buf
)
1041 struct regcache_descr
*descr
= regcache
->descr
;
1042 gdb_assert (regnum
>= 0 && regnum
< descr
->nr_cooked_registers
);
1043 regcache_xfer_part (regcache
, regnum
, offset
, len
, NULL
, buf
,
1044 regcache_cooked_read
, regcache_cooked_write
);
1047 /* Hack to keep code that view the register buffer as raw bytes
1051 register_offset_hack (struct gdbarch
*gdbarch
, int regnum
)
1053 struct regcache_descr
*descr
= regcache_descr (gdbarch
);
1054 gdb_assert (regnum
>= 0 && regnum
< descr
->nr_cooked_registers
);
1055 return descr
->register_offset
[regnum
];
1058 /* Return the contents of register REGNUM as an unsigned integer. */
1061 read_register (int regnum
)
1063 char *buf
= alloca (REGISTER_RAW_SIZE (regnum
));
1064 deprecated_read_register_gen (regnum
, buf
);
1065 return (extract_unsigned_integer (buf
, REGISTER_RAW_SIZE (regnum
)));
1069 read_register_pid (int regnum
, ptid_t ptid
)
1075 if (ptid_equal (ptid
, inferior_ptid
))
1076 return read_register (regnum
);
1078 save_ptid
= inferior_ptid
;
1080 inferior_ptid
= ptid
;
1082 retval
= read_register (regnum
);
1084 inferior_ptid
= save_ptid
;
1089 /* Return the contents of register REGNUM as a signed integer. */
1092 read_signed_register (int regnum
)
1094 void *buf
= alloca (REGISTER_RAW_SIZE (regnum
));
1095 deprecated_read_register_gen (regnum
, buf
);
1096 return (extract_signed_integer (buf
, REGISTER_RAW_SIZE (regnum
)));
1100 read_signed_register_pid (int regnum
, ptid_t ptid
)
1105 if (ptid_equal (ptid
, inferior_ptid
))
1106 return read_signed_register (regnum
);
1108 save_ptid
= inferior_ptid
;
1110 inferior_ptid
= ptid
;
1112 retval
= read_signed_register (regnum
);
1114 inferior_ptid
= save_ptid
;
1119 /* Store VALUE into the raw contents of register number REGNUM. */
1122 write_register (int regnum
, LONGEST val
)
1126 size
= REGISTER_RAW_SIZE (regnum
);
1127 buf
= alloca (size
);
1128 store_signed_integer (buf
, size
, (LONGEST
) val
);
1129 deprecated_write_register_gen (regnum
, buf
);
1133 write_register_pid (int regnum
, CORE_ADDR val
, ptid_t ptid
)
1137 if (ptid_equal (ptid
, inferior_ptid
))
1139 write_register (regnum
, val
);
1143 save_ptid
= inferior_ptid
;
1145 inferior_ptid
= ptid
;
1147 write_register (regnum
, val
);
1149 inferior_ptid
= save_ptid
;
1152 /* SUPPLY_REGISTER()
1154 Record that register REGNUM contains VAL. This is used when the
1155 value is obtained from the inferior or core dump, so there is no
1156 need to store the value there.
1158 If VAL is a NULL pointer, then it's probably an unsupported register.
1159 We just set its value to all zeros. We might want to record this
1160 fact, and report it to the users of read_register and friends. */
1163 supply_register (int regnum
, const void *val
)
1166 if (! ptid_equal (registers_ptid
, inferior_ptid
))
1168 registers_changed ();
1169 registers_ptid
= inferior_ptid
;
1173 set_register_cached (regnum
, 1);
1175 memcpy (register_buffer (current_regcache
, regnum
), val
,
1176 REGISTER_RAW_SIZE (regnum
));
1178 memset (register_buffer (current_regcache
, regnum
), '\000',
1179 REGISTER_RAW_SIZE (regnum
));
1181 /* On some architectures, e.g. HPPA, there are a few stray bits in
1182 some registers, that the rest of the code would like to ignore. */
1184 /* NOTE: cagney/2001-03-16: The macro CLEAN_UP_REGISTER_VALUE is
1185 going to be deprecated. Instead architectures will leave the raw
1186 register value as is and instead clean things up as they pass
1187 through the method gdbarch_pseudo_register_read() clean up the
1190 #ifdef DEPRECATED_CLEAN_UP_REGISTER_VALUE
1191 DEPRECATED_CLEAN_UP_REGISTER_VALUE \
1192 (regnum
, register_buffer (current_regcache
, regnum
));
1197 regcache_collect (int regnum
, void *buf
)
1199 memcpy (buf
, register_buffer (current_regcache
, regnum
),
1200 REGISTER_RAW_SIZE (regnum
));
1204 /* read_pc, write_pc, read_sp, write_sp, read_fp, etc. Special
1205 handling for registers PC, SP, and FP. */
1207 /* NOTE: cagney/2001-02-18: The functions generic_target_read_pc(),
1208 read_pc_pid(), read_pc(), generic_target_write_pc(),
1209 write_pc_pid(), write_pc(), generic_target_read_sp(), read_sp(),
1210 generic_target_write_sp(), write_sp(), generic_target_read_fp() and
1211 read_fp(), will eventually be moved out of the reg-cache into
1212 either frame.[hc] or to the multi-arch framework. The are not part
1213 of the raw register cache. */
1215 /* This routine is getting awfully cluttered with #if's. It's probably
1216 time to turn this into READ_PC and define it in the tm.h file.
1219 1999-06-08: The following were re-written so that it assumes the
1220 existence of a TARGET_READ_PC et.al. macro. A default generic
1221 version of that macro is made available where needed.
1223 Since the ``TARGET_READ_PC'' et.al. macro is going to be controlled
1224 by the multi-arch framework, it will eventually be possible to
1225 eliminate the intermediate read_pc_pid(). The client would call
1226 TARGET_READ_PC directly. (cagney). */
1229 generic_target_read_pc (ptid_t ptid
)
1234 CORE_ADDR pc_val
= ADDR_BITS_REMOVE ((CORE_ADDR
) read_register_pid (PC_REGNUM
, ptid
));
1238 internal_error (__FILE__
, __LINE__
,
1239 "generic_target_read_pc");
1244 read_pc_pid (ptid_t ptid
)
1246 ptid_t saved_inferior_ptid
;
1249 /* In case ptid != inferior_ptid. */
1250 saved_inferior_ptid
= inferior_ptid
;
1251 inferior_ptid
= ptid
;
1253 pc_val
= TARGET_READ_PC (ptid
);
1255 inferior_ptid
= saved_inferior_ptid
;
1262 return read_pc_pid (inferior_ptid
);
1266 generic_target_write_pc (CORE_ADDR pc
, ptid_t ptid
)
1270 write_register_pid (PC_REGNUM
, pc
, ptid
);
1271 if (NPC_REGNUM
>= 0)
1272 write_register_pid (NPC_REGNUM
, pc
+ 4, ptid
);
1274 internal_error (__FILE__
, __LINE__
,
1275 "generic_target_write_pc");
1280 write_pc_pid (CORE_ADDR pc
, ptid_t ptid
)
1282 ptid_t saved_inferior_ptid
;
1284 /* In case ptid != inferior_ptid. */
1285 saved_inferior_ptid
= inferior_ptid
;
1286 inferior_ptid
= ptid
;
1288 TARGET_WRITE_PC (pc
, ptid
);
1290 inferior_ptid
= saved_inferior_ptid
;
1294 write_pc (CORE_ADDR pc
)
1296 write_pc_pid (pc
, inferior_ptid
);
1299 /* Cope with strage ways of getting to the stack and frame pointers */
1302 generic_target_read_sp (void)
1306 return read_register (SP_REGNUM
);
1308 internal_error (__FILE__
, __LINE__
,
1309 "generic_target_read_sp");
1315 return TARGET_READ_SP ();
1319 generic_target_write_sp (CORE_ADDR val
)
1324 write_register (SP_REGNUM
, val
);
1328 internal_error (__FILE__
, __LINE__
,
1329 "generic_target_write_sp");
1333 write_sp (CORE_ADDR val
)
1335 TARGET_WRITE_SP (val
);
1339 generic_target_read_fp (void)
1343 return read_register (FP_REGNUM
);
1345 internal_error (__FILE__
, __LINE__
,
1346 "generic_target_read_fp");
1352 return TARGET_READ_FP ();
1357 reg_flush_command (char *command
, int from_tty
)
1359 /* Force-flush the register cache. */
1360 registers_changed ();
1362 printf_filtered ("Register cache flushed.\n");
1366 build_regcache (void)
1368 current_regcache
= regcache_xmalloc (current_gdbarch
);
1369 current_regcache
->passthrough_p
= 1;
1370 registers
= deprecated_grub_regcache_for_registers (current_regcache
);
1371 deprecated_register_valid
= deprecated_grub_regcache_for_register_valid (current_regcache
);
1375 dump_endian_bytes (struct ui_file
*file
, enum bfd_endian endian
,
1376 const unsigned char *buf
, long len
)
1381 case BFD_ENDIAN_BIG
:
1382 for (i
= 0; i
< len
; i
++)
1383 fprintf_unfiltered (file
, "%02x", buf
[i
]);
1385 case BFD_ENDIAN_LITTLE
:
1386 for (i
= len
- 1; i
>= 0; i
--)
1387 fprintf_unfiltered (file
, "%02x", buf
[i
]);
1390 internal_error (__FILE__
, __LINE__
, "Bad switch");
1394 enum regcache_dump_what
1396 regcache_dump_none
, regcache_dump_raw
, regcache_dump_cooked
, regcache_dump_groups
1400 regcache_dump (struct regcache
*regcache
, struct ui_file
*file
,
1401 enum regcache_dump_what what_to_dump
)
1403 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
1404 struct gdbarch
*gdbarch
= regcache
->descr
->gdbarch
;
1405 struct reggroup
*const *groups
= reggroups (gdbarch
);
1407 int footnote_nr
= 0;
1408 int footnote_register_size
= 0;
1409 int footnote_register_offset
= 0;
1410 int footnote_register_type_name_null
= 0;
1411 long register_offset
= 0;
1412 unsigned char *buf
= alloca (regcache
->descr
->max_register_size
);
1415 fprintf_unfiltered (file
, "legacy_p %d\n", regcache
->descr
->legacy_p
);
1416 fprintf_unfiltered (file
, "nr_raw_registers %d\n",
1417 regcache
->descr
->nr_raw_registers
);
1418 fprintf_unfiltered (file
, "nr_cooked_registers %d\n",
1419 regcache
->descr
->nr_cooked_registers
);
1420 fprintf_unfiltered (file
, "sizeof_raw_registers %ld\n",
1421 regcache
->descr
->sizeof_raw_registers
);
1422 fprintf_unfiltered (file
, "sizeof_raw_register_valid_p %ld\n",
1423 regcache
->descr
->sizeof_raw_register_valid_p
);
1424 fprintf_unfiltered (file
, "max_register_size %ld\n",
1425 regcache
->descr
->max_register_size
);
1426 fprintf_unfiltered (file
, "NUM_REGS %d\n", NUM_REGS
);
1427 fprintf_unfiltered (file
, "NUM_PSEUDO_REGS %d\n", NUM_PSEUDO_REGS
);
1430 gdb_assert (regcache
->descr
->nr_cooked_registers
1431 == (NUM_REGS
+ NUM_PSEUDO_REGS
));
1433 for (regnum
= -1; regnum
< regcache
->descr
->nr_cooked_registers
; regnum
++)
1437 fprintf_unfiltered (file
, " %-10s", "Name");
1440 const char *p
= REGISTER_NAME (regnum
);
1443 else if (p
[0] == '\0')
1445 fprintf_unfiltered (file
, " %-10s", p
);
1450 fprintf_unfiltered (file
, " %4s", "Nr");
1452 fprintf_unfiltered (file
, " %4d", regnum
);
1454 /* Relative number. */
1456 fprintf_unfiltered (file
, " %4s", "Rel");
1457 else if (regnum
< NUM_REGS
)
1458 fprintf_unfiltered (file
, " %4d", regnum
);
1460 fprintf_unfiltered (file
, " %4d", (regnum
- NUM_REGS
));
1464 fprintf_unfiltered (file
, " %6s ", "Offset");
1467 fprintf_unfiltered (file
, " %6ld",
1468 regcache
->descr
->register_offset
[regnum
]);
1469 if (register_offset
!= regcache
->descr
->register_offset
[regnum
]
1470 || register_offset
!= REGISTER_BYTE (regnum
)
1472 && (regcache
->descr
->register_offset
[regnum
]
1473 != (regcache
->descr
->register_offset
[regnum
- 1]
1474 + regcache
->descr
->sizeof_register
[regnum
- 1])))
1477 if (!footnote_register_offset
)
1478 footnote_register_offset
= ++footnote_nr
;
1479 fprintf_unfiltered (file
, "*%d", footnote_register_offset
);
1482 fprintf_unfiltered (file
, " ");
1483 register_offset
= (regcache
->descr
->register_offset
[regnum
]
1484 + regcache
->descr
->sizeof_register
[regnum
]);
1489 fprintf_unfiltered (file
, " %5s ", "Size");
1492 fprintf_unfiltered (file
, " %5ld",
1493 regcache
->descr
->sizeof_register
[regnum
]);
1494 if ((regcache
->descr
->sizeof_register
[regnum
]
1495 != REGISTER_RAW_SIZE (regnum
))
1496 || (regcache
->descr
->sizeof_register
[regnum
]
1497 != REGISTER_VIRTUAL_SIZE (regnum
))
1498 || (regcache
->descr
->sizeof_register
[regnum
]
1499 != TYPE_LENGTH (register_type (regcache
->descr
->gdbarch
,
1503 if (!footnote_register_size
)
1504 footnote_register_size
= ++footnote_nr
;
1505 fprintf_unfiltered (file
, "*%d", footnote_register_size
);
1508 fprintf_unfiltered (file
, " ");
1518 static const char blt
[] = "builtin_type";
1519 t
= TYPE_NAME (register_type (regcache
->descr
->gdbarch
, regnum
));
1523 if (!footnote_register_type_name_null
)
1524 footnote_register_type_name_null
= ++footnote_nr
;
1525 xasprintf (&n
, "*%d", footnote_register_type_name_null
);
1526 make_cleanup (xfree
, n
);
1529 /* Chop a leading builtin_type. */
1530 if (strncmp (t
, blt
, strlen (blt
)) == 0)
1533 fprintf_unfiltered (file
, " %-15s", t
);
1536 /* Leading space always present. */
1537 fprintf_unfiltered (file
, " ");
1540 if (what_to_dump
== regcache_dump_raw
)
1543 fprintf_unfiltered (file
, "Raw value");
1544 else if (regnum
>= regcache
->descr
->nr_raw_registers
)
1545 fprintf_unfiltered (file
, "<cooked>");
1546 else if (!regcache_valid_p (regcache
, regnum
))
1547 fprintf_unfiltered (file
, "<invalid>");
1550 regcache_raw_read (regcache
, regnum
, buf
);
1551 fprintf_unfiltered (file
, "0x");
1552 dump_endian_bytes (file
, TARGET_BYTE_ORDER
, buf
,
1553 REGISTER_RAW_SIZE (regnum
));
1557 /* Value, cooked. */
1558 if (what_to_dump
== regcache_dump_cooked
)
1561 fprintf_unfiltered (file
, "Cooked value");
1564 regcache_cooked_read (regcache
, regnum
, buf
);
1565 fprintf_unfiltered (file
, "0x");
1566 dump_endian_bytes (file
, TARGET_BYTE_ORDER
, buf
,
1567 REGISTER_VIRTUAL_SIZE (regnum
));
1571 /* Group members. */
1572 if (what_to_dump
== regcache_dump_groups
)
1575 fprintf_unfiltered (file
, "Groups");
1579 const char *sep
= "";
1580 for (i
= 0; groups
[i
] != NULL
; i
++)
1582 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, groups
[i
]))
1584 fprintf_unfiltered (file
, "%s%s", sep
, reggroup_name (groups
[i
]));
1591 fprintf_unfiltered (file
, "\n");
1594 if (footnote_register_size
)
1595 fprintf_unfiltered (file
, "*%d: Inconsistent register sizes.\n",
1596 footnote_register_size
);
1597 if (footnote_register_offset
)
1598 fprintf_unfiltered (file
, "*%d: Inconsistent register offsets.\n",
1599 footnote_register_offset
);
1600 if (footnote_register_type_name_null
)
1601 fprintf_unfiltered (file
,
1602 "*%d: Register type's name NULL.\n",
1603 footnote_register_type_name_null
);
1604 do_cleanups (cleanups
);
1608 regcache_print (char *args
, enum regcache_dump_what what_to_dump
)
1611 regcache_dump (current_regcache
, gdb_stdout
, what_to_dump
);
1614 struct ui_file
*file
= gdb_fopen (args
, "w");
1616 perror_with_name ("maintenance print architecture");
1617 regcache_dump (current_regcache
, file
, what_to_dump
);
1618 ui_file_delete (file
);
1623 maintenance_print_registers (char *args
, int from_tty
)
1625 regcache_print (args
, regcache_dump_none
);
1629 maintenance_print_raw_registers (char *args
, int from_tty
)
1631 regcache_print (args
, regcache_dump_raw
);
1635 maintenance_print_cooked_registers (char *args
, int from_tty
)
1637 regcache_print (args
, regcache_dump_cooked
);
1641 maintenance_print_register_groups (char *args
, int from_tty
)
1643 regcache_print (args
, regcache_dump_groups
);
1647 _initialize_regcache (void)
1649 regcache_descr_handle
= register_gdbarch_data (init_regcache_descr
,
1650 xfree_regcache_descr
);
1651 REGISTER_GDBARCH_SWAP (current_regcache
);
1652 register_gdbarch_swap (®isters
, sizeof (registers
), NULL
);
1653 register_gdbarch_swap (&deprecated_register_valid
, sizeof (deprecated_register_valid
), NULL
);
1654 register_gdbarch_swap (NULL
, 0, build_regcache
);
1656 add_com ("flushregs", class_maintenance
, reg_flush_command
,
1657 "Force gdb to flush its register cache (maintainer command)");
1659 /* Initialize the thread/process associated with the current set of
1660 registers. For now, -1 is special, and means `no current process'. */
1661 registers_ptid
= pid_to_ptid (-1);
1663 add_cmd ("registers", class_maintenance
,
1664 maintenance_print_registers
,
1665 "Print the internal register configuration.\
1666 Takes an optional file parameter.",
1667 &maintenanceprintlist
);
1668 add_cmd ("raw-registers", class_maintenance
,
1669 maintenance_print_raw_registers
,
1670 "Print the internal register configuration including raw values.\
1671 Takes an optional file parameter.",
1672 &maintenanceprintlist
);
1673 add_cmd ("cooked-registers", class_maintenance
,
1674 maintenance_print_cooked_registers
,
1675 "Print the internal register configuration including cooked values.\
1676 Takes an optional file parameter.",
1677 &maintenanceprintlist
);
1678 add_cmd ("register-groups", class_maintenance
,
1679 maintenance_print_register_groups
,
1680 "Print the internal register configuration including each register's group.\
1681 Takes an optional file parameter.",
1682 &maintenanceprintlist
);