1 /* Cache and manage the values of registers for GDB, the GNU debugger.
3 Copyright 1986, 1987, 1989, 1991, 1994, 1995, 1996, 1998, 2000,
4 2001, 2002 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
29 #include "reggroups.h"
30 #include "gdb_assert.h"
31 #include "gdb_string.h"
32 #include "gdbcmd.h" /* For maintenanceprintlist. */
37 * Here is the actual register cache.
40 /* Per-architecture object describing the layout of a register cache.
41 Computed once when the architecture is created */
43 struct gdbarch_data
*regcache_descr_handle
;
47 /* The architecture this descriptor belongs to. */
48 struct gdbarch
*gdbarch
;
50 /* Is this a ``legacy'' register cache? Such caches reserve space
51 for raw and pseudo registers and allow access to both. */
54 /* The raw register cache. This should contain just [0
55 .. NUM_RAW_REGISTERS). However, for older targets, it contains
56 space for the full [0 .. NUM_RAW_REGISTERS +
57 NUM_PSEUDO_REGISTERS). */
59 long sizeof_raw_registers
;
60 long sizeof_raw_register_valid_p
;
62 /* The cooked register space. Each cooked register in the range
63 [0..NR_RAW_REGISTERS) is direct-mapped onto the corresponding raw
64 register. The remaining [NR_RAW_REGISTERS
65 .. NR_COOKED_REGISTERS) (a.k.a. pseudo regiters) are mapped onto
66 both raw registers and memory by the architecture methods
67 gdbarch_register_read and gdbarch_register_write. */
68 int nr_cooked_registers
;
69 long sizeof_cooked_registers
;
70 long sizeof_cooked_register_valid_p
;
72 /* Offset and size (in 8 bit bytes), of reach register in the
73 register cache. All registers (including those in the range
74 [NR_RAW_REGISTERS .. NR_COOKED_REGISTERS) are given an offset.
75 Assigning all registers an offset makes it possible to keep
76 legacy code, such as that found in read_register_bytes() and
77 write_register_bytes() working. */
78 long *register_offset
;
79 long *sizeof_register
;
81 /* Useful constant. Largest of all the registers. */
82 long max_register_size
;
84 /* Cached table containing the type of each register. */
85 struct type
**register_type
;
89 init_legacy_regcache_descr (struct gdbarch
*gdbarch
,
90 struct regcache_descr
*descr
)
93 /* FIXME: cagney/2002-05-11: gdbarch_data() should take that
94 ``gdbarch'' as a parameter. */
95 gdb_assert (gdbarch
!= NULL
);
97 /* FIXME: cagney/2002-05-11: Shouldn't be including pseudo-registers
98 in the register cache. Unfortunatly some architectures still
99 rely on this and the pseudo_register_write() method. */
100 descr
->nr_raw_registers
= descr
->nr_cooked_registers
;
101 descr
->sizeof_raw_register_valid_p
= descr
->sizeof_cooked_register_valid_p
;
103 /* Compute the offset of each register. Legacy architectures define
104 REGISTER_BYTE() so use that. */
105 /* FIXME: cagney/2002-11-07: Instead of using REGISTER_BYTE() this
106 code should, as is done in init_regcache_descr(), compute the
107 offets at runtime. This currently isn't possible as some ISAs
108 define overlapping register regions - see the mess in
109 read_register_bytes() and write_register_bytes() registers. */
110 descr
->sizeof_register
= XCALLOC (descr
->nr_cooked_registers
, long);
111 descr
->register_offset
= XCALLOC (descr
->nr_cooked_registers
, long);
112 descr
->max_register_size
= 0;
113 for (i
= 0; i
< descr
->nr_cooked_registers
; i
++)
115 /* FIXME: cagney/2001-12-04: This code shouldn't need to use
116 REGISTER_BYTE(). Unfortunatly, legacy code likes to lay the
117 buffer out so that certain registers just happen to overlap.
118 Ulgh! New targets use gdbarch's register read/write and
119 entirely avoid this uglyness. */
120 descr
->register_offset
[i
] = REGISTER_BYTE (i
);
121 descr
->sizeof_register
[i
] = REGISTER_RAW_SIZE (i
);
122 if (descr
->max_register_size
< REGISTER_RAW_SIZE (i
))
123 descr
->max_register_size
= REGISTER_RAW_SIZE (i
);
124 if (descr
->max_register_size
< REGISTER_VIRTUAL_SIZE (i
))
125 descr
->max_register_size
= REGISTER_VIRTUAL_SIZE (i
);
128 /* Compute the real size of the register buffer. Start out by
129 trusting REGISTER_BYTES, but then adjust it upwards should that
130 be found to not be sufficient. */
131 /* FIXME: cagney/2002-11-05: Instead of using REGISTER_BYTES, this
132 code should, as is done in init_regcache_descr(), compute the
133 total number of register bytes using the accumulated offsets. */
134 descr
->sizeof_cooked_registers
= REGISTER_BYTES
; /* OK use. */
135 for (i
= 0; i
< descr
->nr_cooked_registers
; i
++)
138 /* Keep extending the buffer so that there is always enough
139 space for all registers. The comparison is necessary since
140 legacy code is free to put registers in random places in the
141 buffer separated by holes. Once REGISTER_BYTE() is killed
142 this can be greatly simplified. */
143 regend
= descr
->register_offset
[i
] + descr
->sizeof_register
[i
];
144 if (descr
->sizeof_cooked_registers
< regend
)
145 descr
->sizeof_cooked_registers
= regend
;
147 /* FIXME: cagney/2002-05-11: Shouldn't be including pseudo-registers
148 in the register cache. Unfortunatly some architectures still
149 rely on this and the pseudo_register_write() method. */
150 descr
->sizeof_raw_registers
= descr
->sizeof_cooked_registers
;
154 init_regcache_descr (struct gdbarch
*gdbarch
)
157 struct regcache_descr
*descr
;
158 gdb_assert (gdbarch
!= NULL
);
160 /* Create an initial, zero filled, table. */
161 descr
= XCALLOC (1, struct regcache_descr
);
162 descr
->gdbarch
= gdbarch
;
164 /* Total size of the register space. The raw registers are mapped
165 directly onto the raw register cache while the pseudo's are
166 either mapped onto raw-registers or memory. */
167 descr
->nr_cooked_registers
= NUM_REGS
+ NUM_PSEUDO_REGS
;
168 descr
->sizeof_cooked_register_valid_p
= NUM_REGS
+ NUM_PSEUDO_REGS
;
170 /* Fill in a table of register types. */
171 descr
->register_type
= XCALLOC (descr
->nr_cooked_registers
,
173 for (i
= 0; i
< descr
->nr_cooked_registers
; i
++)
175 descr
->register_type
[i
] = REGISTER_VIRTUAL_TYPE (i
);
178 /* If an old style architecture, fill in the remainder of the
179 register cache descriptor using the register macros. */
180 if (!gdbarch_pseudo_register_read_p (gdbarch
)
181 && !gdbarch_pseudo_register_write_p (gdbarch
))
184 init_legacy_regcache_descr (gdbarch
, descr
);
188 /* Construct a strictly RAW register cache. Don't allow pseudo's
189 into the register cache. */
190 descr
->nr_raw_registers
= NUM_REGS
;
192 /* FIXME: cagney/2002-08-13: Overallocate the register_valid_p
193 array. This pretects GDB from erant code that accesses elements
194 of the global register_valid_p[] array in the range [NUM_REGS
195 .. NUM_REGS + NUM_PSEUDO_REGS). */
196 descr
->sizeof_raw_register_valid_p
= descr
->sizeof_cooked_register_valid_p
;
198 /* Lay out the register cache.
200 NOTE: cagney/2002-05-22: Only register_type() is used when
201 constructing the register cache. It is assumed that the
202 register's raw size, virtual size and type length are all the
207 descr
->sizeof_register
= XCALLOC (descr
->nr_cooked_registers
, long);
208 descr
->register_offset
= XCALLOC (descr
->nr_cooked_registers
, long);
209 descr
->max_register_size
= 0;
210 for (i
= 0; i
< descr
->nr_cooked_registers
; i
++)
212 descr
->sizeof_register
[i
] = TYPE_LENGTH (descr
->register_type
[i
]);
213 descr
->register_offset
[i
] = offset
;
214 offset
+= descr
->sizeof_register
[i
];
215 if (descr
->max_register_size
< descr
->sizeof_register
[i
])
216 descr
->max_register_size
= descr
->sizeof_register
[i
];
218 /* Set the real size of the register cache buffer. */
219 descr
->sizeof_cooked_registers
= offset
;
222 /* FIXME: cagney/2002-05-22: Should only need to allocate space for
223 the raw registers. Unfortunatly some code still accesses the
224 register array directly using the global registers[]. Until that
225 code has been purged, play safe and over allocating the register
227 descr
->sizeof_raw_registers
= descr
->sizeof_cooked_registers
;
230 /* Sanity check. Confirm that the assumptions about gdbarch are
231 true. The REGCACHE_DESCR_HANDLE is set before doing the checks
232 so that targets using the generic methods supplied by regcache
233 don't go into infinite recursion trying to, again, create the
235 set_gdbarch_data (gdbarch
, regcache_descr_handle
, descr
);
236 for (i
= 0; i
< descr
->nr_cooked_registers
; i
++)
238 gdb_assert (descr
->sizeof_register
[i
] == REGISTER_RAW_SIZE (i
));
239 gdb_assert (descr
->sizeof_register
[i
] == REGISTER_VIRTUAL_SIZE (i
));
240 gdb_assert (descr
->register_offset
[i
] == REGISTER_BYTE (i
));
242 /* gdb_assert (descr->sizeof_raw_registers == REGISTER_BYTES (i)); */
248 static struct regcache_descr
*
249 regcache_descr (struct gdbarch
*gdbarch
)
251 return gdbarch_data (gdbarch
, regcache_descr_handle
);
255 xfree_regcache_descr (struct gdbarch
*gdbarch
, void *ptr
)
257 struct regcache_descr
*descr
= ptr
;
260 xfree (descr
->register_offset
);
261 xfree (descr
->sizeof_register
);
262 descr
->register_offset
= NULL
;
263 descr
->sizeof_register
= NULL
;
267 /* Utility functions returning useful register attributes stored in
268 the regcache descr. */
271 register_type (struct gdbarch
*gdbarch
, int regnum
)
273 struct regcache_descr
*descr
= regcache_descr (gdbarch
);
274 gdb_assert (regnum
>= 0 && regnum
< descr
->nr_cooked_registers
);
275 return descr
->register_type
[regnum
];
278 /* Utility functions returning useful register attributes stored in
279 the regcache descr. */
282 max_register_size (struct gdbarch
*gdbarch
)
284 struct regcache_descr
*descr
= regcache_descr (gdbarch
);
285 return descr
->max_register_size
;
288 /* The register cache for storing raw register values. */
292 struct regcache_descr
*descr
;
293 /* The register buffers. A read-only register cache can hold the
294 full [0 .. NUM_REGS + NUM_PSEUDO_REGS) while a read/write
295 register cache can only hold [0 .. NUM_REGS). */
297 char *register_valid_p
;
298 /* Is this a read-only cache? A read-only cache is used for saving
299 the target's register state (e.g, across an inferior function
300 call or just before forcing a function return). A read-only
301 cache can only be updated via the methods regcache_dup() and
302 regcache_cpy(). The actual contents are determined by the
303 reggroup_save and reggroup_restore methods. */
308 regcache_xmalloc (struct gdbarch
*gdbarch
)
310 struct regcache_descr
*descr
;
311 struct regcache
*regcache
;
312 gdb_assert (gdbarch
!= NULL
);
313 descr
= regcache_descr (gdbarch
);
314 regcache
= XMALLOC (struct regcache
);
315 regcache
->descr
= descr
;
317 = XCALLOC (descr
->sizeof_raw_registers
, char);
318 regcache
->register_valid_p
319 = XCALLOC (descr
->sizeof_raw_register_valid_p
, char);
320 regcache
->readonly_p
= 1;
325 regcache_xfree (struct regcache
*regcache
)
327 if (regcache
== NULL
)
329 xfree (regcache
->registers
);
330 xfree (regcache
->register_valid_p
);
335 do_regcache_xfree (void *data
)
337 regcache_xfree (data
);
341 make_cleanup_regcache_xfree (struct regcache
*regcache
)
343 return make_cleanup (do_regcache_xfree
, regcache
);
346 /* Return a pointer to register REGNUM's buffer cache. */
349 register_buffer (struct regcache
*regcache
, int regnum
)
351 return regcache
->registers
+ regcache
->descr
->register_offset
[regnum
];
355 regcache_save (struct regcache
*dst
, struct regcache
*src
)
357 struct gdbarch
*gdbarch
= dst
->descr
->gdbarch
;
359 /* The SRC and DST register caches had better belong to the same
361 gdb_assert (src
->descr
->gdbarch
== dst
->descr
->gdbarch
);
362 /* The DST should be `read-only', if it wasn't then the save would
363 end up trying to write the register values out through to the
365 gdb_assert (!src
->readonly_p
);
366 gdb_assert (dst
->readonly_p
);
367 /* Clear the dest. */
368 memset (dst
->registers
, 0, dst
->descr
->sizeof_cooked_registers
);
369 memset (dst
->register_valid_p
, 0, dst
->descr
->sizeof_cooked_register_valid_p
);
370 /* Copy over any registers (identified by their membership in the
371 save_reggroup) and mark them as valid. The full [0
372 .. NUM_REGS+NUM_PSEUDO_REGS) range is checked since some
373 architectures need to save/restore `cooked' registers that live
375 for (regnum
= 0; regnum
< dst
->descr
->nr_cooked_registers
; regnum
++)
377 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, save_reggroup
))
379 regcache_cooked_read (src
, regnum
, register_buffer (dst
, regnum
));
380 dst
->register_valid_p
[regnum
] = 1;
386 regcache_restore (struct regcache
*dst
, struct regcache
*src
)
388 struct gdbarch
*gdbarch
= dst
->descr
->gdbarch
;
390 gdb_assert (src
->descr
->gdbarch
== dst
->descr
->gdbarch
);
391 gdb_assert (!dst
->readonly_p
);
392 gdb_assert (src
->readonly_p
);
393 /* Copy over any registers, being careful to only restore those that
394 were both saved and need to be restored. The full [0
395 .. NUM_REGS+NUM_PSEUDO_REGS) range is checked since some
396 architectures need to save/restore `cooked' registers that live
398 for (regnum
= 0; regnum
< src
->descr
->nr_cooked_registers
; regnum
++)
400 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, restore_reggroup
)
401 && src
->register_valid_p
[regnum
])
403 regcache_cooked_write (dst
, regnum
, register_buffer (src
, regnum
));
409 regcache_cpy (struct regcache
*dst
, struct regcache
*src
)
413 gdb_assert (src
!= NULL
&& dst
!= NULL
);
414 gdb_assert (src
->descr
->gdbarch
== dst
->descr
->gdbarch
);
415 gdb_assert (src
!= dst
);
416 gdb_assert (src
->readonly_p
|| dst
->readonly_p
);
417 if (!src
->readonly_p
)
418 regcache_save (dst
, src
);
419 else if (!dst
->readonly_p
)
420 regcache_restore (dst
, src
);
422 regcache_cpy_no_passthrough (dst
, src
);
426 regcache_cpy_no_passthrough (struct regcache
*dst
, struct regcache
*src
)
429 gdb_assert (src
!= NULL
&& dst
!= NULL
);
430 gdb_assert (src
->descr
->gdbarch
== dst
->descr
->gdbarch
);
431 /* NOTE: cagney/2002-05-17: Don't let the caller do a no-passthrough
432 move of data into the current_regcache(). Doing this would be
433 silly - it would mean that valid_p would be completly invalid. */
434 gdb_assert (dst
!= current_regcache
);
435 memcpy (dst
->registers
, src
->registers
, dst
->descr
->sizeof_raw_registers
);
436 memcpy (dst
->register_valid_p
, src
->register_valid_p
,
437 dst
->descr
->sizeof_raw_register_valid_p
);
441 regcache_dup (struct regcache
*src
)
443 struct regcache
*newbuf
;
444 gdb_assert (current_regcache
!= NULL
);
445 newbuf
= regcache_xmalloc (src
->descr
->gdbarch
);
446 regcache_cpy (newbuf
, src
);
451 regcache_dup_no_passthrough (struct regcache
*src
)
453 struct regcache
*newbuf
;
454 gdb_assert (current_regcache
!= NULL
);
455 newbuf
= regcache_xmalloc (src
->descr
->gdbarch
);
456 regcache_cpy_no_passthrough (newbuf
, src
);
461 regcache_valid_p (struct regcache
*regcache
, int regnum
)
463 gdb_assert (regcache
!= NULL
);
464 gdb_assert (regnum
>= 0 && regnum
< regcache
->descr
->nr_raw_registers
);
465 return regcache
->register_valid_p
[regnum
];
469 deprecated_grub_regcache_for_registers (struct regcache
*regcache
)
471 return regcache
->registers
;
475 deprecated_grub_regcache_for_register_valid (struct regcache
*regcache
)
477 return regcache
->register_valid_p
;
480 /* Global structure containing the current regcache. */
481 /* FIXME: cagney/2002-05-11: The two global arrays registers[] and
482 deprecated_register_valid[] currently point into this structure. */
483 struct regcache
*current_regcache
;
485 /* NOTE: this is a write-through cache. There is no "dirty" bit for
486 recording if the register values have been changed (eg. by the
487 user). Therefore all registers must be written back to the
488 target when appropriate. */
490 /* REGISTERS contains the cached register values (in target byte order). */
492 char *deprecated_registers
;
494 /* DEPRECATED_REGISTER_VALID is 0 if the register needs to be fetched,
495 1 if it has been fetched, and
496 -1 if the register value was not available.
498 "Not available" indicates that the target is not not able to supply
499 the register at this state. The register may become available at a
500 later time (after the next resume). This often occures when GDB is
501 manipulating a target that contains only a snapshot of the entire
502 system being debugged - some of the registers in such a system may
503 not have been saved. */
505 signed char *deprecated_register_valid
;
507 /* The thread/process associated with the current set of registers. */
509 static ptid_t registers_ptid
;
517 Returns 0 if the value is not in the cache (needs fetch).
518 >0 if the value is in the cache.
519 <0 if the value is permanently unavailable (don't ask again). */
522 register_cached (int regnum
)
524 return deprecated_register_valid
[regnum
];
527 /* Record that REGNUM's value is cached if STATE is >0, uncached but
528 fetchable if STATE is 0, and uncached and unfetchable if STATE is <0. */
531 set_register_cached (int regnum
, int state
)
533 gdb_assert (regnum
>= 0);
534 gdb_assert (regnum
< current_regcache
->descr
->nr_raw_registers
);
535 current_regcache
->register_valid_p
[regnum
] = state
;
538 /* Return whether register REGNUM is a real register. */
541 real_register (int regnum
)
543 return regnum
>= 0 && regnum
< NUM_REGS
;
546 /* Low level examining and depositing of registers.
548 The caller is responsible for making sure that the inferior is
549 stopped before calling the fetching routines, or it will get
550 garbage. (a change from GDB version 3, in which the caller got the
551 value from the last stop). */
553 /* REGISTERS_CHANGED ()
555 Indicate that registers may have changed, so invalidate the cache. */
558 registers_changed (void)
562 registers_ptid
= pid_to_ptid (-1);
564 /* Force cleanup of any alloca areas if using C alloca instead of
565 a builtin alloca. This particular call is used to clean up
566 areas allocated by low level target code which may build up
567 during lengthy interactions between gdb and the target before
568 gdb gives control to the user (ie watchpoints). */
571 for (i
= 0; i
< current_regcache
->descr
->nr_raw_registers
; i
++)
572 set_register_cached (i
, 0);
574 if (registers_changed_hook
)
575 registers_changed_hook ();
578 /* DEPRECATED_REGISTERS_FETCHED ()
580 Indicate that all registers have been fetched, so mark them all valid. */
582 /* NOTE: cagney/2001-12-04: This function does not set valid on the
583 pseudo-register range since pseudo registers are always supplied
584 using supply_register(). */
585 /* FIXME: cagney/2001-12-04: This function is DEPRECATED. The target
586 code was blatting the registers[] array and then calling this.
587 Since targets should only be using supply_register() the need for
588 this function/hack is eliminated. */
591 deprecated_registers_fetched (void)
595 for (i
= 0; i
< NUM_REGS
; i
++)
596 set_register_cached (i
, 1);
597 /* Do not assume that the pseudo-regs have also been fetched.
598 Fetching all real regs NEVER accounts for pseudo-regs. */
601 /* deprecated_read_register_bytes and deprecated_write_register_bytes
602 are generally a *BAD* idea. They are inefficient because they need
603 to check for partial updates, which can only be done by scanning
604 through all of the registers and seeing if the bytes that are being
605 read/written fall inside of an invalid register. [The main reason
606 this is necessary is that register sizes can vary, so a simple
607 index won't suffice.] It is far better to call read_register_gen
608 and write_register_gen if you want to get at the raw register
609 contents, as it only takes a regnum as an argument, and therefore
610 can't do a partial register update.
612 Prior to the recent fixes to check for partial updates, both read
613 and deprecated_write_register_bytes always checked to see if any
614 registers were stale, and then called target_fetch_registers (-1)
615 to update the whole set. This caused really slowed things down for
618 /* Copy INLEN bytes of consecutive data from registers
619 starting with the INREGBYTE'th byte of register data
620 into memory at MYADDR. */
623 deprecated_read_register_bytes (int in_start
, char *in_buf
, int in_len
)
625 int in_end
= in_start
+ in_len
;
627 char *reg_buf
= alloca (MAX_REGISTER_RAW_SIZE
);
629 /* See if we are trying to read bytes from out-of-date registers. If so,
630 update just those registers. */
632 for (regnum
= 0; regnum
< NUM_REGS
+ NUM_PSEUDO_REGS
; regnum
++)
641 reg_start
= REGISTER_BYTE (regnum
);
642 reg_len
= REGISTER_RAW_SIZE (regnum
);
643 reg_end
= reg_start
+ reg_len
;
645 if (reg_end
<= in_start
|| in_end
<= reg_start
)
646 /* The range the user wants to read doesn't overlap with regnum. */
649 if (REGISTER_NAME (regnum
) != NULL
&& *REGISTER_NAME (regnum
) != '\0')
650 /* Force the cache to fetch the entire register. */
651 deprecated_read_register_gen (regnum
, reg_buf
);
653 /* Legacy note: even though this register is ``invalid'' we
654 still need to return something. It would appear that some
655 code relies on apparent gaps in the register array also
657 /* FIXME: cagney/2001-08-18: This is just silly. It defeats
658 the entire register read/write flow of control. Must
659 resist temptation to return 0xdeadbeef. */
660 memcpy (reg_buf
, &deprecated_registers
[reg_start
], reg_len
);
662 /* Legacy note: This function, for some reason, allows a NULL
663 input buffer. If the buffer is NULL, the registers are still
664 fetched, just the final transfer is skipped. */
668 /* start = max (reg_start, in_start) */
669 if (reg_start
> in_start
)
674 /* end = min (reg_end, in_end) */
675 if (reg_end
< in_end
)
680 /* Transfer just the bytes common to both IN_BUF and REG_BUF */
681 for (byte
= start
; byte
< end
; byte
++)
683 in_buf
[byte
- in_start
] = reg_buf
[byte
- reg_start
];
688 /* Read register REGNUM into memory at MYADDR, which must be large
689 enough for REGISTER_RAW_BYTES (REGNUM). Target byte-order. If the
690 register is known to be the size of a CORE_ADDR or smaller,
691 read_register can be used instead. */
694 legacy_read_register_gen (int regnum
, char *myaddr
)
696 gdb_assert (regnum
>= 0 && regnum
< (NUM_REGS
+ NUM_PSEUDO_REGS
));
697 if (! ptid_equal (registers_ptid
, inferior_ptid
))
699 registers_changed ();
700 registers_ptid
= inferior_ptid
;
703 if (!register_cached (regnum
))
704 target_fetch_registers (regnum
);
706 memcpy (myaddr
, register_buffer (current_regcache
, regnum
),
707 REGISTER_RAW_SIZE (regnum
));
711 regcache_raw_read (struct regcache
*regcache
, int regnum
, void *buf
)
713 gdb_assert (regcache
!= NULL
&& buf
!= NULL
);
714 gdb_assert (regnum
>= 0 && regnum
< regcache
->descr
->nr_raw_registers
);
715 if (regcache
->descr
->legacy_p
716 && !regcache
->readonly_p
)
718 gdb_assert (regcache
== current_regcache
);
719 /* For moment, just use underlying legacy code. Ulgh!!! This
720 silently and very indirectly updates the regcache's regcache
721 via the global deprecated_register_valid[]. */
722 legacy_read_register_gen (regnum
, buf
);
725 /* Make certain that the register cache is up-to-date with respect
726 to the current thread. This switching shouldn't be necessary
727 only there is still only one target side register cache. Sigh!
728 On the bright side, at least there is a regcache object. */
729 if (!regcache
->readonly_p
)
731 gdb_assert (regcache
== current_regcache
);
732 if (! ptid_equal (registers_ptid
, inferior_ptid
))
734 registers_changed ();
735 registers_ptid
= inferior_ptid
;
737 if (!register_cached (regnum
))
738 target_fetch_registers (regnum
);
740 /* Copy the value directly into the register cache. */
741 memcpy (buf
, register_buffer (regcache
, regnum
),
742 regcache
->descr
->sizeof_register
[regnum
]);
746 regcache_raw_read_signed (struct regcache
*regcache
, int regnum
, LONGEST
*val
)
749 gdb_assert (regcache
!= NULL
);
750 gdb_assert (regnum
>= 0 && regnum
< regcache
->descr
->nr_raw_registers
);
751 buf
= alloca (regcache
->descr
->sizeof_register
[regnum
]);
752 regcache_raw_read (regcache
, regnum
, buf
);
753 (*val
) = extract_signed_integer (buf
,
754 regcache
->descr
->sizeof_register
[regnum
]);
758 regcache_raw_read_unsigned (struct regcache
*regcache
, int regnum
,
762 gdb_assert (regcache
!= NULL
);
763 gdb_assert (regnum
>= 0 && regnum
< regcache
->descr
->nr_raw_registers
);
764 buf
= alloca (regcache
->descr
->sizeof_register
[regnum
]);
765 regcache_raw_read (regcache
, regnum
, buf
);
766 (*val
) = extract_unsigned_integer (buf
,
767 regcache
->descr
->sizeof_register
[regnum
]);
771 regcache_raw_write_signed (struct regcache
*regcache
, int regnum
, LONGEST val
)
774 gdb_assert (regcache
!= NULL
);
775 gdb_assert (regnum
>=0 && regnum
< regcache
->descr
->nr_raw_registers
);
776 buf
= alloca (regcache
->descr
->sizeof_register
[regnum
]);
777 store_signed_integer (buf
, regcache
->descr
->sizeof_register
[regnum
], val
);
778 regcache_raw_write (regcache
, regnum
, buf
);
782 regcache_raw_write_unsigned (struct regcache
*regcache
, int regnum
,
786 gdb_assert (regcache
!= NULL
);
787 gdb_assert (regnum
>=0 && regnum
< regcache
->descr
->nr_raw_registers
);
788 buf
= alloca (regcache
->descr
->sizeof_register
[regnum
]);
789 store_unsigned_integer (buf
, regcache
->descr
->sizeof_register
[regnum
], val
);
790 regcache_raw_write (regcache
, regnum
, buf
);
794 deprecated_read_register_gen (int regnum
, char *buf
)
796 gdb_assert (current_regcache
!= NULL
);
797 gdb_assert (current_regcache
->descr
->gdbarch
== current_gdbarch
);
798 if (current_regcache
->descr
->legacy_p
)
800 legacy_read_register_gen (regnum
, buf
);
803 regcache_cooked_read (current_regcache
, regnum
, buf
);
807 regcache_cooked_read (struct regcache
*regcache
, int regnum
, void *buf
)
809 gdb_assert (regnum
>= 0);
810 gdb_assert (regnum
< regcache
->descr
->nr_cooked_registers
);
811 if (regnum
< regcache
->descr
->nr_raw_registers
)
812 regcache_raw_read (regcache
, regnum
, buf
);
813 else if (regcache
->readonly_p
814 && regnum
< regcache
->descr
->nr_cooked_registers
815 && regcache
->register_valid_p
[regnum
])
816 /* Read-only register cache, perhaphs the cooked value was cached? */
817 memcpy (buf
, register_buffer (regcache
, regnum
),
818 regcache
->descr
->sizeof_register
[regnum
]);
820 gdbarch_pseudo_register_read (regcache
->descr
->gdbarch
, regcache
,
825 regcache_cooked_read_signed (struct regcache
*regcache
, int regnum
,
829 gdb_assert (regcache
!= NULL
);
830 gdb_assert (regnum
>= 0 && regnum
< regcache
->descr
->nr_raw_registers
);
831 buf
= alloca (regcache
->descr
->sizeof_register
[regnum
]);
832 regcache_cooked_read (regcache
, regnum
, buf
);
833 (*val
) = extract_signed_integer (buf
,
834 regcache
->descr
->sizeof_register
[regnum
]);
838 regcache_cooked_read_unsigned (struct regcache
*regcache
, int regnum
,
842 gdb_assert (regcache
!= NULL
);
843 gdb_assert (regnum
>= 0 && regnum
< regcache
->descr
->nr_raw_registers
);
844 buf
= alloca (regcache
->descr
->sizeof_register
[regnum
]);
845 regcache_cooked_read (regcache
, regnum
, buf
);
846 (*val
) = extract_unsigned_integer (buf
,
847 regcache
->descr
->sizeof_register
[regnum
]);
850 /* Write register REGNUM at MYADDR to the target. MYADDR points at
851 REGISTER_RAW_BYTES(REGNUM), which must be in target byte-order. */
854 legacy_write_register_gen (int regnum
, const void *myaddr
)
857 gdb_assert (regnum
>= 0 && regnum
< (NUM_REGS
+ NUM_PSEUDO_REGS
));
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 if (! ptid_equal (registers_ptid
, inferior_ptid
))
866 registers_changed ();
867 registers_ptid
= inferior_ptid
;
870 size
= REGISTER_RAW_SIZE (regnum
);
872 if (real_register (regnum
))
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 (register_cached (regnum
)
877 && (memcmp (register_buffer (current_regcache
, regnum
), myaddr
, size
)
881 target_prepare_to_store ();
884 memcpy (register_buffer (current_regcache
, regnum
), myaddr
, size
);
886 set_register_cached (regnum
, 1);
887 target_store_registers (regnum
);
891 regcache_raw_write (struct regcache
*regcache
, int regnum
, const void *buf
)
893 gdb_assert (regcache
!= NULL
&& buf
!= NULL
);
894 gdb_assert (regnum
>= 0 && regnum
< regcache
->descr
->nr_raw_registers
);
895 gdb_assert (!regcache
->readonly_p
);
897 if (regcache
->descr
->legacy_p
)
899 /* For moment, just use underlying legacy code. Ulgh!!! This
900 silently and very indirectly updates the regcache's buffers
901 via the globals deprecated_register_valid[] and registers[]. */
902 gdb_assert (regcache
== current_regcache
);
903 legacy_write_register_gen (regnum
, buf
);
907 /* On the sparc, writing %g0 is a no-op, so we don't even want to
908 change the registers array if something writes to this register. */
909 if (CANNOT_STORE_REGISTER (regnum
))
912 /* Make certain that the correct cache is selected. */
913 gdb_assert (regcache
== current_regcache
);
914 if (! ptid_equal (registers_ptid
, inferior_ptid
))
916 registers_changed ();
917 registers_ptid
= inferior_ptid
;
920 /* If we have a valid copy of the register, and new value == old
921 value, then don't bother doing the actual store. */
922 if (regcache_valid_p (regcache
, regnum
)
923 && (memcmp (register_buffer (regcache
, regnum
), buf
,
924 regcache
->descr
->sizeof_register
[regnum
]) == 0))
927 target_prepare_to_store ();
928 memcpy (register_buffer (regcache
, regnum
), buf
,
929 regcache
->descr
->sizeof_register
[regnum
]);
930 regcache
->register_valid_p
[regnum
] = 1;
931 target_store_registers (regnum
);
935 deprecated_write_register_gen (int regnum
, char *buf
)
937 gdb_assert (current_regcache
!= NULL
);
938 gdb_assert (current_regcache
->descr
->gdbarch
== current_gdbarch
);
939 if (current_regcache
->descr
->legacy_p
)
941 legacy_write_register_gen (regnum
, buf
);
944 regcache_cooked_write (current_regcache
, regnum
, buf
);
948 regcache_cooked_write (struct regcache
*regcache
, int regnum
, const void *buf
)
950 gdb_assert (regnum
>= 0);
951 gdb_assert (regnum
< regcache
->descr
->nr_cooked_registers
);
952 if (regnum
< regcache
->descr
->nr_raw_registers
)
953 regcache_raw_write (regcache
, regnum
, buf
);
955 gdbarch_pseudo_register_write (regcache
->descr
->gdbarch
, regcache
,
959 /* Copy INLEN bytes of consecutive data from memory at MYADDR
960 into registers starting with the MYREGSTART'th byte of register data. */
963 deprecated_write_register_bytes (int myregstart
, char *myaddr
, int inlen
)
965 int myregend
= myregstart
+ inlen
;
968 target_prepare_to_store ();
970 /* Scan through the registers updating any that are covered by the
971 range myregstart<=>myregend using write_register_gen, which does
972 nice things like handling threads, and avoiding updates when the
973 new and old contents are the same. */
975 for (regnum
= 0; regnum
< NUM_REGS
+ NUM_PSEUDO_REGS
; regnum
++)
977 int regstart
, regend
;
979 regstart
= REGISTER_BYTE (regnum
);
980 regend
= regstart
+ REGISTER_RAW_SIZE (regnum
);
982 /* Is this register completely outside the range the user is writing? */
983 if (myregend
<= regstart
|| regend
<= myregstart
)
986 /* Is this register completely within the range the user is writing? */
987 else if (myregstart
<= regstart
&& regend
<= myregend
)
988 deprecated_write_register_gen (regnum
, myaddr
+ (regstart
- myregstart
));
990 /* The register partially overlaps the range being written. */
993 char *regbuf
= (char*) alloca (MAX_REGISTER_RAW_SIZE
);
994 /* What's the overlap between this register's bytes and
995 those the caller wants to write? */
996 int overlapstart
= max (regstart
, myregstart
);
997 int overlapend
= min (regend
, myregend
);
999 /* We may be doing a partial update of an invalid register.
1000 Update it from the target before scribbling on it. */
1001 deprecated_read_register_gen (regnum
, regbuf
);
1003 memcpy (&deprecated_registers
[overlapstart
],
1004 myaddr
+ (overlapstart
- myregstart
),
1005 overlapend
- overlapstart
);
1007 target_store_registers (regnum
);
1012 /* Perform a partial register transfer using a read, modify, write
1015 typedef void (regcache_read_ftype
) (struct regcache
*regcache
, int regnum
,
1017 typedef void (regcache_write_ftype
) (struct regcache
*regcache
, int regnum
,
1021 regcache_xfer_part (struct regcache
*regcache
, int regnum
,
1022 int offset
, int len
, void *in
, const void *out
,
1023 regcache_read_ftype
*read
, regcache_write_ftype
*write
)
1025 struct regcache_descr
*descr
= regcache
->descr
;
1026 bfd_byte
*reg
= alloca (descr
->max_register_size
);
1027 gdb_assert (offset
>= 0 && offset
<= descr
->sizeof_register
[regnum
]);
1028 gdb_assert (len
>= 0 && offset
+ len
<= descr
->sizeof_register
[regnum
]);
1029 /* Something to do? */
1030 if (offset
+ len
== 0)
1032 /* Read (when needed) ... */
1035 || offset
+ len
< descr
->sizeof_register
[regnum
])
1037 gdb_assert (read
!= NULL
);
1038 read (regcache
, regnum
, reg
);
1040 /* ... modify ... */
1042 memcpy (in
, reg
+ offset
, len
);
1044 memcpy (reg
+ offset
, out
, len
);
1045 /* ... write (when needed). */
1048 gdb_assert (write
!= NULL
);
1049 write (regcache
, regnum
, reg
);
1054 regcache_raw_read_part (struct regcache
*regcache
, int regnum
,
1055 int offset
, int len
, void *buf
)
1057 struct regcache_descr
*descr
= regcache
->descr
;
1058 gdb_assert (regnum
>= 0 && regnum
< descr
->nr_raw_registers
);
1059 regcache_xfer_part (regcache
, regnum
, offset
, len
, buf
, NULL
,
1060 regcache_raw_read
, regcache_raw_write
);
1064 regcache_raw_write_part (struct regcache
*regcache
, int regnum
,
1065 int offset
, int len
, const void *buf
)
1067 struct regcache_descr
*descr
= regcache
->descr
;
1068 gdb_assert (regnum
>= 0 && regnum
< descr
->nr_raw_registers
);
1069 regcache_xfer_part (regcache
, regnum
, offset
, len
, NULL
, buf
,
1070 regcache_raw_read
, regcache_raw_write
);
1074 regcache_cooked_read_part (struct regcache
*regcache
, int regnum
,
1075 int offset
, int len
, void *buf
)
1077 struct regcache_descr
*descr
= regcache
->descr
;
1078 gdb_assert (regnum
>= 0 && regnum
< descr
->nr_cooked_registers
);
1079 regcache_xfer_part (regcache
, regnum
, offset
, len
, buf
, NULL
,
1080 regcache_cooked_read
, regcache_cooked_write
);
1084 regcache_cooked_write_part (struct regcache
*regcache
, int regnum
,
1085 int offset
, int len
, const void *buf
)
1087 struct regcache_descr
*descr
= regcache
->descr
;
1088 gdb_assert (regnum
>= 0 && regnum
< descr
->nr_cooked_registers
);
1089 regcache_xfer_part (regcache
, regnum
, offset
, len
, NULL
, buf
,
1090 regcache_cooked_read
, regcache_cooked_write
);
1093 /* Hack to keep code that view the register buffer as raw bytes
1097 register_offset_hack (struct gdbarch
*gdbarch
, int regnum
)
1099 struct regcache_descr
*descr
= regcache_descr (gdbarch
);
1100 gdb_assert (regnum
>= 0 && regnum
< descr
->nr_cooked_registers
);
1101 return descr
->register_offset
[regnum
];
1104 /* Return the contents of register REGNUM as an unsigned integer. */
1107 read_register (int regnum
)
1109 char *buf
= alloca (REGISTER_RAW_SIZE (regnum
));
1110 deprecated_read_register_gen (regnum
, buf
);
1111 return (extract_unsigned_integer (buf
, REGISTER_RAW_SIZE (regnum
)));
1115 read_register_pid (int regnum
, ptid_t ptid
)
1121 if (ptid_equal (ptid
, inferior_ptid
))
1122 return read_register (regnum
);
1124 save_ptid
= inferior_ptid
;
1126 inferior_ptid
= ptid
;
1128 retval
= read_register (regnum
);
1130 inferior_ptid
= save_ptid
;
1135 /* Return the contents of register REGNUM as a signed integer. */
1138 read_signed_register (int regnum
)
1140 void *buf
= alloca (REGISTER_RAW_SIZE (regnum
));
1141 deprecated_read_register_gen (regnum
, buf
);
1142 return (extract_signed_integer (buf
, REGISTER_RAW_SIZE (regnum
)));
1146 read_signed_register_pid (int regnum
, ptid_t ptid
)
1151 if (ptid_equal (ptid
, inferior_ptid
))
1152 return read_signed_register (regnum
);
1154 save_ptid
= inferior_ptid
;
1156 inferior_ptid
= ptid
;
1158 retval
= read_signed_register (regnum
);
1160 inferior_ptid
= save_ptid
;
1165 /* Store VALUE into the raw contents of register number REGNUM. */
1168 write_register (int regnum
, LONGEST val
)
1172 size
= REGISTER_RAW_SIZE (regnum
);
1173 buf
= alloca (size
);
1174 store_signed_integer (buf
, size
, (LONGEST
) val
);
1175 deprecated_write_register_gen (regnum
, buf
);
1179 write_register_pid (int regnum
, CORE_ADDR val
, ptid_t ptid
)
1183 if (ptid_equal (ptid
, inferior_ptid
))
1185 write_register (regnum
, val
);
1189 save_ptid
= inferior_ptid
;
1191 inferior_ptid
= ptid
;
1193 write_register (regnum
, val
);
1195 inferior_ptid
= save_ptid
;
1198 /* SUPPLY_REGISTER()
1200 Record that register REGNUM contains VAL. This is used when the
1201 value is obtained from the inferior or core dump, so there is no
1202 need to store the value there.
1204 If VAL is a NULL pointer, then it's probably an unsupported register.
1205 We just set its value to all zeros. We might want to record this
1206 fact, and report it to the users of read_register and friends. */
1209 supply_register (int regnum
, const void *val
)
1212 if (! ptid_equal (registers_ptid
, inferior_ptid
))
1214 registers_changed ();
1215 registers_ptid
= inferior_ptid
;
1219 set_register_cached (regnum
, 1);
1221 memcpy (register_buffer (current_regcache
, regnum
), val
,
1222 REGISTER_RAW_SIZE (regnum
));
1224 memset (register_buffer (current_regcache
, regnum
), '\000',
1225 REGISTER_RAW_SIZE (regnum
));
1227 /* On some architectures, e.g. HPPA, there are a few stray bits in
1228 some registers, that the rest of the code would like to ignore. */
1230 /* NOTE: cagney/2001-03-16: The macro CLEAN_UP_REGISTER_VALUE is
1231 going to be deprecated. Instead architectures will leave the raw
1232 register value as is and instead clean things up as they pass
1233 through the method gdbarch_pseudo_register_read() clean up the
1236 #ifdef DEPRECATED_CLEAN_UP_REGISTER_VALUE
1237 DEPRECATED_CLEAN_UP_REGISTER_VALUE \
1238 (regnum
, register_buffer (current_regcache
, regnum
));
1243 regcache_collect (int regnum
, void *buf
)
1245 memcpy (buf
, register_buffer (current_regcache
, regnum
),
1246 REGISTER_RAW_SIZE (regnum
));
1250 /* read_pc, write_pc, read_sp, write_sp, read_fp, etc. Special
1251 handling for registers PC, SP, and FP. */
1253 /* NOTE: cagney/2001-02-18: The functions generic_target_read_pc(),
1254 read_pc_pid(), read_pc(), generic_target_write_pc(),
1255 write_pc_pid(), write_pc(), generic_target_read_sp(), read_sp(),
1256 generic_target_write_sp(), write_sp(), generic_target_read_fp() and
1257 read_fp(), will eventually be moved out of the reg-cache into
1258 either frame.[hc] or to the multi-arch framework. The are not part
1259 of the raw register cache. */
1261 /* This routine is getting awfully cluttered with #if's. It's probably
1262 time to turn this into READ_PC and define it in the tm.h file.
1265 1999-06-08: The following were re-written so that it assumes the
1266 existence of a TARGET_READ_PC et.al. macro. A default generic
1267 version of that macro is made available where needed.
1269 Since the ``TARGET_READ_PC'' et.al. macro is going to be controlled
1270 by the multi-arch framework, it will eventually be possible to
1271 eliminate the intermediate read_pc_pid(). The client would call
1272 TARGET_READ_PC directly. (cagney). */
1275 generic_target_read_pc (ptid_t ptid
)
1280 CORE_ADDR pc_val
= ADDR_BITS_REMOVE ((CORE_ADDR
) read_register_pid (PC_REGNUM
, ptid
));
1284 internal_error (__FILE__
, __LINE__
,
1285 "generic_target_read_pc");
1290 read_pc_pid (ptid_t ptid
)
1292 ptid_t saved_inferior_ptid
;
1295 /* In case ptid != inferior_ptid. */
1296 saved_inferior_ptid
= inferior_ptid
;
1297 inferior_ptid
= ptid
;
1299 pc_val
= TARGET_READ_PC (ptid
);
1301 inferior_ptid
= saved_inferior_ptid
;
1308 return read_pc_pid (inferior_ptid
);
1312 generic_target_write_pc (CORE_ADDR pc
, ptid_t ptid
)
1316 write_register_pid (PC_REGNUM
, pc
, ptid
);
1317 if (NPC_REGNUM
>= 0)
1318 write_register_pid (NPC_REGNUM
, pc
+ 4, ptid
);
1320 internal_error (__FILE__
, __LINE__
,
1321 "generic_target_write_pc");
1326 write_pc_pid (CORE_ADDR pc
, ptid_t ptid
)
1328 ptid_t saved_inferior_ptid
;
1330 /* In case ptid != inferior_ptid. */
1331 saved_inferior_ptid
= inferior_ptid
;
1332 inferior_ptid
= ptid
;
1334 TARGET_WRITE_PC (pc
, ptid
);
1336 inferior_ptid
= saved_inferior_ptid
;
1340 write_pc (CORE_ADDR pc
)
1342 write_pc_pid (pc
, inferior_ptid
);
1345 /* Cope with strage ways of getting to the stack and frame pointers */
1348 generic_target_read_sp (void)
1352 return read_register (SP_REGNUM
);
1354 internal_error (__FILE__
, __LINE__
,
1355 "generic_target_read_sp");
1361 return TARGET_READ_SP ();
1365 generic_target_write_sp (CORE_ADDR val
)
1370 write_register (SP_REGNUM
, val
);
1374 internal_error (__FILE__
, __LINE__
,
1375 "generic_target_write_sp");
1379 write_sp (CORE_ADDR val
)
1381 TARGET_WRITE_SP (val
);
1385 generic_target_read_fp (void)
1389 return read_register (FP_REGNUM
);
1391 internal_error (__FILE__
, __LINE__
,
1392 "generic_target_read_fp");
1398 return TARGET_READ_FP ();
1403 reg_flush_command (char *command
, int from_tty
)
1405 /* Force-flush the register cache. */
1406 registers_changed ();
1408 printf_filtered ("Register cache flushed.\n");
1412 build_regcache (void)
1414 current_regcache
= regcache_xmalloc (current_gdbarch
);
1415 current_regcache
->readonly_p
= 0;
1416 deprecated_registers
= deprecated_grub_regcache_for_registers (current_regcache
);
1417 deprecated_register_valid
= deprecated_grub_regcache_for_register_valid (current_regcache
);
1421 dump_endian_bytes (struct ui_file
*file
, enum bfd_endian endian
,
1422 const unsigned char *buf
, long len
)
1427 case BFD_ENDIAN_BIG
:
1428 for (i
= 0; i
< len
; i
++)
1429 fprintf_unfiltered (file
, "%02x", buf
[i
]);
1431 case BFD_ENDIAN_LITTLE
:
1432 for (i
= len
- 1; i
>= 0; i
--)
1433 fprintf_unfiltered (file
, "%02x", buf
[i
]);
1436 internal_error (__FILE__
, __LINE__
, "Bad switch");
1440 enum regcache_dump_what
1442 regcache_dump_none
, regcache_dump_raw
, regcache_dump_cooked
, regcache_dump_groups
1446 regcache_dump (struct regcache
*regcache
, struct ui_file
*file
,
1447 enum regcache_dump_what what_to_dump
)
1449 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
1450 struct gdbarch
*gdbarch
= regcache
->descr
->gdbarch
;
1451 struct reggroup
*const *groups
= reggroups (gdbarch
);
1453 int footnote_nr
= 0;
1454 int footnote_register_size
= 0;
1455 int footnote_register_offset
= 0;
1456 int footnote_register_type_name_null
= 0;
1457 long register_offset
= 0;
1458 unsigned char *buf
= alloca (regcache
->descr
->max_register_size
);
1461 fprintf_unfiltered (file
, "legacy_p %d\n", regcache
->descr
->legacy_p
);
1462 fprintf_unfiltered (file
, "nr_raw_registers %d\n",
1463 regcache
->descr
->nr_raw_registers
);
1464 fprintf_unfiltered (file
, "nr_cooked_registers %d\n",
1465 regcache
->descr
->nr_cooked_registers
);
1466 fprintf_unfiltered (file
, "sizeof_raw_registers %ld\n",
1467 regcache
->descr
->sizeof_raw_registers
);
1468 fprintf_unfiltered (file
, "sizeof_raw_register_valid_p %ld\n",
1469 regcache
->descr
->sizeof_raw_register_valid_p
);
1470 fprintf_unfiltered (file
, "max_register_size %ld\n",
1471 regcache
->descr
->max_register_size
);
1472 fprintf_unfiltered (file
, "NUM_REGS %d\n", NUM_REGS
);
1473 fprintf_unfiltered (file
, "NUM_PSEUDO_REGS %d\n", NUM_PSEUDO_REGS
);
1476 gdb_assert (regcache
->descr
->nr_cooked_registers
1477 == (NUM_REGS
+ NUM_PSEUDO_REGS
));
1479 for (regnum
= -1; regnum
< regcache
->descr
->nr_cooked_registers
; regnum
++)
1483 fprintf_unfiltered (file
, " %-10s", "Name");
1486 const char *p
= REGISTER_NAME (regnum
);
1489 else if (p
[0] == '\0')
1491 fprintf_unfiltered (file
, " %-10s", p
);
1496 fprintf_unfiltered (file
, " %4s", "Nr");
1498 fprintf_unfiltered (file
, " %4d", regnum
);
1500 /* Relative number. */
1502 fprintf_unfiltered (file
, " %4s", "Rel");
1503 else if (regnum
< NUM_REGS
)
1504 fprintf_unfiltered (file
, " %4d", regnum
);
1506 fprintf_unfiltered (file
, " %4d", (regnum
- NUM_REGS
));
1510 fprintf_unfiltered (file
, " %6s ", "Offset");
1513 fprintf_unfiltered (file
, " %6ld",
1514 regcache
->descr
->register_offset
[regnum
]);
1515 if (register_offset
!= regcache
->descr
->register_offset
[regnum
]
1516 || register_offset
!= REGISTER_BYTE (regnum
)
1518 && (regcache
->descr
->register_offset
[regnum
]
1519 != (regcache
->descr
->register_offset
[regnum
- 1]
1520 + regcache
->descr
->sizeof_register
[regnum
- 1])))
1523 if (!footnote_register_offset
)
1524 footnote_register_offset
= ++footnote_nr
;
1525 fprintf_unfiltered (file
, "*%d", footnote_register_offset
);
1528 fprintf_unfiltered (file
, " ");
1529 register_offset
= (regcache
->descr
->register_offset
[regnum
]
1530 + regcache
->descr
->sizeof_register
[regnum
]);
1535 fprintf_unfiltered (file
, " %5s ", "Size");
1538 fprintf_unfiltered (file
, " %5ld",
1539 regcache
->descr
->sizeof_register
[regnum
]);
1540 if ((regcache
->descr
->sizeof_register
[regnum
]
1541 != REGISTER_RAW_SIZE (regnum
))
1542 || (regcache
->descr
->sizeof_register
[regnum
]
1543 != REGISTER_VIRTUAL_SIZE (regnum
))
1544 || (regcache
->descr
->sizeof_register
[regnum
]
1545 != TYPE_LENGTH (register_type (regcache
->descr
->gdbarch
,
1549 if (!footnote_register_size
)
1550 footnote_register_size
= ++footnote_nr
;
1551 fprintf_unfiltered (file
, "*%d", footnote_register_size
);
1554 fprintf_unfiltered (file
, " ");
1564 static const char blt
[] = "builtin_type";
1565 t
= TYPE_NAME (register_type (regcache
->descr
->gdbarch
, regnum
));
1569 if (!footnote_register_type_name_null
)
1570 footnote_register_type_name_null
= ++footnote_nr
;
1571 xasprintf (&n
, "*%d", footnote_register_type_name_null
);
1572 make_cleanup (xfree
, n
);
1575 /* Chop a leading builtin_type. */
1576 if (strncmp (t
, blt
, strlen (blt
)) == 0)
1579 fprintf_unfiltered (file
, " %-15s", t
);
1582 /* Leading space always present. */
1583 fprintf_unfiltered (file
, " ");
1586 if (what_to_dump
== regcache_dump_raw
)
1589 fprintf_unfiltered (file
, "Raw value");
1590 else if (regnum
>= regcache
->descr
->nr_raw_registers
)
1591 fprintf_unfiltered (file
, "<cooked>");
1592 else if (!regcache_valid_p (regcache
, regnum
))
1593 fprintf_unfiltered (file
, "<invalid>");
1596 regcache_raw_read (regcache
, regnum
, buf
);
1597 fprintf_unfiltered (file
, "0x");
1598 dump_endian_bytes (file
, TARGET_BYTE_ORDER
, buf
,
1599 REGISTER_RAW_SIZE (regnum
));
1603 /* Value, cooked. */
1604 if (what_to_dump
== regcache_dump_cooked
)
1607 fprintf_unfiltered (file
, "Cooked value");
1610 regcache_cooked_read (regcache
, regnum
, buf
);
1611 fprintf_unfiltered (file
, "0x");
1612 dump_endian_bytes (file
, TARGET_BYTE_ORDER
, buf
,
1613 REGISTER_VIRTUAL_SIZE (regnum
));
1617 /* Group members. */
1618 if (what_to_dump
== regcache_dump_groups
)
1621 fprintf_unfiltered (file
, "Groups");
1625 const char *sep
= "";
1626 for (i
= 0; groups
[i
] != NULL
; i
++)
1628 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, groups
[i
]))
1630 fprintf_unfiltered (file
, "%s%s", sep
, reggroup_name (groups
[i
]));
1637 fprintf_unfiltered (file
, "\n");
1640 if (footnote_register_size
)
1641 fprintf_unfiltered (file
, "*%d: Inconsistent register sizes.\n",
1642 footnote_register_size
);
1643 if (footnote_register_offset
)
1644 fprintf_unfiltered (file
, "*%d: Inconsistent register offsets.\n",
1645 footnote_register_offset
);
1646 if (footnote_register_type_name_null
)
1647 fprintf_unfiltered (file
,
1648 "*%d: Register type's name NULL.\n",
1649 footnote_register_type_name_null
);
1650 do_cleanups (cleanups
);
1654 regcache_print (char *args
, enum regcache_dump_what what_to_dump
)
1657 regcache_dump (current_regcache
, gdb_stdout
, what_to_dump
);
1660 struct ui_file
*file
= gdb_fopen (args
, "w");
1662 perror_with_name ("maintenance print architecture");
1663 regcache_dump (current_regcache
, file
, what_to_dump
);
1664 ui_file_delete (file
);
1669 maintenance_print_registers (char *args
, int from_tty
)
1671 regcache_print (args
, regcache_dump_none
);
1675 maintenance_print_raw_registers (char *args
, int from_tty
)
1677 regcache_print (args
, regcache_dump_raw
);
1681 maintenance_print_cooked_registers (char *args
, int from_tty
)
1683 regcache_print (args
, regcache_dump_cooked
);
1687 maintenance_print_register_groups (char *args
, int from_tty
)
1689 regcache_print (args
, regcache_dump_groups
);
1693 _initialize_regcache (void)
1695 regcache_descr_handle
= register_gdbarch_data (init_regcache_descr
,
1696 xfree_regcache_descr
);
1697 REGISTER_GDBARCH_SWAP (current_regcache
);
1698 register_gdbarch_swap (&deprecated_registers
, sizeof (deprecated_registers
), NULL
);
1699 register_gdbarch_swap (&deprecated_register_valid
, sizeof (deprecated_register_valid
), NULL
);
1700 register_gdbarch_swap (NULL
, 0, build_regcache
);
1702 add_com ("flushregs", class_maintenance
, reg_flush_command
,
1703 "Force gdb to flush its register cache (maintainer command)");
1705 /* Initialize the thread/process associated with the current set of
1706 registers. For now, -1 is special, and means `no current process'. */
1707 registers_ptid
= pid_to_ptid (-1);
1709 add_cmd ("registers", class_maintenance
,
1710 maintenance_print_registers
,
1711 "Print the internal register configuration.\
1712 Takes an optional file parameter.",
1713 &maintenanceprintlist
);
1714 add_cmd ("raw-registers", class_maintenance
,
1715 maintenance_print_raw_registers
,
1716 "Print the internal register configuration including raw values.\
1717 Takes an optional file parameter.",
1718 &maintenanceprintlist
);
1719 add_cmd ("cooked-registers", class_maintenance
,
1720 maintenance_print_cooked_registers
,
1721 "Print the internal register configuration including cooked values.\
1722 Takes an optional file parameter.",
1723 &maintenanceprintlist
);
1724 add_cmd ("register-groups", class_maintenance
,
1725 maintenance_print_register_groups
,
1726 "Print the internal register configuration including each register's group.\
1727 Takes an optional file parameter.",
1728 &maintenanceprintlist
);