1 /* Process record and replay target for GDB, the GNU debugger.
3 Copyright (C) 2013-2020 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
23 #include "gdbthread.h"
25 #include "event-top.h"
26 #include "completer.h"
27 #include "arch-utils.h"
31 #include "record-full.h"
34 #include "gdbsupport/event-loop.h"
37 #include "observable.h"
39 #include "gdbsupport/gdb_unlinker.h"
40 #include "gdbsupport/byte-vector.h"
41 #include "async-event.h"
45 /* This module implements "target record-full", also known as "process
46 record and replay". This target sits on top of a "normal" target
47 (a target that "has execution"), and provides a record and replay
48 functionality, including reverse debugging.
50 Target record has two modes: recording, and replaying.
52 In record mode, we intercept the resume and wait methods.
53 Whenever gdb resumes the target, we run the target in single step
54 mode, and we build up an execution log in which, for each executed
55 instruction, we record all changes in memory and register state.
56 This is invisible to the user, to whom it just looks like an
57 ordinary debugging session (except for performance degradation).
59 In replay mode, instead of actually letting the inferior run as a
60 process, we simulate its execution by playing back the recorded
61 execution log. For each instruction in the log, we simulate the
62 instruction's side effects by duplicating the changes that it would
63 have made on memory and registers. */
65 #define DEFAULT_RECORD_FULL_INSN_MAX_NUM 200000
67 #define RECORD_FULL_IS_REPLAY \
68 (record_full_list->next || ::execution_direction == EXEC_REVERSE)
70 #define RECORD_FULL_FILE_MAGIC netorder32(0x20091016)
72 /* These are the core structs of the process record functionality.
74 A record_full_entry is a record of the value change of a register
75 ("record_full_reg") or a part of memory ("record_full_mem"). And each
76 instruction must have a struct record_full_entry ("record_full_end")
77 that indicates that this is the last struct record_full_entry of this
80 Each struct record_full_entry is linked to "record_full_list" by "prev"
81 and "next" pointers. */
83 struct record_full_mem_entry
87 /* Set this flag if target memory for this entry
88 can no longer be accessed. */
89 int mem_entry_not_accessible;
93 gdb_byte buf[sizeof (gdb_byte *)];
97 struct record_full_reg_entry
104 gdb_byte buf[2 * sizeof (gdb_byte *)];
108 struct record_full_end_entry
110 enum gdb_signal sigval;
114 enum record_full_type
121 /* This is the data structure that makes up the execution log.
123 The execution log consists of a single linked list of entries
124 of type "struct record_full_entry". It is doubly linked so that it
125 can be traversed in either direction.
127 The start of the list is anchored by a struct called
128 "record_full_first". The pointer "record_full_list" either points
129 to the last entry that was added to the list (in record mode), or to
130 the next entry in the list that will be executed (in replay mode).
132 Each list element (struct record_full_entry), in addition to next
133 and prev pointers, consists of a union of three entry types: mem,
134 reg, and end. A field called "type" determines which entry type is
135 represented by a given list element.
137 Each instruction that is added to the execution log is represented
138 by a variable number of list elements ('entries'). The instruction
139 will have one "reg" entry for each register that is changed by
140 executing the instruction (including the PC in every case). It
141 will also have one "mem" entry for each memory change. Finally,
142 each instruction will have an "end" entry that separates it from
143 the changes associated with the next instruction. */
145 struct record_full_entry
147 struct record_full_entry *prev;
148 struct record_full_entry *next;
149 enum record_full_type type;
153 struct record_full_reg_entry reg;
155 struct record_full_mem_entry mem;
157 struct record_full_end_entry end;
161 /* If true, query if PREC cannot record memory
162 change of next instruction. */
163 bool record_full_memory_query = false;
165 struct record_full_core_buf_entry
167 struct record_full_core_buf_entry *prev;
168 struct target_section *p;
172 /* Record buf with core target. */
173 static detached_regcache *record_full_core_regbuf = NULL;
174 static target_section_table record_full_core_sections;
175 static struct record_full_core_buf_entry *record_full_core_buf_list = NULL;
177 /* The following variables are used for managing the linked list that
178 represents the execution log.
180 record_full_first is the anchor that holds down the beginning of
183 record_full_list serves two functions:
184 1) In record mode, it anchors the end of the list.
185 2) In replay mode, it traverses the list and points to
186 the next instruction that must be emulated.
188 record_full_arch_list_head and record_full_arch_list_tail are used
189 to manage a separate list, which is used to build up the change
190 elements of the currently executing instruction during record mode.
191 When this instruction has been completely annotated in the "arch
192 list", it will be appended to the main execution log. */
194 static struct record_full_entry record_full_first;
195 static struct record_full_entry *record_full_list = &record_full_first;
196 static struct record_full_entry *record_full_arch_list_head = NULL;
197 static struct record_full_entry *record_full_arch_list_tail = NULL;
199 /* true ask user. false auto delete the last struct record_full_entry. */
200 static bool record_full_stop_at_limit = true;
201 /* Maximum allowed number of insns in execution log. */
202 static unsigned int record_full_insn_max_num
203 = DEFAULT_RECORD_FULL_INSN_MAX_NUM;
204 /* Actual count of insns presently in execution log. */
205 static unsigned int record_full_insn_num = 0;
206 /* Count of insns logged so far (may be larger
207 than count of insns presently in execution log). */
208 static ULONGEST record_full_insn_count;
210 static const char record_longname[]
211 = N_("Process record and replay target");
212 static const char record_doc[]
213 = N_("Log program while executing and replay execution from log.");
215 /* Base class implementing functionality common to both the
216 "record-full" and "record-core" targets. */
218 class record_full_base_target : public target_ops
221 const target_info &info () const override = 0;
223 strata stratum () const override { return record_stratum; }
225 void close () override;
226 void async (int) override;
227 ptid_t wait (ptid_t, struct target_waitstatus *, target_wait_flags) override;
228 bool stopped_by_watchpoint () override;
229 bool stopped_data_address (CORE_ADDR *) override;
231 bool stopped_by_sw_breakpoint () override;
232 bool supports_stopped_by_sw_breakpoint () override;
234 bool stopped_by_hw_breakpoint () override;
235 bool supports_stopped_by_hw_breakpoint () override;
237 bool can_execute_reverse () override;
239 /* Add bookmark target methods. */
240 gdb_byte *get_bookmark (const char *, int) override;
241 void goto_bookmark (const gdb_byte *, int) override;
242 enum exec_direction_kind execution_direction () override;
243 enum record_method record_method (ptid_t ptid) override;
244 void info_record () override;
245 void save_record (const char *filename) override;
246 bool supports_delete_record () override;
247 void delete_record () override;
248 bool record_is_replaying (ptid_t ptid) override;
249 bool record_will_replay (ptid_t ptid, int dir) override;
250 void record_stop_replaying () override;
251 void goto_record_begin () override;
252 void goto_record_end () override;
253 void goto_record (ULONGEST insn) override;
256 /* The "record-full" target. */
258 static const target_info record_full_target_info = {
264 class record_full_target final : public record_full_base_target
267 const target_info &info () const override
268 { return record_full_target_info; }
270 void commit_resume () override;
271 void resume (ptid_t, int, enum gdb_signal) override;
272 void disconnect (const char *, int) override;
273 void detach (inferior *, int) override;
274 void mourn_inferior () override;
275 void kill () override;
276 void store_registers (struct regcache *, int) override;
277 enum target_xfer_status xfer_partial (enum target_object object,
280 const gdb_byte *writebuf,
281 ULONGEST offset, ULONGEST len,
282 ULONGEST *xfered_len) override;
283 int insert_breakpoint (struct gdbarch *,
284 struct bp_target_info *) override;
285 int remove_breakpoint (struct gdbarch *,
286 struct bp_target_info *,
287 enum remove_bp_reason) override;
290 /* The "record-core" target. */
292 static const target_info record_full_core_target_info = {
298 class record_full_core_target final : public record_full_base_target
301 const target_info &info () const override
302 { return record_full_core_target_info; }
304 void resume (ptid_t, int, enum gdb_signal) override;
305 void disconnect (const char *, int) override;
306 void kill () override;
307 void fetch_registers (struct regcache *regcache, int regno) override;
308 void prepare_to_store (struct regcache *regcache) override;
309 void store_registers (struct regcache *, int) override;
310 enum target_xfer_status xfer_partial (enum target_object object,
313 const gdb_byte *writebuf,
314 ULONGEST offset, ULONGEST len,
315 ULONGEST *xfered_len) override;
316 int insert_breakpoint (struct gdbarch *,
317 struct bp_target_info *) override;
318 int remove_breakpoint (struct gdbarch *,
319 struct bp_target_info *,
320 enum remove_bp_reason) override;
322 bool has_execution (inferior *inf) override;
325 static record_full_target record_full_ops;
326 static record_full_core_target record_full_core_ops;
329 record_full_target::detach (inferior *inf, int from_tty)
331 record_detach (this, inf, from_tty);
335 record_full_target::disconnect (const char *args, int from_tty)
337 record_disconnect (this, args, from_tty);
341 record_full_core_target::disconnect (const char *args, int from_tty)
343 record_disconnect (this, args, from_tty);
347 record_full_target::mourn_inferior ()
349 record_mourn_inferior (this);
353 record_full_target::kill ()
358 /* See record-full.h. */
361 record_full_is_used (void)
363 struct target_ops *t;
365 t = find_record_target ();
366 return (t == &record_full_ops
367 || t == &record_full_core_ops);
371 /* Command lists for "set/show record full". */
372 static struct cmd_list_element *set_record_full_cmdlist;
373 static struct cmd_list_element *show_record_full_cmdlist;
375 /* Command list for "record full". */
376 static struct cmd_list_element *record_full_cmdlist;
378 static void record_full_goto_insn (struct record_full_entry *entry,
379 enum exec_direction_kind dir);
381 /* Alloc and free functions for record_full_reg, record_full_mem, and
382 record_full_end entries. */
384 /* Alloc a record_full_reg record entry. */
386 static inline struct record_full_entry *
387 record_full_reg_alloc (struct regcache *regcache, int regnum)
389 struct record_full_entry *rec;
390 struct gdbarch *gdbarch = regcache->arch ();
392 rec = XCNEW (struct record_full_entry);
393 rec->type = record_full_reg;
394 rec->u.reg.num = regnum;
395 rec->u.reg.len = register_size (gdbarch, regnum);
396 if (rec->u.reg.len > sizeof (rec->u.reg.u.buf))
397 rec->u.reg.u.ptr = (gdb_byte *) xmalloc (rec->u.reg.len);
402 /* Free a record_full_reg record entry. */
405 record_full_reg_release (struct record_full_entry *rec)
407 gdb_assert (rec->type == record_full_reg);
408 if (rec->u.reg.len > sizeof (rec->u.reg.u.buf))
409 xfree (rec->u.reg.u.ptr);
413 /* Alloc a record_full_mem record entry. */
415 static inline struct record_full_entry *
416 record_full_mem_alloc (CORE_ADDR addr, int len)
418 struct record_full_entry *rec;
420 rec = XCNEW (struct record_full_entry);
421 rec->type = record_full_mem;
422 rec->u.mem.addr = addr;
423 rec->u.mem.len = len;
424 if (rec->u.mem.len > sizeof (rec->u.mem.u.buf))
425 rec->u.mem.u.ptr = (gdb_byte *) xmalloc (len);
430 /* Free a record_full_mem record entry. */
433 record_full_mem_release (struct record_full_entry *rec)
435 gdb_assert (rec->type == record_full_mem);
436 if (rec->u.mem.len > sizeof (rec->u.mem.u.buf))
437 xfree (rec->u.mem.u.ptr);
441 /* Alloc a record_full_end record entry. */
443 static inline struct record_full_entry *
444 record_full_end_alloc (void)
446 struct record_full_entry *rec;
448 rec = XCNEW (struct record_full_entry);
449 rec->type = record_full_end;
454 /* Free a record_full_end record entry. */
457 record_full_end_release (struct record_full_entry *rec)
462 /* Free one record entry, any type.
463 Return entry->type, in case caller wants to know. */
465 static inline enum record_full_type
466 record_full_entry_release (struct record_full_entry *rec)
468 enum record_full_type type = rec->type;
471 case record_full_reg:
472 record_full_reg_release (rec);
474 case record_full_mem:
475 record_full_mem_release (rec);
477 case record_full_end:
478 record_full_end_release (rec);
484 /* Free all record entries in list pointed to by REC. */
487 record_full_list_release (struct record_full_entry *rec)
498 record_full_entry_release (rec->next);
501 if (rec == &record_full_first)
503 record_full_insn_num = 0;
504 record_full_first.next = NULL;
507 record_full_entry_release (rec);
510 /* Free all record entries forward of the given list position. */
513 record_full_list_release_following (struct record_full_entry *rec)
515 struct record_full_entry *tmp = rec->next;
521 if (record_full_entry_release (tmp) == record_full_end)
523 record_full_insn_num--;
524 record_full_insn_count--;
530 /* Delete the first instruction from the beginning of the log, to make
531 room for adding a new instruction at the end of the log.
533 Note -- this function does not modify record_full_insn_num. */
536 record_full_list_release_first (void)
538 struct record_full_entry *tmp;
540 if (!record_full_first.next)
543 /* Loop until a record_full_end. */
546 /* Cut record_full_first.next out of the linked list. */
547 tmp = record_full_first.next;
548 record_full_first.next = tmp->next;
549 tmp->next->prev = &record_full_first;
551 /* tmp is now isolated, and can be deleted. */
552 if (record_full_entry_release (tmp) == record_full_end)
553 break; /* End loop at first record_full_end. */
555 if (!record_full_first.next)
557 gdb_assert (record_full_insn_num == 1);
558 break; /* End loop when list is empty. */
563 /* Add a struct record_full_entry to record_full_arch_list. */
566 record_full_arch_list_add (struct record_full_entry *rec)
568 if (record_debug > 1)
569 fprintf_unfiltered (gdb_stdlog,
570 "Process record: record_full_arch_list_add %s.\n",
571 host_address_to_string (rec));
573 if (record_full_arch_list_tail)
575 record_full_arch_list_tail->next = rec;
576 rec->prev = record_full_arch_list_tail;
577 record_full_arch_list_tail = rec;
581 record_full_arch_list_head = rec;
582 record_full_arch_list_tail = rec;
586 /* Return the value storage location of a record entry. */
587 static inline gdb_byte *
588 record_full_get_loc (struct record_full_entry *rec)
591 case record_full_mem:
592 if (rec->u.mem.len > sizeof (rec->u.mem.u.buf))
593 return rec->u.mem.u.ptr;
595 return rec->u.mem.u.buf;
596 case record_full_reg:
597 if (rec->u.reg.len > sizeof (rec->u.reg.u.buf))
598 return rec->u.reg.u.ptr;
600 return rec->u.reg.u.buf;
601 case record_full_end:
603 gdb_assert_not_reached ("unexpected record_full_entry type");
608 /* Record the value of a register NUM to record_full_arch_list. */
611 record_full_arch_list_add_reg (struct regcache *regcache, int regnum)
613 struct record_full_entry *rec;
615 if (record_debug > 1)
616 fprintf_unfiltered (gdb_stdlog,
617 "Process record: add register num = %d to "
621 rec = record_full_reg_alloc (regcache, regnum);
623 regcache->raw_read (regnum, record_full_get_loc (rec));
625 record_full_arch_list_add (rec);
630 /* Record the value of a region of memory whose address is ADDR and
631 length is LEN to record_full_arch_list. */
634 record_full_arch_list_add_mem (CORE_ADDR addr, int len)
636 struct record_full_entry *rec;
638 if (record_debug > 1)
639 fprintf_unfiltered (gdb_stdlog,
640 "Process record: add mem addr = %s len = %d to "
642 paddress (target_gdbarch (), addr), len);
644 if (!addr) /* FIXME: Why? Some arch must permit it... */
647 rec = record_full_mem_alloc (addr, len);
649 if (record_read_memory (target_gdbarch (), addr,
650 record_full_get_loc (rec), len))
652 record_full_mem_release (rec);
656 record_full_arch_list_add (rec);
661 /* Add a record_full_end type struct record_full_entry to
662 record_full_arch_list. */
665 record_full_arch_list_add_end (void)
667 struct record_full_entry *rec;
669 if (record_debug > 1)
670 fprintf_unfiltered (gdb_stdlog,
671 "Process record: add end to arch list.\n");
673 rec = record_full_end_alloc ();
674 rec->u.end.sigval = GDB_SIGNAL_0;
675 rec->u.end.insn_num = ++record_full_insn_count;
677 record_full_arch_list_add (rec);
683 record_full_check_insn_num (void)
685 if (record_full_insn_num == record_full_insn_max_num)
687 /* Ask user what to do. */
688 if (record_full_stop_at_limit)
690 if (!yquery (_("Do you want to auto delete previous execution "
691 "log entries when record/replay buffer becomes "
692 "full (record full stop-at-limit)?")))
693 error (_("Process record: stopped by user."));
694 record_full_stop_at_limit = 0;
699 /* Before inferior step (when GDB record the running message, inferior
700 only can step), GDB will call this function to record the values to
701 record_full_list. This function will call gdbarch_process_record to
702 record the running message of inferior and set them to
703 record_full_arch_list, and add it to record_full_list. */
706 record_full_message (struct regcache *regcache, enum gdb_signal signal)
709 struct gdbarch *gdbarch = regcache->arch ();
713 record_full_arch_list_head = NULL;
714 record_full_arch_list_tail = NULL;
716 /* Check record_full_insn_num. */
717 record_full_check_insn_num ();
719 /* If gdb sends a signal value to target_resume,
720 save it in the 'end' field of the previous instruction.
722 Maybe process record should record what really happened,
723 rather than what gdb pretends has happened.
725 So if Linux delivered the signal to the child process during
726 the record mode, we will record it and deliver it again in
729 If user says "ignore this signal" during the record mode, then
730 it will be ignored again during the replay mode (no matter if
731 the user says something different, like "deliver this signal"
732 during the replay mode).
734 User should understand that nothing he does during the replay
735 mode will change the behavior of the child. If he tries,
736 then that is a user error.
738 But we should still deliver the signal to gdb during the replay,
739 if we delivered it during the recording. Therefore we should
740 record the signal during record_full_wait, not
741 record_full_resume. */
742 if (record_full_list != &record_full_first) /* FIXME better way
745 gdb_assert (record_full_list->type == record_full_end);
746 record_full_list->u.end.sigval = signal;
749 if (signal == GDB_SIGNAL_0
750 || !gdbarch_process_record_signal_p (gdbarch))
751 ret = gdbarch_process_record (gdbarch,
753 regcache_read_pc (regcache));
755 ret = gdbarch_process_record_signal (gdbarch,
760 error (_("Process record: inferior program stopped."));
762 error (_("Process record: failed to record execution log."));
764 catch (const gdb_exception &ex)
766 record_full_list_release (record_full_arch_list_tail);
770 record_full_list->next = record_full_arch_list_head;
771 record_full_arch_list_head->prev = record_full_list;
772 record_full_list = record_full_arch_list_tail;
774 if (record_full_insn_num == record_full_insn_max_num)
775 record_full_list_release_first ();
777 record_full_insn_num++;
781 record_full_message_wrapper_safe (struct regcache *regcache,
782 enum gdb_signal signal)
786 record_full_message (regcache, signal);
788 catch (const gdb_exception &ex)
790 exception_print (gdb_stderr, ex);
797 /* Set to 1 if record_full_store_registers and record_full_xfer_partial
798 doesn't need record. */
800 static int record_full_gdb_operation_disable = 0;
802 scoped_restore_tmpl<int>
803 record_full_gdb_operation_disable_set (void)
805 return make_scoped_restore (&record_full_gdb_operation_disable, 1);
808 /* Flag set to TRUE for target_stopped_by_watchpoint. */
809 static enum target_stop_reason record_full_stop_reason
810 = TARGET_STOPPED_BY_NO_REASON;
812 /* Execute one instruction from the record log. Each instruction in
813 the log will be represented by an arbitrary sequence of register
814 entries and memory entries, followed by an 'end' entry. */
817 record_full_exec_insn (struct regcache *regcache,
818 struct gdbarch *gdbarch,
819 struct record_full_entry *entry)
823 case record_full_reg: /* reg */
825 gdb::byte_vector reg (entry->u.reg.len);
827 if (record_debug > 1)
828 fprintf_unfiltered (gdb_stdlog,
829 "Process record: record_full_reg %s to "
830 "inferior num = %d.\n",
831 host_address_to_string (entry),
834 regcache->cooked_read (entry->u.reg.num, reg.data ());
835 regcache->cooked_write (entry->u.reg.num, record_full_get_loc (entry));
836 memcpy (record_full_get_loc (entry), reg.data (), entry->u.reg.len);
840 case record_full_mem: /* mem */
842 /* Nothing to do if the entry is flagged not_accessible. */
843 if (!entry->u.mem.mem_entry_not_accessible)
845 gdb::byte_vector mem (entry->u.mem.len);
847 if (record_debug > 1)
848 fprintf_unfiltered (gdb_stdlog,
849 "Process record: record_full_mem %s to "
850 "inferior addr = %s len = %d.\n",
851 host_address_to_string (entry),
852 paddress (gdbarch, entry->u.mem.addr),
855 if (record_read_memory (gdbarch,
856 entry->u.mem.addr, mem.data (),
858 entry->u.mem.mem_entry_not_accessible = 1;
861 if (target_write_memory (entry->u.mem.addr,
862 record_full_get_loc (entry),
865 entry->u.mem.mem_entry_not_accessible = 1;
867 warning (_("Process record: error writing memory at "
868 "addr = %s len = %d."),
869 paddress (gdbarch, entry->u.mem.addr),
874 memcpy (record_full_get_loc (entry), mem.data (),
877 /* We've changed memory --- check if a hardware
878 watchpoint should trap. Note that this
879 presently assumes the target beneath supports
880 continuable watchpoints. On non-continuable
881 watchpoints target, we'll want to check this
882 _before_ actually doing the memory change, and
883 not doing the change at all if the watchpoint
885 if (hardware_watchpoint_inserted_in_range
886 (regcache->aspace (),
887 entry->u.mem.addr, entry->u.mem.len))
888 record_full_stop_reason = TARGET_STOPPED_BY_WATCHPOINT;
897 static void record_full_restore (void);
899 /* Asynchronous signal handle registered as event loop source for when
900 we have pending events ready to be passed to the core. */
902 static struct async_event_handler *record_full_async_inferior_event_token;
905 record_full_async_inferior_event_handler (gdb_client_data data)
907 inferior_event_handler (INF_REG_EVENT);
910 /* Open the process record target for 'core' files. */
913 record_full_core_open_1 (const char *name, int from_tty)
915 struct regcache *regcache = get_current_regcache ();
916 int regnum = gdbarch_num_regs (regcache->arch ());
919 /* Get record_full_core_regbuf. */
920 target_fetch_registers (regcache, -1);
921 record_full_core_regbuf = new detached_regcache (regcache->arch (), false);
923 for (i = 0; i < regnum; i ++)
924 record_full_core_regbuf->raw_supply (i, *regcache);
926 record_full_core_sections = build_section_table (core_bfd);
928 push_target (&record_full_core_ops);
929 record_full_restore ();
932 /* Open the process record target for 'live' processes. */
935 record_full_open_1 (const char *name, int from_tty)
938 fprintf_unfiltered (gdb_stdlog, "Process record: record_full_open_1\n");
941 if (!target_has_execution ())
942 error (_("Process record: the program is not being run."));
944 error (_("Process record target can't debug inferior in non-stop mode "
947 if (!gdbarch_process_record_p (target_gdbarch ()))
948 error (_("Process record: the current architecture doesn't support "
949 "record function."));
951 push_target (&record_full_ops);
954 static void record_full_init_record_breakpoints (void);
956 /* Open the process record target. */
959 record_full_open (const char *name, int from_tty)
962 fprintf_unfiltered (gdb_stdlog, "Process record: record_full_open\n");
967 record_full_insn_num = 0;
968 record_full_insn_count = 0;
969 record_full_list = &record_full_first;
970 record_full_list->next = NULL;
973 record_full_core_open_1 (name, from_tty);
975 record_full_open_1 (name, from_tty);
977 /* Register extra event sources in the event loop. */
978 record_full_async_inferior_event_token
979 = create_async_event_handler (record_full_async_inferior_event_handler,
980 NULL, "record-full");
982 record_full_init_record_breakpoints ();
984 gdb::observers::record_changed.notify (current_inferior (), 1, "full", NULL);
987 /* "close" target method. Close the process record target. */
990 record_full_base_target::close ()
992 struct record_full_core_buf_entry *entry;
995 fprintf_unfiltered (gdb_stdlog, "Process record: record_full_close\n");
997 record_full_list_release (record_full_list);
999 /* Release record_full_core_regbuf. */
1000 if (record_full_core_regbuf)
1002 delete record_full_core_regbuf;
1003 record_full_core_regbuf = NULL;
1006 /* Release record_full_core_buf_list. */
1007 while (record_full_core_buf_list)
1009 entry = record_full_core_buf_list;
1010 record_full_core_buf_list = record_full_core_buf_list->prev;
1014 if (record_full_async_inferior_event_token)
1015 delete_async_event_handler (&record_full_async_inferior_event_token);
1018 /* "async" target method. */
1021 record_full_base_target::async (int enable)
1024 mark_async_event_handler (record_full_async_inferior_event_token);
1026 clear_async_event_handler (record_full_async_inferior_event_token);
1028 beneath ()->async (enable);
1031 /* The PTID and STEP arguments last passed to
1032 record_full_target::resume. */
1033 static ptid_t record_full_resume_ptid = null_ptid;
1034 static int record_full_resume_step = 0;
1036 /* True if we've been resumed, and so each record_full_wait call should
1037 advance execution. If this is false, record_full_wait will return a
1038 TARGET_WAITKIND_IGNORE. */
1039 static int record_full_resumed = 0;
1041 /* The execution direction of the last resume we got. This is
1042 necessary for async mode. Vis (order is not strictly accurate):
1044 1. user has the global execution direction set to forward
1045 2. user does a reverse-step command
1046 3. record_full_resume is called with global execution direction
1047 temporarily switched to reverse
1048 4. GDB's execution direction is reverted back to forward
1049 5. target record notifies event loop there's an event to handle
1050 6. infrun asks the target which direction was it going, and switches
1051 the global execution direction accordingly (to reverse)
1052 7. infrun polls an event out of the record target, and handles it
1053 8. GDB goes back to the event loop, and goto #4.
1055 static enum exec_direction_kind record_full_execution_dir = EXEC_FORWARD;
1057 /* "resume" target method. Resume the process record target. */
1060 record_full_target::resume (ptid_t ptid, int step, enum gdb_signal signal)
1062 record_full_resume_ptid = inferior_ptid;
1063 record_full_resume_step = step;
1064 record_full_resumed = 1;
1065 record_full_execution_dir = ::execution_direction;
1067 if (!RECORD_FULL_IS_REPLAY)
1069 struct gdbarch *gdbarch = target_thread_architecture (ptid);
1071 record_full_message (get_current_regcache (), signal);
1075 /* This is not hard single step. */
1076 if (!gdbarch_software_single_step_p (gdbarch))
1078 /* This is a normal continue. */
1083 /* This arch supports soft single step. */
1084 if (thread_has_single_step_breakpoints_set (inferior_thread ()))
1086 /* This is a soft single step. */
1087 record_full_resume_step = 1;
1090 step = !insert_single_step_breakpoints (gdbarch);
1094 /* Make sure the target beneath reports all signals. */
1095 target_pass_signals ({});
1097 this->beneath ()->resume (ptid, step, signal);
1100 /* We are about to start executing the inferior (or simulate it),
1101 let's register it with the event loop. */
1102 if (target_can_async_p ())
1106 /* "commit_resume" method for process record target. */
1109 record_full_target::commit_resume ()
1111 if (!RECORD_FULL_IS_REPLAY)
1112 beneath ()->commit_resume ();
1115 static int record_full_get_sig = 0;
1117 /* SIGINT signal handler, registered by "wait" method. */
1120 record_full_sig_handler (int signo)
1123 fprintf_unfiltered (gdb_stdlog, "Process record: get a signal\n");
1125 /* It will break the running inferior in replay mode. */
1126 record_full_resume_step = 1;
1128 /* It will let record_full_wait set inferior status to get the signal
1130 record_full_get_sig = 1;
1133 /* "wait" target method for process record target.
1135 In record mode, the target is always run in singlestep mode
1136 (even when gdb says to continue). The wait method intercepts
1137 the stop events and determines which ones are to be passed on to
1138 gdb. Most stop events are just singlestep events that gdb is not
1139 to know about, so the wait method just records them and keeps
1142 In replay mode, this function emulates the recorded execution log,
1143 one instruction at a time (forward or backward), and determines
1147 record_full_wait_1 (struct target_ops *ops,
1148 ptid_t ptid, struct target_waitstatus *status,
1149 target_wait_flags options)
1151 scoped_restore restore_operation_disable
1152 = record_full_gdb_operation_disable_set ();
1155 fprintf_unfiltered (gdb_stdlog,
1156 "Process record: record_full_wait "
1157 "record_full_resume_step = %d, "
1158 "record_full_resumed = %d, direction=%s\n",
1159 record_full_resume_step, record_full_resumed,
1160 record_full_execution_dir == EXEC_FORWARD
1161 ? "forward" : "reverse");
1163 if (!record_full_resumed)
1165 gdb_assert ((options & TARGET_WNOHANG) != 0);
1167 /* No interesting event. */
1168 status->kind = TARGET_WAITKIND_IGNORE;
1169 return minus_one_ptid;
1172 record_full_get_sig = 0;
1173 signal (SIGINT, record_full_sig_handler);
1175 record_full_stop_reason = TARGET_STOPPED_BY_NO_REASON;
1177 if (!RECORD_FULL_IS_REPLAY && ops != &record_full_core_ops)
1179 if (record_full_resume_step)
1181 /* This is a single step. */
1182 return ops->beneath ()->wait (ptid, status, options);
1186 /* This is not a single step. */
1189 struct gdbarch *gdbarch
1190 = target_thread_architecture (record_full_resume_ptid);
1194 ret = ops->beneath ()->wait (ptid, status, options);
1195 if (status->kind == TARGET_WAITKIND_IGNORE)
1198 fprintf_unfiltered (gdb_stdlog,
1199 "Process record: record_full_wait "
1200 "target beneath not done yet\n");
1204 for (thread_info *tp : all_non_exited_threads ())
1205 delete_single_step_breakpoints (tp);
1207 if (record_full_resume_step)
1210 /* Is this a SIGTRAP? */
1211 if (status->kind == TARGET_WAITKIND_STOPPED
1212 && status->value.sig == GDB_SIGNAL_TRAP)
1214 struct regcache *regcache;
1215 enum target_stop_reason *stop_reason_p
1216 = &record_full_stop_reason;
1218 /* Yes -- this is likely our single-step finishing,
1219 but check if there's any reason the core would be
1220 interested in the event. */
1222 registers_changed ();
1223 switch_to_thread (current_inferior ()->process_target (),
1225 regcache = get_current_regcache ();
1226 tmp_pc = regcache_read_pc (regcache);
1227 const struct address_space *aspace = regcache->aspace ();
1229 if (target_stopped_by_watchpoint ())
1231 /* Always interested in watchpoints. */
1233 else if (record_check_stopped_by_breakpoint (aspace, tmp_pc,
1236 /* There is a breakpoint here. Let the core
1241 /* This is a single-step trap. Record the
1242 insn and issue another step.
1243 FIXME: this part can be a random SIGTRAP too.
1244 But GDB cannot handle it. */
1247 if (!record_full_message_wrapper_safe (regcache,
1250 status->kind = TARGET_WAITKIND_STOPPED;
1251 status->value.sig = GDB_SIGNAL_0;
1255 if (gdbarch_software_single_step_p (gdbarch))
1257 process_stratum_target *proc_target
1258 = current_inferior ()->process_target ();
1260 /* Try to insert the software single step breakpoint.
1261 If insert success, set step to 0. */
1262 set_executing (proc_target, inferior_ptid, false);
1263 reinit_frame_cache ();
1265 step = !insert_single_step_breakpoints (gdbarch);
1267 set_executing (proc_target, inferior_ptid, true);
1271 fprintf_unfiltered (gdb_stdlog,
1272 "Process record: record_full_wait "
1273 "issuing one more step in the "
1274 "target beneath\n");
1275 ops->beneath ()->resume (ptid, step, GDB_SIGNAL_0);
1276 ops->beneath ()->commit_resume ();
1281 /* The inferior is broken by a breakpoint or a signal. */
1290 switch_to_thread (current_inferior ()->process_target (),
1291 record_full_resume_ptid);
1292 struct regcache *regcache = get_current_regcache ();
1293 struct gdbarch *gdbarch = regcache->arch ();
1294 const struct address_space *aspace = regcache->aspace ();
1295 int continue_flag = 1;
1296 int first_record_full_end = 1;
1302 record_full_stop_reason = TARGET_STOPPED_BY_NO_REASON;
1303 status->kind = TARGET_WAITKIND_STOPPED;
1305 /* Check breakpoint when forward execute. */
1306 if (execution_direction == EXEC_FORWARD)
1308 tmp_pc = regcache_read_pc (regcache);
1309 if (record_check_stopped_by_breakpoint (aspace, tmp_pc,
1310 &record_full_stop_reason))
1313 fprintf_unfiltered (gdb_stdlog,
1314 "Process record: break at %s.\n",
1315 paddress (gdbarch, tmp_pc));
1320 /* If GDB is in terminal_inferior mode, it will not get the
1321 signal. And in GDB replay mode, GDB doesn't need to be
1322 in terminal_inferior mode, because inferior will not
1323 executed. Then set it to terminal_ours to make GDB get
1325 target_terminal::ours ();
1327 /* In EXEC_FORWARD mode, record_full_list points to the tail of prev
1329 if (execution_direction == EXEC_FORWARD && record_full_list->next)
1330 record_full_list = record_full_list->next;
1332 /* Loop over the record_full_list, looking for the next place to
1336 /* Check for beginning and end of log. */
1337 if (execution_direction == EXEC_REVERSE
1338 && record_full_list == &record_full_first)
1340 /* Hit beginning of record log in reverse. */
1341 status->kind = TARGET_WAITKIND_NO_HISTORY;
1344 if (execution_direction != EXEC_REVERSE
1345 && !record_full_list->next)
1347 /* Hit end of record log going forward. */
1348 status->kind = TARGET_WAITKIND_NO_HISTORY;
1352 record_full_exec_insn (regcache, gdbarch, record_full_list);
1354 if (record_full_list->type == record_full_end)
1356 if (record_debug > 1)
1359 "Process record: record_full_end %s to "
1361 host_address_to_string (record_full_list));
1363 if (first_record_full_end
1364 && execution_direction == EXEC_REVERSE)
1366 /* When reverse execute, the first
1367 record_full_end is the part of current
1369 first_record_full_end = 0;
1373 /* In EXEC_REVERSE mode, this is the
1374 record_full_end of prev instruction. In
1375 EXEC_FORWARD mode, this is the
1376 record_full_end of current instruction. */
1378 if (record_full_resume_step)
1380 if (record_debug > 1)
1381 fprintf_unfiltered (gdb_stdlog,
1382 "Process record: step.\n");
1386 /* check breakpoint */
1387 tmp_pc = regcache_read_pc (regcache);
1388 if (record_check_stopped_by_breakpoint
1389 (aspace, tmp_pc, &record_full_stop_reason))
1392 fprintf_unfiltered (gdb_stdlog,
1393 "Process record: break "
1395 paddress (gdbarch, tmp_pc));
1400 if (record_full_stop_reason
1401 == TARGET_STOPPED_BY_WATCHPOINT)
1404 fprintf_unfiltered (gdb_stdlog,
1405 "Process record: hit hw "
1409 /* Check target signal */
1410 if (record_full_list->u.end.sigval != GDB_SIGNAL_0)
1411 /* FIXME: better way to check */
1418 if (execution_direction == EXEC_REVERSE)
1420 if (record_full_list->prev)
1421 record_full_list = record_full_list->prev;
1425 if (record_full_list->next)
1426 record_full_list = record_full_list->next;
1430 while (continue_flag);
1433 if (record_full_get_sig)
1434 status->value.sig = GDB_SIGNAL_INT;
1435 else if (record_full_list->u.end.sigval != GDB_SIGNAL_0)
1436 /* FIXME: better way to check */
1437 status->value.sig = record_full_list->u.end.sigval;
1439 status->value.sig = GDB_SIGNAL_TRAP;
1441 catch (const gdb_exception &ex)
1443 if (execution_direction == EXEC_REVERSE)
1445 if (record_full_list->next)
1446 record_full_list = record_full_list->next;
1449 record_full_list = record_full_list->prev;
1455 signal (SIGINT, handle_sigint);
1457 return inferior_ptid;
1461 record_full_base_target::wait (ptid_t ptid, struct target_waitstatus *status,
1462 target_wait_flags options)
1466 return_ptid = record_full_wait_1 (this, ptid, status, options);
1467 if (status->kind != TARGET_WAITKIND_IGNORE)
1469 /* We're reporting a stop. Make sure any spurious
1470 target_wait(WNOHANG) doesn't advance the target until the
1471 core wants us resumed again. */
1472 record_full_resumed = 0;
1478 record_full_base_target::stopped_by_watchpoint ()
1480 if (RECORD_FULL_IS_REPLAY)
1481 return record_full_stop_reason == TARGET_STOPPED_BY_WATCHPOINT;
1483 return beneath ()->stopped_by_watchpoint ();
1487 record_full_base_target::stopped_data_address (CORE_ADDR *addr_p)
1489 if (RECORD_FULL_IS_REPLAY)
1492 return this->beneath ()->stopped_data_address (addr_p);
1495 /* The stopped_by_sw_breakpoint method of target record-full. */
1498 record_full_base_target::stopped_by_sw_breakpoint ()
1500 return record_full_stop_reason == TARGET_STOPPED_BY_SW_BREAKPOINT;
1503 /* The supports_stopped_by_sw_breakpoint method of target
1507 record_full_base_target::supports_stopped_by_sw_breakpoint ()
1512 /* The stopped_by_hw_breakpoint method of target record-full. */
1515 record_full_base_target::stopped_by_hw_breakpoint ()
1517 return record_full_stop_reason == TARGET_STOPPED_BY_HW_BREAKPOINT;
1520 /* The supports_stopped_by_sw_breakpoint method of target
1524 record_full_base_target::supports_stopped_by_hw_breakpoint ()
1529 /* Record registers change (by user or by GDB) to list as an instruction. */
1532 record_full_registers_change (struct regcache *regcache, int regnum)
1534 /* Check record_full_insn_num. */
1535 record_full_check_insn_num ();
1537 record_full_arch_list_head = NULL;
1538 record_full_arch_list_tail = NULL;
1544 for (i = 0; i < gdbarch_num_regs (regcache->arch ()); i++)
1546 if (record_full_arch_list_add_reg (regcache, i))
1548 record_full_list_release (record_full_arch_list_tail);
1549 error (_("Process record: failed to record execution log."));
1555 if (record_full_arch_list_add_reg (regcache, regnum))
1557 record_full_list_release (record_full_arch_list_tail);
1558 error (_("Process record: failed to record execution log."));
1561 if (record_full_arch_list_add_end ())
1563 record_full_list_release (record_full_arch_list_tail);
1564 error (_("Process record: failed to record execution log."));
1566 record_full_list->next = record_full_arch_list_head;
1567 record_full_arch_list_head->prev = record_full_list;
1568 record_full_list = record_full_arch_list_tail;
1570 if (record_full_insn_num == record_full_insn_max_num)
1571 record_full_list_release_first ();
1573 record_full_insn_num++;
1576 /* "store_registers" method for process record target. */
1579 record_full_target::store_registers (struct regcache *regcache, int regno)
1581 if (!record_full_gdb_operation_disable)
1583 if (RECORD_FULL_IS_REPLAY)
1587 /* Let user choose if he wants to write register or not. */
1590 query (_("Because GDB is in replay mode, changing the "
1591 "value of a register will make the execution "
1592 "log unusable from this point onward. "
1593 "Change all registers?"));
1596 query (_("Because GDB is in replay mode, changing the value "
1597 "of a register will make the execution log unusable "
1598 "from this point onward. Change register %s?"),
1599 gdbarch_register_name (regcache->arch (),
1604 /* Invalidate the value of regcache that was set in function
1605 "regcache_raw_write". */
1611 i < gdbarch_num_regs (regcache->arch ());
1613 regcache->invalidate (i);
1616 regcache->invalidate (regno);
1618 error (_("Process record canceled the operation."));
1621 /* Destroy the record from here forward. */
1622 record_full_list_release_following (record_full_list);
1625 record_full_registers_change (regcache, regno);
1627 this->beneath ()->store_registers (regcache, regno);
1630 /* "xfer_partial" method. Behavior is conditional on
1631 RECORD_FULL_IS_REPLAY.
1632 In replay mode, we cannot write memory unles we are willing to
1633 invalidate the record/replay log from this point forward. */
1635 enum target_xfer_status
1636 record_full_target::xfer_partial (enum target_object object,
1637 const char *annex, gdb_byte *readbuf,
1638 const gdb_byte *writebuf, ULONGEST offset,
1639 ULONGEST len, ULONGEST *xfered_len)
1641 if (!record_full_gdb_operation_disable
1642 && (object == TARGET_OBJECT_MEMORY
1643 || object == TARGET_OBJECT_RAW_MEMORY) && writebuf)
1645 if (RECORD_FULL_IS_REPLAY)
1647 /* Let user choose if he wants to write memory or not. */
1648 if (!query (_("Because GDB is in replay mode, writing to memory "
1649 "will make the execution log unusable from this "
1650 "point onward. Write memory at address %s?"),
1651 paddress (target_gdbarch (), offset)))
1652 error (_("Process record canceled the operation."));
1654 /* Destroy the record from here forward. */
1655 record_full_list_release_following (record_full_list);
1658 /* Check record_full_insn_num */
1659 record_full_check_insn_num ();
1661 /* Record registers change to list as an instruction. */
1662 record_full_arch_list_head = NULL;
1663 record_full_arch_list_tail = NULL;
1664 if (record_full_arch_list_add_mem (offset, len))
1666 record_full_list_release (record_full_arch_list_tail);
1668 fprintf_unfiltered (gdb_stdlog,
1669 "Process record: failed to record "
1671 return TARGET_XFER_E_IO;
1673 if (record_full_arch_list_add_end ())
1675 record_full_list_release (record_full_arch_list_tail);
1677 fprintf_unfiltered (gdb_stdlog,
1678 "Process record: failed to record "
1680 return TARGET_XFER_E_IO;
1682 record_full_list->next = record_full_arch_list_head;
1683 record_full_arch_list_head->prev = record_full_list;
1684 record_full_list = record_full_arch_list_tail;
1686 if (record_full_insn_num == record_full_insn_max_num)
1687 record_full_list_release_first ();
1689 record_full_insn_num++;
1692 return this->beneath ()->xfer_partial (object, annex, readbuf, writebuf,
1693 offset, len, xfered_len);
1696 /* This structure represents a breakpoint inserted while the record
1697 target is active. We use this to know when to install/remove
1698 breakpoints in/from the target beneath. For example, a breakpoint
1699 may be inserted while recording, but removed when not replaying nor
1700 recording. In that case, the breakpoint had not been inserted on
1701 the target beneath, so we should not try to remove it there. */
1703 struct record_full_breakpoint
1705 record_full_breakpoint (struct address_space *address_space_,
1707 bool in_target_beneath_)
1708 : address_space (address_space_),
1710 in_target_beneath (in_target_beneath_)
1714 /* The address and address space the breakpoint was set at. */
1715 struct address_space *address_space;
1718 /* True when the breakpoint has been also installed in the target
1719 beneath. This will be false for breakpoints set during replay or
1721 bool in_target_beneath;
1724 /* The list of breakpoints inserted while the record target is
1726 static std::vector<record_full_breakpoint> record_full_breakpoints;
1729 record_full_sync_record_breakpoints (struct bp_location *loc, void *data)
1731 if (loc->loc_type != bp_loc_software_breakpoint)
1736 record_full_breakpoints.emplace_back
1737 (loc->target_info.placed_address_space,
1738 loc->target_info.placed_address,
1743 /* Sync existing breakpoints to record_full_breakpoints. */
1746 record_full_init_record_breakpoints (void)
1748 record_full_breakpoints.clear ();
1750 iterate_over_bp_locations (record_full_sync_record_breakpoints);
1753 /* Behavior is conditional on RECORD_FULL_IS_REPLAY. We will not actually
1754 insert or remove breakpoints in the real target when replaying, nor
1758 record_full_target::insert_breakpoint (struct gdbarch *gdbarch,
1759 struct bp_target_info *bp_tgt)
1761 bool in_target_beneath = false;
1763 if (!RECORD_FULL_IS_REPLAY)
1765 /* When recording, we currently always single-step, so we don't
1766 really need to install regular breakpoints in the inferior.
1767 However, we do have to insert software single-step
1768 breakpoints, in case the target can't hardware step. To keep
1769 things simple, we always insert. */
1771 scoped_restore restore_operation_disable
1772 = record_full_gdb_operation_disable_set ();
1774 int ret = this->beneath ()->insert_breakpoint (gdbarch, bp_tgt);
1778 in_target_beneath = true;
1781 /* Use the existing entries if found in order to avoid duplication
1782 in record_full_breakpoints. */
1784 for (const record_full_breakpoint &bp : record_full_breakpoints)
1786 if (bp.addr == bp_tgt->placed_address
1787 && bp.address_space == bp_tgt->placed_address_space)
1789 gdb_assert (bp.in_target_beneath == in_target_beneath);
1794 record_full_breakpoints.emplace_back (bp_tgt->placed_address_space,
1795 bp_tgt->placed_address,
1800 /* "remove_breakpoint" method for process record target. */
1803 record_full_target::remove_breakpoint (struct gdbarch *gdbarch,
1804 struct bp_target_info *bp_tgt,
1805 enum remove_bp_reason reason)
1807 for (auto iter = record_full_breakpoints.begin ();
1808 iter != record_full_breakpoints.end ();
1811 struct record_full_breakpoint &bp = *iter;
1813 if (bp.addr == bp_tgt->placed_address
1814 && bp.address_space == bp_tgt->placed_address_space)
1816 if (bp.in_target_beneath)
1818 scoped_restore restore_operation_disable
1819 = record_full_gdb_operation_disable_set ();
1821 int ret = this->beneath ()->remove_breakpoint (gdbarch, bp_tgt,
1827 if (reason == REMOVE_BREAKPOINT)
1828 unordered_remove (record_full_breakpoints, iter);
1833 gdb_assert_not_reached ("removing unknown breakpoint");
1836 /* "can_execute_reverse" method for process record target. */
1839 record_full_base_target::can_execute_reverse ()
1844 /* "get_bookmark" method for process record and prec over core. */
1847 record_full_base_target::get_bookmark (const char *args, int from_tty)
1851 /* Return stringified form of instruction count. */
1852 if (record_full_list && record_full_list->type == record_full_end)
1853 ret = xstrdup (pulongest (record_full_list->u.end.insn_num));
1858 fprintf_unfiltered (gdb_stdlog,
1859 "record_full_get_bookmark returns %s\n", ret);
1861 fprintf_unfiltered (gdb_stdlog,
1862 "record_full_get_bookmark returns NULL\n");
1864 return (gdb_byte *) ret;
1867 /* "goto_bookmark" method for process record and prec over core. */
1870 record_full_base_target::goto_bookmark (const gdb_byte *raw_bookmark,
1873 const char *bookmark = (const char *) raw_bookmark;
1876 fprintf_unfiltered (gdb_stdlog,
1877 "record_full_goto_bookmark receives %s\n", bookmark);
1879 std::string name_holder;
1880 if (bookmark[0] == '\'' || bookmark[0] == '\"')
1882 if (bookmark[strlen (bookmark) - 1] != bookmark[0])
1883 error (_("Unbalanced quotes: %s"), bookmark);
1885 name_holder = std::string (bookmark + 1, strlen (bookmark) - 2);
1886 bookmark = name_holder.c_str ();
1889 record_goto (bookmark);
1892 enum exec_direction_kind
1893 record_full_base_target::execution_direction ()
1895 return record_full_execution_dir;
1898 /* The record_method method of target record-full. */
1901 record_full_base_target::record_method (ptid_t ptid)
1903 return RECORD_METHOD_FULL;
1907 record_full_base_target::info_record ()
1909 struct record_full_entry *p;
1911 if (RECORD_FULL_IS_REPLAY)
1912 printf_filtered (_("Replay mode:\n"));
1914 printf_filtered (_("Record mode:\n"));
1916 /* Find entry for first actual instruction in the log. */
1917 for (p = record_full_first.next;
1918 p != NULL && p->type != record_full_end;
1922 /* Do we have a log at all? */
1923 if (p != NULL && p->type == record_full_end)
1925 /* Display instruction number for first instruction in the log. */
1926 printf_filtered (_("Lowest recorded instruction number is %s.\n"),
1927 pulongest (p->u.end.insn_num));
1929 /* If in replay mode, display where we are in the log. */
1930 if (RECORD_FULL_IS_REPLAY)
1931 printf_filtered (_("Current instruction number is %s.\n"),
1932 pulongest (record_full_list->u.end.insn_num));
1934 /* Display instruction number for last instruction in the log. */
1935 printf_filtered (_("Highest recorded instruction number is %s.\n"),
1936 pulongest (record_full_insn_count));
1938 /* Display log count. */
1939 printf_filtered (_("Log contains %u instructions.\n"),
1940 record_full_insn_num);
1943 printf_filtered (_("No instructions have been logged.\n"));
1945 /* Display max log size. */
1946 printf_filtered (_("Max logged instructions is %u.\n"),
1947 record_full_insn_max_num);
1951 record_full_base_target::supports_delete_record ()
1956 /* The "delete_record" target method. */
1959 record_full_base_target::delete_record ()
1961 record_full_list_release_following (record_full_list);
1964 /* The "record_is_replaying" target method. */
1967 record_full_base_target::record_is_replaying (ptid_t ptid)
1969 return RECORD_FULL_IS_REPLAY;
1972 /* The "record_will_replay" target method. */
1975 record_full_base_target::record_will_replay (ptid_t ptid, int dir)
1977 /* We can currently only record when executing forwards. Should we be able
1978 to record when executing backwards on targets that support reverse
1979 execution, this needs to be changed. */
1981 return RECORD_FULL_IS_REPLAY || dir == EXEC_REVERSE;
1984 /* Go to a specific entry. */
1987 record_full_goto_entry (struct record_full_entry *p)
1990 error (_("Target insn not found."));
1991 else if (p == record_full_list)
1992 error (_("Already at target insn."));
1993 else if (p->u.end.insn_num > record_full_list->u.end.insn_num)
1995 printf_filtered (_("Go forward to insn number %s\n"),
1996 pulongest (p->u.end.insn_num));
1997 record_full_goto_insn (p, EXEC_FORWARD);
2001 printf_filtered (_("Go backward to insn number %s\n"),
2002 pulongest (p->u.end.insn_num));
2003 record_full_goto_insn (p, EXEC_REVERSE);
2006 registers_changed ();
2007 reinit_frame_cache ();
2008 inferior_thread ()->suspend.stop_pc
2009 = regcache_read_pc (get_current_regcache ());
2010 print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1);
2013 /* The "goto_record_begin" target method. */
2016 record_full_base_target::goto_record_begin ()
2018 struct record_full_entry *p = NULL;
2020 for (p = &record_full_first; p != NULL; p = p->next)
2021 if (p->type == record_full_end)
2024 record_full_goto_entry (p);
2027 /* The "goto_record_end" target method. */
2030 record_full_base_target::goto_record_end ()
2032 struct record_full_entry *p = NULL;
2034 for (p = record_full_list; p->next != NULL; p = p->next)
2036 for (; p!= NULL; p = p->prev)
2037 if (p->type == record_full_end)
2040 record_full_goto_entry (p);
2043 /* The "goto_record" target method. */
2046 record_full_base_target::goto_record (ULONGEST target_insn)
2048 struct record_full_entry *p = NULL;
2050 for (p = &record_full_first; p != NULL; p = p->next)
2051 if (p->type == record_full_end && p->u.end.insn_num == target_insn)
2054 record_full_goto_entry (p);
2057 /* The "record_stop_replaying" target method. */
2060 record_full_base_target::record_stop_replaying ()
2065 /* "resume" method for prec over corefile. */
2068 record_full_core_target::resume (ptid_t ptid, int step,
2069 enum gdb_signal signal)
2071 record_full_resume_step = step;
2072 record_full_resumed = 1;
2073 record_full_execution_dir = ::execution_direction;
2075 /* We are about to start executing the inferior (or simulate it),
2076 let's register it with the event loop. */
2077 if (target_can_async_p ())
2081 /* "kill" method for prec over corefile. */
2084 record_full_core_target::kill ()
2087 fprintf_unfiltered (gdb_stdlog, "Process record: record_full_core_kill\n");
2089 unpush_target (this);
2092 /* "fetch_registers" method for prec over corefile. */
2095 record_full_core_target::fetch_registers (struct regcache *regcache,
2100 int num = gdbarch_num_regs (regcache->arch ());
2103 for (i = 0; i < num; i ++)
2104 regcache->raw_supply (i, *record_full_core_regbuf);
2107 regcache->raw_supply (regno, *record_full_core_regbuf);
2110 /* "prepare_to_store" method for prec over corefile. */
2113 record_full_core_target::prepare_to_store (struct regcache *regcache)
2117 /* "store_registers" method for prec over corefile. */
2120 record_full_core_target::store_registers (struct regcache *regcache,
2123 if (record_full_gdb_operation_disable)
2124 record_full_core_regbuf->raw_supply (regno, *regcache);
2126 error (_("You can't do that without a process to debug."));
2129 /* "xfer_partial" method for prec over corefile. */
2131 enum target_xfer_status
2132 record_full_core_target::xfer_partial (enum target_object object,
2133 const char *annex, gdb_byte *readbuf,
2134 const gdb_byte *writebuf, ULONGEST offset,
2135 ULONGEST len, ULONGEST *xfered_len)
2137 if (object == TARGET_OBJECT_MEMORY)
2139 if (record_full_gdb_operation_disable || !writebuf)
2141 for (target_section &p : record_full_core_sections)
2143 if (offset >= p.addr)
2145 struct record_full_core_buf_entry *entry;
2146 ULONGEST sec_offset;
2148 if (offset >= p.endaddr)
2151 if (offset + len > p.endaddr)
2152 len = p.endaddr - offset;
2154 sec_offset = offset - p.addr;
2156 /* Read readbuf or write writebuf p, offset, len. */
2158 if (p.the_bfd_section->flags & SEC_CONSTRUCTOR
2159 || (p.the_bfd_section->flags & SEC_HAS_CONTENTS) == 0)
2162 memset (readbuf, 0, len);
2165 return TARGET_XFER_OK;
2167 /* Get record_full_core_buf_entry. */
2168 for (entry = record_full_core_buf_list; entry;
2169 entry = entry->prev)
2176 /* Add a new entry. */
2177 entry = XNEW (struct record_full_core_buf_entry);
2179 if (!bfd_malloc_and_get_section
2180 (p.the_bfd_section->owner,
2185 return TARGET_XFER_EOF;
2187 entry->prev = record_full_core_buf_list;
2188 record_full_core_buf_list = entry;
2191 memcpy (entry->buf + sec_offset, writebuf,
2197 return this->beneath ()->xfer_partial (object, annex,
2202 memcpy (readbuf, entry->buf + sec_offset,
2207 return TARGET_XFER_OK;
2211 return TARGET_XFER_E_IO;
2214 error (_("You can't do that without a process to debug."));
2217 return this->beneath ()->xfer_partial (object, annex,
2218 readbuf, writebuf, offset, len,
2222 /* "insert_breakpoint" method for prec over corefile. */
2225 record_full_core_target::insert_breakpoint (struct gdbarch *gdbarch,
2226 struct bp_target_info *bp_tgt)
2231 /* "remove_breakpoint" method for prec over corefile. */
2234 record_full_core_target::remove_breakpoint (struct gdbarch *gdbarch,
2235 struct bp_target_info *bp_tgt,
2236 enum remove_bp_reason reason)
2241 /* "has_execution" method for prec over corefile. */
2244 record_full_core_target::has_execution (inferior *inf)
2249 /* Record log save-file format
2250 Version 1 (never released)
2253 4 bytes: magic number htonl(0x20090829).
2254 NOTE: be sure to change whenever this file format changes!
2258 1 byte: record type (record_full_end, see enum record_full_type).
2260 1 byte: record type (record_full_reg, see enum record_full_type).
2261 8 bytes: register id (network byte order).
2262 MAX_REGISTER_SIZE bytes: register value.
2264 1 byte: record type (record_full_mem, see enum record_full_type).
2265 8 bytes: memory length (network byte order).
2266 8 bytes: memory address (network byte order).
2267 n bytes: memory value (n == memory length).
2270 4 bytes: magic number netorder32(0x20091016).
2271 NOTE: be sure to change whenever this file format changes!
2275 1 byte: record type (record_full_end, see enum record_full_type).
2277 4 bytes: instruction count
2279 1 byte: record type (record_full_reg, see enum record_full_type).
2280 4 bytes: register id (network byte order).
2281 n bytes: register value (n == actual register size).
2282 (eg. 4 bytes for x86 general registers).
2284 1 byte: record type (record_full_mem, see enum record_full_type).
2285 4 bytes: memory length (network byte order).
2286 8 bytes: memory address (network byte order).
2287 n bytes: memory value (n == memory length).
2291 /* bfdcore_read -- read bytes from a core file section. */
2294 bfdcore_read (bfd *obfd, asection *osec, void *buf, int len, int *offset)
2296 int ret = bfd_get_section_contents (obfd, osec, buf, *offset, len);
2301 error (_("Failed to read %d bytes from core file %s ('%s')."),
2302 len, bfd_get_filename (obfd),
2303 bfd_errmsg (bfd_get_error ()));
2306 static inline uint64_t
2307 netorder64 (uint64_t input)
2311 store_unsigned_integer ((gdb_byte *) &ret, sizeof (ret),
2312 BFD_ENDIAN_BIG, input);
2316 static inline uint32_t
2317 netorder32 (uint32_t input)
2321 store_unsigned_integer ((gdb_byte *) &ret, sizeof (ret),
2322 BFD_ENDIAN_BIG, input);
2326 /* Restore the execution log from a core_bfd file. */
2328 record_full_restore (void)
2331 struct record_full_entry *rec;
2335 struct regcache *regcache;
2337 /* We restore the execution log from the open core bfd,
2339 if (core_bfd == NULL)
2342 /* "record_full_restore" can only be called when record list is empty. */
2343 gdb_assert (record_full_first.next == NULL);
2346 fprintf_unfiltered (gdb_stdlog, "Restoring recording from core file.\n");
2348 /* Now need to find our special note section. */
2349 osec = bfd_get_section_by_name (core_bfd, "null0");
2351 fprintf_unfiltered (gdb_stdlog, "Find precord section %s.\n",
2352 osec ? "succeeded" : "failed");
2355 osec_size = bfd_section_size (osec);
2357 fprintf_unfiltered (gdb_stdlog, "%s", bfd_section_name (osec));
2359 /* Check the magic code. */
2360 bfdcore_read (core_bfd, osec, &magic, sizeof (magic), &bfd_offset);
2361 if (magic != RECORD_FULL_FILE_MAGIC)
2362 error (_("Version mis-match or file format error in core file %s."),
2363 bfd_get_filename (core_bfd));
2365 fprintf_unfiltered (gdb_stdlog,
2366 " Reading 4-byte magic cookie "
2367 "RECORD_FULL_FILE_MAGIC (0x%s)\n",
2368 phex_nz (netorder32 (magic), 4));
2370 /* Restore the entries in recfd into record_full_arch_list_head and
2371 record_full_arch_list_tail. */
2372 record_full_arch_list_head = NULL;
2373 record_full_arch_list_tail = NULL;
2374 record_full_insn_num = 0;
2378 regcache = get_current_regcache ();
2383 uint32_t regnum, len, signal, count;
2386 /* We are finished when offset reaches osec_size. */
2387 if (bfd_offset >= osec_size)
2389 bfdcore_read (core_bfd, osec, &rectype, sizeof (rectype), &bfd_offset);
2393 case record_full_reg: /* reg */
2394 /* Get register number to regnum. */
2395 bfdcore_read (core_bfd, osec, ®num,
2396 sizeof (regnum), &bfd_offset);
2397 regnum = netorder32 (regnum);
2399 rec = record_full_reg_alloc (regcache, regnum);
2402 bfdcore_read (core_bfd, osec, record_full_get_loc (rec),
2403 rec->u.reg.len, &bfd_offset);
2406 fprintf_unfiltered (gdb_stdlog,
2407 " Reading register %d (1 "
2408 "plus %lu plus %d bytes)\n",
2410 (unsigned long) sizeof (regnum),
2414 case record_full_mem: /* mem */
2416 bfdcore_read (core_bfd, osec, &len,
2417 sizeof (len), &bfd_offset);
2418 len = netorder32 (len);
2421 bfdcore_read (core_bfd, osec, &addr,
2422 sizeof (addr), &bfd_offset);
2423 addr = netorder64 (addr);
2425 rec = record_full_mem_alloc (addr, len);
2428 bfdcore_read (core_bfd, osec, record_full_get_loc (rec),
2429 rec->u.mem.len, &bfd_offset);
2432 fprintf_unfiltered (gdb_stdlog,
2433 " Reading memory %s (1 plus "
2434 "%lu plus %lu plus %d bytes)\n",
2435 paddress (get_current_arch (),
2437 (unsigned long) sizeof (addr),
2438 (unsigned long) sizeof (len),
2442 case record_full_end: /* end */
2443 rec = record_full_end_alloc ();
2444 record_full_insn_num ++;
2446 /* Get signal value. */
2447 bfdcore_read (core_bfd, osec, &signal,
2448 sizeof (signal), &bfd_offset);
2449 signal = netorder32 (signal);
2450 rec->u.end.sigval = (enum gdb_signal) signal;
2452 /* Get insn count. */
2453 bfdcore_read (core_bfd, osec, &count,
2454 sizeof (count), &bfd_offset);
2455 count = netorder32 (count);
2456 rec->u.end.insn_num = count;
2457 record_full_insn_count = count + 1;
2459 fprintf_unfiltered (gdb_stdlog,
2460 " Reading record_full_end (1 + "
2461 "%lu + %lu bytes), offset == %s\n",
2462 (unsigned long) sizeof (signal),
2463 (unsigned long) sizeof (count),
2464 paddress (get_current_arch (),
2469 error (_("Bad entry type in core file %s."),
2470 bfd_get_filename (core_bfd));
2474 /* Add rec to record arch list. */
2475 record_full_arch_list_add (rec);
2478 catch (const gdb_exception &ex)
2480 record_full_list_release (record_full_arch_list_tail);
2484 /* Add record_full_arch_list_head to the end of record list. */
2485 record_full_first.next = record_full_arch_list_head;
2486 record_full_arch_list_head->prev = &record_full_first;
2487 record_full_arch_list_tail->next = NULL;
2488 record_full_list = &record_full_first;
2490 /* Update record_full_insn_max_num. */
2491 if (record_full_insn_num > record_full_insn_max_num)
2493 record_full_insn_max_num = record_full_insn_num;
2494 warning (_("Auto increase record/replay buffer limit to %u."),
2495 record_full_insn_max_num);
2499 printf_filtered (_("Restored records from core file %s.\n"),
2500 bfd_get_filename (core_bfd));
2502 print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1);
2505 /* bfdcore_write -- write bytes into a core file section. */
2508 bfdcore_write (bfd *obfd, asection *osec, void *buf, int len, int *offset)
2510 int ret = bfd_set_section_contents (obfd, osec, buf, *offset, len);
2515 error (_("Failed to write %d bytes to core file %s ('%s')."),
2516 len, bfd_get_filename (obfd),
2517 bfd_errmsg (bfd_get_error ()));
2520 /* Restore the execution log from a file. We use a modified elf
2521 corefile format, with an extra section for our data. */
2524 cmd_record_full_restore (const char *args, int from_tty)
2526 core_file_command (args, from_tty);
2527 record_full_open (args, from_tty);
2530 /* Save the execution log to a file. We use a modified elf corefile
2531 format, with an extra section for our data. */
2534 record_full_base_target::save_record (const char *recfilename)
2536 struct record_full_entry *cur_record_full_list;
2538 struct regcache *regcache;
2539 struct gdbarch *gdbarch;
2541 asection *osec = NULL;
2544 /* Open the save file. */
2546 fprintf_unfiltered (gdb_stdlog, "Saving execution log to core file '%s'\n",
2549 /* Open the output file. */
2550 gdb_bfd_ref_ptr obfd (create_gcore_bfd (recfilename));
2552 /* Arrange to remove the output file on failure. */
2553 gdb::unlinker unlink_file (recfilename);
2555 /* Save the current record entry to "cur_record_full_list". */
2556 cur_record_full_list = record_full_list;
2558 /* Get the values of regcache and gdbarch. */
2559 regcache = get_current_regcache ();
2560 gdbarch = regcache->arch ();
2562 /* Disable the GDB operation record. */
2563 scoped_restore restore_operation_disable
2564 = record_full_gdb_operation_disable_set ();
2566 /* Reverse execute to the begin of record list. */
2569 /* Check for beginning and end of log. */
2570 if (record_full_list == &record_full_first)
2573 record_full_exec_insn (regcache, gdbarch, record_full_list);
2575 if (record_full_list->prev)
2576 record_full_list = record_full_list->prev;
2579 /* Compute the size needed for the extra bfd section. */
2580 save_size = 4; /* magic cookie */
2581 for (record_full_list = record_full_first.next; record_full_list;
2582 record_full_list = record_full_list->next)
2583 switch (record_full_list->type)
2585 case record_full_end:
2586 save_size += 1 + 4 + 4;
2588 case record_full_reg:
2589 save_size += 1 + 4 + record_full_list->u.reg.len;
2591 case record_full_mem:
2592 save_size += 1 + 4 + 8 + record_full_list->u.mem.len;
2596 /* Make the new bfd section. */
2597 osec = bfd_make_section_anyway_with_flags (obfd.get (), "precord",
2601 error (_("Failed to create 'precord' section for corefile %s: %s"),
2603 bfd_errmsg (bfd_get_error ()));
2604 bfd_set_section_size (osec, save_size);
2605 bfd_set_section_vma (osec, 0);
2606 bfd_set_section_alignment (osec, 0);
2608 /* Save corefile state. */
2609 write_gcore_file (obfd.get ());
2611 /* Write out the record log. */
2612 /* Write the magic code. */
2613 magic = RECORD_FULL_FILE_MAGIC;
2615 fprintf_unfiltered (gdb_stdlog,
2616 " Writing 4-byte magic cookie "
2617 "RECORD_FULL_FILE_MAGIC (0x%s)\n",
2618 phex_nz (magic, 4));
2619 bfdcore_write (obfd.get (), osec, &magic, sizeof (magic), &bfd_offset);
2621 /* Save the entries to recfd and forward execute to the end of
2623 record_full_list = &record_full_first;
2627 if (record_full_list != &record_full_first)
2630 uint32_t regnum, len, signal, count;
2633 type = record_full_list->type;
2634 bfdcore_write (obfd.get (), osec, &type, sizeof (type), &bfd_offset);
2636 switch (record_full_list->type)
2638 case record_full_reg: /* reg */
2640 fprintf_unfiltered (gdb_stdlog,
2641 " Writing register %d (1 "
2642 "plus %lu plus %d bytes)\n",
2643 record_full_list->u.reg.num,
2644 (unsigned long) sizeof (regnum),
2645 record_full_list->u.reg.len);
2648 regnum = netorder32 (record_full_list->u.reg.num);
2649 bfdcore_write (obfd.get (), osec, ®num,
2650 sizeof (regnum), &bfd_offset);
2653 bfdcore_write (obfd.get (), osec,
2654 record_full_get_loc (record_full_list),
2655 record_full_list->u.reg.len, &bfd_offset);
2658 case record_full_mem: /* mem */
2660 fprintf_unfiltered (gdb_stdlog,
2661 " Writing memory %s (1 plus "
2662 "%lu plus %lu plus %d bytes)\n",
2664 record_full_list->u.mem.addr),
2665 (unsigned long) sizeof (addr),
2666 (unsigned long) sizeof (len),
2667 record_full_list->u.mem.len);
2670 len = netorder32 (record_full_list->u.mem.len);
2671 bfdcore_write (obfd.get (), osec, &len, sizeof (len),
2674 /* Write memaddr. */
2675 addr = netorder64 (record_full_list->u.mem.addr);
2676 bfdcore_write (obfd.get (), osec, &addr,
2677 sizeof (addr), &bfd_offset);
2680 bfdcore_write (obfd.get (), osec,
2681 record_full_get_loc (record_full_list),
2682 record_full_list->u.mem.len, &bfd_offset);
2685 case record_full_end:
2687 fprintf_unfiltered (gdb_stdlog,
2688 " Writing record_full_end (1 + "
2689 "%lu + %lu bytes)\n",
2690 (unsigned long) sizeof (signal),
2691 (unsigned long) sizeof (count));
2692 /* Write signal value. */
2693 signal = netorder32 (record_full_list->u.end.sigval);
2694 bfdcore_write (obfd.get (), osec, &signal,
2695 sizeof (signal), &bfd_offset);
2697 /* Write insn count. */
2698 count = netorder32 (record_full_list->u.end.insn_num);
2699 bfdcore_write (obfd.get (), osec, &count,
2700 sizeof (count), &bfd_offset);
2705 /* Execute entry. */
2706 record_full_exec_insn (regcache, gdbarch, record_full_list);
2708 if (record_full_list->next)
2709 record_full_list = record_full_list->next;
2714 /* Reverse execute to cur_record_full_list. */
2717 /* Check for beginning and end of log. */
2718 if (record_full_list == cur_record_full_list)
2721 record_full_exec_insn (regcache, gdbarch, record_full_list);
2723 if (record_full_list->prev)
2724 record_full_list = record_full_list->prev;
2727 unlink_file.keep ();
2730 printf_filtered (_("Saved core file %s with execution log.\n"),
2734 /* record_full_goto_insn -- rewind the record log (forward or backward,
2735 depending on DIR) to the given entry, changing the program state
2739 record_full_goto_insn (struct record_full_entry *entry,
2740 enum exec_direction_kind dir)
2742 scoped_restore restore_operation_disable
2743 = record_full_gdb_operation_disable_set ();
2744 struct regcache *regcache = get_current_regcache ();
2745 struct gdbarch *gdbarch = regcache->arch ();
2747 /* Assume everything is valid: we will hit the entry,
2748 and we will not hit the end of the recording. */
2750 if (dir == EXEC_FORWARD)
2751 record_full_list = record_full_list->next;
2755 record_full_exec_insn (regcache, gdbarch, record_full_list);
2756 if (dir == EXEC_REVERSE)
2757 record_full_list = record_full_list->prev;
2759 record_full_list = record_full_list->next;
2760 } while (record_full_list != entry);
2763 /* Alias for "target record-full". */
2766 cmd_record_full_start (const char *args, int from_tty)
2768 execute_command ("target record-full", from_tty);
2772 set_record_full_insn_max_num (const char *args, int from_tty,
2773 struct cmd_list_element *c)
2775 if (record_full_insn_num > record_full_insn_max_num)
2777 /* Count down record_full_insn_num while releasing records from list. */
2778 while (record_full_insn_num > record_full_insn_max_num)
2780 record_full_list_release_first ();
2781 record_full_insn_num--;
2786 void _initialize_record_full ();
2788 _initialize_record_full ()
2790 struct cmd_list_element *c;
2792 /* Init record_full_first. */
2793 record_full_first.prev = NULL;
2794 record_full_first.next = NULL;
2795 record_full_first.type = record_full_end;
2797 add_target (record_full_target_info, record_full_open);
2798 add_deprecated_target_alias (record_full_target_info, "record");
2799 add_target (record_full_core_target_info, record_full_open);
2801 add_prefix_cmd ("full", class_obscure, cmd_record_full_start,
2802 _("Start full execution recording."), &record_full_cmdlist,
2803 "record full ", 0, &record_cmdlist);
2805 c = add_cmd ("restore", class_obscure, cmd_record_full_restore,
2806 _("Restore the execution log from a file.\n\
2807 Argument is filename. File must be created with 'record save'."),
2808 &record_full_cmdlist);
2809 set_cmd_completer (c, filename_completer);
2811 /* Deprecate the old version without "full" prefix. */
2812 c = add_alias_cmd ("restore", "full restore", class_obscure, 1,
2814 set_cmd_completer (c, filename_completer);
2815 deprecate_cmd (c, "record full restore");
2817 add_basic_prefix_cmd ("full", class_support,
2818 _("Set record options."), &set_record_full_cmdlist,
2819 "set record full ", 0, &set_record_cmdlist);
2821 add_show_prefix_cmd ("full", class_support,
2822 _("Show record options."), &show_record_full_cmdlist,
2823 "show record full ", 0, &show_record_cmdlist);
2825 /* Record instructions number limit command. */
2826 add_setshow_boolean_cmd ("stop-at-limit", no_class,
2827 &record_full_stop_at_limit, _("\
2828 Set whether record/replay stops when record/replay buffer becomes full."), _("\
2829 Show whether record/replay stops when record/replay buffer becomes full."),
2830 _("Default is ON.\n\
2831 When ON, if the record/replay buffer becomes full, ask user what to do.\n\
2832 When OFF, if the record/replay buffer becomes full,\n\
2833 delete the oldest recorded instruction to make room for each new one."),
2835 &set_record_full_cmdlist, &show_record_full_cmdlist);
2837 c = add_alias_cmd ("stop-at-limit", "full stop-at-limit", no_class, 1,
2838 &set_record_cmdlist);
2839 deprecate_cmd (c, "set record full stop-at-limit");
2841 c = add_alias_cmd ("stop-at-limit", "full stop-at-limit", no_class, 1,
2842 &show_record_cmdlist);
2843 deprecate_cmd (c, "show record full stop-at-limit");
2845 add_setshow_uinteger_cmd ("insn-number-max", no_class,
2846 &record_full_insn_max_num,
2847 _("Set record/replay buffer limit."),
2848 _("Show record/replay buffer limit."), _("\
2849 Set the maximum number of instructions to be stored in the\n\
2850 record/replay buffer. A value of either \"unlimited\" or zero means no\n\
2851 limit. Default is 200000."),
2852 set_record_full_insn_max_num,
2853 NULL, &set_record_full_cmdlist,
2854 &show_record_full_cmdlist);
2856 c = add_alias_cmd ("insn-number-max", "full insn-number-max", no_class, 1,
2857 &set_record_cmdlist);
2858 deprecate_cmd (c, "set record full insn-number-max");
2860 c = add_alias_cmd ("insn-number-max", "full insn-number-max", no_class, 1,
2861 &show_record_cmdlist);
2862 deprecate_cmd (c, "show record full insn-number-max");
2864 add_setshow_boolean_cmd ("memory-query", no_class,
2865 &record_full_memory_query, _("\
2866 Set whether query if PREC cannot record memory change of next instruction."),
2868 Show whether query if PREC cannot record memory change of next instruction."),
2871 When ON, query if PREC cannot record memory change of next instruction."),
2873 &set_record_full_cmdlist,
2874 &show_record_full_cmdlist);
2876 c = add_alias_cmd ("memory-query", "full memory-query", no_class, 1,
2877 &set_record_cmdlist);
2878 deprecate_cmd (c, "set record full memory-query");
2880 c = add_alias_cmd ("memory-query", "full memory-query", no_class, 1,
2881 &show_record_cmdlist);
2882 deprecate_cmd (c, "show record full memory-query");