Add two callback data casts
[deliverable/binutils-gdb.git] / gdb / regcache.c
... / ...
CommitLineData
1/* Cache and manage the values of registers for GDB, the GNU debugger.
2
3 Copyright (C) 1986-2015 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20#include "defs.h"
21#include "inferior.h"
22#include "target.h"
23#include "gdbarch.h"
24#include "gdbcmd.h"
25#include "regcache.h"
26#include "reggroups.h"
27#include "observer.h"
28#include "remote.h"
29#include "valprint.h"
30#include "regset.h"
31
32/*
33 * DATA STRUCTURE
34 *
35 * Here is the actual register cache.
36 */
37
38/* Per-architecture object describing the layout of a register cache.
39 Computed once when the architecture is created. */
40
41struct gdbarch_data *regcache_descr_handle;
42
43struct regcache_descr
44{
45 /* The architecture this descriptor belongs to. */
46 struct gdbarch *gdbarch;
47
48 /* The raw register cache. Each raw (or hard) register is supplied
49 by the target interface. The raw cache should not contain
50 redundant information - if the PC is constructed from two
51 registers then those registers and not the PC lives in the raw
52 cache. */
53 int nr_raw_registers;
54 long sizeof_raw_registers;
55 long sizeof_raw_register_status;
56
57 /* The cooked register space. Each cooked register in the range
58 [0..NR_RAW_REGISTERS) is direct-mapped onto the corresponding raw
59 register. The remaining [NR_RAW_REGISTERS
60 .. NR_COOKED_REGISTERS) (a.k.a. pseudo registers) are mapped onto
61 both raw registers and memory by the architecture methods
62 gdbarch_pseudo_register_read and gdbarch_pseudo_register_write. */
63 int nr_cooked_registers;
64 long sizeof_cooked_registers;
65 long sizeof_cooked_register_status;
66
67 /* Offset and size (in 8 bit bytes), of each register in the
68 register cache. All registers (including those in the range
69 [NR_RAW_REGISTERS .. NR_COOKED_REGISTERS) are given an
70 offset. */
71 long *register_offset;
72 long *sizeof_register;
73
74 /* Cached table containing the type of each register. */
75 struct type **register_type;
76};
77
78static void *
79init_regcache_descr (struct gdbarch *gdbarch)
80{
81 int i;
82 struct regcache_descr *descr;
83 gdb_assert (gdbarch != NULL);
84
85 /* Create an initial, zero filled, table. */
86 descr = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct regcache_descr);
87 descr->gdbarch = gdbarch;
88
89 /* Total size of the register space. The raw registers are mapped
90 directly onto the raw register cache while the pseudo's are
91 either mapped onto raw-registers or memory. */
92 descr->nr_cooked_registers = gdbarch_num_regs (gdbarch)
93 + gdbarch_num_pseudo_regs (gdbarch);
94 descr->sizeof_cooked_register_status
95 = gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch);
96
97 /* Fill in a table of register types. */
98 descr->register_type
99 = GDBARCH_OBSTACK_CALLOC (gdbarch, descr->nr_cooked_registers,
100 struct type *);
101 for (i = 0; i < descr->nr_cooked_registers; i++)
102 descr->register_type[i] = gdbarch_register_type (gdbarch, i);
103
104 /* Construct a strictly RAW register cache. Don't allow pseudo's
105 into the register cache. */
106 descr->nr_raw_registers = gdbarch_num_regs (gdbarch);
107 descr->sizeof_raw_register_status = gdbarch_num_regs (gdbarch);
108
109 /* Lay out the register cache.
110
111 NOTE: cagney/2002-05-22: Only register_type() is used when
112 constructing the register cache. It is assumed that the
113 register's raw size, virtual size and type length are all the
114 same. */
115
116 {
117 long offset = 0;
118
119 descr->sizeof_register
120 = GDBARCH_OBSTACK_CALLOC (gdbarch, descr->nr_cooked_registers, long);
121 descr->register_offset
122 = GDBARCH_OBSTACK_CALLOC (gdbarch, descr->nr_cooked_registers, long);
123 for (i = 0; i < descr->nr_raw_registers; i++)
124 {
125 descr->sizeof_register[i] = TYPE_LENGTH (descr->register_type[i]);
126 descr->register_offset[i] = offset;
127 offset += descr->sizeof_register[i];
128 gdb_assert (MAX_REGISTER_SIZE >= descr->sizeof_register[i]);
129 }
130 /* Set the real size of the raw register cache buffer. */
131 descr->sizeof_raw_registers = offset;
132
133 for (; i < descr->nr_cooked_registers; i++)
134 {
135 descr->sizeof_register[i] = TYPE_LENGTH (descr->register_type[i]);
136 descr->register_offset[i] = offset;
137 offset += descr->sizeof_register[i];
138 gdb_assert (MAX_REGISTER_SIZE >= descr->sizeof_register[i]);
139 }
140 /* Set the real size of the readonly register cache buffer. */
141 descr->sizeof_cooked_registers = offset;
142 }
143
144 return descr;
145}
146
147static struct regcache_descr *
148regcache_descr (struct gdbarch *gdbarch)
149{
150 return (struct regcache_descr *) gdbarch_data (gdbarch,
151 regcache_descr_handle);
152}
153
154/* Utility functions returning useful register attributes stored in
155 the regcache descr. */
156
157struct type *
158register_type (struct gdbarch *gdbarch, int regnum)
159{
160 struct regcache_descr *descr = regcache_descr (gdbarch);
161
162 gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
163 return descr->register_type[regnum];
164}
165
166/* Utility functions returning useful register attributes stored in
167 the regcache descr. */
168
169int
170register_size (struct gdbarch *gdbarch, int regnum)
171{
172 struct regcache_descr *descr = regcache_descr (gdbarch);
173 int size;
174
175 gdb_assert (regnum >= 0
176 && regnum < (gdbarch_num_regs (gdbarch)
177 + gdbarch_num_pseudo_regs (gdbarch)));
178 size = descr->sizeof_register[regnum];
179 return size;
180}
181
182/* The register cache for storing raw register values. */
183
184struct regcache
185{
186 struct regcache_descr *descr;
187
188 /* The address space of this register cache (for registers where it
189 makes sense, like PC or SP). */
190 struct address_space *aspace;
191
192 /* The register buffers. A read-only register cache can hold the
193 full [0 .. gdbarch_num_regs + gdbarch_num_pseudo_regs) while a read/write
194 register cache can only hold [0 .. gdbarch_num_regs). */
195 gdb_byte *registers;
196 /* Register cache status. */
197 signed char *register_status;
198 /* Is this a read-only cache? A read-only cache is used for saving
199 the target's register state (e.g, across an inferior function
200 call or just before forcing a function return). A read-only
201 cache can only be updated via the methods regcache_dup() and
202 regcache_cpy(). The actual contents are determined by the
203 reggroup_save and reggroup_restore methods. */
204 int readonly_p;
205 /* If this is a read-write cache, which thread's registers is
206 it connected to? */
207 ptid_t ptid;
208};
209
210static struct regcache *
211regcache_xmalloc_1 (struct gdbarch *gdbarch, struct address_space *aspace,
212 int readonly_p)
213{
214 struct regcache_descr *descr;
215 struct regcache *regcache;
216
217 gdb_assert (gdbarch != NULL);
218 descr = regcache_descr (gdbarch);
219 regcache = XNEW (struct regcache);
220 regcache->descr = descr;
221 regcache->readonly_p = readonly_p;
222 if (readonly_p)
223 {
224 regcache->registers
225 = XCNEWVEC (gdb_byte, descr->sizeof_cooked_registers);
226 regcache->register_status
227 = XCNEWVEC (signed char, descr->sizeof_cooked_register_status);
228 }
229 else
230 {
231 regcache->registers
232 = XCNEWVEC (gdb_byte, descr->sizeof_raw_registers);
233 regcache->register_status
234 = XCNEWVEC (signed char, descr->sizeof_raw_register_status);
235 }
236 regcache->aspace = aspace;
237 regcache->ptid = minus_one_ptid;
238 return regcache;
239}
240
241struct regcache *
242regcache_xmalloc (struct gdbarch *gdbarch, struct address_space *aspace)
243{
244 return regcache_xmalloc_1 (gdbarch, aspace, 1);
245}
246
247void
248regcache_xfree (struct regcache *regcache)
249{
250 if (regcache == NULL)
251 return;
252 xfree (regcache->registers);
253 xfree (regcache->register_status);
254 xfree (regcache);
255}
256
257static void
258do_regcache_xfree (void *data)
259{
260 regcache_xfree ((struct regcache *) data);
261}
262
263struct cleanup *
264make_cleanup_regcache_xfree (struct regcache *regcache)
265{
266 return make_cleanup (do_regcache_xfree, regcache);
267}
268
269/* Cleanup routines for invalidating a register. */
270
271struct register_to_invalidate
272{
273 struct regcache *regcache;
274 int regnum;
275};
276
277static void
278do_regcache_invalidate (void *data)
279{
280 struct register_to_invalidate *reg = (struct register_to_invalidate *) data;
281
282 regcache_invalidate (reg->regcache, reg->regnum);
283}
284
285static struct cleanup *
286make_cleanup_regcache_invalidate (struct regcache *regcache, int regnum)
287{
288 struct register_to_invalidate* reg = XNEW (struct register_to_invalidate);
289
290 reg->regcache = regcache;
291 reg->regnum = regnum;
292 return make_cleanup_dtor (do_regcache_invalidate, (void *) reg, xfree);
293}
294
295/* Return REGCACHE's architecture. */
296
297struct gdbarch *
298get_regcache_arch (const struct regcache *regcache)
299{
300 return regcache->descr->gdbarch;
301}
302
303struct address_space *
304get_regcache_aspace (const struct regcache *regcache)
305{
306 return regcache->aspace;
307}
308
309/* Return a pointer to register REGNUM's buffer cache. */
310
311static gdb_byte *
312register_buffer (const struct regcache *regcache, int regnum)
313{
314 return regcache->registers + regcache->descr->register_offset[regnum];
315}
316
317void
318regcache_save (struct regcache *dst, regcache_cooked_read_ftype *cooked_read,
319 void *src)
320{
321 struct gdbarch *gdbarch = dst->descr->gdbarch;
322 gdb_byte buf[MAX_REGISTER_SIZE];
323 int regnum;
324
325 /* The DST should be `read-only', if it wasn't then the save would
326 end up trying to write the register values back out to the
327 target. */
328 gdb_assert (dst->readonly_p);
329 /* Clear the dest. */
330 memset (dst->registers, 0, dst->descr->sizeof_cooked_registers);
331 memset (dst->register_status, 0,
332 dst->descr->sizeof_cooked_register_status);
333 /* Copy over any registers (identified by their membership in the
334 save_reggroup) and mark them as valid. The full [0 .. gdbarch_num_regs +
335 gdbarch_num_pseudo_regs) range is checked since some architectures need
336 to save/restore `cooked' registers that live in memory. */
337 for (regnum = 0; regnum < dst->descr->nr_cooked_registers; regnum++)
338 {
339 if (gdbarch_register_reggroup_p (gdbarch, regnum, save_reggroup))
340 {
341 enum register_status status = cooked_read (src, regnum, buf);
342
343 if (status == REG_VALID)
344 memcpy (register_buffer (dst, regnum), buf,
345 register_size (gdbarch, regnum));
346 else
347 {
348 gdb_assert (status != REG_UNKNOWN);
349
350 memset (register_buffer (dst, regnum), 0,
351 register_size (gdbarch, regnum));
352 }
353 dst->register_status[regnum] = status;
354 }
355 }
356}
357
358static void
359regcache_restore (struct regcache *dst,
360 regcache_cooked_read_ftype *cooked_read,
361 void *cooked_read_context)
362{
363 struct gdbarch *gdbarch = dst->descr->gdbarch;
364 gdb_byte buf[MAX_REGISTER_SIZE];
365 int regnum;
366
367 /* The dst had better not be read-only. If it is, the `restore'
368 doesn't make much sense. */
369 gdb_assert (!dst->readonly_p);
370 /* Copy over any registers, being careful to only restore those that
371 were both saved and need to be restored. The full [0 .. gdbarch_num_regs
372 + gdbarch_num_pseudo_regs) range is checked since some architectures need
373 to save/restore `cooked' registers that live in memory. */
374 for (regnum = 0; regnum < dst->descr->nr_cooked_registers; regnum++)
375 {
376 if (gdbarch_register_reggroup_p (gdbarch, regnum, restore_reggroup))
377 {
378 enum register_status status;
379
380 status = cooked_read (cooked_read_context, regnum, buf);
381 if (status == REG_VALID)
382 regcache_cooked_write (dst, regnum, buf);
383 }
384 }
385}
386
387static enum register_status
388do_cooked_read (void *src, int regnum, gdb_byte *buf)
389{
390 struct regcache *regcache = (struct regcache *) src;
391
392 return regcache_cooked_read (regcache, regnum, buf);
393}
394
395static void regcache_cpy_no_passthrough (struct regcache *dst,
396 struct regcache *src);
397
398void
399regcache_cpy (struct regcache *dst, struct regcache *src)
400{
401 gdb_assert (src != NULL && dst != NULL);
402 gdb_assert (src->descr->gdbarch == dst->descr->gdbarch);
403 gdb_assert (src != dst);
404 gdb_assert (src->readonly_p || dst->readonly_p);
405
406 if (!src->readonly_p)
407 regcache_save (dst, do_cooked_read, src);
408 else if (!dst->readonly_p)
409 regcache_restore (dst, do_cooked_read, src);
410 else
411 regcache_cpy_no_passthrough (dst, src);
412}
413
414/* Copy/duplicate the contents of a register cache. Unlike regcache_cpy,
415 which is pass-through, this does not go through to the target.
416 Only values values already in the cache are transferred. The SRC and DST
417 buffers must not overlap. */
418
419static void
420regcache_cpy_no_passthrough (struct regcache *dst, struct regcache *src)
421{
422 gdb_assert (src != NULL && dst != NULL);
423 gdb_assert (src->descr->gdbarch == dst->descr->gdbarch);
424 /* NOTE: cagney/2002-05-17: Don't let the caller do a no-passthrough
425 move of data into a thread's regcache. Doing this would be silly
426 - it would mean that regcache->register_status would be
427 completely invalid. */
428 gdb_assert (dst->readonly_p && src->readonly_p);
429
430 memcpy (dst->registers, src->registers,
431 dst->descr->sizeof_cooked_registers);
432 memcpy (dst->register_status, src->register_status,
433 dst->descr->sizeof_cooked_register_status);
434}
435
436struct regcache *
437regcache_dup (struct regcache *src)
438{
439 struct regcache *newbuf;
440
441 newbuf = regcache_xmalloc (src->descr->gdbarch, get_regcache_aspace (src));
442 regcache_cpy (newbuf, src);
443 return newbuf;
444}
445
446enum register_status
447regcache_register_status (const struct regcache *regcache, int regnum)
448{
449 gdb_assert (regcache != NULL);
450 gdb_assert (regnum >= 0);
451 if (regcache->readonly_p)
452 gdb_assert (regnum < regcache->descr->nr_cooked_registers);
453 else
454 gdb_assert (regnum < regcache->descr->nr_raw_registers);
455
456 return (enum register_status) regcache->register_status[regnum];
457}
458
459void
460regcache_invalidate (struct regcache *regcache, int regnum)
461{
462 gdb_assert (regcache != NULL);
463 gdb_assert (regnum >= 0);
464 gdb_assert (!regcache->readonly_p);
465 gdb_assert (regnum < regcache->descr->nr_raw_registers);
466 regcache->register_status[regnum] = REG_UNKNOWN;
467}
468
469
470/* Global structure containing the current regcache. */
471
472/* NOTE: this is a write-through cache. There is no "dirty" bit for
473 recording if the register values have been changed (eg. by the
474 user). Therefore all registers must be written back to the
475 target when appropriate. */
476
477struct regcache_list
478{
479 struct regcache *regcache;
480 struct regcache_list *next;
481};
482
483static struct regcache_list *current_regcache;
484
485struct regcache *
486get_thread_arch_aspace_regcache (ptid_t ptid, struct gdbarch *gdbarch,
487 struct address_space *aspace)
488{
489 struct regcache_list *list;
490 struct regcache *new_regcache;
491
492 for (list = current_regcache; list; list = list->next)
493 if (ptid_equal (list->regcache->ptid, ptid)
494 && get_regcache_arch (list->regcache) == gdbarch)
495 return list->regcache;
496
497 new_regcache = regcache_xmalloc_1 (gdbarch, aspace, 0);
498 new_regcache->ptid = ptid;
499
500 list = XNEW (struct regcache_list);
501 list->regcache = new_regcache;
502 list->next = current_regcache;
503 current_regcache = list;
504
505 return new_regcache;
506}
507
508struct regcache *
509get_thread_arch_regcache (ptid_t ptid, struct gdbarch *gdbarch)
510{
511 struct address_space *aspace;
512
513 /* For the benefit of "maint print registers" & co when debugging an
514 executable, allow dumping the regcache even when there is no
515 thread selected (target_thread_address_space internal-errors if
516 no address space is found). Note that normal user commands will
517 fail higher up on the call stack due to no
518 target_has_registers. */
519 aspace = (ptid_equal (null_ptid, ptid)
520 ? NULL
521 : target_thread_address_space (ptid));
522
523 return get_thread_arch_aspace_regcache (ptid, gdbarch, aspace);
524}
525
526static ptid_t current_thread_ptid;
527static struct gdbarch *current_thread_arch;
528
529struct regcache *
530get_thread_regcache (ptid_t ptid)
531{
532 if (!current_thread_arch || !ptid_equal (current_thread_ptid, ptid))
533 {
534 current_thread_ptid = ptid;
535 current_thread_arch = target_thread_architecture (ptid);
536 }
537
538 return get_thread_arch_regcache (ptid, current_thread_arch);
539}
540
541struct regcache *
542get_current_regcache (void)
543{
544 return get_thread_regcache (inferior_ptid);
545}
546
547/* See common/common-regcache.h. */
548
549struct regcache *
550get_thread_regcache_for_ptid (ptid_t ptid)
551{
552 return get_thread_regcache (ptid);
553}
554
555/* Observer for the target_changed event. */
556
557static void
558regcache_observer_target_changed (struct target_ops *target)
559{
560 registers_changed ();
561}
562
563/* Update global variables old ptids to hold NEW_PTID if they were
564 holding OLD_PTID. */
565static void
566regcache_thread_ptid_changed (ptid_t old_ptid, ptid_t new_ptid)
567{
568 struct regcache_list *list;
569
570 for (list = current_regcache; list; list = list->next)
571 if (ptid_equal (list->regcache->ptid, old_ptid))
572 list->regcache->ptid = new_ptid;
573}
574
575/* Low level examining and depositing of registers.
576
577 The caller is responsible for making sure that the inferior is
578 stopped before calling the fetching routines, or it will get
579 garbage. (a change from GDB version 3, in which the caller got the
580 value from the last stop). */
581
582/* REGISTERS_CHANGED ()
583
584 Indicate that registers may have changed, so invalidate the cache. */
585
586void
587registers_changed_ptid (ptid_t ptid)
588{
589 struct regcache_list *list, **list_link;
590
591 list = current_regcache;
592 list_link = &current_regcache;
593 while (list)
594 {
595 if (ptid_match (list->regcache->ptid, ptid))
596 {
597 struct regcache_list *dead = list;
598
599 *list_link = list->next;
600 regcache_xfree (list->regcache);
601 list = *list_link;
602 xfree (dead);
603 continue;
604 }
605
606 list_link = &list->next;
607 list = *list_link;
608 }
609
610 if (ptid_match (current_thread_ptid, ptid))
611 {
612 current_thread_ptid = null_ptid;
613 current_thread_arch = NULL;
614 }
615
616 if (ptid_match (inferior_ptid, ptid))
617 {
618 /* We just deleted the regcache of the current thread. Need to
619 forget about any frames we have cached, too. */
620 reinit_frame_cache ();
621 }
622}
623
624void
625registers_changed (void)
626{
627 registers_changed_ptid (minus_one_ptid);
628
629 /* Force cleanup of any alloca areas if using C alloca instead of
630 a builtin alloca. This particular call is used to clean up
631 areas allocated by low level target code which may build up
632 during lengthy interactions between gdb and the target before
633 gdb gives control to the user (ie watchpoints). */
634 alloca (0);
635}
636
637enum register_status
638regcache_raw_read (struct regcache *regcache, int regnum, gdb_byte *buf)
639{
640 gdb_assert (regcache != NULL && buf != NULL);
641 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
642 /* Make certain that the register cache is up-to-date with respect
643 to the current thread. This switching shouldn't be necessary
644 only there is still only one target side register cache. Sigh!
645 On the bright side, at least there is a regcache object. */
646 if (!regcache->readonly_p
647 && regcache_register_status (regcache, regnum) == REG_UNKNOWN)
648 {
649 struct cleanup *old_chain = save_inferior_ptid ();
650
651 inferior_ptid = regcache->ptid;
652 target_fetch_registers (regcache, regnum);
653 do_cleanups (old_chain);
654
655 /* A number of targets can't access the whole set of raw
656 registers (because the debug API provides no means to get at
657 them). */
658 if (regcache->register_status[regnum] == REG_UNKNOWN)
659 regcache->register_status[regnum] = REG_UNAVAILABLE;
660 }
661
662 if (regcache->register_status[regnum] != REG_VALID)
663 memset (buf, 0, regcache->descr->sizeof_register[regnum]);
664 else
665 memcpy (buf, register_buffer (regcache, regnum),
666 regcache->descr->sizeof_register[regnum]);
667
668 return (enum register_status) regcache->register_status[regnum];
669}
670
671enum register_status
672regcache_raw_read_signed (struct regcache *regcache, int regnum, LONGEST *val)
673{
674 gdb_byte *buf;
675 enum register_status status;
676
677 gdb_assert (regcache != NULL);
678 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
679 buf = (gdb_byte *) alloca (regcache->descr->sizeof_register[regnum]);
680 status = regcache_raw_read (regcache, regnum, buf);
681 if (status == REG_VALID)
682 *val = extract_signed_integer
683 (buf, regcache->descr->sizeof_register[regnum],
684 gdbarch_byte_order (regcache->descr->gdbarch));
685 else
686 *val = 0;
687 return status;
688}
689
690enum register_status
691regcache_raw_read_unsigned (struct regcache *regcache, int regnum,
692 ULONGEST *val)
693{
694 gdb_byte *buf;
695 enum register_status status;
696
697 gdb_assert (regcache != NULL);
698 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
699 buf = (gdb_byte *) alloca (regcache->descr->sizeof_register[regnum]);
700 status = regcache_raw_read (regcache, regnum, buf);
701 if (status == REG_VALID)
702 *val = extract_unsigned_integer
703 (buf, regcache->descr->sizeof_register[regnum],
704 gdbarch_byte_order (regcache->descr->gdbarch));
705 else
706 *val = 0;
707 return status;
708}
709
710void
711regcache_raw_write_signed (struct regcache *regcache, int regnum, LONGEST val)
712{
713 void *buf;
714
715 gdb_assert (regcache != NULL);
716 gdb_assert (regnum >=0 && regnum < regcache->descr->nr_raw_registers);
717 buf = alloca (regcache->descr->sizeof_register[regnum]);
718 store_signed_integer (buf, regcache->descr->sizeof_register[regnum],
719 gdbarch_byte_order (regcache->descr->gdbarch), val);
720 regcache_raw_write (regcache, regnum, buf);
721}
722
723void
724regcache_raw_write_unsigned (struct regcache *regcache, int regnum,
725 ULONGEST val)
726{
727 void *buf;
728
729 gdb_assert (regcache != NULL);
730 gdb_assert (regnum >=0 && regnum < regcache->descr->nr_raw_registers);
731 buf = alloca (regcache->descr->sizeof_register[regnum]);
732 store_unsigned_integer (buf, regcache->descr->sizeof_register[regnum],
733 gdbarch_byte_order (regcache->descr->gdbarch), val);
734 regcache_raw_write (regcache, regnum, buf);
735}
736
737enum register_status
738regcache_cooked_read (struct regcache *regcache, int regnum, gdb_byte *buf)
739{
740 gdb_assert (regnum >= 0);
741 gdb_assert (regnum < regcache->descr->nr_cooked_registers);
742 if (regnum < regcache->descr->nr_raw_registers)
743 return regcache_raw_read (regcache, regnum, buf);
744 else if (regcache->readonly_p
745 && regcache->register_status[regnum] != REG_UNKNOWN)
746 {
747 /* Read-only register cache, perhaps the cooked value was
748 cached? */
749 if (regcache->register_status[regnum] == REG_VALID)
750 memcpy (buf, register_buffer (regcache, regnum),
751 regcache->descr->sizeof_register[regnum]);
752 else
753 memset (buf, 0, regcache->descr->sizeof_register[regnum]);
754
755 return (enum register_status) regcache->register_status[regnum];
756 }
757 else if (gdbarch_pseudo_register_read_value_p (regcache->descr->gdbarch))
758 {
759 struct value *mark, *computed;
760 enum register_status result = REG_VALID;
761
762 mark = value_mark ();
763
764 computed = gdbarch_pseudo_register_read_value (regcache->descr->gdbarch,
765 regcache, regnum);
766 if (value_entirely_available (computed))
767 memcpy (buf, value_contents_raw (computed),
768 regcache->descr->sizeof_register[regnum]);
769 else
770 {
771 memset (buf, 0, regcache->descr->sizeof_register[regnum]);
772 result = REG_UNAVAILABLE;
773 }
774
775 value_free_to_mark (mark);
776
777 return result;
778 }
779 else
780 return gdbarch_pseudo_register_read (regcache->descr->gdbarch, regcache,
781 regnum, buf);
782}
783
784struct value *
785regcache_cooked_read_value (struct regcache *regcache, int regnum)
786{
787 gdb_assert (regnum >= 0);
788 gdb_assert (regnum < regcache->descr->nr_cooked_registers);
789
790 if (regnum < regcache->descr->nr_raw_registers
791 || (regcache->readonly_p
792 && regcache->register_status[regnum] != REG_UNKNOWN)
793 || !gdbarch_pseudo_register_read_value_p (regcache->descr->gdbarch))
794 {
795 struct value *result;
796
797 result = allocate_value (register_type (regcache->descr->gdbarch,
798 regnum));
799 VALUE_LVAL (result) = lval_register;
800 VALUE_REGNUM (result) = regnum;
801
802 /* It is more efficient in general to do this delegation in this
803 direction than in the other one, even though the value-based
804 API is preferred. */
805 if (regcache_cooked_read (regcache, regnum,
806 value_contents_raw (result)) == REG_UNAVAILABLE)
807 mark_value_bytes_unavailable (result, 0,
808 TYPE_LENGTH (value_type (result)));
809
810 return result;
811 }
812 else
813 return gdbarch_pseudo_register_read_value (regcache->descr->gdbarch,
814 regcache, regnum);
815}
816
817enum register_status
818regcache_cooked_read_signed (struct regcache *regcache, int regnum,
819 LONGEST *val)
820{
821 enum register_status status;
822 gdb_byte *buf;
823
824 gdb_assert (regcache != NULL);
825 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_cooked_registers);
826 buf = (gdb_byte *) alloca (regcache->descr->sizeof_register[regnum]);
827 status = regcache_cooked_read (regcache, regnum, buf);
828 if (status == REG_VALID)
829 *val = extract_signed_integer
830 (buf, regcache->descr->sizeof_register[regnum],
831 gdbarch_byte_order (regcache->descr->gdbarch));
832 else
833 *val = 0;
834 return status;
835}
836
837enum register_status
838regcache_cooked_read_unsigned (struct regcache *regcache, int regnum,
839 ULONGEST *val)
840{
841 enum register_status status;
842 gdb_byte *buf;
843
844 gdb_assert (regcache != NULL);
845 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_cooked_registers);
846 buf = (gdb_byte *) alloca (regcache->descr->sizeof_register[regnum]);
847 status = regcache_cooked_read (regcache, regnum, buf);
848 if (status == REG_VALID)
849 *val = extract_unsigned_integer
850 (buf, regcache->descr->sizeof_register[regnum],
851 gdbarch_byte_order (regcache->descr->gdbarch));
852 else
853 *val = 0;
854 return status;
855}
856
857void
858regcache_cooked_write_signed (struct regcache *regcache, int regnum,
859 LONGEST val)
860{
861 void *buf;
862
863 gdb_assert (regcache != NULL);
864 gdb_assert (regnum >=0 && regnum < regcache->descr->nr_cooked_registers);
865 buf = alloca (regcache->descr->sizeof_register[regnum]);
866 store_signed_integer (buf, regcache->descr->sizeof_register[regnum],
867 gdbarch_byte_order (regcache->descr->gdbarch), val);
868 regcache_cooked_write (regcache, regnum, buf);
869}
870
871void
872regcache_cooked_write_unsigned (struct regcache *regcache, int regnum,
873 ULONGEST val)
874{
875 void *buf;
876
877 gdb_assert (regcache != NULL);
878 gdb_assert (regnum >=0 && regnum < regcache->descr->nr_cooked_registers);
879 buf = alloca (regcache->descr->sizeof_register[regnum]);
880 store_unsigned_integer (buf, regcache->descr->sizeof_register[regnum],
881 gdbarch_byte_order (regcache->descr->gdbarch), val);
882 regcache_cooked_write (regcache, regnum, buf);
883}
884
885void
886regcache_raw_write (struct regcache *regcache, int regnum,
887 const gdb_byte *buf)
888{
889 struct cleanup *chain_before_save_inferior;
890 struct cleanup *chain_before_invalidate_register;
891
892 gdb_assert (regcache != NULL && buf != NULL);
893 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
894 gdb_assert (!regcache->readonly_p);
895
896 /* On the sparc, writing %g0 is a no-op, so we don't even want to
897 change the registers array if something writes to this register. */
898 if (gdbarch_cannot_store_register (get_regcache_arch (regcache), regnum))
899 return;
900
901 /* If we have a valid copy of the register, and new value == old
902 value, then don't bother doing the actual store. */
903 if (regcache_register_status (regcache, regnum) == REG_VALID
904 && (memcmp (register_buffer (regcache, regnum), buf,
905 regcache->descr->sizeof_register[regnum]) == 0))
906 return;
907
908 chain_before_save_inferior = save_inferior_ptid ();
909 inferior_ptid = regcache->ptid;
910
911 target_prepare_to_store (regcache);
912 memcpy (register_buffer (regcache, regnum), buf,
913 regcache->descr->sizeof_register[regnum]);
914 regcache->register_status[regnum] = REG_VALID;
915
916 /* Register a cleanup function for invalidating the register after it is
917 written, in case of a failure. */
918 chain_before_invalidate_register
919 = make_cleanup_regcache_invalidate (regcache, regnum);
920
921 target_store_registers (regcache, regnum);
922
923 /* The target did not throw an error so we can discard invalidating the
924 register and restore the cleanup chain to what it was. */
925 discard_cleanups (chain_before_invalidate_register);
926
927 do_cleanups (chain_before_save_inferior);
928}
929
930void
931regcache_cooked_write (struct regcache *regcache, int regnum,
932 const gdb_byte *buf)
933{
934 gdb_assert (regnum >= 0);
935 gdb_assert (regnum < regcache->descr->nr_cooked_registers);
936 if (regnum < regcache->descr->nr_raw_registers)
937 regcache_raw_write (regcache, regnum, buf);
938 else
939 gdbarch_pseudo_register_write (regcache->descr->gdbarch, regcache,
940 regnum, buf);
941}
942
943/* Perform a partial register transfer using a read, modify, write
944 operation. */
945
946typedef void (regcache_read_ftype) (struct regcache *regcache, int regnum,
947 void *buf);
948typedef void (regcache_write_ftype) (struct regcache *regcache, int regnum,
949 const void *buf);
950
951static enum register_status
952regcache_xfer_part (struct regcache *regcache, int regnum,
953 int offset, int len, void *in, const void *out,
954 enum register_status (*read) (struct regcache *regcache,
955 int regnum,
956 gdb_byte *buf),
957 void (*write) (struct regcache *regcache, int regnum,
958 const gdb_byte *buf))
959{
960 struct regcache_descr *descr = regcache->descr;
961 gdb_byte reg[MAX_REGISTER_SIZE];
962
963 gdb_assert (offset >= 0 && offset <= descr->sizeof_register[regnum]);
964 gdb_assert (len >= 0 && offset + len <= descr->sizeof_register[regnum]);
965 /* Something to do? */
966 if (offset + len == 0)
967 return REG_VALID;
968 /* Read (when needed) ... */
969 if (in != NULL
970 || offset > 0
971 || offset + len < descr->sizeof_register[regnum])
972 {
973 enum register_status status;
974
975 gdb_assert (read != NULL);
976 status = read (regcache, regnum, reg);
977 if (status != REG_VALID)
978 return status;
979 }
980 /* ... modify ... */
981 if (in != NULL)
982 memcpy (in, reg + offset, len);
983 if (out != NULL)
984 memcpy (reg + offset, out, len);
985 /* ... write (when needed). */
986 if (out != NULL)
987 {
988 gdb_assert (write != NULL);
989 write (regcache, regnum, reg);
990 }
991
992 return REG_VALID;
993}
994
995enum register_status
996regcache_raw_read_part (struct regcache *regcache, int regnum,
997 int offset, int len, gdb_byte *buf)
998{
999 struct regcache_descr *descr = regcache->descr;
1000
1001 gdb_assert (regnum >= 0 && regnum < descr->nr_raw_registers);
1002 return regcache_xfer_part (regcache, regnum, offset, len, buf, NULL,
1003 regcache_raw_read, regcache_raw_write);
1004}
1005
1006void
1007regcache_raw_write_part (struct regcache *regcache, int regnum,
1008 int offset, int len, const gdb_byte *buf)
1009{
1010 struct regcache_descr *descr = regcache->descr;
1011
1012 gdb_assert (regnum >= 0 && regnum < descr->nr_raw_registers);
1013 regcache_xfer_part (regcache, regnum, offset, len, NULL, buf,
1014 regcache_raw_read, regcache_raw_write);
1015}
1016
1017enum register_status
1018regcache_cooked_read_part (struct regcache *regcache, int regnum,
1019 int offset, int len, gdb_byte *buf)
1020{
1021 struct regcache_descr *descr = regcache->descr;
1022
1023 gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
1024 return regcache_xfer_part (regcache, regnum, offset, len, buf, NULL,
1025 regcache_cooked_read, regcache_cooked_write);
1026}
1027
1028void
1029regcache_cooked_write_part (struct regcache *regcache, int regnum,
1030 int offset, int len, const gdb_byte *buf)
1031{
1032 struct regcache_descr *descr = regcache->descr;
1033
1034 gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
1035 regcache_xfer_part (regcache, regnum, offset, len, NULL, buf,
1036 regcache_cooked_read, regcache_cooked_write);
1037}
1038
1039/* Supply register REGNUM, whose contents are stored in BUF, to REGCACHE. */
1040
1041void
1042regcache_raw_supply (struct regcache *regcache, int regnum, const void *buf)
1043{
1044 void *regbuf;
1045 size_t size;
1046
1047 gdb_assert (regcache != NULL);
1048 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
1049 gdb_assert (!regcache->readonly_p);
1050
1051 regbuf = register_buffer (regcache, regnum);
1052 size = regcache->descr->sizeof_register[regnum];
1053
1054 if (buf)
1055 {
1056 memcpy (regbuf, buf, size);
1057 regcache->register_status[regnum] = REG_VALID;
1058 }
1059 else
1060 {
1061 /* This memset not strictly necessary, but better than garbage
1062 in case the register value manages to escape somewhere (due
1063 to a bug, no less). */
1064 memset (regbuf, 0, size);
1065 regcache->register_status[regnum] = REG_UNAVAILABLE;
1066 }
1067}
1068
1069/* Collect register REGNUM from REGCACHE and store its contents in BUF. */
1070
1071void
1072regcache_raw_collect (const struct regcache *regcache, int regnum, void *buf)
1073{
1074 const void *regbuf;
1075 size_t size;
1076
1077 gdb_assert (regcache != NULL && buf != NULL);
1078 gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
1079
1080 regbuf = register_buffer (regcache, regnum);
1081 size = regcache->descr->sizeof_register[regnum];
1082 memcpy (buf, regbuf, size);
1083}
1084
1085/* Transfer a single or all registers belonging to a certain register
1086 set to or from a buffer. This is the main worker function for
1087 regcache_supply_regset and regcache_collect_regset. */
1088
1089static void
1090regcache_transfer_regset (const struct regset *regset,
1091 const struct regcache *regcache,
1092 struct regcache *out_regcache,
1093 int regnum, const void *in_buf,
1094 void *out_buf, size_t size)
1095{
1096 const struct regcache_map_entry *map;
1097 int offs = 0, count;
1098
1099 for (map = (const struct regcache_map_entry *) regset->regmap;
1100 (count = map->count) != 0;
1101 map++)
1102 {
1103 int regno = map->regno;
1104 int slot_size = map->size;
1105
1106 if (slot_size == 0 && regno != REGCACHE_MAP_SKIP)
1107 slot_size = regcache->descr->sizeof_register[regno];
1108
1109 if (regno == REGCACHE_MAP_SKIP
1110 || (regnum != -1
1111 && (regnum < regno || regnum >= regno + count)))
1112 offs += count * slot_size;
1113
1114 else if (regnum == -1)
1115 for (; count--; regno++, offs += slot_size)
1116 {
1117 if (offs + slot_size > size)
1118 break;
1119
1120 if (out_buf)
1121 regcache_raw_collect (regcache, regno,
1122 (gdb_byte *) out_buf + offs);
1123 else
1124 regcache_raw_supply (out_regcache, regno, in_buf
1125 ? (const gdb_byte *) in_buf + offs
1126 : NULL);
1127 }
1128 else
1129 {
1130 /* Transfer a single register and return. */
1131 offs += (regnum - regno) * slot_size;
1132 if (offs + slot_size > size)
1133 return;
1134
1135 if (out_buf)
1136 regcache_raw_collect (regcache, regnum,
1137 (gdb_byte *) out_buf + offs);
1138 else
1139 regcache_raw_supply (out_regcache, regnum, in_buf
1140 ? (const gdb_byte *) in_buf + offs
1141 : NULL);
1142 return;
1143 }
1144 }
1145}
1146
1147/* Supply register REGNUM from BUF to REGCACHE, using the register map
1148 in REGSET. If REGNUM is -1, do this for all registers in REGSET.
1149 If BUF is NULL, set the register(s) to "unavailable" status. */
1150
1151void
1152regcache_supply_regset (const struct regset *regset,
1153 struct regcache *regcache,
1154 int regnum, const void *buf, size_t size)
1155{
1156 regcache_transfer_regset (regset, regcache, regcache, regnum,
1157 buf, NULL, size);
1158}
1159
1160/* Collect register REGNUM from REGCACHE to BUF, using the register
1161 map in REGSET. If REGNUM is -1, do this for all registers in
1162 REGSET. */
1163
1164void
1165regcache_collect_regset (const struct regset *regset,
1166 const struct regcache *regcache,
1167 int regnum, void *buf, size_t size)
1168{
1169 regcache_transfer_regset (regset, regcache, NULL, regnum,
1170 NULL, buf, size);
1171}
1172
1173
1174/* Special handling for register PC. */
1175
1176CORE_ADDR
1177regcache_read_pc (struct regcache *regcache)
1178{
1179 struct gdbarch *gdbarch = get_regcache_arch (regcache);
1180
1181 CORE_ADDR pc_val;
1182
1183 if (gdbarch_read_pc_p (gdbarch))
1184 pc_val = gdbarch_read_pc (gdbarch, regcache);
1185 /* Else use per-frame method on get_current_frame. */
1186 else if (gdbarch_pc_regnum (gdbarch) >= 0)
1187 {
1188 ULONGEST raw_val;
1189
1190 if (regcache_cooked_read_unsigned (regcache,
1191 gdbarch_pc_regnum (gdbarch),
1192 &raw_val) == REG_UNAVAILABLE)
1193 throw_error (NOT_AVAILABLE_ERROR, _("PC register is not available"));
1194
1195 pc_val = gdbarch_addr_bits_remove (gdbarch, raw_val);
1196 }
1197 else
1198 internal_error (__FILE__, __LINE__,
1199 _("regcache_read_pc: Unable to find PC"));
1200 return pc_val;
1201}
1202
1203void
1204regcache_write_pc (struct regcache *regcache, CORE_ADDR pc)
1205{
1206 struct gdbarch *gdbarch = get_regcache_arch (regcache);
1207
1208 if (gdbarch_write_pc_p (gdbarch))
1209 gdbarch_write_pc (gdbarch, regcache, pc);
1210 else if (gdbarch_pc_regnum (gdbarch) >= 0)
1211 regcache_cooked_write_unsigned (regcache,
1212 gdbarch_pc_regnum (gdbarch), pc);
1213 else
1214 internal_error (__FILE__, __LINE__,
1215 _("regcache_write_pc: Unable to update PC"));
1216
1217 /* Writing the PC (for instance, from "load") invalidates the
1218 current frame. */
1219 reinit_frame_cache ();
1220}
1221
1222
1223static void
1224reg_flush_command (char *command, int from_tty)
1225{
1226 /* Force-flush the register cache. */
1227 registers_changed ();
1228 if (from_tty)
1229 printf_filtered (_("Register cache flushed.\n"));
1230}
1231
1232enum regcache_dump_what
1233{
1234 regcache_dump_none, regcache_dump_raw,
1235 regcache_dump_cooked, regcache_dump_groups,
1236 regcache_dump_remote
1237};
1238
1239static void
1240regcache_dump (struct regcache *regcache, struct ui_file *file,
1241 enum regcache_dump_what what_to_dump)
1242{
1243 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
1244 struct gdbarch *gdbarch = regcache->descr->gdbarch;
1245 int regnum;
1246 int footnote_nr = 0;
1247 int footnote_register_size = 0;
1248 int footnote_register_offset = 0;
1249 int footnote_register_type_name_null = 0;
1250 long register_offset = 0;
1251 gdb_byte buf[MAX_REGISTER_SIZE];
1252
1253#if 0
1254 fprintf_unfiltered (file, "nr_raw_registers %d\n",
1255 regcache->descr->nr_raw_registers);
1256 fprintf_unfiltered (file, "nr_cooked_registers %d\n",
1257 regcache->descr->nr_cooked_registers);
1258 fprintf_unfiltered (file, "sizeof_raw_registers %ld\n",
1259 regcache->descr->sizeof_raw_registers);
1260 fprintf_unfiltered (file, "sizeof_raw_register_status %ld\n",
1261 regcache->descr->sizeof_raw_register_status);
1262 fprintf_unfiltered (file, "gdbarch_num_regs %d\n",
1263 gdbarch_num_regs (gdbarch));
1264 fprintf_unfiltered (file, "gdbarch_num_pseudo_regs %d\n",
1265 gdbarch_num_pseudo_regs (gdbarch));
1266#endif
1267
1268 gdb_assert (regcache->descr->nr_cooked_registers
1269 == (gdbarch_num_regs (gdbarch)
1270 + gdbarch_num_pseudo_regs (gdbarch)));
1271
1272 for (regnum = -1; regnum < regcache->descr->nr_cooked_registers; regnum++)
1273 {
1274 /* Name. */
1275 if (regnum < 0)
1276 fprintf_unfiltered (file, " %-10s", "Name");
1277 else
1278 {
1279 const char *p = gdbarch_register_name (gdbarch, regnum);
1280
1281 if (p == NULL)
1282 p = "";
1283 else if (p[0] == '\0')
1284 p = "''";
1285 fprintf_unfiltered (file, " %-10s", p);
1286 }
1287
1288 /* Number. */
1289 if (regnum < 0)
1290 fprintf_unfiltered (file, " %4s", "Nr");
1291 else
1292 fprintf_unfiltered (file, " %4d", regnum);
1293
1294 /* Relative number. */
1295 if (regnum < 0)
1296 fprintf_unfiltered (file, " %4s", "Rel");
1297 else if (regnum < gdbarch_num_regs (gdbarch))
1298 fprintf_unfiltered (file, " %4d", regnum);
1299 else
1300 fprintf_unfiltered (file, " %4d",
1301 (regnum - gdbarch_num_regs (gdbarch)));
1302
1303 /* Offset. */
1304 if (regnum < 0)
1305 fprintf_unfiltered (file, " %6s ", "Offset");
1306 else
1307 {
1308 fprintf_unfiltered (file, " %6ld",
1309 regcache->descr->register_offset[regnum]);
1310 if (register_offset != regcache->descr->register_offset[regnum]
1311 || (regnum > 0
1312 && (regcache->descr->register_offset[regnum]
1313 != (regcache->descr->register_offset[regnum - 1]
1314 + regcache->descr->sizeof_register[regnum - 1])))
1315 )
1316 {
1317 if (!footnote_register_offset)
1318 footnote_register_offset = ++footnote_nr;
1319 fprintf_unfiltered (file, "*%d", footnote_register_offset);
1320 }
1321 else
1322 fprintf_unfiltered (file, " ");
1323 register_offset = (regcache->descr->register_offset[regnum]
1324 + regcache->descr->sizeof_register[regnum]);
1325 }
1326
1327 /* Size. */
1328 if (regnum < 0)
1329 fprintf_unfiltered (file, " %5s ", "Size");
1330 else
1331 fprintf_unfiltered (file, " %5ld",
1332 regcache->descr->sizeof_register[regnum]);
1333
1334 /* Type. */
1335 {
1336 const char *t;
1337
1338 if (regnum < 0)
1339 t = "Type";
1340 else
1341 {
1342 static const char blt[] = "builtin_type";
1343
1344 t = TYPE_NAME (register_type (regcache->descr->gdbarch, regnum));
1345 if (t == NULL)
1346 {
1347 char *n;
1348
1349 if (!footnote_register_type_name_null)
1350 footnote_register_type_name_null = ++footnote_nr;
1351 n = xstrprintf ("*%d", footnote_register_type_name_null);
1352 make_cleanup (xfree, n);
1353 t = n;
1354 }
1355 /* Chop a leading builtin_type. */
1356 if (startswith (t, blt))
1357 t += strlen (blt);
1358 }
1359 fprintf_unfiltered (file, " %-15s", t);
1360 }
1361
1362 /* Leading space always present. */
1363 fprintf_unfiltered (file, " ");
1364
1365 /* Value, raw. */
1366 if (what_to_dump == regcache_dump_raw)
1367 {
1368 if (regnum < 0)
1369 fprintf_unfiltered (file, "Raw value");
1370 else if (regnum >= regcache->descr->nr_raw_registers)
1371 fprintf_unfiltered (file, "<cooked>");
1372 else if (regcache_register_status (regcache, regnum) == REG_UNKNOWN)
1373 fprintf_unfiltered (file, "<invalid>");
1374 else if (regcache_register_status (regcache, regnum) == REG_UNAVAILABLE)
1375 fprintf_unfiltered (file, "<unavailable>");
1376 else
1377 {
1378 regcache_raw_read (regcache, regnum, buf);
1379 print_hex_chars (file, buf,
1380 regcache->descr->sizeof_register[regnum],
1381 gdbarch_byte_order (gdbarch));
1382 }
1383 }
1384
1385 /* Value, cooked. */
1386 if (what_to_dump == regcache_dump_cooked)
1387 {
1388 if (regnum < 0)
1389 fprintf_unfiltered (file, "Cooked value");
1390 else
1391 {
1392 enum register_status status;
1393
1394 status = regcache_cooked_read (regcache, regnum, buf);
1395 if (status == REG_UNKNOWN)
1396 fprintf_unfiltered (file, "<invalid>");
1397 else if (status == REG_UNAVAILABLE)
1398 fprintf_unfiltered (file, "<unavailable>");
1399 else
1400 print_hex_chars (file, buf,
1401 regcache->descr->sizeof_register[regnum],
1402 gdbarch_byte_order (gdbarch));
1403 }
1404 }
1405
1406 /* Group members. */
1407 if (what_to_dump == regcache_dump_groups)
1408 {
1409 if (regnum < 0)
1410 fprintf_unfiltered (file, "Groups");
1411 else
1412 {
1413 const char *sep = "";
1414 struct reggroup *group;
1415
1416 for (group = reggroup_next (gdbarch, NULL);
1417 group != NULL;
1418 group = reggroup_next (gdbarch, group))
1419 {
1420 if (gdbarch_register_reggroup_p (gdbarch, regnum, group))
1421 {
1422 fprintf_unfiltered (file,
1423 "%s%s", sep, reggroup_name (group));
1424 sep = ",";
1425 }
1426 }
1427 }
1428 }
1429
1430 /* Remote packet configuration. */
1431 if (what_to_dump == regcache_dump_remote)
1432 {
1433 if (regnum < 0)
1434 {
1435 fprintf_unfiltered (file, "Rmt Nr g/G Offset");
1436 }
1437 else if (regnum < regcache->descr->nr_raw_registers)
1438 {
1439 int pnum, poffset;
1440
1441 if (remote_register_number_and_offset (get_regcache_arch (regcache), regnum,
1442 &pnum, &poffset))
1443 fprintf_unfiltered (file, "%7d %11d", pnum, poffset);
1444 }
1445 }
1446
1447 fprintf_unfiltered (file, "\n");
1448 }
1449
1450 if (footnote_register_size)
1451 fprintf_unfiltered (file, "*%d: Inconsistent register sizes.\n",
1452 footnote_register_size);
1453 if (footnote_register_offset)
1454 fprintf_unfiltered (file, "*%d: Inconsistent register offsets.\n",
1455 footnote_register_offset);
1456 if (footnote_register_type_name_null)
1457 fprintf_unfiltered (file,
1458 "*%d: Register type's name NULL.\n",
1459 footnote_register_type_name_null);
1460 do_cleanups (cleanups);
1461}
1462
1463static void
1464regcache_print (char *args, enum regcache_dump_what what_to_dump)
1465{
1466 if (args == NULL)
1467 regcache_dump (get_current_regcache (), gdb_stdout, what_to_dump);
1468 else
1469 {
1470 struct cleanup *cleanups;
1471 struct ui_file *file = gdb_fopen (args, "w");
1472
1473 if (file == NULL)
1474 perror_with_name (_("maintenance print architecture"));
1475 cleanups = make_cleanup_ui_file_delete (file);
1476 regcache_dump (get_current_regcache (), file, what_to_dump);
1477 do_cleanups (cleanups);
1478 }
1479}
1480
1481static void
1482maintenance_print_registers (char *args, int from_tty)
1483{
1484 regcache_print (args, regcache_dump_none);
1485}
1486
1487static void
1488maintenance_print_raw_registers (char *args, int from_tty)
1489{
1490 regcache_print (args, regcache_dump_raw);
1491}
1492
1493static void
1494maintenance_print_cooked_registers (char *args, int from_tty)
1495{
1496 regcache_print (args, regcache_dump_cooked);
1497}
1498
1499static void
1500maintenance_print_register_groups (char *args, int from_tty)
1501{
1502 regcache_print (args, regcache_dump_groups);
1503}
1504
1505static void
1506maintenance_print_remote_registers (char *args, int from_tty)
1507{
1508 regcache_print (args, regcache_dump_remote);
1509}
1510
1511extern initialize_file_ftype _initialize_regcache; /* -Wmissing-prototype */
1512
1513void
1514_initialize_regcache (void)
1515{
1516 regcache_descr_handle
1517 = gdbarch_data_register_post_init (init_regcache_descr);
1518
1519 observer_attach_target_changed (regcache_observer_target_changed);
1520 observer_attach_thread_ptid_changed (regcache_thread_ptid_changed);
1521
1522 add_com ("flushregs", class_maintenance, reg_flush_command,
1523 _("Force gdb to flush its register cache (maintainer command)"));
1524
1525 add_cmd ("registers", class_maintenance, maintenance_print_registers,
1526 _("Print the internal register configuration.\n"
1527 "Takes an optional file parameter."), &maintenanceprintlist);
1528 add_cmd ("raw-registers", class_maintenance,
1529 maintenance_print_raw_registers,
1530 _("Print the internal register configuration "
1531 "including raw values.\n"
1532 "Takes an optional file parameter."), &maintenanceprintlist);
1533 add_cmd ("cooked-registers", class_maintenance,
1534 maintenance_print_cooked_registers,
1535 _("Print the internal register configuration "
1536 "including cooked values.\n"
1537 "Takes an optional file parameter."), &maintenanceprintlist);
1538 add_cmd ("register-groups", class_maintenance,
1539 maintenance_print_register_groups,
1540 _("Print the internal register configuration "
1541 "including each register's group.\n"
1542 "Takes an optional file parameter."),
1543 &maintenanceprintlist);
1544 add_cmd ("remote-registers", class_maintenance,
1545 maintenance_print_remote_registers, _("\
1546Print the internal register configuration including each register's\n\
1547remote register number and buffer offset in the g/G packets.\n\
1548Takes an optional file parameter."),
1549 &maintenanceprintlist);
1550
1551}
This page took 0.042586 seconds and 4 git commands to generate.