1 /* Cache and manage the values of registers for GDB, the GNU debugger.
3 Copyright (C) 1986-2017 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
26 #include "reggroups.h"
35 * Here is the actual register cache.
38 /* Per-architecture object describing the layout of a register cache.
39 Computed once when the architecture is created. */
41 struct gdbarch_data
*regcache_descr_handle
;
45 /* The architecture this descriptor belongs to. */
46 struct gdbarch
*gdbarch
;
48 /* The raw register cache. Each raw (or hard) register is supplied
49 by the target interface. The raw cache should not contain
50 redundant information - if the PC is constructed from two
51 registers then those registers and not the PC lives in the raw
54 long sizeof_raw_registers
;
55 long sizeof_raw_register_status
;
57 /* The cooked register space. Each cooked register in the range
58 [0..NR_RAW_REGISTERS) is direct-mapped onto the corresponding raw
59 register. The remaining [NR_RAW_REGISTERS
60 .. NR_COOKED_REGISTERS) (a.k.a. pseudo registers) are mapped onto
61 both raw registers and memory by the architecture methods
62 gdbarch_pseudo_register_read and gdbarch_pseudo_register_write. */
63 int nr_cooked_registers
;
64 long sizeof_cooked_registers
;
65 long sizeof_cooked_register_status
;
67 /* Offset and size (in 8 bit bytes), of each register in the
68 register cache. All registers (including those in the range
69 [NR_RAW_REGISTERS .. NR_COOKED_REGISTERS) are given an
71 long *register_offset
;
72 long *sizeof_register
;
74 /* Cached table containing the type of each register. */
75 struct type
**register_type
;
79 init_regcache_descr (struct gdbarch
*gdbarch
)
82 struct regcache_descr
*descr
;
83 gdb_assert (gdbarch
!= NULL
);
85 /* Create an initial, zero filled, table. */
86 descr
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct regcache_descr
);
87 descr
->gdbarch
= gdbarch
;
89 /* Total size of the register space. The raw registers are mapped
90 directly onto the raw register cache while the pseudo's are
91 either mapped onto raw-registers or memory. */
92 descr
->nr_cooked_registers
= gdbarch_num_regs (gdbarch
)
93 + gdbarch_num_pseudo_regs (gdbarch
);
94 descr
->sizeof_cooked_register_status
95 = gdbarch_num_regs (gdbarch
) + gdbarch_num_pseudo_regs (gdbarch
);
97 /* Fill in a table of register types. */
99 = GDBARCH_OBSTACK_CALLOC (gdbarch
, descr
->nr_cooked_registers
,
101 for (i
= 0; i
< descr
->nr_cooked_registers
; i
++)
102 descr
->register_type
[i
] = gdbarch_register_type (gdbarch
, i
);
104 /* Construct a strictly RAW register cache. Don't allow pseudo's
105 into the register cache. */
106 descr
->nr_raw_registers
= gdbarch_num_regs (gdbarch
);
107 descr
->sizeof_raw_register_status
= gdbarch_num_regs (gdbarch
);
109 /* Lay out the register cache.
111 NOTE: cagney/2002-05-22: Only register_type() is used when
112 constructing the register cache. It is assumed that the
113 register's raw size, virtual size and type length are all the
119 descr
->sizeof_register
120 = GDBARCH_OBSTACK_CALLOC (gdbarch
, descr
->nr_cooked_registers
, long);
121 descr
->register_offset
122 = GDBARCH_OBSTACK_CALLOC (gdbarch
, descr
->nr_cooked_registers
, long);
123 for (i
= 0; i
< descr
->nr_raw_registers
; i
++)
125 descr
->sizeof_register
[i
] = TYPE_LENGTH (descr
->register_type
[i
]);
126 descr
->register_offset
[i
] = offset
;
127 offset
+= descr
->sizeof_register
[i
];
128 gdb_assert (MAX_REGISTER_SIZE
>= descr
->sizeof_register
[i
]);
130 /* Set the real size of the raw register cache buffer. */
131 descr
->sizeof_raw_registers
= offset
;
133 for (; i
< descr
->nr_cooked_registers
; i
++)
135 descr
->sizeof_register
[i
] = TYPE_LENGTH (descr
->register_type
[i
]);
136 descr
->register_offset
[i
] = offset
;
137 offset
+= descr
->sizeof_register
[i
];
138 gdb_assert (MAX_REGISTER_SIZE
>= descr
->sizeof_register
[i
]);
140 /* Set the real size of the readonly register cache buffer. */
141 descr
->sizeof_cooked_registers
= offset
;
147 static struct regcache_descr
*
148 regcache_descr (struct gdbarch
*gdbarch
)
150 return (struct regcache_descr
*) gdbarch_data (gdbarch
,
151 regcache_descr_handle
);
154 /* Utility functions returning useful register attributes stored in
155 the regcache descr. */
158 register_type (struct gdbarch
*gdbarch
, int regnum
)
160 struct regcache_descr
*descr
= regcache_descr (gdbarch
);
162 gdb_assert (regnum
>= 0 && regnum
< descr
->nr_cooked_registers
);
163 return descr
->register_type
[regnum
];
166 /* Utility functions returning useful register attributes stored in
167 the regcache descr. */
170 register_size (struct gdbarch
*gdbarch
, int regnum
)
172 struct regcache_descr
*descr
= regcache_descr (gdbarch
);
175 gdb_assert (regnum
>= 0
176 && regnum
< (gdbarch_num_regs (gdbarch
)
177 + gdbarch_num_pseudo_regs (gdbarch
)));
178 size
= descr
->sizeof_register
[regnum
];
182 /* See common/common-regcache.h. */
185 regcache_register_size (const struct regcache
*regcache
, int n
)
187 return register_size (get_regcache_arch (regcache
), n
);
190 /* The register cache for storing raw register values. */
194 struct regcache_descr
*descr
;
196 /* The address space of this register cache (for registers where it
197 makes sense, like PC or SP). */
198 struct address_space
*aspace
;
200 /* The register buffers. A read-only register cache can hold the
201 full [0 .. gdbarch_num_regs + gdbarch_num_pseudo_regs) while a read/write
202 register cache can only hold [0 .. gdbarch_num_regs). */
204 /* Register cache status. */
205 signed char *register_status
;
206 /* Is this a read-only cache? A read-only cache is used for saving
207 the target's register state (e.g, across an inferior function
208 call or just before forcing a function return). A read-only
209 cache can only be updated via the methods regcache_dup() and
210 regcache_cpy(). The actual contents are determined by the
211 reggroup_save and reggroup_restore methods. */
213 /* If this is a read-write cache, which thread's registers is
218 /* See regcache.h. */
221 regcache_get_ptid (const struct regcache
*regcache
)
223 gdb_assert (!ptid_equal (regcache
->ptid
, minus_one_ptid
));
225 return regcache
->ptid
;
228 static struct regcache
*
229 regcache_xmalloc_1 (struct gdbarch
*gdbarch
, struct address_space
*aspace
,
232 struct regcache_descr
*descr
;
233 struct regcache
*regcache
;
235 gdb_assert (gdbarch
!= NULL
);
236 descr
= regcache_descr (gdbarch
);
237 regcache
= XNEW (struct regcache
);
238 regcache
->descr
= descr
;
239 regcache
->readonly_p
= readonly_p
;
243 = XCNEWVEC (gdb_byte
, descr
->sizeof_cooked_registers
);
244 regcache
->register_status
245 = XCNEWVEC (signed char, descr
->sizeof_cooked_register_status
);
250 = XCNEWVEC (gdb_byte
, descr
->sizeof_raw_registers
);
251 regcache
->register_status
252 = XCNEWVEC (signed char, descr
->sizeof_raw_register_status
);
254 regcache
->aspace
= aspace
;
255 regcache
->ptid
= minus_one_ptid
;
260 regcache_xmalloc (struct gdbarch
*gdbarch
, struct address_space
*aspace
)
262 return regcache_xmalloc_1 (gdbarch
, aspace
, true);
266 regcache_xfree (struct regcache
*regcache
)
268 if (regcache
== NULL
)
270 xfree (regcache
->registers
);
271 xfree (regcache
->register_status
);
276 do_regcache_xfree (void *data
)
278 regcache_xfree ((struct regcache
*) data
);
282 make_cleanup_regcache_xfree (struct regcache
*regcache
)
284 return make_cleanup (do_regcache_xfree
, regcache
);
287 /* Cleanup routines for invalidating a register. */
289 struct register_to_invalidate
291 struct regcache
*regcache
;
296 do_regcache_invalidate (void *data
)
298 struct register_to_invalidate
*reg
= (struct register_to_invalidate
*) data
;
300 regcache_invalidate (reg
->regcache
, reg
->regnum
);
303 static struct cleanup
*
304 make_cleanup_regcache_invalidate (struct regcache
*regcache
, int regnum
)
306 struct register_to_invalidate
* reg
= XNEW (struct register_to_invalidate
);
308 reg
->regcache
= regcache
;
309 reg
->regnum
= regnum
;
310 return make_cleanup_dtor (do_regcache_invalidate
, (void *) reg
, xfree
);
313 /* Return REGCACHE's architecture. */
316 get_regcache_arch (const struct regcache
*regcache
)
318 return regcache
->descr
->gdbarch
;
321 struct address_space
*
322 get_regcache_aspace (const struct regcache
*regcache
)
324 return regcache
->aspace
;
327 /* Return a pointer to register REGNUM's buffer cache. */
330 register_buffer (const struct regcache
*regcache
, int regnum
)
332 return regcache
->registers
+ regcache
->descr
->register_offset
[regnum
];
336 regcache_save (struct regcache
*dst
, regcache_cooked_read_ftype
*cooked_read
,
339 struct gdbarch
*gdbarch
= dst
->descr
->gdbarch
;
340 gdb_byte buf
[MAX_REGISTER_SIZE
];
343 /* The DST should be `read-only', if it wasn't then the save would
344 end up trying to write the register values back out to the
346 gdb_assert (dst
->readonly_p
);
347 /* Clear the dest. */
348 memset (dst
->registers
, 0, dst
->descr
->sizeof_cooked_registers
);
349 memset (dst
->register_status
, 0,
350 dst
->descr
->sizeof_cooked_register_status
);
351 /* Copy over any registers (identified by their membership in the
352 save_reggroup) and mark them as valid. The full [0 .. gdbarch_num_regs +
353 gdbarch_num_pseudo_regs) range is checked since some architectures need
354 to save/restore `cooked' registers that live in memory. */
355 for (regnum
= 0; regnum
< dst
->descr
->nr_cooked_registers
; regnum
++)
357 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, save_reggroup
))
359 enum register_status status
= cooked_read (src
, regnum
, buf
);
361 if (status
== REG_VALID
)
362 memcpy (register_buffer (dst
, regnum
), buf
,
363 register_size (gdbarch
, regnum
));
366 gdb_assert (status
!= REG_UNKNOWN
);
368 memset (register_buffer (dst
, regnum
), 0,
369 register_size (gdbarch
, regnum
));
371 dst
->register_status
[regnum
] = status
;
377 regcache_restore (struct regcache
*dst
, struct regcache
*src
)
379 struct gdbarch
*gdbarch
= dst
->descr
->gdbarch
;
382 /* The dst had better not be read-only. If it is, the `restore'
383 doesn't make much sense. */
384 gdb_assert (!dst
->readonly_p
);
385 gdb_assert (src
->readonly_p
);
386 /* Copy over any registers, being careful to only restore those that
387 were both saved and need to be restored. The full [0 .. gdbarch_num_regs
388 + gdbarch_num_pseudo_regs) range is checked since some architectures need
389 to save/restore `cooked' registers that live in memory. */
390 for (regnum
= 0; regnum
< dst
->descr
->nr_cooked_registers
; regnum
++)
392 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, restore_reggroup
))
394 if (src
->register_status
[regnum
] == REG_VALID
)
395 regcache_cooked_write (dst
, regnum
, register_buffer (src
, regnum
));
400 static enum register_status
401 do_cooked_read (void *src
, int regnum
, gdb_byte
*buf
)
403 struct regcache
*regcache
= (struct regcache
*) src
;
405 return regcache_cooked_read (regcache
, regnum
, buf
);
408 static void regcache_cpy_no_passthrough (struct regcache
*dst
,
409 struct regcache
*src
);
412 regcache_cpy (struct regcache
*dst
, struct regcache
*src
)
414 gdb_assert (src
!= NULL
&& dst
!= NULL
);
415 gdb_assert (src
->descr
->gdbarch
== dst
->descr
->gdbarch
);
416 gdb_assert (src
!= dst
);
417 gdb_assert (src
->readonly_p
|| dst
->readonly_p
);
419 if (!src
->readonly_p
)
420 regcache_save (dst
, do_cooked_read
, src
);
421 else if (!dst
->readonly_p
)
422 regcache_restore (dst
, src
);
424 regcache_cpy_no_passthrough (dst
, src
);
427 /* Copy/duplicate the contents of a register cache. Unlike regcache_cpy,
428 which is pass-through, this does not go through to the target.
429 Only values values already in the cache are transferred. The SRC and DST
430 buffers must not overlap. */
433 regcache_cpy_no_passthrough (struct regcache
*dst
, struct regcache
*src
)
435 gdb_assert (src
!= NULL
&& dst
!= NULL
);
436 gdb_assert (src
->descr
->gdbarch
== dst
->descr
->gdbarch
);
437 /* NOTE: cagney/2002-05-17: Don't let the caller do a no-passthrough
438 move of data into a thread's regcache. Doing this would be silly
439 - it would mean that regcache->register_status would be
440 completely invalid. */
441 gdb_assert (dst
->readonly_p
&& src
->readonly_p
);
443 memcpy (dst
->registers
, src
->registers
,
444 dst
->descr
->sizeof_cooked_registers
);
445 memcpy (dst
->register_status
, src
->register_status
,
446 dst
->descr
->sizeof_cooked_register_status
);
450 regcache_dup (struct regcache
*src
)
452 struct regcache
*newbuf
;
454 newbuf
= regcache_xmalloc (src
->descr
->gdbarch
, get_regcache_aspace (src
));
455 regcache_cpy (newbuf
, src
);
460 regcache_register_status (const struct regcache
*regcache
, int regnum
)
462 gdb_assert (regcache
!= NULL
);
463 gdb_assert (regnum
>= 0);
464 if (regcache
->readonly_p
)
465 gdb_assert (regnum
< regcache
->descr
->nr_cooked_registers
);
467 gdb_assert (regnum
< regcache
->descr
->nr_raw_registers
);
469 return (enum register_status
) regcache
->register_status
[regnum
];
473 regcache_invalidate (struct regcache
*regcache
, int regnum
)
475 gdb_assert (regcache
!= NULL
);
476 gdb_assert (regnum
>= 0);
477 gdb_assert (!regcache
->readonly_p
);
478 gdb_assert (regnum
< regcache
->descr
->nr_raw_registers
);
479 regcache
->register_status
[regnum
] = REG_UNKNOWN
;
483 /* Global structure containing the 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. */
492 struct regcache
*regcache
;
493 struct regcache_list
*next
;
496 static struct regcache_list
*current_regcache
;
499 get_thread_arch_aspace_regcache (ptid_t ptid
, struct gdbarch
*gdbarch
,
500 struct address_space
*aspace
)
502 struct regcache_list
*list
;
503 struct regcache
*new_regcache
;
505 for (list
= current_regcache
; list
; list
= list
->next
)
506 if (ptid_equal (list
->regcache
->ptid
, ptid
)
507 && get_regcache_arch (list
->regcache
) == gdbarch
)
508 return list
->regcache
;
510 new_regcache
= regcache_xmalloc_1 (gdbarch
, aspace
, false);
511 new_regcache
->ptid
= ptid
;
513 list
= XNEW (struct regcache_list
);
514 list
->regcache
= new_regcache
;
515 list
->next
= current_regcache
;
516 current_regcache
= list
;
522 get_thread_arch_regcache (ptid_t ptid
, struct gdbarch
*gdbarch
)
524 struct address_space
*aspace
;
526 /* For the benefit of "maint print registers" & co when debugging an
527 executable, allow dumping the regcache even when there is no
528 thread selected (target_thread_address_space internal-errors if
529 no address space is found). Note that normal user commands will
530 fail higher up on the call stack due to no
531 target_has_registers. */
532 aspace
= (ptid_equal (null_ptid
, ptid
)
534 : target_thread_address_space (ptid
));
536 return get_thread_arch_aspace_regcache (ptid
, gdbarch
, aspace
);
539 static ptid_t current_thread_ptid
;
540 static struct gdbarch
*current_thread_arch
;
543 get_thread_regcache (ptid_t ptid
)
545 if (!current_thread_arch
|| !ptid_equal (current_thread_ptid
, ptid
))
547 current_thread_ptid
= ptid
;
548 current_thread_arch
= target_thread_architecture (ptid
);
551 return get_thread_arch_regcache (ptid
, current_thread_arch
);
555 get_current_regcache (void)
557 return get_thread_regcache (inferior_ptid
);
560 /* See common/common-regcache.h. */
563 get_thread_regcache_for_ptid (ptid_t ptid
)
565 return get_thread_regcache (ptid
);
568 /* Observer for the target_changed event. */
571 regcache_observer_target_changed (struct target_ops
*target
)
573 registers_changed ();
576 /* Update global variables old ptids to hold NEW_PTID if they were
579 regcache_thread_ptid_changed (ptid_t old_ptid
, ptid_t new_ptid
)
581 struct regcache_list
*list
;
583 for (list
= current_regcache
; list
; list
= list
->next
)
584 if (ptid_equal (list
->regcache
->ptid
, old_ptid
))
585 list
->regcache
->ptid
= new_ptid
;
588 /* Low level examining and depositing of registers.
590 The caller is responsible for making sure that the inferior is
591 stopped before calling the fetching routines, or it will get
592 garbage. (a change from GDB version 3, in which the caller got the
593 value from the last stop). */
595 /* REGISTERS_CHANGED ()
597 Indicate that registers may have changed, so invalidate the cache. */
600 registers_changed_ptid (ptid_t ptid
)
602 struct regcache_list
*list
, **list_link
;
604 list
= current_regcache
;
605 list_link
= ¤t_regcache
;
608 if (ptid_match (list
->regcache
->ptid
, ptid
))
610 struct regcache_list
*dead
= list
;
612 *list_link
= list
->next
;
613 regcache_xfree (list
->regcache
);
619 list_link
= &list
->next
;
623 if (ptid_match (current_thread_ptid
, ptid
))
625 current_thread_ptid
= null_ptid
;
626 current_thread_arch
= NULL
;
629 if (ptid_match (inferior_ptid
, ptid
))
631 /* We just deleted the regcache of the current thread. Need to
632 forget about any frames we have cached, too. */
633 reinit_frame_cache ();
638 registers_changed (void)
640 registers_changed_ptid (minus_one_ptid
);
642 /* Force cleanup of any alloca areas if using C alloca instead of
643 a builtin alloca. This particular call is used to clean up
644 areas allocated by low level target code which may build up
645 during lengthy interactions between gdb and the target before
646 gdb gives control to the user (ie watchpoints). */
651 regcache_raw_update (struct regcache
*regcache
, int regnum
)
653 gdb_assert (regcache
!= NULL
);
654 gdb_assert (regnum
>= 0 && regnum
< regcache
->descr
->nr_raw_registers
);
656 /* Make certain that the register cache is up-to-date with respect
657 to the current thread. This switching shouldn't be necessary
658 only there is still only one target side register cache. Sigh!
659 On the bright side, at least there is a regcache object. */
661 if (!regcache
->readonly_p
662 && regcache_register_status (regcache
, regnum
) == REG_UNKNOWN
)
664 target_fetch_registers (regcache
, regnum
);
666 /* A number of targets can't access the whole set of raw
667 registers (because the debug API provides no means to get at
669 if (regcache
->register_status
[regnum
] == REG_UNKNOWN
)
670 regcache
->register_status
[regnum
] = REG_UNAVAILABLE
;
675 regcache_raw_read (struct regcache
*regcache
, int regnum
, gdb_byte
*buf
)
677 gdb_assert (buf
!= NULL
);
678 regcache_raw_update (regcache
, regnum
);
680 if (regcache
->register_status
[regnum
] != REG_VALID
)
681 memset (buf
, 0, regcache
->descr
->sizeof_register
[regnum
]);
683 memcpy (buf
, register_buffer (regcache
, regnum
),
684 regcache
->descr
->sizeof_register
[regnum
]);
686 return (enum register_status
) regcache
->register_status
[regnum
];
690 regcache_raw_read_signed (struct regcache
*regcache
, int regnum
, LONGEST
*val
)
693 enum register_status status
;
695 gdb_assert (regcache
!= NULL
);
696 gdb_assert (regnum
>= 0 && regnum
< regcache
->descr
->nr_raw_registers
);
697 buf
= (gdb_byte
*) alloca (regcache
->descr
->sizeof_register
[regnum
]);
698 status
= regcache_raw_read (regcache
, regnum
, buf
);
699 if (status
== REG_VALID
)
700 *val
= extract_signed_integer
701 (buf
, regcache
->descr
->sizeof_register
[regnum
],
702 gdbarch_byte_order (regcache
->descr
->gdbarch
));
709 regcache_raw_read_unsigned (struct regcache
*regcache
, int regnum
,
713 enum register_status status
;
715 gdb_assert (regcache
!= NULL
);
716 gdb_assert (regnum
>= 0 && regnum
< regcache
->descr
->nr_raw_registers
);
717 buf
= (gdb_byte
*) alloca (regcache
->descr
->sizeof_register
[regnum
]);
718 status
= regcache_raw_read (regcache
, regnum
, buf
);
719 if (status
== REG_VALID
)
720 *val
= extract_unsigned_integer
721 (buf
, regcache
->descr
->sizeof_register
[regnum
],
722 gdbarch_byte_order (regcache
->descr
->gdbarch
));
729 regcache_raw_write_signed (struct regcache
*regcache
, int regnum
, LONGEST val
)
733 gdb_assert (regcache
!= NULL
);
734 gdb_assert (regnum
>=0 && regnum
< regcache
->descr
->nr_raw_registers
);
735 buf
= (gdb_byte
*) alloca (regcache
->descr
->sizeof_register
[regnum
]);
736 store_signed_integer (buf
, regcache
->descr
->sizeof_register
[regnum
],
737 gdbarch_byte_order (regcache
->descr
->gdbarch
), val
);
738 regcache_raw_write (regcache
, regnum
, buf
);
742 regcache_raw_write_unsigned (struct regcache
*regcache
, int regnum
,
747 gdb_assert (regcache
!= NULL
);
748 gdb_assert (regnum
>=0 && regnum
< regcache
->descr
->nr_raw_registers
);
749 buf
= (gdb_byte
*) alloca (regcache
->descr
->sizeof_register
[regnum
]);
750 store_unsigned_integer (buf
, regcache
->descr
->sizeof_register
[regnum
],
751 gdbarch_byte_order (regcache
->descr
->gdbarch
), val
);
752 regcache_raw_write (regcache
, regnum
, buf
);
756 regcache_raw_get_signed (struct regcache
*regcache
, int regnum
)
759 enum register_status status
;
761 status
= regcache_raw_read_signed (regcache
, regnum
, &value
);
762 if (status
== REG_UNAVAILABLE
)
763 throw_error (NOT_AVAILABLE_ERROR
,
764 _("Register %d is not available"), regnum
);
769 regcache_cooked_read (struct regcache
*regcache
, int regnum
, gdb_byte
*buf
)
771 gdb_assert (regnum
>= 0);
772 gdb_assert (regnum
< regcache
->descr
->nr_cooked_registers
);
773 if (regnum
< regcache
->descr
->nr_raw_registers
)
774 return regcache_raw_read (regcache
, regnum
, buf
);
775 else if (regcache
->readonly_p
776 && regcache
->register_status
[regnum
] != REG_UNKNOWN
)
778 /* Read-only register cache, perhaps the cooked value was
780 if (regcache
->register_status
[regnum
] == REG_VALID
)
781 memcpy (buf
, register_buffer (regcache
, regnum
),
782 regcache
->descr
->sizeof_register
[regnum
]);
784 memset (buf
, 0, regcache
->descr
->sizeof_register
[regnum
]);
786 return (enum register_status
) regcache
->register_status
[regnum
];
788 else if (gdbarch_pseudo_register_read_value_p (regcache
->descr
->gdbarch
))
790 struct value
*mark
, *computed
;
791 enum register_status result
= REG_VALID
;
793 mark
= value_mark ();
795 computed
= gdbarch_pseudo_register_read_value (regcache
->descr
->gdbarch
,
797 if (value_entirely_available (computed
))
798 memcpy (buf
, value_contents_raw (computed
),
799 regcache
->descr
->sizeof_register
[regnum
]);
802 memset (buf
, 0, regcache
->descr
->sizeof_register
[regnum
]);
803 result
= REG_UNAVAILABLE
;
806 value_free_to_mark (mark
);
811 return gdbarch_pseudo_register_read (regcache
->descr
->gdbarch
, regcache
,
816 regcache_cooked_read_value (struct regcache
*regcache
, int regnum
)
818 gdb_assert (regnum
>= 0);
819 gdb_assert (regnum
< regcache
->descr
->nr_cooked_registers
);
821 if (regnum
< regcache
->descr
->nr_raw_registers
822 || (regcache
->readonly_p
823 && regcache
->register_status
[regnum
] != REG_UNKNOWN
)
824 || !gdbarch_pseudo_register_read_value_p (regcache
->descr
->gdbarch
))
826 struct value
*result
;
828 result
= allocate_value (register_type (regcache
->descr
->gdbarch
,
830 VALUE_LVAL (result
) = lval_register
;
831 VALUE_REGNUM (result
) = regnum
;
833 /* It is more efficient in general to do this delegation in this
834 direction than in the other one, even though the value-based
836 if (regcache_cooked_read (regcache
, regnum
,
837 value_contents_raw (result
)) == REG_UNAVAILABLE
)
838 mark_value_bytes_unavailable (result
, 0,
839 TYPE_LENGTH (value_type (result
)));
844 return gdbarch_pseudo_register_read_value (regcache
->descr
->gdbarch
,
849 regcache_cooked_read_signed (struct regcache
*regcache
, int regnum
,
852 enum register_status status
;
855 gdb_assert (regcache
!= NULL
);
856 gdb_assert (regnum
>= 0 && regnum
< regcache
->descr
->nr_cooked_registers
);
857 buf
= (gdb_byte
*) alloca (regcache
->descr
->sizeof_register
[regnum
]);
858 status
= regcache_cooked_read (regcache
, regnum
, buf
);
859 if (status
== REG_VALID
)
860 *val
= extract_signed_integer
861 (buf
, regcache
->descr
->sizeof_register
[regnum
],
862 gdbarch_byte_order (regcache
->descr
->gdbarch
));
869 regcache_cooked_read_unsigned (struct regcache
*regcache
, int regnum
,
872 enum register_status status
;
875 gdb_assert (regcache
!= NULL
);
876 gdb_assert (regnum
>= 0 && regnum
< regcache
->descr
->nr_cooked_registers
);
877 buf
= (gdb_byte
*) alloca (regcache
->descr
->sizeof_register
[regnum
]);
878 status
= regcache_cooked_read (regcache
, regnum
, buf
);
879 if (status
== REG_VALID
)
880 *val
= extract_unsigned_integer
881 (buf
, regcache
->descr
->sizeof_register
[regnum
],
882 gdbarch_byte_order (regcache
->descr
->gdbarch
));
889 regcache_cooked_write_signed (struct regcache
*regcache
, int regnum
,
894 gdb_assert (regcache
!= NULL
);
895 gdb_assert (regnum
>=0 && regnum
< regcache
->descr
->nr_cooked_registers
);
896 buf
= (gdb_byte
*) alloca (regcache
->descr
->sizeof_register
[regnum
]);
897 store_signed_integer (buf
, regcache
->descr
->sizeof_register
[regnum
],
898 gdbarch_byte_order (regcache
->descr
->gdbarch
), val
);
899 regcache_cooked_write (regcache
, regnum
, buf
);
903 regcache_cooked_write_unsigned (struct regcache
*regcache
, int regnum
,
908 gdb_assert (regcache
!= NULL
);
909 gdb_assert (regnum
>=0 && regnum
< regcache
->descr
->nr_cooked_registers
);
910 buf
= (gdb_byte
*) alloca (regcache
->descr
->sizeof_register
[regnum
]);
911 store_unsigned_integer (buf
, regcache
->descr
->sizeof_register
[regnum
],
912 gdbarch_byte_order (regcache
->descr
->gdbarch
), val
);
913 regcache_cooked_write (regcache
, regnum
, buf
);
916 /* See regcache.h. */
919 regcache_raw_set_cached_value (struct regcache
*regcache
, int regnum
,
922 memcpy (register_buffer (regcache
, regnum
), buf
,
923 regcache
->descr
->sizeof_register
[regnum
]);
924 regcache
->register_status
[regnum
] = REG_VALID
;
928 regcache_raw_write (struct regcache
*regcache
, int regnum
,
931 struct cleanup
*old_chain
;
933 gdb_assert (regcache
!= NULL
&& buf
!= NULL
);
934 gdb_assert (regnum
>= 0 && regnum
< regcache
->descr
->nr_raw_registers
);
935 gdb_assert (!regcache
->readonly_p
);
937 /* On the sparc, writing %g0 is a no-op, so we don't even want to
938 change the registers array if something writes to this register. */
939 if (gdbarch_cannot_store_register (get_regcache_arch (regcache
), regnum
))
942 /* If we have a valid copy of the register, and new value == old
943 value, then don't bother doing the actual store. */
944 if (regcache_register_status (regcache
, regnum
) == REG_VALID
945 && (memcmp (register_buffer (regcache
, regnum
), buf
,
946 regcache
->descr
->sizeof_register
[regnum
]) == 0))
949 target_prepare_to_store (regcache
);
950 regcache_raw_set_cached_value (regcache
, regnum
, buf
);
952 /* Register a cleanup function for invalidating the register after it is
953 written, in case of a failure. */
954 old_chain
= make_cleanup_regcache_invalidate (regcache
, regnum
);
956 target_store_registers (regcache
, regnum
);
958 /* The target did not throw an error so we can discard invalidating the
959 register and restore the cleanup chain to what it was. */
960 discard_cleanups (old_chain
);
964 regcache_cooked_write (struct regcache
*regcache
, int regnum
,
967 gdb_assert (regnum
>= 0);
968 gdb_assert (regnum
< regcache
->descr
->nr_cooked_registers
);
969 if (regnum
< regcache
->descr
->nr_raw_registers
)
970 regcache_raw_write (regcache
, regnum
, buf
);
972 gdbarch_pseudo_register_write (regcache
->descr
->gdbarch
, regcache
,
976 /* Perform a partial register transfer using a read, modify, write
979 typedef void (regcache_read_ftype
) (struct regcache
*regcache
, int regnum
,
981 typedef void (regcache_write_ftype
) (struct regcache
*regcache
, int regnum
,
984 static enum register_status
985 regcache_xfer_part (struct regcache
*regcache
, int regnum
,
986 int offset
, int len
, void *in
, const void *out
,
987 enum register_status (*read
) (struct regcache
*regcache
,
990 void (*write
) (struct regcache
*regcache
, int regnum
,
991 const gdb_byte
*buf
))
993 struct regcache_descr
*descr
= regcache
->descr
;
994 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
995 gdb_byte
*reg
= (gdb_byte
*) alloca (register_size (gdbarch
, regnum
));
997 gdb_assert (offset
>= 0 && offset
<= descr
->sizeof_register
[regnum
]);
998 gdb_assert (len
>= 0 && offset
+ len
<= descr
->sizeof_register
[regnum
]);
999 /* Something to do? */
1000 if (offset
+ len
== 0)
1002 /* Read (when needed) ... */
1005 || offset
+ len
< descr
->sizeof_register
[regnum
])
1007 enum register_status status
;
1009 gdb_assert (read
!= NULL
);
1010 status
= read (regcache
, regnum
, reg
);
1011 if (status
!= REG_VALID
)
1014 /* ... modify ... */
1016 memcpy (in
, reg
+ offset
, len
);
1018 memcpy (reg
+ offset
, out
, len
);
1019 /* ... write (when needed). */
1022 gdb_assert (write
!= NULL
);
1023 write (regcache
, regnum
, reg
);
1029 enum register_status
1030 regcache_raw_read_part (struct regcache
*regcache
, int regnum
,
1031 int offset
, int len
, gdb_byte
*buf
)
1033 struct regcache_descr
*descr
= regcache
->descr
;
1035 gdb_assert (regnum
>= 0 && regnum
< descr
->nr_raw_registers
);
1036 return regcache_xfer_part (regcache
, regnum
, offset
, len
, buf
, NULL
,
1037 regcache_raw_read
, regcache_raw_write
);
1041 regcache_raw_write_part (struct regcache
*regcache
, int regnum
,
1042 int offset
, int len
, const gdb_byte
*buf
)
1044 struct regcache_descr
*descr
= regcache
->descr
;
1046 gdb_assert (regnum
>= 0 && regnum
< descr
->nr_raw_registers
);
1047 regcache_xfer_part (regcache
, regnum
, offset
, len
, NULL
, buf
,
1048 regcache_raw_read
, regcache_raw_write
);
1051 enum register_status
1052 regcache_cooked_read_part (struct regcache
*regcache
, int regnum
,
1053 int offset
, int len
, gdb_byte
*buf
)
1055 struct regcache_descr
*descr
= regcache
->descr
;
1057 gdb_assert (regnum
>= 0 && regnum
< descr
->nr_cooked_registers
);
1058 return regcache_xfer_part (regcache
, regnum
, offset
, len
, buf
, NULL
,
1059 regcache_cooked_read
, regcache_cooked_write
);
1063 regcache_cooked_write_part (struct regcache
*regcache
, int regnum
,
1064 int offset
, int len
, const gdb_byte
*buf
)
1066 struct regcache_descr
*descr
= regcache
->descr
;
1068 gdb_assert (regnum
>= 0 && regnum
< descr
->nr_cooked_registers
);
1069 regcache_xfer_part (regcache
, regnum
, offset
, len
, NULL
, buf
,
1070 regcache_cooked_read
, regcache_cooked_write
);
1073 /* Supply register REGNUM, whose contents are stored in BUF, to REGCACHE. */
1076 regcache_raw_supply (struct regcache
*regcache
, int regnum
, const void *buf
)
1081 gdb_assert (regcache
!= NULL
);
1082 gdb_assert (regnum
>= 0 && regnum
< regcache
->descr
->nr_raw_registers
);
1083 gdb_assert (!regcache
->readonly_p
);
1085 regbuf
= register_buffer (regcache
, regnum
);
1086 size
= regcache
->descr
->sizeof_register
[regnum
];
1090 memcpy (regbuf
, buf
, size
);
1091 regcache
->register_status
[regnum
] = REG_VALID
;
1095 /* This memset not strictly necessary, but better than garbage
1096 in case the register value manages to escape somewhere (due
1097 to a bug, no less). */
1098 memset (regbuf
, 0, size
);
1099 regcache
->register_status
[regnum
] = REG_UNAVAILABLE
;
1103 /* Collect register REGNUM from REGCACHE and store its contents in BUF. */
1106 regcache_raw_collect (const struct regcache
*regcache
, int regnum
, void *buf
)
1111 gdb_assert (regcache
!= NULL
&& buf
!= NULL
);
1112 gdb_assert (regnum
>= 0 && regnum
< regcache
->descr
->nr_raw_registers
);
1114 regbuf
= register_buffer (regcache
, regnum
);
1115 size
= regcache
->descr
->sizeof_register
[regnum
];
1116 memcpy (buf
, regbuf
, size
);
1119 /* Transfer a single or all registers belonging to a certain register
1120 set to or from a buffer. This is the main worker function for
1121 regcache_supply_regset and regcache_collect_regset. */
1124 regcache_transfer_regset (const struct regset
*regset
,
1125 const struct regcache
*regcache
,
1126 struct regcache
*out_regcache
,
1127 int regnum
, const void *in_buf
,
1128 void *out_buf
, size_t size
)
1130 const struct regcache_map_entry
*map
;
1131 int offs
= 0, count
;
1133 for (map
= (const struct regcache_map_entry
*) regset
->regmap
;
1134 (count
= map
->count
) != 0;
1137 int regno
= map
->regno
;
1138 int slot_size
= map
->size
;
1140 if (slot_size
== 0 && regno
!= REGCACHE_MAP_SKIP
)
1141 slot_size
= regcache
->descr
->sizeof_register
[regno
];
1143 if (regno
== REGCACHE_MAP_SKIP
1145 && (regnum
< regno
|| regnum
>= regno
+ count
)))
1146 offs
+= count
* slot_size
;
1148 else if (regnum
== -1)
1149 for (; count
--; regno
++, offs
+= slot_size
)
1151 if (offs
+ slot_size
> size
)
1155 regcache_raw_collect (regcache
, regno
,
1156 (gdb_byte
*) out_buf
+ offs
);
1158 regcache_raw_supply (out_regcache
, regno
, in_buf
1159 ? (const gdb_byte
*) in_buf
+ offs
1164 /* Transfer a single register and return. */
1165 offs
+= (regnum
- regno
) * slot_size
;
1166 if (offs
+ slot_size
> size
)
1170 regcache_raw_collect (regcache
, regnum
,
1171 (gdb_byte
*) out_buf
+ offs
);
1173 regcache_raw_supply (out_regcache
, regnum
, in_buf
1174 ? (const gdb_byte
*) in_buf
+ offs
1181 /* Supply register REGNUM from BUF to REGCACHE, using the register map
1182 in REGSET. If REGNUM is -1, do this for all registers in REGSET.
1183 If BUF is NULL, set the register(s) to "unavailable" status. */
1186 regcache_supply_regset (const struct regset
*regset
,
1187 struct regcache
*regcache
,
1188 int regnum
, const void *buf
, size_t size
)
1190 regcache_transfer_regset (regset
, regcache
, regcache
, regnum
,
1194 /* Collect register REGNUM from REGCACHE to BUF, using the register
1195 map in REGSET. If REGNUM is -1, do this for all registers in
1199 regcache_collect_regset (const struct regset
*regset
,
1200 const struct regcache
*regcache
,
1201 int regnum
, void *buf
, size_t size
)
1203 regcache_transfer_regset (regset
, regcache
, NULL
, regnum
,
1208 /* Special handling for register PC. */
1211 regcache_read_pc (struct regcache
*regcache
)
1213 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1217 if (gdbarch_read_pc_p (gdbarch
))
1218 pc_val
= gdbarch_read_pc (gdbarch
, regcache
);
1219 /* Else use per-frame method on get_current_frame. */
1220 else if (gdbarch_pc_regnum (gdbarch
) >= 0)
1224 if (regcache_cooked_read_unsigned (regcache
,
1225 gdbarch_pc_regnum (gdbarch
),
1226 &raw_val
) == REG_UNAVAILABLE
)
1227 throw_error (NOT_AVAILABLE_ERROR
, _("PC register is not available"));
1229 pc_val
= gdbarch_addr_bits_remove (gdbarch
, raw_val
);
1232 internal_error (__FILE__
, __LINE__
,
1233 _("regcache_read_pc: Unable to find PC"));
1238 regcache_write_pc (struct regcache
*regcache
, CORE_ADDR pc
)
1240 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1242 if (gdbarch_write_pc_p (gdbarch
))
1243 gdbarch_write_pc (gdbarch
, regcache
, pc
);
1244 else if (gdbarch_pc_regnum (gdbarch
) >= 0)
1245 regcache_cooked_write_unsigned (regcache
,
1246 gdbarch_pc_regnum (gdbarch
), pc
);
1248 internal_error (__FILE__
, __LINE__
,
1249 _("regcache_write_pc: Unable to update PC"));
1251 /* Writing the PC (for instance, from "load") invalidates the
1253 reinit_frame_cache ();
1257 regcache_debug_print_register (const char *func
, struct regcache
*regcache
,
1260 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1262 fprintf_unfiltered (gdb_stdlog
, "%s ", func
);
1263 if (regno
>= 0 && regno
< gdbarch_num_regs (gdbarch
)
1264 && gdbarch_register_name (gdbarch
, regno
) != NULL
1265 && gdbarch_register_name (gdbarch
, regno
)[0] != '\0')
1266 fprintf_unfiltered (gdb_stdlog
, "(%s)",
1267 gdbarch_register_name (gdbarch
, regno
));
1269 fprintf_unfiltered (gdb_stdlog
, "(%d)", regno
);
1270 if (regno
>= 0 && regno
< gdbarch_num_regs (gdbarch
))
1272 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1273 int size
= register_size (gdbarch
, regno
);
1274 gdb_byte
*buf
= register_buffer (regcache
, regno
);
1276 fprintf_unfiltered (gdb_stdlog
, " = ");
1277 for (int i
= 0; i
< size
; i
++)
1279 fprintf_unfiltered (gdb_stdlog
, "%02x", buf
[i
]);
1281 if (size
<= sizeof (LONGEST
))
1283 ULONGEST val
= extract_unsigned_integer (buf
, size
, byte_order
);
1285 fprintf_unfiltered (gdb_stdlog
, " %s %s",
1286 core_addr_to_string_nz (val
), plongest (val
));
1289 fprintf_unfiltered (gdb_stdlog
, "\n");
1293 reg_flush_command (char *command
, int from_tty
)
1295 /* Force-flush the register cache. */
1296 registers_changed ();
1298 printf_filtered (_("Register cache flushed.\n"));
1301 enum regcache_dump_what
1303 regcache_dump_none
, regcache_dump_raw
,
1304 regcache_dump_cooked
, regcache_dump_groups
,
1305 regcache_dump_remote
1309 regcache_dump (struct regcache
*regcache
, struct ui_file
*file
,
1310 enum regcache_dump_what what_to_dump
)
1312 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
1313 struct gdbarch
*gdbarch
= regcache
->descr
->gdbarch
;
1315 int footnote_nr
= 0;
1316 int footnote_register_size
= 0;
1317 int footnote_register_offset
= 0;
1318 int footnote_register_type_name_null
= 0;
1319 long register_offset
= 0;
1320 gdb_byte buf
[MAX_REGISTER_SIZE
];
1323 fprintf_unfiltered (file
, "nr_raw_registers %d\n",
1324 regcache
->descr
->nr_raw_registers
);
1325 fprintf_unfiltered (file
, "nr_cooked_registers %d\n",
1326 regcache
->descr
->nr_cooked_registers
);
1327 fprintf_unfiltered (file
, "sizeof_raw_registers %ld\n",
1328 regcache
->descr
->sizeof_raw_registers
);
1329 fprintf_unfiltered (file
, "sizeof_raw_register_status %ld\n",
1330 regcache
->descr
->sizeof_raw_register_status
);
1331 fprintf_unfiltered (file
, "gdbarch_num_regs %d\n",
1332 gdbarch_num_regs (gdbarch
));
1333 fprintf_unfiltered (file
, "gdbarch_num_pseudo_regs %d\n",
1334 gdbarch_num_pseudo_regs (gdbarch
));
1337 gdb_assert (regcache
->descr
->nr_cooked_registers
1338 == (gdbarch_num_regs (gdbarch
)
1339 + gdbarch_num_pseudo_regs (gdbarch
)));
1341 for (regnum
= -1; regnum
< regcache
->descr
->nr_cooked_registers
; regnum
++)
1345 fprintf_unfiltered (file
, " %-10s", "Name");
1348 const char *p
= gdbarch_register_name (gdbarch
, regnum
);
1352 else if (p
[0] == '\0')
1354 fprintf_unfiltered (file
, " %-10s", p
);
1359 fprintf_unfiltered (file
, " %4s", "Nr");
1361 fprintf_unfiltered (file
, " %4d", regnum
);
1363 /* Relative number. */
1365 fprintf_unfiltered (file
, " %4s", "Rel");
1366 else if (regnum
< gdbarch_num_regs (gdbarch
))
1367 fprintf_unfiltered (file
, " %4d", regnum
);
1369 fprintf_unfiltered (file
, " %4d",
1370 (regnum
- gdbarch_num_regs (gdbarch
)));
1374 fprintf_unfiltered (file
, " %6s ", "Offset");
1377 fprintf_unfiltered (file
, " %6ld",
1378 regcache
->descr
->register_offset
[regnum
]);
1379 if (register_offset
!= regcache
->descr
->register_offset
[regnum
]
1381 && (regcache
->descr
->register_offset
[regnum
]
1382 != (regcache
->descr
->register_offset
[regnum
- 1]
1383 + regcache
->descr
->sizeof_register
[regnum
- 1])))
1386 if (!footnote_register_offset
)
1387 footnote_register_offset
= ++footnote_nr
;
1388 fprintf_unfiltered (file
, "*%d", footnote_register_offset
);
1391 fprintf_unfiltered (file
, " ");
1392 register_offset
= (regcache
->descr
->register_offset
[regnum
]
1393 + regcache
->descr
->sizeof_register
[regnum
]);
1398 fprintf_unfiltered (file
, " %5s ", "Size");
1400 fprintf_unfiltered (file
, " %5ld",
1401 regcache
->descr
->sizeof_register
[regnum
]);
1411 static const char blt
[] = "builtin_type";
1413 t
= TYPE_NAME (register_type (regcache
->descr
->gdbarch
, regnum
));
1418 if (!footnote_register_type_name_null
)
1419 footnote_register_type_name_null
= ++footnote_nr
;
1420 n
= xstrprintf ("*%d", footnote_register_type_name_null
);
1421 make_cleanup (xfree
, n
);
1424 /* Chop a leading builtin_type. */
1425 if (startswith (t
, blt
))
1428 fprintf_unfiltered (file
, " %-15s", t
);
1431 /* Leading space always present. */
1432 fprintf_unfiltered (file
, " ");
1435 if (what_to_dump
== regcache_dump_raw
)
1438 fprintf_unfiltered (file
, "Raw value");
1439 else if (regnum
>= regcache
->descr
->nr_raw_registers
)
1440 fprintf_unfiltered (file
, "<cooked>");
1441 else if (regcache_register_status (regcache
, regnum
) == REG_UNKNOWN
)
1442 fprintf_unfiltered (file
, "<invalid>");
1443 else if (regcache_register_status (regcache
, regnum
) == REG_UNAVAILABLE
)
1444 fprintf_unfiltered (file
, "<unavailable>");
1447 regcache_raw_read (regcache
, regnum
, buf
);
1448 print_hex_chars (file
, buf
,
1449 regcache
->descr
->sizeof_register
[regnum
],
1450 gdbarch_byte_order (gdbarch
));
1454 /* Value, cooked. */
1455 if (what_to_dump
== regcache_dump_cooked
)
1458 fprintf_unfiltered (file
, "Cooked value");
1461 enum register_status status
;
1463 status
= regcache_cooked_read (regcache
, regnum
, buf
);
1464 if (status
== REG_UNKNOWN
)
1465 fprintf_unfiltered (file
, "<invalid>");
1466 else if (status
== REG_UNAVAILABLE
)
1467 fprintf_unfiltered (file
, "<unavailable>");
1469 print_hex_chars (file
, buf
,
1470 regcache
->descr
->sizeof_register
[regnum
],
1471 gdbarch_byte_order (gdbarch
));
1475 /* Group members. */
1476 if (what_to_dump
== regcache_dump_groups
)
1479 fprintf_unfiltered (file
, "Groups");
1482 const char *sep
= "";
1483 struct reggroup
*group
;
1485 for (group
= reggroup_next (gdbarch
, NULL
);
1487 group
= reggroup_next (gdbarch
, group
))
1489 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, group
))
1491 fprintf_unfiltered (file
,
1492 "%s%s", sep
, reggroup_name (group
));
1499 /* Remote packet configuration. */
1500 if (what_to_dump
== regcache_dump_remote
)
1504 fprintf_unfiltered (file
, "Rmt Nr g/G Offset");
1506 else if (regnum
< regcache
->descr
->nr_raw_registers
)
1510 if (remote_register_number_and_offset (get_regcache_arch (regcache
), regnum
,
1512 fprintf_unfiltered (file
, "%7d %11d", pnum
, poffset
);
1516 fprintf_unfiltered (file
, "\n");
1519 if (footnote_register_size
)
1520 fprintf_unfiltered (file
, "*%d: Inconsistent register sizes.\n",
1521 footnote_register_size
);
1522 if (footnote_register_offset
)
1523 fprintf_unfiltered (file
, "*%d: Inconsistent register offsets.\n",
1524 footnote_register_offset
);
1525 if (footnote_register_type_name_null
)
1526 fprintf_unfiltered (file
,
1527 "*%d: Register type's name NULL.\n",
1528 footnote_register_type_name_null
);
1529 do_cleanups (cleanups
);
1533 regcache_print (char *args
, enum regcache_dump_what what_to_dump
)
1536 regcache_dump (get_current_regcache (), gdb_stdout
, what_to_dump
);
1541 if (!file
.open (args
, "w"))
1542 perror_with_name (_("maintenance print architecture"));
1543 regcache_dump (get_current_regcache (), &file
, what_to_dump
);
1548 maintenance_print_registers (char *args
, int from_tty
)
1550 regcache_print (args
, regcache_dump_none
);
1554 maintenance_print_raw_registers (char *args
, int from_tty
)
1556 regcache_print (args
, regcache_dump_raw
);
1560 maintenance_print_cooked_registers (char *args
, int from_tty
)
1562 regcache_print (args
, regcache_dump_cooked
);
1566 maintenance_print_register_groups (char *args
, int from_tty
)
1568 regcache_print (args
, regcache_dump_groups
);
1572 maintenance_print_remote_registers (char *args
, int from_tty
)
1574 regcache_print (args
, regcache_dump_remote
);
1577 extern initialize_file_ftype _initialize_regcache
; /* -Wmissing-prototype */
1580 _initialize_regcache (void)
1582 regcache_descr_handle
1583 = gdbarch_data_register_post_init (init_regcache_descr
);
1585 observer_attach_target_changed (regcache_observer_target_changed
);
1586 observer_attach_thread_ptid_changed (regcache_thread_ptid_changed
);
1588 add_com ("flushregs", class_maintenance
, reg_flush_command
,
1589 _("Force gdb to flush its register cache (maintainer command)"));
1591 add_cmd ("registers", class_maintenance
, maintenance_print_registers
,
1592 _("Print the internal register configuration.\n"
1593 "Takes an optional file parameter."), &maintenanceprintlist
);
1594 add_cmd ("raw-registers", class_maintenance
,
1595 maintenance_print_raw_registers
,
1596 _("Print the internal register configuration "
1597 "including raw values.\n"
1598 "Takes an optional file parameter."), &maintenanceprintlist
);
1599 add_cmd ("cooked-registers", class_maintenance
,
1600 maintenance_print_cooked_registers
,
1601 _("Print the internal register configuration "
1602 "including cooked values.\n"
1603 "Takes an optional file parameter."), &maintenanceprintlist
);
1604 add_cmd ("register-groups", class_maintenance
,
1605 maintenance_print_register_groups
,
1606 _("Print the internal register configuration "
1607 "including each register's group.\n"
1608 "Takes an optional file parameter."),
1609 &maintenanceprintlist
);
1610 add_cmd ("remote-registers", class_maintenance
,
1611 maintenance_print_remote_registers
, _("\
1612 Print the internal register configuration including each register's\n\
1613 remote register number and buffer offset in the g/G packets.\n\
1614 Takes an optional file parameter."),
1615 &maintenanceprintlist
);