1 /* Cache and manage the values of registers for GDB, the GNU debugger.
3 Copyright 1986, 1987, 1989, 1991, 1994, 1995, 1996, 1998, 2000,
4 2001, 2002 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
29 #include "reggroups.h"
30 #include "gdb_assert.h"
31 #include "gdb_string.h"
32 #include "gdbcmd.h" /* For maintenanceprintlist. */
37 * Here is the actual register cache.
40 /* Per-architecture object describing the layout of a register cache.
41 Computed once when the architecture is created */
43 struct gdbarch_data
*regcache_descr_handle
;
47 /* The architecture this descriptor belongs to. */
48 struct gdbarch
*gdbarch
;
50 /* Is this a ``legacy'' register cache? Such caches reserve space
51 for raw and pseudo registers and allow access to both. */
54 /* The raw register cache. This should contain just [0
55 .. NUM_RAW_REGISTERS). However, for older targets, it contains
56 space for the full [0 .. NUM_RAW_REGISTERS +
57 NUM_PSEUDO_REGISTERS). */
59 long sizeof_raw_registers
;
60 long sizeof_raw_register_valid_p
;
62 /* The cooked register space. Each cooked register in the range
63 [0..NR_RAW_REGISTERS) is direct-mapped onto the corresponding raw
64 register. The remaining [NR_RAW_REGISTERS
65 .. NR_COOKED_REGISTERS) (a.k.a. pseudo regiters) are mapped onto
66 both raw registers and memory by the architecture methods
67 gdbarch_register_read and gdbarch_register_write. */
68 int nr_cooked_registers
;
69 long sizeof_cooked_registers
;
70 long sizeof_cooked_register_valid_p
;
72 /* Offset and size (in 8 bit bytes), of reach register in the
73 register cache. All registers (including those in the range
74 [NR_RAW_REGISTERS .. NR_COOKED_REGISTERS) are given an offset.
75 Assigning all registers an offset makes it possible to keep
76 legacy code, such as that found in read_register_bytes() and
77 write_register_bytes() working. */
78 long *register_offset
;
79 long *sizeof_register
;
81 /* Useful constant. Largest of all the registers. */
82 long max_register_size
;
84 /* Cached table containing the type of each register. */
85 struct type
**register_type
;
89 init_legacy_regcache_descr (struct gdbarch
*gdbarch
,
90 struct regcache_descr
*descr
)
93 /* FIXME: cagney/2002-05-11: gdbarch_data() should take that
94 ``gdbarch'' as a parameter. */
95 gdb_assert (gdbarch
!= NULL
);
97 /* FIXME: cagney/2002-05-11: Shouldn't be including pseudo-registers
98 in the register cache. Unfortunatly some architectures still
99 rely on this and the pseudo_register_write() method. */
100 descr
->nr_raw_registers
= descr
->nr_cooked_registers
;
101 descr
->sizeof_raw_register_valid_p
= descr
->sizeof_cooked_register_valid_p
;
103 /* Compute the offset of each register. Legacy architectures define
104 REGISTER_BYTE() so use that. */
105 /* FIXME: cagney/2002-11-07: Instead of using REGISTER_BYTE() this
106 code should, as is done in init_regcache_descr(), compute the
107 offets at runtime. This currently isn't possible as some ISAs
108 define overlapping register regions - see the mess in
109 read_register_bytes() and write_register_bytes() registers. */
110 descr
->sizeof_register
= XCALLOC (descr
->nr_cooked_registers
, long);
111 descr
->register_offset
= XCALLOC (descr
->nr_cooked_registers
, long);
112 descr
->max_register_size
= 0;
113 for (i
= 0; i
< descr
->nr_cooked_registers
; i
++)
115 /* FIXME: cagney/2001-12-04: This code shouldn't need to use
116 REGISTER_BYTE(). Unfortunatly, legacy code likes to lay the
117 buffer out so that certain registers just happen to overlap.
118 Ulgh! New targets use gdbarch's register read/write and
119 entirely avoid this uglyness. */
120 descr
->register_offset
[i
] = REGISTER_BYTE (i
);
121 descr
->sizeof_register
[i
] = REGISTER_RAW_SIZE (i
);
122 if (descr
->max_register_size
< REGISTER_RAW_SIZE (i
))
123 descr
->max_register_size
= REGISTER_RAW_SIZE (i
);
124 if (descr
->max_register_size
< REGISTER_VIRTUAL_SIZE (i
))
125 descr
->max_register_size
= REGISTER_VIRTUAL_SIZE (i
);
128 /* Compute the real size of the register buffer. Start out by
129 trusting REGISTER_BYTES, but then adjust it upwards should that
130 be found to not be sufficient. */
131 /* FIXME: cagney/2002-11-05: Instead of using REGISTER_BYTES, this
132 code should, as is done in init_regcache_descr(), compute the
133 total number of register bytes using the accumulated offsets. */
134 descr
->sizeof_cooked_registers
= REGISTER_BYTES
; /* OK use. */
135 for (i
= 0; i
< descr
->nr_cooked_registers
; i
++)
138 /* Keep extending the buffer so that there is always enough
139 space for all registers. The comparison is necessary since
140 legacy code is free to put registers in random places in the
141 buffer separated by holes. Once REGISTER_BYTE() is killed
142 this can be greatly simplified. */
143 regend
= descr
->register_offset
[i
] + descr
->sizeof_register
[i
];
144 if (descr
->sizeof_cooked_registers
< regend
)
145 descr
->sizeof_cooked_registers
= regend
;
147 /* FIXME: cagney/2002-05-11: Shouldn't be including pseudo-registers
148 in the register cache. Unfortunatly some architectures still
149 rely on this and the pseudo_register_write() method. */
150 descr
->sizeof_raw_registers
= descr
->sizeof_cooked_registers
;
154 init_regcache_descr (struct gdbarch
*gdbarch
)
157 struct regcache_descr
*descr
;
158 gdb_assert (gdbarch
!= NULL
);
160 /* Create an initial, zero filled, table. */
161 descr
= XCALLOC (1, struct regcache_descr
);
162 descr
->gdbarch
= gdbarch
;
164 /* Total size of the register space. The raw registers are mapped
165 directly onto the raw register cache while the pseudo's are
166 either mapped onto raw-registers or memory. */
167 descr
->nr_cooked_registers
= NUM_REGS
+ NUM_PSEUDO_REGS
;
168 descr
->sizeof_cooked_register_valid_p
= NUM_REGS
+ NUM_PSEUDO_REGS
;
170 /* Fill in a table of register types. */
171 descr
->register_type
= XCALLOC (descr
->nr_cooked_registers
,
173 for (i
= 0; i
< descr
->nr_cooked_registers
; i
++)
175 descr
->register_type
[i
] = REGISTER_VIRTUAL_TYPE (i
);
178 /* If an old style architecture, fill in the remainder of the
179 register cache descriptor using the register macros. */
180 if (!gdbarch_pseudo_register_read_p (gdbarch
)
181 && !gdbarch_pseudo_register_write_p (gdbarch
))
184 init_legacy_regcache_descr (gdbarch
, descr
);
188 /* Construct a strictly RAW register cache. Don't allow pseudo's
189 into the register cache. */
190 descr
->nr_raw_registers
= NUM_REGS
;
192 /* FIXME: cagney/2002-08-13: Overallocate the register_valid_p
193 array. This pretects GDB from erant code that accesses elements
194 of the global register_valid_p[] array in the range [NUM_REGS
195 .. NUM_REGS + NUM_PSEUDO_REGS). */
196 descr
->sizeof_raw_register_valid_p
= descr
->sizeof_cooked_register_valid_p
;
198 /* Lay out the register cache.
200 NOTE: cagney/2002-05-22: Only register_type() is used when
201 constructing the register cache. It is assumed that the
202 register's raw size, virtual size and type length are all the
207 descr
->sizeof_register
= XCALLOC (descr
->nr_cooked_registers
, long);
208 descr
->register_offset
= XCALLOC (descr
->nr_cooked_registers
, long);
209 descr
->max_register_size
= 0;
210 for (i
= 0; i
< descr
->nr_cooked_registers
; i
++)
212 descr
->sizeof_register
[i
] = TYPE_LENGTH (descr
->register_type
[i
]);
213 descr
->register_offset
[i
] = offset
;
214 offset
+= descr
->sizeof_register
[i
];
215 if (descr
->max_register_size
< descr
->sizeof_register
[i
])
216 descr
->max_register_size
= descr
->sizeof_register
[i
];
218 /* Set the real size of the register cache buffer. */
219 descr
->sizeof_cooked_registers
= offset
;
222 /* FIXME: cagney/2002-05-22: Should only need to allocate space for
223 the raw registers. Unfortunatly some code still accesses the
224 register array directly using the global registers[]. Until that
225 code has been purged, play safe and over allocating the register
227 descr
->sizeof_raw_registers
= descr
->sizeof_cooked_registers
;
230 /* Sanity check. Confirm that the assumptions about gdbarch are
231 true. The REGCACHE_DESCR_HANDLE is set before doing the checks
232 so that targets using the generic methods supplied by regcache
233 don't go into infinite recursion trying to, again, create the
235 set_gdbarch_data (gdbarch
, regcache_descr_handle
, descr
);
236 for (i
= 0; i
< descr
->nr_cooked_registers
; i
++)
238 gdb_assert (descr
->sizeof_register
[i
] == REGISTER_RAW_SIZE (i
));
239 gdb_assert (descr
->sizeof_register
[i
] == REGISTER_VIRTUAL_SIZE (i
));
240 gdb_assert (descr
->register_offset
[i
] == REGISTER_BYTE (i
));
242 /* gdb_assert (descr->sizeof_raw_registers == REGISTER_BYTES (i)); */
248 static struct regcache_descr
*
249 regcache_descr (struct gdbarch
*gdbarch
)
251 return gdbarch_data (gdbarch
, regcache_descr_handle
);
255 xfree_regcache_descr (struct gdbarch
*gdbarch
, void *ptr
)
257 struct regcache_descr
*descr
= ptr
;
260 xfree (descr
->register_offset
);
261 xfree (descr
->sizeof_register
);
262 descr
->register_offset
= NULL
;
263 descr
->sizeof_register
= NULL
;
267 /* Utility functions returning useful register attributes stored in
268 the regcache descr. */
271 register_type (struct gdbarch
*gdbarch
, int regnum
)
273 struct regcache_descr
*descr
= regcache_descr (gdbarch
);
274 gdb_assert (regnum
>= 0 && regnum
< descr
->nr_cooked_registers
);
275 return descr
->register_type
[regnum
];
278 /* Utility functions returning useful register attributes stored in
279 the regcache descr. */
282 max_register_size (struct gdbarch
*gdbarch
)
284 struct regcache_descr
*descr
= regcache_descr (gdbarch
);
285 return descr
->max_register_size
;
289 register_size (struct gdbarch
*gdbarch
, int regnum
)
291 struct regcache_descr
*descr
= regcache_descr (gdbarch
);
293 gdb_assert (regnum
>= 0 && regnum
< (NUM_REGS
+ NUM_PSEUDO_REGS
));
294 size
= descr
->sizeof_register
[regnum
];
295 gdb_assert (size
== REGISTER_RAW_SIZE (regnum
)); /* OK */
296 gdb_assert (size
== REGISTER_RAW_SIZE (regnum
)); /* OK */
300 /* The register cache for storing raw register values. */
304 struct regcache_descr
*descr
;
305 /* The register buffers. A read-only register cache can hold the
306 full [0 .. NUM_REGS + NUM_PSEUDO_REGS) while a read/write
307 register cache can only hold [0 .. NUM_REGS). */
309 char *register_valid_p
;
310 /* Is this a read-only cache? A read-only cache is used for saving
311 the target's register state (e.g, across an inferior function
312 call or just before forcing a function return). A read-only
313 cache can only be updated via the methods regcache_dup() and
314 regcache_cpy(). The actual contents are determined by the
315 reggroup_save and reggroup_restore methods. */
320 regcache_xmalloc (struct gdbarch
*gdbarch
)
322 struct regcache_descr
*descr
;
323 struct regcache
*regcache
;
324 gdb_assert (gdbarch
!= NULL
);
325 descr
= regcache_descr (gdbarch
);
326 regcache
= XMALLOC (struct regcache
);
327 regcache
->descr
= descr
;
329 = XCALLOC (descr
->sizeof_raw_registers
, char);
330 regcache
->register_valid_p
331 = XCALLOC (descr
->sizeof_raw_register_valid_p
, char);
332 regcache
->readonly_p
= 1;
337 regcache_xfree (struct regcache
*regcache
)
339 if (regcache
== NULL
)
341 xfree (regcache
->registers
);
342 xfree (regcache
->register_valid_p
);
347 do_regcache_xfree (void *data
)
349 regcache_xfree (data
);
353 make_cleanup_regcache_xfree (struct regcache
*regcache
)
355 return make_cleanup (do_regcache_xfree
, regcache
);
358 /* Return a pointer to register REGNUM's buffer cache. */
361 register_buffer (struct regcache
*regcache
, int regnum
)
363 return regcache
->registers
+ regcache
->descr
->register_offset
[regnum
];
367 regcache_save (struct regcache
*dst
, struct regcache
*src
)
369 struct gdbarch
*gdbarch
= dst
->descr
->gdbarch
;
371 /* The SRC and DST register caches had better belong to the same
373 gdb_assert (src
->descr
->gdbarch
== dst
->descr
->gdbarch
);
374 /* The DST should be `read-only', if it wasn't then the save would
375 end up trying to write the register values out through to the
377 gdb_assert (!src
->readonly_p
);
378 gdb_assert (dst
->readonly_p
);
379 /* Clear the dest. */
380 memset (dst
->registers
, 0, dst
->descr
->sizeof_cooked_registers
);
381 memset (dst
->register_valid_p
, 0, dst
->descr
->sizeof_cooked_register_valid_p
);
382 /* Copy over any registers (identified by their membership in the
383 save_reggroup) and mark them as valid. The full [0
384 .. NUM_REGS+NUM_PSEUDO_REGS) range is checked since some
385 architectures need to save/restore `cooked' registers that live
387 for (regnum
= 0; regnum
< dst
->descr
->nr_cooked_registers
; regnum
++)
389 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, save_reggroup
))
391 regcache_cooked_read (src
, regnum
, register_buffer (dst
, regnum
));
392 dst
->register_valid_p
[regnum
] = 1;
398 regcache_restore (struct regcache
*dst
, struct regcache
*src
)
400 struct gdbarch
*gdbarch
= dst
->descr
->gdbarch
;
402 gdb_assert (src
->descr
->gdbarch
== dst
->descr
->gdbarch
);
403 gdb_assert (!dst
->readonly_p
);
404 gdb_assert (src
->readonly_p
);
405 /* Copy over any registers, being careful to only restore those that
406 were both saved and need to be restored. The full [0
407 .. NUM_REGS+NUM_PSEUDO_REGS) range is checked since some
408 architectures need to save/restore `cooked' registers that live
410 for (regnum
= 0; regnum
< src
->descr
->nr_cooked_registers
; regnum
++)
412 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, restore_reggroup
)
413 && src
->register_valid_p
[regnum
])
415 regcache_cooked_write (dst
, regnum
, register_buffer (src
, regnum
));
421 regcache_cpy (struct regcache
*dst
, struct regcache
*src
)
425 gdb_assert (src
!= NULL
&& dst
!= NULL
);
426 gdb_assert (src
->descr
->gdbarch
== dst
->descr
->gdbarch
);
427 gdb_assert (src
!= dst
);
428 gdb_assert (src
->readonly_p
|| dst
->readonly_p
);
429 if (!src
->readonly_p
)
430 regcache_save (dst
, src
);
431 else if (!dst
->readonly_p
)
432 regcache_restore (dst
, src
);
434 regcache_cpy_no_passthrough (dst
, src
);
438 regcache_cpy_no_passthrough (struct regcache
*dst
, struct regcache
*src
)
441 gdb_assert (src
!= NULL
&& dst
!= NULL
);
442 gdb_assert (src
->descr
->gdbarch
== dst
->descr
->gdbarch
);
443 /* NOTE: cagney/2002-05-17: Don't let the caller do a no-passthrough
444 move of data into the current_regcache(). Doing this would be
445 silly - it would mean that valid_p would be completly invalid. */
446 gdb_assert (dst
!= current_regcache
);
447 memcpy (dst
->registers
, src
->registers
, dst
->descr
->sizeof_raw_registers
);
448 memcpy (dst
->register_valid_p
, src
->register_valid_p
,
449 dst
->descr
->sizeof_raw_register_valid_p
);
453 regcache_dup (struct regcache
*src
)
455 struct regcache
*newbuf
;
456 gdb_assert (current_regcache
!= NULL
);
457 newbuf
= regcache_xmalloc (src
->descr
->gdbarch
);
458 regcache_cpy (newbuf
, src
);
463 regcache_dup_no_passthrough (struct regcache
*src
)
465 struct regcache
*newbuf
;
466 gdb_assert (current_regcache
!= NULL
);
467 newbuf
= regcache_xmalloc (src
->descr
->gdbarch
);
468 regcache_cpy_no_passthrough (newbuf
, src
);
473 regcache_valid_p (struct regcache
*regcache
, int regnum
)
475 gdb_assert (regcache
!= NULL
);
476 gdb_assert (regnum
>= 0 && regnum
< regcache
->descr
->nr_raw_registers
);
477 return regcache
->register_valid_p
[regnum
];
481 deprecated_grub_regcache_for_registers (struct regcache
*regcache
)
483 return regcache
->registers
;
487 deprecated_grub_regcache_for_register_valid (struct regcache
*regcache
)
489 return regcache
->register_valid_p
;
492 /* Global structure containing the current regcache. */
493 /* FIXME: cagney/2002-05-11: The two global arrays registers[] and
494 deprecated_register_valid[] currently point into this structure. */
495 struct regcache
*current_regcache
;
497 /* NOTE: this is a write-through cache. There is no "dirty" bit for
498 recording if the register values have been changed (eg. by the
499 user). Therefore all registers must be written back to the
500 target when appropriate. */
502 /* REGISTERS contains the cached register values (in target byte order). */
504 char *deprecated_registers
;
506 /* DEPRECATED_REGISTER_VALID is 0 if the register needs to be fetched,
507 1 if it has been fetched, and
508 -1 if the register value was not available.
510 "Not available" indicates that the target is not not able to supply
511 the register at this state. The register may become available at a
512 later time (after the next resume). This often occures when GDB is
513 manipulating a target that contains only a snapshot of the entire
514 system being debugged - some of the registers in such a system may
515 not have been saved. */
517 signed char *deprecated_register_valid
;
519 /* The thread/process associated with the current set of registers. */
521 static ptid_t registers_ptid
;
529 Returns 0 if the value is not in the cache (needs fetch).
530 >0 if the value is in the cache.
531 <0 if the value is permanently unavailable (don't ask again). */
534 register_cached (int regnum
)
536 return deprecated_register_valid
[regnum
];
539 /* Record that REGNUM's value is cached if STATE is >0, uncached but
540 fetchable if STATE is 0, and uncached and unfetchable if STATE is <0. */
543 set_register_cached (int regnum
, int state
)
545 gdb_assert (regnum
>= 0);
546 gdb_assert (regnum
< current_regcache
->descr
->nr_raw_registers
);
547 current_regcache
->register_valid_p
[regnum
] = state
;
550 /* Return whether register REGNUM is a real register. */
553 real_register (int regnum
)
555 return regnum
>= 0 && regnum
< NUM_REGS
;
558 /* Low level examining and depositing of registers.
560 The caller is responsible for making sure that the inferior is
561 stopped before calling the fetching routines, or it will get
562 garbage. (a change from GDB version 3, in which the caller got the
563 value from the last stop). */
565 /* REGISTERS_CHANGED ()
567 Indicate that registers may have changed, so invalidate the cache. */
570 registers_changed (void)
574 registers_ptid
= pid_to_ptid (-1);
576 /* Force cleanup of any alloca areas if using C alloca instead of
577 a builtin alloca. This particular call is used to clean up
578 areas allocated by low level target code which may build up
579 during lengthy interactions between gdb and the target before
580 gdb gives control to the user (ie watchpoints). */
583 for (i
= 0; i
< current_regcache
->descr
->nr_raw_registers
; i
++)
584 set_register_cached (i
, 0);
586 if (registers_changed_hook
)
587 registers_changed_hook ();
590 /* DEPRECATED_REGISTERS_FETCHED ()
592 Indicate that all registers have been fetched, so mark them all valid. */
594 /* NOTE: cagney/2001-12-04: This function does not set valid on the
595 pseudo-register range since pseudo registers are always supplied
596 using supply_register(). */
597 /* FIXME: cagney/2001-12-04: This function is DEPRECATED. The target
598 code was blatting the registers[] array and then calling this.
599 Since targets should only be using supply_register() the need for
600 this function/hack is eliminated. */
603 deprecated_registers_fetched (void)
607 for (i
= 0; i
< NUM_REGS
; i
++)
608 set_register_cached (i
, 1);
609 /* Do not assume that the pseudo-regs have also been fetched.
610 Fetching all real regs NEVER accounts for pseudo-regs. */
613 /* deprecated_read_register_bytes and deprecated_write_register_bytes
614 are generally a *BAD* idea. They are inefficient because they need
615 to check for partial updates, which can only be done by scanning
616 through all of the registers and seeing if the bytes that are being
617 read/written fall inside of an invalid register. [The main reason
618 this is necessary is that register sizes can vary, so a simple
619 index won't suffice.] It is far better to call read_register_gen
620 and write_register_gen if you want to get at the raw register
621 contents, as it only takes a regnum as an argument, and therefore
622 can't do a partial register update.
624 Prior to the recent fixes to check for partial updates, both read
625 and deprecated_write_register_bytes always checked to see if any
626 registers were stale, and then called target_fetch_registers (-1)
627 to update the whole set. This caused really slowed things down for
630 /* Copy INLEN bytes of consecutive data from registers
631 starting with the INREGBYTE'th byte of register data
632 into memory at MYADDR. */
635 deprecated_read_register_bytes (int in_start
, char *in_buf
, int in_len
)
637 int in_end
= in_start
+ in_len
;
639 char *reg_buf
= alloca (MAX_REGISTER_RAW_SIZE
);
641 /* See if we are trying to read bytes from out-of-date registers. If so,
642 update just those registers. */
644 for (regnum
= 0; regnum
< NUM_REGS
+ NUM_PSEUDO_REGS
; regnum
++)
653 reg_start
= REGISTER_BYTE (regnum
);
654 reg_len
= REGISTER_RAW_SIZE (regnum
);
655 reg_end
= reg_start
+ reg_len
;
657 if (reg_end
<= in_start
|| in_end
<= reg_start
)
658 /* The range the user wants to read doesn't overlap with regnum. */
661 if (REGISTER_NAME (regnum
) != NULL
&& *REGISTER_NAME (regnum
) != '\0')
662 /* Force the cache to fetch the entire register. */
663 deprecated_read_register_gen (regnum
, reg_buf
);
665 /* Legacy note: even though this register is ``invalid'' we
666 still need to return something. It would appear that some
667 code relies on apparent gaps in the register array also
669 /* FIXME: cagney/2001-08-18: This is just silly. It defeats
670 the entire register read/write flow of control. Must
671 resist temptation to return 0xdeadbeef. */
672 memcpy (reg_buf
, &deprecated_registers
[reg_start
], reg_len
);
674 /* Legacy note: This function, for some reason, allows a NULL
675 input buffer. If the buffer is NULL, the registers are still
676 fetched, just the final transfer is skipped. */
680 /* start = max (reg_start, in_start) */
681 if (reg_start
> in_start
)
686 /* end = min (reg_end, in_end) */
687 if (reg_end
< in_end
)
692 /* Transfer just the bytes common to both IN_BUF and REG_BUF */
693 for (byte
= start
; byte
< end
; byte
++)
695 in_buf
[byte
- in_start
] = reg_buf
[byte
- reg_start
];
700 /* Read register REGNUM into memory at MYADDR, which must be large
701 enough for REGISTER_RAW_BYTES (REGNUM). Target byte-order. If the
702 register is known to be the size of a CORE_ADDR or smaller,
703 read_register can be used instead. */
706 legacy_read_register_gen (int regnum
, char *myaddr
)
708 gdb_assert (regnum
>= 0 && regnum
< (NUM_REGS
+ NUM_PSEUDO_REGS
));
709 if (! ptid_equal (registers_ptid
, inferior_ptid
))
711 registers_changed ();
712 registers_ptid
= inferior_ptid
;
715 if (!register_cached (regnum
))
716 target_fetch_registers (regnum
);
718 memcpy (myaddr
, register_buffer (current_regcache
, regnum
),
719 REGISTER_RAW_SIZE (regnum
));
723 regcache_raw_read (struct regcache
*regcache
, int regnum
, void *buf
)
725 gdb_assert (regcache
!= NULL
&& buf
!= NULL
);
726 gdb_assert (regnum
>= 0 && regnum
< regcache
->descr
->nr_raw_registers
);
727 if (regcache
->descr
->legacy_p
728 && !regcache
->readonly_p
)
730 gdb_assert (regcache
== current_regcache
);
731 /* For moment, just use underlying legacy code. Ulgh!!! This
732 silently and very indirectly updates the regcache's regcache
733 via the global deprecated_register_valid[]. */
734 legacy_read_register_gen (regnum
, buf
);
737 /* Make certain that the register cache is up-to-date with respect
738 to the current thread. This switching shouldn't be necessary
739 only there is still only one target side register cache. Sigh!
740 On the bright side, at least there is a regcache object. */
741 if (!regcache
->readonly_p
)
743 gdb_assert (regcache
== current_regcache
);
744 if (! ptid_equal (registers_ptid
, inferior_ptid
))
746 registers_changed ();
747 registers_ptid
= inferior_ptid
;
749 if (!register_cached (regnum
))
750 target_fetch_registers (regnum
);
752 /* Copy the value directly into the register cache. */
753 memcpy (buf
, register_buffer (regcache
, regnum
),
754 regcache
->descr
->sizeof_register
[regnum
]);
758 regcache_raw_read_signed (struct regcache
*regcache
, int regnum
, LONGEST
*val
)
761 gdb_assert (regcache
!= NULL
);
762 gdb_assert (regnum
>= 0 && regnum
< regcache
->descr
->nr_raw_registers
);
763 buf
= alloca (regcache
->descr
->sizeof_register
[regnum
]);
764 regcache_raw_read (regcache
, regnum
, buf
);
765 (*val
) = extract_signed_integer (buf
,
766 regcache
->descr
->sizeof_register
[regnum
]);
770 regcache_raw_read_unsigned (struct regcache
*regcache
, int regnum
,
774 gdb_assert (regcache
!= NULL
);
775 gdb_assert (regnum
>= 0 && regnum
< regcache
->descr
->nr_raw_registers
);
776 buf
= alloca (regcache
->descr
->sizeof_register
[regnum
]);
777 regcache_raw_read (regcache
, regnum
, buf
);
778 (*val
) = extract_unsigned_integer (buf
,
779 regcache
->descr
->sizeof_register
[regnum
]);
783 regcache_raw_write_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 store_signed_integer (buf
, regcache
->descr
->sizeof_register
[regnum
], val
);
790 regcache_raw_write (regcache
, regnum
, buf
);
794 regcache_raw_write_unsigned (struct regcache
*regcache
, int regnum
,
798 gdb_assert (regcache
!= NULL
);
799 gdb_assert (regnum
>=0 && regnum
< regcache
->descr
->nr_raw_registers
);
800 buf
= alloca (regcache
->descr
->sizeof_register
[regnum
]);
801 store_unsigned_integer (buf
, regcache
->descr
->sizeof_register
[regnum
], val
);
802 regcache_raw_write (regcache
, regnum
, buf
);
806 deprecated_read_register_gen (int regnum
, char *buf
)
808 gdb_assert (current_regcache
!= NULL
);
809 gdb_assert (current_regcache
->descr
->gdbarch
== current_gdbarch
);
810 if (current_regcache
->descr
->legacy_p
)
812 legacy_read_register_gen (regnum
, buf
);
815 regcache_cooked_read (current_regcache
, regnum
, buf
);
819 regcache_cooked_read (struct regcache
*regcache
, int regnum
, void *buf
)
821 gdb_assert (regnum
>= 0);
822 gdb_assert (regnum
< regcache
->descr
->nr_cooked_registers
);
823 if (regnum
< regcache
->descr
->nr_raw_registers
)
824 regcache_raw_read (regcache
, regnum
, buf
);
825 else if (regcache
->readonly_p
826 && regnum
< regcache
->descr
->nr_cooked_registers
827 && regcache
->register_valid_p
[regnum
])
828 /* Read-only register cache, perhaphs the cooked value was cached? */
829 memcpy (buf
, register_buffer (regcache
, regnum
),
830 regcache
->descr
->sizeof_register
[regnum
]);
832 gdbarch_pseudo_register_read (regcache
->descr
->gdbarch
, regcache
,
837 regcache_cooked_read_signed (struct regcache
*regcache
, int regnum
,
841 gdb_assert (regcache
!= NULL
);
842 gdb_assert (regnum
>= 0 && regnum
< regcache
->descr
->nr_raw_registers
);
843 buf
= alloca (regcache
->descr
->sizeof_register
[regnum
]);
844 regcache_cooked_read (regcache
, regnum
, buf
);
845 (*val
) = extract_signed_integer (buf
,
846 regcache
->descr
->sizeof_register
[regnum
]);
850 regcache_cooked_read_unsigned (struct regcache
*regcache
, int regnum
,
854 gdb_assert (regcache
!= NULL
);
855 gdb_assert (regnum
>= 0 && regnum
< regcache
->descr
->nr_raw_registers
);
856 buf
= alloca (regcache
->descr
->sizeof_register
[regnum
]);
857 regcache_cooked_read (regcache
, regnum
, buf
);
858 (*val
) = extract_unsigned_integer (buf
,
859 regcache
->descr
->sizeof_register
[regnum
]);
862 /* Write register REGNUM at MYADDR to the target. MYADDR points at
863 REGISTER_RAW_BYTES(REGNUM), which must be in target byte-order. */
866 legacy_write_register_gen (int regnum
, const void *myaddr
)
869 gdb_assert (regnum
>= 0 && regnum
< (NUM_REGS
+ NUM_PSEUDO_REGS
));
871 /* On the sparc, writing %g0 is a no-op, so we don't even want to
872 change the registers array if something writes to this register. */
873 if (CANNOT_STORE_REGISTER (regnum
))
876 if (! ptid_equal (registers_ptid
, inferior_ptid
))
878 registers_changed ();
879 registers_ptid
= inferior_ptid
;
882 size
= REGISTER_RAW_SIZE (regnum
);
884 if (real_register (regnum
))
886 /* If we have a valid copy of the register, and new value == old
887 value, then don't bother doing the actual store. */
888 if (register_cached (regnum
)
889 && (memcmp (register_buffer (current_regcache
, regnum
), myaddr
, size
)
893 target_prepare_to_store ();
896 memcpy (register_buffer (current_regcache
, regnum
), myaddr
, size
);
898 set_register_cached (regnum
, 1);
899 target_store_registers (regnum
);
903 regcache_raw_write (struct regcache
*regcache
, int regnum
, const void *buf
)
905 gdb_assert (regcache
!= NULL
&& buf
!= NULL
);
906 gdb_assert (regnum
>= 0 && regnum
< regcache
->descr
->nr_raw_registers
);
907 gdb_assert (!regcache
->readonly_p
);
909 if (regcache
->descr
->legacy_p
)
911 /* For moment, just use underlying legacy code. Ulgh!!! This
912 silently and very indirectly updates the regcache's buffers
913 via the globals deprecated_register_valid[] and registers[]. */
914 gdb_assert (regcache
== current_regcache
);
915 legacy_write_register_gen (regnum
, buf
);
919 /* On the sparc, writing %g0 is a no-op, so we don't even want to
920 change the registers array if something writes to this register. */
921 if (CANNOT_STORE_REGISTER (regnum
))
924 /* Make certain that the correct cache is selected. */
925 gdb_assert (regcache
== current_regcache
);
926 if (! ptid_equal (registers_ptid
, inferior_ptid
))
928 registers_changed ();
929 registers_ptid
= inferior_ptid
;
932 /* If we have a valid copy of the register, and new value == old
933 value, then don't bother doing the actual store. */
934 if (regcache_valid_p (regcache
, regnum
)
935 && (memcmp (register_buffer (regcache
, regnum
), buf
,
936 regcache
->descr
->sizeof_register
[regnum
]) == 0))
939 target_prepare_to_store ();
940 memcpy (register_buffer (regcache
, regnum
), buf
,
941 regcache
->descr
->sizeof_register
[regnum
]);
942 regcache
->register_valid_p
[regnum
] = 1;
943 target_store_registers (regnum
);
947 deprecated_write_register_gen (int regnum
, char *buf
)
949 gdb_assert (current_regcache
!= NULL
);
950 gdb_assert (current_regcache
->descr
->gdbarch
== current_gdbarch
);
951 if (current_regcache
->descr
->legacy_p
)
953 legacy_write_register_gen (regnum
, buf
);
956 regcache_cooked_write (current_regcache
, regnum
, buf
);
960 regcache_cooked_write (struct regcache
*regcache
, int regnum
, const void *buf
)
962 gdb_assert (regnum
>= 0);
963 gdb_assert (regnum
< regcache
->descr
->nr_cooked_registers
);
964 if (regnum
< regcache
->descr
->nr_raw_registers
)
965 regcache_raw_write (regcache
, regnum
, buf
);
967 gdbarch_pseudo_register_write (regcache
->descr
->gdbarch
, regcache
,
971 /* Copy INLEN bytes of consecutive data from memory at MYADDR
972 into registers starting with the MYREGSTART'th byte of register data. */
975 deprecated_write_register_bytes (int myregstart
, char *myaddr
, int inlen
)
977 int myregend
= myregstart
+ inlen
;
980 target_prepare_to_store ();
982 /* Scan through the registers updating any that are covered by the
983 range myregstart<=>myregend using write_register_gen, which does
984 nice things like handling threads, and avoiding updates when the
985 new and old contents are the same. */
987 for (regnum
= 0; regnum
< NUM_REGS
+ NUM_PSEUDO_REGS
; regnum
++)
989 int regstart
, regend
;
991 regstart
= REGISTER_BYTE (regnum
);
992 regend
= regstart
+ REGISTER_RAW_SIZE (regnum
);
994 /* Is this register completely outside the range the user is writing? */
995 if (myregend
<= regstart
|| regend
<= myregstart
)
998 /* Is this register completely within the range the user is writing? */
999 else if (myregstart
<= regstart
&& regend
<= myregend
)
1000 deprecated_write_register_gen (regnum
, myaddr
+ (regstart
- myregstart
));
1002 /* The register partially overlaps the range being written. */
1005 char *regbuf
= (char*) alloca (MAX_REGISTER_RAW_SIZE
);
1006 /* What's the overlap between this register's bytes and
1007 those the caller wants to write? */
1008 int overlapstart
= max (regstart
, myregstart
);
1009 int overlapend
= min (regend
, myregend
);
1011 /* We may be doing a partial update of an invalid register.
1012 Update it from the target before scribbling on it. */
1013 deprecated_read_register_gen (regnum
, regbuf
);
1015 memcpy (&deprecated_registers
[overlapstart
],
1016 myaddr
+ (overlapstart
- myregstart
),
1017 overlapend
- overlapstart
);
1019 target_store_registers (regnum
);
1024 /* Perform a partial register transfer using a read, modify, write
1027 typedef void (regcache_read_ftype
) (struct regcache
*regcache
, int regnum
,
1029 typedef void (regcache_write_ftype
) (struct regcache
*regcache
, int regnum
,
1033 regcache_xfer_part (struct regcache
*regcache
, int regnum
,
1034 int offset
, int len
, void *in
, const void *out
,
1035 regcache_read_ftype
*read
, regcache_write_ftype
*write
)
1037 struct regcache_descr
*descr
= regcache
->descr
;
1038 bfd_byte
*reg
= alloca (descr
->max_register_size
);
1039 gdb_assert (offset
>= 0 && offset
<= descr
->sizeof_register
[regnum
]);
1040 gdb_assert (len
>= 0 && offset
+ len
<= descr
->sizeof_register
[regnum
]);
1041 /* Something to do? */
1042 if (offset
+ len
== 0)
1044 /* Read (when needed) ... */
1047 || offset
+ len
< descr
->sizeof_register
[regnum
])
1049 gdb_assert (read
!= NULL
);
1050 read (regcache
, regnum
, reg
);
1052 /* ... modify ... */
1054 memcpy (in
, reg
+ offset
, len
);
1056 memcpy (reg
+ offset
, out
, len
);
1057 /* ... write (when needed). */
1060 gdb_assert (write
!= NULL
);
1061 write (regcache
, regnum
, reg
);
1066 regcache_raw_read_part (struct regcache
*regcache
, int regnum
,
1067 int offset
, int len
, void *buf
)
1069 struct regcache_descr
*descr
= regcache
->descr
;
1070 gdb_assert (regnum
>= 0 && regnum
< descr
->nr_raw_registers
);
1071 regcache_xfer_part (regcache
, regnum
, offset
, len
, buf
, NULL
,
1072 regcache_raw_read
, regcache_raw_write
);
1076 regcache_raw_write_part (struct regcache
*regcache
, int regnum
,
1077 int offset
, int len
, const void *buf
)
1079 struct regcache_descr
*descr
= regcache
->descr
;
1080 gdb_assert (regnum
>= 0 && regnum
< descr
->nr_raw_registers
);
1081 regcache_xfer_part (regcache
, regnum
, offset
, len
, NULL
, buf
,
1082 regcache_raw_read
, regcache_raw_write
);
1086 regcache_cooked_read_part (struct regcache
*regcache
, int regnum
,
1087 int offset
, int len
, void *buf
)
1089 struct regcache_descr
*descr
= regcache
->descr
;
1090 gdb_assert (regnum
>= 0 && regnum
< descr
->nr_cooked_registers
);
1091 regcache_xfer_part (regcache
, regnum
, offset
, len
, buf
, NULL
,
1092 regcache_cooked_read
, regcache_cooked_write
);
1096 regcache_cooked_write_part (struct regcache
*regcache
, int regnum
,
1097 int offset
, int len
, const void *buf
)
1099 struct regcache_descr
*descr
= regcache
->descr
;
1100 gdb_assert (regnum
>= 0 && regnum
< descr
->nr_cooked_registers
);
1101 regcache_xfer_part (regcache
, regnum
, offset
, len
, NULL
, buf
,
1102 regcache_cooked_read
, regcache_cooked_write
);
1105 /* Hack to keep code that view the register buffer as raw bytes
1109 register_offset_hack (struct gdbarch
*gdbarch
, int regnum
)
1111 struct regcache_descr
*descr
= regcache_descr (gdbarch
);
1112 gdb_assert (regnum
>= 0 && regnum
< descr
->nr_cooked_registers
);
1113 return descr
->register_offset
[regnum
];
1116 /* Return the contents of register REGNUM as an unsigned integer. */
1119 read_register (int regnum
)
1121 char *buf
= alloca (REGISTER_RAW_SIZE (regnum
));
1122 deprecated_read_register_gen (regnum
, buf
);
1123 return (extract_unsigned_integer (buf
, REGISTER_RAW_SIZE (regnum
)));
1127 read_register_pid (int regnum
, ptid_t ptid
)
1133 if (ptid_equal (ptid
, inferior_ptid
))
1134 return read_register (regnum
);
1136 save_ptid
= inferior_ptid
;
1138 inferior_ptid
= ptid
;
1140 retval
= read_register (regnum
);
1142 inferior_ptid
= save_ptid
;
1147 /* Return the contents of register REGNUM as a signed integer. */
1150 read_signed_register (int regnum
)
1152 void *buf
= alloca (REGISTER_RAW_SIZE (regnum
));
1153 deprecated_read_register_gen (regnum
, buf
);
1154 return (extract_signed_integer (buf
, REGISTER_RAW_SIZE (regnum
)));
1158 read_signed_register_pid (int regnum
, ptid_t ptid
)
1163 if (ptid_equal (ptid
, inferior_ptid
))
1164 return read_signed_register (regnum
);
1166 save_ptid
= inferior_ptid
;
1168 inferior_ptid
= ptid
;
1170 retval
= read_signed_register (regnum
);
1172 inferior_ptid
= save_ptid
;
1177 /* Store VALUE into the raw contents of register number REGNUM. */
1180 write_register (int regnum
, LONGEST val
)
1184 size
= REGISTER_RAW_SIZE (regnum
);
1185 buf
= alloca (size
);
1186 store_signed_integer (buf
, size
, (LONGEST
) val
);
1187 deprecated_write_register_gen (regnum
, buf
);
1191 write_register_pid (int regnum
, CORE_ADDR val
, ptid_t ptid
)
1195 if (ptid_equal (ptid
, inferior_ptid
))
1197 write_register (regnum
, val
);
1201 save_ptid
= inferior_ptid
;
1203 inferior_ptid
= ptid
;
1205 write_register (regnum
, val
);
1207 inferior_ptid
= save_ptid
;
1210 /* SUPPLY_REGISTER()
1212 Record that register REGNUM contains VAL. This is used when the
1213 value is obtained from the inferior or core dump, so there is no
1214 need to store the value there.
1216 If VAL is a NULL pointer, then it's probably an unsupported register.
1217 We just set its value to all zeros. We might want to record this
1218 fact, and report it to the users of read_register and friends. */
1221 supply_register (int regnum
, const void *val
)
1224 if (! ptid_equal (registers_ptid
, inferior_ptid
))
1226 registers_changed ();
1227 registers_ptid
= inferior_ptid
;
1231 set_register_cached (regnum
, 1);
1233 memcpy (register_buffer (current_regcache
, regnum
), val
,
1234 REGISTER_RAW_SIZE (regnum
));
1236 memset (register_buffer (current_regcache
, regnum
), '\000',
1237 REGISTER_RAW_SIZE (regnum
));
1239 /* On some architectures, e.g. HPPA, there are a few stray bits in
1240 some registers, that the rest of the code would like to ignore. */
1242 /* NOTE: cagney/2001-03-16: The macro CLEAN_UP_REGISTER_VALUE is
1243 going to be deprecated. Instead architectures will leave the raw
1244 register value as is and instead clean things up as they pass
1245 through the method gdbarch_pseudo_register_read() clean up the
1248 #ifdef DEPRECATED_CLEAN_UP_REGISTER_VALUE
1249 DEPRECATED_CLEAN_UP_REGISTER_VALUE \
1250 (regnum
, register_buffer (current_regcache
, regnum
));
1255 regcache_collect (int regnum
, void *buf
)
1257 memcpy (buf
, register_buffer (current_regcache
, regnum
),
1258 REGISTER_RAW_SIZE (regnum
));
1262 /* read_pc, write_pc, read_sp, write_sp, read_fp, etc. Special
1263 handling for registers PC, SP, and FP. */
1265 /* NOTE: cagney/2001-02-18: The functions generic_target_read_pc(),
1266 read_pc_pid(), read_pc(), generic_target_write_pc(),
1267 write_pc_pid(), write_pc(), generic_target_read_sp(), read_sp(),
1268 generic_target_write_sp(), write_sp(), generic_target_read_fp() and
1269 read_fp(), will eventually be moved out of the reg-cache into
1270 either frame.[hc] or to the multi-arch framework. The are not part
1271 of the raw register cache. */
1273 /* This routine is getting awfully cluttered with #if's. It's probably
1274 time to turn this into READ_PC and define it in the tm.h file.
1277 1999-06-08: The following were re-written so that it assumes the
1278 existence of a TARGET_READ_PC et.al. macro. A default generic
1279 version of that macro is made available where needed.
1281 Since the ``TARGET_READ_PC'' et.al. macro is going to be controlled
1282 by the multi-arch framework, it will eventually be possible to
1283 eliminate the intermediate read_pc_pid(). The client would call
1284 TARGET_READ_PC directly. (cagney). */
1287 generic_target_read_pc (ptid_t ptid
)
1292 CORE_ADDR pc_val
= ADDR_BITS_REMOVE ((CORE_ADDR
) read_register_pid (PC_REGNUM
, ptid
));
1296 internal_error (__FILE__
, __LINE__
,
1297 "generic_target_read_pc");
1302 read_pc_pid (ptid_t ptid
)
1304 ptid_t saved_inferior_ptid
;
1307 /* In case ptid != inferior_ptid. */
1308 saved_inferior_ptid
= inferior_ptid
;
1309 inferior_ptid
= ptid
;
1311 pc_val
= TARGET_READ_PC (ptid
);
1313 inferior_ptid
= saved_inferior_ptid
;
1320 return read_pc_pid (inferior_ptid
);
1324 generic_target_write_pc (CORE_ADDR pc
, ptid_t ptid
)
1328 write_register_pid (PC_REGNUM
, pc
, ptid
);
1329 if (NPC_REGNUM
>= 0)
1330 write_register_pid (NPC_REGNUM
, pc
+ 4, ptid
);
1332 internal_error (__FILE__
, __LINE__
,
1333 "generic_target_write_pc");
1338 write_pc_pid (CORE_ADDR pc
, ptid_t ptid
)
1340 ptid_t saved_inferior_ptid
;
1342 /* In case ptid != inferior_ptid. */
1343 saved_inferior_ptid
= inferior_ptid
;
1344 inferior_ptid
= ptid
;
1346 TARGET_WRITE_PC (pc
, ptid
);
1348 inferior_ptid
= saved_inferior_ptid
;
1352 write_pc (CORE_ADDR pc
)
1354 write_pc_pid (pc
, inferior_ptid
);
1357 /* Cope with strage ways of getting to the stack and frame pointers */
1360 generic_target_read_sp (void)
1364 return read_register (SP_REGNUM
);
1366 internal_error (__FILE__
, __LINE__
,
1367 "generic_target_read_sp");
1373 return TARGET_READ_SP ();
1377 generic_target_write_sp (CORE_ADDR val
)
1382 write_register (SP_REGNUM
, val
);
1386 internal_error (__FILE__
, __LINE__
,
1387 "generic_target_write_sp");
1391 write_sp (CORE_ADDR val
)
1393 TARGET_WRITE_SP (val
);
1397 generic_target_read_fp (void)
1401 return read_register (FP_REGNUM
);
1403 internal_error (__FILE__
, __LINE__
,
1404 "generic_target_read_fp");
1410 return TARGET_READ_FP ();
1415 reg_flush_command (char *command
, int from_tty
)
1417 /* Force-flush the register cache. */
1418 registers_changed ();
1420 printf_filtered ("Register cache flushed.\n");
1424 build_regcache (void)
1426 current_regcache
= regcache_xmalloc (current_gdbarch
);
1427 current_regcache
->readonly_p
= 0;
1428 deprecated_registers
= deprecated_grub_regcache_for_registers (current_regcache
);
1429 deprecated_register_valid
= deprecated_grub_regcache_for_register_valid (current_regcache
);
1433 dump_endian_bytes (struct ui_file
*file
, enum bfd_endian endian
,
1434 const unsigned char *buf
, long len
)
1439 case BFD_ENDIAN_BIG
:
1440 for (i
= 0; i
< len
; i
++)
1441 fprintf_unfiltered (file
, "%02x", buf
[i
]);
1443 case BFD_ENDIAN_LITTLE
:
1444 for (i
= len
- 1; i
>= 0; i
--)
1445 fprintf_unfiltered (file
, "%02x", buf
[i
]);
1448 internal_error (__FILE__
, __LINE__
, "Bad switch");
1452 enum regcache_dump_what
1454 regcache_dump_none
, regcache_dump_raw
, regcache_dump_cooked
, regcache_dump_groups
1458 regcache_dump (struct regcache
*regcache
, struct ui_file
*file
,
1459 enum regcache_dump_what what_to_dump
)
1461 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
1462 struct gdbarch
*gdbarch
= regcache
->descr
->gdbarch
;
1463 struct reggroup
*const *groups
= reggroups (gdbarch
);
1465 int footnote_nr
= 0;
1466 int footnote_register_size
= 0;
1467 int footnote_register_offset
= 0;
1468 int footnote_register_type_name_null
= 0;
1469 long register_offset
= 0;
1470 unsigned char *buf
= alloca (regcache
->descr
->max_register_size
);
1473 fprintf_unfiltered (file
, "legacy_p %d\n", regcache
->descr
->legacy_p
);
1474 fprintf_unfiltered (file
, "nr_raw_registers %d\n",
1475 regcache
->descr
->nr_raw_registers
);
1476 fprintf_unfiltered (file
, "nr_cooked_registers %d\n",
1477 regcache
->descr
->nr_cooked_registers
);
1478 fprintf_unfiltered (file
, "sizeof_raw_registers %ld\n",
1479 regcache
->descr
->sizeof_raw_registers
);
1480 fprintf_unfiltered (file
, "sizeof_raw_register_valid_p %ld\n",
1481 regcache
->descr
->sizeof_raw_register_valid_p
);
1482 fprintf_unfiltered (file
, "max_register_size %ld\n",
1483 regcache
->descr
->max_register_size
);
1484 fprintf_unfiltered (file
, "NUM_REGS %d\n", NUM_REGS
);
1485 fprintf_unfiltered (file
, "NUM_PSEUDO_REGS %d\n", NUM_PSEUDO_REGS
);
1488 gdb_assert (regcache
->descr
->nr_cooked_registers
1489 == (NUM_REGS
+ NUM_PSEUDO_REGS
));
1491 for (regnum
= -1; regnum
< regcache
->descr
->nr_cooked_registers
; regnum
++)
1495 fprintf_unfiltered (file
, " %-10s", "Name");
1498 const char *p
= REGISTER_NAME (regnum
);
1501 else if (p
[0] == '\0')
1503 fprintf_unfiltered (file
, " %-10s", p
);
1508 fprintf_unfiltered (file
, " %4s", "Nr");
1510 fprintf_unfiltered (file
, " %4d", regnum
);
1512 /* Relative number. */
1514 fprintf_unfiltered (file
, " %4s", "Rel");
1515 else if (regnum
< NUM_REGS
)
1516 fprintf_unfiltered (file
, " %4d", regnum
);
1518 fprintf_unfiltered (file
, " %4d", (regnum
- NUM_REGS
));
1522 fprintf_unfiltered (file
, " %6s ", "Offset");
1525 fprintf_unfiltered (file
, " %6ld",
1526 regcache
->descr
->register_offset
[regnum
]);
1527 if (register_offset
!= regcache
->descr
->register_offset
[regnum
]
1528 || register_offset
!= REGISTER_BYTE (regnum
)
1530 && (regcache
->descr
->register_offset
[regnum
]
1531 != (regcache
->descr
->register_offset
[regnum
- 1]
1532 + regcache
->descr
->sizeof_register
[regnum
- 1])))
1535 if (!footnote_register_offset
)
1536 footnote_register_offset
= ++footnote_nr
;
1537 fprintf_unfiltered (file
, "*%d", footnote_register_offset
);
1540 fprintf_unfiltered (file
, " ");
1541 register_offset
= (regcache
->descr
->register_offset
[regnum
]
1542 + regcache
->descr
->sizeof_register
[regnum
]);
1547 fprintf_unfiltered (file
, " %5s ", "Size");
1550 fprintf_unfiltered (file
, " %5ld",
1551 regcache
->descr
->sizeof_register
[regnum
]);
1552 if ((regcache
->descr
->sizeof_register
[regnum
]
1553 != REGISTER_RAW_SIZE (regnum
))
1554 || (regcache
->descr
->sizeof_register
[regnum
]
1555 != REGISTER_VIRTUAL_SIZE (regnum
))
1556 || (regcache
->descr
->sizeof_register
[regnum
]
1557 != TYPE_LENGTH (register_type (regcache
->descr
->gdbarch
,
1561 if (!footnote_register_size
)
1562 footnote_register_size
= ++footnote_nr
;
1563 fprintf_unfiltered (file
, "*%d", footnote_register_size
);
1566 fprintf_unfiltered (file
, " ");
1576 static const char blt
[] = "builtin_type";
1577 t
= TYPE_NAME (register_type (regcache
->descr
->gdbarch
, regnum
));
1581 if (!footnote_register_type_name_null
)
1582 footnote_register_type_name_null
= ++footnote_nr
;
1583 xasprintf (&n
, "*%d", footnote_register_type_name_null
);
1584 make_cleanup (xfree
, n
);
1587 /* Chop a leading builtin_type. */
1588 if (strncmp (t
, blt
, strlen (blt
)) == 0)
1591 fprintf_unfiltered (file
, " %-15s", t
);
1594 /* Leading space always present. */
1595 fprintf_unfiltered (file
, " ");
1598 if (what_to_dump
== regcache_dump_raw
)
1601 fprintf_unfiltered (file
, "Raw value");
1602 else if (regnum
>= regcache
->descr
->nr_raw_registers
)
1603 fprintf_unfiltered (file
, "<cooked>");
1604 else if (!regcache_valid_p (regcache
, regnum
))
1605 fprintf_unfiltered (file
, "<invalid>");
1608 regcache_raw_read (regcache
, regnum
, buf
);
1609 fprintf_unfiltered (file
, "0x");
1610 dump_endian_bytes (file
, TARGET_BYTE_ORDER
, buf
,
1611 REGISTER_RAW_SIZE (regnum
));
1615 /* Value, cooked. */
1616 if (what_to_dump
== regcache_dump_cooked
)
1619 fprintf_unfiltered (file
, "Cooked value");
1622 regcache_cooked_read (regcache
, regnum
, buf
);
1623 fprintf_unfiltered (file
, "0x");
1624 dump_endian_bytes (file
, TARGET_BYTE_ORDER
, buf
,
1625 REGISTER_VIRTUAL_SIZE (regnum
));
1629 /* Group members. */
1630 if (what_to_dump
== regcache_dump_groups
)
1633 fprintf_unfiltered (file
, "Groups");
1637 const char *sep
= "";
1638 for (i
= 0; groups
[i
] != NULL
; i
++)
1640 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, groups
[i
]))
1642 fprintf_unfiltered (file
, "%s%s", sep
, reggroup_name (groups
[i
]));
1649 fprintf_unfiltered (file
, "\n");
1652 if (footnote_register_size
)
1653 fprintf_unfiltered (file
, "*%d: Inconsistent register sizes.\n",
1654 footnote_register_size
);
1655 if (footnote_register_offset
)
1656 fprintf_unfiltered (file
, "*%d: Inconsistent register offsets.\n",
1657 footnote_register_offset
);
1658 if (footnote_register_type_name_null
)
1659 fprintf_unfiltered (file
,
1660 "*%d: Register type's name NULL.\n",
1661 footnote_register_type_name_null
);
1662 do_cleanups (cleanups
);
1666 regcache_print (char *args
, enum regcache_dump_what what_to_dump
)
1669 regcache_dump (current_regcache
, gdb_stdout
, what_to_dump
);
1672 struct ui_file
*file
= gdb_fopen (args
, "w");
1674 perror_with_name ("maintenance print architecture");
1675 regcache_dump (current_regcache
, file
, what_to_dump
);
1676 ui_file_delete (file
);
1681 maintenance_print_registers (char *args
, int from_tty
)
1683 regcache_print (args
, regcache_dump_none
);
1687 maintenance_print_raw_registers (char *args
, int from_tty
)
1689 regcache_print (args
, regcache_dump_raw
);
1693 maintenance_print_cooked_registers (char *args
, int from_tty
)
1695 regcache_print (args
, regcache_dump_cooked
);
1699 maintenance_print_register_groups (char *args
, int from_tty
)
1701 regcache_print (args
, regcache_dump_groups
);
1705 _initialize_regcache (void)
1707 regcache_descr_handle
= register_gdbarch_data (init_regcache_descr
,
1708 xfree_regcache_descr
);
1709 REGISTER_GDBARCH_SWAP (current_regcache
);
1710 register_gdbarch_swap (&deprecated_registers
, sizeof (deprecated_registers
), NULL
);
1711 register_gdbarch_swap (&deprecated_register_valid
, sizeof (deprecated_register_valid
), NULL
);
1712 register_gdbarch_swap (NULL
, 0, build_regcache
);
1714 add_com ("flushregs", class_maintenance
, reg_flush_command
,
1715 "Force gdb to flush its register cache (maintainer command)");
1717 /* Initialize the thread/process associated with the current set of
1718 registers. For now, -1 is special, and means `no current process'. */
1719 registers_ptid
= pid_to_ptid (-1);
1721 add_cmd ("registers", class_maintenance
,
1722 maintenance_print_registers
,
1723 "Print the internal register configuration.\
1724 Takes an optional file parameter.",
1725 &maintenanceprintlist
);
1726 add_cmd ("raw-registers", class_maintenance
,
1727 maintenance_print_raw_registers
,
1728 "Print the internal register configuration including raw values.\
1729 Takes an optional file parameter.",
1730 &maintenanceprintlist
);
1731 add_cmd ("cooked-registers", class_maintenance
,
1732 maintenance_print_cooked_registers
,
1733 "Print the internal register configuration including cooked values.\
1734 Takes an optional file parameter.",
1735 &maintenanceprintlist
);
1736 add_cmd ("register-groups", class_maintenance
,
1737 maintenance_print_register_groups
,
1738 "Print the internal register configuration including each register's group.\
1739 Takes an optional file parameter.",
1740 &maintenanceprintlist
);