1 /* Cache and manage the values of registers for GDB, the GNU debugger.
3 Copyright 1986, 1987, 1989, 1991, 1994, 1995, 1996, 1998, 2000,
4 2001, 2002 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
29 #include "reggroups.h"
30 #include "gdb_assert.h"
31 #include "gdb_string.h"
32 #include "gdbcmd.h" /* For maintenanceprintlist. */
37 * Here is the actual register cache.
40 /* Per-architecture object describing the layout of a register cache.
41 Computed once when the architecture is created */
43 struct gdbarch_data
*regcache_descr_handle
;
47 /* The architecture this descriptor belongs to. */
48 struct gdbarch
*gdbarch
;
50 /* Is this a ``legacy'' register cache? Such caches reserve space
51 for raw and pseudo registers and allow access to both. */
54 /* The raw register cache. This should contain just [0
55 .. NUM_RAW_REGISTERS). However, for older targets, it contains
56 space for the full [0 .. NUM_RAW_REGISTERS +
57 NUM_PSEUDO_REGISTERS). */
59 long sizeof_raw_registers
;
60 long sizeof_raw_register_valid_p
;
62 /* The cooked register space. Each cooked register in the range
63 [0..NR_RAW_REGISTERS) is direct-mapped onto the corresponding raw
64 register. The remaining [NR_RAW_REGISTERS
65 .. NR_COOKED_REGISTERS) (a.k.a. pseudo regiters) are mapped onto
66 both raw registers and memory by the architecture methods
67 gdbarch_register_read and gdbarch_register_write. */
68 int nr_cooked_registers
;
69 long sizeof_cooked_registers
;
70 long sizeof_cooked_register_valid_p
;
72 /* Offset and size (in 8 bit bytes), of reach register in the
73 register cache. All registers (including those in the range
74 [NR_RAW_REGISTERS .. NR_COOKED_REGISTERS) are given an offset.
75 Assigning all registers an offset makes it possible to keep
76 legacy code, such as that found in read_register_bytes() and
77 write_register_bytes() working. */
78 long *register_offset
;
79 long *sizeof_register
;
81 /* Useful constant. Largest of all the registers. */
82 long max_register_size
;
84 /* Cached table containing the type of each register. */
85 struct type
**register_type
;
89 init_legacy_regcache_descr (struct gdbarch
*gdbarch
,
90 struct regcache_descr
*descr
)
93 /* FIXME: cagney/2002-05-11: gdbarch_data() should take that
94 ``gdbarch'' as a parameter. */
95 gdb_assert (gdbarch
!= NULL
);
97 /* FIXME: cagney/2002-05-11: Shouldn't be including pseudo-registers
98 in the register cache. Unfortunatly some architectures still
99 rely on this and the pseudo_register_write() method. */
100 descr
->nr_raw_registers
= descr
->nr_cooked_registers
;
101 descr
->sizeof_raw_register_valid_p
= descr
->sizeof_cooked_register_valid_p
;
103 /* Compute the offset of each register. Legacy architectures define
104 REGISTER_BYTE() so use that. */
105 /* FIXME: cagney/2002-11-07: Instead of using REGISTER_BYTE() this
106 code should, as is done in init_regcache_descr(), compute the
107 offets at runtime. This currently isn't possible as some ISAs
108 define overlapping register regions - see the mess in
109 read_register_bytes() and write_register_bytes() registers. */
110 descr
->sizeof_register
= XCALLOC (descr
->nr_cooked_registers
, long);
111 descr
->register_offset
= XCALLOC (descr
->nr_cooked_registers
, long);
112 descr
->max_register_size
= 0;
113 for (i
= 0; i
< descr
->nr_cooked_registers
; i
++)
115 /* FIXME: cagney/2001-12-04: This code shouldn't need to use
116 REGISTER_BYTE(). Unfortunatly, legacy code likes to lay the
117 buffer out so that certain registers just happen to overlap.
118 Ulgh! New targets use gdbarch's register read/write and
119 entirely avoid this uglyness. */
120 descr
->register_offset
[i
] = REGISTER_BYTE (i
);
121 descr
->sizeof_register
[i
] = REGISTER_RAW_SIZE (i
);
122 if (descr
->max_register_size
< REGISTER_RAW_SIZE (i
))
123 descr
->max_register_size
= REGISTER_RAW_SIZE (i
);
124 if (descr
->max_register_size
< REGISTER_VIRTUAL_SIZE (i
))
125 descr
->max_register_size
= REGISTER_VIRTUAL_SIZE (i
);
128 /* Compute the real size of the register buffer. Start out by
129 trusting REGISTER_BYTES, but then adjust it upwards should that
130 be found to not be sufficient. */
131 /* FIXME: cagney/2002-11-05: Instead of using REGISTER_BYTES, this
132 code should, as is done in init_regcache_descr(), compute the
133 total number of register bytes using the accumulated offsets. */
134 descr
->sizeof_cooked_registers
= REGISTER_BYTES
; /* OK use. */
135 for (i
= 0; i
< descr
->nr_cooked_registers
; i
++)
138 /* Keep extending the buffer so that there is always enough
139 space for all registers. The comparison is necessary since
140 legacy code is free to put registers in random places in the
141 buffer separated by holes. Once REGISTER_BYTE() is killed
142 this can be greatly simplified. */
143 regend
= descr
->register_offset
[i
] + descr
->sizeof_register
[i
];
144 if (descr
->sizeof_cooked_registers
< regend
)
145 descr
->sizeof_cooked_registers
= regend
;
147 /* FIXME: cagney/2002-05-11: Shouldn't be including pseudo-registers
148 in the register cache. Unfortunatly some architectures still
149 rely on this and the pseudo_register_write() method. */
150 descr
->sizeof_raw_registers
= descr
->sizeof_cooked_registers
;
154 init_regcache_descr (struct gdbarch
*gdbarch
)
157 struct regcache_descr
*descr
;
158 gdb_assert (gdbarch
!= NULL
);
160 /* Create an initial, zero filled, table. */
161 descr
= XCALLOC (1, struct regcache_descr
);
162 descr
->gdbarch
= gdbarch
;
164 /* Total size of the register space. The raw registers are mapped
165 directly onto the raw register cache while the pseudo's are
166 either mapped onto raw-registers or memory. */
167 descr
->nr_cooked_registers
= NUM_REGS
+ NUM_PSEUDO_REGS
;
168 descr
->sizeof_cooked_register_valid_p
= NUM_REGS
+ NUM_PSEUDO_REGS
;
170 /* Fill in a table of register types. */
171 descr
->register_type
= XCALLOC (descr
->nr_cooked_registers
,
173 for (i
= 0; i
< descr
->nr_cooked_registers
; i
++)
175 if (gdbarch_register_type_p (gdbarch
))
177 gdb_assert (!REGISTER_VIRTUAL_TYPE_P ()); /* OK */
178 descr
->register_type
[i
] = gdbarch_register_type (gdbarch
, i
);
181 descr
->register_type
[i
] = REGISTER_VIRTUAL_TYPE (i
); /* OK */
184 /* If an old style architecture, fill in the remainder of the
185 register cache descriptor using the register macros. */
186 if (!gdbarch_pseudo_register_read_p (gdbarch
)
187 && !gdbarch_pseudo_register_write_p (gdbarch
)
188 && !gdbarch_register_type_p (gdbarch
))
191 init_legacy_regcache_descr (gdbarch
, descr
);
195 /* Construct a strictly RAW register cache. Don't allow pseudo's
196 into the register cache. */
197 descr
->nr_raw_registers
= NUM_REGS
;
199 /* FIXME: cagney/2002-08-13: Overallocate the register_valid_p
200 array. This pretects GDB from erant code that accesses elements
201 of the global register_valid_p[] array in the range [NUM_REGS
202 .. NUM_REGS + NUM_PSEUDO_REGS). */
203 descr
->sizeof_raw_register_valid_p
= descr
->sizeof_cooked_register_valid_p
;
205 /* Lay out the register cache.
207 NOTE: cagney/2002-05-22: Only register_type() is used when
208 constructing the register cache. It is assumed that the
209 register's raw size, virtual size and type length are all the
214 descr
->sizeof_register
= XCALLOC (descr
->nr_cooked_registers
, long);
215 descr
->register_offset
= XCALLOC (descr
->nr_cooked_registers
, long);
216 descr
->max_register_size
= 0;
217 for (i
= 0; i
< descr
->nr_cooked_registers
; i
++)
219 descr
->sizeof_register
[i
] = TYPE_LENGTH (descr
->register_type
[i
]);
220 descr
->register_offset
[i
] = offset
;
221 offset
+= descr
->sizeof_register
[i
];
222 if (descr
->max_register_size
< descr
->sizeof_register
[i
])
223 descr
->max_register_size
= descr
->sizeof_register
[i
];
225 /* Set the real size of the register cache buffer. */
226 descr
->sizeof_cooked_registers
= offset
;
229 /* FIXME: cagney/2002-05-22: Should only need to allocate space for
230 the raw registers. Unfortunatly some code still accesses the
231 register array directly using the global registers[]. Until that
232 code has been purged, play safe and over allocating the register
234 descr
->sizeof_raw_registers
= descr
->sizeof_cooked_registers
;
237 /* Sanity check. Confirm that the assumptions about gdbarch are
238 true. The REGCACHE_DESCR_HANDLE is set before doing the checks
239 so that targets using the generic methods supplied by regcache
240 don't go into infinite recursion trying to, again, create the
242 set_gdbarch_data (gdbarch
, regcache_descr_handle
, descr
);
243 for (i
= 0; i
< descr
->nr_cooked_registers
; i
++)
245 gdb_assert (descr
->sizeof_register
[i
] == REGISTER_RAW_SIZE (i
));
246 gdb_assert (descr
->sizeof_register
[i
] == REGISTER_VIRTUAL_SIZE (i
));
247 gdb_assert (descr
->register_offset
[i
] == REGISTER_BYTE (i
));
249 /* gdb_assert (descr->sizeof_raw_registers == REGISTER_BYTES (i)); */
255 static struct regcache_descr
*
256 regcache_descr (struct gdbarch
*gdbarch
)
258 return gdbarch_data (gdbarch
, regcache_descr_handle
);
262 xfree_regcache_descr (struct gdbarch
*gdbarch
, void *ptr
)
264 struct regcache_descr
*descr
= ptr
;
267 xfree (descr
->register_offset
);
268 xfree (descr
->sizeof_register
);
269 descr
->register_offset
= NULL
;
270 descr
->sizeof_register
= NULL
;
274 /* Utility functions returning useful register attributes stored in
275 the regcache descr. */
278 register_type (struct gdbarch
*gdbarch
, int regnum
)
280 struct regcache_descr
*descr
= regcache_descr (gdbarch
);
281 gdb_assert (regnum
>= 0 && regnum
< descr
->nr_cooked_registers
);
282 return descr
->register_type
[regnum
];
285 /* Utility functions returning useful register attributes stored in
286 the regcache descr. */
289 max_register_size (struct gdbarch
*gdbarch
)
291 struct regcache_descr
*descr
= regcache_descr (gdbarch
);
292 return descr
->max_register_size
;
296 legacy_max_register_raw_size (void)
298 if (DEPRECATED_MAX_REGISTER_RAW_SIZE_P ())
299 return DEPRECATED_MAX_REGISTER_RAW_SIZE
;
301 return max_register_size (current_gdbarch
);
305 legacy_max_register_virtual_size (void)
307 if (DEPRECATED_MAX_REGISTER_VIRTUAL_SIZE_P ())
308 return DEPRECATED_MAX_REGISTER_VIRTUAL_SIZE
;
310 return max_register_size (current_gdbarch
);
314 register_size (struct gdbarch
*gdbarch
, int regnum
)
316 struct regcache_descr
*descr
= regcache_descr (gdbarch
);
318 gdb_assert (regnum
>= 0 && regnum
< (NUM_REGS
+ NUM_PSEUDO_REGS
));
319 size
= descr
->sizeof_register
[regnum
];
320 gdb_assert (size
== REGISTER_RAW_SIZE (regnum
)); /* OK */
321 gdb_assert (size
== REGISTER_RAW_SIZE (regnum
)); /* OK */
325 /* The register cache for storing raw register values. */
329 struct regcache_descr
*descr
;
330 /* The register buffers. A read-only register cache can hold the
331 full [0 .. NUM_REGS + NUM_PSEUDO_REGS) while a read/write
332 register cache can only hold [0 .. NUM_REGS). */
334 char *register_valid_p
;
335 /* Is this a read-only cache? A read-only cache is used for saving
336 the target's register state (e.g, across an inferior function
337 call or just before forcing a function return). A read-only
338 cache can only be updated via the methods regcache_dup() and
339 regcache_cpy(). The actual contents are determined by the
340 reggroup_save and reggroup_restore methods. */
345 regcache_xmalloc (struct gdbarch
*gdbarch
)
347 struct regcache_descr
*descr
;
348 struct regcache
*regcache
;
349 gdb_assert (gdbarch
!= NULL
);
350 descr
= regcache_descr (gdbarch
);
351 regcache
= XMALLOC (struct regcache
);
352 regcache
->descr
= descr
;
354 = XCALLOC (descr
->sizeof_raw_registers
, char);
355 regcache
->register_valid_p
356 = XCALLOC (descr
->sizeof_raw_register_valid_p
, char);
357 regcache
->readonly_p
= 1;
362 regcache_xfree (struct regcache
*regcache
)
364 if (regcache
== NULL
)
366 xfree (regcache
->registers
);
367 xfree (regcache
->register_valid_p
);
372 do_regcache_xfree (void *data
)
374 regcache_xfree (data
);
378 make_cleanup_regcache_xfree (struct regcache
*regcache
)
380 return make_cleanup (do_regcache_xfree
, regcache
);
383 /* Return a pointer to register REGNUM's buffer cache. */
386 register_buffer (struct regcache
*regcache
, int regnum
)
388 return regcache
->registers
+ regcache
->descr
->register_offset
[regnum
];
392 regcache_save (struct regcache
*dst
, struct regcache
*src
)
394 struct gdbarch
*gdbarch
= dst
->descr
->gdbarch
;
396 /* The SRC and DST register caches had better belong to the same
398 gdb_assert (src
->descr
->gdbarch
== dst
->descr
->gdbarch
);
399 /* The DST should be `read-only', if it wasn't then the save would
400 end up trying to write the register values out through to the
402 gdb_assert (!src
->readonly_p
);
403 gdb_assert (dst
->readonly_p
);
404 /* Clear the dest. */
405 memset (dst
->registers
, 0, dst
->descr
->sizeof_cooked_registers
);
406 memset (dst
->register_valid_p
, 0, dst
->descr
->sizeof_cooked_register_valid_p
);
407 /* Copy over any registers (identified by their membership in the
408 save_reggroup) and mark them as valid. The full [0
409 .. NUM_REGS+NUM_PSEUDO_REGS) range is checked since some
410 architectures need to save/restore `cooked' registers that live
412 for (regnum
= 0; regnum
< dst
->descr
->nr_cooked_registers
; regnum
++)
414 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, save_reggroup
))
416 regcache_cooked_read (src
, regnum
, register_buffer (dst
, regnum
));
417 dst
->register_valid_p
[regnum
] = 1;
423 regcache_restore (struct regcache
*dst
, struct regcache
*src
)
425 struct gdbarch
*gdbarch
= dst
->descr
->gdbarch
;
427 gdb_assert (src
->descr
->gdbarch
== dst
->descr
->gdbarch
);
428 gdb_assert (!dst
->readonly_p
);
429 gdb_assert (src
->readonly_p
);
430 /* Copy over any registers, being careful to only restore those that
431 were both saved and need to be restored. The full [0
432 .. NUM_REGS+NUM_PSEUDO_REGS) range is checked since some
433 architectures need to save/restore `cooked' registers that live
435 for (regnum
= 0; regnum
< src
->descr
->nr_cooked_registers
; regnum
++)
437 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, restore_reggroup
)
438 && src
->register_valid_p
[regnum
])
440 regcache_cooked_write (dst
, regnum
, register_buffer (src
, regnum
));
446 regcache_cpy (struct regcache
*dst
, struct regcache
*src
)
450 gdb_assert (src
!= NULL
&& dst
!= NULL
);
451 gdb_assert (src
->descr
->gdbarch
== dst
->descr
->gdbarch
);
452 gdb_assert (src
!= dst
);
453 gdb_assert (src
->readonly_p
|| dst
->readonly_p
);
454 if (!src
->readonly_p
)
455 regcache_save (dst
, src
);
456 else if (!dst
->readonly_p
)
457 regcache_restore (dst
, src
);
459 regcache_cpy_no_passthrough (dst
, src
);
463 regcache_cpy_no_passthrough (struct regcache
*dst
, struct regcache
*src
)
466 gdb_assert (src
!= NULL
&& dst
!= NULL
);
467 gdb_assert (src
->descr
->gdbarch
== dst
->descr
->gdbarch
);
468 /* NOTE: cagney/2002-05-17: Don't let the caller do a no-passthrough
469 move of data into the current_regcache(). Doing this would be
470 silly - it would mean that valid_p would be completly invalid. */
471 gdb_assert (dst
!= current_regcache
);
472 memcpy (dst
->registers
, src
->registers
, dst
->descr
->sizeof_raw_registers
);
473 memcpy (dst
->register_valid_p
, src
->register_valid_p
,
474 dst
->descr
->sizeof_raw_register_valid_p
);
478 regcache_dup (struct regcache
*src
)
480 struct regcache
*newbuf
;
481 gdb_assert (current_regcache
!= NULL
);
482 newbuf
= regcache_xmalloc (src
->descr
->gdbarch
);
483 regcache_cpy (newbuf
, src
);
488 regcache_dup_no_passthrough (struct regcache
*src
)
490 struct regcache
*newbuf
;
491 gdb_assert (current_regcache
!= NULL
);
492 newbuf
= regcache_xmalloc (src
->descr
->gdbarch
);
493 regcache_cpy_no_passthrough (newbuf
, src
);
498 regcache_valid_p (struct regcache
*regcache
, int regnum
)
500 gdb_assert (regcache
!= NULL
);
501 gdb_assert (regnum
>= 0 && regnum
< regcache
->descr
->nr_raw_registers
);
502 return regcache
->register_valid_p
[regnum
];
506 deprecated_grub_regcache_for_registers (struct regcache
*regcache
)
508 return regcache
->registers
;
512 deprecated_grub_regcache_for_register_valid (struct regcache
*regcache
)
514 return regcache
->register_valid_p
;
517 /* Global structure containing the current regcache. */
518 /* FIXME: cagney/2002-05-11: The two global arrays registers[] and
519 deprecated_register_valid[] currently point into this structure. */
520 struct regcache
*current_regcache
;
522 /* NOTE: this is a write-through cache. There is no "dirty" bit for
523 recording if the register values have been changed (eg. by the
524 user). Therefore all registers must be written back to the
525 target when appropriate. */
527 /* REGISTERS contains the cached register values (in target byte order). */
529 char *deprecated_registers
;
531 /* DEPRECATED_REGISTER_VALID is 0 if the register needs to be fetched,
532 1 if it has been fetched, and
533 -1 if the register value was not available.
535 "Not available" indicates that the target is not not able to supply
536 the register at this state. The register may become available at a
537 later time (after the next resume). This often occures when GDB is
538 manipulating a target that contains only a snapshot of the entire
539 system being debugged - some of the registers in such a system may
540 not have been saved. */
542 signed char *deprecated_register_valid
;
544 /* The thread/process associated with the current set of registers. */
546 static ptid_t registers_ptid
;
554 Returns 0 if the value is not in the cache (needs fetch).
555 >0 if the value is in the cache.
556 <0 if the value is permanently unavailable (don't ask again). */
559 register_cached (int regnum
)
561 return deprecated_register_valid
[regnum
];
564 /* Record that REGNUM's value is cached if STATE is >0, uncached but
565 fetchable if STATE is 0, and uncached and unfetchable if STATE is <0. */
568 set_register_cached (int regnum
, int state
)
570 gdb_assert (regnum
>= 0);
571 gdb_assert (regnum
< current_regcache
->descr
->nr_raw_registers
);
572 current_regcache
->register_valid_p
[regnum
] = state
;
575 /* Return whether register REGNUM is a real register. */
578 real_register (int regnum
)
580 return regnum
>= 0 && regnum
< NUM_REGS
;
583 /* Low level examining and depositing of registers.
585 The caller is responsible for making sure that the inferior is
586 stopped before calling the fetching routines, or it will get
587 garbage. (a change from GDB version 3, in which the caller got the
588 value from the last stop). */
590 /* REGISTERS_CHANGED ()
592 Indicate that registers may have changed, so invalidate the cache. */
595 registers_changed (void)
599 registers_ptid
= pid_to_ptid (-1);
601 /* Force cleanup of any alloca areas if using C alloca instead of
602 a builtin alloca. This particular call is used to clean up
603 areas allocated by low level target code which may build up
604 during lengthy interactions between gdb and the target before
605 gdb gives control to the user (ie watchpoints). */
608 for (i
= 0; i
< current_regcache
->descr
->nr_raw_registers
; i
++)
609 set_register_cached (i
, 0);
611 if (registers_changed_hook
)
612 registers_changed_hook ();
615 /* DEPRECATED_REGISTERS_FETCHED ()
617 Indicate that all registers have been fetched, so mark them all valid. */
619 /* NOTE: cagney/2001-12-04: This function does not set valid on the
620 pseudo-register range since pseudo registers are always supplied
621 using supply_register(). */
622 /* FIXME: cagney/2001-12-04: This function is DEPRECATED. The target
623 code was blatting the registers[] array and then calling this.
624 Since targets should only be using supply_register() the need for
625 this function/hack is eliminated. */
628 deprecated_registers_fetched (void)
632 for (i
= 0; i
< NUM_REGS
; i
++)
633 set_register_cached (i
, 1);
634 /* Do not assume that the pseudo-regs have also been fetched.
635 Fetching all real regs NEVER accounts for pseudo-regs. */
638 /* deprecated_read_register_bytes and deprecated_write_register_bytes
639 are generally a *BAD* idea. They are inefficient because they need
640 to check for partial updates, which can only be done by scanning
641 through all of the registers and seeing if the bytes that are being
642 read/written fall inside of an invalid register. [The main reason
643 this is necessary is that register sizes can vary, so a simple
644 index won't suffice.] It is far better to call read_register_gen
645 and write_register_gen if you want to get at the raw register
646 contents, as it only takes a regnum as an argument, and therefore
647 can't do a partial register update.
649 Prior to the recent fixes to check for partial updates, both read
650 and deprecated_write_register_bytes always checked to see if any
651 registers were stale, and then called target_fetch_registers (-1)
652 to update the whole set. This caused really slowed things down for
655 /* Copy INLEN bytes of consecutive data from registers
656 starting with the INREGBYTE'th byte of register data
657 into memory at MYADDR. */
660 deprecated_read_register_bytes (int in_start
, char *in_buf
, int in_len
)
662 int in_end
= in_start
+ in_len
;
664 char *reg_buf
= alloca (MAX_REGISTER_RAW_SIZE
);
666 /* See if we are trying to read bytes from out-of-date registers. If so,
667 update just those registers. */
669 for (regnum
= 0; regnum
< NUM_REGS
+ NUM_PSEUDO_REGS
; regnum
++)
678 reg_start
= REGISTER_BYTE (regnum
);
679 reg_len
= REGISTER_RAW_SIZE (regnum
);
680 reg_end
= reg_start
+ reg_len
;
682 if (reg_end
<= in_start
|| in_end
<= reg_start
)
683 /* The range the user wants to read doesn't overlap with regnum. */
686 if (REGISTER_NAME (regnum
) != NULL
&& *REGISTER_NAME (regnum
) != '\0')
687 /* Force the cache to fetch the entire register. */
688 deprecated_read_register_gen (regnum
, reg_buf
);
690 /* Legacy note: even though this register is ``invalid'' we
691 still need to return something. It would appear that some
692 code relies on apparent gaps in the register array also
694 /* FIXME: cagney/2001-08-18: This is just silly. It defeats
695 the entire register read/write flow of control. Must
696 resist temptation to return 0xdeadbeef. */
697 memcpy (reg_buf
, &deprecated_registers
[reg_start
], reg_len
);
699 /* Legacy note: This function, for some reason, allows a NULL
700 input buffer. If the buffer is NULL, the registers are still
701 fetched, just the final transfer is skipped. */
705 /* start = max (reg_start, in_start) */
706 if (reg_start
> in_start
)
711 /* end = min (reg_end, in_end) */
712 if (reg_end
< in_end
)
717 /* Transfer just the bytes common to both IN_BUF and REG_BUF */
718 for (byte
= start
; byte
< end
; byte
++)
720 in_buf
[byte
- in_start
] = reg_buf
[byte
- reg_start
];
725 /* Read register REGNUM into memory at MYADDR, which must be large
726 enough for REGISTER_RAW_BYTES (REGNUM). Target byte-order. If the
727 register is known to be the size of a CORE_ADDR or smaller,
728 read_register can be used instead. */
731 legacy_read_register_gen (int regnum
, char *myaddr
)
733 gdb_assert (regnum
>= 0 && regnum
< (NUM_REGS
+ NUM_PSEUDO_REGS
));
734 if (! ptid_equal (registers_ptid
, inferior_ptid
))
736 registers_changed ();
737 registers_ptid
= inferior_ptid
;
740 if (!register_cached (regnum
))
741 target_fetch_registers (regnum
);
743 memcpy (myaddr
, register_buffer (current_regcache
, regnum
),
744 REGISTER_RAW_SIZE (regnum
));
748 regcache_raw_read (struct regcache
*regcache
, int regnum
, void *buf
)
750 gdb_assert (regcache
!= NULL
&& buf
!= NULL
);
751 gdb_assert (regnum
>= 0 && regnum
< regcache
->descr
->nr_raw_registers
);
752 if (regcache
->descr
->legacy_p
753 && !regcache
->readonly_p
)
755 gdb_assert (regcache
== current_regcache
);
756 /* For moment, just use underlying legacy code. Ulgh!!! This
757 silently and very indirectly updates the regcache's regcache
758 via the global deprecated_register_valid[]. */
759 legacy_read_register_gen (regnum
, buf
);
762 /* Make certain that the register cache is up-to-date with respect
763 to the current thread. This switching shouldn't be necessary
764 only there is still only one target side register cache. Sigh!
765 On the bright side, at least there is a regcache object. */
766 if (!regcache
->readonly_p
)
768 gdb_assert (regcache
== current_regcache
);
769 if (! ptid_equal (registers_ptid
, inferior_ptid
))
771 registers_changed ();
772 registers_ptid
= inferior_ptid
;
774 if (!register_cached (regnum
))
775 target_fetch_registers (regnum
);
777 /* Copy the value directly into the register cache. */
778 memcpy (buf
, register_buffer (regcache
, regnum
),
779 regcache
->descr
->sizeof_register
[regnum
]);
783 regcache_raw_read_signed (struct regcache
*regcache
, int regnum
, LONGEST
*val
)
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 regcache_raw_read (regcache
, regnum
, buf
);
790 (*val
) = extract_signed_integer (buf
,
791 regcache
->descr
->sizeof_register
[regnum
]);
795 regcache_raw_read_unsigned (struct regcache
*regcache
, int regnum
,
799 gdb_assert (regcache
!= NULL
);
800 gdb_assert (regnum
>= 0 && regnum
< regcache
->descr
->nr_raw_registers
);
801 buf
= alloca (regcache
->descr
->sizeof_register
[regnum
]);
802 regcache_raw_read (regcache
, regnum
, buf
);
803 (*val
) = extract_unsigned_integer (buf
,
804 regcache
->descr
->sizeof_register
[regnum
]);
808 regcache_raw_write_signed (struct regcache
*regcache
, int regnum
, LONGEST val
)
811 gdb_assert (regcache
!= NULL
);
812 gdb_assert (regnum
>=0 && regnum
< regcache
->descr
->nr_raw_registers
);
813 buf
= alloca (regcache
->descr
->sizeof_register
[regnum
]);
814 store_signed_integer (buf
, regcache
->descr
->sizeof_register
[regnum
], val
);
815 regcache_raw_write (regcache
, regnum
, buf
);
819 regcache_raw_write_unsigned (struct regcache
*regcache
, int regnum
,
823 gdb_assert (regcache
!= NULL
);
824 gdb_assert (regnum
>=0 && regnum
< regcache
->descr
->nr_raw_registers
);
825 buf
= alloca (regcache
->descr
->sizeof_register
[regnum
]);
826 store_unsigned_integer (buf
, regcache
->descr
->sizeof_register
[regnum
], val
);
827 regcache_raw_write (regcache
, regnum
, buf
);
831 deprecated_read_register_gen (int regnum
, char *buf
)
833 gdb_assert (current_regcache
!= NULL
);
834 gdb_assert (current_regcache
->descr
->gdbarch
== current_gdbarch
);
835 if (current_regcache
->descr
->legacy_p
)
837 legacy_read_register_gen (regnum
, buf
);
840 regcache_cooked_read (current_regcache
, regnum
, buf
);
844 regcache_cooked_read (struct regcache
*regcache
, int regnum
, void *buf
)
846 gdb_assert (regnum
>= 0);
847 gdb_assert (regnum
< regcache
->descr
->nr_cooked_registers
);
848 if (regnum
< regcache
->descr
->nr_raw_registers
)
849 regcache_raw_read (regcache
, regnum
, buf
);
850 else if (regcache
->readonly_p
851 && regnum
< regcache
->descr
->nr_cooked_registers
852 && regcache
->register_valid_p
[regnum
])
853 /* Read-only register cache, perhaphs the cooked value was cached? */
854 memcpy (buf
, register_buffer (regcache
, regnum
),
855 regcache
->descr
->sizeof_register
[regnum
]);
857 gdbarch_pseudo_register_read (regcache
->descr
->gdbarch
, regcache
,
862 regcache_cooked_read_signed (struct regcache
*regcache
, int regnum
,
866 gdb_assert (regcache
!= NULL
);
867 gdb_assert (regnum
>= 0 && regnum
< regcache
->descr
->nr_raw_registers
);
868 buf
= alloca (regcache
->descr
->sizeof_register
[regnum
]);
869 regcache_cooked_read (regcache
, regnum
, buf
);
870 (*val
) = extract_signed_integer (buf
,
871 regcache
->descr
->sizeof_register
[regnum
]);
875 regcache_cooked_read_unsigned (struct regcache
*regcache
, int regnum
,
879 gdb_assert (regcache
!= NULL
);
880 gdb_assert (regnum
>= 0 && regnum
< regcache
->descr
->nr_raw_registers
);
881 buf
= alloca (regcache
->descr
->sizeof_register
[regnum
]);
882 regcache_cooked_read (regcache
, regnum
, buf
);
883 (*val
) = extract_unsigned_integer (buf
,
884 regcache
->descr
->sizeof_register
[regnum
]);
887 /* Write register REGNUM at MYADDR to the target. MYADDR points at
888 REGISTER_RAW_BYTES(REGNUM), which must be in target byte-order. */
891 legacy_write_register_gen (int regnum
, const void *myaddr
)
894 gdb_assert (regnum
>= 0 && regnum
< (NUM_REGS
+ NUM_PSEUDO_REGS
));
896 /* On the sparc, writing %g0 is a no-op, so we don't even want to
897 change the registers array if something writes to this register. */
898 if (CANNOT_STORE_REGISTER (regnum
))
901 if (! ptid_equal (registers_ptid
, inferior_ptid
))
903 registers_changed ();
904 registers_ptid
= inferior_ptid
;
907 size
= REGISTER_RAW_SIZE (regnum
);
909 if (real_register (regnum
))
911 /* If we have a valid copy of the register, and new value == old
912 value, then don't bother doing the actual store. */
913 if (register_cached (regnum
)
914 && (memcmp (register_buffer (current_regcache
, regnum
), myaddr
, size
)
918 target_prepare_to_store ();
921 memcpy (register_buffer (current_regcache
, regnum
), myaddr
, size
);
923 set_register_cached (regnum
, 1);
924 target_store_registers (regnum
);
928 regcache_raw_write (struct regcache
*regcache
, int regnum
, const void *buf
)
930 gdb_assert (regcache
!= NULL
&& buf
!= NULL
);
931 gdb_assert (regnum
>= 0 && regnum
< regcache
->descr
->nr_raw_registers
);
932 gdb_assert (!regcache
->readonly_p
);
934 if (regcache
->descr
->legacy_p
)
936 /* For moment, just use underlying legacy code. Ulgh!!! This
937 silently and very indirectly updates the regcache's buffers
938 via the globals deprecated_register_valid[] and registers[]. */
939 gdb_assert (regcache
== current_regcache
);
940 legacy_write_register_gen (regnum
, buf
);
944 /* On the sparc, writing %g0 is a no-op, so we don't even want to
945 change the registers array if something writes to this register. */
946 if (CANNOT_STORE_REGISTER (regnum
))
949 /* Make certain that the correct cache is selected. */
950 gdb_assert (regcache
== current_regcache
);
951 if (! ptid_equal (registers_ptid
, inferior_ptid
))
953 registers_changed ();
954 registers_ptid
= inferior_ptid
;
957 /* If we have a valid copy of the register, and new value == old
958 value, then don't bother doing the actual store. */
959 if (regcache_valid_p (regcache
, regnum
)
960 && (memcmp (register_buffer (regcache
, regnum
), buf
,
961 regcache
->descr
->sizeof_register
[regnum
]) == 0))
964 target_prepare_to_store ();
965 memcpy (register_buffer (regcache
, regnum
), buf
,
966 regcache
->descr
->sizeof_register
[regnum
]);
967 regcache
->register_valid_p
[regnum
] = 1;
968 target_store_registers (regnum
);
972 deprecated_write_register_gen (int regnum
, char *buf
)
974 gdb_assert (current_regcache
!= NULL
);
975 gdb_assert (current_regcache
->descr
->gdbarch
== current_gdbarch
);
976 if (current_regcache
->descr
->legacy_p
)
978 legacy_write_register_gen (regnum
, buf
);
981 regcache_cooked_write (current_regcache
, regnum
, buf
);
985 regcache_cooked_write (struct regcache
*regcache
, int regnum
, const void *buf
)
987 gdb_assert (regnum
>= 0);
988 gdb_assert (regnum
< regcache
->descr
->nr_cooked_registers
);
989 if (regnum
< regcache
->descr
->nr_raw_registers
)
990 regcache_raw_write (regcache
, regnum
, buf
);
992 gdbarch_pseudo_register_write (regcache
->descr
->gdbarch
, regcache
,
996 /* Copy INLEN bytes of consecutive data from memory at MYADDR
997 into registers starting with the MYREGSTART'th byte of register data. */
1000 deprecated_write_register_bytes (int myregstart
, char *myaddr
, int inlen
)
1002 int myregend
= myregstart
+ inlen
;
1005 target_prepare_to_store ();
1007 /* Scan through the registers updating any that are covered by the
1008 range myregstart<=>myregend using write_register_gen, which does
1009 nice things like handling threads, and avoiding updates when the
1010 new and old contents are the same. */
1012 for (regnum
= 0; regnum
< NUM_REGS
+ NUM_PSEUDO_REGS
; regnum
++)
1014 int regstart
, regend
;
1016 regstart
= REGISTER_BYTE (regnum
);
1017 regend
= regstart
+ REGISTER_RAW_SIZE (regnum
);
1019 /* Is this register completely outside the range the user is writing? */
1020 if (myregend
<= regstart
|| regend
<= myregstart
)
1023 /* Is this register completely within the range the user is writing? */
1024 else if (myregstart
<= regstart
&& regend
<= myregend
)
1025 deprecated_write_register_gen (regnum
, myaddr
+ (regstart
- myregstart
));
1027 /* The register partially overlaps the range being written. */
1030 char *regbuf
= (char*) alloca (MAX_REGISTER_RAW_SIZE
);
1031 /* What's the overlap between this register's bytes and
1032 those the caller wants to write? */
1033 int overlapstart
= max (regstart
, myregstart
);
1034 int overlapend
= min (regend
, myregend
);
1036 /* We may be doing a partial update of an invalid register.
1037 Update it from the target before scribbling on it. */
1038 deprecated_read_register_gen (regnum
, regbuf
);
1040 memcpy (&deprecated_registers
[overlapstart
],
1041 myaddr
+ (overlapstart
- myregstart
),
1042 overlapend
- overlapstart
);
1044 target_store_registers (regnum
);
1049 /* Perform a partial register transfer using a read, modify, write
1052 typedef void (regcache_read_ftype
) (struct regcache
*regcache
, int regnum
,
1054 typedef void (regcache_write_ftype
) (struct regcache
*regcache
, int regnum
,
1058 regcache_xfer_part (struct regcache
*regcache
, int regnum
,
1059 int offset
, int len
, void *in
, const void *out
,
1060 regcache_read_ftype
*read
, regcache_write_ftype
*write
)
1062 struct regcache_descr
*descr
= regcache
->descr
;
1063 bfd_byte
*reg
= alloca (descr
->max_register_size
);
1064 gdb_assert (offset
>= 0 && offset
<= descr
->sizeof_register
[regnum
]);
1065 gdb_assert (len
>= 0 && offset
+ len
<= descr
->sizeof_register
[regnum
]);
1066 /* Something to do? */
1067 if (offset
+ len
== 0)
1069 /* Read (when needed) ... */
1072 || offset
+ len
< descr
->sizeof_register
[regnum
])
1074 gdb_assert (read
!= NULL
);
1075 read (regcache
, regnum
, reg
);
1077 /* ... modify ... */
1079 memcpy (in
, reg
+ offset
, len
);
1081 memcpy (reg
+ offset
, out
, len
);
1082 /* ... write (when needed). */
1085 gdb_assert (write
!= NULL
);
1086 write (regcache
, regnum
, reg
);
1091 regcache_raw_read_part (struct regcache
*regcache
, int regnum
,
1092 int offset
, int len
, void *buf
)
1094 struct regcache_descr
*descr
= regcache
->descr
;
1095 gdb_assert (regnum
>= 0 && regnum
< descr
->nr_raw_registers
);
1096 regcache_xfer_part (regcache
, regnum
, offset
, len
, buf
, NULL
,
1097 regcache_raw_read
, regcache_raw_write
);
1101 regcache_raw_write_part (struct regcache
*regcache
, int regnum
,
1102 int offset
, int len
, const void *buf
)
1104 struct regcache_descr
*descr
= regcache
->descr
;
1105 gdb_assert (regnum
>= 0 && regnum
< descr
->nr_raw_registers
);
1106 regcache_xfer_part (regcache
, regnum
, offset
, len
, NULL
, buf
,
1107 regcache_raw_read
, regcache_raw_write
);
1111 regcache_cooked_read_part (struct regcache
*regcache
, int regnum
,
1112 int offset
, int len
, void *buf
)
1114 struct regcache_descr
*descr
= regcache
->descr
;
1115 gdb_assert (regnum
>= 0 && regnum
< descr
->nr_cooked_registers
);
1116 regcache_xfer_part (regcache
, regnum
, offset
, len
, buf
, NULL
,
1117 regcache_cooked_read
, regcache_cooked_write
);
1121 regcache_cooked_write_part (struct regcache
*regcache
, int regnum
,
1122 int offset
, int len
, const void *buf
)
1124 struct regcache_descr
*descr
= regcache
->descr
;
1125 gdb_assert (regnum
>= 0 && regnum
< descr
->nr_cooked_registers
);
1126 regcache_xfer_part (regcache
, regnum
, offset
, len
, NULL
, buf
,
1127 regcache_cooked_read
, regcache_cooked_write
);
1130 /* Hack to keep code that view the register buffer as raw bytes
1134 register_offset_hack (struct gdbarch
*gdbarch
, int regnum
)
1136 struct regcache_descr
*descr
= regcache_descr (gdbarch
);
1137 gdb_assert (regnum
>= 0 && regnum
< descr
->nr_cooked_registers
);
1138 return descr
->register_offset
[regnum
];
1141 /* Return the contents of register REGNUM as an unsigned integer. */
1144 read_register (int regnum
)
1146 char *buf
= alloca (REGISTER_RAW_SIZE (regnum
));
1147 deprecated_read_register_gen (regnum
, buf
);
1148 return (extract_unsigned_integer (buf
, REGISTER_RAW_SIZE (regnum
)));
1152 read_register_pid (int regnum
, ptid_t ptid
)
1158 if (ptid_equal (ptid
, inferior_ptid
))
1159 return read_register (regnum
);
1161 save_ptid
= inferior_ptid
;
1163 inferior_ptid
= ptid
;
1165 retval
= read_register (regnum
);
1167 inferior_ptid
= save_ptid
;
1172 /* Return the contents of register REGNUM as a signed integer. */
1175 read_signed_register (int regnum
)
1177 void *buf
= alloca (REGISTER_RAW_SIZE (regnum
));
1178 deprecated_read_register_gen (regnum
, buf
);
1179 return (extract_signed_integer (buf
, REGISTER_RAW_SIZE (regnum
)));
1183 read_signed_register_pid (int regnum
, ptid_t ptid
)
1188 if (ptid_equal (ptid
, inferior_ptid
))
1189 return read_signed_register (regnum
);
1191 save_ptid
= inferior_ptid
;
1193 inferior_ptid
= ptid
;
1195 retval
= read_signed_register (regnum
);
1197 inferior_ptid
= save_ptid
;
1202 /* Store VALUE into the raw contents of register number REGNUM. */
1205 write_register (int regnum
, LONGEST val
)
1209 size
= REGISTER_RAW_SIZE (regnum
);
1210 buf
= alloca (size
);
1211 store_signed_integer (buf
, size
, (LONGEST
) val
);
1212 deprecated_write_register_gen (regnum
, buf
);
1216 write_register_pid (int regnum
, CORE_ADDR val
, ptid_t ptid
)
1220 if (ptid_equal (ptid
, inferior_ptid
))
1222 write_register (regnum
, val
);
1226 save_ptid
= inferior_ptid
;
1228 inferior_ptid
= ptid
;
1230 write_register (regnum
, val
);
1232 inferior_ptid
= save_ptid
;
1235 /* SUPPLY_REGISTER()
1237 Record that register REGNUM contains VAL. This is used when the
1238 value is obtained from the inferior or core dump, so there is no
1239 need to store the value there.
1241 If VAL is a NULL pointer, then it's probably an unsupported register.
1242 We just set its value to all zeros. We might want to record this
1243 fact, and report it to the users of read_register and friends. */
1246 supply_register (int regnum
, const void *val
)
1249 if (! ptid_equal (registers_ptid
, inferior_ptid
))
1251 registers_changed ();
1252 registers_ptid
= inferior_ptid
;
1256 set_register_cached (regnum
, 1);
1258 memcpy (register_buffer (current_regcache
, regnum
), val
,
1259 REGISTER_RAW_SIZE (regnum
));
1261 memset (register_buffer (current_regcache
, regnum
), '\000',
1262 REGISTER_RAW_SIZE (regnum
));
1264 /* On some architectures, e.g. HPPA, there are a few stray bits in
1265 some registers, that the rest of the code would like to ignore. */
1267 /* NOTE: cagney/2001-03-16: The macro CLEAN_UP_REGISTER_VALUE is
1268 going to be deprecated. Instead architectures will leave the raw
1269 register value as is and instead clean things up as they pass
1270 through the method gdbarch_pseudo_register_read() clean up the
1273 #ifdef DEPRECATED_CLEAN_UP_REGISTER_VALUE
1274 DEPRECATED_CLEAN_UP_REGISTER_VALUE \
1275 (regnum
, register_buffer (current_regcache
, regnum
));
1280 regcache_collect (int regnum
, void *buf
)
1282 memcpy (buf
, register_buffer (current_regcache
, regnum
),
1283 REGISTER_RAW_SIZE (regnum
));
1287 /* read_pc, write_pc, read_sp, write_sp, read_fp, etc. Special
1288 handling for registers PC, SP, and FP. */
1290 /* NOTE: cagney/2001-02-18: The functions generic_target_read_pc(),
1291 read_pc_pid(), read_pc(), generic_target_write_pc(),
1292 write_pc_pid(), write_pc(), generic_target_read_sp(), read_sp(),
1293 generic_target_write_sp(), write_sp(), generic_target_read_fp() and
1294 read_fp(), will eventually be moved out of the reg-cache into
1295 either frame.[hc] or to the multi-arch framework. The are not part
1296 of the raw register cache. */
1298 /* This routine is getting awfully cluttered with #if's. It's probably
1299 time to turn this into READ_PC and define it in the tm.h file.
1302 1999-06-08: The following were re-written so that it assumes the
1303 existence of a TARGET_READ_PC et.al. macro. A default generic
1304 version of that macro is made available where needed.
1306 Since the ``TARGET_READ_PC'' et.al. macro is going to be controlled
1307 by the multi-arch framework, it will eventually be possible to
1308 eliminate the intermediate read_pc_pid(). The client would call
1309 TARGET_READ_PC directly. (cagney). */
1312 generic_target_read_pc (ptid_t ptid
)
1317 CORE_ADDR pc_val
= ADDR_BITS_REMOVE ((CORE_ADDR
) read_register_pid (PC_REGNUM
, ptid
));
1321 internal_error (__FILE__
, __LINE__
,
1322 "generic_target_read_pc");
1327 read_pc_pid (ptid_t ptid
)
1329 ptid_t saved_inferior_ptid
;
1332 /* In case ptid != inferior_ptid. */
1333 saved_inferior_ptid
= inferior_ptid
;
1334 inferior_ptid
= ptid
;
1336 pc_val
= TARGET_READ_PC (ptid
);
1338 inferior_ptid
= saved_inferior_ptid
;
1345 return read_pc_pid (inferior_ptid
);
1349 generic_target_write_pc (CORE_ADDR pc
, ptid_t ptid
)
1353 write_register_pid (PC_REGNUM
, pc
, ptid
);
1354 if (NPC_REGNUM
>= 0)
1355 write_register_pid (NPC_REGNUM
, pc
+ 4, ptid
);
1357 internal_error (__FILE__
, __LINE__
,
1358 "generic_target_write_pc");
1363 write_pc_pid (CORE_ADDR pc
, ptid_t ptid
)
1365 ptid_t saved_inferior_ptid
;
1367 /* In case ptid != inferior_ptid. */
1368 saved_inferior_ptid
= inferior_ptid
;
1369 inferior_ptid
= ptid
;
1371 TARGET_WRITE_PC (pc
, ptid
);
1373 inferior_ptid
= saved_inferior_ptid
;
1377 write_pc (CORE_ADDR pc
)
1379 write_pc_pid (pc
, inferior_ptid
);
1382 /* Cope with strage ways of getting to the stack and frame pointers */
1385 generic_target_read_sp (void)
1389 return read_register (SP_REGNUM
);
1391 internal_error (__FILE__
, __LINE__
,
1392 "generic_target_read_sp");
1398 return TARGET_READ_SP ();
1402 generic_target_write_sp (CORE_ADDR val
)
1407 write_register (SP_REGNUM
, val
);
1411 internal_error (__FILE__
, __LINE__
,
1412 "generic_target_write_sp");
1416 write_sp (CORE_ADDR val
)
1418 TARGET_WRITE_SP (val
);
1422 generic_target_read_fp (void)
1426 return read_register (FP_REGNUM
);
1428 internal_error (__FILE__
, __LINE__
,
1429 "generic_target_read_fp");
1435 return TARGET_READ_FP ();
1440 reg_flush_command (char *command
, int from_tty
)
1442 /* Force-flush the register cache. */
1443 registers_changed ();
1445 printf_filtered ("Register cache flushed.\n");
1449 build_regcache (void)
1451 current_regcache
= regcache_xmalloc (current_gdbarch
);
1452 current_regcache
->readonly_p
= 0;
1453 deprecated_registers
= deprecated_grub_regcache_for_registers (current_regcache
);
1454 deprecated_register_valid
= deprecated_grub_regcache_for_register_valid (current_regcache
);
1458 dump_endian_bytes (struct ui_file
*file
, enum bfd_endian endian
,
1459 const unsigned char *buf
, long len
)
1464 case BFD_ENDIAN_BIG
:
1465 for (i
= 0; i
< len
; i
++)
1466 fprintf_unfiltered (file
, "%02x", buf
[i
]);
1468 case BFD_ENDIAN_LITTLE
:
1469 for (i
= len
- 1; i
>= 0; i
--)
1470 fprintf_unfiltered (file
, "%02x", buf
[i
]);
1473 internal_error (__FILE__
, __LINE__
, "Bad switch");
1477 enum regcache_dump_what
1479 regcache_dump_none
, regcache_dump_raw
, regcache_dump_cooked
, regcache_dump_groups
1483 regcache_dump (struct regcache
*regcache
, struct ui_file
*file
,
1484 enum regcache_dump_what what_to_dump
)
1486 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
1487 struct gdbarch
*gdbarch
= regcache
->descr
->gdbarch
;
1488 struct reggroup
*const *groups
= reggroups (gdbarch
);
1490 int footnote_nr
= 0;
1491 int footnote_register_size
= 0;
1492 int footnote_register_offset
= 0;
1493 int footnote_register_type_name_null
= 0;
1494 long register_offset
= 0;
1495 unsigned char *buf
= alloca (regcache
->descr
->max_register_size
);
1498 fprintf_unfiltered (file
, "legacy_p %d\n", regcache
->descr
->legacy_p
);
1499 fprintf_unfiltered (file
, "nr_raw_registers %d\n",
1500 regcache
->descr
->nr_raw_registers
);
1501 fprintf_unfiltered (file
, "nr_cooked_registers %d\n",
1502 regcache
->descr
->nr_cooked_registers
);
1503 fprintf_unfiltered (file
, "sizeof_raw_registers %ld\n",
1504 regcache
->descr
->sizeof_raw_registers
);
1505 fprintf_unfiltered (file
, "sizeof_raw_register_valid_p %ld\n",
1506 regcache
->descr
->sizeof_raw_register_valid_p
);
1507 fprintf_unfiltered (file
, "max_register_size %ld\n",
1508 regcache
->descr
->max_register_size
);
1509 fprintf_unfiltered (file
, "NUM_REGS %d\n", NUM_REGS
);
1510 fprintf_unfiltered (file
, "NUM_PSEUDO_REGS %d\n", NUM_PSEUDO_REGS
);
1513 gdb_assert (regcache
->descr
->nr_cooked_registers
1514 == (NUM_REGS
+ NUM_PSEUDO_REGS
));
1516 for (regnum
= -1; regnum
< regcache
->descr
->nr_cooked_registers
; regnum
++)
1520 fprintf_unfiltered (file
, " %-10s", "Name");
1523 const char *p
= REGISTER_NAME (regnum
);
1526 else if (p
[0] == '\0')
1528 fprintf_unfiltered (file
, " %-10s", p
);
1533 fprintf_unfiltered (file
, " %4s", "Nr");
1535 fprintf_unfiltered (file
, " %4d", regnum
);
1537 /* Relative number. */
1539 fprintf_unfiltered (file
, " %4s", "Rel");
1540 else if (regnum
< NUM_REGS
)
1541 fprintf_unfiltered (file
, " %4d", regnum
);
1543 fprintf_unfiltered (file
, " %4d", (regnum
- NUM_REGS
));
1547 fprintf_unfiltered (file
, " %6s ", "Offset");
1550 fprintf_unfiltered (file
, " %6ld",
1551 regcache
->descr
->register_offset
[regnum
]);
1552 if (register_offset
!= regcache
->descr
->register_offset
[regnum
]
1553 || register_offset
!= REGISTER_BYTE (regnum
)
1555 && (regcache
->descr
->register_offset
[regnum
]
1556 != (regcache
->descr
->register_offset
[regnum
- 1]
1557 + regcache
->descr
->sizeof_register
[regnum
- 1])))
1560 if (!footnote_register_offset
)
1561 footnote_register_offset
= ++footnote_nr
;
1562 fprintf_unfiltered (file
, "*%d", footnote_register_offset
);
1565 fprintf_unfiltered (file
, " ");
1566 register_offset
= (regcache
->descr
->register_offset
[regnum
]
1567 + regcache
->descr
->sizeof_register
[regnum
]);
1572 fprintf_unfiltered (file
, " %5s ", "Size");
1575 fprintf_unfiltered (file
, " %5ld",
1576 regcache
->descr
->sizeof_register
[regnum
]);
1577 if ((regcache
->descr
->sizeof_register
[regnum
]
1578 != REGISTER_RAW_SIZE (regnum
))
1579 || (regcache
->descr
->sizeof_register
[regnum
]
1580 != REGISTER_VIRTUAL_SIZE (regnum
))
1581 || (regcache
->descr
->sizeof_register
[regnum
]
1582 != TYPE_LENGTH (register_type (regcache
->descr
->gdbarch
,
1586 if (!footnote_register_size
)
1587 footnote_register_size
= ++footnote_nr
;
1588 fprintf_unfiltered (file
, "*%d", footnote_register_size
);
1591 fprintf_unfiltered (file
, " ");
1601 static const char blt
[] = "builtin_type";
1602 t
= TYPE_NAME (register_type (regcache
->descr
->gdbarch
, regnum
));
1606 if (!footnote_register_type_name_null
)
1607 footnote_register_type_name_null
= ++footnote_nr
;
1608 xasprintf (&n
, "*%d", footnote_register_type_name_null
);
1609 make_cleanup (xfree
, n
);
1612 /* Chop a leading builtin_type. */
1613 if (strncmp (t
, blt
, strlen (blt
)) == 0)
1616 fprintf_unfiltered (file
, " %-15s", t
);
1619 /* Leading space always present. */
1620 fprintf_unfiltered (file
, " ");
1623 if (what_to_dump
== regcache_dump_raw
)
1626 fprintf_unfiltered (file
, "Raw value");
1627 else if (regnum
>= regcache
->descr
->nr_raw_registers
)
1628 fprintf_unfiltered (file
, "<cooked>");
1629 else if (!regcache_valid_p (regcache
, regnum
))
1630 fprintf_unfiltered (file
, "<invalid>");
1633 regcache_raw_read (regcache
, regnum
, buf
);
1634 fprintf_unfiltered (file
, "0x");
1635 dump_endian_bytes (file
, TARGET_BYTE_ORDER
, buf
,
1636 REGISTER_RAW_SIZE (regnum
));
1640 /* Value, cooked. */
1641 if (what_to_dump
== regcache_dump_cooked
)
1644 fprintf_unfiltered (file
, "Cooked value");
1647 regcache_cooked_read (regcache
, regnum
, buf
);
1648 fprintf_unfiltered (file
, "0x");
1649 dump_endian_bytes (file
, TARGET_BYTE_ORDER
, buf
,
1650 REGISTER_VIRTUAL_SIZE (regnum
));
1654 /* Group members. */
1655 if (what_to_dump
== regcache_dump_groups
)
1658 fprintf_unfiltered (file
, "Groups");
1662 const char *sep
= "";
1663 for (i
= 0; groups
[i
] != NULL
; i
++)
1665 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, groups
[i
]))
1667 fprintf_unfiltered (file
, "%s%s", sep
, reggroup_name (groups
[i
]));
1674 fprintf_unfiltered (file
, "\n");
1677 if (footnote_register_size
)
1678 fprintf_unfiltered (file
, "*%d: Inconsistent register sizes.\n",
1679 footnote_register_size
);
1680 if (footnote_register_offset
)
1681 fprintf_unfiltered (file
, "*%d: Inconsistent register offsets.\n",
1682 footnote_register_offset
);
1683 if (footnote_register_type_name_null
)
1684 fprintf_unfiltered (file
,
1685 "*%d: Register type's name NULL.\n",
1686 footnote_register_type_name_null
);
1687 do_cleanups (cleanups
);
1691 regcache_print (char *args
, enum regcache_dump_what what_to_dump
)
1694 regcache_dump (current_regcache
, gdb_stdout
, what_to_dump
);
1697 struct ui_file
*file
= gdb_fopen (args
, "w");
1699 perror_with_name ("maintenance print architecture");
1700 regcache_dump (current_regcache
, file
, what_to_dump
);
1701 ui_file_delete (file
);
1706 maintenance_print_registers (char *args
, int from_tty
)
1708 regcache_print (args
, regcache_dump_none
);
1712 maintenance_print_raw_registers (char *args
, int from_tty
)
1714 regcache_print (args
, regcache_dump_raw
);
1718 maintenance_print_cooked_registers (char *args
, int from_tty
)
1720 regcache_print (args
, regcache_dump_cooked
);
1724 maintenance_print_register_groups (char *args
, int from_tty
)
1726 regcache_print (args
, regcache_dump_groups
);
1730 _initialize_regcache (void)
1732 regcache_descr_handle
= register_gdbarch_data (init_regcache_descr
,
1733 xfree_regcache_descr
);
1734 REGISTER_GDBARCH_SWAP (current_regcache
);
1735 register_gdbarch_swap (&deprecated_registers
, sizeof (deprecated_registers
), NULL
);
1736 register_gdbarch_swap (&deprecated_register_valid
, sizeof (deprecated_register_valid
), NULL
);
1737 register_gdbarch_swap (NULL
, 0, build_regcache
);
1739 add_com ("flushregs", class_maintenance
, reg_flush_command
,
1740 "Force gdb to flush its register cache (maintainer command)");
1742 /* Initialize the thread/process associated with the current set of
1743 registers. For now, -1 is special, and means `no current process'. */
1744 registers_ptid
= pid_to_ptid (-1);
1746 add_cmd ("registers", class_maintenance
,
1747 maintenance_print_registers
,
1748 "Print the internal register configuration.\
1749 Takes an optional file parameter.",
1750 &maintenanceprintlist
);
1751 add_cmd ("raw-registers", class_maintenance
,
1752 maintenance_print_raw_registers
,
1753 "Print the internal register configuration including raw values.\
1754 Takes an optional file parameter.",
1755 &maintenanceprintlist
);
1756 add_cmd ("cooked-registers", class_maintenance
,
1757 maintenance_print_cooked_registers
,
1758 "Print the internal register configuration including cooked values.\
1759 Takes an optional file parameter.",
1760 &maintenanceprintlist
);
1761 add_cmd ("register-groups", class_maintenance
,
1762 maintenance_print_register_groups
,
1763 "Print the internal register configuration including each register's group.\
1764 Takes an optional file parameter.",
1765 &maintenanceprintlist
);