GDB (xrefs)
Loading...
Searching...
No Matches
record-full.c
Go to the documentation of this file.
1/* Process record and replay target for GDB, the GNU debugger.
2
3 Copyright (C) 2013-2023 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 "gdbcmd.h"
22#include "regcache.h"
23#include "gdbthread.h"
24#include "inferior.h"
25#include "event-top.h"
26#include "completer.h"
27#include "arch-utils.h"
28#include "gdbcore.h"
29#include "exec.h"
30#include "record.h"
31#include "record-full.h"
32#include "elf-bfd.h"
33#include "gcore.h"
34#include "gdbsupport/event-loop.h"
35#include "inf-loop.h"
36#include "gdb_bfd.h"
37#include "observable.h"
38#include "infrun.h"
39#include "gdbsupport/gdb_unlinker.h"
40#include "gdbsupport/byte-vector.h"
41#include "async-event.h"
42#include "valprint.h"
43#include "interps.h"
44
45#include <signal.h>
46
47/* This module implements "target record-full", also known as "process
48 record and replay". This target sits on top of a "normal" target
49 (a target that "has execution"), and provides a record and replay
50 functionality, including reverse debugging.
51
52 Target record has two modes: recording, and replaying.
53
54 In record mode, we intercept the resume and wait methods.
55 Whenever gdb resumes the target, we run the target in single step
56 mode, and we build up an execution log in which, for each executed
57 instruction, we record all changes in memory and register state.
58 This is invisible to the user, to whom it just looks like an
59 ordinary debugging session (except for performance degradation).
60
61 In replay mode, instead of actually letting the inferior run as a
62 process, we simulate its execution by playing back the recorded
63 execution log. For each instruction in the log, we simulate the
64 instruction's side effects by duplicating the changes that it would
65 have made on memory and registers. */
66
67#define DEFAULT_RECORD_FULL_INSN_MAX_NUM 200000
68
69#define RECORD_FULL_IS_REPLAY \
70 (record_full_list->next || ::execution_direction == EXEC_REVERSE)
71
72#define RECORD_FULL_FILE_MAGIC netorder32(0x20091016)
73
74/* These are the core structs of the process record functionality.
75
76 A record_full_entry is a record of the value change of a register
77 ("record_full_reg") or a part of memory ("record_full_mem"). And each
78 instruction must have a struct record_full_entry ("record_full_end")
79 that indicates that this is the last struct record_full_entry of this
80 instruction.
81
82 Each struct record_full_entry is linked to "record_full_list" by "prev"
83 and "next" pointers. */
84
86{
87 CORE_ADDR addr;
88 int len;
89 /* Set this flag if target memory for this entry
90 can no longer be accessed. */
92 union
93 {
94 gdb_byte *ptr;
95 gdb_byte buf[sizeof (gdb_byte *)];
96 } u;
97};
98
100{
101 unsigned short num;
102 unsigned short len;
103 union
104 {
105 gdb_byte *ptr;
106 gdb_byte buf[2 * sizeof (gdb_byte *)];
107 } u;
108};
109
111{
112 enum gdb_signal sigval;
113 ULONGEST insn_num;
114};
115
122
123/* This is the data structure that makes up the execution log.
124
125 The execution log consists of a single linked list of entries
126 of type "struct record_full_entry". It is doubly linked so that it
127 can be traversed in either direction.
128
129 The start of the list is anchored by a struct called
130 "record_full_first". The pointer "record_full_list" either points
131 to the last entry that was added to the list (in record mode), or to
132 the next entry in the list that will be executed (in replay mode).
133
134 Each list element (struct record_full_entry), in addition to next
135 and prev pointers, consists of a union of three entry types: mem,
136 reg, and end. A field called "type" determines which entry type is
137 represented by a given list element.
138
139 Each instruction that is added to the execution log is represented
140 by a variable number of list elements ('entries'). The instruction
141 will have one "reg" entry for each register that is changed by
142 executing the instruction (including the PC in every case). It
143 will also have one "mem" entry for each memory change. Finally,
144 each instruction will have an "end" entry that separates it from
145 the changes associated with the next instruction. */
146
148{
152 union
153 {
154 /* reg */
156 /* mem */
158 /* end */
160 } u;
161};
162
163/* If true, query if PREC cannot record memory
164 change of next instruction. */
166
173
174/* Record buf with core target. */
178
179/* The following variables are used for managing the linked list that
180 represents the execution log.
181
182 record_full_first is the anchor that holds down the beginning of
183 the list.
184
185 record_full_list serves two functions:
186 1) In record mode, it anchors the end of the list.
187 2) In replay mode, it traverses the list and points to
188 the next instruction that must be emulated.
189
190 record_full_arch_list_head and record_full_arch_list_tail are used
191 to manage a separate list, which is used to build up the change
192 elements of the currently executing instruction during record mode.
193 When this instruction has been completely annotated in the "arch
194 list", it will be appended to the main execution log. */
195
200
201/* true ask user. false auto delete the last struct record_full_entry. */
202static bool record_full_stop_at_limit = true;
203/* Maximum allowed number of insns in execution log. */
204static unsigned int record_full_insn_max_num
206/* Actual count of insns presently in execution log. */
207static unsigned int record_full_insn_num = 0;
208/* Count of insns logged so far (may be larger
209 than count of insns presently in execution log). */
211
212static const char record_longname[]
213 = N_("Process record and replay target");
214static const char record_doc[]
215 = N_("Log program while executing and replay execution from log.");
216
217/* Base class implementing functionality common to both the
218 "record-full" and "record-core" targets. */
219
221{
222public:
223 const target_info &info () const override = 0;
224
225 strata stratum () const override { return record_stratum; }
226
227 void close () override;
228 void async (bool) override;
229 ptid_t wait (ptid_t, struct target_waitstatus *, target_wait_flags) override;
230 bool stopped_by_watchpoint () override;
231 bool stopped_data_address (CORE_ADDR *) override;
232
233 bool stopped_by_sw_breakpoint () override;
234 bool supports_stopped_by_sw_breakpoint () override;
235
236 bool stopped_by_hw_breakpoint () override;
237 bool supports_stopped_by_hw_breakpoint () override;
238
239 bool can_execute_reverse () override;
240
241 /* Add bookmark target methods. */
242 gdb_byte *get_bookmark (const char *, int) override;
243 void goto_bookmark (const gdb_byte *, int) override;
245 enum record_method record_method (ptid_t ptid) override;
246 void info_record () override;
247 void save_record (const char *filename) override;
248 bool supports_delete_record () override;
249 void delete_record () override;
250 bool record_is_replaying (ptid_t ptid) override;
251 bool record_will_replay (ptid_t ptid, int dir) override;
252 void record_stop_replaying () override;
253 void goto_record_begin () override;
254 void goto_record_end () override;
255 void goto_record (ULONGEST insn) override;
256};
257
258/* The "record-full" target. */
259
261 "record-full",
264};
265
267{
268public:
269 const target_info &info () const override
270 { return record_full_target_info; }
271
272 void resume (ptid_t, int, enum gdb_signal) override;
273 void disconnect (const char *, int) override;
274 void detach (inferior *, int) override;
275 void mourn_inferior () override;
276 void kill () override;
277 void store_registers (struct regcache *, int) override;
279 const char *annex,
280 gdb_byte *readbuf,
281 const gdb_byte *writebuf,
282 ULONGEST offset, ULONGEST len,
283 ULONGEST *xfered_len) override;
284 int insert_breakpoint (struct gdbarch *,
285 struct bp_target_info *) override;
286 int remove_breakpoint (struct gdbarch *,
287 struct bp_target_info *,
288 enum remove_bp_reason) override;
289};
290
291/* The "record-core" target. */
292
294 "record-core",
297};
298
300{
301public:
302 const target_info &info () const override
304
305 void resume (ptid_t, int, enum gdb_signal) override;
306 void disconnect (const char *, int) override;
307 void kill () override;
308 void fetch_registers (struct regcache *regcache, int regno) override;
309 void prepare_to_store (struct regcache *regcache) override;
310 void store_registers (struct regcache *, int) override;
312 const char *annex,
313 gdb_byte *readbuf,
314 const gdb_byte *writebuf,
315 ULONGEST offset, ULONGEST len,
316 ULONGEST *xfered_len) override;
317 int insert_breakpoint (struct gdbarch *,
318 struct bp_target_info *) override;
319 int remove_breakpoint (struct gdbarch *,
320 struct bp_target_info *,
321 enum remove_bp_reason) override;
322
323 bool has_execution (inferior *inf) override;
324};
325
328
329void
331{
332 record_detach (this, inf, from_tty);
333}
334
335void
336record_full_target::disconnect (const char *args, int from_tty)
337{
338 record_disconnect (this, args, from_tty);
339}
340
341void
342record_full_core_target::disconnect (const char *args, int from_tty)
343{
344 record_disconnect (this, args, from_tty);
345}
346
347void
352
353void
355{
356 record_kill (this);
357}
358
359/* See record-full.h. */
360
361int
363{
364 struct target_ops *t;
365
366 t = find_record_target ();
367 return (t == &record_full_ops
368 || t == &record_full_core_ops);
369}
370
371
372/* Command lists for "set/show record full". */
375
376/* Command list for "record full". */
378
379static void record_full_goto_insn (struct record_full_entry *entry,
380 enum exec_direction_kind dir);
381
382/* Alloc and free functions for record_full_reg, record_full_mem, and
383 record_full_end entries. */
384
385/* Alloc a record_full_reg record entry. */
386
387static inline struct record_full_entry *
389{
390 struct record_full_entry *rec;
391 struct gdbarch *gdbarch = regcache->arch ();
392
393 rec = XCNEW (struct record_full_entry);
394 rec->type = record_full_reg;
395 rec->u.reg.num = regnum;
397 if (rec->u.reg.len > sizeof (rec->u.reg.u.buf))
398 rec->u.reg.u.ptr = (gdb_byte *) xmalloc (rec->u.reg.len);
399
400 return rec;
401}
402
403/* Free a record_full_reg record entry. */
404
405static inline void
407{
408 gdb_assert (rec->type == record_full_reg);
409 if (rec->u.reg.len > sizeof (rec->u.reg.u.buf))
410 xfree (rec->u.reg.u.ptr);
411 xfree (rec);
412}
413
414/* Alloc a record_full_mem record entry. */
415
416static inline struct record_full_entry *
417record_full_mem_alloc (CORE_ADDR addr, int len)
418{
419 struct record_full_entry *rec;
420
421 rec = XCNEW (struct record_full_entry);
422 rec->type = record_full_mem;
423 rec->u.mem.addr = addr;
424 rec->u.mem.len = len;
425 if (rec->u.mem.len > sizeof (rec->u.mem.u.buf))
426 rec->u.mem.u.ptr = (gdb_byte *) xmalloc (len);
427
428 return rec;
429}
430
431/* Free a record_full_mem record entry. */
432
433static inline void
435{
436 gdb_assert (rec->type == record_full_mem);
437 if (rec->u.mem.len > sizeof (rec->u.mem.u.buf))
438 xfree (rec->u.mem.u.ptr);
439 xfree (rec);
440}
441
442/* Alloc a record_full_end record entry. */
443
444static inline struct record_full_entry *
446{
447 struct record_full_entry *rec;
448
449 rec = XCNEW (struct record_full_entry);
450 rec->type = record_full_end;
451
452 return rec;
453}
454
455/* Free a record_full_end record entry. */
456
457static inline void
459{
460 xfree (rec);
461}
462
463/* Free one record entry, any type.
464 Return entry->type, in case caller wants to know. */
465
466static inline enum record_full_type
468{
469 enum record_full_type type = rec->type;
470
471 switch (type) {
472 case record_full_reg:
474 break;
475 case record_full_mem:
477 break;
478 case record_full_end:
480 break;
481 }
482 return type;
483}
484
485/* Free all record entries in list pointed to by REC. */
486
487static void
489{
490 if (!rec)
491 return;
492
493 while (rec->next)
494 rec = rec->next;
495
496 while (rec->prev)
497 {
498 rec = rec->prev;
500 }
501
502 if (rec == &record_full_first)
503 {
505 record_full_first.next = NULL;
506 }
507 else
509}
510
511/* Free all record entries forward of the given list position. */
512
513static void
515{
516 struct record_full_entry *tmp = rec->next;
517
518 rec->next = NULL;
519 while (tmp)
520 {
521 rec = tmp->next;
523 {
526 }
527 tmp = rec;
528 }
529}
530
531/* Delete the first instruction from the beginning of the log, to make
532 room for adding a new instruction at the end of the log.
533
534 Note -- this function does not modify record_full_insn_num. */
535
536static void
538{
539 struct record_full_entry *tmp;
540
542 return;
543
544 /* Loop until a record_full_end. */
545 while (1)
546 {
547 /* Cut record_full_first.next out of the linked list. */
550 tmp->next->prev = &record_full_first;
551
552 /* tmp is now isolated, and can be deleted. */
554 break; /* End loop at first record_full_end. */
555
557 {
558 gdb_assert (record_full_insn_num == 1);
559 break; /* End loop when list is empty. */
560 }
561 }
562}
563
564/* Add a struct record_full_entry to record_full_arch_list. */
565
566static void
568{
569 if (record_debug > 1)
571 "Process record: record_full_arch_list_add %s.\n",
572 host_address_to_string (rec));
573
575 {
579 }
580 else
581 {
584 }
585}
586
587/* Return the value storage location of a record entry. */
588static inline gdb_byte *
590{
591 switch (rec->type) {
592 case record_full_mem:
593 if (rec->u.mem.len > sizeof (rec->u.mem.u.buf))
594 return rec->u.mem.u.ptr;
595 else
596 return rec->u.mem.u.buf;
597 case record_full_reg:
598 if (rec->u.reg.len > sizeof (rec->u.reg.u.buf))
599 return rec->u.reg.u.ptr;
600 else
601 return rec->u.reg.u.buf;
602 case record_full_end:
603 default:
604 gdb_assert_not_reached ("unexpected record_full_entry type");
605 return NULL;
606 }
607}
608
609/* Record the value of a register NUM to record_full_arch_list. */
610
611int
613{
614 struct record_full_entry *rec;
615
616 if (record_debug > 1)
618 "Process record: add register num = %d to "
619 "record list.\n",
620 regnum);
621
623
625
627
628 return 0;
629}
630
631/* Record the value of a region of memory whose address is ADDR and
632 length is LEN to record_full_arch_list. */
633
634int
635record_full_arch_list_add_mem (CORE_ADDR addr, int len)
636{
637 struct record_full_entry *rec;
638
639 if (record_debug > 1)
641 "Process record: add mem addr = %s len = %d to "
642 "record list.\n",
643 paddress (target_gdbarch (), addr), len);
644
645 if (!addr) /* FIXME: Why? Some arch must permit it... */
646 return 0;
647
648 rec = record_full_mem_alloc (addr, len);
649
651 record_full_get_loc (rec), len))
652 {
654 return -1;
655 }
656
658
659 return 0;
660}
661
662/* Add a record_full_end type struct record_full_entry to
663 record_full_arch_list. */
664
665int
667{
668 struct record_full_entry *rec;
669
670 if (record_debug > 1)
672 "Process record: add end to arch list.\n");
673
674 rec = record_full_end_alloc ();
675 rec->u.end.sigval = GDB_SIGNAL_0;
677
679
680 return 0;
681}
682
683static void
685{
687 {
688 /* Ask user what to do. */
690 {
691 if (!yquery (_("Do you want to auto delete previous execution "
692 "log entries when record/replay buffer becomes "
693 "full (record full stop-at-limit)?")))
694 error (_("Process record: stopped by user."));
696 }
697 }
698}
699
700/* Before inferior step (when GDB record the running message, inferior
701 only can step), GDB will call this function to record the values to
702 record_full_list. This function will call gdbarch_process_record to
703 record the running message of inferior and set them to
704 record_full_arch_list, and add it to record_full_list. */
705
706static void
707record_full_message (struct regcache *regcache, enum gdb_signal signal)
708{
709 int ret;
710 struct gdbarch *gdbarch = regcache->arch ();
711
712 try
713 {
716
717 /* Check record_full_insn_num. */
719
720 /* If gdb sends a signal value to target_resume,
721 save it in the 'end' field of the previous instruction.
722
723 Maybe process record should record what really happened,
724 rather than what gdb pretends has happened.
725
726 So if Linux delivered the signal to the child process during
727 the record mode, we will record it and deliver it again in
728 the replay mode.
729
730 If user says "ignore this signal" during the record mode, then
731 it will be ignored again during the replay mode (no matter if
732 the user says something different, like "deliver this signal"
733 during the replay mode).
734
735 User should understand that nothing he does during the replay
736 mode will change the behavior of the child. If he tries,
737 then that is a user error.
738
739 But we should still deliver the signal to gdb during the replay,
740 if we delivered it during the recording. Therefore we should
741 record the signal during record_full_wait, not
742 record_full_resume. */
743 if (record_full_list != &record_full_first) /* FIXME better way
744 to check */
745 {
746 gdb_assert (record_full_list->type == record_full_end);
747 record_full_list->u.end.sigval = signal;
748 }
749
750 if (signal == GDB_SIGNAL_0
753 regcache,
755 else
757 regcache,
758 signal);
759
760 if (ret > 0)
761 error (_("Process record: inferior program stopped."));
762 if (ret < 0)
763 error (_("Process record: failed to record execution log."));
764 }
765 catch (const gdb_exception &ex)
766 {
768 throw;
769 }
770
774
777 else
779}
780
781static bool
783 enum gdb_signal signal)
784{
785 try
786 {
788 }
789 catch (const gdb_exception_error &ex)
790 {
792 return false;
793 }
794
795 return true;
796}
797
798/* Set to 1 if record_full_store_registers and record_full_xfer_partial
799 doesn't need record. */
800
802
803scoped_restore_tmpl<int>
805{
806 return make_scoped_restore (&record_full_gdb_operation_disable, 1);
807}
808
809/* Flag set to TRUE for target_stopped_by_watchpoint. */
812
813/* Execute one instruction from the record log. Each instruction in
814 the log will be represented by an arbitrary sequence of register
815 entries and memory entries, followed by an 'end' entry. */
816
817static inline void
819 struct gdbarch *gdbarch,
820 struct record_full_entry *entry)
821{
822 switch (entry->type)
823 {
824 case record_full_reg: /* reg */
825 {
826 gdb::byte_vector reg (entry->u.reg.len);
827
828 if (record_debug > 1)
830 "Process record: record_full_reg %s to "
831 "inferior num = %d.\n",
832 host_address_to_string (entry),
833 entry->u.reg.num);
834
835 regcache->cooked_read (entry->u.reg.num, reg.data ());
836 regcache->cooked_write (entry->u.reg.num, record_full_get_loc (entry));
837 memcpy (record_full_get_loc (entry), reg.data (), entry->u.reg.len);
838 }
839 break;
840
841 case record_full_mem: /* mem */
842 {
843 /* Nothing to do if the entry is flagged not_accessible. */
844 if (!entry->u.mem.mem_entry_not_accessible)
845 {
846 gdb::byte_vector mem (entry->u.mem.len);
847
848 if (record_debug > 1)
850 "Process record: record_full_mem %s to "
851 "inferior addr = %s len = %d.\n",
852 host_address_to_string (entry),
853 paddress (gdbarch, entry->u.mem.addr),
854 entry->u.mem.len);
855
857 entry->u.mem.addr, mem.data (),
858 entry->u.mem.len))
859 entry->u.mem.mem_entry_not_accessible = 1;
860 else
861 {
862 if (target_write_memory (entry->u.mem.addr,
863 record_full_get_loc (entry),
864 entry->u.mem.len))
865 {
866 entry->u.mem.mem_entry_not_accessible = 1;
867 if (record_debug)
868 warning (_("Process record: error writing memory at "
869 "addr = %s len = %d."),
870 paddress (gdbarch, entry->u.mem.addr),
871 entry->u.mem.len);
872 }
873 else
874 {
875 memcpy (record_full_get_loc (entry), mem.data (),
876 entry->u.mem.len);
877
878 /* We've changed memory --- check if a hardware
879 watchpoint should trap. Note that this
880 presently assumes the target beneath supports
881 continuable watchpoints. On non-continuable
882 watchpoints target, we'll want to check this
883 _before_ actually doing the memory change, and
884 not doing the change at all if the watchpoint
885 traps. */
887 (regcache->aspace (),
888 entry->u.mem.addr, entry->u.mem.len))
890 }
891 }
892 }
893 }
894 break;
895 }
896}
897
898static void record_full_restore (void);
899
900/* Asynchronous signal handle registered as event loop source for when
901 we have pending events ready to be passed to the core. */
902
904
905static void
910
911/* Open the process record target for 'core' files. */
912
913static void
914record_full_core_open_1 (const char *name, int from_tty)
915{
918 int i;
919
920 /* Get record_full_core_regbuf. */
923
924 for (i = 0; i < regnum; i ++)
926
928
931}
932
933/* Open the process record target for 'live' processes. */
934
935static void
936record_full_open_1 (const char *name, int from_tty)
937{
938 if (record_debug)
939 gdb_printf (gdb_stdlog, "Process record: record_full_open_1\n");
940
941 /* check exec */
942 if (!target_has_execution ())
943 error (_("Process record: the program is not being run."));
944 if (non_stop)
945 error (_("Process record target can't debug inferior in non-stop mode "
946 "(non-stop)."));
947
949 error (_("Process record: the current architecture doesn't support "
950 "record function."));
951
953}
954
955static void record_full_init_record_breakpoints (void);
956
957/* Open the process record target. */
958
959static void
960record_full_open (const char *name, int from_tty)
961{
962 if (record_debug)
963 gdb_printf (gdb_stdlog, "Process record: record_full_open\n");
964
966
967 /* Reset */
971 record_full_list->next = NULL;
972
973 if (core_bfd)
974 record_full_core_open_1 (name, from_tty);
975 else
976 record_full_open_1 (name, from_tty);
977
978 /* Register extra event sources in the event loop. */
981 NULL, "record-full");
982
984
986}
987
988/* "close" target method. Close the process record target. */
989
990void
992{
993 struct record_full_core_buf_entry *entry;
994
995 if (record_debug)
996 gdb_printf (gdb_stdlog, "Process record: record_full_close\n");
997
999
1000 /* Release record_full_core_regbuf. */
1002 {
1005 }
1006
1007 /* Release record_full_core_buf_list. */
1009 {
1012 xfree (entry);
1013 }
1014
1017}
1018
1019/* "async" target method. */
1020
1021void
1031
1032/* The PTID and STEP arguments last passed to
1033 record_full_target::resume. */
1034static ptid_t record_full_resume_ptid = null_ptid;
1036
1037/* True if we've been resumed, and so each record_full_wait call should
1038 advance execution. If this is false, record_full_wait will return a
1039 TARGET_WAITKIND_IGNORE. */
1040static int record_full_resumed = 0;
1041
1042/* The execution direction of the last resume we got. This is
1043 necessary for async mode. Vis (order is not strictly accurate):
1044
1045 1. user has the global execution direction set to forward
1046 2. user does a reverse-step command
1047 3. record_full_resume is called with global execution direction
1048 temporarily switched to reverse
1049 4. GDB's execution direction is reverted back to forward
1050 5. target record notifies event loop there's an event to handle
1051 6. infrun asks the target which direction was it going, and switches
1052 the global execution direction accordingly (to reverse)
1053 7. infrun polls an event out of the record target, and handles it
1054 8. GDB goes back to the event loop, and goto #4.
1055*/
1057
1058/* "resume" target method. Resume the process record target. */
1059
1060void
1061record_full_target::resume (ptid_t ptid, int step, enum gdb_signal signal)
1062{
1067
1069 {
1071
1073
1074 if (!step)
1075 {
1076 /* This is not hard single step. */
1078 {
1079 /* This is a normal continue. */
1080 step = 1;
1081 }
1082 else
1083 {
1084 /* This arch supports soft single step. */
1086 {
1087 /* This is a soft single step. */
1089 }
1090 else
1092 }
1093 }
1094
1095 /* Make sure the target beneath reports all signals. */
1097
1098 /* Disable range-stepping, forcing the process target to report stops for
1099 all executed instructions, so we can record them all. */
1100 process_stratum_target *proc_target
1102 for (thread_info *thread : all_non_exited_threads (proc_target, ptid))
1103 thread->control.may_range_step = 0;
1104
1105 this->beneath ()->resume (ptid, step, signal);
1106 }
1107}
1108
1109static int record_full_get_sig = 0;
1110
1111/* SIGINT signal handler, registered by "wait" method. */
1112
1113static void
1115{
1116 if (record_debug)
1117 gdb_printf (gdb_stdlog, "Process record: get a signal\n");
1118
1119 /* It will break the running inferior in replay mode. */
1121
1122 /* It will let record_full_wait set inferior status to get the signal
1123 SIGINT. */
1125}
1126
1127/* "wait" target method for process record target.
1128
1129 In record mode, the target is always run in singlestep mode
1130 (even when gdb says to continue). The wait method intercepts
1131 the stop events and determines which ones are to be passed on to
1132 gdb. Most stop events are just singlestep events that gdb is not
1133 to know about, so the wait method just records them and keeps
1134 singlestepping.
1135
1136 In replay mode, this function emulates the recorded execution log,
1137 one instruction at a time (forward or backward), and determines
1138 where to stop. */
1139
1140static ptid_t
1142 ptid_t ptid, struct target_waitstatus *status,
1143 target_wait_flags options)
1144{
1145 scoped_restore restore_operation_disable
1147
1148 if (record_debug)
1150 "Process record: record_full_wait "
1151 "record_full_resume_step = %d, "
1152 "record_full_resumed = %d, direction=%s\n",
1155 ? "forward" : "reverse");
1156
1158 {
1159 gdb_assert ((options & TARGET_WNOHANG) != 0);
1160
1161 /* No interesting event. */
1162 status->set_ignore ();
1163 return minus_one_ptid;
1164 }
1165
1167 signal (SIGINT, record_full_sig_handler);
1168
1170
1172 {
1174 {
1175 /* This is a single step. */
1176 return ops->beneath ()->wait (ptid, status, options);
1177 }
1178 else
1179 {
1180 /* This is not a single step. */
1181 ptid_t ret;
1182 CORE_ADDR tmp_pc;
1183 struct gdbarch *gdbarch
1185
1186 while (1)
1187 {
1188 ret = ops->beneath ()->wait (ptid, status, options);
1189 if (status->kind () == TARGET_WAITKIND_IGNORE)
1190 {
1191 if (record_debug)
1193 "Process record: record_full_wait "
1194 "target beneath not done yet\n");
1195 return ret;
1196 }
1197
1198 for (thread_info *tp : all_non_exited_threads ())
1200
1202 return ret;
1203
1204 /* Is this a SIGTRAP? */
1205 if (status->kind () == TARGET_WAITKIND_STOPPED
1206 && status->sig () == GDB_SIGNAL_TRAP)
1207 {
1208 struct regcache *regcache;
1209 enum target_stop_reason *stop_reason_p
1211
1212 /* Yes -- this is likely our single-step finishing,
1213 but check if there's any reason the core would be
1214 interested in the event. */
1215
1217 switch_to_thread (current_inferior ()->process_target (),
1218 ret);
1220 tmp_pc = regcache_read_pc (regcache);
1221 const struct address_space *aspace = regcache->aspace ();
1222
1224 {
1225 /* Always interested in watchpoints. */
1226 }
1227 else if (record_check_stopped_by_breakpoint (aspace, tmp_pc,
1228 stop_reason_p))
1229 {
1230 /* There is a breakpoint here. Let the core
1231 handle it. */
1232 }
1233 else
1234 {
1235 /* This is a single-step trap. Record the
1236 insn and issue another step.
1237 FIXME: this part can be a random SIGTRAP too.
1238 But GDB cannot handle it. */
1239 int step = 1;
1240
1242 GDB_SIGNAL_0))
1243 {
1244 status->set_stopped (GDB_SIGNAL_0);
1245 break;
1246 }
1247
1248 process_stratum_target *proc_target
1250
1252 {
1253 /* Try to insert the software single step breakpoint.
1254 If insert success, set step to 0. */
1255 set_executing (proc_target, inferior_ptid, false);
1256 SCOPE_EXIT
1257 {
1258 set_executing (proc_target, inferior_ptid, true);
1259 };
1260
1263 }
1264
1265 if (record_debug)
1267 "Process record: record_full_wait "
1268 "issuing one more step in the "
1269 "target beneath\n");
1270 ops->beneath ()->resume (ptid, step, GDB_SIGNAL_0);
1271 proc_target->commit_resumed_state = true;
1272 proc_target->commit_resumed ();
1273 proc_target->commit_resumed_state = false;
1274 continue;
1275 }
1276 }
1277
1278 /* The inferior is broken by a breakpoint or a signal. */
1279 break;
1280 }
1281
1282 return ret;
1283 }
1284 }
1285 else
1286 {
1287 switch_to_thread (current_inferior ()->process_target (),
1290 struct gdbarch *gdbarch = regcache->arch ();
1291 const struct address_space *aspace = regcache->aspace ();
1292 int continue_flag = 1;
1293 int first_record_full_end = 1;
1294
1295 try
1296 {
1297 CORE_ADDR tmp_pc;
1298
1300 status->set_stopped (GDB_SIGNAL_0);
1301
1302 /* Check breakpoint when forward execute. */
1304 {
1305 tmp_pc = regcache_read_pc (regcache);
1306 if (record_check_stopped_by_breakpoint (aspace, tmp_pc,
1308 {
1309 if (record_debug)
1311 "Process record: break at %s.\n",
1312 paddress (gdbarch, tmp_pc));
1313 goto replay_out;
1314 }
1315 }
1316
1317 /* If GDB is in terminal_inferior mode, it will not get the
1318 signal. And in GDB replay mode, GDB doesn't need to be
1319 in terminal_inferior mode, because inferior will not
1320 executed. Then set it to terminal_ours to make GDB get
1321 the signal. */
1323
1324 /* In EXEC_FORWARD mode, record_full_list points to the tail of prev
1325 instruction. */
1328
1329 /* Loop over the record_full_list, looking for the next place to
1330 stop. */
1331 do
1332 {
1333 /* Check for beginning and end of log. */
1336 {
1337 /* Hit beginning of record log in reverse. */
1338 status->set_no_history ();
1339 break;
1340 }
1343 {
1344 /* Hit end of record log going forward. */
1345 status->set_no_history ();
1346 break;
1347 }
1348
1350
1352 {
1353 if (record_debug > 1)
1355 (gdb_stdlog,
1356 "Process record: record_full_end %s to "
1357 "inferior.\n",
1358 host_address_to_string (record_full_list));
1359
1360 if (first_record_full_end
1362 {
1363 /* When reverse execute, the first
1364 record_full_end is the part of current
1365 instruction. */
1366 first_record_full_end = 0;
1367 }
1368 else
1369 {
1370 /* In EXEC_REVERSE mode, this is the
1371 record_full_end of prev instruction. In
1372 EXEC_FORWARD mode, this is the
1373 record_full_end of current instruction. */
1374 /* step */
1376 {
1377 if (record_debug > 1)
1379 "Process record: step.\n");
1380 continue_flag = 0;
1381 }
1382
1383 /* check breakpoint */
1384 tmp_pc = regcache_read_pc (regcache);
1386 (aspace, tmp_pc, &record_full_stop_reason))
1387 {
1388 if (record_debug)
1390 "Process record: break "
1391 "at %s.\n",
1392 paddress (gdbarch, tmp_pc));
1393
1394 continue_flag = 0;
1395 }
1396
1399 {
1400 if (record_debug)
1402 "Process record: hit hw "
1403 "watchpoint.\n");
1404 continue_flag = 0;
1405 }
1406 /* Check target signal */
1407 if (record_full_list->u.end.sigval != GDB_SIGNAL_0)
1408 /* FIXME: better way to check */
1409 continue_flag = 0;
1410 }
1411 }
1412
1413 if (continue_flag)
1414 {
1416 {
1419 }
1420 else
1421 {
1424 }
1425 }
1426 }
1427 while (continue_flag);
1428
1429 replay_out:
1430 if (status->kind () == TARGET_WAITKIND_STOPPED)
1431 {
1433 status->set_stopped (GDB_SIGNAL_INT);
1434 else if (record_full_list->u.end.sigval != GDB_SIGNAL_0)
1435 /* FIXME: better way to check */
1436 status->set_stopped (record_full_list->u.end.sigval);
1437 else
1438 status->set_stopped (GDB_SIGNAL_TRAP);
1439 }
1440 }
1441 catch (const gdb_exception &ex)
1442 {
1444 {
1447 }
1448 else
1450
1451 throw;
1452 }
1453 }
1454
1455 signal (SIGINT, handle_sigint);
1456
1457 return inferior_ptid;
1458}
1459
1460ptid_t
1462 target_wait_flags options)
1463{
1464 ptid_t return_ptid;
1465
1467
1468 return_ptid = record_full_wait_1 (this, ptid, status, options);
1469 if (status->kind () != TARGET_WAITKIND_IGNORE)
1470 {
1471 /* We're reporting a stop. Make sure any spurious
1472 target_wait(WNOHANG) doesn't advance the target until the
1473 core wants us resumed again. */
1475 }
1476 return return_ptid;
1477}
1478
1479bool
1487
1488bool
1490{
1492 return false;
1493 else
1494 return this->beneath ()->stopped_data_address (addr_p);
1495}
1496
1497/* The stopped_by_sw_breakpoint method of target record-full. */
1498
1499bool
1504
1505/* The supports_stopped_by_sw_breakpoint method of target
1506 record-full. */
1507
1508bool
1513
1514/* The stopped_by_hw_breakpoint method of target record-full. */
1515
1516bool
1521
1522/* The supports_stopped_by_sw_breakpoint method of target
1523 record-full. */
1524
1525bool
1530
1531/* Record registers change (by user or by GDB) to list as an instruction. */
1532
1533static void
1535{
1536 /* Check record_full_insn_num. */
1538
1541
1542 if (regnum < 0)
1543 {
1544 int i;
1545
1546 for (i = 0; i < gdbarch_num_regs (regcache->arch ()); i++)
1547 {
1549 {
1551 error (_("Process record: failed to record execution log."));
1552 }
1553 }
1554 }
1555 else
1556 {
1558 {
1560 error (_("Process record: failed to record execution log."));
1561 }
1562 }
1564 {
1566 error (_("Process record: failed to record execution log."));
1567 }
1571
1574 else
1576}
1577
1578/* "store_registers" method for process record target. */
1579
1580void
1582{
1584 {
1586 {
1587 int n;
1588
1589 /* Let user choose if he wants to write register or not. */
1590 if (regno < 0)
1591 n =
1592 query (_("Because GDB is in replay mode, changing the "
1593 "value of a register will make the execution "
1594 "log unusable from this point onward. "
1595 "Change all registers?"));
1596 else
1597 n =
1598 query (_("Because GDB is in replay mode, changing the value "
1599 "of a register will make the execution log unusable "
1600 "from this point onward. Change register %s?"),
1602 regno));
1603
1604 if (!n)
1605 {
1606 /* Invalidate the value of regcache that was set in function
1607 "regcache_raw_write". */
1608 if (regno < 0)
1609 {
1610 int i;
1611
1612 for (i = 0;
1613 i < gdbarch_num_regs (regcache->arch ());
1614 i++)
1615 regcache->invalidate (i);
1616 }
1617 else
1618 regcache->invalidate (regno);
1619
1620 error (_("Process record canceled the operation."));
1621 }
1622
1623 /* Destroy the record from here forward. */
1625 }
1626
1628 }
1629 this->beneath ()->store_registers (regcache, regno);
1630}
1631
1632/* "xfer_partial" method. Behavior is conditional on
1633 RECORD_FULL_IS_REPLAY.
1634 In replay mode, we cannot write memory unles we are willing to
1635 invalidate the record/replay log from this point forward. */
1636
1639 const char *annex, gdb_byte *readbuf,
1640 const gdb_byte *writebuf, ULONGEST offset,
1641 ULONGEST len, ULONGEST *xfered_len)
1642{
1644 && (object == TARGET_OBJECT_MEMORY
1645 || object == TARGET_OBJECT_RAW_MEMORY) && writebuf)
1646 {
1648 {
1649 /* Let user choose if he wants to write memory or not. */
1650 if (!query (_("Because GDB is in replay mode, writing to memory "
1651 "will make the execution log unusable from this "
1652 "point onward. Write memory at address %s?"),
1653 paddress (target_gdbarch (), offset)))
1654 error (_("Process record canceled the operation."));
1655
1656 /* Destroy the record from here forward. */
1658 }
1659
1660 /* Check record_full_insn_num */
1662
1663 /* Record registers change to list as an instruction. */
1666 if (record_full_arch_list_add_mem (offset, len))
1667 {
1669 if (record_debug)
1671 "Process record: failed to record "
1672 "execution log.");
1673 return TARGET_XFER_E_IO;
1674 }
1676 {
1678 if (record_debug)
1680 "Process record: failed to record "
1681 "execution log.");
1682 return TARGET_XFER_E_IO;
1683 }
1687
1690 else
1692 }
1693
1694 return this->beneath ()->xfer_partial (object, annex, readbuf, writebuf,
1695 offset, len, xfered_len);
1696}
1697
1698/* This structure represents a breakpoint inserted while the record
1699 target is active. We use this to know when to install/remove
1700 breakpoints in/from the target beneath. For example, a breakpoint
1701 may be inserted while recording, but removed when not replaying nor
1702 recording. In that case, the breakpoint had not been inserted on
1703 the target beneath, so we should not try to remove it there. */
1704
1706{
1707 record_full_breakpoint (struct address_space *address_space_,
1708 CORE_ADDR addr_,
1709 bool in_target_beneath_)
1710 : address_space (address_space_),
1711 addr (addr_),
1712 in_target_beneath (in_target_beneath_)
1713 {
1714 }
1715
1716 /* The address and address space the breakpoint was set at. */
1718 CORE_ADDR addr;
1719
1720 /* True when the breakpoint has been also installed in the target
1721 beneath. This will be false for breakpoints set during replay or
1722 when recording. */
1724};
1725
1726/* The list of breakpoints inserted while the record target is
1727 active. */
1728static std::vector<record_full_breakpoint> record_full_breakpoints;
1729
1730/* Sync existing breakpoints to record_full_breakpoints. */
1731
1732static void
1734{
1735 record_full_breakpoints.clear ();
1736
1737 for (bp_location *loc : all_bp_locations ())
1738 {
1739 if (loc->loc_type != bp_loc_software_breakpoint)
1740 continue;
1741
1742 if (loc->inserted)
1743 record_full_breakpoints.emplace_back
1744 (loc->target_info.placed_address_space,
1745 loc->target_info.placed_address, 1);
1746 }
1747}
1748
1749/* Behavior is conditional on RECORD_FULL_IS_REPLAY. We will not actually
1750 insert or remove breakpoints in the real target when replaying, nor
1751 when recording. */
1752
1753int
1755 struct bp_target_info *bp_tgt)
1756{
1757 bool in_target_beneath = false;
1758
1760 {
1761 /* When recording, we currently always single-step, so we don't
1762 really need to install regular breakpoints in the inferior.
1763 However, we do have to insert software single-step
1764 breakpoints, in case the target can't hardware step. To keep
1765 things simple, we always insert. */
1766
1767 scoped_restore restore_operation_disable
1769
1770 int ret = this->beneath ()->insert_breakpoint (gdbarch, bp_tgt);
1771 if (ret != 0)
1772 return ret;
1773
1774 in_target_beneath = true;
1775 }
1776
1777 /* Use the existing entries if found in order to avoid duplication
1778 in record_full_breakpoints. */
1779
1781 {
1782 if (bp.addr == bp_tgt->placed_address
1783 && bp.address_space == bp_tgt->placed_address_space)
1784 {
1785 gdb_assert (bp.in_target_beneath == in_target_beneath);
1786 return 0;
1787 }
1788 }
1789
1790 record_full_breakpoints.emplace_back (bp_tgt->placed_address_space,
1791 bp_tgt->placed_address,
1792 in_target_beneath);
1793 return 0;
1794}
1795
1796/* "remove_breakpoint" method for process record target. */
1797
1798int
1800 struct bp_target_info *bp_tgt,
1801 enum remove_bp_reason reason)
1802{
1803 for (auto iter = record_full_breakpoints.begin ();
1804 iter != record_full_breakpoints.end ();
1805 ++iter)
1806 {
1807 struct record_full_breakpoint &bp = *iter;
1808
1809 if (bp.addr == bp_tgt->placed_address
1810 && bp.address_space == bp_tgt->placed_address_space)
1811 {
1812 if (bp.in_target_beneath)
1813 {
1814 scoped_restore restore_operation_disable
1816
1817 int ret = this->beneath ()->remove_breakpoint (gdbarch, bp_tgt,
1818 reason);
1819 if (ret != 0)
1820 return ret;
1821 }
1822
1823 if (reason == REMOVE_BREAKPOINT)
1824 unordered_remove (record_full_breakpoints, iter);
1825 return 0;
1826 }
1827 }
1828
1829 gdb_assert_not_reached ("removing unknown breakpoint");
1830}
1831
1832/* "can_execute_reverse" method for process record target. */
1833
1834bool
1836{
1837 return true;
1838}
1839
1840/* "get_bookmark" method for process record and prec over core. */
1841
1842gdb_byte *
1843record_full_base_target::get_bookmark (const char *args, int from_tty)
1844{
1845 char *ret = NULL;
1846
1847 /* Return stringified form of instruction count. */
1849 ret = xstrdup (pulongest (record_full_list->u.end.insn_num));
1850
1851 if (record_debug)
1852 {
1853 if (ret)
1855 "record_full_get_bookmark returns %s\n", ret);
1856 else
1858 "record_full_get_bookmark returns NULL\n");
1859 }
1860 return (gdb_byte *) ret;
1861}
1862
1863/* "goto_bookmark" method for process record and prec over core. */
1864
1865void
1866record_full_base_target::goto_bookmark (const gdb_byte *raw_bookmark,
1867 int from_tty)
1868{
1869 const char *bookmark = (const char *) raw_bookmark;
1870
1871 if (record_debug)
1873 "record_full_goto_bookmark receives %s\n", bookmark);
1874
1875 std::string name_holder;
1876 if (bookmark[0] == '\'' || bookmark[0] == '\"')
1877 {
1878 if (bookmark[strlen (bookmark) - 1] != bookmark[0])
1879 error (_("Unbalanced quotes: %s"), bookmark);
1880
1881 name_holder = std::string (bookmark + 1, strlen (bookmark) - 2);
1882 bookmark = name_holder.c_str ();
1883 }
1884
1886}
1887
1893
1894/* The record_method method of target record-full. */
1895
1896enum record_method
1898{
1899 return RECORD_METHOD_FULL;
1900}
1901
1902void
1904{
1905 struct record_full_entry *p;
1906
1908 gdb_printf (_("Replay mode:\n"));
1909 else
1910 gdb_printf (_("Record mode:\n"));
1911
1912 /* Find entry for first actual instruction in the log. */
1913 for (p = record_full_first.next;
1914 p != NULL && p->type != record_full_end;
1915 p = p->next)
1916 ;
1917
1918 /* Do we have a log at all? */
1919 if (p != NULL && p->type == record_full_end)
1920 {
1921 /* Display instruction number for first instruction in the log. */
1922 gdb_printf (_("Lowest recorded instruction number is %s.\n"),
1923 pulongest (p->u.end.insn_num));
1924
1925 /* If in replay mode, display where we are in the log. */
1927 gdb_printf (_("Current instruction number is %s.\n"),
1928 pulongest (record_full_list->u.end.insn_num));
1929
1930 /* Display instruction number for last instruction in the log. */
1931 gdb_printf (_("Highest recorded instruction number is %s.\n"),
1932 pulongest (record_full_insn_count));
1933
1934 /* Display log count. */
1935 gdb_printf (_("Log contains %u instructions.\n"),
1937 }
1938 else
1939 gdb_printf (_("No instructions have been logged.\n"));
1940
1941 /* Display max log size. */
1942 gdb_printf (_("Max logged instructions is %u.\n"),
1944}
1945
1946bool
1951
1952/* The "delete_record" target method. */
1953
1954void
1959
1960/* The "record_is_replaying" target method. */
1961
1962bool
1967
1968/* The "record_will_replay" target method. */
1969
1970bool
1972{
1973 /* We can currently only record when executing forwards. Should we be able
1974 to record when executing backwards on targets that support reverse
1975 execution, this needs to be changed. */
1976
1977 return RECORD_FULL_IS_REPLAY || dir == EXEC_REVERSE;
1978}
1979
1980/* Go to a specific entry. */
1981
1982static void
1984{
1985 if (p == NULL)
1986 error (_("Target insn not found."));
1987 else if (p == record_full_list)
1988 error (_("Already at target insn."));
1989 else if (p->u.end.insn_num > record_full_list->u.end.insn_num)
1990 {
1991 gdb_printf (_("Go forward to insn number %s\n"),
1992 pulongest (p->u.end.insn_num));
1994 }
1995 else
1996 {
1997 gdb_printf (_("Go backward to insn number %s\n"),
1998 pulongest (p->u.end.insn_num));
2000 }
2001
2006}
2007
2008/* The "goto_record_begin" target method. */
2009
2010void
2012{
2013 struct record_full_entry *p = NULL;
2014
2015 for (p = &record_full_first; p != NULL; p = p->next)
2016 if (p->type == record_full_end)
2017 break;
2018
2020}
2021
2022/* The "goto_record_end" target method. */
2023
2024void
2026{
2027 struct record_full_entry *p = NULL;
2028
2029 for (p = record_full_list; p->next != NULL; p = p->next)
2030 ;
2031 for (; p!= NULL; p = p->prev)
2032 if (p->type == record_full_end)
2033 break;
2034
2036}
2037
2038/* The "goto_record" target method. */
2039
2040void
2042{
2043 struct record_full_entry *p = NULL;
2044
2045 for (p = &record_full_first; p != NULL; p = p->next)
2046 if (p->type == record_full_end && p->u.end.insn_num == target_insn)
2047 break;
2048
2050}
2051
2052/* The "record_stop_replaying" target method. */
2053
2054void
2059
2060/* "resume" method for prec over corefile. */
2061
2062void
2063record_full_core_target::resume (ptid_t ptid, int step,
2064 enum gdb_signal signal)
2065{
2069}
2070
2071/* "kill" method for prec over corefile. */
2072
2073void
2075{
2076 if (record_debug)
2077 gdb_printf (gdb_stdlog, "Process record: record_full_core_kill\n");
2078
2080}
2081
2082/* "fetch_registers" method for prec over corefile. */
2083
2084void
2086 int regno)
2087{
2088 if (regno < 0)
2089 {
2090 int num = gdbarch_num_regs (regcache->arch ());
2091 int i;
2092
2093 for (i = 0; i < num; i ++)
2095 }
2096 else
2098}
2099
2100/* "prepare_to_store" method for prec over corefile. */
2101
2102void
2106
2107/* "store_registers" method for prec over corefile. */
2108
2109void
2111 int regno)
2112{
2115 else
2116 error (_("You can't do that without a process to debug."));
2117}
2118
2119/* "xfer_partial" method for prec over corefile. */
2120
2123 const char *annex, gdb_byte *readbuf,
2124 const gdb_byte *writebuf, ULONGEST offset,
2125 ULONGEST len, ULONGEST *xfered_len)
2126{
2127 if (object == TARGET_OBJECT_MEMORY)
2128 {
2129 if (record_full_gdb_operation_disable || !writebuf)
2130 {
2132 {
2133 if (offset >= p.addr)
2134 {
2135 struct record_full_core_buf_entry *entry;
2136 ULONGEST sec_offset;
2137
2138 if (offset >= p.endaddr)
2139 continue;
2140
2141 if (offset + len > p.endaddr)
2142 len = p.endaddr - offset;
2143
2144 sec_offset = offset - p.addr;
2145
2146 /* Read readbuf or write writebuf p, offset, len. */
2147 /* Check flags. */
2148 if (p.the_bfd_section->flags & SEC_CONSTRUCTOR
2149 || (p.the_bfd_section->flags & SEC_HAS_CONTENTS) == 0)
2150 {
2151 if (readbuf)
2152 memset (readbuf, 0, len);
2153
2154 *xfered_len = len;
2155 return TARGET_XFER_OK;
2156 }
2157 /* Get record_full_core_buf_entry. */
2158 for (entry = record_full_core_buf_list; entry;
2159 entry = entry->prev)
2160 if (entry->p == &p)
2161 break;
2162 if (writebuf)
2163 {
2164 if (!entry)
2165 {
2166 /* Add a new entry. */
2167 entry = XNEW (struct record_full_core_buf_entry);
2168 entry->p = &p;
2169 if (!bfd_malloc_and_get_section
2170 (p.the_bfd_section->owner,
2171 p.the_bfd_section,
2172 &entry->buf))
2173 {
2174 xfree (entry);
2175 return TARGET_XFER_EOF;
2176 }
2177 entry->prev = record_full_core_buf_list;
2179 }
2180
2181 memcpy (entry->buf + sec_offset, writebuf,
2182 (size_t) len);
2183 }
2184 else
2185 {
2186 if (!entry)
2187 return this->beneath ()->xfer_partial (object, annex,
2188 readbuf, writebuf,
2189 offset, len,
2190 xfered_len);
2191
2192 memcpy (readbuf, entry->buf + sec_offset,
2193 (size_t) len);
2194 }
2195
2196 *xfered_len = len;
2197 return TARGET_XFER_OK;
2198 }
2199 }
2200
2201 return TARGET_XFER_E_IO;
2202 }
2203 else
2204 error (_("You can't do that without a process to debug."));
2205 }
2206
2207 return this->beneath ()->xfer_partial (object, annex,
2208 readbuf, writebuf, offset, len,
2209 xfered_len);
2210}
2211
2212/* "insert_breakpoint" method for prec over corefile. */
2213
2214int
2216 struct bp_target_info *bp_tgt)
2217{
2218 return 0;
2219}
2220
2221/* "remove_breakpoint" method for prec over corefile. */
2222
2223int
2225 struct bp_target_info *bp_tgt,
2226 enum remove_bp_reason reason)
2227{
2228 return 0;
2229}
2230
2231/* "has_execution" method for prec over corefile. */
2232
2233bool
2235{
2236 return true;
2237}
2238
2239/* Record log save-file format
2240 Version 1 (never released)
2241
2242 Header:
2243 4 bytes: magic number htonl(0x20090829).
2244 NOTE: be sure to change whenever this file format changes!
2245
2246 Records:
2247 record_full_end:
2248 1 byte: record type (record_full_end, see enum record_full_type).
2249 record_full_reg:
2250 1 byte: record type (record_full_reg, see enum record_full_type).
2251 8 bytes: register id (network byte order).
2252 MAX_REGISTER_SIZE bytes: register value.
2253 record_full_mem:
2254 1 byte: record type (record_full_mem, see enum record_full_type).
2255 8 bytes: memory length (network byte order).
2256 8 bytes: memory address (network byte order).
2257 n bytes: memory value (n == memory length).
2258
2259 Version 2
2260 4 bytes: magic number netorder32(0x20091016).
2261 NOTE: be sure to change whenever this file format changes!
2262
2263 Records:
2264 record_full_end:
2265 1 byte: record type (record_full_end, see enum record_full_type).
2266 4 bytes: signal
2267 4 bytes: instruction count
2268 record_full_reg:
2269 1 byte: record type (record_full_reg, see enum record_full_type).
2270 4 bytes: register id (network byte order).
2271 n bytes: register value (n == actual register size).
2272 (eg. 4 bytes for x86 general registers).
2273 record_full_mem:
2274 1 byte: record type (record_full_mem, see enum record_full_type).
2275 4 bytes: memory length (network byte order).
2276 8 bytes: memory address (network byte order).
2277 n bytes: memory value (n == memory length).
2278
2279*/
2280
2281/* bfdcore_read -- read bytes from a core file section. */
2282
2283static inline void
2284bfdcore_read (bfd *obfd, asection *osec, void *buf, int len, int *offset)
2285{
2286 int ret = bfd_get_section_contents (obfd, osec, buf, *offset, len);
2287
2288 if (ret)
2289 *offset += len;
2290 else
2291 error (_("Failed to read %d bytes from core file %s ('%s')."),
2292 len, bfd_get_filename (obfd),
2293 bfd_errmsg (bfd_get_error ()));
2294}
2295
2296static inline uint64_t
2297netorder64 (uint64_t input)
2298{
2299 uint64_t ret;
2300
2301 store_unsigned_integer ((gdb_byte *) &ret, sizeof (ret),
2302 BFD_ENDIAN_BIG, input);
2303 return ret;
2304}
2305
2306static inline uint32_t
2307netorder32 (uint32_t input)
2308{
2309 uint32_t ret;
2310
2311 store_unsigned_integer ((gdb_byte *) &ret, sizeof (ret),
2312 BFD_ENDIAN_BIG, input);
2313 return ret;
2314}
2315
2316/* Restore the execution log from a core_bfd file. */
2317static void
2319{
2320 uint32_t magic;
2321 struct record_full_entry *rec;
2322 asection *osec;
2323 uint32_t osec_size;
2324 int bfd_offset = 0;
2325 struct regcache *regcache;
2326
2327 /* We restore the execution log from the open core bfd,
2328 if there is one. */
2329 if (core_bfd == NULL)
2330 return;
2331
2332 /* "record_full_restore" can only be called when record list is empty. */
2333 gdb_assert (record_full_first.next == NULL);
2334
2335 if (record_debug)
2336 gdb_printf (gdb_stdlog, "Restoring recording from core file.\n");
2337
2338 /* Now need to find our special note section. */
2339 osec = bfd_get_section_by_name (core_bfd, "null0");
2340 if (record_debug)
2341 gdb_printf (gdb_stdlog, "Find precord section %s.\n",
2342 osec ? "succeeded" : "failed");
2343 if (osec == NULL)
2344 return;
2345 osec_size = bfd_section_size (osec);
2346 if (record_debug)
2347 gdb_printf (gdb_stdlog, "%s", bfd_section_name (osec));
2348
2349 /* Check the magic code. */
2350 bfdcore_read (core_bfd, osec, &magic, sizeof (magic), &bfd_offset);
2351 if (magic != RECORD_FULL_FILE_MAGIC)
2352 error (_("Version mis-match or file format error in core file %s."),
2353 bfd_get_filename (core_bfd));
2354 if (record_debug)
2356 " Reading 4-byte magic cookie "
2357 "RECORD_FULL_FILE_MAGIC (0x%s)\n",
2358 phex_nz (netorder32 (magic), 4));
2359
2360 /* Restore the entries in recfd into record_full_arch_list_head and
2361 record_full_arch_list_tail. */
2365
2366 try
2367 {
2369
2370 while (1)
2371 {
2372 uint8_t rectype;
2373 uint32_t regnum, len, signal, count;
2374 uint64_t addr;
2375
2376 /* We are finished when offset reaches osec_size. */
2377 if (bfd_offset >= osec_size)
2378 break;
2379 bfdcore_read (core_bfd, osec, &rectype, sizeof (rectype), &bfd_offset);
2380
2381 switch (rectype)
2382 {
2383 case record_full_reg: /* reg */
2384 /* Get register number to regnum. */
2385 bfdcore_read (core_bfd, osec, &regnum,
2386 sizeof (regnum), &bfd_offset);
2388
2390
2391 /* Get val. */
2393 rec->u.reg.len, &bfd_offset);
2394
2395 if (record_debug)
2397 " Reading register %d (1 "
2398 "plus %lu plus %d bytes)\n",
2399 rec->u.reg.num,
2400 (unsigned long) sizeof (regnum),
2401 rec->u.reg.len);
2402 break;
2403
2404 case record_full_mem: /* mem */
2405 /* Get len. */
2406 bfdcore_read (core_bfd, osec, &len,
2407 sizeof (len), &bfd_offset);
2408 len = netorder32 (len);
2409
2410 /* Get addr. */
2411 bfdcore_read (core_bfd, osec, &addr,
2412 sizeof (addr), &bfd_offset);
2413 addr = netorder64 (addr);
2414
2415 rec = record_full_mem_alloc (addr, len);
2416
2417 /* Get val. */
2419 rec->u.mem.len, &bfd_offset);
2420
2421 if (record_debug)
2423 " Reading memory %s (1 plus "
2424 "%lu plus %lu plus %d bytes)\n",
2426 rec->u.mem.addr),
2427 (unsigned long) sizeof (addr),
2428 (unsigned long) sizeof (len),
2429 rec->u.mem.len);
2430 break;
2431
2432 case record_full_end: /* end */
2433 rec = record_full_end_alloc ();
2435
2436 /* Get signal value. */
2437 bfdcore_read (core_bfd, osec, &signal,
2438 sizeof (signal), &bfd_offset);
2439 signal = netorder32 (signal);
2440 rec->u.end.sigval = (enum gdb_signal) signal;
2441
2442 /* Get insn count. */
2443 bfdcore_read (core_bfd, osec, &count,
2444 sizeof (count), &bfd_offset);
2445 count = netorder32 (count);
2446 rec->u.end.insn_num = count;
2447 record_full_insn_count = count + 1;
2448 if (record_debug)
2450 " Reading record_full_end (1 + "
2451 "%lu + %lu bytes), offset == %s\n",
2452 (unsigned long) sizeof (signal),
2453 (unsigned long) sizeof (count),
2455 bfd_offset));
2456 break;
2457
2458 default:
2459 error (_("Bad entry type in core file %s."),
2460 bfd_get_filename (core_bfd));
2461 break;
2462 }
2463
2464 /* Add rec to record arch list. */
2466 }
2467 }
2468 catch (const gdb_exception &ex)
2469 {
2471 throw;
2472 }
2473
2474 /* Add record_full_arch_list_head to the end of record list. */
2479
2480 /* Update record_full_insn_max_num. */
2482 {
2484 warning (_("Auto increase record/replay buffer limit to %u."),
2486 }
2487
2488 /* Succeeded. */
2489 gdb_printf (_("Restored records from core file %s.\n"),
2490 bfd_get_filename (core_bfd));
2491
2493}
2494
2495/* bfdcore_write -- write bytes into a core file section. */
2496
2497static inline void
2498bfdcore_write (bfd *obfd, asection *osec, void *buf, int len, int *offset)
2499{
2500 int ret = bfd_set_section_contents (obfd, osec, buf, *offset, len);
2501
2502 if (ret)
2503 *offset += len;
2504 else
2505 error (_("Failed to write %d bytes to core file %s ('%s')."),
2506 len, bfd_get_filename (obfd),
2507 bfd_errmsg (bfd_get_error ()));
2508}
2509
2510/* Restore the execution log from a file. We use a modified elf
2511 corefile format, with an extra section for our data. */
2512
2513static void
2514cmd_record_full_restore (const char *args, int from_tty)
2515{
2516 core_file_command (args, from_tty);
2517 record_full_open (args, from_tty);
2518}
2519
2520/* Save the execution log to a file. We use a modified elf corefile
2521 format, with an extra section for our data. */
2522
2523void
2525{
2526 struct record_full_entry *cur_record_full_list;
2527 uint32_t magic;
2528 struct regcache *regcache;
2529 struct gdbarch *gdbarch;
2530 int save_size = 0;
2531 asection *osec = NULL;
2532 int bfd_offset = 0;
2533
2534 /* Open the save file. */
2535 if (record_debug)
2536 gdb_printf (gdb_stdlog, "Saving execution log to core file '%s'\n",
2537 recfilename);
2538
2539 /* Open the output file. */
2540 gdb_bfd_ref_ptr obfd (create_gcore_bfd (recfilename));
2541
2542 /* Arrange to remove the output file on failure. */
2543 gdb::unlinker unlink_file (recfilename);
2544
2545 /* Save the current record entry to "cur_record_full_list". */
2546 cur_record_full_list = record_full_list;
2547
2548 /* Get the values of regcache and gdbarch. */
2550 gdbarch = regcache->arch ();
2551
2552 /* Disable the GDB operation record. */
2553 scoped_restore restore_operation_disable
2555
2556 /* Reverse execute to the begin of record list. */
2557 while (1)
2558 {
2559 /* Check for beginning and end of log. */
2561 break;
2562
2564
2567 }
2568
2569 /* Compute the size needed for the extra bfd section. */
2570 save_size = 4; /* magic cookie */
2573 switch (record_full_list->type)
2574 {
2575 case record_full_end:
2576 save_size += 1 + 4 + 4;
2577 break;
2578 case record_full_reg:
2579 save_size += 1 + 4 + record_full_list->u.reg.len;
2580 break;
2581 case record_full_mem:
2582 save_size += 1 + 4 + 8 + record_full_list->u.mem.len;
2583 break;
2584 }
2585
2586 /* Make the new bfd section. */
2587 osec = bfd_make_section_anyway_with_flags (obfd.get (), "precord",
2588 SEC_HAS_CONTENTS
2589 | SEC_READONLY);
2590 if (osec == NULL)
2591 error (_("Failed to create 'precord' section for corefile %s: %s"),
2592 recfilename,
2593 bfd_errmsg (bfd_get_error ()));
2594 bfd_set_section_size (osec, save_size);
2595 bfd_set_section_vma (osec, 0);
2596 bfd_set_section_alignment (osec, 0);
2597
2598 /* Save corefile state. */
2599 write_gcore_file (obfd.get ());
2600
2601 /* Write out the record log. */
2602 /* Write the magic code. */
2603 magic = RECORD_FULL_FILE_MAGIC;
2604 if (record_debug)
2606 " Writing 4-byte magic cookie "
2607 "RECORD_FULL_FILE_MAGIC (0x%s)\n",
2608 phex_nz (magic, 4));
2609 bfdcore_write (obfd.get (), osec, &magic, sizeof (magic), &bfd_offset);
2610
2611 /* Save the entries to recfd and forward execute to the end of
2612 record list. */
2614 while (1)
2615 {
2616 /* Save entry. */
2618 {
2619 uint8_t type;
2620 uint32_t regnum, len, signal, count;
2621 uint64_t addr;
2622
2624 bfdcore_write (obfd.get (), osec, &type, sizeof (type), &bfd_offset);
2625
2626 switch (record_full_list->type)
2627 {
2628 case record_full_reg: /* reg */
2629 if (record_debug)
2631 " Writing register %d (1 "
2632 "plus %lu plus %d bytes)\n",
2634 (unsigned long) sizeof (regnum),
2636
2637 /* Write regnum. */
2639 bfdcore_write (obfd.get (), osec, &regnum,
2640 sizeof (regnum), &bfd_offset);
2641
2642 /* Write regval. */
2643 bfdcore_write (obfd.get (), osec,
2645 record_full_list->u.reg.len, &bfd_offset);
2646 break;
2647
2648 case record_full_mem: /* mem */
2649 if (record_debug)
2651 " Writing memory %s (1 plus "
2652 "%lu plus %lu plus %d bytes)\n",
2655 (unsigned long) sizeof (addr),
2656 (unsigned long) sizeof (len),
2658
2659 /* Write memlen. */
2661 bfdcore_write (obfd.get (), osec, &len, sizeof (len),
2662 &bfd_offset);
2663
2664 /* Write memaddr. */
2666 bfdcore_write (obfd.get (), osec, &addr,
2667 sizeof (addr), &bfd_offset);
2668
2669 /* Write memval. */
2670 bfdcore_write (obfd.get (), osec,
2672 record_full_list->u.mem.len, &bfd_offset);
2673 break;
2674
2675 case record_full_end:
2676 if (record_debug)
2678 " Writing record_full_end (1 + "
2679 "%lu + %lu bytes)\n",
2680 (unsigned long) sizeof (signal),
2681 (unsigned long) sizeof (count));
2682 /* Write signal value. */
2684 bfdcore_write (obfd.get (), osec, &signal,
2685 sizeof (signal), &bfd_offset);
2686
2687 /* Write insn count. */
2689 bfdcore_write (obfd.get (), osec, &count,
2690 sizeof (count), &bfd_offset);
2691 break;
2692 }
2693 }
2694
2695 /* Execute entry. */
2697
2700 else
2701 break;
2702 }
2703
2704 /* Reverse execute to cur_record_full_list. */
2705 while (1)
2706 {
2707 /* Check for beginning and end of log. */
2708 if (record_full_list == cur_record_full_list)
2709 break;
2710
2712
2715 }
2716
2717 unlink_file.keep ();
2718
2719 /* Succeeded. */
2720 gdb_printf (_("Saved core file %s with execution log.\n"),
2721 recfilename);
2722}
2723
2724/* record_full_goto_insn -- rewind the record log (forward or backward,
2725 depending on DIR) to the given entry, changing the program state
2726 correspondingly. */
2727
2728static void
2730 enum exec_direction_kind dir)
2731{
2732 scoped_restore restore_operation_disable
2735 struct gdbarch *gdbarch = regcache->arch ();
2736
2737 /* Assume everything is valid: we will hit the entry,
2738 and we will not hit the end of the recording. */
2739
2740 if (dir == EXEC_FORWARD)
2742
2743 do
2744 {
2746 if (dir == EXEC_REVERSE)
2748 else
2750 } while (record_full_list != entry);
2751}
2752
2753/* Alias for "target record-full". */
2754
2755static void
2756cmd_record_full_start (const char *args, int from_tty)
2757{
2758 execute_command ("target record-full", from_tty);
2759}
2760
2761static void
2762set_record_full_insn_max_num (const char *args, int from_tty,
2763 struct cmd_list_element *c)
2764{
2766 {
2767 /* Count down record_full_insn_num while releasing records from list. */
2769 {
2772 }
2773 }
2774}
2775
2776/* Implement the 'maintenance print record-instruction' command. */
2777
2778static void
2779maintenance_print_record_instruction (const char *args, int from_tty)
2780{
2781 struct record_full_entry *to_print = record_full_list;
2782
2783 if (args != nullptr)
2784 {
2785 int offset = value_as_long (parse_and_eval (args));
2786 if (offset > 0)
2787 {
2788 /* Move forward OFFSET instructions. We know we found the
2789 end of an instruction when to_print->type is record_full_end. */
2790 while (to_print->next != nullptr && offset > 0)
2791 {
2792 to_print = to_print->next;
2793 if (to_print->type == record_full_end)
2794 offset--;
2795 }
2796 if (offset != 0)
2797 error (_("Not enough recorded history"));
2798 }
2799 else
2800 {
2801 while (to_print->prev != nullptr && offset < 0)
2802 {
2803 to_print = to_print->prev;
2804 if (to_print->type == record_full_end)
2805 offset++;
2806 }
2807 if (offset != 0)
2808 error (_("Not enough recorded history"));
2809 }
2810 }
2811 gdb_assert (to_print != nullptr);
2812
2813 /* Go back to the start of the instruction. */
2814 while (to_print->prev != nullptr && to_print->prev->type != record_full_end)
2815 to_print = to_print->prev;
2816
2817 /* if we're in the first record, there are no actual instructions
2818 recorded. Warn the user and leave. */
2819 if (to_print == &record_full_first)
2820 error (_("Not enough recorded history"));
2821
2822 while (to_print->type != record_full_end)
2823 {
2824 switch (to_print->type)
2825 {
2826 case record_full_reg:
2827 {
2829 to_print->u.reg.num);
2830 value *val
2831 = value_from_contents (regtype,
2832 record_full_get_loc (to_print));
2833 gdb_printf ("Register %s changed: ",
2835 to_print->u.reg.num));
2836 struct value_print_options opts;
2837 get_user_print_options (&opts);
2838 opts.raw = true;
2839 value_print (val, gdb_stdout, &opts);
2840 gdb_printf ("\n");
2841 break;
2842 }
2843 case record_full_mem:
2844 {
2845 gdb_byte *b = record_full_get_loc (to_print);
2846 gdb_printf ("%d bytes of memory at address %s changed from:",
2847 to_print->u.mem.len,
2849 to_print->u.mem.addr));
2850 for (int i = 0; i < to_print->u.mem.len; i++)
2851 gdb_printf (" %02x", b[i]);
2852 gdb_printf ("\n");
2853 break;
2854 }
2855 }
2856 to_print = to_print->next;
2857 }
2858}
2859
2861void
2863{
2864 struct cmd_list_element *c;
2865
2866 /* Init record_full_first. */
2867 record_full_first.prev = NULL;
2868 record_full_first.next = NULL;
2870
2874
2876 _("Start full execution recording."), &record_full_cmdlist,
2877 0, &record_cmdlist);
2878
2879 cmd_list_element *record_full_restore_cmd
2881 _("Restore the execution log from a file.\n\
2882Argument is filename. File must be created with 'record save'."),
2884 set_cmd_completer (record_full_restore_cmd, filename_completer);
2885
2886 /* Deprecate the old version without "full" prefix. */
2887 c = add_alias_cmd ("restore", record_full_restore_cmd, class_obscure, 1,
2890 deprecate_cmd (c, "record full restore");
2891
2893 _("Set record options."),
2894 _("Show record options."),
2899
2900 /* Record instructions number limit command. */
2901 set_show_commands set_record_full_stop_at_limit_cmds
2902 = add_setshow_boolean_cmd ("stop-at-limit", no_class,
2904Set whether record/replay stops when record/replay buffer becomes full."), _("\
2905Show whether record/replay stops when record/replay buffer becomes full."),
2906 _("Default is ON.\n\
2907When ON, if the record/replay buffer becomes full, ask user what to do.\n\
2908When OFF, if the record/replay buffer becomes full,\n\
2909delete the oldest recorded instruction to make room for each new one."),
2910 NULL, NULL,
2913
2914 c = add_alias_cmd ("stop-at-limit",
2915 set_record_full_stop_at_limit_cmds.set, no_class, 1,
2917 deprecate_cmd (c, "set record full stop-at-limit");
2918
2919 c = add_alias_cmd ("stop-at-limit",
2920 set_record_full_stop_at_limit_cmds.show, no_class, 1,
2922 deprecate_cmd (c, "show record full stop-at-limit");
2923
2924 set_show_commands record_full_insn_number_max_cmds
2925 = add_setshow_uinteger_cmd ("insn-number-max", no_class,
2927 _("Set record/replay buffer limit."),
2928 _("Show record/replay buffer limit."), _("\
2929Set the maximum number of instructions to be stored in the\n\
2930record/replay buffer. A value of either \"unlimited\" or zero means no\n\
2931limit. Default is 200000."),
2935
2936 c = add_alias_cmd ("insn-number-max", record_full_insn_number_max_cmds.set,
2938 deprecate_cmd (c, "set record full insn-number-max");
2939
2940 c = add_alias_cmd ("insn-number-max", record_full_insn_number_max_cmds.show,
2942 deprecate_cmd (c, "show record full insn-number-max");
2943
2944 set_show_commands record_full_memory_query_cmds
2945 = add_setshow_boolean_cmd ("memory-query", no_class,
2947Set whether query if PREC cannot record memory change of next instruction."),
2948 _("\
2949Show whether query if PREC cannot record memory change of next instruction."),
2950 _("\
2951Default is OFF.\n\
2952When ON, query if PREC cannot record memory change of next instruction."),
2953 NULL, NULL,
2956
2957 c = add_alias_cmd ("memory-query", record_full_memory_query_cmds.set,
2959 deprecate_cmd (c, "set record full memory-query");
2960
2961 c = add_alias_cmd ("memory-query", record_full_memory_query_cmds.show,
2963 deprecate_cmd (c, "show record full memory-query");
2964
2965 add_cmd ("record-instruction", class_maintenance,
2967 _("\
2968Print a recorded instruction.\n\
2969If no argument is provided, print the last instruction recorded.\n\
2970If a negative argument is given, prints how the nth previous \
2971instruction will be undone.\n\
2972If a positive argument is given, prints \
2973how the nth following instruction will be redone."), &maintenanceprintlist);
2974}
int regnum
const char *const name
void * xmalloc(YYSIZE_T)
void xfree(void *)
struct gdbarch * get_current_arch(void)
Definition arch-utils.c:846
struct gdbarch * target_gdbarch(void)
void mark_async_event_handler(async_event_handler *async_handler_ptr)
async_event_handler * create_async_event_handler(async_event_handler_func *proc, gdb_client_data client_data, const char *name)
void clear_async_event_handler(async_event_handler *async_handler_ptr)
void delete_async_event_handler(async_event_handler **async_handler_ptr)
const std::vector< bp_location * > & all_bp_locations()
Definition breakpoint.c:733
int hardware_watchpoint_inserted_in_range(const address_space *aspace, CORE_ADDR addr, ULONGEST len)
int insert_single_step_breakpoints(struct gdbarch *gdbarch)
remove_bp_reason
Definition breakpoint.h:64
@ REMOVE_BREAKPOINT
Definition breakpoint.h:67
@ bp_loc_software_breakpoint
Definition breakpoint.h:316
int unpush_target(struct target_ops *t)
Definition inferior.c:96
void push_target(struct target_ops *t)
Definition inferior.h:406
struct process_stratum_target * process_target()
Definition inferior.h:449
enum register_status raw_read(int regnum, gdb_byte *buf)
Definition regcache.c:611
enum register_status cooked_read(int regnum, gdb_byte *buf)
Definition regcache.c:698
void info_record() override
bool can_execute_reverse() override
void goto_bookmark(const gdb_byte *, int) override
ptid_t wait(ptid_t, struct target_waitstatus *, target_wait_flags) override
enum record_method record_method(ptid_t ptid) override
void goto_record_begin() override
void goto_record_end() override
bool supports_stopped_by_hw_breakpoint() override
bool supports_delete_record() override
bool stopped_by_sw_breakpoint() override
void goto_record(ULONGEST insn) override
gdb_byte * get_bookmark(const char *, int) override
enum exec_direction_kind execution_direction() override
bool supports_stopped_by_sw_breakpoint() override
void close() override
bool stopped_by_watchpoint() override
void delete_record() override
strata stratum() const override
bool stopped_data_address(CORE_ADDR *) override
void save_record(const char *filename) override
void async(bool) override
bool record_will_replay(ptid_t ptid, int dir) override
bool stopped_by_hw_breakpoint() override
void record_stop_replaying() override
bool record_is_replaying(ptid_t ptid) override
const target_info & info() const override=0
enum target_xfer_status xfer_partial(enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len) override
void resume(ptid_t, int, enum gdb_signal) override
void store_registers(struct regcache *, int) override
void fetch_registers(struct regcache *regcache, int regno) override
void prepare_to_store(struct regcache *regcache) override
int remove_breakpoint(struct gdbarch *, struct bp_target_info *, enum remove_bp_reason) override
const target_info & info() const override
int insert_breakpoint(struct gdbarch *, struct bp_target_info *) override
bool has_execution(inferior *inf) override
void disconnect(const char *, int) override
void disconnect(const char *, int) override
void mourn_inferior() override
int remove_breakpoint(struct gdbarch *, struct bp_target_info *, enum remove_bp_reason) override
void kill() override
void store_registers(struct regcache *, int) override
void detach(inferior *, int) override
int insert_breakpoint(struct gdbarch *, struct bp_target_info *) override
enum target_xfer_status xfer_partial(enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len) override
void resume(ptid_t, int, enum gdb_signal) override
const target_info & info() const override
friend class regcache
Definition regcache.h:269
gdbarch * arch() const
Definition regcache.c:231
void invalidate(int regnum)
Definition regcache.c:312
void raw_supply(int regnum, const void *buf) override
Definition regcache.c:1062
friend class detached_regcache
Definition regcache.h:270
void cooked_write(int regnum, const gdb_byte *buf)
Definition regcache.c:870
const address_space * aspace() const
Definition regcache.h:343
static void ours()
Definition target.c:1070
void set_stop_pc(CORE_ADDR stop_pc)
Definition gdbthread.h:372
struct cmd_list_element * maintenanceprintlist
Definition cli-cmds.c:151
struct cmd_list_element * add_alias_cmd(const char *name, cmd_list_element *target, enum command_class theclass, int abbrev_flag, struct cmd_list_element **list)
Definition cli-decode.c:294
struct cmd_list_element * add_cmd(const char *name, enum command_class theclass, const char *doc, struct cmd_list_element **list)
Definition cli-decode.c:233
void set_cmd_completer(struct cmd_list_element *cmd, completer_ftype *completer)
Definition cli-decode.c:117
set_show_commands add_setshow_uinteger_cmd(const char *name, enum command_class theclass, unsigned int *var, const literal_def *extra_literals, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
struct cmd_list_element * deprecate_cmd(struct cmd_list_element *cmd, const char *replacement)
Definition cli-decode.c:280
set_show_commands add_setshow_prefix_cmd(const char *name, command_class theclass, const char *set_doc, const char *show_doc, cmd_list_element **set_subcommands_list, cmd_list_element **show_subcommands_list, cmd_list_element **set_list, cmd_list_element **show_list)
Definition cli-decode.c:428
struct cmd_list_element * add_prefix_cmd(const char *name, enum command_class theclass, cmd_simple_func_ftype *fun, const char *doc, struct cmd_list_element **subcommands, int allow_unknown, struct cmd_list_element **list)
Definition cli-decode.c:357
set_show_commands add_setshow_boolean_cmd(const char *name, enum command_class theclass, bool *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
Definition cli-decode.c:809
@ class_obscure
Definition command.h:64
@ class_maintenance
Definition command.h:65
@ class_support
Definition command.h:58
@ no_class
Definition command.h:53
void filename_completer(struct cmd_list_element *ignore, completion_tracker &tracker, const char *text, const char *word)
Definition completer.c:204
void core_file_command(const char *filename, int from_tty)
Definition corelow.c:395
static void store_unsigned_integer(gdb_byte *addr, int len, enum bfd_endian byte_order, ULONGEST val)
Definition defs.h:515
struct value * parse_and_eval(const char *exp, parser_flags flags)
Definition eval.c:70
void handle_sigint(int sig)
Definition event-top.c:1085
void exception_print(struct ui_file *file, const struct gdb_exception &e)
Definition exceptions.c:106
target_section_table build_section_table(struct bfd *some_bfd)
Definition exec.c:572
void reinit_frame_cache(void)
Definition frame.c:2107
frame_info_ptr get_selected_frame(const char *message)
Definition frame.c:1888
@ SRC_AND_LOC
Definition frame.h:811
void print_stack_frame(frame_info_ptr, int print_level, enum print_what print_what, int set_current_sal)
Definition stack.c:353
gdb_bfd_ref_ptr create_gcore_bfd(const char *filename)
Definition gcore.c:55
void write_gcore_file(bfd *obfd)
Definition gcore.c:115
gdb::ref_ptr< struct bfd, gdb_bfd_ref_policy > gdb_bfd_ref_ptr
Definition gdb_bfd.h:79
const char * gdbarch_register_name(struct gdbarch *gdbarch, int regnr)
Definition gdbarch.c:2173
int gdbarch_process_record_signal(struct gdbarch *gdbarch, struct regcache *regcache, enum gdb_signal signal)
Definition gdbarch.c:4379
struct type * gdbarch_register_type(struct gdbarch *gdbarch, int reg_nr)
Definition gdbarch.c:2194
int gdbarch_num_regs(struct gdbarch *gdbarch)
Definition gdbarch.c:1930
bfd * obfd
int gdbarch_process_record(struct gdbarch *gdbarch, struct regcache *regcache, CORE_ADDR addr)
Definition gdbarch.c:4355
bool gdbarch_process_record_signal_p(struct gdbarch *gdbarch)
Definition gdbarch.c:4372
bool gdbarch_software_single_step_p(struct gdbarch *gdbarch)
Definition gdbarch.c:3288
bool gdbarch_process_record_p(struct gdbarch *gdbarch)
Definition gdbarch.c:4348
void execute_command(const char *, int)
Definition top.c:459
#define core_bfd
Definition gdbcore.h:130
all_non_exited_threads_range all_non_exited_threads(process_stratum_target *proc_target=nullptr, ptid_t filter_ptid=minus_one_ptid)
Definition gdbthread.h:753
void set_executing(process_stratum_target *targ, ptid_t ptid, bool executing)
Definition thread.c:908
struct thread_info * inferior_thread(void)
Definition thread.c:85
void switch_to_thread(struct thread_info *thr)
Definition thread.c:1360
int thread_has_single_step_breakpoints_set(struct thread_info *tp)
Definition thread.c:142
void delete_single_step_breakpoints(struct thread_info *tp)
Definition thread.c:120
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t int status
Definition gnu-nat.c:1790
void inferior_event_handler(enum inferior_event_type event_type)
Definition inf-loop.c:37
ptid_t inferior_ptid
Definition infcmd.c:74
struct inferior * current_inferior(void)
Definition inferior.c:55
enum exec_direction_kind execution_direction
Definition infrun.c:9768
bool non_stop
Definition infrun.c:226
exec_direction_kind
Definition infrun.h:112
@ EXEC_REVERSE
Definition infrun.h:114
@ EXEC_FORWARD
Definition infrun.h:113
void interps_notify_record_changed(inferior *inf, int started, const char *method, const char *format)
Definition interps.c:474
static void record_full_restore(void)
static struct record_full_entry * record_full_end_alloc(void)
static unsigned int record_full_insn_num
#define DEFAULT_RECORD_FULL_INSN_MAX_NUM
Definition record-full.c:67
static void record_full_end_release(struct record_full_entry *rec)
static enum exec_direction_kind record_full_execution_dir
record_full_type
@ record_full_end
@ record_full_reg
@ record_full_mem
static struct record_full_entry * record_full_list
static void record_full_registers_change(struct regcache *regcache, int regnum)
static void record_full_goto_entry(struct record_full_entry *p)
static const char record_doc[]
static struct record_full_entry * record_full_arch_list_tail
static ptid_t record_full_resume_ptid
static void record_full_sig_handler(int signo)
static void cmd_record_full_start(const char *args, int from_tty)
static void record_full_goto_insn(struct record_full_entry *entry, enum exec_direction_kind dir)
static unsigned int record_full_insn_max_num
#define RECORD_FULL_IS_REPLAY
Definition record-full.c:69
static int record_full_resume_step
static struct cmd_list_element * set_record_full_cmdlist
static enum target_stop_reason record_full_stop_reason
static void record_full_exec_insn(struct regcache *regcache, struct gdbarch *gdbarch, struct record_full_entry *entry)
bool record_full_memory_query
static struct cmd_list_element * show_record_full_cmdlist
static void record_full_check_insn_num(void)
static const target_info record_full_target_info
static void record_full_message(struct regcache *regcache, enum gdb_signal signal)
static struct cmd_list_element * record_full_cmdlist
static void record_full_list_release_following(struct record_full_entry *rec)
int record_full_arch_list_add_reg(struct regcache *regcache, int regnum)
static uint64_t netorder64(uint64_t input)
static struct async_event_handler * record_full_async_inferior_event_token
static record_full_core_target record_full_core_ops
static void maintenance_print_record_instruction(const char *args, int from_tty)
#define RECORD_FULL_FILE_MAGIC
Definition record-full.c:72
static void set_record_full_insn_max_num(const char *args, int from_tty, struct cmd_list_element *c)
static struct record_full_entry record_full_first
int record_full_arch_list_add_mem(CORE_ADDR addr, int len)
static struct record_full_entry * record_full_arch_list_head
int record_full_arch_list_add_end(void)
static struct record_full_entry * record_full_mem_alloc(CORE_ADDR addr, int len)
static uint32_t netorder32(uint32_t input)
static void bfdcore_write(bfd *obfd, asection *osec, void *buf, int len, int *offset)
static void record_full_list_release(struct record_full_entry *rec)
static void record_full_mem_release(struct record_full_entry *rec)
static record_full_target record_full_ops
static int record_full_gdb_operation_disable
static void record_full_arch_list_add(struct record_full_entry *rec)
static void record_full_list_release_first(void)
static void record_full_open_1(const char *name, int from_tty)
void _initialize_record_full()
static bool record_full_message_wrapper_safe(struct regcache *regcache, enum gdb_signal signal)
static int record_full_get_sig
static bool record_full_stop_at_limit
int record_full_is_used(void)
static ULONGEST record_full_insn_count
static void record_full_reg_release(struct record_full_entry *rec)
static detached_regcache * record_full_core_regbuf
static ptid_t record_full_wait_1(struct target_ops *ops, ptid_t ptid, struct target_waitstatus *status, target_wait_flags options)
static void record_full_core_open_1(const char *name, int from_tty)
static struct record_full_core_buf_entry * record_full_core_buf_list
static struct record_full_entry * record_full_reg_alloc(struct regcache *regcache, int regnum)
static target_section_table record_full_core_sections
static std::vector< record_full_breakpoint > record_full_breakpoints
static void record_full_init_record_breakpoints(void)
static gdb_byte * record_full_get_loc(struct record_full_entry *rec)
static enum record_full_type record_full_entry_release(struct record_full_entry *rec)
static void bfdcore_read(bfd *obfd, asection *osec, void *buf, int len, int *offset)
static void cmd_record_full_restore(const char *args, int from_tty)
static const target_info record_full_core_target_info
static const char record_longname[]
static void record_full_open(const char *name, int from_tty)
static int record_full_resumed
static void record_full_async_inferior_event_handler(gdb_client_data data)
scoped_restore_tmpl< int > record_full_gdb_operation_disable_set(void)
void record_detach(struct target_ops *t, inferior *inf, int from_tty)
Definition record.c:191
unsigned int record_debug
Definition record.c:34
struct cmd_list_element * set_record_cmdlist
Definition record.c:53
void record_goto(const char *arg)
Definition record.c:363
int record_read_memory(struct gdbarch *gdbarch, CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
Definition record.c:140
struct cmd_list_element * show_record_cmdlist
Definition record.c:54
void record_disconnect(struct target_ops *t, const char *args, int from_tty)
Definition record.c:176
struct cmd_list_element * record_cmdlist
Definition record.c:51
struct target_ops * find_record_target(void)
Definition record.c:64
void record_preopen(void)
Definition record.c:87
void record_mourn_inferior(struct target_ops *t)
Definition record.c:206
void record_kill(struct target_ops *t)
Definition record.c:222
int record_check_stopped_by_breakpoint(const address_space *aspace, CORE_ADDR pc, enum target_stop_reason *reason)
Definition record.c:238
record_method
Definition record.h:44
@ RECORD_METHOD_FULL
Definition record.h:49
CORE_ADDR regcache_read_pc(struct regcache *regcache)
Definition regcache.c:1333
int register_size(struct gdbarch *gdbarch, int regnum)
Definition regcache.c:170
struct regcache * get_current_regcache(void)
Definition regcache.c:429
void registers_changed(void)
Definition regcache.c:580
enum var_types type
Definition scm-param.c:142
#define enable()
Definition ser-go32.c:239
CORE_ADDR placed_address
Definition breakpoint.h:266
struct address_space * placed_address_space
Definition breakpoint.h:259
Definition gnu-nat.c:153
struct address_space * address_space
record_full_breakpoint(struct address_space *address_space_, CORE_ADDR addr_, bool in_target_beneath_)
struct target_section * p
bfd_byte * buf
struct record_full_core_buf_entry * prev
ULONGEST insn_num
enum gdb_signal sigval
struct record_full_mem_entry mem
struct record_full_end_entry end
enum record_full_type type
union record_full_entry::@159 u
struct record_full_entry * next
struct record_full_entry * prev
struct record_full_reg_entry reg
Definition record-full.c:86
CORE_ADDR addr
Definition record-full.c:87
gdb_byte * ptr
Definition record-full.c:94
union record_full_mem_entry::@157 u
int len
Definition record-full.c:88
gdb_byte buf[sizeof(gdb_byte *)]
Definition record-full.c:95
int mem_entry_not_accessible
Definition record-full.c:91
gdb_byte buf[2 *sizeof(gdb_byte *)]
unsigned short num
gdb_byte * ptr
union record_full_reg_entry::@158 u
unsigned short len
cmd_list_element * set
Definition command.h:422
cmd_list_element * show
Definition command.h:422
virtual ptid_t wait(ptid_t, struct target_waitstatus *, target_wait_flags options) TARGET_DEFAULT_FUNC(default_target_wait)
virtual int remove_breakpoint(struct gdbarch *, struct bp_target_info *, enum remove_bp_reason) TARGET_DEFAULT_NORETURN(noprocess())
virtual bool stopped_by_watchpoint() TARGET_DEFAULT_RETURN(false)
target_ops * beneath() const
Definition target.c:3041
virtual bool stopped_data_address(CORE_ADDR *) TARGET_DEFAULT_RETURN(false)
virtual void commit_resumed() TARGET_DEFAULT_IGNORE()
virtual void store_registers(struct regcache *, int) TARGET_DEFAULT_NORETURN(noprocess())
virtual enum target_xfer_status xfer_partial(enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len) TARGET_DEFAULT_RETURN(TARGET_XFER_E_IO)
virtual void async(bool) TARGET_DEFAULT_NORETURN(tcomplain())
virtual void resume(ptid_t, int TARGET_DEBUG_PRINTER(target_debug_print_step), enum gdb_signal) TARGET_DEFAULT_NORETURN(noprocess())
virtual int insert_breakpoint(struct gdbarch *, struct bp_target_info *) TARGET_DEFAULT_NORETURN(noprocess())
Definition value.h:130
std::vector< target_section > target_section_table
void target_fetch_registers(struct regcache *regcache, int regno)
Definition target.c:3928
void target_pass_signals(gdb::array_view< const unsigned char > pass_signals)
Definition target.c:2698
gdbarch * target_thread_architecture(ptid_t ptid)
Definition target.c:434
void add_deprecated_target_alias(const target_info &tinfo, const char *alias)
Definition target.c:896
int target_write_memory(CORE_ADDR memaddr, const gdb_byte *myaddr, ssize_t len)
Definition target.c:1861
bool target_has_execution(inferior *inf)
Definition target.c:201
void add_target(const target_info &t, target_open_ftype *func, completer_ftype *completer)
Definition target.c:868
bool target_stopped_by_watchpoint()
Definition target.c:470
@ INF_REG_EVENT
Definition target.h:134
target_xfer_status
Definition target.h:219
@ TARGET_XFER_E_IO
Definition target.h:232
@ TARGET_XFER_EOF
Definition target.h:224
@ TARGET_XFER_OK
Definition target.h:221
target_object
Definition target.h:143
@ TARGET_OBJECT_RAW_MEMORY
Definition target.h:151
@ TARGET_OBJECT_MEMORY
Definition target.h:147
strata
Definition target.h:94
@ record_stratum
Definition target.h:99
const char * print_core_address(struct gdbarch *gdbarch, CORE_ADDR address)
Definition utils.c:3187
int query(const char *ctlstr,...)
Definition utils.c:943
const char * paddress(struct gdbarch *gdbarch, CORE_ADDR addr)
Definition utils.c:3166
int yquery(const char *ctlstr,...)
Definition utils.c:926
void gdb_printf(struct ui_file *stream, const char *format,...)
Definition utils.c:1886
#define gdb_stderr
Definition utils.h:187
#define gdb_stdlog
Definition utils.h:190
#define gdb_stdout
Definition utils.h:182
void value_print(struct value *val, struct ui_file *stream, const struct value_print_options *options)
Definition valprint.c:1191
void get_user_print_options(struct value_print_options *opts)
Definition valprint.c:135
struct value * value_from_contents(struct type *type, const gdb_byte *contents)
Definition value.c:3581
LONGEST value_as_long(struct value *val)
Definition value.c:2554
@ TARGET_WNOHANG
Definition wait.h:32
@ TARGET_WAITKIND_STOPPED
Definition waitstatus.h:36
@ TARGET_WAITKIND_IGNORE
Definition waitstatus.h:89
target_stop_reason
Definition waitstatus.h:428
@ TARGET_STOPPED_BY_SW_BREAKPOINT
Definition waitstatus.h:434
@ TARGET_STOPPED_BY_WATCHPOINT
Definition waitstatus.h:440
@ TARGET_STOPPED_BY_HW_BREAKPOINT
Definition waitstatus.h:437
@ TARGET_STOPPED_BY_NO_REASON
Definition waitstatus.h:431