Remove regcache::m_readonly_p
[deliverable/binutils-gdb.git] / gdb / regcache.c
1 /* Cache and manage the values of registers for GDB, the GNU debugger.
2
3 Copyright (C) 1986-2018 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 #include <forward_list>
32
33 /*
34 * DATA STRUCTURE
35 *
36 * Here is the actual register cache.
37 */
38
39 /* Per-architecture object describing the layout of a register cache.
40 Computed once when the architecture is created. */
41
42 struct gdbarch_data *regcache_descr_handle;
43
44 struct regcache_descr
45 {
46 /* The architecture this descriptor belongs to. */
47 struct gdbarch *gdbarch;
48
49 /* The raw register cache. Each raw (or hard) register is supplied
50 by the target interface. The raw cache should not contain
51 redundant information - if the PC is constructed from two
52 registers then those registers and not the PC lives in the raw
53 cache. */
54 long sizeof_raw_registers;
55
56 /* The cooked register space. Each cooked register in the range
57 [0..NR_RAW_REGISTERS) is direct-mapped onto the corresponding raw
58 register. The remaining [NR_RAW_REGISTERS
59 .. NR_COOKED_REGISTERS) (a.k.a. pseudo registers) are mapped onto
60 both raw registers and memory by the architecture methods
61 gdbarch_pseudo_register_read and gdbarch_pseudo_register_write. */
62 int nr_cooked_registers;
63 long sizeof_cooked_registers;
64
65 /* Offset and size (in 8 bit bytes), of each register in the
66 register cache. All registers (including those in the range
67 [NR_RAW_REGISTERS .. NR_COOKED_REGISTERS) are given an
68 offset. */
69 long *register_offset;
70 long *sizeof_register;
71
72 /* Cached table containing the type of each register. */
73 struct type **register_type;
74 };
75
76 static void *
77 init_regcache_descr (struct gdbarch *gdbarch)
78 {
79 int i;
80 struct regcache_descr *descr;
81 gdb_assert (gdbarch != NULL);
82
83 /* Create an initial, zero filled, table. */
84 descr = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct regcache_descr);
85 descr->gdbarch = gdbarch;
86
87 /* Total size of the register space. The raw registers are mapped
88 directly onto the raw register cache while the pseudo's are
89 either mapped onto raw-registers or memory. */
90 descr->nr_cooked_registers = gdbarch_num_regs (gdbarch)
91 + gdbarch_num_pseudo_regs (gdbarch);
92
93 /* Fill in a table of register types. */
94 descr->register_type
95 = GDBARCH_OBSTACK_CALLOC (gdbarch, descr->nr_cooked_registers,
96 struct type *);
97 for (i = 0; i < descr->nr_cooked_registers; i++)
98 descr->register_type[i] = gdbarch_register_type (gdbarch, i);
99
100 /* Construct a strictly RAW register cache. Don't allow pseudo's
101 into the register cache. */
102
103 /* Lay out the register cache.
104
105 NOTE: cagney/2002-05-22: Only register_type() is used when
106 constructing the register cache. It is assumed that the
107 register's raw size, virtual size and type length are all the
108 same. */
109
110 {
111 long offset = 0;
112
113 descr->sizeof_register
114 = GDBARCH_OBSTACK_CALLOC (gdbarch, descr->nr_cooked_registers, long);
115 descr->register_offset
116 = GDBARCH_OBSTACK_CALLOC (gdbarch, descr->nr_cooked_registers, long);
117 for (i = 0; i < gdbarch_num_regs (gdbarch); i++)
118 {
119 descr->sizeof_register[i] = TYPE_LENGTH (descr->register_type[i]);
120 descr->register_offset[i] = offset;
121 offset += descr->sizeof_register[i];
122 gdb_assert (MAX_REGISTER_SIZE >= descr->sizeof_register[i]);
123 }
124 /* Set the real size of the raw register cache buffer. */
125 descr->sizeof_raw_registers = offset;
126
127 for (; i < descr->nr_cooked_registers; i++)
128 {
129 descr->sizeof_register[i] = TYPE_LENGTH (descr->register_type[i]);
130 descr->register_offset[i] = offset;
131 offset += descr->sizeof_register[i];
132 gdb_assert (MAX_REGISTER_SIZE >= descr->sizeof_register[i]);
133 }
134 /* Set the real size of the readonly register cache buffer. */
135 descr->sizeof_cooked_registers = offset;
136 }
137
138 return descr;
139 }
140
141 static struct regcache_descr *
142 regcache_descr (struct gdbarch *gdbarch)
143 {
144 return (struct regcache_descr *) gdbarch_data (gdbarch,
145 regcache_descr_handle);
146 }
147
148 /* Utility functions returning useful register attributes stored in
149 the regcache descr. */
150
151 struct type *
152 register_type (struct gdbarch *gdbarch, int regnum)
153 {
154 struct regcache_descr *descr = regcache_descr (gdbarch);
155
156 gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
157 return descr->register_type[regnum];
158 }
159
160 /* Utility functions returning useful register attributes stored in
161 the regcache descr. */
162
163 int
164 register_size (struct gdbarch *gdbarch, int regnum)
165 {
166 struct regcache_descr *descr = regcache_descr (gdbarch);
167 int size;
168
169 gdb_assert (regnum >= 0
170 && regnum < (gdbarch_num_regs (gdbarch)
171 + gdbarch_num_pseudo_regs (gdbarch)));
172 size = descr->sizeof_register[regnum];
173 return size;
174 }
175
176 /* See common/common-regcache.h. */
177
178 int
179 regcache_register_size (const struct regcache *regcache, int n)
180 {
181 return register_size (regcache->arch (), n);
182 }
183
184 reg_buffer::reg_buffer (gdbarch *gdbarch, bool has_pseudo)
185 : m_has_pseudo (has_pseudo)
186 {
187 gdb_assert (gdbarch != NULL);
188 m_descr = regcache_descr (gdbarch);
189
190 if (has_pseudo)
191 {
192 m_registers = XCNEWVEC (gdb_byte, m_descr->sizeof_cooked_registers);
193 m_register_status = XCNEWVEC (signed char,
194 m_descr->nr_cooked_registers);
195 }
196 else
197 {
198 m_registers = XCNEWVEC (gdb_byte, m_descr->sizeof_raw_registers);
199 m_register_status = XCNEWVEC (signed char, gdbarch_num_regs (gdbarch));
200 }
201 }
202
203 regcache::regcache (gdbarch *gdbarch, const address_space *aspace_)
204 /* The register buffers. A read/write register cache can only hold
205 [0 .. gdbarch_num_regs). */
206 : detached_regcache (gdbarch, false), m_aspace (aspace_)
207 {
208 m_ptid = minus_one_ptid;
209 }
210
211 static enum register_status
212 do_cooked_read (void *src, int regnum, gdb_byte *buf)
213 {
214 struct regcache *regcache = (struct regcache *) src;
215
216 return regcache_cooked_read (regcache, regnum, buf);
217 }
218
219 readonly_detached_regcache::readonly_detached_regcache (const regcache &src)
220 : readonly_detached_regcache (src.arch (), do_cooked_read, (void *) &src)
221 {
222 }
223
224 gdbarch *
225 reg_buffer::arch () const
226 {
227 return m_descr->gdbarch;
228 }
229
230 /* See regcache.h. */
231
232 ptid_t
233 regcache_get_ptid (const struct regcache *regcache)
234 {
235 gdb_assert (!ptid_equal (regcache->ptid (), minus_one_ptid));
236
237 return regcache->ptid ();
238 }
239
240 /* Cleanup class for invalidating a register. */
241
242 class regcache_invalidator
243 {
244 public:
245
246 regcache_invalidator (struct regcache *regcache, int regnum)
247 : m_regcache (regcache),
248 m_regnum (regnum)
249 {
250 }
251
252 ~regcache_invalidator ()
253 {
254 if (m_regcache != nullptr)
255 regcache_invalidate (m_regcache, m_regnum);
256 }
257
258 DISABLE_COPY_AND_ASSIGN (regcache_invalidator);
259
260 void release ()
261 {
262 m_regcache = nullptr;
263 }
264
265 private:
266
267 struct regcache *m_regcache;
268 int m_regnum;
269 };
270
271 /* Return a pointer to register REGNUM's buffer cache. */
272
273 gdb_byte *
274 reg_buffer::register_buffer (int regnum) const
275 {
276 return m_registers + m_descr->register_offset[regnum];
277 }
278
279 void
280 reg_buffer::save (regcache_cooked_read_ftype *cooked_read,
281 void *src)
282 {
283 struct gdbarch *gdbarch = m_descr->gdbarch;
284 int regnum;
285
286 /* It should have pseudo registers. */
287 gdb_assert (m_has_pseudo);
288 /* Clear the dest. */
289 memset (m_registers, 0, m_descr->sizeof_cooked_registers);
290 memset (m_register_status, 0, m_descr->nr_cooked_registers);
291 /* Copy over any registers (identified by their membership in the
292 save_reggroup) and mark them as valid. The full [0 .. gdbarch_num_regs +
293 gdbarch_num_pseudo_regs) range is checked since some architectures need
294 to save/restore `cooked' registers that live in memory. */
295 for (regnum = 0; regnum < m_descr->nr_cooked_registers; regnum++)
296 {
297 if (gdbarch_register_reggroup_p (gdbarch, regnum, save_reggroup))
298 {
299 gdb_byte *dst_buf = register_buffer (regnum);
300 enum register_status status = cooked_read (src, regnum, dst_buf);
301
302 gdb_assert (status != REG_UNKNOWN);
303
304 if (status != REG_VALID)
305 memset (dst_buf, 0, register_size (gdbarch, regnum));
306
307 m_register_status[regnum] = status;
308 }
309 }
310 }
311
312 void
313 regcache::restore (readonly_detached_regcache *src)
314 {
315 struct gdbarch *gdbarch = m_descr->gdbarch;
316 int regnum;
317
318 gdb_assert (src != NULL);
319 gdb_assert (src->m_has_pseudo);
320
321 gdb_assert (gdbarch == src->arch ());
322
323 /* Copy over any registers, being careful to only restore those that
324 were both saved and need to be restored. The full [0 .. gdbarch_num_regs
325 + gdbarch_num_pseudo_regs) range is checked since some architectures need
326 to save/restore `cooked' registers that live in memory. */
327 for (regnum = 0; regnum < m_descr->nr_cooked_registers; regnum++)
328 {
329 if (gdbarch_register_reggroup_p (gdbarch, regnum, restore_reggroup))
330 {
331 if (src->m_register_status[regnum] == REG_VALID)
332 cooked_write (regnum, src->register_buffer (regnum));
333 }
334 }
335 }
336
337 enum register_status
338 regcache_register_status (const struct regcache *regcache, int regnum)
339 {
340 gdb_assert (regcache != NULL);
341 return regcache->get_register_status (regnum);
342 }
343
344 enum register_status
345 reg_buffer::get_register_status (int regnum) const
346 {
347 assert_regnum (regnum);
348
349 return (enum register_status) m_register_status[regnum];
350 }
351
352 void
353 regcache_invalidate (struct regcache *regcache, int regnum)
354 {
355 gdb_assert (regcache != NULL);
356 regcache->invalidate (regnum);
357 }
358
359 void
360 detached_regcache::invalidate (int regnum)
361 {
362 assert_regnum (regnum);
363 m_register_status[regnum] = REG_UNKNOWN;
364 }
365
366 void
367 reg_buffer::assert_regnum (int regnum) const
368 {
369 gdb_assert (regnum >= 0);
370 if (m_has_pseudo)
371 gdb_assert (regnum < m_descr->nr_cooked_registers);
372 else
373 gdb_assert (regnum < gdbarch_num_regs (arch ()));
374 }
375
376 /* Global structure containing the current regcache. */
377
378 /* NOTE: this is a write-through cache. There is no "dirty" bit for
379 recording if the register values have been changed (eg. by the
380 user). Therefore all registers must be written back to the
381 target when appropriate. */
382 std::forward_list<regcache *> regcache::current_regcache;
383
384 struct regcache *
385 get_thread_arch_aspace_regcache (ptid_t ptid, struct gdbarch *gdbarch,
386 struct address_space *aspace)
387 {
388 for (const auto &regcache : regcache::current_regcache)
389 if (ptid_equal (regcache->ptid (), ptid) && regcache->arch () == gdbarch)
390 return regcache;
391
392 regcache *new_regcache = new regcache (gdbarch, aspace);
393
394 regcache::current_regcache.push_front (new_regcache);
395 new_regcache->set_ptid (ptid);
396
397 return new_regcache;
398 }
399
400 struct regcache *
401 get_thread_arch_regcache (ptid_t ptid, struct gdbarch *gdbarch)
402 {
403 address_space *aspace = target_thread_address_space (ptid);
404
405 return get_thread_arch_aspace_regcache (ptid, gdbarch, aspace);
406 }
407
408 static ptid_t current_thread_ptid;
409 static struct gdbarch *current_thread_arch;
410
411 struct regcache *
412 get_thread_regcache (ptid_t ptid)
413 {
414 if (!current_thread_arch || !ptid_equal (current_thread_ptid, ptid))
415 {
416 current_thread_ptid = ptid;
417 current_thread_arch = target_thread_architecture (ptid);
418 }
419
420 return get_thread_arch_regcache (ptid, current_thread_arch);
421 }
422
423 struct regcache *
424 get_current_regcache (void)
425 {
426 return get_thread_regcache (inferior_ptid);
427 }
428
429 /* See common/common-regcache.h. */
430
431 struct regcache *
432 get_thread_regcache_for_ptid (ptid_t ptid)
433 {
434 return get_thread_regcache (ptid);
435 }
436
437 /* Observer for the target_changed event. */
438
439 static void
440 regcache_observer_target_changed (struct target_ops *target)
441 {
442 registers_changed ();
443 }
444
445 /* Update global variables old ptids to hold NEW_PTID if they were
446 holding OLD_PTID. */
447 void
448 regcache::regcache_thread_ptid_changed (ptid_t old_ptid, ptid_t new_ptid)
449 {
450 for (auto &regcache : regcache::current_regcache)
451 {
452 if (ptid_equal (regcache->ptid (), old_ptid))
453 regcache->set_ptid (new_ptid);
454 }
455 }
456
457 /* Low level examining and depositing of registers.
458
459 The caller is responsible for making sure that the inferior is
460 stopped before calling the fetching routines, or it will get
461 garbage. (a change from GDB version 3, in which the caller got the
462 value from the last stop). */
463
464 /* REGISTERS_CHANGED ()
465
466 Indicate that registers may have changed, so invalidate the cache. */
467
468 void
469 registers_changed_ptid (ptid_t ptid)
470 {
471 for (auto oit = regcache::current_regcache.before_begin (),
472 it = std::next (oit);
473 it != regcache::current_regcache.end ();
474 )
475 {
476 if (ptid_match ((*it)->ptid (), ptid))
477 {
478 delete *it;
479 it = regcache::current_regcache.erase_after (oit);
480 }
481 else
482 oit = it++;
483 }
484
485 if (ptid_match (current_thread_ptid, ptid))
486 {
487 current_thread_ptid = null_ptid;
488 current_thread_arch = NULL;
489 }
490
491 if (ptid_match (inferior_ptid, ptid))
492 {
493 /* We just deleted the regcache of the current thread. Need to
494 forget about any frames we have cached, too. */
495 reinit_frame_cache ();
496 }
497 }
498
499 void
500 registers_changed (void)
501 {
502 registers_changed_ptid (minus_one_ptid);
503
504 /* Force cleanup of any alloca areas if using C alloca instead of
505 a builtin alloca. This particular call is used to clean up
506 areas allocated by low level target code which may build up
507 during lengthy interactions between gdb and the target before
508 gdb gives control to the user (ie watchpoints). */
509 alloca (0);
510 }
511
512 void
513 regcache_raw_update (struct regcache *regcache, int regnum)
514 {
515 gdb_assert (regcache != NULL);
516
517 regcache->raw_update (regnum);
518 }
519
520 void
521 regcache::raw_update (int regnum)
522 {
523 assert_regnum (regnum);
524
525 /* Make certain that the register cache is up-to-date with respect
526 to the current thread. This switching shouldn't be necessary
527 only there is still only one target side register cache. Sigh!
528 On the bright side, at least there is a regcache object. */
529
530 if (get_register_status (regnum) == REG_UNKNOWN)
531 {
532 target_fetch_registers (this, regnum);
533
534 /* A number of targets can't access the whole set of raw
535 registers (because the debug API provides no means to get at
536 them). */
537 if (m_register_status[regnum] == REG_UNKNOWN)
538 m_register_status[regnum] = REG_UNAVAILABLE;
539 }
540 }
541
542 enum register_status
543 regcache_raw_read (struct regcache *regcache, int regnum, gdb_byte *buf)
544 {
545 return regcache->raw_read (regnum, buf);
546 }
547
548 enum register_status
549 readable_regcache::raw_read (int regnum, gdb_byte *buf)
550 {
551 gdb_assert (buf != NULL);
552 raw_update (regnum);
553
554 if (m_register_status[regnum] != REG_VALID)
555 memset (buf, 0, m_descr->sizeof_register[regnum]);
556 else
557 memcpy (buf, register_buffer (regnum),
558 m_descr->sizeof_register[regnum]);
559
560 return (enum register_status) m_register_status[regnum];
561 }
562
563 enum register_status
564 regcache_raw_read_signed (struct regcache *regcache, int regnum, LONGEST *val)
565 {
566 gdb_assert (regcache != NULL);
567 return regcache->raw_read (regnum, val);
568 }
569
570 template<typename T, typename>
571 enum register_status
572 readable_regcache::raw_read (int regnum, T *val)
573 {
574 gdb_byte *buf;
575 enum register_status status;
576
577 assert_regnum (regnum);
578 buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]);
579 status = raw_read (regnum, buf);
580 if (status == REG_VALID)
581 *val = extract_integer<T> (buf,
582 m_descr->sizeof_register[regnum],
583 gdbarch_byte_order (m_descr->gdbarch));
584 else
585 *val = 0;
586 return status;
587 }
588
589 enum register_status
590 regcache_raw_read_unsigned (struct regcache *regcache, int regnum,
591 ULONGEST *val)
592 {
593 gdb_assert (regcache != NULL);
594 return regcache->raw_read (regnum, val);
595 }
596
597 void
598 regcache_raw_write_signed (struct regcache *regcache, int regnum, LONGEST val)
599 {
600 gdb_assert (regcache != NULL);
601 regcache->raw_write (regnum, val);
602 }
603
604 template<typename T, typename>
605 void
606 regcache::raw_write (int regnum, T val)
607 {
608 gdb_byte *buf;
609
610 assert_regnum (regnum);
611 buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]);
612 store_integer (buf, m_descr->sizeof_register[regnum],
613 gdbarch_byte_order (m_descr->gdbarch), val);
614 raw_write (regnum, buf);
615 }
616
617 void
618 regcache_raw_write_unsigned (struct regcache *regcache, int regnum,
619 ULONGEST val)
620 {
621 gdb_assert (regcache != NULL);
622 regcache->raw_write (regnum, val);
623 }
624
625 LONGEST
626 regcache_raw_get_signed (struct regcache *regcache, int regnum)
627 {
628 LONGEST value;
629 enum register_status status;
630
631 status = regcache_raw_read_signed (regcache, regnum, &value);
632 if (status == REG_UNAVAILABLE)
633 throw_error (NOT_AVAILABLE_ERROR,
634 _("Register %d is not available"), regnum);
635 return value;
636 }
637
638 enum register_status
639 regcache_cooked_read (struct regcache *regcache, int regnum, gdb_byte *buf)
640 {
641 return regcache->cooked_read (regnum, buf);
642 }
643
644 enum register_status
645 readable_regcache::cooked_read (int regnum, gdb_byte *buf)
646 {
647 gdb_assert (regnum >= 0);
648 gdb_assert (regnum < m_descr->nr_cooked_registers);
649 if (regnum < num_raw_registers ())
650 return raw_read (regnum, buf);
651 else if (m_has_pseudo
652 && m_register_status[regnum] != REG_UNKNOWN)
653 {
654 if (m_register_status[regnum] == REG_VALID)
655 memcpy (buf, register_buffer (regnum),
656 m_descr->sizeof_register[regnum]);
657 else
658 memset (buf, 0, m_descr->sizeof_register[regnum]);
659
660 return (enum register_status) m_register_status[regnum];
661 }
662 else if (gdbarch_pseudo_register_read_value_p (m_descr->gdbarch))
663 {
664 struct value *mark, *computed;
665 enum register_status result = REG_VALID;
666
667 mark = value_mark ();
668
669 computed = gdbarch_pseudo_register_read_value (m_descr->gdbarch,
670 this, regnum);
671 if (value_entirely_available (computed))
672 memcpy (buf, value_contents_raw (computed),
673 m_descr->sizeof_register[regnum]);
674 else
675 {
676 memset (buf, 0, m_descr->sizeof_register[regnum]);
677 result = REG_UNAVAILABLE;
678 }
679
680 value_free_to_mark (mark);
681
682 return result;
683 }
684 else
685 return gdbarch_pseudo_register_read (m_descr->gdbarch, this,
686 regnum, buf);
687 }
688
689 struct value *
690 regcache_cooked_read_value (struct regcache *regcache, int regnum)
691 {
692 return regcache->cooked_read_value (regnum);
693 }
694
695 struct value *
696 readable_regcache::cooked_read_value (int regnum)
697 {
698 gdb_assert (regnum >= 0);
699 gdb_assert (regnum < m_descr->nr_cooked_registers);
700
701 if (regnum < num_raw_registers ()
702 || (m_has_pseudo && m_register_status[regnum] != REG_UNKNOWN)
703 || !gdbarch_pseudo_register_read_value_p (m_descr->gdbarch))
704 {
705 struct value *result;
706
707 result = allocate_value (register_type (m_descr->gdbarch, regnum));
708 VALUE_LVAL (result) = lval_register;
709 VALUE_REGNUM (result) = regnum;
710
711 /* It is more efficient in general to do this delegation in this
712 direction than in the other one, even though the value-based
713 API is preferred. */
714 if (cooked_read (regnum,
715 value_contents_raw (result)) == REG_UNAVAILABLE)
716 mark_value_bytes_unavailable (result, 0,
717 TYPE_LENGTH (value_type (result)));
718
719 return result;
720 }
721 else
722 return gdbarch_pseudo_register_read_value (m_descr->gdbarch,
723 this, regnum);
724 }
725
726 enum register_status
727 regcache_cooked_read_signed (struct regcache *regcache, int regnum,
728 LONGEST *val)
729 {
730 gdb_assert (regcache != NULL);
731 return regcache->cooked_read (regnum, val);
732 }
733
734 template<typename T, typename>
735 enum register_status
736 readable_regcache::cooked_read (int regnum, T *val)
737 {
738 enum register_status status;
739 gdb_byte *buf;
740
741 gdb_assert (regnum >= 0 && regnum < m_descr->nr_cooked_registers);
742 buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]);
743 status = cooked_read (regnum, buf);
744 if (status == REG_VALID)
745 *val = extract_integer<T> (buf, m_descr->sizeof_register[regnum],
746 gdbarch_byte_order (m_descr->gdbarch));
747 else
748 *val = 0;
749 return status;
750 }
751
752 enum register_status
753 regcache_cooked_read_unsigned (struct regcache *regcache, int regnum,
754 ULONGEST *val)
755 {
756 gdb_assert (regcache != NULL);
757 return regcache->cooked_read (regnum, val);
758 }
759
760 void
761 regcache_cooked_write_signed (struct regcache *regcache, int regnum,
762 LONGEST val)
763 {
764 gdb_assert (regcache != NULL);
765 regcache->cooked_write (regnum, val);
766 }
767
768 template<typename T, typename>
769 void
770 regcache::cooked_write (int regnum, T val)
771 {
772 gdb_byte *buf;
773
774 gdb_assert (regnum >=0 && regnum < m_descr->nr_cooked_registers);
775 buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]);
776 store_integer (buf, m_descr->sizeof_register[regnum],
777 gdbarch_byte_order (m_descr->gdbarch), val);
778 cooked_write (regnum, buf);
779 }
780
781 void
782 regcache_cooked_write_unsigned (struct regcache *regcache, int regnum,
783 ULONGEST val)
784 {
785 gdb_assert (regcache != NULL);
786 regcache->cooked_write (regnum, val);
787 }
788
789 void
790 regcache_raw_write (struct regcache *regcache, int regnum,
791 const gdb_byte *buf)
792 {
793 gdb_assert (regcache != NULL && buf != NULL);
794 regcache->raw_write (regnum, buf);
795 }
796
797 void
798 regcache::raw_write (int regnum, const gdb_byte *buf)
799 {
800
801 gdb_assert (buf != NULL);
802 assert_regnum (regnum);
803
804 /* On the sparc, writing %g0 is a no-op, so we don't even want to
805 change the registers array if something writes to this register. */
806 if (gdbarch_cannot_store_register (arch (), regnum))
807 return;
808
809 /* If we have a valid copy of the register, and new value == old
810 value, then don't bother doing the actual store. */
811 if (get_register_status (regnum) == REG_VALID
812 && (memcmp (register_buffer (regnum), buf,
813 m_descr->sizeof_register[regnum]) == 0))
814 return;
815
816 target_prepare_to_store (this);
817 raw_supply (regnum, buf);
818
819 /* Invalidate the register after it is written, in case of a
820 failure. */
821 regcache_invalidator invalidator (this, regnum);
822
823 target_store_registers (this, regnum);
824
825 /* The target did not throw an error so we can discard invalidating
826 the register. */
827 invalidator.release ();
828 }
829
830 void
831 regcache_cooked_write (struct regcache *regcache, int regnum,
832 const gdb_byte *buf)
833 {
834 regcache->cooked_write (regnum, buf);
835 }
836
837 void
838 regcache::cooked_write (int regnum, const gdb_byte *buf)
839 {
840 gdb_assert (regnum >= 0);
841 gdb_assert (regnum < m_descr->nr_cooked_registers);
842 if (regnum < num_raw_registers ())
843 raw_write (regnum, buf);
844 else
845 gdbarch_pseudo_register_write (m_descr->gdbarch, this,
846 regnum, buf);
847 }
848
849 /* Perform a partial register transfer using a read, modify, write
850 operation. */
851
852 typedef void (regcache_read_ftype) (struct regcache *regcache, int regnum,
853 void *buf);
854 typedef void (regcache_write_ftype) (struct regcache *regcache, int regnum,
855 const void *buf);
856
857 enum register_status
858 readable_regcache::read_part (int regnum, int offset, int len, void *in,
859 bool is_raw)
860 {
861 struct gdbarch *gdbarch = arch ();
862 gdb_byte *reg = (gdb_byte *) alloca (register_size (gdbarch, regnum));
863
864 gdb_assert (in != NULL);
865 gdb_assert (offset >= 0 && offset <= m_descr->sizeof_register[regnum]);
866 gdb_assert (len >= 0 && offset + len <= m_descr->sizeof_register[regnum]);
867 /* Something to do? */
868 if (offset + len == 0)
869 return REG_VALID;
870 /* Read (when needed) ... */
871 enum register_status status;
872
873 if (is_raw)
874 status = raw_read (regnum, reg);
875 else
876 status = cooked_read (regnum, reg);
877 if (status != REG_VALID)
878 return status;
879
880 /* ... modify ... */
881 memcpy (in, reg + offset, len);
882
883 return REG_VALID;
884 }
885
886 enum register_status
887 regcache::write_part (int regnum, int offset, int len,
888 const void *out, bool is_raw)
889 {
890 struct gdbarch *gdbarch = arch ();
891 gdb_byte *reg = (gdb_byte *) alloca (register_size (gdbarch, regnum));
892
893 gdb_assert (out != NULL);
894 gdb_assert (offset >= 0 && offset <= m_descr->sizeof_register[regnum]);
895 gdb_assert (len >= 0 && offset + len <= m_descr->sizeof_register[regnum]);
896 /* Something to do? */
897 if (offset + len == 0)
898 return REG_VALID;
899 /* Read (when needed) ... */
900 if (offset > 0
901 || offset + len < m_descr->sizeof_register[regnum])
902 {
903 enum register_status status;
904
905 if (is_raw)
906 status = raw_read (regnum, reg);
907 else
908 status = cooked_read (regnum, reg);
909 if (status != REG_VALID)
910 return status;
911 }
912
913 memcpy (reg + offset, out, len);
914 /* ... write (when needed). */
915 if (is_raw)
916 raw_write (regnum, reg);
917 else
918 cooked_write (regnum, reg);
919
920 return REG_VALID;
921 }
922
923 enum register_status
924 regcache_raw_read_part (struct regcache *regcache, int regnum,
925 int offset, int len, gdb_byte *buf)
926 {
927 return regcache->raw_read_part (regnum, offset, len, buf);
928 }
929
930 enum register_status
931 readable_regcache::raw_read_part (int regnum, int offset, int len, gdb_byte *buf)
932 {
933 assert_regnum (regnum);
934 return read_part (regnum, offset, len, buf, true);
935 }
936
937 void
938 regcache_raw_write_part (struct regcache *regcache, int regnum,
939 int offset, int len, const gdb_byte *buf)
940 {
941 regcache->raw_write_part (regnum, offset, len, buf);
942 }
943
944 void
945 regcache::raw_write_part (int regnum, int offset, int len,
946 const gdb_byte *buf)
947 {
948 assert_regnum (regnum);
949 write_part (regnum, offset, len, buf, true);
950 }
951
952 enum register_status
953 regcache_cooked_read_part (struct regcache *regcache, int regnum,
954 int offset, int len, gdb_byte *buf)
955 {
956 return regcache->cooked_read_part (regnum, offset, len, buf);
957 }
958
959
960 enum register_status
961 readable_regcache::cooked_read_part (int regnum, int offset, int len,
962 gdb_byte *buf)
963 {
964 gdb_assert (regnum >= 0 && regnum < m_descr->nr_cooked_registers);
965 return read_part (regnum, offset, len, buf, false);
966 }
967
968 void
969 regcache_cooked_write_part (struct regcache *regcache, int regnum,
970 int offset, int len, const gdb_byte *buf)
971 {
972 regcache->cooked_write_part (regnum, offset, len, buf);
973 }
974
975 void
976 regcache::cooked_write_part (int regnum, int offset, int len,
977 const gdb_byte *buf)
978 {
979 gdb_assert (regnum >= 0 && regnum < m_descr->nr_cooked_registers);
980 write_part (regnum, offset, len, buf, false);
981 }
982
983 /* Supply register REGNUM, whose contents are stored in BUF, to REGCACHE. */
984
985 void
986 regcache_raw_supply (struct regcache *regcache, int regnum, const void *buf)
987 {
988 gdb_assert (regcache != NULL);
989 regcache->raw_supply (regnum, buf);
990 }
991
992 void
993 detached_regcache::raw_supply (int regnum, const void *buf)
994 {
995 void *regbuf;
996 size_t size;
997
998 assert_regnum (regnum);
999
1000 regbuf = register_buffer (regnum);
1001 size = m_descr->sizeof_register[regnum];
1002
1003 if (buf)
1004 {
1005 memcpy (regbuf, buf, size);
1006 m_register_status[regnum] = REG_VALID;
1007 }
1008 else
1009 {
1010 /* This memset not strictly necessary, but better than garbage
1011 in case the register value manages to escape somewhere (due
1012 to a bug, no less). */
1013 memset (regbuf, 0, size);
1014 m_register_status[regnum] = REG_UNAVAILABLE;
1015 }
1016 }
1017
1018 /* Supply register REGNUM to REGCACHE. Value to supply is an integer stored at
1019 address ADDR, in target endian, with length ADDR_LEN and sign IS_SIGNED. If
1020 the register size is greater than ADDR_LEN, then the integer will be sign or
1021 zero extended. If the register size is smaller than the integer, then the
1022 most significant bytes of the integer will be truncated. */
1023
1024 void
1025 detached_regcache::raw_supply_integer (int regnum, const gdb_byte *addr,
1026 int addr_len, bool is_signed)
1027 {
1028 enum bfd_endian byte_order = gdbarch_byte_order (m_descr->gdbarch);
1029 gdb_byte *regbuf;
1030 size_t regsize;
1031
1032 assert_regnum (regnum);
1033
1034 regbuf = register_buffer (regnum);
1035 regsize = m_descr->sizeof_register[regnum];
1036
1037 copy_integer_to_size (regbuf, regsize, addr, addr_len, is_signed,
1038 byte_order);
1039 m_register_status[regnum] = REG_VALID;
1040 }
1041
1042 /* Supply register REGNUM with zeroed value to REGCACHE. This is not the same
1043 as calling raw_supply with NULL (which will set the state to
1044 unavailable). */
1045
1046 void
1047 detached_regcache::raw_supply_zeroed (int regnum)
1048 {
1049 void *regbuf;
1050 size_t size;
1051
1052 assert_regnum (regnum);
1053
1054 regbuf = register_buffer (regnum);
1055 size = m_descr->sizeof_register[regnum];
1056
1057 memset (regbuf, 0, size);
1058 m_register_status[regnum] = REG_VALID;
1059 }
1060
1061 /* Collect register REGNUM from REGCACHE and store its contents in BUF. */
1062
1063 void
1064 regcache_raw_collect (const struct regcache *regcache, int regnum, void *buf)
1065 {
1066 gdb_assert (regcache != NULL && buf != NULL);
1067 regcache->raw_collect (regnum, buf);
1068 }
1069
1070 void
1071 regcache::raw_collect (int regnum, void *buf) const
1072 {
1073 const void *regbuf;
1074 size_t size;
1075
1076 gdb_assert (buf != NULL);
1077 assert_regnum (regnum);
1078
1079 regbuf = register_buffer (regnum);
1080 size = m_descr->sizeof_register[regnum];
1081 memcpy (buf, regbuf, size);
1082 }
1083
1084 /* Transfer a single or all registers belonging to a certain register
1085 set to or from a buffer. This is the main worker function for
1086 regcache_supply_regset and regcache_collect_regset. */
1087
1088 /* Collect register REGNUM from REGCACHE. Store collected value as an integer
1089 at address ADDR, in target endian, with length ADDR_LEN and sign IS_SIGNED.
1090 If ADDR_LEN is greater than the register size, then the integer will be sign
1091 or zero extended. If ADDR_LEN is smaller than the register size, then the
1092 most significant bytes of the integer will be truncated. */
1093
1094 void
1095 regcache::raw_collect_integer (int regnum, gdb_byte *addr, int addr_len,
1096 bool is_signed) const
1097 {
1098 enum bfd_endian byte_order = gdbarch_byte_order (m_descr->gdbarch);
1099 const gdb_byte *regbuf;
1100 size_t regsize;
1101
1102 assert_regnum (regnum);
1103
1104 regbuf = register_buffer (regnum);
1105 regsize = m_descr->sizeof_register[regnum];
1106
1107 copy_integer_to_size (addr, addr_len, regbuf, regsize, is_signed,
1108 byte_order);
1109 }
1110
1111 void
1112 regcache::transfer_regset (const struct regset *regset,
1113 struct regcache *out_regcache,
1114 int regnum, const void *in_buf,
1115 void *out_buf, size_t size) const
1116 {
1117 const struct regcache_map_entry *map;
1118 int offs = 0, count;
1119
1120 for (map = (const struct regcache_map_entry *) regset->regmap;
1121 (count = map->count) != 0;
1122 map++)
1123 {
1124 int regno = map->regno;
1125 int slot_size = map->size;
1126
1127 if (slot_size == 0 && regno != REGCACHE_MAP_SKIP)
1128 slot_size = m_descr->sizeof_register[regno];
1129
1130 if (regno == REGCACHE_MAP_SKIP
1131 || (regnum != -1
1132 && (regnum < regno || regnum >= regno + count)))
1133 offs += count * slot_size;
1134
1135 else if (regnum == -1)
1136 for (; count--; regno++, offs += slot_size)
1137 {
1138 if (offs + slot_size > size)
1139 break;
1140
1141 if (out_buf)
1142 raw_collect (regno, (gdb_byte *) out_buf + offs);
1143 else
1144 out_regcache->raw_supply (regno, in_buf
1145 ? (const gdb_byte *) in_buf + offs
1146 : NULL);
1147 }
1148 else
1149 {
1150 /* Transfer a single register and return. */
1151 offs += (regnum - regno) * slot_size;
1152 if (offs + slot_size > size)
1153 return;
1154
1155 if (out_buf)
1156 raw_collect (regnum, (gdb_byte *) out_buf + offs);
1157 else
1158 out_regcache->raw_supply (regnum, in_buf
1159 ? (const gdb_byte *) in_buf + offs
1160 : NULL);
1161 return;
1162 }
1163 }
1164 }
1165
1166 /* Supply register REGNUM from BUF to REGCACHE, using the register map
1167 in REGSET. If REGNUM is -1, do this for all registers in REGSET.
1168 If BUF is NULL, set the register(s) to "unavailable" status. */
1169
1170 void
1171 regcache_supply_regset (const struct regset *regset,
1172 struct regcache *regcache,
1173 int regnum, const void *buf, size_t size)
1174 {
1175 regcache->supply_regset (regset, regnum, buf, size);
1176 }
1177
1178 void
1179 regcache::supply_regset (const struct regset *regset,
1180 int regnum, const void *buf, size_t size)
1181 {
1182 transfer_regset (regset, this, regnum, buf, NULL, size);
1183 }
1184
1185 /* Collect register REGNUM from REGCACHE to BUF, using the register
1186 map in REGSET. If REGNUM is -1, do this for all registers in
1187 REGSET. */
1188
1189 void
1190 regcache_collect_regset (const struct regset *regset,
1191 const struct regcache *regcache,
1192 int regnum, void *buf, size_t size)
1193 {
1194 regcache->collect_regset (regset, regnum, buf, size);
1195 }
1196
1197 void
1198 regcache::collect_regset (const struct regset *regset,
1199 int regnum, void *buf, size_t size) const
1200 {
1201 transfer_regset (regset, NULL, regnum, NULL, buf, size);
1202 }
1203
1204
1205 /* Special handling for register PC. */
1206
1207 CORE_ADDR
1208 regcache_read_pc (struct regcache *regcache)
1209 {
1210 struct gdbarch *gdbarch = regcache->arch ();
1211
1212 CORE_ADDR pc_val;
1213
1214 if (gdbarch_read_pc_p (gdbarch))
1215 pc_val = gdbarch_read_pc (gdbarch, regcache);
1216 /* Else use per-frame method on get_current_frame. */
1217 else if (gdbarch_pc_regnum (gdbarch) >= 0)
1218 {
1219 ULONGEST raw_val;
1220
1221 if (regcache_cooked_read_unsigned (regcache,
1222 gdbarch_pc_regnum (gdbarch),
1223 &raw_val) == REG_UNAVAILABLE)
1224 throw_error (NOT_AVAILABLE_ERROR, _("PC register is not available"));
1225
1226 pc_val = gdbarch_addr_bits_remove (gdbarch, raw_val);
1227 }
1228 else
1229 internal_error (__FILE__, __LINE__,
1230 _("regcache_read_pc: Unable to find PC"));
1231 return pc_val;
1232 }
1233
1234 void
1235 regcache_write_pc (struct regcache *regcache, CORE_ADDR pc)
1236 {
1237 struct gdbarch *gdbarch = regcache->arch ();
1238
1239 if (gdbarch_write_pc_p (gdbarch))
1240 gdbarch_write_pc (gdbarch, regcache, pc);
1241 else if (gdbarch_pc_regnum (gdbarch) >= 0)
1242 regcache_cooked_write_unsigned (regcache,
1243 gdbarch_pc_regnum (gdbarch), pc);
1244 else
1245 internal_error (__FILE__, __LINE__,
1246 _("regcache_write_pc: Unable to update PC"));
1247
1248 /* Writing the PC (for instance, from "load") invalidates the
1249 current frame. */
1250 reinit_frame_cache ();
1251 }
1252
1253 int
1254 reg_buffer::num_raw_registers () const
1255 {
1256 return gdbarch_num_regs (arch ());
1257 }
1258
1259 void
1260 regcache::debug_print_register (const char *func, int regno)
1261 {
1262 struct gdbarch *gdbarch = arch ();
1263
1264 fprintf_unfiltered (gdb_stdlog, "%s ", func);
1265 if (regno >= 0 && regno < gdbarch_num_regs (gdbarch)
1266 && gdbarch_register_name (gdbarch, regno) != NULL
1267 && gdbarch_register_name (gdbarch, regno)[0] != '\0')
1268 fprintf_unfiltered (gdb_stdlog, "(%s)",
1269 gdbarch_register_name (gdbarch, regno));
1270 else
1271 fprintf_unfiltered (gdb_stdlog, "(%d)", regno);
1272 if (regno >= 0 && regno < gdbarch_num_regs (gdbarch))
1273 {
1274 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1275 int size = register_size (gdbarch, regno);
1276 gdb_byte *buf = register_buffer (regno);
1277
1278 fprintf_unfiltered (gdb_stdlog, " = ");
1279 for (int i = 0; i < size; i++)
1280 {
1281 fprintf_unfiltered (gdb_stdlog, "%02x", buf[i]);
1282 }
1283 if (size <= sizeof (LONGEST))
1284 {
1285 ULONGEST val = extract_unsigned_integer (buf, size, byte_order);
1286
1287 fprintf_unfiltered (gdb_stdlog, " %s %s",
1288 core_addr_to_string_nz (val), plongest (val));
1289 }
1290 }
1291 fprintf_unfiltered (gdb_stdlog, "\n");
1292 }
1293
1294 static void
1295 reg_flush_command (const char *command, int from_tty)
1296 {
1297 /* Force-flush the register cache. */
1298 registers_changed ();
1299 if (from_tty)
1300 printf_filtered (_("Register cache flushed.\n"));
1301 }
1302
1303 /* An abstract base class for register dump. */
1304
1305 class register_dump
1306 {
1307 public:
1308 void dump (ui_file *file)
1309 {
1310 auto descr = regcache_descr (m_gdbarch);
1311 int regnum;
1312 int footnote_nr = 0;
1313 int footnote_register_offset = 0;
1314 int footnote_register_type_name_null = 0;
1315 long register_offset = 0;
1316
1317 gdb_assert (descr->nr_cooked_registers
1318 == (gdbarch_num_regs (m_gdbarch)
1319 + gdbarch_num_pseudo_regs (m_gdbarch)));
1320
1321 for (regnum = -1; regnum < descr->nr_cooked_registers; regnum++)
1322 {
1323 /* Name. */
1324 if (regnum < 0)
1325 fprintf_unfiltered (file, " %-10s", "Name");
1326 else
1327 {
1328 const char *p = gdbarch_register_name (m_gdbarch, regnum);
1329
1330 if (p == NULL)
1331 p = "";
1332 else if (p[0] == '\0')
1333 p = "''";
1334 fprintf_unfiltered (file, " %-10s", p);
1335 }
1336
1337 /* Number. */
1338 if (regnum < 0)
1339 fprintf_unfiltered (file, " %4s", "Nr");
1340 else
1341 fprintf_unfiltered (file, " %4d", regnum);
1342
1343 /* Relative number. */
1344 if (regnum < 0)
1345 fprintf_unfiltered (file, " %4s", "Rel");
1346 else if (regnum < gdbarch_num_regs (m_gdbarch))
1347 fprintf_unfiltered (file, " %4d", regnum);
1348 else
1349 fprintf_unfiltered (file, " %4d",
1350 (regnum - gdbarch_num_regs (m_gdbarch)));
1351
1352 /* Offset. */
1353 if (regnum < 0)
1354 fprintf_unfiltered (file, " %6s ", "Offset");
1355 else
1356 {
1357 fprintf_unfiltered (file, " %6ld",
1358 descr->register_offset[regnum]);
1359 if (register_offset != descr->register_offset[regnum]
1360 || (regnum > 0
1361 && (descr->register_offset[regnum]
1362 != (descr->register_offset[regnum - 1]
1363 + descr->sizeof_register[regnum - 1])))
1364 )
1365 {
1366 if (!footnote_register_offset)
1367 footnote_register_offset = ++footnote_nr;
1368 fprintf_unfiltered (file, "*%d", footnote_register_offset);
1369 }
1370 else
1371 fprintf_unfiltered (file, " ");
1372 register_offset = (descr->register_offset[regnum]
1373 + descr->sizeof_register[regnum]);
1374 }
1375
1376 /* Size. */
1377 if (regnum < 0)
1378 fprintf_unfiltered (file, " %5s ", "Size");
1379 else
1380 fprintf_unfiltered (file, " %5ld", descr->sizeof_register[regnum]);
1381
1382 /* Type. */
1383 {
1384 const char *t;
1385 std::string name_holder;
1386
1387 if (regnum < 0)
1388 t = "Type";
1389 else
1390 {
1391 static const char blt[] = "builtin_type";
1392
1393 t = TYPE_NAME (register_type (m_gdbarch, regnum));
1394 if (t == NULL)
1395 {
1396 if (!footnote_register_type_name_null)
1397 footnote_register_type_name_null = ++footnote_nr;
1398 name_holder = string_printf ("*%d",
1399 footnote_register_type_name_null);
1400 t = name_holder.c_str ();
1401 }
1402 /* Chop a leading builtin_type. */
1403 if (startswith (t, blt))
1404 t += strlen (blt);
1405 }
1406 fprintf_unfiltered (file, " %-15s", t);
1407 }
1408
1409 /* Leading space always present. */
1410 fprintf_unfiltered (file, " ");
1411
1412 dump_reg (file, regnum);
1413
1414 fprintf_unfiltered (file, "\n");
1415 }
1416
1417 if (footnote_register_offset)
1418 fprintf_unfiltered (file, "*%d: Inconsistent register offsets.\n",
1419 footnote_register_offset);
1420 if (footnote_register_type_name_null)
1421 fprintf_unfiltered (file,
1422 "*%d: Register type's name NULL.\n",
1423 footnote_register_type_name_null);
1424 }
1425
1426 virtual ~register_dump () {};
1427
1428 protected:
1429 register_dump (gdbarch *arch)
1430 : m_gdbarch (arch)
1431 {}
1432
1433 /* Dump the register REGNUM contents. If REGNUM is -1, print the
1434 header. */
1435 virtual void dump_reg (ui_file *file, int regnum) = 0;
1436
1437 gdbarch *m_gdbarch;
1438 };
1439
1440 /* Dump registers from regcache, used for dump raw registers and
1441 cooked registers. */
1442
1443 class register_dump_regcache : public register_dump
1444 {
1445 public:
1446 register_dump_regcache (regcache *regcache, bool dump_pseudo)
1447 : register_dump (regcache->arch ()), m_regcache (regcache),
1448 m_dump_pseudo (dump_pseudo)
1449 {
1450 }
1451
1452 protected:
1453 void dump_reg (ui_file *file, int regnum) override
1454 {
1455 if (regnum < 0)
1456 {
1457 if (m_dump_pseudo)
1458 fprintf_unfiltered (file, "Cooked value");
1459 else
1460 fprintf_unfiltered (file, "Raw value");
1461 }
1462 else
1463 {
1464 if (regnum < gdbarch_num_regs (m_gdbarch) || m_dump_pseudo)
1465 {
1466 auto size = register_size (m_gdbarch, regnum);
1467
1468 if (size == 0)
1469 return;
1470
1471 gdb::def_vector<gdb_byte> buf (size);
1472 auto status = m_regcache->cooked_read (regnum, buf.data ());
1473
1474 if (status == REG_UNKNOWN)
1475 fprintf_unfiltered (file, "<invalid>");
1476 else if (status == REG_UNAVAILABLE)
1477 fprintf_unfiltered (file, "<unavailable>");
1478 else
1479 {
1480 print_hex_chars (file, buf.data (), size,
1481 gdbarch_byte_order (m_gdbarch), true);
1482 }
1483 }
1484 else
1485 {
1486 /* Just print "<cooked>" for pseudo register when
1487 regcache_dump_raw. */
1488 fprintf_unfiltered (file, "<cooked>");
1489 }
1490 }
1491 }
1492
1493 private:
1494 regcache *m_regcache;
1495
1496 /* Dump pseudo registers or not. */
1497 const bool m_dump_pseudo;
1498 };
1499
1500 /* Dump from reg_buffer, used when there is no thread or
1501 registers. */
1502
1503 class register_dump_reg_buffer : public register_dump, reg_buffer
1504 {
1505 public:
1506 register_dump_reg_buffer (gdbarch *gdbarch, bool dump_pseudo)
1507 : register_dump (gdbarch), reg_buffer (gdbarch, dump_pseudo)
1508 {
1509 }
1510
1511 protected:
1512 void dump_reg (ui_file *file, int regnum) override
1513 {
1514 if (regnum < 0)
1515 {
1516 if (m_has_pseudo)
1517 fprintf_unfiltered (file, "Cooked value");
1518 else
1519 fprintf_unfiltered (file, "Raw value");
1520 }
1521 else
1522 {
1523 if (regnum < gdbarch_num_regs (m_gdbarch) || m_has_pseudo)
1524 {
1525 auto size = register_size (m_gdbarch, regnum);
1526
1527 if (size == 0)
1528 return;
1529
1530 auto status = get_register_status (regnum);
1531
1532 gdb_assert (status != REG_VALID);
1533
1534 if (status == REG_UNKNOWN)
1535 fprintf_unfiltered (file, "<invalid>");
1536 else
1537 fprintf_unfiltered (file, "<unavailable>");
1538 }
1539 else
1540 {
1541 /* Just print "<cooked>" for pseudo register when
1542 regcache_dump_raw. */
1543 fprintf_unfiltered (file, "<cooked>");
1544 }
1545 }
1546 }
1547 };
1548
1549 /* For "maint print registers". */
1550
1551 class register_dump_none : public register_dump
1552 {
1553 public:
1554 register_dump_none (gdbarch *arch)
1555 : register_dump (arch)
1556 {}
1557
1558 protected:
1559 void dump_reg (ui_file *file, int regnum) override
1560 {}
1561 };
1562
1563 /* For "maint print remote-registers". */
1564
1565 class register_dump_remote : public register_dump
1566 {
1567 public:
1568 register_dump_remote (gdbarch *arch)
1569 : register_dump (arch)
1570 {}
1571
1572 protected:
1573 void dump_reg (ui_file *file, int regnum) override
1574 {
1575 if (regnum < 0)
1576 {
1577 fprintf_unfiltered (file, "Rmt Nr g/G Offset");
1578 }
1579 else if (regnum < gdbarch_num_regs (m_gdbarch))
1580 {
1581 int pnum, poffset;
1582
1583 if (remote_register_number_and_offset (m_gdbarch, regnum,
1584 &pnum, &poffset))
1585 fprintf_unfiltered (file, "%7d %11d", pnum, poffset);
1586 }
1587 }
1588 };
1589
1590 /* For "maint print register-groups". */
1591
1592 class register_dump_groups : public register_dump
1593 {
1594 public:
1595 register_dump_groups (gdbarch *arch)
1596 : register_dump (arch)
1597 {}
1598
1599 protected:
1600 void dump_reg (ui_file *file, int regnum) override
1601 {
1602 if (regnum < 0)
1603 fprintf_unfiltered (file, "Groups");
1604 else
1605 {
1606 const char *sep = "";
1607 struct reggroup *group;
1608
1609 for (group = reggroup_next (m_gdbarch, NULL);
1610 group != NULL;
1611 group = reggroup_next (m_gdbarch, group))
1612 {
1613 if (gdbarch_register_reggroup_p (m_gdbarch, regnum, group))
1614 {
1615 fprintf_unfiltered (file,
1616 "%s%s", sep, reggroup_name (group));
1617 sep = ",";
1618 }
1619 }
1620 }
1621 }
1622 };
1623
1624 enum regcache_dump_what
1625 {
1626 regcache_dump_none, regcache_dump_raw,
1627 regcache_dump_cooked, regcache_dump_groups,
1628 regcache_dump_remote
1629 };
1630
1631 static void
1632 regcache_print (const char *args, enum regcache_dump_what what_to_dump)
1633 {
1634 /* Where to send output. */
1635 stdio_file file;
1636 ui_file *out;
1637
1638 if (args == NULL)
1639 out = gdb_stdout;
1640 else
1641 {
1642 if (!file.open (args, "w"))
1643 perror_with_name (_("maintenance print architecture"));
1644 out = &file;
1645 }
1646
1647 std::unique_ptr<register_dump> dump;
1648 std::unique_ptr<regcache> regs;
1649 gdbarch *gdbarch;
1650
1651 if (target_has_registers)
1652 gdbarch = get_current_regcache ()->arch ();
1653 else
1654 gdbarch = target_gdbarch ();
1655
1656 switch (what_to_dump)
1657 {
1658 case regcache_dump_none:
1659 dump.reset (new register_dump_none (gdbarch));
1660 break;
1661 case regcache_dump_remote:
1662 dump.reset (new register_dump_remote (gdbarch));
1663 break;
1664 case regcache_dump_groups:
1665 dump.reset (new register_dump_groups (gdbarch));
1666 break;
1667 case regcache_dump_raw:
1668 case regcache_dump_cooked:
1669 {
1670 auto dump_pseudo = (what_to_dump == regcache_dump_cooked);
1671
1672 if (target_has_registers)
1673 dump.reset (new register_dump_regcache (get_current_regcache (),
1674 dump_pseudo));
1675 else
1676 {
1677 /* For the benefit of "maint print registers" & co when
1678 debugging an executable, allow dumping a regcache even when
1679 there is no thread selected / no registers. */
1680 dump.reset (new register_dump_reg_buffer (target_gdbarch (),
1681 dump_pseudo));
1682 }
1683 }
1684 break;
1685 }
1686
1687 dump->dump (out);
1688 }
1689
1690 static void
1691 maintenance_print_registers (const char *args, int from_tty)
1692 {
1693 regcache_print (args, regcache_dump_none);
1694 }
1695
1696 static void
1697 maintenance_print_raw_registers (const char *args, int from_tty)
1698 {
1699 regcache_print (args, regcache_dump_raw);
1700 }
1701
1702 static void
1703 maintenance_print_cooked_registers (const char *args, int from_tty)
1704 {
1705 regcache_print (args, regcache_dump_cooked);
1706 }
1707
1708 static void
1709 maintenance_print_register_groups (const char *args, int from_tty)
1710 {
1711 regcache_print (args, regcache_dump_groups);
1712 }
1713
1714 static void
1715 maintenance_print_remote_registers (const char *args, int from_tty)
1716 {
1717 regcache_print (args, regcache_dump_remote);
1718 }
1719
1720 #if GDB_SELF_TEST
1721 #include "selftest.h"
1722 #include "selftest-arch.h"
1723 #include "gdbthread.h"
1724 #include "target-float.h"
1725
1726 namespace selftests {
1727
1728 class regcache_access : public regcache
1729 {
1730 public:
1731
1732 /* Return the number of elements in current_regcache. */
1733
1734 static size_t
1735 current_regcache_size ()
1736 {
1737 return std::distance (regcache::current_regcache.begin (),
1738 regcache::current_regcache.end ());
1739 }
1740 };
1741
1742 static void
1743 current_regcache_test (void)
1744 {
1745 /* It is empty at the start. */
1746 SELF_CHECK (regcache_access::current_regcache_size () == 0);
1747
1748 ptid_t ptid1 (1), ptid2 (2), ptid3 (3);
1749
1750 /* Get regcache from ptid1, a new regcache is added to
1751 current_regcache. */
1752 regcache *regcache = get_thread_arch_aspace_regcache (ptid1,
1753 target_gdbarch (),
1754 NULL);
1755
1756 SELF_CHECK (regcache != NULL);
1757 SELF_CHECK (regcache->ptid () == ptid1);
1758 SELF_CHECK (regcache_access::current_regcache_size () == 1);
1759
1760 /* Get regcache from ptid2, a new regcache is added to
1761 current_regcache. */
1762 regcache = get_thread_arch_aspace_regcache (ptid2,
1763 target_gdbarch (),
1764 NULL);
1765 SELF_CHECK (regcache != NULL);
1766 SELF_CHECK (regcache->ptid () == ptid2);
1767 SELF_CHECK (regcache_access::current_regcache_size () == 2);
1768
1769 /* Get regcache from ptid3, a new regcache is added to
1770 current_regcache. */
1771 regcache = get_thread_arch_aspace_regcache (ptid3,
1772 target_gdbarch (),
1773 NULL);
1774 SELF_CHECK (regcache != NULL);
1775 SELF_CHECK (regcache->ptid () == ptid3);
1776 SELF_CHECK (regcache_access::current_regcache_size () == 3);
1777
1778 /* Get regcache from ptid2 again, nothing is added to
1779 current_regcache. */
1780 regcache = get_thread_arch_aspace_regcache (ptid2,
1781 target_gdbarch (),
1782 NULL);
1783 SELF_CHECK (regcache != NULL);
1784 SELF_CHECK (regcache->ptid () == ptid2);
1785 SELF_CHECK (regcache_access::current_regcache_size () == 3);
1786
1787 /* Mark ptid2 is changed, so regcache of ptid2 should be removed from
1788 current_regcache. */
1789 registers_changed_ptid (ptid2);
1790 SELF_CHECK (regcache_access::current_regcache_size () == 2);
1791 }
1792
1793 static void test_target_fetch_registers (target_ops *self, regcache *regs,
1794 int regno);
1795 static void test_target_store_registers (target_ops *self, regcache *regs,
1796 int regno);
1797 static enum target_xfer_status
1798 test_target_xfer_partial (struct target_ops *ops,
1799 enum target_object object,
1800 const char *annex, gdb_byte *readbuf,
1801 const gdb_byte *writebuf,
1802 ULONGEST offset, ULONGEST len,
1803 ULONGEST *xfered_len);
1804
1805 class target_ops_no_register : public test_target_ops
1806 {
1807 public:
1808 target_ops_no_register ()
1809 : test_target_ops {}
1810 {
1811 to_fetch_registers = test_target_fetch_registers;
1812 to_store_registers = test_target_store_registers;
1813 to_xfer_partial = test_target_xfer_partial;
1814
1815 to_data = this;
1816 }
1817
1818 void reset ()
1819 {
1820 fetch_registers_called = 0;
1821 store_registers_called = 0;
1822 xfer_partial_called = 0;
1823 }
1824
1825 unsigned int fetch_registers_called = 0;
1826 unsigned int store_registers_called = 0;
1827 unsigned int xfer_partial_called = 0;
1828 };
1829
1830 static void
1831 test_target_fetch_registers (target_ops *self, regcache *regs, int regno)
1832 {
1833 auto ops = static_cast<target_ops_no_register *> (self->to_data);
1834
1835 /* Mark register available. */
1836 regs->raw_supply_zeroed (regno);
1837 ops->fetch_registers_called++;
1838 }
1839
1840 static void
1841 test_target_store_registers (target_ops *self, regcache *regs, int regno)
1842 {
1843 auto ops = static_cast<target_ops_no_register *> (self->to_data);
1844
1845 ops->store_registers_called++;
1846 }
1847
1848 static enum target_xfer_status
1849 test_target_xfer_partial (struct target_ops *self, enum target_object object,
1850 const char *annex, gdb_byte *readbuf,
1851 const gdb_byte *writebuf,
1852 ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
1853 {
1854 auto ops = static_cast<target_ops_no_register *> (self->to_data);
1855
1856 ops->xfer_partial_called++;
1857
1858 *xfered_len = len;
1859 return TARGET_XFER_OK;
1860 }
1861
1862 class readwrite_regcache : public regcache
1863 {
1864 public:
1865 readwrite_regcache (struct gdbarch *gdbarch)
1866 : regcache (gdbarch, nullptr)
1867 {}
1868 };
1869
1870 /* Test regcache::cooked_read gets registers from raw registers and
1871 memory instead of target to_{fetch,store}_registers. */
1872
1873 static void
1874 cooked_read_test (struct gdbarch *gdbarch)
1875 {
1876 /* Error out if debugging something, because we're going to push the
1877 test target, which would pop any existing target. */
1878 if (current_target.to_stratum >= process_stratum)
1879 error (_("target already pushed"));
1880
1881 /* Create a mock environment. An inferior with a thread, with a
1882 process_stratum target pushed. */
1883
1884 target_ops_no_register mock_target;
1885 ptid_t mock_ptid (1, 1);
1886 inferior mock_inferior (mock_ptid.pid ());
1887 address_space mock_aspace {};
1888 mock_inferior.gdbarch = gdbarch;
1889 mock_inferior.aspace = &mock_aspace;
1890 thread_info mock_thread (&mock_inferior, mock_ptid);
1891
1892 scoped_restore restore_thread_list
1893 = make_scoped_restore (&thread_list, &mock_thread);
1894
1895 /* Add the mock inferior to the inferior list so that look ups by
1896 target+ptid can find it. */
1897 scoped_restore restore_inferior_list
1898 = make_scoped_restore (&inferior_list);
1899 inferior_list = &mock_inferior;
1900
1901 /* Switch to the mock inferior. */
1902 scoped_restore_current_inferior restore_current_inferior;
1903 set_current_inferior (&mock_inferior);
1904
1905 /* Push the process_stratum target so we can mock accessing
1906 registers. */
1907 push_target (&mock_target);
1908
1909 /* Pop it again on exit (return/exception). */
1910 struct on_exit
1911 {
1912 ~on_exit ()
1913 {
1914 pop_all_targets_at_and_above (process_stratum);
1915 }
1916 } pop_targets;
1917
1918 /* Switch to the mock thread. */
1919 scoped_restore restore_inferior_ptid
1920 = make_scoped_restore (&inferior_ptid, mock_ptid);
1921
1922 /* Test that read one raw register from regcache_no_target will go
1923 to the target layer. */
1924 int regnum;
1925
1926 /* Find a raw register which size isn't zero. */
1927 for (regnum = 0; regnum < gdbarch_num_regs (gdbarch); regnum++)
1928 {
1929 if (register_size (gdbarch, regnum) != 0)
1930 break;
1931 }
1932
1933 readwrite_regcache readwrite (gdbarch);
1934 gdb::def_vector<gdb_byte> buf (register_size (gdbarch, regnum));
1935
1936 readwrite.raw_read (regnum, buf.data ());
1937
1938 /* raw_read calls target_fetch_registers. */
1939 SELF_CHECK (mock_target.fetch_registers_called > 0);
1940 mock_target.reset ();
1941
1942 /* Mark all raw registers valid, so the following raw registers
1943 accesses won't go to target. */
1944 for (auto i = 0; i < gdbarch_num_regs (gdbarch); i++)
1945 readwrite.raw_update (i);
1946
1947 mock_target.reset ();
1948 /* Then, read all raw and pseudo registers, and don't expect calling
1949 to_{fetch,store}_registers. */
1950 for (int regnum = 0;
1951 regnum < gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch);
1952 regnum++)
1953 {
1954 if (register_size (gdbarch, regnum) == 0)
1955 continue;
1956
1957 gdb::def_vector<gdb_byte> buf (register_size (gdbarch, regnum));
1958
1959 SELF_CHECK (REG_VALID == readwrite.cooked_read (regnum, buf.data ()));
1960
1961 SELF_CHECK (mock_target.fetch_registers_called == 0);
1962 SELF_CHECK (mock_target.store_registers_called == 0);
1963
1964 /* Some SPU pseudo registers are got via TARGET_OBJECT_SPU. */
1965 if (gdbarch_bfd_arch_info (gdbarch)->arch != bfd_arch_spu)
1966 SELF_CHECK (mock_target.xfer_partial_called == 0);
1967
1968 mock_target.reset ();
1969 }
1970
1971 readonly_detached_regcache readonly (readwrite);
1972
1973 /* GDB may go to target layer to fetch all registers and memory for
1974 readonly regcache. */
1975 mock_target.reset ();
1976
1977 for (int regnum = 0;
1978 regnum < gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch);
1979 regnum++)
1980 {
1981 if (register_size (gdbarch, regnum) == 0)
1982 continue;
1983
1984 gdb::def_vector<gdb_byte> buf (register_size (gdbarch, regnum));
1985 enum register_status status = readonly.cooked_read (regnum,
1986 buf.data ());
1987
1988 if (regnum < gdbarch_num_regs (gdbarch))
1989 {
1990 auto bfd_arch = gdbarch_bfd_arch_info (gdbarch)->arch;
1991
1992 if (bfd_arch == bfd_arch_frv || bfd_arch == bfd_arch_h8300
1993 || bfd_arch == bfd_arch_m32c || bfd_arch == bfd_arch_sh
1994 || bfd_arch == bfd_arch_alpha || bfd_arch == bfd_arch_v850
1995 || bfd_arch == bfd_arch_msp430 || bfd_arch == bfd_arch_mep
1996 || bfd_arch == bfd_arch_mips || bfd_arch == bfd_arch_v850_rh850
1997 || bfd_arch == bfd_arch_tic6x || bfd_arch == bfd_arch_mn10300
1998 || bfd_arch == bfd_arch_rl78 || bfd_arch == bfd_arch_score)
1999 {
2000 /* Raw registers. If raw registers are not in save_reggroup,
2001 their status are unknown. */
2002 if (gdbarch_register_reggroup_p (gdbarch, regnum, save_reggroup))
2003 SELF_CHECK (status == REG_VALID);
2004 else
2005 SELF_CHECK (status == REG_UNKNOWN);
2006 }
2007 else
2008 SELF_CHECK (status == REG_VALID);
2009 }
2010 else
2011 {
2012 if (gdbarch_register_reggroup_p (gdbarch, regnum, save_reggroup))
2013 SELF_CHECK (status == REG_VALID);
2014 else
2015 {
2016 /* If pseudo registers are not in save_reggroup, some of
2017 them can be computed from saved raw registers, but some
2018 of them are unknown. */
2019 auto bfd_arch = gdbarch_bfd_arch_info (gdbarch)->arch;
2020
2021 if (bfd_arch == bfd_arch_frv
2022 || bfd_arch == bfd_arch_m32c
2023 || bfd_arch == bfd_arch_mep
2024 || bfd_arch == bfd_arch_sh)
2025 SELF_CHECK (status == REG_VALID || status == REG_UNKNOWN);
2026 else if (bfd_arch == bfd_arch_mips
2027 || bfd_arch == bfd_arch_h8300)
2028 SELF_CHECK (status == REG_UNKNOWN);
2029 else
2030 SELF_CHECK (status == REG_VALID);
2031 }
2032 }
2033
2034 SELF_CHECK (mock_target.fetch_registers_called == 0);
2035 SELF_CHECK (mock_target.store_registers_called == 0);
2036 SELF_CHECK (mock_target.xfer_partial_called == 0);
2037
2038 mock_target.reset ();
2039 }
2040 }
2041
2042 /* Test regcache::cooked_write by writing some expected contents to
2043 registers, and checking that contents read from registers and the
2044 expected contents are the same. */
2045
2046 static void
2047 cooked_write_test (struct gdbarch *gdbarch)
2048 {
2049 /* Error out if debugging something, because we're going to push the
2050 test target, which would pop any existing target. */
2051 if (current_target.to_stratum >= process_stratum)
2052 error (_("target already pushed"));
2053
2054 /* Create a mock environment. A process_stratum target pushed. */
2055
2056 target_ops_no_register mock_target;
2057
2058 /* Push the process_stratum target so we can mock accessing
2059 registers. */
2060 push_target (&mock_target);
2061
2062 /* Pop it again on exit (return/exception). */
2063 struct on_exit
2064 {
2065 ~on_exit ()
2066 {
2067 pop_all_targets_at_and_above (process_stratum);
2068 }
2069 } pop_targets;
2070
2071 readwrite_regcache readwrite (gdbarch);
2072
2073 const int num_regs = (gdbarch_num_regs (gdbarch)
2074 + gdbarch_num_pseudo_regs (gdbarch));
2075
2076 for (auto regnum = 0; regnum < num_regs; regnum++)
2077 {
2078 if (register_size (gdbarch, regnum) == 0
2079 || gdbarch_cannot_store_register (gdbarch, regnum))
2080 continue;
2081
2082 auto bfd_arch = gdbarch_bfd_arch_info (gdbarch)->arch;
2083
2084 if ((bfd_arch == bfd_arch_sparc
2085 /* SPARC64_CWP_REGNUM, SPARC64_PSTATE_REGNUM,
2086 SPARC64_ASI_REGNUM and SPARC64_CCR_REGNUM are hard to test. */
2087 && gdbarch_ptr_bit (gdbarch) == 64
2088 && (regnum >= gdbarch_num_regs (gdbarch)
2089 && regnum <= gdbarch_num_regs (gdbarch) + 4))
2090 || (bfd_arch == bfd_arch_sh
2091 /* FPSCR_C_REGNUM in sh64 is hard to test. */
2092 && gdbarch_bfd_arch_info (gdbarch)->mach == bfd_mach_sh5
2093 && regnum == 243)
2094 || (bfd_arch == bfd_arch_spu
2095 /* SPU pseudo registers except SPU_SP_REGNUM are got by
2096 TARGET_OBJECT_SPU. */
2097 && regnum >= gdbarch_num_regs (gdbarch) && regnum != 130))
2098 continue;
2099
2100 std::vector<gdb_byte> expected (register_size (gdbarch, regnum), 0);
2101 std::vector<gdb_byte> buf (register_size (gdbarch, regnum), 0);
2102 const auto type = register_type (gdbarch, regnum);
2103
2104 if (TYPE_CODE (type) == TYPE_CODE_FLT
2105 || TYPE_CODE (type) == TYPE_CODE_DECFLOAT)
2106 {
2107 /* Generate valid float format. */
2108 target_float_from_string (expected.data (), type, "1.25");
2109 }
2110 else if (TYPE_CODE (type) == TYPE_CODE_INT
2111 || TYPE_CODE (type) == TYPE_CODE_ARRAY
2112 || TYPE_CODE (type) == TYPE_CODE_PTR
2113 || TYPE_CODE (type) == TYPE_CODE_UNION
2114 || TYPE_CODE (type) == TYPE_CODE_STRUCT)
2115 {
2116 if (bfd_arch == bfd_arch_ia64
2117 || (regnum >= gdbarch_num_regs (gdbarch)
2118 && (bfd_arch == bfd_arch_xtensa
2119 || bfd_arch == bfd_arch_bfin
2120 || bfd_arch == bfd_arch_m32c
2121 /* m68hc11 pseudo registers are in memory. */
2122 || bfd_arch == bfd_arch_m68hc11
2123 || bfd_arch == bfd_arch_m68hc12
2124 || bfd_arch == bfd_arch_s390))
2125 || (bfd_arch == bfd_arch_frv
2126 /* FRV pseudo registers except iacc0. */
2127 && regnum > gdbarch_num_regs (gdbarch)))
2128 {
2129 /* Skip setting the expected values for some architecture
2130 registers. */
2131 }
2132 else if (bfd_arch == bfd_arch_rl78 && regnum == 40)
2133 {
2134 /* RL78_PC_REGNUM */
2135 for (auto j = 0; j < register_size (gdbarch, regnum) - 1; j++)
2136 expected[j] = j;
2137 }
2138 else
2139 {
2140 for (auto j = 0; j < register_size (gdbarch, regnum); j++)
2141 expected[j] = j;
2142 }
2143 }
2144 else if (TYPE_CODE (type) == TYPE_CODE_FLAGS)
2145 {
2146 /* No idea how to test flags. */
2147 continue;
2148 }
2149 else
2150 {
2151 /* If we don't know how to create the expected value for the
2152 this type, make it fail. */
2153 SELF_CHECK (0);
2154 }
2155
2156 readwrite.cooked_write (regnum, expected.data ());
2157
2158 SELF_CHECK (readwrite.cooked_read (regnum, buf.data ()) == REG_VALID);
2159 SELF_CHECK (expected == buf);
2160 }
2161 }
2162
2163 } // namespace selftests
2164 #endif /* GDB_SELF_TEST */
2165
2166 void
2167 _initialize_regcache (void)
2168 {
2169 regcache_descr_handle
2170 = gdbarch_data_register_post_init (init_regcache_descr);
2171
2172 observer_attach_target_changed (regcache_observer_target_changed);
2173 observer_attach_thread_ptid_changed (regcache::regcache_thread_ptid_changed);
2174
2175 add_com ("flushregs", class_maintenance, reg_flush_command,
2176 _("Force gdb to flush its register cache (maintainer command)"));
2177
2178 add_cmd ("registers", class_maintenance, maintenance_print_registers,
2179 _("Print the internal register configuration.\n"
2180 "Takes an optional file parameter."), &maintenanceprintlist);
2181 add_cmd ("raw-registers", class_maintenance,
2182 maintenance_print_raw_registers,
2183 _("Print the internal register configuration "
2184 "including raw values.\n"
2185 "Takes an optional file parameter."), &maintenanceprintlist);
2186 add_cmd ("cooked-registers", class_maintenance,
2187 maintenance_print_cooked_registers,
2188 _("Print the internal register configuration "
2189 "including cooked values.\n"
2190 "Takes an optional file parameter."), &maintenanceprintlist);
2191 add_cmd ("register-groups", class_maintenance,
2192 maintenance_print_register_groups,
2193 _("Print the internal register configuration "
2194 "including each register's group.\n"
2195 "Takes an optional file parameter."),
2196 &maintenanceprintlist);
2197 add_cmd ("remote-registers", class_maintenance,
2198 maintenance_print_remote_registers, _("\
2199 Print the internal register configuration including each register's\n\
2200 remote register number and buffer offset in the g/G packets.\n\
2201 Takes an optional file parameter."),
2202 &maintenanceprintlist);
2203
2204 #if GDB_SELF_TEST
2205 selftests::register_test ("current_regcache", selftests::current_regcache_test);
2206
2207 selftests::register_test_foreach_arch ("regcache::cooked_read_test",
2208 selftests::cooked_read_test);
2209 selftests::register_test_foreach_arch ("regcache::cooked_write_test",
2210 selftests::cooked_write_test);
2211 #endif
2212 }
This page took 0.140283 seconds and 5 git commands to generate.