1 /* Process record and replay target for GDB, the GNU debugger.
3 Copyright (C) 2013-2018 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"
24 #include "event-top.h"
25 #include "completer.h"
26 #include "arch-utils.h"
30 #include "record-full.h"
33 #include "event-loop.h"
36 #include "observable.h"
38 #include "common/gdb_unlinker.h"
39 #include "common/byte-vector.h"
43 /* This module implements "target record-full", also known as "process
44 record and replay". This target sits on top of a "normal" target
45 (a target that "has execution"), and provides a record and replay
46 functionality, including reverse debugging.
48 Target record has two modes: recording, and replaying.
50 In record mode, we intercept the resume and wait methods.
51 Whenever gdb resumes the target, we run the target in single step
52 mode, and we build up an execution log in which, for each executed
53 instruction, we record all changes in memory and register state.
54 This is invisible to the user, to whom it just looks like an
55 ordinary debugging session (except for performance degredation).
57 In replay mode, instead of actually letting the inferior run as a
58 process, we simulate its execution by playing back the recorded
59 execution log. For each instruction in the log, we simulate the
60 instruction's side effects by duplicating the changes that it would
61 have made on memory and registers. */
63 #define DEFAULT_RECORD_FULL_INSN_MAX_NUM 200000
65 #define RECORD_FULL_IS_REPLAY \
66 (record_full_list->next || ::execution_direction == EXEC_REVERSE)
68 #define RECORD_FULL_FILE_MAGIC netorder32(0x20091016)
70 /* These are the core structs of the process record functionality.
72 A record_full_entry is a record of the value change of a register
73 ("record_full_reg") or a part of memory ("record_full_mem"). And each
74 instruction must have a struct record_full_entry ("record_full_end")
75 that indicates that this is the last struct record_full_entry of this
78 Each struct record_full_entry is linked to "record_full_list" by "prev"
79 and "next" pointers. */
81 struct record_full_mem_entry
85 /* Set this flag if target memory for this entry
86 can no longer be accessed. */
87 int mem_entry_not_accessible;
91 gdb_byte buf[sizeof (gdb_byte *)];
95 struct record_full_reg_entry
102 gdb_byte buf[2 * sizeof (gdb_byte *)];
106 struct record_full_end_entry
108 enum gdb_signal sigval;
112 enum record_full_type
119 /* This is the data structure that makes up the execution log.
121 The execution log consists of a single linked list of entries
122 of type "struct record_full_entry". It is doubly linked so that it
123 can be traversed in either direction.
125 The start of the list is anchored by a struct called
126 "record_full_first". The pointer "record_full_list" either points
127 to the last entry that was added to the list (in record mode), or to
128 the next entry in the list that will be executed (in replay mode).
130 Each list element (struct record_full_entry), in addition to next
131 and prev pointers, consists of a union of three entry types: mem,
132 reg, and end. A field called "type" determines which entry type is
133 represented by a given list element.
135 Each instruction that is added to the execution log is represented
136 by a variable number of list elements ('entries'). The instruction
137 will have one "reg" entry for each register that is changed by
138 executing the instruction (including the PC in every case). It
139 will also have one "mem" entry for each memory change. Finally,
140 each instruction will have an "end" entry that separates it from
141 the changes associated with the next instruction. */
143 struct record_full_entry
145 struct record_full_entry *prev;
146 struct record_full_entry *next;
147 enum record_full_type type;
151 struct record_full_reg_entry reg;
153 struct record_full_mem_entry mem;
155 struct record_full_end_entry end;
159 /* If true, query if PREC cannot record memory
160 change of next instruction. */
161 int record_full_memory_query = 0;
163 struct record_full_core_buf_entry
165 struct record_full_core_buf_entry *prev;
166 struct target_section *p;
170 /* Record buf with core target. */
171 static detached_regcache *record_full_core_regbuf = NULL;
172 static struct target_section *record_full_core_start;
173 static struct target_section *record_full_core_end;
174 static struct record_full_core_buf_entry *record_full_core_buf_list = NULL;
176 /* The following variables are used for managing the linked list that
177 represents the execution log.
179 record_full_first is the anchor that holds down the beginning of
182 record_full_list serves two functions:
183 1) In record mode, it anchors the end of the list.
184 2) In replay mode, it traverses the list and points to
185 the next instruction that must be emulated.
187 record_full_arch_list_head and record_full_arch_list_tail are used
188 to manage a separate list, which is used to build up the change
189 elements of the currently executing instruction during record mode.
190 When this instruction has been completely annotated in the "arch
191 list", it will be appended to the main execution log. */
193 static struct record_full_entry record_full_first;
194 static struct record_full_entry *record_full_list = &record_full_first;
195 static struct record_full_entry *record_full_arch_list_head = NULL;
196 static struct record_full_entry *record_full_arch_list_tail = NULL;
198 /* 1 ask user. 0 auto delete the last struct record_full_entry. */
199 static int record_full_stop_at_limit = 1;
200 /* Maximum allowed number of insns in execution log. */
201 static unsigned int record_full_insn_max_num
202 = DEFAULT_RECORD_FULL_INSN_MAX_NUM;
203 /* Actual count of insns presently in execution log. */
204 static unsigned int record_full_insn_num = 0;
205 /* Count of insns logged so far (may be larger
206 than count of insns presently in execution log). */
207 static ULONGEST record_full_insn_count;
209 /* Base class implementing functionality common to both the
210 "record-full" and "record-core" targets. */
212 class record_full_base_target : public target_ops
215 record_full_base_target ()
216 { to_stratum = record_stratum; }
218 const char *shortname () override = 0;
220 const char *longname () override
221 { return _("Process record and replay target"); }
223 const char *doc () override
224 { return _("Log program while executing and replay execution from log."); }
226 void open (const char *, int) override;
227 void close () override;
228 void async (int) override;
229 ptid_t wait (ptid_t, struct target_waitstatus *, int) override;
230 bool stopped_by_watchpoint () override;
231 bool stopped_data_address (CORE_ADDR *) override;
233 bool stopped_by_sw_breakpoint () override;
234 bool supports_stopped_by_sw_breakpoint () override;
236 bool stopped_by_hw_breakpoint () override;
237 bool supports_stopped_by_hw_breakpoint () override;
239 bool can_execute_reverse () override;
241 /* Add bookmark target methods. */
242 gdb_byte *get_bookmark (const char *, int) override;
243 void goto_bookmark (const gdb_byte *, int) override;
244 enum exec_direction_kind execution_direction () 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;
258 /* The "record-full" target. */
260 class record_full_target final : public record_full_base_target
263 const char *shortname () override
264 { return "record-full"; }
266 void commit_resume () override;
267 void resume (ptid_t, int, enum gdb_signal) override;
268 void disconnect (const char *, int) override;
269 void detach (inferior *, int) override;
270 void mourn_inferior () override;
271 void kill () override;
272 void store_registers (struct regcache *, int) override;
273 enum target_xfer_status xfer_partial (enum target_object object,
276 const gdb_byte *writebuf,
277 ULONGEST offset, ULONGEST len,
278 ULONGEST *xfered_len) override;
279 int insert_breakpoint (struct gdbarch *,
280 struct bp_target_info *) override;
281 int remove_breakpoint (struct gdbarch *,
282 struct bp_target_info *,
283 enum remove_bp_reason) override;
286 /* The "record-core" target. */
288 class record_full_core_target final : public record_full_base_target
291 const char *shortname () override
292 { return "record-core"; }
294 void resume (ptid_t, int, enum gdb_signal) override;
295 void disconnect (const char *, int) override;
296 void kill () override;
297 void fetch_registers (struct regcache *regcache, int regno) override;
298 void prepare_to_store (struct regcache *regcache) override;
299 void store_registers (struct regcache *, int) override;
300 enum target_xfer_status xfer_partial (enum target_object object,
303 const gdb_byte *writebuf,
304 ULONGEST offset, ULONGEST len,
305 ULONGEST *xfered_len) override;
306 int insert_breakpoint (struct gdbarch *,
307 struct bp_target_info *) override;
308 int remove_breakpoint (struct gdbarch *,
309 struct bp_target_info *,
310 enum remove_bp_reason) override;
312 bool has_execution (ptid_t) override;
315 static record_full_target record_full_ops;
316 static record_full_core_target record_full_core_ops;
319 record_full_target::detach (inferior *inf, int from_tty)
321 record_detach (this, inf, from_tty);
325 record_full_target::disconnect (const char *args, int from_tty)
327 record_disconnect (this, args, from_tty);
331 record_full_core_target::disconnect (const char *args, int from_tty)
333 record_disconnect (this, args, from_tty);
337 record_full_target::mourn_inferior ()
339 record_mourn_inferior (this);
343 record_full_target::kill ()
348 /* See record-full.h. */
351 record_full_is_used (void)
353 struct target_ops *t;
355 t = find_record_target ();
356 return (t == &record_full_ops
357 || t == &record_full_core_ops);
361 /* Command lists for "set/show record full". */
362 static struct cmd_list_element *set_record_full_cmdlist;
363 static struct cmd_list_element *show_record_full_cmdlist;
365 /* Command list for "record full". */
366 static struct cmd_list_element *record_full_cmdlist;
368 static void record_full_goto_insn (struct record_full_entry *entry,
369 enum exec_direction_kind dir);
371 /* Alloc and free functions for record_full_reg, record_full_mem, and
372 record_full_end entries. */
374 /* Alloc a record_full_reg record entry. */
376 static inline struct record_full_entry *
377 record_full_reg_alloc (struct regcache *regcache, int regnum)
379 struct record_full_entry *rec;
380 struct gdbarch *gdbarch = regcache->arch ();
382 rec = XCNEW (struct record_full_entry);
383 rec->type = record_full_reg;
384 rec->u.reg.num = regnum;
385 rec->u.reg.len = register_size (gdbarch, regnum);
386 if (rec->u.reg.len > sizeof (rec->u.reg.u.buf))
387 rec->u.reg.u.ptr = (gdb_byte *) xmalloc (rec->u.reg.len);
392 /* Free a record_full_reg record entry. */
395 record_full_reg_release (struct record_full_entry *rec)
397 gdb_assert (rec->type == record_full_reg);
398 if (rec->u.reg.len > sizeof (rec->u.reg.u.buf))
399 xfree (rec->u.reg.u.ptr);
403 /* Alloc a record_full_mem record entry. */
405 static inline struct record_full_entry *
406 record_full_mem_alloc (CORE_ADDR addr, int len)
408 struct record_full_entry *rec;
410 rec = XCNEW (struct record_full_entry);
411 rec->type = record_full_mem;
412 rec->u.mem.addr = addr;
413 rec->u.mem.len = len;
414 if (rec->u.mem.len > sizeof (rec->u.mem.u.buf))
415 rec->u.mem.u.ptr = (gdb_byte *) xmalloc (len);
420 /* Free a record_full_mem record entry. */
423 record_full_mem_release (struct record_full_entry *rec)
425 gdb_assert (rec->type == record_full_mem);
426 if (rec->u.mem.len > sizeof (rec->u.mem.u.buf))
427 xfree (rec->u.mem.u.ptr);
431 /* Alloc a record_full_end record entry. */
433 static inline struct record_full_entry *
434 record_full_end_alloc (void)
436 struct record_full_entry *rec;
438 rec = XCNEW (struct record_full_entry);
439 rec->type = record_full_end;
444 /* Free a record_full_end record entry. */
447 record_full_end_release (struct record_full_entry *rec)
452 /* Free one record entry, any type.
453 Return entry->type, in case caller wants to know. */
455 static inline enum record_full_type
456 record_full_entry_release (struct record_full_entry *rec)
458 enum record_full_type type = rec->type;
461 case record_full_reg:
462 record_full_reg_release (rec);
464 case record_full_mem:
465 record_full_mem_release (rec);
467 case record_full_end:
468 record_full_end_release (rec);
474 /* Free all record entries in list pointed to by REC. */
477 record_full_list_release (struct record_full_entry *rec)
488 record_full_entry_release (rec->next);
491 if (rec == &record_full_first)
493 record_full_insn_num = 0;
494 record_full_first.next = NULL;
497 record_full_entry_release (rec);
500 /* Free all record entries forward of the given list position. */
503 record_full_list_release_following (struct record_full_entry *rec)
505 struct record_full_entry *tmp = rec->next;
511 if (record_full_entry_release (tmp) == record_full_end)
513 record_full_insn_num--;
514 record_full_insn_count--;
520 /* Delete the first instruction from the beginning of the log, to make
521 room for adding a new instruction at the end of the log.
523 Note -- this function does not modify record_full_insn_num. */
526 record_full_list_release_first (void)
528 struct record_full_entry *tmp;
530 if (!record_full_first.next)
533 /* Loop until a record_full_end. */
536 /* Cut record_full_first.next out of the linked list. */
537 tmp = record_full_first.next;
538 record_full_first.next = tmp->next;
539 tmp->next->prev = &record_full_first;
541 /* tmp is now isolated, and can be deleted. */
542 if (record_full_entry_release (tmp) == record_full_end)
543 break; /* End loop at first record_full_end. */
545 if (!record_full_first.next)
547 gdb_assert (record_full_insn_num == 1);
548 break; /* End loop when list is empty. */
553 /* Add a struct record_full_entry to record_full_arch_list. */
556 record_full_arch_list_add (struct record_full_entry *rec)
558 if (record_debug > 1)
559 fprintf_unfiltered (gdb_stdlog,
560 "Process record: record_full_arch_list_add %s.\n",
561 host_address_to_string (rec));
563 if (record_full_arch_list_tail)
565 record_full_arch_list_tail->next = rec;
566 rec->prev = record_full_arch_list_tail;
567 record_full_arch_list_tail = rec;
571 record_full_arch_list_head = rec;
572 record_full_arch_list_tail = rec;
576 /* Return the value storage location of a record entry. */
577 static inline gdb_byte *
578 record_full_get_loc (struct record_full_entry *rec)
581 case record_full_mem:
582 if (rec->u.mem.len > sizeof (rec->u.mem.u.buf))
583 return rec->u.mem.u.ptr;
585 return rec->u.mem.u.buf;
586 case record_full_reg:
587 if (rec->u.reg.len > sizeof (rec->u.reg.u.buf))
588 return rec->u.reg.u.ptr;
590 return rec->u.reg.u.buf;
591 case record_full_end:
593 gdb_assert_not_reached ("unexpected record_full_entry type");
598 /* Record the value of a register NUM to record_full_arch_list. */
601 record_full_arch_list_add_reg (struct regcache *regcache, int regnum)
603 struct record_full_entry *rec;
605 if (record_debug > 1)
606 fprintf_unfiltered (gdb_stdlog,
607 "Process record: add register num = %d to "
611 rec = record_full_reg_alloc (regcache, regnum);
613 regcache_raw_read (regcache, regnum, record_full_get_loc (rec));
615 record_full_arch_list_add (rec);
620 /* Record the value of a region of memory whose address is ADDR and
621 length is LEN to record_full_arch_list. */
624 record_full_arch_list_add_mem (CORE_ADDR addr, int len)
626 struct record_full_entry *rec;
628 if (record_debug > 1)
629 fprintf_unfiltered (gdb_stdlog,
630 "Process record: add mem addr = %s len = %d to "
632 paddress (target_gdbarch (), addr), len);
634 if (!addr) /* FIXME: Why? Some arch must permit it... */
637 rec = record_full_mem_alloc (addr, len);
639 if (record_read_memory (target_gdbarch (), addr,
640 record_full_get_loc (rec), len))
642 record_full_mem_release (rec);
646 record_full_arch_list_add (rec);
651 /* Add a record_full_end type struct record_full_entry to
652 record_full_arch_list. */
655 record_full_arch_list_add_end (void)
657 struct record_full_entry *rec;
659 if (record_debug > 1)
660 fprintf_unfiltered (gdb_stdlog,
661 "Process record: add end to arch list.\n");
663 rec = record_full_end_alloc ();
664 rec->u.end.sigval = GDB_SIGNAL_0;
665 rec->u.end.insn_num = ++record_full_insn_count;
667 record_full_arch_list_add (rec);
673 record_full_check_insn_num (void)
675 if (record_full_insn_num == record_full_insn_max_num)
677 /* Ask user what to do. */
678 if (record_full_stop_at_limit)
680 if (!yquery (_("Do you want to auto delete previous execution "
681 "log entries when record/replay buffer becomes "
682 "full (record full stop-at-limit)?")))
683 error (_("Process record: stopped by user."));
684 record_full_stop_at_limit = 0;
690 record_full_arch_list_cleanups (void *ignore)
692 record_full_list_release (record_full_arch_list_tail);
695 /* Before inferior step (when GDB record the running message, inferior
696 only can step), GDB will call this function to record the values to
697 record_full_list. This function will call gdbarch_process_record to
698 record the running message of inferior and set them to
699 record_full_arch_list, and add it to record_full_list. */
702 record_full_message (struct regcache *regcache, enum gdb_signal signal)
705 struct gdbarch *gdbarch = regcache->arch ();
706 struct cleanup *old_cleanups
707 = make_cleanup (record_full_arch_list_cleanups, 0);
709 record_full_arch_list_head = NULL;
710 record_full_arch_list_tail = NULL;
712 /* Check record_full_insn_num. */
713 record_full_check_insn_num ();
715 /* If gdb sends a signal value to target_resume,
716 save it in the 'end' field of the previous instruction.
718 Maybe process record should record what really happened,
719 rather than what gdb pretends has happened.
721 So if Linux delivered the signal to the child process during
722 the record mode, we will record it and deliver it again in
725 If user says "ignore this signal" during the record mode, then
726 it will be ignored again during the replay mode (no matter if
727 the user says something different, like "deliver this signal"
728 during the replay mode).
730 User should understand that nothing he does during the replay
731 mode will change the behavior of the child. If he tries,
732 then that is a user error.
734 But we should still deliver the signal to gdb during the replay,
735 if we delivered it during the recording. Therefore we should
736 record the signal during record_full_wait, not
737 record_full_resume. */
738 if (record_full_list != &record_full_first) /* FIXME better way to check */
740 gdb_assert (record_full_list->type == record_full_end);
741 record_full_list->u.end.sigval = signal;
744 if (signal == GDB_SIGNAL_0
745 || !gdbarch_process_record_signal_p (gdbarch))
746 ret = gdbarch_process_record (gdbarch,
748 regcache_read_pc (regcache));
750 ret = gdbarch_process_record_signal (gdbarch,
755 error (_("Process record: inferior program stopped."));
757 error (_("Process record: failed to record execution log."));
759 discard_cleanups (old_cleanups);
761 record_full_list->next = record_full_arch_list_head;
762 record_full_arch_list_head->prev = record_full_list;
763 record_full_list = record_full_arch_list_tail;
765 if (record_full_insn_num == record_full_insn_max_num)
766 record_full_list_release_first ();
768 record_full_insn_num++;
772 record_full_message_wrapper_safe (struct regcache *regcache,
773 enum gdb_signal signal)
777 record_full_message (regcache, signal);
779 CATCH (ex, RETURN_MASK_ALL)
781 exception_print (gdb_stderr, ex);
789 /* Set to 1 if record_full_store_registers and record_full_xfer_partial
790 doesn't need record. */
792 static int record_full_gdb_operation_disable = 0;
794 scoped_restore_tmpl<int>
795 record_full_gdb_operation_disable_set (void)
797 return make_scoped_restore (&record_full_gdb_operation_disable, 1);
800 /* Flag set to TRUE for target_stopped_by_watchpoint. */
801 static enum target_stop_reason record_full_stop_reason
802 = TARGET_STOPPED_BY_NO_REASON;
804 /* Execute one instruction from the record log. Each instruction in
805 the log will be represented by an arbitrary sequence of register
806 entries and memory entries, followed by an 'end' entry. */
809 record_full_exec_insn (struct regcache *regcache,
810 struct gdbarch *gdbarch,
811 struct record_full_entry *entry)
815 case record_full_reg: /* reg */
817 gdb::byte_vector reg (entry->u.reg.len);
819 if (record_debug > 1)
820 fprintf_unfiltered (gdb_stdlog,
821 "Process record: record_full_reg %s to "
822 "inferior num = %d.\n",
823 host_address_to_string (entry),
826 regcache_cooked_read (regcache, entry->u.reg.num, reg.data ());
827 regcache_cooked_write (regcache, entry->u.reg.num,
828 record_full_get_loc (entry));
829 memcpy (record_full_get_loc (entry), reg.data (), entry->u.reg.len);
833 case record_full_mem: /* mem */
835 /* Nothing to do if the entry is flagged not_accessible. */
836 if (!entry->u.mem.mem_entry_not_accessible)
838 gdb::byte_vector mem (entry->u.mem.len);
840 if (record_debug > 1)
841 fprintf_unfiltered (gdb_stdlog,
842 "Process record: record_full_mem %s to "
843 "inferior addr = %s len = %d.\n",
844 host_address_to_string (entry),
845 paddress (gdbarch, entry->u.mem.addr),
848 if (record_read_memory (gdbarch,
849 entry->u.mem.addr, mem.data (),
851 entry->u.mem.mem_entry_not_accessible = 1;
854 if (target_write_memory (entry->u.mem.addr,
855 record_full_get_loc (entry),
858 entry->u.mem.mem_entry_not_accessible = 1;
860 warning (_("Process record: error writing memory at "
861 "addr = %s len = %d."),
862 paddress (gdbarch, entry->u.mem.addr),
867 memcpy (record_full_get_loc (entry), mem.data (),
870 /* We've changed memory --- check if a hardware
871 watchpoint should trap. Note that this
872 presently assumes the target beneath supports
873 continuable watchpoints. On non-continuable
874 watchpoints target, we'll want to check this
875 _before_ actually doing the memory change, and
876 not doing the change at all if the watchpoint
878 if (hardware_watchpoint_inserted_in_range
879 (regcache->aspace (),
880 entry->u.mem.addr, entry->u.mem.len))
881 record_full_stop_reason = TARGET_STOPPED_BY_WATCHPOINT;
890 static void record_full_restore (void);
892 /* Asynchronous signal handle registered as event loop source for when
893 we have pending events ready to be passed to the core. */
895 static struct async_event_handler *record_full_async_inferior_event_token;
898 record_full_async_inferior_event_handler (gdb_client_data data)
900 inferior_event_handler (INF_REG_EVENT, NULL);
903 /* Open the process record target. */
906 record_full_core_open_1 (const char *name, int from_tty)
908 struct regcache *regcache = get_current_regcache ();
909 int regnum = gdbarch_num_regs (regcache->arch ());
912 /* Get record_full_core_regbuf. */
913 target_fetch_registers (regcache, -1);
914 record_full_core_regbuf = new detached_regcache (regcache->arch (), false);
916 for (i = 0; i < regnum; i ++)
917 record_full_core_regbuf->raw_supply (i, *regcache);
919 /* Get record_full_core_start and record_full_core_end. */
920 if (build_section_table (core_bfd, &record_full_core_start,
921 &record_full_core_end))
923 delete record_full_core_regbuf;
924 record_full_core_regbuf = NULL;
925 error (_("\"%s\": Can't find sections: %s"),
926 bfd_get_filename (core_bfd), bfd_errmsg (bfd_get_error ()));
929 push_target (&record_full_core_ops);
930 record_full_restore ();
933 /* "open" target method for 'live' processes. */
936 record_full_open_1 (const char *name, int from_tty)
939 fprintf_unfiltered (gdb_stdlog, "Process record: record_full_open_1\n");
942 if (!target_has_execution)
943 error (_("Process record: the program is not being run."));
945 error (_("Process record target can't debug inferior in non-stop mode "
948 if (!gdbarch_process_record_p (target_gdbarch ()))
949 error (_("Process record: the current architecture doesn't support "
950 "record function."));
952 push_target (&record_full_ops);
955 static void record_full_init_record_breakpoints (void);
957 /* "open" target method. Open the process record target. */
960 record_full_base_target::open (const char *name, int from_tty)
963 fprintf_unfiltered (gdb_stdlog, "Process record: record_full_open\n");
968 record_full_insn_num = 0;
969 record_full_insn_count = 0;
970 record_full_list = &record_full_first;
971 record_full_list->next = NULL;
974 record_full_core_open_1 (name, from_tty);
976 record_full_open_1 (name, from_tty);
978 /* Register extra event sources in the event loop. */
979 record_full_async_inferior_event_token
980 = create_async_event_handler (record_full_async_inferior_event_handler,
983 record_full_init_record_breakpoints ();
985 gdb::observers::record_changed.notify (current_inferior (), 1, "full", NULL);
988 /* "close" target method. Close the process record target. */
991 record_full_base_target::close ()
993 struct record_full_core_buf_entry *entry;
996 fprintf_unfiltered (gdb_stdlog, "Process record: record_full_close\n");
998 record_full_list_release (record_full_list);
1000 /* Release record_full_core_regbuf. */
1001 if (record_full_core_regbuf)
1003 delete record_full_core_regbuf;
1004 record_full_core_regbuf = NULL;
1007 /* Release record_full_core_buf_list. */
1008 if (record_full_core_buf_list)
1010 for (entry = record_full_core_buf_list->prev; entry;
1011 entry = entry->prev)
1013 xfree (record_full_core_buf_list);
1014 record_full_core_buf_list = entry;
1016 record_full_core_buf_list = NULL;
1019 if (record_full_async_inferior_event_token)
1020 delete_async_event_handler (&record_full_async_inferior_event_token);
1023 /* "async" target method. */
1026 record_full_base_target::async (int enable)
1029 mark_async_event_handler (record_full_async_inferior_event_token);
1031 clear_async_event_handler (record_full_async_inferior_event_token);
1033 beneath->async (enable);
1036 static int record_full_resume_step = 0;
1038 /* True if we've been resumed, and so each record_full_wait call should
1039 advance execution. If this is false, record_full_wait will return a
1040 TARGET_WAITKIND_IGNORE. */
1041 static int record_full_resumed = 0;
1043 /* The execution direction of the last resume we got. This is
1044 necessary for async mode. Vis (order is not strictly accurate):
1046 1. user has the global execution direction set to forward
1047 2. user does a reverse-step command
1048 3. record_full_resume is called with global execution direction
1049 temporarily switched to reverse
1050 4. GDB's execution direction is reverted back to forward
1051 5. target record notifies event loop there's an event to handle
1052 6. infrun asks the target which direction was it going, and switches
1053 the global execution direction accordingly (to reverse)
1054 7. infrun polls an event out of the record target, and handles it
1055 8. GDB goes back to the event loop, and goto #4.
1057 static enum exec_direction_kind record_full_execution_dir = EXEC_FORWARD;
1059 /* "resume" target method. Resume the process record target. */
1062 record_full_target::resume (ptid_t ptid, int step, enum gdb_signal signal)
1064 record_full_resume_step = step;
1065 record_full_resumed = 1;
1066 record_full_execution_dir = ::execution_direction;
1068 if (!RECORD_FULL_IS_REPLAY)
1070 struct gdbarch *gdbarch = target_thread_architecture (ptid);
1072 record_full_message (get_current_regcache (), signal);
1076 /* This is not hard single step. */
1077 if (!gdbarch_software_single_step_p (gdbarch))
1079 /* This is a normal continue. */
1084 /* This arch supports soft single step. */
1085 if (thread_has_single_step_breakpoints_set (inferior_thread ()))
1087 /* This is a soft single step. */
1088 record_full_resume_step = 1;
1091 step = !insert_single_step_breakpoints (gdbarch);
1095 /* Make sure the target beneath reports all signals. */
1096 target_pass_signals (0, NULL);
1098 this->beneath->resume (ptid, step, signal);
1101 /* We are about to start executing the inferior (or simulate it),
1102 let's register it with the event loop. */
1103 if (target_can_async_p ())
1107 /* "commit_resume" method for process record target. */
1110 record_full_target::commit_resume ()
1112 if (!RECORD_FULL_IS_REPLAY)
1113 beneath->commit_resume ();
1116 static int record_full_get_sig = 0;
1118 /* SIGINT signal handler, registered by "wait" method. */
1121 record_full_sig_handler (int signo)
1124 fprintf_unfiltered (gdb_stdlog, "Process record: get a signal\n");
1126 /* It will break the running inferior in replay mode. */
1127 record_full_resume_step = 1;
1129 /* It will let record_full_wait set inferior status to get the signal
1131 record_full_get_sig = 1;
1135 record_full_wait_cleanups (void *ignore)
1137 if (execution_direction == EXEC_REVERSE)
1139 if (record_full_list->next)
1140 record_full_list = record_full_list->next;
1143 record_full_list = record_full_list->prev;
1146 /* "wait" target method for process record target.
1148 In record mode, the target is always run in singlestep mode
1149 (even when gdb says to continue). The wait method intercepts
1150 the stop events and determines which ones are to be passed on to
1151 gdb. Most stop events are just singlestep events that gdb is not
1152 to know about, so the wait method just records them and keeps
1155 In replay mode, this function emulates the recorded execution log,
1156 one instruction at a time (forward or backward), and determines
1160 record_full_wait_1 (struct target_ops *ops,
1161 ptid_t ptid, struct target_waitstatus *status,
1164 scoped_restore restore_operation_disable
1165 = record_full_gdb_operation_disable_set ();
1168 fprintf_unfiltered (gdb_stdlog,
1169 "Process record: record_full_wait "
1170 "record_full_resume_step = %d, "
1171 "record_full_resumed = %d, direction=%s\n",
1172 record_full_resume_step, record_full_resumed,
1173 record_full_execution_dir == EXEC_FORWARD
1174 ? "forward" : "reverse");
1176 if (!record_full_resumed)
1178 gdb_assert ((options & TARGET_WNOHANG) != 0);
1180 /* No interesting event. */
1181 status->kind = TARGET_WAITKIND_IGNORE;
1182 return minus_one_ptid;
1185 record_full_get_sig = 0;
1186 signal (SIGINT, record_full_sig_handler);
1188 record_full_stop_reason = TARGET_STOPPED_BY_NO_REASON;
1190 if (!RECORD_FULL_IS_REPLAY && ops != &record_full_core_ops)
1192 if (record_full_resume_step)
1194 /* This is a single step. */
1195 return ops->beneath->wait (ptid, status, options);
1199 /* This is not a single step. */
1202 struct gdbarch *gdbarch = target_thread_architecture (inferior_ptid);
1206 struct thread_info *tp;
1208 ret = ops->beneath->wait (ptid, status, options);
1209 if (status->kind == TARGET_WAITKIND_IGNORE)
1212 fprintf_unfiltered (gdb_stdlog,
1213 "Process record: record_full_wait "
1214 "target beneath not done yet\n");
1218 ALL_NON_EXITED_THREADS (tp)
1219 delete_single_step_breakpoints (tp);
1221 if (record_full_resume_step)
1224 /* Is this a SIGTRAP? */
1225 if (status->kind == TARGET_WAITKIND_STOPPED
1226 && status->value.sig == GDB_SIGNAL_TRAP)
1228 struct regcache *regcache;
1229 enum target_stop_reason *stop_reason_p
1230 = &record_full_stop_reason;
1232 /* Yes -- this is likely our single-step finishing,
1233 but check if there's any reason the core would be
1234 interested in the event. */
1236 registers_changed ();
1237 regcache = get_current_regcache ();
1238 tmp_pc = regcache_read_pc (regcache);
1239 const struct address_space *aspace = regcache->aspace ();
1241 if (target_stopped_by_watchpoint ())
1243 /* Always interested in watchpoints. */
1245 else if (record_check_stopped_by_breakpoint (aspace, tmp_pc,
1248 /* There is a breakpoint here. Let the core
1253 /* This is a single-step trap. Record the
1254 insn and issue another step.
1255 FIXME: this part can be a random SIGTRAP too.
1256 But GDB cannot handle it. */
1259 if (!record_full_message_wrapper_safe (regcache,
1262 status->kind = TARGET_WAITKIND_STOPPED;
1263 status->value.sig = GDB_SIGNAL_0;
1267 if (gdbarch_software_single_step_p (gdbarch))
1269 /* Try to insert the software single step breakpoint.
1270 If insert success, set step to 0. */
1271 set_executing (inferior_ptid, 0);
1272 reinit_frame_cache ();
1274 step = !insert_single_step_breakpoints (gdbarch);
1276 set_executing (inferior_ptid, 1);
1280 fprintf_unfiltered (gdb_stdlog,
1281 "Process record: record_full_wait "
1282 "issuing one more step in the "
1283 "target beneath\n");
1284 ops->beneath->resume (ptid, step, GDB_SIGNAL_0);
1285 ops->beneath->commit_resume ();
1290 /* The inferior is broken by a breakpoint or a signal. */
1299 struct regcache *regcache = get_current_regcache ();
1300 struct gdbarch *gdbarch = regcache->arch ();
1301 const struct address_space *aspace = regcache->aspace ();
1302 int continue_flag = 1;
1303 int first_record_full_end = 1;
1304 struct cleanup *old_cleanups
1305 = make_cleanup (record_full_wait_cleanups, 0);
1308 record_full_stop_reason = TARGET_STOPPED_BY_NO_REASON;
1309 status->kind = TARGET_WAITKIND_STOPPED;
1311 /* Check breakpoint when forward execute. */
1312 if (execution_direction == EXEC_FORWARD)
1314 tmp_pc = regcache_read_pc (regcache);
1315 if (record_check_stopped_by_breakpoint (aspace, tmp_pc,
1316 &record_full_stop_reason))
1319 fprintf_unfiltered (gdb_stdlog,
1320 "Process record: break at %s.\n",
1321 paddress (gdbarch, tmp_pc));
1326 /* If GDB is in terminal_inferior mode, it will not get the signal.
1327 And in GDB replay mode, GDB doesn't need to be in terminal_inferior
1328 mode, because inferior will not executed.
1329 Then set it to terminal_ours to make GDB get the signal. */
1330 target_terminal::ours ();
1332 /* In EXEC_FORWARD mode, record_full_list points to the tail of prev
1334 if (execution_direction == EXEC_FORWARD && record_full_list->next)
1335 record_full_list = record_full_list->next;
1337 /* Loop over the record_full_list, looking for the next place to
1341 /* Check for beginning and end of log. */
1342 if (execution_direction == EXEC_REVERSE
1343 && record_full_list == &record_full_first)
1345 /* Hit beginning of record log in reverse. */
1346 status->kind = TARGET_WAITKIND_NO_HISTORY;
1349 if (execution_direction != EXEC_REVERSE && !record_full_list->next)
1351 /* Hit end of record log going forward. */
1352 status->kind = TARGET_WAITKIND_NO_HISTORY;
1356 record_full_exec_insn (regcache, gdbarch, record_full_list);
1358 if (record_full_list->type == record_full_end)
1360 if (record_debug > 1)
1361 fprintf_unfiltered (gdb_stdlog,
1362 "Process record: record_full_end %s to "
1364 host_address_to_string (record_full_list));
1366 if (first_record_full_end && execution_direction == EXEC_REVERSE)
1368 /* When reverse excute, the first record_full_end is the
1369 part of current instruction. */
1370 first_record_full_end = 0;
1374 /* In EXEC_REVERSE mode, this is the record_full_end of prev
1376 In EXEC_FORWARD mode, this is the record_full_end of
1377 current instruction. */
1379 if (record_full_resume_step)
1381 if (record_debug > 1)
1382 fprintf_unfiltered (gdb_stdlog,
1383 "Process record: step.\n");
1387 /* check breakpoint */
1388 tmp_pc = regcache_read_pc (regcache);
1389 if (record_check_stopped_by_breakpoint (aspace, tmp_pc,
1390 &record_full_stop_reason))
1393 fprintf_unfiltered (gdb_stdlog,
1394 "Process record: break "
1396 paddress (gdbarch, tmp_pc));
1401 if (record_full_stop_reason == 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 discard_cleanups (old_cleanups);
1444 signal (SIGINT, handle_sigint);
1446 return inferior_ptid;
1450 record_full_base_target::wait (ptid_t ptid, struct target_waitstatus *status,
1455 return_ptid = record_full_wait_1 (this, ptid, status, options);
1456 if (status->kind != TARGET_WAITKIND_IGNORE)
1458 /* We're reporting a stop. Make sure any spurious
1459 target_wait(WNOHANG) doesn't advance the target until the
1460 core wants us resumed again. */
1461 record_full_resumed = 0;
1467 record_full_base_target::stopped_by_watchpoint ()
1469 if (RECORD_FULL_IS_REPLAY)
1470 return record_full_stop_reason == TARGET_STOPPED_BY_WATCHPOINT;
1472 return beneath->stopped_by_watchpoint ();
1476 record_full_base_target::stopped_data_address (CORE_ADDR *addr_p)
1478 if (RECORD_FULL_IS_REPLAY)
1481 return this->beneath->stopped_data_address (addr_p);
1484 /* The stopped_by_sw_breakpoint method of target record-full. */
1487 record_full_base_target::stopped_by_sw_breakpoint ()
1489 return record_full_stop_reason == TARGET_STOPPED_BY_SW_BREAKPOINT;
1492 /* The supports_stopped_by_sw_breakpoint method of target
1496 record_full_base_target::supports_stopped_by_sw_breakpoint ()
1501 /* The stopped_by_hw_breakpoint method of target record-full. */
1504 record_full_base_target::stopped_by_hw_breakpoint ()
1506 return record_full_stop_reason == TARGET_STOPPED_BY_HW_BREAKPOINT;
1509 /* The supports_stopped_by_sw_breakpoint method of target
1513 record_full_base_target::supports_stopped_by_hw_breakpoint ()
1518 /* Record registers change (by user or by GDB) to list as an instruction. */
1521 record_full_registers_change (struct regcache *regcache, int regnum)
1523 /* Check record_full_insn_num. */
1524 record_full_check_insn_num ();
1526 record_full_arch_list_head = NULL;
1527 record_full_arch_list_tail = NULL;
1533 for (i = 0; i < gdbarch_num_regs (regcache->arch ()); i++)
1535 if (record_full_arch_list_add_reg (regcache, i))
1537 record_full_list_release (record_full_arch_list_tail);
1538 error (_("Process record: failed to record execution log."));
1544 if (record_full_arch_list_add_reg (regcache, regnum))
1546 record_full_list_release (record_full_arch_list_tail);
1547 error (_("Process record: failed to record execution log."));
1550 if (record_full_arch_list_add_end ())
1552 record_full_list_release (record_full_arch_list_tail);
1553 error (_("Process record: failed to record execution log."));
1555 record_full_list->next = record_full_arch_list_head;
1556 record_full_arch_list_head->prev = record_full_list;
1557 record_full_list = record_full_arch_list_tail;
1559 if (record_full_insn_num == record_full_insn_max_num)
1560 record_full_list_release_first ();
1562 record_full_insn_num++;
1565 /* "store_registers" method for process record target. */
1568 record_full_target::store_registers (struct regcache *regcache, int regno)
1570 if (!record_full_gdb_operation_disable)
1572 if (RECORD_FULL_IS_REPLAY)
1576 /* Let user choose if he wants to write register or not. */
1579 query (_("Because GDB is in replay mode, changing the "
1580 "value of a register will make the execution "
1581 "log unusable from this point onward. "
1582 "Change all registers?"));
1585 query (_("Because GDB is in replay mode, changing the value "
1586 "of a register will make the execution log unusable "
1587 "from this point onward. Change register %s?"),
1588 gdbarch_register_name (regcache->arch (),
1593 /* Invalidate the value of regcache that was set in function
1594 "regcache_raw_write". */
1600 i < gdbarch_num_regs (regcache->arch ());
1602 regcache_invalidate (regcache, i);
1605 regcache_invalidate (regcache, regno);
1607 error (_("Process record canceled the operation."));
1610 /* Destroy the record from here forward. */
1611 record_full_list_release_following (record_full_list);
1614 record_full_registers_change (regcache, regno);
1616 this->beneath->store_registers (regcache, regno);
1619 /* "xfer_partial" method. Behavior is conditional on
1620 RECORD_FULL_IS_REPLAY.
1621 In replay mode, we cannot write memory unles we are willing to
1622 invalidate the record/replay log from this point forward. */
1624 enum target_xfer_status
1625 record_full_target::xfer_partial (enum target_object object,
1626 const char *annex, gdb_byte *readbuf,
1627 const gdb_byte *writebuf, ULONGEST offset,
1628 ULONGEST len, ULONGEST *xfered_len)
1630 if (!record_full_gdb_operation_disable
1631 && (object == TARGET_OBJECT_MEMORY
1632 || object == TARGET_OBJECT_RAW_MEMORY) && writebuf)
1634 if (RECORD_FULL_IS_REPLAY)
1636 /* Let user choose if he wants to write memory or not. */
1637 if (!query (_("Because GDB is in replay mode, writing to memory "
1638 "will make the execution log unusable from this "
1639 "point onward. Write memory at address %s?"),
1640 paddress (target_gdbarch (), offset)))
1641 error (_("Process record canceled the operation."));
1643 /* Destroy the record from here forward. */
1644 record_full_list_release_following (record_full_list);
1647 /* Check record_full_insn_num */
1648 record_full_check_insn_num ();
1650 /* Record registers change to list as an instruction. */
1651 record_full_arch_list_head = NULL;
1652 record_full_arch_list_tail = NULL;
1653 if (record_full_arch_list_add_mem (offset, len))
1655 record_full_list_release (record_full_arch_list_tail);
1657 fprintf_unfiltered (gdb_stdlog,
1658 "Process record: failed to record "
1660 return TARGET_XFER_E_IO;
1662 if (record_full_arch_list_add_end ())
1664 record_full_list_release (record_full_arch_list_tail);
1666 fprintf_unfiltered (gdb_stdlog,
1667 "Process record: failed to record "
1669 return TARGET_XFER_E_IO;
1671 record_full_list->next = record_full_arch_list_head;
1672 record_full_arch_list_head->prev = record_full_list;
1673 record_full_list = record_full_arch_list_tail;
1675 if (record_full_insn_num == record_full_insn_max_num)
1676 record_full_list_release_first ();
1678 record_full_insn_num++;
1681 return this->beneath->xfer_partial (object, annex, readbuf, writebuf, offset,
1685 /* This structure represents a breakpoint inserted while the record
1686 target is active. We use this to know when to install/remove
1687 breakpoints in/from the target beneath. For example, a breakpoint
1688 may be inserted while recording, but removed when not replaying nor
1689 recording. In that case, the breakpoint had not been inserted on
1690 the target beneath, so we should not try to remove it there. */
1692 struct record_full_breakpoint
1694 /* The address and address space the breakpoint was set at. */
1695 struct address_space *address_space;
1698 /* True when the breakpoint has been also installed in the target
1699 beneath. This will be false for breakpoints set during replay or
1701 int in_target_beneath;
1704 typedef struct record_full_breakpoint *record_full_breakpoint_p;
1705 DEF_VEC_P(record_full_breakpoint_p);
1707 /* The list of breakpoints inserted while the record target is
1709 VEC(record_full_breakpoint_p) *record_full_breakpoints = NULL;
1712 record_full_sync_record_breakpoints (struct bp_location *loc, void *data)
1714 if (loc->loc_type != bp_loc_software_breakpoint)
1719 struct record_full_breakpoint *bp = XNEW (struct record_full_breakpoint);
1721 bp->addr = loc->target_info.placed_address;
1722 bp->address_space = loc->target_info.placed_address_space;
1724 bp->in_target_beneath = 1;
1726 VEC_safe_push (record_full_breakpoint_p, record_full_breakpoints, bp);
1730 /* Sync existing breakpoints to record_full_breakpoints. */
1733 record_full_init_record_breakpoints (void)
1735 VEC_free (record_full_breakpoint_p, record_full_breakpoints);
1737 iterate_over_bp_locations (record_full_sync_record_breakpoints);
1740 /* Behavior is conditional on RECORD_FULL_IS_REPLAY. We will not actually
1741 insert or remove breakpoints in the real target when replaying, nor
1745 record_full_target::insert_breakpoint (struct gdbarch *gdbarch,
1746 struct bp_target_info *bp_tgt)
1748 struct record_full_breakpoint *bp;
1749 int in_target_beneath = 0;
1752 if (!RECORD_FULL_IS_REPLAY)
1754 /* When recording, we currently always single-step, so we don't
1755 really need to install regular breakpoints in the inferior.
1756 However, we do have to insert software single-step
1757 breakpoints, in case the target can't hardware step. To keep
1758 things simple, we always insert. */
1760 scoped_restore restore_operation_disable
1761 = record_full_gdb_operation_disable_set ();
1763 int ret = this->beneath->insert_breakpoint (gdbarch, bp_tgt);
1767 in_target_beneath = 1;
1770 /* Use the existing entries if found in order to avoid duplication
1771 in record_full_breakpoints. */
1774 VEC_iterate (record_full_breakpoint_p,
1775 record_full_breakpoints, ix, bp);
1778 if (bp->addr == bp_tgt->placed_address
1779 && bp->address_space == bp_tgt->placed_address_space)
1781 gdb_assert (bp->in_target_beneath == in_target_beneath);
1786 bp = XNEW (struct record_full_breakpoint);
1787 bp->addr = bp_tgt->placed_address;
1788 bp->address_space = bp_tgt->placed_address_space;
1789 bp->in_target_beneath = in_target_beneath;
1790 VEC_safe_push (record_full_breakpoint_p, record_full_breakpoints, bp);
1794 /* "remove_breakpoint" method for process record target. */
1797 record_full_target::remove_breakpoint (struct gdbarch *gdbarch,
1798 struct bp_target_info *bp_tgt,
1799 enum remove_bp_reason reason)
1801 struct record_full_breakpoint *bp;
1805 VEC_iterate (record_full_breakpoint_p,
1806 record_full_breakpoints, ix, bp);
1809 if (bp->addr == bp_tgt->placed_address
1810 && bp->address_space == bp_tgt->placed_address_space)
1812 if (bp->in_target_beneath)
1814 scoped_restore restore_operation_disable
1815 = record_full_gdb_operation_disable_set ();
1817 int ret = this->beneath->remove_breakpoint (gdbarch, bp_tgt,
1823 if (reason == REMOVE_BREAKPOINT)
1825 VEC_unordered_remove (record_full_breakpoint_p,
1826 record_full_breakpoints, ix);
1832 gdb_assert_not_reached ("removing unknown breakpoint");
1835 /* "can_execute_reverse" method for process record target. */
1838 record_full_base_target::can_execute_reverse ()
1843 /* "get_bookmark" method for process record and prec over core. */
1846 record_full_base_target::get_bookmark (const char *args, int from_tty)
1850 /* Return stringified form of instruction count. */
1851 if (record_full_list && record_full_list->type == record_full_end)
1852 ret = xstrdup (pulongest (record_full_list->u.end.insn_num));
1857 fprintf_unfiltered (gdb_stdlog,
1858 "record_full_get_bookmark returns %s\n", ret);
1860 fprintf_unfiltered (gdb_stdlog,
1861 "record_full_get_bookmark returns NULL\n");
1863 return (gdb_byte *) ret;
1866 /* "goto_bookmark" method for process record and prec over core. */
1869 record_full_base_target::goto_bookmark (const gdb_byte *raw_bookmark,
1872 const char *bookmark = (const char *) raw_bookmark;
1875 fprintf_unfiltered (gdb_stdlog,
1876 "record_full_goto_bookmark receives %s\n", bookmark);
1878 std::string name_holder;
1879 if (bookmark[0] == '\'' || bookmark[0] == '\"')
1881 if (bookmark[strlen (bookmark) - 1] != bookmark[0])
1882 error (_("Unbalanced quotes: %s"), bookmark);
1884 name_holder = std::string (bookmark + 1, strlen (bookmark) - 2);
1885 bookmark = name_holder.c_str ();
1888 record_goto (bookmark);
1891 enum exec_direction_kind
1892 record_full_base_target::execution_direction ()
1894 return record_full_execution_dir;
1897 /* The record_method method of target record-full. */
1900 record_full_base_target::record_method (ptid_t ptid)
1902 return RECORD_METHOD_FULL;
1906 record_full_base_target::info_record ()
1908 struct record_full_entry *p;
1910 if (RECORD_FULL_IS_REPLAY)
1911 printf_filtered (_("Replay mode:\n"));
1913 printf_filtered (_("Record mode:\n"));
1915 /* Find entry for first actual instruction in the log. */
1916 for (p = record_full_first.next;
1917 p != NULL && p->type != record_full_end;
1921 /* Do we have a log at all? */
1922 if (p != NULL && p->type == record_full_end)
1924 /* Display instruction number for first instruction in the log. */
1925 printf_filtered (_("Lowest recorded instruction number is %s.\n"),
1926 pulongest (p->u.end.insn_num));
1928 /* If in replay mode, display where we are in the log. */
1929 if (RECORD_FULL_IS_REPLAY)
1930 printf_filtered (_("Current instruction number is %s.\n"),
1931 pulongest (record_full_list->u.end.insn_num));
1933 /* Display instruction number for last instruction in the log. */
1934 printf_filtered (_("Highest recorded instruction number is %s.\n"),
1935 pulongest (record_full_insn_count));
1937 /* Display log count. */
1938 printf_filtered (_("Log contains %u instructions.\n"),
1939 record_full_insn_num);
1942 printf_filtered (_("No instructions have been logged.\n"));
1944 /* Display max log size. */
1945 printf_filtered (_("Max logged instructions is %u.\n"),
1946 record_full_insn_max_num);
1950 record_full_base_target::supports_delete_record ()
1955 /* The "delete_record" target method. */
1958 record_full_base_target::delete_record ()
1960 record_full_list_release_following (record_full_list);
1963 /* The "record_is_replaying" target method. */
1966 record_full_base_target::record_is_replaying (ptid_t ptid)
1968 return RECORD_FULL_IS_REPLAY;
1971 /* The "record_will_replay" target method. */
1974 record_full_base_target::record_will_replay (ptid_t ptid, int dir)
1976 /* We can currently only record when executing forwards. Should we be able
1977 to record when executing backwards on targets that support reverse
1978 execution, this needs to be changed. */
1980 return RECORD_FULL_IS_REPLAY || dir == EXEC_REVERSE;
1983 /* Go to a specific entry. */
1986 record_full_goto_entry (struct record_full_entry *p)
1989 error (_("Target insn not found."));
1990 else if (p == record_full_list)
1991 error (_("Already at target insn."));
1992 else if (p->u.end.insn_num > record_full_list->u.end.insn_num)
1994 printf_filtered (_("Go forward to insn number %s\n"),
1995 pulongest (p->u.end.insn_num));
1996 record_full_goto_insn (p, EXEC_FORWARD);
2000 printf_filtered (_("Go backward to insn number %s\n"),
2001 pulongest (p->u.end.insn_num));
2002 record_full_goto_insn (p, EXEC_REVERSE);
2005 registers_changed ();
2006 reinit_frame_cache ();
2007 stop_pc = regcache_read_pc (get_current_regcache ());
2008 print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1);
2011 /* The "goto_record_begin" target method. */
2014 record_full_base_target::goto_record_begin ()
2016 struct record_full_entry *p = NULL;
2018 for (p = &record_full_first; p != NULL; p = p->next)
2019 if (p->type == record_full_end)
2022 record_full_goto_entry (p);
2025 /* The "goto_record_end" target method. */
2028 record_full_base_target::goto_record_end ()
2030 struct record_full_entry *p = NULL;
2032 for (p = record_full_list; p->next != NULL; p = p->next)
2034 for (; p!= NULL; p = p->prev)
2035 if (p->type == record_full_end)
2038 record_full_goto_entry (p);
2041 /* The "goto_record" target method. */
2044 record_full_base_target::goto_record (ULONGEST target_insn)
2046 struct record_full_entry *p = NULL;
2048 for (p = &record_full_first; p != NULL; p = p->next)
2049 if (p->type == record_full_end && p->u.end.insn_num == target_insn)
2052 record_full_goto_entry (p);
2055 /* The "record_stop_replaying" target method. */
2058 record_full_base_target::record_stop_replaying ()
2063 /* "resume" method for prec over corefile. */
2066 record_full_core_target::resume (ptid_t ptid, int step,
2067 enum gdb_signal signal)
2069 record_full_resume_step = step;
2070 record_full_resumed = 1;
2071 record_full_execution_dir = ::execution_direction;
2073 /* We are about to start executing the inferior (or simulate it),
2074 let's register it with the event loop. */
2075 if (target_can_async_p ())
2079 /* "kill" method for prec over corefile. */
2082 record_full_core_target::kill ()
2085 fprintf_unfiltered (gdb_stdlog, "Process record: record_full_core_kill\n");
2087 unpush_target (this);
2090 /* "fetch_registers" method for prec over corefile. */
2093 record_full_core_target::fetch_registers (struct regcache *regcache,
2098 int num = gdbarch_num_regs (regcache->arch ());
2101 for (i = 0; i < num; i ++)
2102 regcache->raw_supply (i, *record_full_core_regbuf);
2105 regcache->raw_supply (regno, *record_full_core_regbuf);
2108 /* "prepare_to_store" method for prec over corefile. */
2111 record_full_core_target::prepare_to_store (struct regcache *regcache)
2115 /* "store_registers" method for prec over corefile. */
2118 record_full_core_target::store_registers (struct regcache *regcache,
2121 if (record_full_gdb_operation_disable)
2122 record_full_core_regbuf->raw_supply (regno, *regcache);
2124 error (_("You can't do that without a process to debug."));
2127 /* "xfer_partial" method for prec over corefile. */
2129 enum target_xfer_status
2130 record_full_core_target::xfer_partial (enum target_object object,
2131 const char *annex, gdb_byte *readbuf,
2132 const gdb_byte *writebuf, ULONGEST offset,
2133 ULONGEST len, ULONGEST *xfered_len)
2135 if (object == TARGET_OBJECT_MEMORY)
2137 if (record_full_gdb_operation_disable || !writebuf)
2139 struct target_section *p;
2141 for (p = record_full_core_start; p < record_full_core_end; p++)
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 (ptid_t the_ptid)
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 cleanup *old_cleanups;
2332 struct record_full_entry *rec;
2336 struct regcache *regcache;
2338 /* We restore the execution log from the open core bfd,
2340 if (core_bfd == NULL)
2343 /* "record_full_restore" can only be called when record list is empty. */
2344 gdb_assert (record_full_first.next == NULL);
2347 fprintf_unfiltered (gdb_stdlog, "Restoring recording from core file.\n");
2349 /* Now need to find our special note section. */
2350 osec = bfd_get_section_by_name (core_bfd, "null0");
2352 fprintf_unfiltered (gdb_stdlog, "Find precord section %s.\n",
2353 osec ? "succeeded" : "failed");
2356 osec_size = bfd_section_size (core_bfd, osec);
2358 fprintf_unfiltered (gdb_stdlog, "%s", bfd_section_name (core_bfd, osec));
2360 /* Check the magic code. */
2361 bfdcore_read (core_bfd, osec, &magic, sizeof (magic), &bfd_offset);
2362 if (magic != RECORD_FULL_FILE_MAGIC)
2363 error (_("Version mis-match or file format error in core file %s."),
2364 bfd_get_filename (core_bfd));
2366 fprintf_unfiltered (gdb_stdlog,
2367 " Reading 4-byte magic cookie "
2368 "RECORD_FULL_FILE_MAGIC (0x%s)\n",
2369 phex_nz (netorder32 (magic), 4));
2371 /* Restore the entries in recfd into record_full_arch_list_head and
2372 record_full_arch_list_tail. */
2373 record_full_arch_list_head = NULL;
2374 record_full_arch_list_tail = NULL;
2375 record_full_insn_num = 0;
2376 old_cleanups = make_cleanup (record_full_arch_list_cleanups, 0);
2377 regcache = get_current_regcache ();
2382 uint32_t regnum, len, signal, count;
2385 /* We are finished when offset reaches osec_size. */
2386 if (bfd_offset >= osec_size)
2388 bfdcore_read (core_bfd, osec, &rectype, sizeof (rectype), &bfd_offset);
2392 case record_full_reg: /* reg */
2393 /* Get register number to regnum. */
2394 bfdcore_read (core_bfd, osec, ®num,
2395 sizeof (regnum), &bfd_offset);
2396 regnum = netorder32 (regnum);
2398 rec = record_full_reg_alloc (regcache, regnum);
2401 bfdcore_read (core_bfd, osec, record_full_get_loc (rec),
2402 rec->u.reg.len, &bfd_offset);
2405 fprintf_unfiltered (gdb_stdlog,
2406 " Reading register %d (1 "
2407 "plus %lu plus %d bytes)\n",
2409 (unsigned long) sizeof (regnum),
2413 case record_full_mem: /* mem */
2415 bfdcore_read (core_bfd, osec, &len,
2416 sizeof (len), &bfd_offset);
2417 len = netorder32 (len);
2420 bfdcore_read (core_bfd, osec, &addr,
2421 sizeof (addr), &bfd_offset);
2422 addr = netorder64 (addr);
2424 rec = record_full_mem_alloc (addr, len);
2427 bfdcore_read (core_bfd, osec, record_full_get_loc (rec),
2428 rec->u.mem.len, &bfd_offset);
2431 fprintf_unfiltered (gdb_stdlog,
2432 " Reading memory %s (1 plus "
2433 "%lu plus %lu plus %d bytes)\n",
2434 paddress (get_current_arch (),
2436 (unsigned long) sizeof (addr),
2437 (unsigned long) sizeof (len),
2441 case record_full_end: /* end */
2442 rec = record_full_end_alloc ();
2443 record_full_insn_num ++;
2445 /* Get signal value. */
2446 bfdcore_read (core_bfd, osec, &signal,
2447 sizeof (signal), &bfd_offset);
2448 signal = netorder32 (signal);
2449 rec->u.end.sigval = (enum gdb_signal) signal;
2451 /* Get insn count. */
2452 bfdcore_read (core_bfd, osec, &count,
2453 sizeof (count), &bfd_offset);
2454 count = netorder32 (count);
2455 rec->u.end.insn_num = count;
2456 record_full_insn_count = count + 1;
2458 fprintf_unfiltered (gdb_stdlog,
2459 " Reading record_full_end (1 + "
2460 "%lu + %lu bytes), offset == %s\n",
2461 (unsigned long) sizeof (signal),
2462 (unsigned long) sizeof (count),
2463 paddress (get_current_arch (),
2468 error (_("Bad entry type in core file %s."),
2469 bfd_get_filename (core_bfd));
2473 /* Add rec to record arch list. */
2474 record_full_arch_list_add (rec);
2477 discard_cleanups (old_cleanups);
2479 /* Add record_full_arch_list_head to the end of record list. */
2480 record_full_first.next = record_full_arch_list_head;
2481 record_full_arch_list_head->prev = &record_full_first;
2482 record_full_arch_list_tail->next = NULL;
2483 record_full_list = &record_full_first;
2485 /* Update record_full_insn_max_num. */
2486 if (record_full_insn_num > record_full_insn_max_num)
2488 record_full_insn_max_num = record_full_insn_num;
2489 warning (_("Auto increase record/replay buffer limit to %u."),
2490 record_full_insn_max_num);
2494 printf_filtered (_("Restored records from core file %s.\n"),
2495 bfd_get_filename (core_bfd));
2497 print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1);
2500 /* bfdcore_write -- write bytes into a core file section. */
2503 bfdcore_write (bfd *obfd, asection *osec, void *buf, int len, int *offset)
2505 int ret = bfd_set_section_contents (obfd, osec, buf, *offset, len);
2510 error (_("Failed to write %d bytes to core file %s ('%s')."),
2511 len, bfd_get_filename (obfd),
2512 bfd_errmsg (bfd_get_error ()));
2515 /* Restore the execution log from a file. We use a modified elf
2516 corefile format, with an extra section for our data. */
2519 cmd_record_full_restore (const char *args, int from_tty)
2521 core_file_command (args, from_tty);
2522 record_full_ops.open (args, from_tty);
2525 /* Save the execution log to a file. We use a modified elf corefile
2526 format, with an extra section for our data. */
2529 record_full_base_target::save_record (const char *recfilename)
2531 struct record_full_entry *cur_record_full_list;
2533 struct regcache *regcache;
2534 struct gdbarch *gdbarch;
2536 asection *osec = NULL;
2539 /* Open the save file. */
2541 fprintf_unfiltered (gdb_stdlog, "Saving execution log to core file '%s'\n",
2544 /* Open the output file. */
2545 gdb_bfd_ref_ptr obfd (create_gcore_bfd (recfilename));
2547 /* Arrange to remove the output file on failure. */
2548 gdb::unlinker unlink_file (recfilename);
2550 /* Save the current record entry to "cur_record_full_list". */
2551 cur_record_full_list = record_full_list;
2553 /* Get the values of regcache and gdbarch. */
2554 regcache = get_current_regcache ();
2555 gdbarch = regcache->arch ();
2557 /* Disable the GDB operation record. */
2558 scoped_restore restore_operation_disable
2559 = record_full_gdb_operation_disable_set ();
2561 /* Reverse execute to the begin of record list. */
2564 /* Check for beginning and end of log. */
2565 if (record_full_list == &record_full_first)
2568 record_full_exec_insn (regcache, gdbarch, record_full_list);
2570 if (record_full_list->prev)
2571 record_full_list = record_full_list->prev;
2574 /* Compute the size needed for the extra bfd section. */
2575 save_size = 4; /* magic cookie */
2576 for (record_full_list = record_full_first.next; record_full_list;
2577 record_full_list = record_full_list->next)
2578 switch (record_full_list->type)
2580 case record_full_end:
2581 save_size += 1 + 4 + 4;
2583 case record_full_reg:
2584 save_size += 1 + 4 + record_full_list->u.reg.len;
2586 case record_full_mem:
2587 save_size += 1 + 4 + 8 + record_full_list->u.mem.len;
2591 /* Make the new bfd section. */
2592 osec = bfd_make_section_anyway_with_flags (obfd.get (), "precord",
2596 error (_("Failed to create 'precord' section for corefile %s: %s"),
2598 bfd_errmsg (bfd_get_error ()));
2599 bfd_set_section_size (obfd.get (), osec, save_size);
2600 bfd_set_section_vma (obfd.get (), osec, 0);
2601 bfd_set_section_alignment (obfd.get (), osec, 0);
2602 bfd_section_lma (obfd.get (), osec) = 0;
2604 /* Save corefile state. */
2605 write_gcore_file (obfd.get ());
2607 /* Write out the record log. */
2608 /* Write the magic code. */
2609 magic = RECORD_FULL_FILE_MAGIC;
2611 fprintf_unfiltered (gdb_stdlog,
2612 " Writing 4-byte magic cookie "
2613 "RECORD_FULL_FILE_MAGIC (0x%s)\n",
2614 phex_nz (magic, 4));
2615 bfdcore_write (obfd.get (), osec, &magic, sizeof (magic), &bfd_offset);
2617 /* Save the entries to recfd and forward execute to the end of
2619 record_full_list = &record_full_first;
2623 if (record_full_list != &record_full_first)
2626 uint32_t regnum, len, signal, count;
2629 type = record_full_list->type;
2630 bfdcore_write (obfd.get (), osec, &type, sizeof (type), &bfd_offset);
2632 switch (record_full_list->type)
2634 case record_full_reg: /* reg */
2636 fprintf_unfiltered (gdb_stdlog,
2637 " Writing register %d (1 "
2638 "plus %lu plus %d bytes)\n",
2639 record_full_list->u.reg.num,
2640 (unsigned long) sizeof (regnum),
2641 record_full_list->u.reg.len);
2644 regnum = netorder32 (record_full_list->u.reg.num);
2645 bfdcore_write (obfd.get (), osec, ®num,
2646 sizeof (regnum), &bfd_offset);
2649 bfdcore_write (obfd.get (), osec,
2650 record_full_get_loc (record_full_list),
2651 record_full_list->u.reg.len, &bfd_offset);
2654 case record_full_mem: /* mem */
2656 fprintf_unfiltered (gdb_stdlog,
2657 " Writing memory %s (1 plus "
2658 "%lu plus %lu plus %d bytes)\n",
2660 record_full_list->u.mem.addr),
2661 (unsigned long) sizeof (addr),
2662 (unsigned long) sizeof (len),
2663 record_full_list->u.mem.len);
2666 len = netorder32 (record_full_list->u.mem.len);
2667 bfdcore_write (obfd.get (), osec, &len, sizeof (len),
2670 /* Write memaddr. */
2671 addr = netorder64 (record_full_list->u.mem.addr);
2672 bfdcore_write (obfd.get (), osec, &addr,
2673 sizeof (addr), &bfd_offset);
2676 bfdcore_write (obfd.get (), osec,
2677 record_full_get_loc (record_full_list),
2678 record_full_list->u.mem.len, &bfd_offset);
2681 case record_full_end:
2683 fprintf_unfiltered (gdb_stdlog,
2684 " Writing record_full_end (1 + "
2685 "%lu + %lu bytes)\n",
2686 (unsigned long) sizeof (signal),
2687 (unsigned long) sizeof (count));
2688 /* Write signal value. */
2689 signal = netorder32 (record_full_list->u.end.sigval);
2690 bfdcore_write (obfd.get (), osec, &signal,
2691 sizeof (signal), &bfd_offset);
2693 /* Write insn count. */
2694 count = netorder32 (record_full_list->u.end.insn_num);
2695 bfdcore_write (obfd.get (), osec, &count,
2696 sizeof (count), &bfd_offset);
2701 /* Execute entry. */
2702 record_full_exec_insn (regcache, gdbarch, record_full_list);
2704 if (record_full_list->next)
2705 record_full_list = record_full_list->next;
2710 /* Reverse execute to cur_record_full_list. */
2713 /* Check for beginning and end of log. */
2714 if (record_full_list == cur_record_full_list)
2717 record_full_exec_insn (regcache, gdbarch, record_full_list);
2719 if (record_full_list->prev)
2720 record_full_list = record_full_list->prev;
2723 unlink_file.keep ();
2726 printf_filtered (_("Saved core file %s with execution log.\n"),
2730 /* record_full_goto_insn -- rewind the record log (forward or backward,
2731 depending on DIR) to the given entry, changing the program state
2735 record_full_goto_insn (struct record_full_entry *entry,
2736 enum exec_direction_kind dir)
2738 scoped_restore restore_operation_disable
2739 = record_full_gdb_operation_disable_set ();
2740 struct regcache *regcache = get_current_regcache ();
2741 struct gdbarch *gdbarch = regcache->arch ();
2743 /* Assume everything is valid: we will hit the entry,
2744 and we will not hit the end of the recording. */
2746 if (dir == EXEC_FORWARD)
2747 record_full_list = record_full_list->next;
2751 record_full_exec_insn (regcache, gdbarch, record_full_list);
2752 if (dir == EXEC_REVERSE)
2753 record_full_list = record_full_list->prev;
2755 record_full_list = record_full_list->next;
2756 } while (record_full_list != entry);
2759 /* Alias for "target record-full". */
2762 cmd_record_full_start (const char *args, int from_tty)
2764 execute_command ("target record-full", from_tty);
2768 set_record_full_insn_max_num (const char *args, int from_tty,
2769 struct cmd_list_element *c)
2771 if (record_full_insn_num > record_full_insn_max_num)
2773 /* Count down record_full_insn_num while releasing records from list. */
2774 while (record_full_insn_num > record_full_insn_max_num)
2776 record_full_list_release_first ();
2777 record_full_insn_num--;
2782 /* The "set record full" command. */
2785 set_record_full_command (const char *args, int from_tty)
2787 printf_unfiltered (_("\"set record full\" must be followed "
2788 "by an appropriate subcommand.\n"));
2789 help_list (set_record_full_cmdlist, "set record full ", all_commands,
2793 /* The "show record full" command. */
2796 show_record_full_command (const char *args, int from_tty)
2798 cmd_show_list (show_record_full_cmdlist, from_tty, "");
2802 _initialize_record_full (void)
2804 struct cmd_list_element *c;
2806 /* Init record_full_first. */
2807 record_full_first.prev = NULL;
2808 record_full_first.next = NULL;
2809 record_full_first.type = record_full_end;
2811 add_target (&record_full_ops);
2812 add_deprecated_target_alias (&record_full_ops, "record");
2813 add_target (&record_full_core_ops);
2815 add_prefix_cmd ("full", class_obscure, cmd_record_full_start,
2816 _("Start full execution recording."), &record_full_cmdlist,
2817 "record full ", 0, &record_cmdlist);
2819 c = add_cmd ("restore", class_obscure, cmd_record_full_restore,
2820 _("Restore the execution log from a file.\n\
2821 Argument is filename. File must be created with 'record save'."),
2822 &record_full_cmdlist);
2823 set_cmd_completer (c, filename_completer);
2825 /* Deprecate the old version without "full" prefix. */
2826 c = add_alias_cmd ("restore", "full restore", class_obscure, 1,
2828 set_cmd_completer (c, filename_completer);
2829 deprecate_cmd (c, "record full restore");
2831 add_prefix_cmd ("full", class_support, set_record_full_command,
2832 _("Set record options"), &set_record_full_cmdlist,
2833 "set record full ", 0, &set_record_cmdlist);
2835 add_prefix_cmd ("full", class_support, show_record_full_command,
2836 _("Show record options"), &show_record_full_cmdlist,
2837 "show record full ", 0, &show_record_cmdlist);
2839 /* Record instructions number limit command. */
2840 add_setshow_boolean_cmd ("stop-at-limit", no_class,
2841 &record_full_stop_at_limit, _("\
2842 Set whether record/replay stops when record/replay buffer becomes full."), _("\
2843 Show whether record/replay stops when record/replay buffer becomes full."),
2844 _("Default is ON.\n\
2845 When ON, if the record/replay buffer becomes full, ask user what to do.\n\
2846 When OFF, if the record/replay buffer becomes full,\n\
2847 delete the oldest recorded instruction to make room for each new one."),
2849 &set_record_full_cmdlist, &show_record_full_cmdlist);
2851 c = add_alias_cmd ("stop-at-limit", "full stop-at-limit", no_class, 1,
2852 &set_record_cmdlist);
2853 deprecate_cmd (c, "set record full stop-at-limit");
2855 c = add_alias_cmd ("stop-at-limit", "full stop-at-limit", no_class, 1,
2856 &show_record_cmdlist);
2857 deprecate_cmd (c, "show record full stop-at-limit");
2859 add_setshow_uinteger_cmd ("insn-number-max", no_class,
2860 &record_full_insn_max_num,
2861 _("Set record/replay buffer limit."),
2862 _("Show record/replay buffer limit."), _("\
2863 Set the maximum number of instructions to be stored in the\n\
2864 record/replay buffer. A value of either \"unlimited\" or zero means no\n\
2865 limit. Default is 200000."),
2866 set_record_full_insn_max_num,
2867 NULL, &set_record_full_cmdlist,
2868 &show_record_full_cmdlist);
2870 c = add_alias_cmd ("insn-number-max", "full insn-number-max", no_class, 1,
2871 &set_record_cmdlist);
2872 deprecate_cmd (c, "set record full insn-number-max");
2874 c = add_alias_cmd ("insn-number-max", "full insn-number-max", no_class, 1,
2875 &show_record_cmdlist);
2876 deprecate_cmd (c, "show record full insn-number-max");
2878 add_setshow_boolean_cmd ("memory-query", no_class,
2879 &record_full_memory_query, _("\
2880 Set whether query if PREC cannot record memory change of next instruction."),
2882 Show whether query if PREC cannot record memory change of next instruction."),
2885 When ON, query if PREC cannot record memory change of next instruction."),
2887 &set_record_full_cmdlist,
2888 &show_record_full_cmdlist);
2890 c = add_alias_cmd ("memory-query", "full memory-query", no_class, 1,
2891 &set_record_cmdlist);
2892 deprecate_cmd (c, "set record full memory-query");
2894 c = add_alias_cmd ("memory-query", "full memory-query", no_class, 1,
2895 &show_record_cmdlist);
2896 deprecate_cmd (c, "show record full memory-query");