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
;
479 invalidate a single register REGNUM in the cache */
481 register_changed (int regnum
)
483 set_register_cached (regnum
, 0);
486 /* If REGNUM >= 0, return a pointer to register REGNUM's cache buffer area,
487 else return a pointer to the start of the cache buffer. */
490 register_buffer (struct regcache
*regcache
, int regnum
)
492 return regcache
->raw_registers
+ regcache
->descr
->register_offset
[regnum
];
495 /* Return whether register REGNUM is a real register. */
498 real_register (int regnum
)
500 return regnum
>= 0 && regnum
< NUM_REGS
;
503 /* Low level examining and depositing of registers.
505 The caller is responsible for making sure that the inferior is
506 stopped before calling the fetching routines, or it will get
507 garbage. (a change from GDB version 3, in which the caller got the
508 value from the last stop). */
510 /* REGISTERS_CHANGED ()
512 Indicate that registers may have changed, so invalidate the cache. */
515 registers_changed (void)
519 registers_ptid
= pid_to_ptid (-1);
521 /* Force cleanup of any alloca areas if using C alloca instead of
522 a builtin alloca. This particular call is used to clean up
523 areas allocated by low level target code which may build up
524 during lengthy interactions between gdb and the target before
525 gdb gives control to the user (ie watchpoints). */
528 for (i
= 0; i
< current_regcache
->descr
->nr_raw_registers
; i
++)
529 set_register_cached (i
, 0);
531 if (registers_changed_hook
)
532 registers_changed_hook ();
535 /* DEPRECATED_REGISTERS_FETCHED ()
537 Indicate that all registers have been fetched, so mark them all valid. */
539 /* NOTE: cagney/2001-12-04: This function does not set valid on the
540 pseudo-register range since pseudo registers are always supplied
541 using supply_register(). */
542 /* FIXME: cagney/2001-12-04: This function is DEPRECATED. The target
543 code was blatting the registers[] array and then calling this.
544 Since targets should only be using supply_register() the need for
545 this function/hack is eliminated. */
548 deprecated_registers_fetched (void)
552 for (i
= 0; i
< NUM_REGS
; i
++)
553 set_register_cached (i
, 1);
554 /* Do not assume that the pseudo-regs have also been fetched.
555 Fetching all real regs NEVER accounts for pseudo-regs. */
558 /* read_register_bytes and write_register_bytes are generally a *BAD*
559 idea. They are inefficient because they need to check for partial
560 updates, which can only be done by scanning through all of the
561 registers and seeing if the bytes that are being read/written fall
562 inside of an invalid register. [The main reason this is necessary
563 is that register sizes can vary, so a simple index won't suffice.]
564 It is far better to call read_register_gen and write_register_gen
565 if you want to get at the raw register contents, as it only takes a
566 regnum as an argument, and therefore can't do a partial register
569 Prior to the recent fixes to check for partial updates, both read
570 and write_register_bytes always checked to see if any registers
571 were stale, and then called target_fetch_registers (-1) to update
572 the whole set. This caused really slowed things down for remote
575 /* Copy INLEN bytes of consecutive data from registers
576 starting with the INREGBYTE'th byte of register data
577 into memory at MYADDR. */
580 read_register_bytes (int in_start
, char *in_buf
, int in_len
)
582 int in_end
= in_start
+ in_len
;
584 char *reg_buf
= alloca (MAX_REGISTER_RAW_SIZE
);
586 /* See if we are trying to read bytes from out-of-date registers. If so,
587 update just those registers. */
589 for (regnum
= 0; regnum
< NUM_REGS
+ NUM_PSEUDO_REGS
; regnum
++)
598 reg_start
= REGISTER_BYTE (regnum
);
599 reg_len
= REGISTER_RAW_SIZE (regnum
);
600 reg_end
= reg_start
+ reg_len
;
602 if (reg_end
<= in_start
|| in_end
<= reg_start
)
603 /* The range the user wants to read doesn't overlap with regnum. */
606 if (REGISTER_NAME (regnum
) != NULL
&& *REGISTER_NAME (regnum
) != '\0')
607 /* Force the cache to fetch the entire register. */
608 deprecated_read_register_gen (regnum
, reg_buf
);
610 /* Legacy note: even though this register is ``invalid'' we
611 still need to return something. It would appear that some
612 code relies on apparent gaps in the register array also
614 /* FIXME: cagney/2001-08-18: This is just silly. It defeats
615 the entire register read/write flow of control. Must
616 resist temptation to return 0xdeadbeef. */
617 memcpy (reg_buf
, registers
+ reg_start
, reg_len
);
619 /* Legacy note: This function, for some reason, allows a NULL
620 input buffer. If the buffer is NULL, the registers are still
621 fetched, just the final transfer is skipped. */
625 /* start = max (reg_start, in_start) */
626 if (reg_start
> in_start
)
631 /* end = min (reg_end, in_end) */
632 if (reg_end
< in_end
)
637 /* Transfer just the bytes common to both IN_BUF and REG_BUF */
638 for (byte
= start
; byte
< end
; byte
++)
640 in_buf
[byte
- in_start
] = reg_buf
[byte
- reg_start
];
645 /* Read register REGNUM into memory at MYADDR, which must be large
646 enough for REGISTER_RAW_BYTES (REGNUM). Target byte-order. If the
647 register is known to be the size of a CORE_ADDR or smaller,
648 read_register can be used instead. */
651 legacy_read_register_gen (int regnum
, char *myaddr
)
653 gdb_assert (regnum
>= 0 && regnum
< (NUM_REGS
+ NUM_PSEUDO_REGS
));
654 if (! ptid_equal (registers_ptid
, inferior_ptid
))
656 registers_changed ();
657 registers_ptid
= inferior_ptid
;
660 if (!register_cached (regnum
))
661 target_fetch_registers (regnum
);
663 memcpy (myaddr
, register_buffer (current_regcache
, regnum
),
664 REGISTER_RAW_SIZE (regnum
));
668 regcache_raw_read (struct regcache
*regcache
, int regnum
, void *buf
)
670 gdb_assert (regcache
!= NULL
&& buf
!= NULL
);
671 gdb_assert (regnum
>= 0 && regnum
< regcache
->descr
->nr_raw_registers
);
672 if (regcache
->descr
->legacy_p
673 && regcache
->passthrough_p
)
675 gdb_assert (regcache
== current_regcache
);
676 /* For moment, just use underlying legacy code. Ulgh!!! This
677 silently and very indirectly updates the regcache's regcache
678 via the global deprecated_register_valid[]. */
679 legacy_read_register_gen (regnum
, buf
);
682 /* Make certain that the register cache is up-to-date with respect
683 to the current thread. This switching shouldn't be necessary
684 only there is still only one target side register cache. Sigh!
685 On the bright side, at least there is a regcache object. */
686 if (regcache
->passthrough_p
)
688 gdb_assert (regcache
== current_regcache
);
689 if (! ptid_equal (registers_ptid
, inferior_ptid
))
691 registers_changed ();
692 registers_ptid
= inferior_ptid
;
694 if (!register_cached (regnum
))
695 target_fetch_registers (regnum
);
697 /* Copy the value directly into the register cache. */
698 memcpy (buf
, (regcache
->raw_registers
699 + regcache
->descr
->register_offset
[regnum
]),
700 regcache
->descr
->sizeof_register
[regnum
]);
704 regcache_raw_read_signed (struct regcache
*regcache
, int regnum
, LONGEST
*val
)
707 gdb_assert (regcache
!= NULL
);
708 gdb_assert (regnum
>= 0 && regnum
< regcache
->descr
->nr_raw_registers
);
709 buf
= alloca (regcache
->descr
->sizeof_register
[regnum
]);
710 regcache_raw_read (regcache
, regnum
, buf
);
711 (*val
) = extract_signed_integer (buf
,
712 regcache
->descr
->sizeof_register
[regnum
]);
716 regcache_raw_read_unsigned (struct regcache
*regcache
, int regnum
,
720 gdb_assert (regcache
!= NULL
);
721 gdb_assert (regnum
>= 0 && regnum
< regcache
->descr
->nr_raw_registers
);
722 buf
= alloca (regcache
->descr
->sizeof_register
[regnum
]);
723 regcache_raw_read (regcache
, regnum
, buf
);
724 (*val
) = extract_unsigned_integer (buf
,
725 regcache
->descr
->sizeof_register
[regnum
]);
729 regcache_raw_write_signed (struct regcache
*regcache
, int regnum
, LONGEST val
)
732 gdb_assert (regcache
!= NULL
);
733 gdb_assert (regnum
>=0 && regnum
< regcache
->descr
->nr_raw_registers
);
734 buf
= alloca (regcache
->descr
->sizeof_register
[regnum
]);
735 store_signed_integer (buf
, regcache
->descr
->sizeof_register
[regnum
], val
);
736 regcache_raw_write (regcache
, regnum
, buf
);
740 regcache_raw_write_unsigned (struct regcache
*regcache
, int regnum
,
744 gdb_assert (regcache
!= NULL
);
745 gdb_assert (regnum
>=0 && regnum
< regcache
->descr
->nr_raw_registers
);
746 buf
= alloca (regcache
->descr
->sizeof_register
[regnum
]);
747 store_unsigned_integer (buf
, regcache
->descr
->sizeof_register
[regnum
], val
);
748 regcache_raw_write (regcache
, regnum
, buf
);
752 deprecated_read_register_gen (int regnum
, char *buf
)
754 gdb_assert (current_regcache
!= NULL
);
755 gdb_assert (current_regcache
->descr
->gdbarch
== current_gdbarch
);
756 if (current_regcache
->descr
->legacy_p
)
758 legacy_read_register_gen (regnum
, buf
);
761 regcache_cooked_read (current_regcache
, regnum
, buf
);
765 regcache_cooked_read (struct regcache
*regcache
, int regnum
, void *buf
)
767 gdb_assert (regnum
>= 0);
768 gdb_assert (regnum
< regcache
->descr
->nr_cooked_registers
);
769 if (regnum
< regcache
->descr
->nr_raw_registers
)
770 regcache_raw_read (regcache
, regnum
, buf
);
772 gdbarch_pseudo_register_read (regcache
->descr
->gdbarch
, regcache
,
777 regcache_cooked_read_signed (struct regcache
*regcache
, int regnum
,
781 gdb_assert (regcache
!= NULL
);
782 gdb_assert (regnum
>= 0 && regnum
< regcache
->descr
->nr_raw_registers
);
783 buf
= alloca (regcache
->descr
->sizeof_register
[regnum
]);
784 regcache_cooked_read (regcache
, regnum
, buf
);
785 (*val
) = extract_signed_integer (buf
,
786 regcache
->descr
->sizeof_register
[regnum
]);
790 regcache_cooked_read_unsigned (struct regcache
*regcache
, int regnum
,
794 gdb_assert (regcache
!= NULL
);
795 gdb_assert (regnum
>= 0 && regnum
< regcache
->descr
->nr_raw_registers
);
796 buf
= alloca (regcache
->descr
->sizeof_register
[regnum
]);
797 regcache_cooked_read (regcache
, regnum
, buf
);
798 (*val
) = extract_unsigned_integer (buf
,
799 regcache
->descr
->sizeof_register
[regnum
]);
802 /* Write register REGNUM at MYADDR to the target. MYADDR points at
803 REGISTER_RAW_BYTES(REGNUM), which must be in target byte-order. */
806 legacy_write_register_gen (int regnum
, const void *myaddr
)
809 gdb_assert (regnum
>= 0 && regnum
< (NUM_REGS
+ NUM_PSEUDO_REGS
));
811 /* On the sparc, writing %g0 is a no-op, so we don't even want to
812 change the registers array if something writes to this register. */
813 if (CANNOT_STORE_REGISTER (regnum
))
816 if (! ptid_equal (registers_ptid
, inferior_ptid
))
818 registers_changed ();
819 registers_ptid
= inferior_ptid
;
822 size
= REGISTER_RAW_SIZE (regnum
);
824 if (real_register (regnum
))
826 /* If we have a valid copy of the register, and new value == old
827 value, then don't bother doing the actual store. */
828 if (register_cached (regnum
)
829 && (memcmp (register_buffer (current_regcache
, regnum
), myaddr
, size
)
833 target_prepare_to_store ();
836 memcpy (register_buffer (current_regcache
, regnum
), myaddr
, size
);
838 set_register_cached (regnum
, 1);
839 target_store_registers (regnum
);
843 regcache_raw_write (struct regcache
*regcache
, int regnum
, const void *buf
)
845 gdb_assert (regcache
!= NULL
&& buf
!= NULL
);
846 gdb_assert (regnum
>= 0 && regnum
< regcache
->descr
->nr_raw_registers
);
848 if (regcache
->passthrough_p
849 && regcache
->descr
->legacy_p
)
851 /* For moment, just use underlying legacy code. Ulgh!!! This
852 silently and very indirectly updates the regcache's buffers
853 via the globals deprecated_register_valid[] and registers[]. */
854 gdb_assert (regcache
== current_regcache
);
855 legacy_write_register_gen (regnum
, buf
);
859 /* On the sparc, writing %g0 is a no-op, so we don't even want to
860 change the registers array if something writes to this register. */
861 if (CANNOT_STORE_REGISTER (regnum
))
864 /* Handle the simple case first -> not write through so just store
866 if (!regcache
->passthrough_p
)
868 memcpy ((regcache
->raw_registers
869 + regcache
->descr
->register_offset
[regnum
]), buf
,
870 regcache
->descr
->sizeof_register
[regnum
]);
871 regcache
->raw_register_valid_p
[regnum
] = 1;
875 /* Make certain that the correct cache is selected. */
876 gdb_assert (regcache
== current_regcache
);
877 if (! ptid_equal (registers_ptid
, inferior_ptid
))
879 registers_changed ();
880 registers_ptid
= inferior_ptid
;
883 /* If we have a valid copy of the register, and new value == old
884 value, then don't bother doing the actual store. */
885 if (regcache_valid_p (regcache
, regnum
)
886 && (memcmp (register_buffer (regcache
, regnum
), buf
,
887 regcache
->descr
->sizeof_register
[regnum
]) == 0))
890 target_prepare_to_store ();
891 memcpy (register_buffer (regcache
, regnum
), buf
,
892 regcache
->descr
->sizeof_register
[regnum
]);
893 regcache
->raw_register_valid_p
[regnum
] = 1;
894 target_store_registers (regnum
);
898 deprecated_write_register_gen (int regnum
, char *buf
)
900 gdb_assert (current_regcache
!= NULL
);
901 gdb_assert (current_regcache
->descr
->gdbarch
== current_gdbarch
);
902 if (current_regcache
->descr
->legacy_p
)
904 legacy_write_register_gen (regnum
, buf
);
907 regcache_cooked_write (current_regcache
, regnum
, buf
);
911 regcache_cooked_write (struct regcache
*regcache
, int regnum
, const void *buf
)
913 gdb_assert (regnum
>= 0);
914 gdb_assert (regnum
< regcache
->descr
->nr_cooked_registers
);
915 if (regnum
< regcache
->descr
->nr_raw_registers
)
916 regcache_raw_write (regcache
, regnum
, buf
);
918 gdbarch_pseudo_register_write (regcache
->descr
->gdbarch
, regcache
,
922 /* Copy INLEN bytes of consecutive data from memory at MYADDR
923 into registers starting with the MYREGSTART'th byte of register data. */
926 write_register_bytes (int myregstart
, char *myaddr
, int inlen
)
928 int myregend
= myregstart
+ inlen
;
931 target_prepare_to_store ();
933 /* Scan through the registers updating any that are covered by the
934 range myregstart<=>myregend using write_register_gen, which does
935 nice things like handling threads, and avoiding updates when the
936 new and old contents are the same. */
938 for (regnum
= 0; regnum
< NUM_REGS
+ NUM_PSEUDO_REGS
; regnum
++)
940 int regstart
, regend
;
942 regstart
= REGISTER_BYTE (regnum
);
943 regend
= regstart
+ REGISTER_RAW_SIZE (regnum
);
945 /* Is this register completely outside the range the user is writing? */
946 if (myregend
<= regstart
|| regend
<= myregstart
)
949 /* Is this register completely within the range the user is writing? */
950 else if (myregstart
<= regstart
&& regend
<= myregend
)
951 deprecated_write_register_gen (regnum
, myaddr
+ (regstart
- myregstart
));
953 /* The register partially overlaps the range being written. */
956 char *regbuf
= (char*) alloca (MAX_REGISTER_RAW_SIZE
);
957 /* What's the overlap between this register's bytes and
958 those the caller wants to write? */
959 int overlapstart
= max (regstart
, myregstart
);
960 int overlapend
= min (regend
, myregend
);
962 /* We may be doing a partial update of an invalid register.
963 Update it from the target before scribbling on it. */
964 deprecated_read_register_gen (regnum
, regbuf
);
966 memcpy (registers
+ overlapstart
,
967 myaddr
+ (overlapstart
- myregstart
),
968 overlapend
- overlapstart
);
970 target_store_registers (regnum
);
975 /* Perform a partial register transfer using a read, modify, write
978 typedef void (regcache_read_ftype
) (struct regcache
*regcache
, int regnum
,
980 typedef void (regcache_write_ftype
) (struct regcache
*regcache
, int regnum
,
984 regcache_xfer_part (struct regcache
*regcache
, int regnum
,
985 int offset
, int len
, void *in
, const void *out
,
986 regcache_read_ftype
*read
, regcache_write_ftype
*write
)
988 struct regcache_descr
*descr
= regcache
->descr
;
989 bfd_byte
*reg
= alloca (descr
->max_register_size
);
990 gdb_assert (offset
>= 0 && offset
<= descr
->sizeof_register
[regnum
]);
991 gdb_assert (len
>= 0 && offset
+ len
<= descr
->sizeof_register
[regnum
]);
992 /* Something to do? */
993 if (offset
+ len
== 0)
995 /* Read (when needed) ... */
998 || offset
+ len
< descr
->sizeof_register
[regnum
])
1000 gdb_assert (read
!= NULL
);
1001 read (regcache
, regnum
, reg
);
1003 /* ... modify ... */
1005 memcpy (in
, reg
+ offset
, len
);
1007 memcpy (reg
+ offset
, out
, len
);
1008 /* ... write (when needed). */
1011 gdb_assert (write
!= NULL
);
1012 write (regcache
, regnum
, reg
);
1017 regcache_raw_read_part (struct regcache
*regcache
, int regnum
,
1018 int offset
, int len
, void *buf
)
1020 struct regcache_descr
*descr
= regcache
->descr
;
1021 gdb_assert (regnum
>= 0 && regnum
< descr
->nr_raw_registers
);
1022 regcache_xfer_part (regcache
, regnum
, offset
, len
, buf
, NULL
,
1023 regcache_raw_read
, regcache_raw_write
);
1027 regcache_raw_write_part (struct regcache
*regcache
, int regnum
,
1028 int offset
, int len
, const void *buf
)
1030 struct regcache_descr
*descr
= regcache
->descr
;
1031 gdb_assert (regnum
>= 0 && regnum
< descr
->nr_raw_registers
);
1032 regcache_xfer_part (regcache
, regnum
, offset
, len
, NULL
, buf
,
1033 regcache_raw_read
, regcache_raw_write
);
1037 regcache_cooked_read_part (struct regcache
*regcache
, int regnum
,
1038 int offset
, int len
, void *buf
)
1040 struct regcache_descr
*descr
= regcache
->descr
;
1041 gdb_assert (regnum
>= 0 && regnum
< descr
->nr_cooked_registers
);
1042 regcache_xfer_part (regcache
, regnum
, offset
, len
, buf
, NULL
,
1043 regcache_cooked_read
, regcache_cooked_write
);
1047 regcache_cooked_write_part (struct regcache
*regcache
, int regnum
,
1048 int offset
, int len
, const void *buf
)
1050 struct regcache_descr
*descr
= regcache
->descr
;
1051 gdb_assert (regnum
>= 0 && regnum
< descr
->nr_cooked_registers
);
1052 regcache_xfer_part (regcache
, regnum
, offset
, len
, NULL
, buf
,
1053 regcache_cooked_read
, regcache_cooked_write
);
1056 /* Hack to keep code that view the register buffer as raw bytes
1060 register_offset_hack (struct gdbarch
*gdbarch
, int regnum
)
1062 struct regcache_descr
*descr
= regcache_descr (gdbarch
);
1063 gdb_assert (regnum
>= 0 && regnum
< descr
->nr_cooked_registers
);
1064 return descr
->register_offset
[regnum
];
1068 cooked_xfer_using_offset_hack (struct regcache
*regcache
,
1069 int buf_start
, int buf_len
, void *in_b
,
1072 struct regcache_descr
*descr
= regcache
->descr
;
1073 struct gdbarch
*gdbarch
= descr
->gdbarch
;
1074 bfd_byte
*in_buf
= in_b
;
1075 const bfd_byte
*out_buf
= out_b
;
1076 int buf_end
= buf_start
+ buf_len
;
1078 char *reg_buf
= alloca (descr
->max_register_size
);
1080 /* NOTE: cagney/2002-08-17: This code assumes that the register
1081 offsets are strictly increasing and do not overlap. If this
1082 isn't the case then the bug is in the target architecture and NOT
1085 /* NOTE: cagney/2002-08-17: This code assumes that only the
1086 registers covered by BUF_START:BUF_LEN should be transfered. If,
1087 for some reason, there is a gap between two registers, then that
1088 gap isn't transfered. (The gap shouldn't be there but that is
1091 /* Iterate through all registers looking for those that lie within
1092 BUF_START:BUF_LEN. */
1094 for (regnum
= 0; regnum
< descr
->nr_cooked_registers
; regnum
++)
1096 /* The register's location. */
1097 int reg_start
= descr
->register_offset
[regnum
];
1098 int reg_len
= descr
->sizeof_register
[regnum
];
1099 int reg_end
= reg_start
+ reg_len
;
1101 /* The START, END and LEN that falls within the current
1107 /* start = max (reg_start, buf_start) */
1108 if (reg_start
> buf_start
)
1109 xfer_start
= reg_start
;
1111 xfer_start
= buf_start
;
1113 /* end = min (reg_end, buf_end) */
1114 if (reg_end
< buf_end
)
1119 /* The number of bytes to transfer. If there isn't anything to
1120 transfer (the end is before the start) this will be -ve. */
1121 xfer_len
= xfer_end
- xfer_start
;
1124 regcache_xfer_part (regcache
, regnum
, xfer_start
- reg_start
,
1125 xfer_len
, in_b
, out_b
, regcache_cooked_read
,
1126 regcache_cooked_write
);
1131 regcache_cooked_read_using_offset_hack (struct regcache
*regcache
,
1132 int buf_start
, int buf_len
, void *b
)
1134 cooked_xfer_using_offset_hack (regcache
, buf_start
, buf_len
, b
, NULL
);
1138 regcache_cooked_write_using_offset_hack (struct regcache
*regcache
,
1139 int buf_start
, int buf_len
,
1142 cooked_xfer_using_offset_hack (regcache
, buf_start
, buf_len
, NULL
, b
);
1145 /* Return the contents of register REGNUM as an unsigned integer. */
1148 read_register (int regnum
)
1150 char *buf
= alloca (REGISTER_RAW_SIZE (regnum
));
1151 deprecated_read_register_gen (regnum
, buf
);
1152 return (extract_unsigned_integer (buf
, REGISTER_RAW_SIZE (regnum
)));
1156 read_register_pid (int regnum
, ptid_t ptid
)
1162 if (ptid_equal (ptid
, inferior_ptid
))
1163 return read_register (regnum
);
1165 save_ptid
= inferior_ptid
;
1167 inferior_ptid
= ptid
;
1169 retval
= read_register (regnum
);
1171 inferior_ptid
= save_ptid
;
1176 /* Return the contents of register REGNUM as a signed integer. */
1179 read_signed_register (int regnum
)
1181 void *buf
= alloca (REGISTER_RAW_SIZE (regnum
));
1182 deprecated_read_register_gen (regnum
, buf
);
1183 return (extract_signed_integer (buf
, REGISTER_RAW_SIZE (regnum
)));
1187 read_signed_register_pid (int regnum
, ptid_t ptid
)
1192 if (ptid_equal (ptid
, inferior_ptid
))
1193 return read_signed_register (regnum
);
1195 save_ptid
= inferior_ptid
;
1197 inferior_ptid
= ptid
;
1199 retval
= read_signed_register (regnum
);
1201 inferior_ptid
= save_ptid
;
1206 /* Store VALUE into the raw contents of register number REGNUM. */
1209 write_register (int regnum
, LONGEST val
)
1213 size
= REGISTER_RAW_SIZE (regnum
);
1214 buf
= alloca (size
);
1215 store_signed_integer (buf
, size
, (LONGEST
) val
);
1216 deprecated_write_register_gen (regnum
, buf
);
1220 write_register_pid (int regnum
, CORE_ADDR val
, ptid_t ptid
)
1224 if (ptid_equal (ptid
, inferior_ptid
))
1226 write_register (regnum
, val
);
1230 save_ptid
= inferior_ptid
;
1232 inferior_ptid
= ptid
;
1234 write_register (regnum
, val
);
1236 inferior_ptid
= save_ptid
;
1239 /* SUPPLY_REGISTER()
1241 Record that register REGNUM contains VAL. This is used when the
1242 value is obtained from the inferior or core dump, so there is no
1243 need to store the value there.
1245 If VAL is a NULL pointer, then it's probably an unsupported register.
1246 We just set its value to all zeros. We might want to record this
1247 fact, and report it to the users of read_register and friends. */
1250 supply_register (int regnum
, const void *val
)
1253 if (! ptid_equal (registers_ptid
, inferior_ptid
))
1255 registers_changed ();
1256 registers_ptid
= inferior_ptid
;
1260 set_register_cached (regnum
, 1);
1262 memcpy (register_buffer (current_regcache
, regnum
), val
,
1263 REGISTER_RAW_SIZE (regnum
));
1265 memset (register_buffer (current_regcache
, regnum
), '\000',
1266 REGISTER_RAW_SIZE (regnum
));
1268 /* On some architectures, e.g. HPPA, there are a few stray bits in
1269 some registers, that the rest of the code would like to ignore. */
1271 /* NOTE: cagney/2001-03-16: The macro CLEAN_UP_REGISTER_VALUE is
1272 going to be deprecated. Instead architectures will leave the raw
1273 register value as is and instead clean things up as they pass
1274 through the method gdbarch_pseudo_register_read() clean up the
1277 #ifdef DEPRECATED_CLEAN_UP_REGISTER_VALUE
1278 DEPRECATED_CLEAN_UP_REGISTER_VALUE \
1279 (regnum
, register_buffer (current_regcache
, regnum
));
1284 regcache_collect (int regnum
, void *buf
)
1286 memcpy (buf
, register_buffer (current_regcache
, regnum
),
1287 REGISTER_RAW_SIZE (regnum
));
1291 /* read_pc, write_pc, read_sp, write_sp, read_fp, etc. Special
1292 handling for registers PC, SP, and FP. */
1294 /* NOTE: cagney/2001-02-18: The functions generic_target_read_pc(),
1295 read_pc_pid(), read_pc(), generic_target_write_pc(),
1296 write_pc_pid(), write_pc(), generic_target_read_sp(), read_sp(),
1297 generic_target_write_sp(), write_sp(), generic_target_read_fp() and
1298 read_fp(), will eventually be moved out of the reg-cache into
1299 either frame.[hc] or to the multi-arch framework. The are not part
1300 of the raw register cache. */
1302 /* This routine is getting awfully cluttered with #if's. It's probably
1303 time to turn this into READ_PC and define it in the tm.h file.
1306 1999-06-08: The following were re-written so that it assumes the
1307 existence of a TARGET_READ_PC et.al. macro. A default generic
1308 version of that macro is made available where needed.
1310 Since the ``TARGET_READ_PC'' et.al. macro is going to be controlled
1311 by the multi-arch framework, it will eventually be possible to
1312 eliminate the intermediate read_pc_pid(). The client would call
1313 TARGET_READ_PC directly. (cagney). */
1316 generic_target_read_pc (ptid_t ptid
)
1321 CORE_ADDR pc_val
= ADDR_BITS_REMOVE ((CORE_ADDR
) read_register_pid (PC_REGNUM
, ptid
));
1325 internal_error (__FILE__
, __LINE__
,
1326 "generic_target_read_pc");
1331 read_pc_pid (ptid_t ptid
)
1333 ptid_t saved_inferior_ptid
;
1336 /* In case ptid != inferior_ptid. */
1337 saved_inferior_ptid
= inferior_ptid
;
1338 inferior_ptid
= ptid
;
1340 pc_val
= TARGET_READ_PC (ptid
);
1342 inferior_ptid
= saved_inferior_ptid
;
1349 return read_pc_pid (inferior_ptid
);
1353 generic_target_write_pc (CORE_ADDR pc
, ptid_t ptid
)
1357 write_register_pid (PC_REGNUM
, pc
, ptid
);
1358 if (NPC_REGNUM
>= 0)
1359 write_register_pid (NPC_REGNUM
, pc
+ 4, ptid
);
1361 internal_error (__FILE__
, __LINE__
,
1362 "generic_target_write_pc");
1367 write_pc_pid (CORE_ADDR pc
, ptid_t ptid
)
1369 ptid_t saved_inferior_ptid
;
1371 /* In case ptid != inferior_ptid. */
1372 saved_inferior_ptid
= inferior_ptid
;
1373 inferior_ptid
= ptid
;
1375 TARGET_WRITE_PC (pc
, ptid
);
1377 inferior_ptid
= saved_inferior_ptid
;
1381 write_pc (CORE_ADDR pc
)
1383 write_pc_pid (pc
, inferior_ptid
);
1386 /* Cope with strage ways of getting to the stack and frame pointers */
1389 generic_target_read_sp (void)
1393 return read_register (SP_REGNUM
);
1395 internal_error (__FILE__
, __LINE__
,
1396 "generic_target_read_sp");
1402 return TARGET_READ_SP ();
1406 generic_target_write_sp (CORE_ADDR val
)
1411 write_register (SP_REGNUM
, val
);
1415 internal_error (__FILE__
, __LINE__
,
1416 "generic_target_write_sp");
1420 write_sp (CORE_ADDR val
)
1422 TARGET_WRITE_SP (val
);
1426 generic_target_read_fp (void)
1430 return read_register (FP_REGNUM
);
1432 internal_error (__FILE__
, __LINE__
,
1433 "generic_target_read_fp");
1439 return TARGET_READ_FP ();
1444 reg_flush_command (char *command
, int from_tty
)
1446 /* Force-flush the register cache. */
1447 registers_changed ();
1449 printf_filtered ("Register cache flushed.\n");
1453 build_regcache (void)
1455 current_regcache
= regcache_xmalloc (current_gdbarch
);
1456 current_regcache
->passthrough_p
= 1;
1457 registers
= deprecated_grub_regcache_for_registers (current_regcache
);
1458 deprecated_register_valid
= deprecated_grub_regcache_for_register_valid (current_regcache
);
1462 dump_endian_bytes (struct ui_file
*file
, enum bfd_endian endian
,
1463 const unsigned char *buf
, long len
)
1468 case BFD_ENDIAN_BIG
:
1469 for (i
= 0; i
< len
; i
++)
1470 fprintf_unfiltered (file
, "%02x", buf
[i
]);
1472 case BFD_ENDIAN_LITTLE
:
1473 for (i
= len
- 1; i
>= 0; i
--)
1474 fprintf_unfiltered (file
, "%02x", buf
[i
]);
1477 internal_error (__FILE__
, __LINE__
, "Bad switch");
1481 enum regcache_dump_what
1483 regcache_dump_none
, regcache_dump_raw
, regcache_dump_cooked
, regcache_dump_groups
1487 regcache_dump (struct regcache
*regcache
, struct ui_file
*file
,
1488 enum regcache_dump_what what_to_dump
)
1490 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
1491 struct gdbarch
*gdbarch
= regcache
->descr
->gdbarch
;
1492 struct reggroup
*const *groups
= reggroups (gdbarch
);
1494 int footnote_nr
= 0;
1495 int footnote_register_size
= 0;
1496 int footnote_register_offset
= 0;
1497 int footnote_register_type_name_null
= 0;
1498 long register_offset
= 0;
1499 unsigned char *buf
= alloca (regcache
->descr
->max_register_size
);
1502 fprintf_unfiltered (file
, "legacy_p %d\n", regcache
->descr
->legacy_p
);
1503 fprintf_unfiltered (file
, "nr_raw_registers %d\n",
1504 regcache
->descr
->nr_raw_registers
);
1505 fprintf_unfiltered (file
, "nr_cooked_registers %d\n",
1506 regcache
->descr
->nr_cooked_registers
);
1507 fprintf_unfiltered (file
, "sizeof_raw_registers %ld\n",
1508 regcache
->descr
->sizeof_raw_registers
);
1509 fprintf_unfiltered (file
, "sizeof_raw_register_valid_p %ld\n",
1510 regcache
->descr
->sizeof_raw_register_valid_p
);
1511 fprintf_unfiltered (file
, "max_register_size %ld\n",
1512 regcache
->descr
->max_register_size
);
1513 fprintf_unfiltered (file
, "NUM_REGS %d\n", NUM_REGS
);
1514 fprintf_unfiltered (file
, "NUM_PSEUDO_REGS %d\n", NUM_PSEUDO_REGS
);
1517 gdb_assert (regcache
->descr
->nr_cooked_registers
1518 == (NUM_REGS
+ NUM_PSEUDO_REGS
));
1520 for (regnum
= -1; regnum
< regcache
->descr
->nr_cooked_registers
; regnum
++)
1524 fprintf_unfiltered (file
, " %-10s", "Name");
1527 const char *p
= REGISTER_NAME (regnum
);
1530 else if (p
[0] == '\0')
1532 fprintf_unfiltered (file
, " %-10s", p
);
1537 fprintf_unfiltered (file
, " %4s", "Nr");
1539 fprintf_unfiltered (file
, " %4d", regnum
);
1541 /* Relative number. */
1543 fprintf_unfiltered (file
, " %4s", "Rel");
1544 else if (regnum
< NUM_REGS
)
1545 fprintf_unfiltered (file
, " %4d", regnum
);
1547 fprintf_unfiltered (file
, " %4d", (regnum
- NUM_REGS
));
1551 fprintf_unfiltered (file
, " %6s ", "Offset");
1554 fprintf_unfiltered (file
, " %6ld",
1555 regcache
->descr
->register_offset
[regnum
]);
1556 if (register_offset
!= regcache
->descr
->register_offset
[regnum
]
1557 || register_offset
!= REGISTER_BYTE (regnum
)
1559 && (regcache
->descr
->register_offset
[regnum
]
1560 != (regcache
->descr
->register_offset
[regnum
- 1]
1561 + regcache
->descr
->sizeof_register
[regnum
- 1])))
1564 if (!footnote_register_offset
)
1565 footnote_register_offset
= ++footnote_nr
;
1566 fprintf_unfiltered (file
, "*%d", footnote_register_offset
);
1569 fprintf_unfiltered (file
, " ");
1570 register_offset
= (regcache
->descr
->register_offset
[regnum
]
1571 + regcache
->descr
->sizeof_register
[regnum
]);
1576 fprintf_unfiltered (file
, " %5s ", "Size");
1579 fprintf_unfiltered (file
, " %5ld",
1580 regcache
->descr
->sizeof_register
[regnum
]);
1581 if ((regcache
->descr
->sizeof_register
[regnum
]
1582 != REGISTER_RAW_SIZE (regnum
))
1583 || (regcache
->descr
->sizeof_register
[regnum
]
1584 != REGISTER_VIRTUAL_SIZE (regnum
))
1585 || (regcache
->descr
->sizeof_register
[regnum
]
1586 != TYPE_LENGTH (register_type (regcache
->descr
->gdbarch
,
1590 if (!footnote_register_size
)
1591 footnote_register_size
= ++footnote_nr
;
1592 fprintf_unfiltered (file
, "*%d", footnote_register_size
);
1595 fprintf_unfiltered (file
, " ");
1605 static const char blt
[] = "builtin_type";
1606 t
= TYPE_NAME (register_type (regcache
->descr
->gdbarch
, regnum
));
1610 if (!footnote_register_type_name_null
)
1611 footnote_register_type_name_null
= ++footnote_nr
;
1612 xasprintf (&n
, "*%d", footnote_register_type_name_null
);
1613 make_cleanup (xfree
, n
);
1616 /* Chop a leading builtin_type. */
1617 if (strncmp (t
, blt
, strlen (blt
)) == 0)
1620 fprintf_unfiltered (file
, " %-15s", t
);
1623 /* Leading space always present. */
1624 fprintf_unfiltered (file
, " ");
1627 if (what_to_dump
== regcache_dump_raw
)
1630 fprintf_unfiltered (file
, "Raw value");
1631 else if (regnum
>= regcache
->descr
->nr_raw_registers
)
1632 fprintf_unfiltered (file
, "<cooked>");
1633 else if (!regcache_valid_p (regcache
, regnum
))
1634 fprintf_unfiltered (file
, "<invalid>");
1637 regcache_raw_read (regcache
, regnum
, buf
);
1638 fprintf_unfiltered (file
, "0x");
1639 dump_endian_bytes (file
, TARGET_BYTE_ORDER
, buf
,
1640 REGISTER_RAW_SIZE (regnum
));
1644 /* Value, cooked. */
1645 if (what_to_dump
== regcache_dump_cooked
)
1648 fprintf_unfiltered (file
, "Cooked value");
1651 regcache_cooked_read (regcache
, regnum
, buf
);
1652 fprintf_unfiltered (file
, "0x");
1653 dump_endian_bytes (file
, TARGET_BYTE_ORDER
, buf
,
1654 REGISTER_VIRTUAL_SIZE (regnum
));
1658 /* Group members. */
1659 if (what_to_dump
== regcache_dump_groups
)
1662 fprintf_unfiltered (file
, "Groups");
1666 const char *sep
= "";
1667 for (i
= 0; groups
[i
] != NULL
; i
++)
1669 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, groups
[i
]))
1671 fprintf_unfiltered (file
, "%s%s", sep
, reggroup_name (groups
[i
]));
1678 fprintf_unfiltered (file
, "\n");
1681 if (footnote_register_size
)
1682 fprintf_unfiltered (file
, "*%d: Inconsistent register sizes.\n",
1683 footnote_register_size
);
1684 if (footnote_register_offset
)
1685 fprintf_unfiltered (file
, "*%d: Inconsistent register offsets.\n",
1686 footnote_register_offset
);
1687 if (footnote_register_type_name_null
)
1688 fprintf_unfiltered (file
,
1689 "*%d: Register type's name NULL.\n",
1690 footnote_register_type_name_null
);
1691 do_cleanups (cleanups
);
1695 regcache_print (char *args
, enum regcache_dump_what what_to_dump
)
1698 regcache_dump (current_regcache
, gdb_stdout
, what_to_dump
);
1701 struct ui_file
*file
= gdb_fopen (args
, "w");
1703 perror_with_name ("maintenance print architecture");
1704 regcache_dump (current_regcache
, file
, what_to_dump
);
1705 ui_file_delete (file
);
1710 maintenance_print_registers (char *args
, int from_tty
)
1712 regcache_print (args
, regcache_dump_none
);
1716 maintenance_print_raw_registers (char *args
, int from_tty
)
1718 regcache_print (args
, regcache_dump_raw
);
1722 maintenance_print_cooked_registers (char *args
, int from_tty
)
1724 regcache_print (args
, regcache_dump_cooked
);
1728 maintenance_print_register_groups (char *args
, int from_tty
)
1730 regcache_print (args
, regcache_dump_groups
);
1734 _initialize_regcache (void)
1736 regcache_descr_handle
= register_gdbarch_data (init_regcache_descr
,
1737 xfree_regcache_descr
);
1738 REGISTER_GDBARCH_SWAP (current_regcache
);
1739 register_gdbarch_swap (®isters
, sizeof (registers
), NULL
);
1740 register_gdbarch_swap (&deprecated_register_valid
, sizeof (deprecated_register_valid
), NULL
);
1741 register_gdbarch_swap (NULL
, 0, build_regcache
);
1743 add_com ("flushregs", class_maintenance
, reg_flush_command
,
1744 "Force gdb to flush its register cache (maintainer command)");
1746 /* Initialize the thread/process associated with the current set of
1747 registers. For now, -1 is special, and means `no current process'. */
1748 registers_ptid
= pid_to_ptid (-1);
1750 add_cmd ("registers", class_maintenance
,
1751 maintenance_print_registers
,
1752 "Print the internal register configuration.\
1753 Takes an optional file parameter.",
1754 &maintenanceprintlist
);
1755 add_cmd ("raw-registers", class_maintenance
,
1756 maintenance_print_raw_registers
,
1757 "Print the internal register configuration including raw values.\
1758 Takes an optional file parameter.",
1759 &maintenanceprintlist
);
1760 add_cmd ("cooked-registers", class_maintenance
,
1761 maintenance_print_cooked_registers
,
1762 "Print the internal register configuration including cooked values.\
1763 Takes an optional file parameter.",
1764 &maintenanceprintlist
);
1765 add_cmd ("register-groups", class_maintenance
,
1766 maintenance_print_register_groups
,
1767 "Print the internal register configuration including each register's group.\
1768 Takes an optional file parameter.",
1769 &maintenanceprintlist
);