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. Each raw (or hard) register is supplied
55 by the target interface. The raw cache should not contain
56 redundant information - if the PC is constructed from two
57 registers then those regigisters and not the PC lives in the raw
60 long sizeof_raw_registers
;
61 long sizeof_raw_register_valid_p
;
63 /* The cooked register space. Each cooked register in the range
64 [0..NR_RAW_REGISTERS) is direct-mapped onto the corresponding raw
65 register. The remaining [NR_RAW_REGISTERS
66 .. NR_COOKED_REGISTERS) (a.k.a. pseudo regiters) are mapped onto
67 both raw registers and memory by the architecture methods
68 gdbarch_register_read and gdbarch_register_write. */
69 int nr_cooked_registers
;
70 long sizeof_cooked_registers
;
71 long sizeof_cooked_register_valid_p
;
73 /* Offset and size (in 8 bit bytes), of reach register in the
74 register cache. All registers (including those in the range
75 [NR_RAW_REGISTERS .. NR_COOKED_REGISTERS) are given an offset.
76 Assigning all registers an offset makes it possible to keep
77 legacy code, such as that found in read_register_bytes() and
78 write_register_bytes() working. */
79 long *register_offset
;
80 long *sizeof_register
;
82 /* Cached table containing the type of each register. */
83 struct type
**register_type
;
87 init_legacy_regcache_descr (struct gdbarch
*gdbarch
,
88 struct regcache_descr
*descr
)
91 /* FIXME: cagney/2002-05-11: gdbarch_data() should take that
92 ``gdbarch'' as a parameter. */
93 gdb_assert (gdbarch
!= NULL
);
95 /* Compute the offset of each register. Legacy architectures define
96 REGISTER_BYTE() so use that. */
97 /* FIXME: cagney/2002-11-07: Instead of using REGISTER_BYTE() this
98 code should, as is done in init_regcache_descr(), compute the
99 offets at runtime. This currently isn't possible as some ISAs
100 define overlapping register regions - see the mess in
101 read_register_bytes() and write_register_bytes() registers. */
102 descr
->sizeof_register
103 = GDBARCH_OBSTACK_CALLOC (gdbarch
, descr
->nr_cooked_registers
, long);
104 descr
->register_offset
105 = GDBARCH_OBSTACK_CALLOC (gdbarch
, descr
->nr_cooked_registers
, long);
106 for (i
= 0; i
< descr
->nr_cooked_registers
; i
++)
108 /* FIXME: cagney/2001-12-04: This code shouldn't need to use
109 REGISTER_BYTE(). Unfortunatly, legacy code likes to lay the
110 buffer out so that certain registers just happen to overlap.
111 Ulgh! New targets use gdbarch's register read/write and
112 entirely avoid this uglyness. */
113 descr
->register_offset
[i
] = REGISTER_BYTE (i
);
114 descr
->sizeof_register
[i
] = REGISTER_RAW_SIZE (i
);
115 gdb_assert (MAX_REGISTER_SIZE
>= REGISTER_RAW_SIZE (i
));
116 gdb_assert (MAX_REGISTER_SIZE
>= REGISTER_VIRTUAL_SIZE (i
));
119 /* Compute the real size of the register buffer. Start out by
120 trusting DEPRECATED_REGISTER_BYTES, but then adjust it upwards
121 should that be found to not be sufficient. */
122 /* FIXME: cagney/2002-11-05: Instead of using the macro
123 DEPRECATED_REGISTER_BYTES, this code should, as is done in
124 init_regcache_descr(), compute the total number of register bytes
125 using the accumulated offsets. */
126 descr
->sizeof_cooked_registers
= DEPRECATED_REGISTER_BYTES
; /* OK */
127 for (i
= 0; i
< descr
->nr_cooked_registers
; i
++)
130 /* Keep extending the buffer so that there is always enough
131 space for all registers. The comparison is necessary since
132 legacy code is free to put registers in random places in the
133 buffer separated by holes. Once REGISTER_BYTE() is killed
134 this can be greatly simplified. */
135 regend
= descr
->register_offset
[i
] + descr
->sizeof_register
[i
];
136 if (descr
->sizeof_cooked_registers
< regend
)
137 descr
->sizeof_cooked_registers
= regend
;
139 /* FIXME: cagney/2002-05-11: Shouldn't be including pseudo-registers
140 in the register cache. Unfortunatly some architectures still
141 rely on this and the pseudo_register_write() method. */
142 descr
->sizeof_raw_registers
= descr
->sizeof_cooked_registers
;
146 init_regcache_descr (struct gdbarch
*gdbarch
)
149 struct regcache_descr
*descr
;
150 gdb_assert (gdbarch
!= NULL
);
152 /* Create an initial, zero filled, table. */
153 descr
= GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct regcache_descr
);
154 descr
->gdbarch
= gdbarch
;
156 /* Total size of the register space. The raw registers are mapped
157 directly onto the raw register cache while the pseudo's are
158 either mapped onto raw-registers or memory. */
159 descr
->nr_cooked_registers
= NUM_REGS
+ NUM_PSEUDO_REGS
;
160 descr
->sizeof_cooked_register_valid_p
= NUM_REGS
+ NUM_PSEUDO_REGS
;
162 /* Fill in a table of register types. */
164 = GDBARCH_OBSTACK_CALLOC (gdbarch
, descr
->nr_cooked_registers
, struct type
*);
165 for (i
= 0; i
< descr
->nr_cooked_registers
; i
++)
167 if (gdbarch_register_type_p (gdbarch
))
169 gdb_assert (!REGISTER_VIRTUAL_TYPE_P ()); /* OK */
170 descr
->register_type
[i
] = gdbarch_register_type (gdbarch
, i
);
173 descr
->register_type
[i
] = REGISTER_VIRTUAL_TYPE (i
); /* OK */
176 /* Construct a strictly RAW register cache. Don't allow pseudo's
177 into the register cache. */
178 descr
->nr_raw_registers
= NUM_REGS
;
180 /* FIXME: cagney/2002-08-13: Overallocate the register_valid_p
181 array. This pretects GDB from erant code that accesses elements
182 of the global register_valid_p[] array in the range [NUM_REGS
183 .. NUM_REGS + NUM_PSEUDO_REGS). */
184 descr
->sizeof_raw_register_valid_p
= descr
->sizeof_cooked_register_valid_p
;
186 /* If an old style architecture, fill in the remainder of the
187 register cache descriptor using the register macros. */
188 /* NOTE: cagney/2003-06-29: If either of REGISTER_BYTE or
189 REGISTER_RAW_SIZE are still present, things are most likely
190 totally screwed. Ex: an architecture with raw register sizes
191 smaller than what REGISTER_BYTE indicates; non monotonic
192 REGISTER_BYTE values. For GDB 6 check for these nasty methods
193 and fall back to legacy code when present. Sigh! */
194 if ((!gdbarch_pseudo_register_read_p (gdbarch
)
195 && !gdbarch_pseudo_register_write_p (gdbarch
)
196 && !gdbarch_register_type_p (gdbarch
))
197 || REGISTER_BYTE_P () || REGISTER_RAW_SIZE_P ())
200 init_legacy_regcache_descr (gdbarch
, descr
);
204 /* Lay out the register cache.
206 NOTE: cagney/2002-05-22: Only register_type() is used when
207 constructing the register cache. It is assumed that the
208 register's raw size, virtual size and type length are all the
213 descr
->sizeof_register
214 = GDBARCH_OBSTACK_CALLOC (gdbarch
, descr
->nr_cooked_registers
, long);
215 descr
->register_offset
216 = GDBARCH_OBSTACK_CALLOC (gdbarch
, descr
->nr_cooked_registers
, long);
217 for (i
= 0; i
< descr
->nr_cooked_registers
; i
++)
219 descr
->sizeof_register
[i
] = TYPE_LENGTH (descr
->register_type
[i
]);
220 descr
->register_offset
[i
] = offset
;
221 offset
+= descr
->sizeof_register
[i
];
222 gdb_assert (MAX_REGISTER_SIZE
>= descr
->sizeof_register
[i
]);
224 /* Set the real size of the register cache buffer. */
225 descr
->sizeof_cooked_registers
= offset
;
228 /* FIXME: cagney/2002-05-22: Should only need to allocate space for
229 the raw registers. Unfortunatly some code still accesses the
230 register array directly using the global registers[]. Until that
231 code has been purged, play safe and over allocating the register
233 descr
->sizeof_raw_registers
= descr
->sizeof_cooked_registers
;
235 /* Sanity check. Confirm that there is agreement between the
236 regcache and the target's redundant REGISTER_BYTE (new targets
237 should not even be defining it). */
238 for (i
= 0; i
< descr
->nr_cooked_registers
; i
++)
240 if (REGISTER_BYTE_P ())
241 gdb_assert (descr
->register_offset
[i
] == REGISTER_BYTE (i
));
243 gdb_assert (descr
->sizeof_register
[i
] == REGISTER_RAW_SIZE (i
));
244 gdb_assert (descr
->sizeof_register
[i
] == REGISTER_VIRTUAL_SIZE (i
));
247 /* gdb_assert (descr->sizeof_raw_registers == DEPRECATED_REGISTER_BYTES (i)); */
252 static struct regcache_descr
*
253 regcache_descr (struct gdbarch
*gdbarch
)
255 return gdbarch_data (gdbarch
, regcache_descr_handle
);
258 /* Utility functions returning useful register attributes stored in
259 the regcache descr. */
262 register_type (struct gdbarch
*gdbarch
, int regnum
)
264 struct regcache_descr
*descr
= regcache_descr (gdbarch
);
265 gdb_assert (regnum
>= 0 && regnum
< descr
->nr_cooked_registers
);
266 return descr
->register_type
[regnum
];
269 /* Utility functions returning useful register attributes stored in
270 the regcache descr. */
273 register_size (struct gdbarch
*gdbarch
, int regnum
)
275 struct regcache_descr
*descr
= regcache_descr (gdbarch
);
277 gdb_assert (regnum
>= 0 && regnum
< (NUM_REGS
+ NUM_PSEUDO_REGS
));
278 size
= descr
->sizeof_register
[regnum
];
279 /* NB: The deprecated REGISTER_RAW_SIZE, if not provided, defaults
280 to the size of the register's type. */
281 gdb_assert (size
== REGISTER_RAW_SIZE (regnum
)); /* OK */
282 /* NB: Don't check the register's virtual size. It, in say the case
283 of the MIPS, may not match the raw size! */
287 /* The register cache for storing raw register values. */
291 struct regcache_descr
*descr
;
292 /* The register buffers. A read-only register cache can hold the
293 full [0 .. NUM_REGS + NUM_PSEUDO_REGS) while a read/write
294 register cache can only hold [0 .. NUM_REGS). */
296 char *register_valid_p
;
297 /* Is this a read-only cache? A read-only cache is used for saving
298 the target's register state (e.g, across an inferior function
299 call or just before forcing a function return). A read-only
300 cache can only be updated via the methods regcache_dup() and
301 regcache_cpy(). The actual contents are determined by the
302 reggroup_save and reggroup_restore methods. */
307 regcache_xmalloc (struct gdbarch
*gdbarch
)
309 struct regcache_descr
*descr
;
310 struct regcache
*regcache
;
311 gdb_assert (gdbarch
!= NULL
);
312 descr
= regcache_descr (gdbarch
);
313 regcache
= XMALLOC (struct regcache
);
314 regcache
->descr
= descr
;
316 = XCALLOC (descr
->sizeof_raw_registers
, char);
317 regcache
->register_valid_p
318 = XCALLOC (descr
->sizeof_raw_register_valid_p
, char);
319 regcache
->readonly_p
= 1;
324 regcache_xfree (struct regcache
*regcache
)
326 if (regcache
== NULL
)
328 xfree (regcache
->registers
);
329 xfree (regcache
->register_valid_p
);
334 do_regcache_xfree (void *data
)
336 regcache_xfree (data
);
340 make_cleanup_regcache_xfree (struct regcache
*regcache
)
342 return make_cleanup (do_regcache_xfree
, regcache
);
345 /* Return a pointer to register REGNUM's buffer cache. */
348 register_buffer (const struct regcache
*regcache
, int regnum
)
350 return regcache
->registers
+ regcache
->descr
->register_offset
[regnum
];
354 regcache_save (struct regcache
*dst
, regcache_cooked_read_ftype
*cooked_read
,
357 struct gdbarch
*gdbarch
= dst
->descr
->gdbarch
;
358 char buf
[MAX_REGISTER_SIZE
];
360 /* The DST should be `read-only', if it wasn't then the save would
361 end up trying to write the register values back out to the
363 gdb_assert (dst
->readonly_p
);
364 /* Clear the dest. */
365 memset (dst
->registers
, 0, dst
->descr
->sizeof_cooked_registers
);
366 memset (dst
->register_valid_p
, 0, dst
->descr
->sizeof_cooked_register_valid_p
);
367 /* Copy over any registers (identified by their membership in the
368 save_reggroup) and mark them as valid. The full [0 .. NUM_REGS +
369 NUM_PSEUDO_REGS) range is checked since some architectures need
370 to save/restore `cooked' registers that live in memory. */
371 for (regnum
= 0; regnum
< dst
->descr
->nr_cooked_registers
; regnum
++)
373 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, save_reggroup
))
375 int valid
= cooked_read (src
, regnum
, buf
);
378 memcpy (register_buffer (dst
, regnum
), buf
,
379 register_size (gdbarch
, regnum
));
380 dst
->register_valid_p
[regnum
] = 1;
387 regcache_restore (struct regcache
*dst
,
388 regcache_cooked_read_ftype
*cooked_read
,
391 struct gdbarch
*gdbarch
= dst
->descr
->gdbarch
;
392 char buf
[MAX_REGISTER_SIZE
];
394 /* The dst had better not be read-only. If it is, the `restore'
395 doesn't make much sense. */
396 gdb_assert (!dst
->readonly_p
);
397 /* Copy over any registers, being careful to only restore those that
398 were both saved and need to be restored. The full [0 .. NUM_REGS
399 + NUM_PSEUDO_REGS) range is checked since some architectures need
400 to save/restore `cooked' registers that live in memory. */
401 for (regnum
= 0; regnum
< dst
->descr
->nr_cooked_registers
; regnum
++)
403 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, restore_reggroup
))
405 int valid
= cooked_read (src
, regnum
, buf
);
407 regcache_cooked_write (dst
, regnum
, buf
);
413 do_cooked_read (void *src
, int regnum
, void *buf
)
415 struct regcache
*regcache
= src
;
416 if (!regcache
->register_valid_p
[regnum
] && regcache
->readonly_p
)
417 /* Don't even think about fetching a register from a read-only
418 cache when the register isn't yet valid. There isn't a target
419 from which the register value can be fetched. */
421 regcache_cooked_read (regcache
, regnum
, buf
);
427 regcache_cpy (struct regcache
*dst
, struct regcache
*src
)
431 gdb_assert (src
!= NULL
&& dst
!= NULL
);
432 gdb_assert (src
->descr
->gdbarch
== dst
->descr
->gdbarch
);
433 gdb_assert (src
!= dst
);
434 gdb_assert (src
->readonly_p
|| dst
->readonly_p
);
435 if (!src
->readonly_p
)
436 regcache_save (dst
, do_cooked_read
, src
);
437 else if (!dst
->readonly_p
)
438 regcache_restore (dst
, do_cooked_read
, src
);
440 regcache_cpy_no_passthrough (dst
, src
);
444 regcache_cpy_no_passthrough (struct regcache
*dst
, struct regcache
*src
)
447 gdb_assert (src
!= NULL
&& dst
!= NULL
);
448 gdb_assert (src
->descr
->gdbarch
== dst
->descr
->gdbarch
);
449 /* NOTE: cagney/2002-05-17: Don't let the caller do a no-passthrough
450 move of data into the current_regcache(). Doing this would be
451 silly - it would mean that valid_p would be completly invalid. */
452 gdb_assert (dst
!= current_regcache
);
453 memcpy (dst
->registers
, src
->registers
, dst
->descr
->sizeof_raw_registers
);
454 memcpy (dst
->register_valid_p
, src
->register_valid_p
,
455 dst
->descr
->sizeof_raw_register_valid_p
);
459 regcache_dup (struct regcache
*src
)
461 struct regcache
*newbuf
;
462 gdb_assert (current_regcache
!= NULL
);
463 newbuf
= regcache_xmalloc (src
->descr
->gdbarch
);
464 regcache_cpy (newbuf
, src
);
469 regcache_dup_no_passthrough (struct regcache
*src
)
471 struct regcache
*newbuf
;
472 gdb_assert (current_regcache
!= NULL
);
473 newbuf
= regcache_xmalloc (src
->descr
->gdbarch
);
474 regcache_cpy_no_passthrough (newbuf
, src
);
479 regcache_valid_p (struct regcache
*regcache
, int regnum
)
481 gdb_assert (regcache
!= NULL
);
482 gdb_assert (regnum
>= 0 && regnum
< regcache
->descr
->nr_raw_registers
);
483 return regcache
->register_valid_p
[regnum
];
487 deprecated_grub_regcache_for_registers (struct regcache
*regcache
)
489 return regcache
->registers
;
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
[MAX_REGISTER_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_cooked_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_cooked_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
]);
863 regcache_cooked_write_signed (struct regcache
*regcache
, int regnum
,
867 gdb_assert (regcache
!= NULL
);
868 gdb_assert (regnum
>=0 && regnum
< regcache
->descr
->nr_cooked_registers
);
869 buf
= alloca (regcache
->descr
->sizeof_register
[regnum
]);
870 store_signed_integer (buf
, regcache
->descr
->sizeof_register
[regnum
], val
);
871 regcache_cooked_write (regcache
, regnum
, buf
);
875 regcache_cooked_write_unsigned (struct regcache
*regcache
, int regnum
,
879 gdb_assert (regcache
!= NULL
);
880 gdb_assert (regnum
>=0 && regnum
< regcache
->descr
->nr_cooked_registers
);
881 buf
= alloca (regcache
->descr
->sizeof_register
[regnum
]);
882 store_unsigned_integer (buf
, regcache
->descr
->sizeof_register
[regnum
], val
);
883 regcache_cooked_write (regcache
, regnum
, buf
);
886 /* Write register REGNUM at MYADDR to the target. MYADDR points at
887 REGISTER_RAW_BYTES(REGNUM), which must be in target byte-order. */
890 legacy_write_register_gen (int regnum
, const void *myaddr
)
893 gdb_assert (regnum
>= 0 && regnum
< (NUM_REGS
+ NUM_PSEUDO_REGS
));
895 /* On the sparc, writing %g0 is a no-op, so we don't even want to
896 change the registers array if something writes to this register. */
897 if (CANNOT_STORE_REGISTER (regnum
))
900 if (! ptid_equal (registers_ptid
, inferior_ptid
))
902 registers_changed ();
903 registers_ptid
= inferior_ptid
;
906 size
= REGISTER_RAW_SIZE (regnum
);
908 if (real_register (regnum
))
910 /* If we have a valid copy of the register, and new value == old
911 value, then don't bother doing the actual store. */
912 if (register_cached (regnum
)
913 && (memcmp (register_buffer (current_regcache
, regnum
), myaddr
, size
)
917 target_prepare_to_store ();
920 memcpy (register_buffer (current_regcache
, regnum
), myaddr
, size
);
922 set_register_cached (regnum
, 1);
923 target_store_registers (regnum
);
927 regcache_raw_write (struct regcache
*regcache
, int regnum
, const void *buf
)
929 gdb_assert (regcache
!= NULL
&& buf
!= NULL
);
930 gdb_assert (regnum
>= 0 && regnum
< regcache
->descr
->nr_raw_registers
);
931 gdb_assert (!regcache
->readonly_p
);
933 if (regcache
->descr
->legacy_p
)
935 /* For moment, just use underlying legacy code. Ulgh!!! This
936 silently and very indirectly updates the regcache's buffers
937 via the globals deprecated_register_valid[] and registers[]. */
938 gdb_assert (regcache
== current_regcache
);
939 legacy_write_register_gen (regnum
, buf
);
943 /* On the sparc, writing %g0 is a no-op, so we don't even want to
944 change the registers array if something writes to this register. */
945 if (CANNOT_STORE_REGISTER (regnum
))
948 /* Make certain that the correct cache is selected. */
949 gdb_assert (regcache
== current_regcache
);
950 if (! ptid_equal (registers_ptid
, inferior_ptid
))
952 registers_changed ();
953 registers_ptid
= inferior_ptid
;
956 /* If we have a valid copy of the register, and new value == old
957 value, then don't bother doing the actual store. */
958 if (regcache_valid_p (regcache
, regnum
)
959 && (memcmp (register_buffer (regcache
, regnum
), buf
,
960 regcache
->descr
->sizeof_register
[regnum
]) == 0))
963 target_prepare_to_store ();
964 memcpy (register_buffer (regcache
, regnum
), buf
,
965 regcache
->descr
->sizeof_register
[regnum
]);
966 regcache
->register_valid_p
[regnum
] = 1;
967 target_store_registers (regnum
);
971 deprecated_write_register_gen (int regnum
, char *buf
)
973 gdb_assert (current_regcache
!= NULL
);
974 gdb_assert (current_regcache
->descr
->gdbarch
== current_gdbarch
);
975 if (current_regcache
->descr
->legacy_p
)
977 legacy_write_register_gen (regnum
, buf
);
980 regcache_cooked_write (current_regcache
, regnum
, buf
);
984 regcache_cooked_write (struct regcache
*regcache
, int regnum
, const void *buf
)
986 gdb_assert (regnum
>= 0);
987 gdb_assert (regnum
< regcache
->descr
->nr_cooked_registers
);
988 if (regnum
< regcache
->descr
->nr_raw_registers
)
989 regcache_raw_write (regcache
, regnum
, buf
);
991 gdbarch_pseudo_register_write (regcache
->descr
->gdbarch
, regcache
,
995 /* Copy INLEN bytes of consecutive data from memory at MYADDR
996 into registers starting with the MYREGSTART'th byte of register data. */
999 deprecated_write_register_bytes (int myregstart
, char *myaddr
, int inlen
)
1001 int myregend
= myregstart
+ inlen
;
1004 target_prepare_to_store ();
1006 /* Scan through the registers updating any that are covered by the
1007 range myregstart<=>myregend using write_register_gen, which does
1008 nice things like handling threads, and avoiding updates when the
1009 new and old contents are the same. */
1011 for (regnum
= 0; regnum
< NUM_REGS
+ NUM_PSEUDO_REGS
; regnum
++)
1013 int regstart
, regend
;
1015 regstart
= REGISTER_BYTE (regnum
);
1016 regend
= regstart
+ REGISTER_RAW_SIZE (regnum
);
1018 /* Is this register completely outside the range the user is writing? */
1019 if (myregend
<= regstart
|| regend
<= myregstart
)
1022 /* Is this register completely within the range the user is writing? */
1023 else if (myregstart
<= regstart
&& regend
<= myregend
)
1024 deprecated_write_register_gen (regnum
, myaddr
+ (regstart
- myregstart
));
1026 /* The register partially overlaps the range being written. */
1029 char regbuf
[MAX_REGISTER_SIZE
];
1030 /* What's the overlap between this register's bytes and
1031 those the caller wants to write? */
1032 int overlapstart
= max (regstart
, myregstart
);
1033 int overlapend
= min (regend
, myregend
);
1035 /* We may be doing a partial update of an invalid register.
1036 Update it from the target before scribbling on it. */
1037 deprecated_read_register_gen (regnum
, regbuf
);
1039 memcpy (&deprecated_registers
[overlapstart
],
1040 myaddr
+ (overlapstart
- myregstart
),
1041 overlapend
- overlapstart
);
1043 target_store_registers (regnum
);
1048 /* Perform a partial register transfer using a read, modify, write
1051 typedef void (regcache_read_ftype
) (struct regcache
*regcache
, int regnum
,
1053 typedef void (regcache_write_ftype
) (struct regcache
*regcache
, int regnum
,
1057 regcache_xfer_part (struct regcache
*regcache
, int regnum
,
1058 int offset
, int len
, void *in
, const void *out
,
1059 regcache_read_ftype
*read
, regcache_write_ftype
*write
)
1061 struct regcache_descr
*descr
= regcache
->descr
;
1062 bfd_byte reg
[MAX_REGISTER_SIZE
];
1063 gdb_assert (offset
>= 0 && offset
<= descr
->sizeof_register
[regnum
]);
1064 gdb_assert (len
>= 0 && offset
+ len
<= descr
->sizeof_register
[regnum
]);
1065 /* Something to do? */
1066 if (offset
+ len
== 0)
1068 /* Read (when needed) ... */
1071 || offset
+ len
< descr
->sizeof_register
[regnum
])
1073 gdb_assert (read
!= NULL
);
1074 read (regcache
, regnum
, reg
);
1076 /* ... modify ... */
1078 memcpy (in
, reg
+ offset
, len
);
1080 memcpy (reg
+ offset
, out
, len
);
1081 /* ... write (when needed). */
1084 gdb_assert (write
!= NULL
);
1085 write (regcache
, regnum
, reg
);
1090 regcache_raw_read_part (struct regcache
*regcache
, int regnum
,
1091 int offset
, int len
, void *buf
)
1093 struct regcache_descr
*descr
= regcache
->descr
;
1094 gdb_assert (regnum
>= 0 && regnum
< descr
->nr_raw_registers
);
1095 regcache_xfer_part (regcache
, regnum
, offset
, len
, buf
, NULL
,
1096 regcache_raw_read
, regcache_raw_write
);
1100 regcache_raw_write_part (struct regcache
*regcache
, int regnum
,
1101 int offset
, int len
, const void *buf
)
1103 struct regcache_descr
*descr
= regcache
->descr
;
1104 gdb_assert (regnum
>= 0 && regnum
< descr
->nr_raw_registers
);
1105 regcache_xfer_part (regcache
, regnum
, offset
, len
, NULL
, buf
,
1106 regcache_raw_read
, regcache_raw_write
);
1110 regcache_cooked_read_part (struct regcache
*regcache
, int regnum
,
1111 int offset
, int len
, void *buf
)
1113 struct regcache_descr
*descr
= regcache
->descr
;
1114 gdb_assert (regnum
>= 0 && regnum
< descr
->nr_cooked_registers
);
1115 regcache_xfer_part (regcache
, regnum
, offset
, len
, buf
, NULL
,
1116 regcache_cooked_read
, regcache_cooked_write
);
1120 regcache_cooked_write_part (struct regcache
*regcache
, int regnum
,
1121 int offset
, int len
, const void *buf
)
1123 struct regcache_descr
*descr
= regcache
->descr
;
1124 gdb_assert (regnum
>= 0 && regnum
< descr
->nr_cooked_registers
);
1125 regcache_xfer_part (regcache
, regnum
, offset
, len
, NULL
, buf
,
1126 regcache_cooked_read
, regcache_cooked_write
);
1129 /* Hack to keep code that view the register buffer as raw bytes
1133 register_offset_hack (struct gdbarch
*gdbarch
, int regnum
)
1135 struct regcache_descr
*descr
= regcache_descr (gdbarch
);
1136 gdb_assert (regnum
>= 0 && regnum
< descr
->nr_cooked_registers
);
1137 return descr
->register_offset
[regnum
];
1140 /* Return the contents of register REGNUM as an unsigned integer. */
1143 read_register (int regnum
)
1145 char *buf
= alloca (REGISTER_RAW_SIZE (regnum
));
1146 deprecated_read_register_gen (regnum
, buf
);
1147 return (extract_unsigned_integer (buf
, REGISTER_RAW_SIZE (regnum
)));
1151 read_register_pid (int regnum
, ptid_t ptid
)
1157 if (ptid_equal (ptid
, inferior_ptid
))
1158 return read_register (regnum
);
1160 save_ptid
= inferior_ptid
;
1162 inferior_ptid
= ptid
;
1164 retval
= read_register (regnum
);
1166 inferior_ptid
= save_ptid
;
1171 /* Store VALUE into the raw contents of register number REGNUM. */
1174 write_register (int regnum
, LONGEST val
)
1178 size
= REGISTER_RAW_SIZE (regnum
);
1179 buf
= alloca (size
);
1180 store_signed_integer (buf
, size
, (LONGEST
) val
);
1181 deprecated_write_register_gen (regnum
, buf
);
1185 write_register_pid (int regnum
, CORE_ADDR val
, ptid_t ptid
)
1189 if (ptid_equal (ptid
, inferior_ptid
))
1191 write_register (regnum
, val
);
1195 save_ptid
= inferior_ptid
;
1197 inferior_ptid
= ptid
;
1199 write_register (regnum
, val
);
1201 inferior_ptid
= save_ptid
;
1204 /* FIXME: kettenis/20030828: We should get rid of supply_register and
1205 regcache_collect in favour of regcache_raw_supply and
1206 regcache_raw_collect. */
1208 /* SUPPLY_REGISTER()
1210 Record that register REGNUM contains VAL. This is used when the
1211 value is obtained from the inferior or core dump, so there is no
1212 need to store the value there.
1214 If VAL is a NULL pointer, then it's probably an unsupported register.
1215 We just set its value to all zeros. We might want to record this
1216 fact, and report it to the users of read_register and friends. */
1219 supply_register (int regnum
, const void *val
)
1221 regcache_raw_supply (current_regcache
, regnum
, val
);
1223 /* On some architectures, e.g. HPPA, there are a few stray bits in
1224 some registers, that the rest of the code would like to ignore. */
1226 /* NOTE: cagney/2001-03-16: The macro CLEAN_UP_REGISTER_VALUE is
1227 going to be deprecated. Instead architectures will leave the raw
1228 register value as is and instead clean things up as they pass
1229 through the method gdbarch_pseudo_register_read() clean up the
1232 #ifdef DEPRECATED_CLEAN_UP_REGISTER_VALUE
1233 DEPRECATED_CLEAN_UP_REGISTER_VALUE \
1234 (regnum
, register_buffer (current_regcache
, regnum
));
1239 regcache_collect (int regnum
, void *buf
)
1241 regcache_raw_collect (current_regcache
, regnum
, buf
);
1244 /* Supply register REGNUM, whose contents are stored in BUF, to REGCACHE. */
1247 regcache_raw_supply (struct regcache
*regcache
, int regnum
, const void *buf
)
1252 gdb_assert (regcache
!= NULL
);
1253 gdb_assert (regnum
>= 0 && regnum
< regcache
->descr
->nr_raw_registers
);
1254 gdb_assert (!regcache
->readonly_p
);
1256 /* FIXME: kettenis/20030828: It shouldn't be necessary to handle
1257 CURRENT_REGCACHE specially here. */
1258 if (regcache
== current_regcache
1259 && !ptid_equal (registers_ptid
, inferior_ptid
))
1261 registers_changed ();
1262 registers_ptid
= inferior_ptid
;
1265 regbuf
= register_buffer (regcache
, regnum
);
1266 size
= regcache
->descr
->sizeof_register
[regnum
];
1269 memcpy (regbuf
, buf
, size
);
1271 memset (regbuf
, 0, size
);
1273 /* Mark the register as cached. */
1274 regcache
->register_valid_p
[regnum
] = 1;
1277 /* Collect register REGNUM from REGCACHE and store its contents in BUF. */
1280 regcache_raw_collect (const struct regcache
*regcache
, int regnum
, void *buf
)
1285 gdb_assert (regcache
!= NULL
&& buf
!= NULL
);
1286 gdb_assert (regnum
>= 0 && regnum
< regcache
->descr
->nr_raw_registers
);
1288 regbuf
= register_buffer (regcache
, regnum
);
1289 size
= regcache
->descr
->sizeof_register
[regnum
];
1290 memcpy (buf
, regbuf
, size
);
1294 /* read_pc, write_pc, read_sp, deprecated_read_fp, etc. Special
1295 handling for registers PC, SP, and FP. */
1297 /* NOTE: cagney/2001-02-18: The functions read_pc_pid(), read_pc(),
1298 read_sp(), and deprecated_read_fp(), will eventually be replaced by
1299 per-frame methods. Instead of relying on the global INFERIOR_PTID,
1300 they will use the contextual information provided by the FRAME.
1301 These functions do not belong in the register cache. */
1303 /* NOTE: cagney/2003-06-07: The functions generic_target_write_pc(),
1304 write_pc_pid(), write_pc(), and deprecated_read_fp(), all need to
1305 be replaced by something that does not rely on global state. But
1309 read_pc_pid (ptid_t ptid
)
1311 ptid_t saved_inferior_ptid
;
1314 /* In case ptid != inferior_ptid. */
1315 saved_inferior_ptid
= inferior_ptid
;
1316 inferior_ptid
= ptid
;
1318 if (TARGET_READ_PC_P ())
1319 pc_val
= TARGET_READ_PC (ptid
);
1320 /* Else use per-frame method on get_current_frame. */
1321 else if (PC_REGNUM
>= 0)
1323 CORE_ADDR raw_val
= read_register_pid (PC_REGNUM
, ptid
);
1324 CORE_ADDR pc_val
= ADDR_BITS_REMOVE (raw_val
);
1328 internal_error (__FILE__
, __LINE__
, "read_pc_pid: Unable to find PC");
1330 inferior_ptid
= saved_inferior_ptid
;
1337 return read_pc_pid (inferior_ptid
);
1341 generic_target_write_pc (CORE_ADDR pc
, ptid_t ptid
)
1345 write_register_pid (PC_REGNUM
, pc
, ptid
);
1346 if (NPC_REGNUM
>= 0)
1347 write_register_pid (NPC_REGNUM
, pc
+ 4, ptid
);
1349 internal_error (__FILE__
, __LINE__
,
1350 "generic_target_write_pc");
1355 write_pc_pid (CORE_ADDR pc
, ptid_t ptid
)
1357 ptid_t saved_inferior_ptid
;
1359 /* In case ptid != inferior_ptid. */
1360 saved_inferior_ptid
= inferior_ptid
;
1361 inferior_ptid
= ptid
;
1363 TARGET_WRITE_PC (pc
, ptid
);
1365 inferior_ptid
= saved_inferior_ptid
;
1369 write_pc (CORE_ADDR pc
)
1371 write_pc_pid (pc
, inferior_ptid
);
1374 /* Cope with strage ways of getting to the stack and frame pointers */
1379 if (TARGET_READ_SP_P ())
1380 return TARGET_READ_SP ();
1381 else if (gdbarch_unwind_sp_p (current_gdbarch
))
1382 return get_frame_sp (get_current_frame ());
1383 else if (SP_REGNUM
>= 0)
1384 /* Try SP_REGNUM last: this makes all sorts of [wrong] assumptions
1385 about the architecture so put it at the end. */
1386 return read_register (SP_REGNUM
);
1387 internal_error (__FILE__
, __LINE__
, "read_sp: Unable to find SP");
1391 deprecated_write_sp (CORE_ADDR val
)
1393 gdb_assert (SP_REGNUM
>= 0);
1394 write_register (SP_REGNUM
, val
);
1398 deprecated_read_fp (void)
1400 if (DEPRECATED_TARGET_READ_FP_P ())
1401 return DEPRECATED_TARGET_READ_FP ();
1402 else if (DEPRECATED_FP_REGNUM
>= 0)
1403 return read_register (DEPRECATED_FP_REGNUM
);
1405 internal_error (__FILE__
, __LINE__
, "deprecated_read_fp");
1410 reg_flush_command (char *command
, int from_tty
)
1412 /* Force-flush the register cache. */
1413 registers_changed ();
1415 printf_filtered ("Register cache flushed.\n");
1419 build_regcache (void)
1421 current_regcache
= regcache_xmalloc (current_gdbarch
);
1422 current_regcache
->readonly_p
= 0;
1423 deprecated_registers
= deprecated_grub_regcache_for_registers (current_regcache
);
1424 deprecated_register_valid
= current_regcache
->register_valid_p
;
1428 dump_endian_bytes (struct ui_file
*file
, enum bfd_endian endian
,
1429 const unsigned char *buf
, long len
)
1434 case BFD_ENDIAN_BIG
:
1435 for (i
= 0; i
< len
; i
++)
1436 fprintf_unfiltered (file
, "%02x", buf
[i
]);
1438 case BFD_ENDIAN_LITTLE
:
1439 for (i
= len
- 1; i
>= 0; i
--)
1440 fprintf_unfiltered (file
, "%02x", buf
[i
]);
1443 internal_error (__FILE__
, __LINE__
, "Bad switch");
1447 enum regcache_dump_what
1449 regcache_dump_none
, regcache_dump_raw
, regcache_dump_cooked
, regcache_dump_groups
1453 regcache_dump (struct regcache
*regcache
, struct ui_file
*file
,
1454 enum regcache_dump_what what_to_dump
)
1456 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
1457 struct gdbarch
*gdbarch
= regcache
->descr
->gdbarch
;
1459 int footnote_nr
= 0;
1460 int footnote_register_size
= 0;
1461 int footnote_register_offset
= 0;
1462 int footnote_register_type_name_null
= 0;
1463 long register_offset
= 0;
1464 unsigned char buf
[MAX_REGISTER_SIZE
];
1467 fprintf_unfiltered (file
, "legacy_p %d\n", regcache
->descr
->legacy_p
);
1468 fprintf_unfiltered (file
, "nr_raw_registers %d\n",
1469 regcache
->descr
->nr_raw_registers
);
1470 fprintf_unfiltered (file
, "nr_cooked_registers %d\n",
1471 regcache
->descr
->nr_cooked_registers
);
1472 fprintf_unfiltered (file
, "sizeof_raw_registers %ld\n",
1473 regcache
->descr
->sizeof_raw_registers
);
1474 fprintf_unfiltered (file
, "sizeof_raw_register_valid_p %ld\n",
1475 regcache
->descr
->sizeof_raw_register_valid_p
);
1476 fprintf_unfiltered (file
, "NUM_REGS %d\n", NUM_REGS
);
1477 fprintf_unfiltered (file
, "NUM_PSEUDO_REGS %d\n", NUM_PSEUDO_REGS
);
1480 gdb_assert (regcache
->descr
->nr_cooked_registers
1481 == (NUM_REGS
+ NUM_PSEUDO_REGS
));
1483 for (regnum
= -1; regnum
< regcache
->descr
->nr_cooked_registers
; regnum
++)
1487 fprintf_unfiltered (file
, " %-10s", "Name");
1490 const char *p
= REGISTER_NAME (regnum
);
1493 else if (p
[0] == '\0')
1495 fprintf_unfiltered (file
, " %-10s", p
);
1500 fprintf_unfiltered (file
, " %4s", "Nr");
1502 fprintf_unfiltered (file
, " %4d", regnum
);
1504 /* Relative number. */
1506 fprintf_unfiltered (file
, " %4s", "Rel");
1507 else if (regnum
< NUM_REGS
)
1508 fprintf_unfiltered (file
, " %4d", regnum
);
1510 fprintf_unfiltered (file
, " %4d", (regnum
- NUM_REGS
));
1514 fprintf_unfiltered (file
, " %6s ", "Offset");
1517 fprintf_unfiltered (file
, " %6ld",
1518 regcache
->descr
->register_offset
[regnum
]);
1519 if (register_offset
!= regcache
->descr
->register_offset
[regnum
]
1520 || register_offset
!= REGISTER_BYTE (regnum
)
1522 && (regcache
->descr
->register_offset
[regnum
]
1523 != (regcache
->descr
->register_offset
[regnum
- 1]
1524 + regcache
->descr
->sizeof_register
[regnum
- 1])))
1527 if (!footnote_register_offset
)
1528 footnote_register_offset
= ++footnote_nr
;
1529 fprintf_unfiltered (file
, "*%d", footnote_register_offset
);
1532 fprintf_unfiltered (file
, " ");
1533 register_offset
= (regcache
->descr
->register_offset
[regnum
]
1534 + regcache
->descr
->sizeof_register
[regnum
]);
1539 fprintf_unfiltered (file
, " %5s ", "Size");
1542 fprintf_unfiltered (file
, " %5ld",
1543 regcache
->descr
->sizeof_register
[regnum
]);
1544 if ((regcache
->descr
->sizeof_register
[regnum
]
1545 != REGISTER_RAW_SIZE (regnum
))
1546 || (regcache
->descr
->sizeof_register
[regnum
]
1547 != REGISTER_VIRTUAL_SIZE (regnum
))
1548 || (regcache
->descr
->sizeof_register
[regnum
]
1549 != TYPE_LENGTH (register_type (regcache
->descr
->gdbarch
,
1553 if (!footnote_register_size
)
1554 footnote_register_size
= ++footnote_nr
;
1555 fprintf_unfiltered (file
, "*%d", footnote_register_size
);
1558 fprintf_unfiltered (file
, " ");
1568 static const char blt
[] = "builtin_type";
1569 t
= TYPE_NAME (register_type (regcache
->descr
->gdbarch
, regnum
));
1573 if (!footnote_register_type_name_null
)
1574 footnote_register_type_name_null
= ++footnote_nr
;
1575 xasprintf (&n
, "*%d", footnote_register_type_name_null
);
1576 make_cleanup (xfree
, n
);
1579 /* Chop a leading builtin_type. */
1580 if (strncmp (t
, blt
, strlen (blt
)) == 0)
1583 fprintf_unfiltered (file
, " %-15s", t
);
1586 /* Leading space always present. */
1587 fprintf_unfiltered (file
, " ");
1590 if (what_to_dump
== regcache_dump_raw
)
1593 fprintf_unfiltered (file
, "Raw value");
1594 else if (regnum
>= regcache
->descr
->nr_raw_registers
)
1595 fprintf_unfiltered (file
, "<cooked>");
1596 else if (!regcache_valid_p (regcache
, regnum
))
1597 fprintf_unfiltered (file
, "<invalid>");
1600 regcache_raw_read (regcache
, regnum
, buf
);
1601 fprintf_unfiltered (file
, "0x");
1602 dump_endian_bytes (file
, TARGET_BYTE_ORDER
, buf
,
1603 REGISTER_RAW_SIZE (regnum
));
1607 /* Value, cooked. */
1608 if (what_to_dump
== regcache_dump_cooked
)
1611 fprintf_unfiltered (file
, "Cooked value");
1614 regcache_cooked_read (regcache
, regnum
, buf
);
1615 fprintf_unfiltered (file
, "0x");
1616 dump_endian_bytes (file
, TARGET_BYTE_ORDER
, buf
,
1617 REGISTER_VIRTUAL_SIZE (regnum
));
1621 /* Group members. */
1622 if (what_to_dump
== regcache_dump_groups
)
1625 fprintf_unfiltered (file
, "Groups");
1628 const char *sep
= "";
1629 struct reggroup
*group
;
1630 for (group
= reggroup_next (gdbarch
, NULL
);
1632 group
= reggroup_next (gdbarch
, group
))
1634 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, group
))
1636 fprintf_unfiltered (file
, "%s%s", sep
, reggroup_name (group
));
1643 fprintf_unfiltered (file
, "\n");
1646 if (footnote_register_size
)
1647 fprintf_unfiltered (file
, "*%d: Inconsistent register sizes.\n",
1648 footnote_register_size
);
1649 if (footnote_register_offset
)
1650 fprintf_unfiltered (file
, "*%d: Inconsistent register offsets.\n",
1651 footnote_register_offset
);
1652 if (footnote_register_type_name_null
)
1653 fprintf_unfiltered (file
,
1654 "*%d: Register type's name NULL.\n",
1655 footnote_register_type_name_null
);
1656 do_cleanups (cleanups
);
1660 regcache_print (char *args
, enum regcache_dump_what what_to_dump
)
1663 regcache_dump (current_regcache
, gdb_stdout
, what_to_dump
);
1666 struct ui_file
*file
= gdb_fopen (args
, "w");
1668 perror_with_name ("maintenance print architecture");
1669 regcache_dump (current_regcache
, file
, what_to_dump
);
1670 ui_file_delete (file
);
1675 maintenance_print_registers (char *args
, int from_tty
)
1677 regcache_print (args
, regcache_dump_none
);
1681 maintenance_print_raw_registers (char *args
, int from_tty
)
1683 regcache_print (args
, regcache_dump_raw
);
1687 maintenance_print_cooked_registers (char *args
, int from_tty
)
1689 regcache_print (args
, regcache_dump_cooked
);
1693 maintenance_print_register_groups (char *args
, int from_tty
)
1695 regcache_print (args
, regcache_dump_groups
);
1698 extern initialize_file_ftype _initialize_regcache
; /* -Wmissing-prototype */
1701 _initialize_regcache (void)
1703 regcache_descr_handle
= register_gdbarch_data (init_regcache_descr
);
1704 REGISTER_GDBARCH_SWAP (current_regcache
);
1705 register_gdbarch_swap (&deprecated_registers
, sizeof (deprecated_registers
), NULL
);
1706 register_gdbarch_swap (&deprecated_register_valid
, sizeof (deprecated_register_valid
), NULL
);
1707 register_gdbarch_swap (NULL
, 0, build_regcache
);
1709 add_com ("flushregs", class_maintenance
, reg_flush_command
,
1710 "Force gdb to flush its register cache (maintainer command)");
1712 /* Initialize the thread/process associated with the current set of
1713 registers. For now, -1 is special, and means `no current process'. */
1714 registers_ptid
= pid_to_ptid (-1);
1716 add_cmd ("registers", class_maintenance
,
1717 maintenance_print_registers
,
1718 "Print the internal register configuration.\
1719 Takes an optional file parameter.",
1720 &maintenanceprintlist
);
1721 add_cmd ("raw-registers", class_maintenance
,
1722 maintenance_print_raw_registers
,
1723 "Print the internal register configuration including raw values.\
1724 Takes an optional file parameter.",
1725 &maintenanceprintlist
);
1726 add_cmd ("cooked-registers", class_maintenance
,
1727 maintenance_print_cooked_registers
,
1728 "Print the internal register configuration including cooked values.\
1729 Takes an optional file parameter.",
1730 &maintenanceprintlist
);
1731 add_cmd ("register-groups", class_maintenance
,
1732 maintenance_print_register_groups
,
1733 "Print the internal register configuration including each register's group.\
1734 Takes an optional file parameter.",
1735 &maintenanceprintlist
);