1 /* Process record and replay target for GDB, the GNU debugger.
3 Copyright (C) 2008, 2009, 2010, 2011 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 "exceptions.h"
26 #include "completer.h"
27 #include "arch-utils.h"
36 /* This module implements "target record", also known as "process
37 record and replay". This target sits on top of a "normal" target
38 (a target that "has execution"), and provides a record and replay
39 functionality, including reverse debugging.
41 Target record has two modes: recording, and replaying.
43 In record mode, we intercept the to_resume and to_wait methods.
44 Whenever gdb resumes the target, we run the target in single step
45 mode, and we build up an execution log in which, for each executed
46 instruction, we record all changes in memory and register state.
47 This is invisible to the user, to whom it just looks like an
48 ordinary debugging session (except for performance degredation).
50 In replay mode, instead of actually letting the inferior run as a
51 process, we simulate its execution by playing back the recorded
52 execution log. For each instruction in the log, we simulate the
53 instruction's side effects by duplicating the changes that it would
54 have made on memory and registers. */
56 #define DEFAULT_RECORD_INSN_MAX_NUM 200000
58 #define RECORD_IS_REPLAY \
59 (record_list->next || execution_direction == EXEC_REVERSE)
61 #define RECORD_FILE_MAGIC netorder32(0x20091016)
63 /* These are the core structs of the process record functionality.
65 A record_entry is a record of the value change of a register
66 ("record_reg") or a part of memory ("record_mem"). And each
67 instruction must have a struct record_entry ("record_end") that
68 indicates that this is the last struct record_entry of this
71 Each struct record_entry is linked to "record_list" by "prev" and
74 struct record_mem_entry
78 /* Set this flag if target memory for this entry
79 can no longer be accessed. */
80 int mem_entry_not_accessible;
84 gdb_byte buf[sizeof (gdb_byte *)];
88 struct record_reg_entry
95 gdb_byte buf[2 * sizeof (gdb_byte *)];
99 struct record_end_entry
101 enum target_signal sigval;
112 /* This is the data structure that makes up the execution log.
114 The execution log consists of a single linked list of entries
115 of type "struct record_entry". It is doubly linked so that it
116 can be traversed in either direction.
118 The start of the list is anchored by a struct called
119 "record_first". The pointer "record_list" either points to the
120 last entry that was added to the list (in record mode), or to the
121 next entry in the list that will be executed (in replay mode).
123 Each list element (struct record_entry), in addition to next and
124 prev pointers, consists of a union of three entry types: mem, reg,
125 and end. A field called "type" determines which entry type is
126 represented by a given list element.
128 Each instruction that is added to the execution log is represented
129 by a variable number of list elements ('entries'). The instruction
130 will have one "reg" entry for each register that is changed by
131 executing the instruction (including the PC in every case). It
132 will also have one "mem" entry for each memory change. Finally,
133 each instruction will have an "end" entry that separates it from
134 the changes associated with the next instruction. */
138 struct record_entry *prev;
139 struct record_entry *next;
140 enum record_type type;
144 struct record_reg_entry reg;
146 struct record_mem_entry mem;
148 struct record_end_entry end;
152 /* This is the debug switch for process record. */
153 int record_debug = 0;
155 /* If true, query if PREC cannot record memory
156 change of next instruction. */
157 int record_memory_query = 0;
159 struct record_core_buf_entry
161 struct record_core_buf_entry *prev;
162 struct target_section *p;
166 /* Record buf with core target. */
167 static gdb_byte *record_core_regbuf = NULL;
168 static struct target_section *record_core_start;
169 static struct target_section *record_core_end;
170 static struct record_core_buf_entry *record_core_buf_list = NULL;
172 /* The following variables are used for managing the linked list that
173 represents the execution log.
175 record_first is the anchor that holds down the beginning of the list.
177 record_list serves two functions:
178 1) In record mode, it anchors the end of the list.
179 2) In replay mode, it traverses the list and points to
180 the next instruction that must be emulated.
182 record_arch_list_head and record_arch_list_tail are used to manage
183 a separate list, which is used to build up the change elements of
184 the currently executing instruction during record mode. When this
185 instruction has been completely annotated in the "arch list", it
186 will be appended to the main execution log. */
188 static struct record_entry record_first;
189 static struct record_entry *record_list = &record_first;
190 static struct record_entry *record_arch_list_head = NULL;
191 static struct record_entry *record_arch_list_tail = NULL;
193 /* 1 ask user. 0 auto delete the last struct record_entry. */
194 static int record_stop_at_limit = 1;
195 /* Maximum allowed number of insns in execution log. */
196 static unsigned int record_insn_max_num = DEFAULT_RECORD_INSN_MAX_NUM;
197 /* Actual count of insns presently in execution log. */
198 static int record_insn_num = 0;
199 /* Count of insns logged so far (may be larger
200 than count of insns presently in execution log). */
201 static ULONGEST record_insn_count;
203 /* The target_ops of process record. */
204 static struct target_ops record_ops;
205 static struct target_ops record_core_ops;
207 /* The beneath function pointers. */
208 static struct target_ops *record_beneath_to_resume_ops;
209 static void (*record_beneath_to_resume) (struct target_ops *, ptid_t, int,
211 static struct target_ops *record_beneath_to_wait_ops;
212 static ptid_t (*record_beneath_to_wait) (struct target_ops *, ptid_t,
213 struct target_waitstatus *,
215 static struct target_ops *record_beneath_to_store_registers_ops;
216 static void (*record_beneath_to_store_registers) (struct target_ops *,
219 static struct target_ops *record_beneath_to_xfer_partial_ops;
220 static LONGEST (*record_beneath_to_xfer_partial) (struct target_ops *ops,
221 enum target_object object,
224 const gdb_byte *writebuf,
227 static int (*record_beneath_to_insert_breakpoint) (struct gdbarch *,
228 struct bp_target_info *);
229 static int (*record_beneath_to_remove_breakpoint) (struct gdbarch *,
230 struct bp_target_info *);
231 static int (*record_beneath_to_stopped_by_watchpoint) (void);
232 static int (*record_beneath_to_stopped_data_address) (struct target_ops *,
235 /* Alloc and free functions for record_reg, record_mem, and record_end
238 /* Alloc a record_reg record entry. */
240 static inline struct record_entry *
241 record_reg_alloc (struct regcache *regcache, int regnum)
243 struct record_entry *rec;
244 struct gdbarch *gdbarch = get_regcache_arch (regcache);
246 rec = (struct record_entry *) xcalloc (1, sizeof (struct record_entry));
247 rec->type = record_reg;
248 rec->u.reg.num = regnum;
249 rec->u.reg.len = register_size (gdbarch, regnum);
250 if (rec->u.reg.len > sizeof (rec->u.reg.u.buf))
251 rec->u.reg.u.ptr = (gdb_byte *) xmalloc (rec->u.reg.len);
256 /* Free a record_reg record entry. */
259 record_reg_release (struct record_entry *rec)
261 gdb_assert (rec->type == record_reg);
262 if (rec->u.reg.len > sizeof (rec->u.reg.u.buf))
263 xfree (rec->u.reg.u.ptr);
267 /* Alloc a record_mem record entry. */
269 static inline struct record_entry *
270 record_mem_alloc (CORE_ADDR addr, int len)
272 struct record_entry *rec;
274 rec = (struct record_entry *) xcalloc (1, sizeof (struct record_entry));
275 rec->type = record_mem;
276 rec->u.mem.addr = addr;
277 rec->u.mem.len = len;
278 if (rec->u.mem.len > sizeof (rec->u.mem.u.buf))
279 rec->u.mem.u.ptr = (gdb_byte *) xmalloc (len);
284 /* Free a record_mem record entry. */
287 record_mem_release (struct record_entry *rec)
289 gdb_assert (rec->type == record_mem);
290 if (rec->u.mem.len > sizeof (rec->u.mem.u.buf))
291 xfree (rec->u.mem.u.ptr);
295 /* Alloc a record_end record entry. */
297 static inline struct record_entry *
298 record_end_alloc (void)
300 struct record_entry *rec;
302 rec = (struct record_entry *) xcalloc (1, sizeof (struct record_entry));
303 rec->type = record_end;
308 /* Free a record_end record entry. */
311 record_end_release (struct record_entry *rec)
316 /* Free one record entry, any type.
317 Return entry->type, in case caller wants to know. */
319 static inline enum record_type
320 record_entry_release (struct record_entry *rec)
322 enum record_type type = rec->type;
326 record_reg_release (rec);
329 record_mem_release (rec);
332 record_end_release (rec);
338 /* Free all record entries in list pointed to by REC. */
341 record_list_release (struct record_entry *rec)
352 record_entry_release (rec->next);
355 if (rec == &record_first)
358 record_first.next = NULL;
361 record_entry_release (rec);
364 /* Free all record entries forward of the given list position. */
367 record_list_release_following (struct record_entry *rec)
369 struct record_entry *tmp = rec->next;
375 if (record_entry_release (tmp) == record_end)
384 /* Delete the first instruction from the beginning of the log, to make
385 room for adding a new instruction at the end of the log.
387 Note -- this function does not modify record_insn_num. */
390 record_list_release_first (void)
392 struct record_entry *tmp;
394 if (!record_first.next)
397 /* Loop until a record_end. */
400 /* Cut record_first.next out of the linked list. */
401 tmp = record_first.next;
402 record_first.next = tmp->next;
403 tmp->next->prev = &record_first;
405 /* tmp is now isolated, and can be deleted. */
406 if (record_entry_release (tmp) == record_end)
407 break; /* End loop at first record_end. */
409 if (!record_first.next)
411 gdb_assert (record_insn_num == 1);
412 break; /* End loop when list is empty. */
417 /* Add a struct record_entry to record_arch_list. */
420 record_arch_list_add (struct record_entry *rec)
422 if (record_debug > 1)
423 fprintf_unfiltered (gdb_stdlog,
424 "Process record: record_arch_list_add %s.\n",
425 host_address_to_string (rec));
427 if (record_arch_list_tail)
429 record_arch_list_tail->next = rec;
430 rec->prev = record_arch_list_tail;
431 record_arch_list_tail = rec;
435 record_arch_list_head = rec;
436 record_arch_list_tail = rec;
440 /* Return the value storage location of a record entry. */
441 static inline gdb_byte *
442 record_get_loc (struct record_entry *rec)
446 if (rec->u.mem.len > sizeof (rec->u.mem.u.buf))
447 return rec->u.mem.u.ptr;
449 return rec->u.mem.u.buf;
451 if (rec->u.reg.len > sizeof (rec->u.reg.u.buf))
452 return rec->u.reg.u.ptr;
454 return rec->u.reg.u.buf;
457 gdb_assert_not_reached ("unexpected record_entry type");
462 /* Record the value of a register NUM to record_arch_list. */
465 record_arch_list_add_reg (struct regcache *regcache, int regnum)
467 struct record_entry *rec;
469 if (record_debug > 1)
470 fprintf_unfiltered (gdb_stdlog,
471 "Process record: add register num = %d to "
475 rec = record_reg_alloc (regcache, regnum);
477 regcache_raw_read (regcache, regnum, record_get_loc (rec));
479 record_arch_list_add (rec);
484 /* Record the value of a region of memory whose address is ADDR and
485 length is LEN to record_arch_list. */
488 record_arch_list_add_mem (CORE_ADDR addr, int len)
490 struct record_entry *rec;
492 if (record_debug > 1)
493 fprintf_unfiltered (gdb_stdlog,
494 "Process record: add mem addr = %s len = %d to "
496 paddress (target_gdbarch, addr), len);
498 if (!addr) /* FIXME: Why? Some arch must permit it... */
501 rec = record_mem_alloc (addr, len);
503 if (target_read_memory (addr, record_get_loc (rec), len))
506 fprintf_unfiltered (gdb_stdlog,
507 "Process record: error reading memory at "
508 "addr = %s len = %d.\n",
509 paddress (target_gdbarch, addr), len);
510 record_mem_release (rec);
514 record_arch_list_add (rec);
519 /* Add a record_end type struct record_entry to record_arch_list. */
522 record_arch_list_add_end (void)
524 struct record_entry *rec;
526 if (record_debug > 1)
527 fprintf_unfiltered (gdb_stdlog,
528 "Process record: add end to arch list.\n");
530 rec = record_end_alloc ();
531 rec->u.end.sigval = TARGET_SIGNAL_0;
532 rec->u.end.insn_num = ++record_insn_count;
534 record_arch_list_add (rec);
540 record_check_insn_num (int set_terminal)
542 if (record_insn_max_num)
544 gdb_assert (record_insn_num <= record_insn_max_num);
545 if (record_insn_num == record_insn_max_num)
547 /* Ask user what to do. */
548 if (record_stop_at_limit)
553 target_terminal_ours ();
554 q = yquery (_("Do you want to auto delete previous execution "
555 "log entries when record/replay buffer becomes "
556 "full (record stop-at-limit)?"));
558 target_terminal_inferior ();
560 record_stop_at_limit = 0;
562 error (_("Process record: stopped by user."));
569 record_arch_list_cleanups (void *ignore)
571 record_list_release (record_arch_list_tail);
574 /* Before inferior step (when GDB record the running message, inferior
575 only can step), GDB will call this function to record the values to
576 record_list. This function will call gdbarch_process_record to
577 record the running message of inferior and set them to
578 record_arch_list, and add it to record_list. */
581 record_message (struct regcache *regcache, enum target_signal signal)
584 struct gdbarch *gdbarch = get_regcache_arch (regcache);
585 struct cleanup *old_cleanups = make_cleanup (record_arch_list_cleanups, 0);
587 record_arch_list_head = NULL;
588 record_arch_list_tail = NULL;
590 /* Check record_insn_num. */
591 record_check_insn_num (1);
593 /* If gdb sends a signal value to target_resume,
594 save it in the 'end' field of the previous instruction.
596 Maybe process record should record what really happened,
597 rather than what gdb pretends has happened.
599 So if Linux delivered the signal to the child process during
600 the record mode, we will record it and deliver it again in
603 If user says "ignore this signal" during the record mode, then
604 it will be ignored again during the replay mode (no matter if
605 the user says something different, like "deliver this signal"
606 during the replay mode).
608 User should understand that nothing he does during the replay
609 mode will change the behavior of the child. If he tries,
610 then that is a user error.
612 But we should still deliver the signal to gdb during the replay,
613 if we delivered it during the recording. Therefore we should
614 record the signal during record_wait, not record_resume. */
615 if (record_list != &record_first) /* FIXME better way to check */
617 gdb_assert (record_list->type == record_end);
618 record_list->u.end.sigval = signal;
621 if (signal == TARGET_SIGNAL_0
622 || !gdbarch_process_record_signal_p (gdbarch))
623 ret = gdbarch_process_record (gdbarch,
625 regcache_read_pc (regcache));
627 ret = gdbarch_process_record_signal (gdbarch,
632 error (_("Process record: inferior program stopped."));
634 error (_("Process record: failed to record execution log."));
636 discard_cleanups (old_cleanups);
638 record_list->next = record_arch_list_head;
639 record_arch_list_head->prev = record_list;
640 record_list = record_arch_list_tail;
642 if (record_insn_num == record_insn_max_num && record_insn_max_num)
643 record_list_release_first ();
650 struct record_message_args {
651 struct regcache *regcache;
652 enum target_signal signal;
656 record_message_wrapper (void *args)
658 struct record_message_args *record_args = args;
660 return record_message (record_args->regcache, record_args->signal);
664 record_message_wrapper_safe (struct regcache *regcache,
665 enum target_signal signal)
667 struct record_message_args args;
669 args.regcache = regcache;
670 args.signal = signal;
672 return catch_errors (record_message_wrapper, &args, NULL, RETURN_MASK_ALL);
675 /* Set to 1 if record_store_registers and record_xfer_partial
676 doesn't need record. */
678 static int record_gdb_operation_disable = 0;
681 record_gdb_operation_disable_set (void)
683 struct cleanup *old_cleanups = NULL;
686 make_cleanup_restore_integer (&record_gdb_operation_disable);
687 record_gdb_operation_disable = 1;
692 /* Flag set to TRUE for target_stopped_by_watchpoint. */
693 static int record_hw_watchpoint = 0;
695 /* Execute one instruction from the record log. Each instruction in
696 the log will be represented by an arbitrary sequence of register
697 entries and memory entries, followed by an 'end' entry. */
700 record_exec_insn (struct regcache *regcache, struct gdbarch *gdbarch,
701 struct record_entry *entry)
705 case record_reg: /* reg */
707 gdb_byte reg[MAX_REGISTER_SIZE];
709 if (record_debug > 1)
710 fprintf_unfiltered (gdb_stdlog,
711 "Process record: record_reg %s to "
712 "inferior num = %d.\n",
713 host_address_to_string (entry),
716 regcache_cooked_read (regcache, entry->u.reg.num, reg);
717 regcache_cooked_write (regcache, entry->u.reg.num,
718 record_get_loc (entry));
719 memcpy (record_get_loc (entry), reg, entry->u.reg.len);
723 case record_mem: /* mem */
725 /* Nothing to do if the entry is flagged not_accessible. */
726 if (!entry->u.mem.mem_entry_not_accessible)
728 gdb_byte *mem = alloca (entry->u.mem.len);
730 if (record_debug > 1)
731 fprintf_unfiltered (gdb_stdlog,
732 "Process record: record_mem %s to "
733 "inferior addr = %s len = %d.\n",
734 host_address_to_string (entry),
735 paddress (gdbarch, entry->u.mem.addr),
738 if (target_read_memory (entry->u.mem.addr, mem, entry->u.mem.len))
740 entry->u.mem.mem_entry_not_accessible = 1;
742 warning ("Process record: error reading memory at "
743 "addr = %s len = %d.",
744 paddress (gdbarch, entry->u.mem.addr),
749 if (target_write_memory (entry->u.mem.addr,
750 record_get_loc (entry),
753 entry->u.mem.mem_entry_not_accessible = 1;
755 warning ("Process record: error writing memory at "
756 "addr = %s len = %d.",
757 paddress (gdbarch, entry->u.mem.addr),
762 memcpy (record_get_loc (entry), mem, entry->u.mem.len);
764 /* We've changed memory --- check if a hardware
765 watchpoint should trap. Note that this
766 presently assumes the target beneath supports
767 continuable watchpoints. On non-continuable
768 watchpoints target, we'll want to check this
769 _before_ actually doing the memory change, and
770 not doing the change at all if the watchpoint
772 if (hardware_watchpoint_inserted_in_range
773 (get_regcache_aspace (regcache),
774 entry->u.mem.addr, entry->u.mem.len))
775 record_hw_watchpoint = 1;
784 static struct target_ops *tmp_to_resume_ops;
785 static void (*tmp_to_resume) (struct target_ops *, ptid_t, int,
787 static struct target_ops *tmp_to_wait_ops;
788 static ptid_t (*tmp_to_wait) (struct target_ops *, ptid_t,
789 struct target_waitstatus *,
791 static struct target_ops *tmp_to_store_registers_ops;
792 static void (*tmp_to_store_registers) (struct target_ops *,
795 static struct target_ops *tmp_to_xfer_partial_ops;
796 static LONGEST (*tmp_to_xfer_partial) (struct target_ops *ops,
797 enum target_object object,
800 const gdb_byte *writebuf,
803 static int (*tmp_to_insert_breakpoint) (struct gdbarch *,
804 struct bp_target_info *);
805 static int (*tmp_to_remove_breakpoint) (struct gdbarch *,
806 struct bp_target_info *);
807 static int (*tmp_to_stopped_by_watchpoint) (void);
808 static int (*tmp_to_stopped_data_address) (struct target_ops *, CORE_ADDR *);
810 static void record_restore (void);
812 /* Open the process record target. */
815 record_core_open_1 (char *name, int from_tty)
817 struct regcache *regcache = get_current_regcache ();
818 int regnum = gdbarch_num_regs (get_regcache_arch (regcache));
821 /* Get record_core_regbuf. */
822 target_fetch_registers (regcache, -1);
823 record_core_regbuf = xmalloc (MAX_REGISTER_SIZE * regnum);
824 for (i = 0; i < regnum; i ++)
825 regcache_raw_collect (regcache, i,
826 record_core_regbuf + MAX_REGISTER_SIZE * i);
828 /* Get record_core_start and record_core_end. */
829 if (build_section_table (core_bfd, &record_core_start, &record_core_end))
831 xfree (record_core_regbuf);
832 record_core_regbuf = NULL;
833 error (_("\"%s\": Can't find sections: %s"),
834 bfd_get_filename (core_bfd), bfd_errmsg (bfd_get_error ()));
837 push_target (&record_core_ops);
841 /* "to_open" target method for 'live' processes. */
844 record_open_1 (char *name, int from_tty)
847 fprintf_unfiltered (gdb_stdlog, "Process record: record_open\n");
850 if (!target_has_execution)
851 error (_("Process record: the program is not being run."));
853 error (_("Process record target can't debug inferior in non-stop mode "
855 if (target_async_permitted)
856 error (_("Process record target can't debug inferior in asynchronous "
857 "mode (target-async)."));
859 if (!gdbarch_process_record_p (target_gdbarch))
860 error (_("Process record: the current architecture doesn't support "
861 "record function."));
864 error (_("Could not find 'to_resume' method on the target stack."));
866 error (_("Could not find 'to_wait' method on the target stack."));
867 if (!tmp_to_store_registers)
868 error (_("Could not find 'to_store_registers' "
869 "method on the target stack."));
870 if (!tmp_to_insert_breakpoint)
871 error (_("Could not find 'to_insert_breakpoint' "
872 "method on the target stack."));
873 if (!tmp_to_remove_breakpoint)
874 error (_("Could not find 'to_remove_breakpoint' "
875 "method on the target stack."));
876 if (!tmp_to_stopped_by_watchpoint)
877 error (_("Could not find 'to_stopped_by_watchpoint' "
878 "method on the target stack."));
879 if (!tmp_to_stopped_data_address)
880 error (_("Could not find 'to_stopped_data_address' "
881 "method on the target stack."));
883 push_target (&record_ops);
886 /* "to_open" target method. Open the process record target. */
889 record_open (char *name, int from_tty)
891 struct target_ops *t;
894 fprintf_unfiltered (gdb_stdlog, "Process record: record_open\n");
896 /* Check if record target is already running. */
897 if (current_target.to_stratum == record_stratum)
898 error (_("Process record target already running. Use \"record stop\" to "
899 "stop record target first."));
901 /* Reset the tmp beneath pointers. */
902 tmp_to_resume_ops = NULL;
903 tmp_to_resume = NULL;
904 tmp_to_wait_ops = NULL;
906 tmp_to_store_registers_ops = NULL;
907 tmp_to_store_registers = NULL;
908 tmp_to_xfer_partial_ops = NULL;
909 tmp_to_xfer_partial = NULL;
910 tmp_to_insert_breakpoint = NULL;
911 tmp_to_remove_breakpoint = NULL;
912 tmp_to_stopped_by_watchpoint = NULL;
913 tmp_to_stopped_data_address = NULL;
915 /* Set the beneath function pointers. */
916 for (t = current_target.beneath; t != NULL; t = t->beneath)
920 tmp_to_resume = t->to_resume;
921 tmp_to_resume_ops = t;
925 tmp_to_wait = t->to_wait;
928 if (!tmp_to_store_registers)
930 tmp_to_store_registers = t->to_store_registers;
931 tmp_to_store_registers_ops = t;
933 if (!tmp_to_xfer_partial)
935 tmp_to_xfer_partial = t->to_xfer_partial;
936 tmp_to_xfer_partial_ops = t;
938 if (!tmp_to_insert_breakpoint)
939 tmp_to_insert_breakpoint = t->to_insert_breakpoint;
940 if (!tmp_to_remove_breakpoint)
941 tmp_to_remove_breakpoint = t->to_remove_breakpoint;
942 if (!tmp_to_stopped_by_watchpoint)
943 tmp_to_stopped_by_watchpoint = t->to_stopped_by_watchpoint;
944 if (!tmp_to_stopped_data_address)
945 tmp_to_stopped_data_address = t->to_stopped_data_address;
947 if (!tmp_to_xfer_partial)
948 error (_("Could not find 'to_xfer_partial' method on the target stack."));
952 record_insn_count = 0;
953 record_list = &record_first;
954 record_list->next = NULL;
956 /* Set the tmp beneath pointers to beneath pointers. */
957 record_beneath_to_resume_ops = tmp_to_resume_ops;
958 record_beneath_to_resume = tmp_to_resume;
959 record_beneath_to_wait_ops = tmp_to_wait_ops;
960 record_beneath_to_wait = tmp_to_wait;
961 record_beneath_to_store_registers_ops = tmp_to_store_registers_ops;
962 record_beneath_to_store_registers = tmp_to_store_registers;
963 record_beneath_to_xfer_partial_ops = tmp_to_xfer_partial_ops;
964 record_beneath_to_xfer_partial = tmp_to_xfer_partial;
965 record_beneath_to_insert_breakpoint = tmp_to_insert_breakpoint;
966 record_beneath_to_remove_breakpoint = tmp_to_remove_breakpoint;
967 record_beneath_to_stopped_by_watchpoint = tmp_to_stopped_by_watchpoint;
968 record_beneath_to_stopped_data_address = tmp_to_stopped_data_address;
971 record_core_open_1 (name, from_tty);
973 record_open_1 (name, from_tty);
976 /* "to_close" target method. Close the process record target. */
979 record_close (int quitting)
981 struct record_core_buf_entry *entry;
984 fprintf_unfiltered (gdb_stdlog, "Process record: record_close\n");
986 record_list_release (record_list);
988 /* Release record_core_regbuf. */
989 if (record_core_regbuf)
991 xfree (record_core_regbuf);
992 record_core_regbuf = NULL;
995 /* Release record_core_buf_list. */
996 if (record_core_buf_list)
998 for (entry = record_core_buf_list->prev; entry; entry = entry->prev)
1000 xfree (record_core_buf_list);
1001 record_core_buf_list = entry;
1003 record_core_buf_list = NULL;
1007 static int record_resume_step = 0;
1009 /* "to_resume" target method. Resume the process record target. */
1012 record_resume (struct target_ops *ops, ptid_t ptid, int step,
1013 enum target_signal signal)
1015 record_resume_step = step;
1017 if (!RECORD_IS_REPLAY)
1019 struct gdbarch *gdbarch = target_thread_architecture (ptid);
1021 record_message (get_current_regcache (), signal);
1025 /* This is not hard single step. */
1026 if (!gdbarch_software_single_step_p (gdbarch))
1028 /* This is a normal continue. */
1033 /* This arch support soft sigle step. */
1034 if (single_step_breakpoints_inserted ())
1036 /* This is a soft single step. */
1037 record_resume_step = 1;
1041 /* This is a continue.
1042 Try to insert a soft single step breakpoint. */
1043 if (!gdbarch_software_single_step (gdbarch,
1044 get_current_frame ()))
1046 /* This system don't want use soft single step.
1047 Use hard sigle step. */
1054 record_beneath_to_resume (record_beneath_to_resume_ops,
1055 ptid, step, signal);
1059 static int record_get_sig = 0;
1061 /* SIGINT signal handler, registered by "to_wait" method. */
1064 record_sig_handler (int signo)
1067 fprintf_unfiltered (gdb_stdlog, "Process record: get a signal\n");
1069 /* It will break the running inferior in replay mode. */
1070 record_resume_step = 1;
1072 /* It will let record_wait set inferior status to get the signal
1078 record_wait_cleanups (void *ignore)
1080 if (execution_direction == EXEC_REVERSE)
1082 if (record_list->next)
1083 record_list = record_list->next;
1086 record_list = record_list->prev;
1089 /* "to_wait" target method for process record target.
1091 In record mode, the target is always run in singlestep mode
1092 (even when gdb says to continue). The to_wait method intercepts
1093 the stop events and determines which ones are to be passed on to
1094 gdb. Most stop events are just singlestep events that gdb is not
1095 to know about, so the to_wait method just records them and keeps
1098 In replay mode, this function emulates the recorded execution log,
1099 one instruction at a time (forward or backward), and determines
1103 record_wait (struct target_ops *ops,
1104 ptid_t ptid, struct target_waitstatus *status,
1107 struct cleanup *set_cleanups = record_gdb_operation_disable_set ();
1110 fprintf_unfiltered (gdb_stdlog,
1111 "Process record: record_wait "
1112 "record_resume_step = %d\n",
1113 record_resume_step);
1116 signal (SIGINT, record_sig_handler);
1118 if (!RECORD_IS_REPLAY && ops != &record_core_ops)
1120 if (record_resume_step)
1122 /* This is a single step. */
1123 return record_beneath_to_wait (record_beneath_to_wait_ops,
1124 ptid, status, options);
1128 /* This is not a single step. */
1131 struct gdbarch *gdbarch = target_thread_architecture (inferior_ptid);
1135 ret = record_beneath_to_wait (record_beneath_to_wait_ops,
1136 ptid, status, options);
1138 if (single_step_breakpoints_inserted ())
1139 remove_single_step_breakpoints ();
1141 if (record_resume_step)
1144 /* Is this a SIGTRAP? */
1145 if (status->kind == TARGET_WAITKIND_STOPPED
1146 && status->value.sig == TARGET_SIGNAL_TRAP)
1148 struct regcache *regcache;
1149 struct address_space *aspace;
1151 /* Yes -- this is likely our single-step finishing,
1152 but check if there's any reason the core would be
1153 interested in the event. */
1155 registers_changed ();
1156 regcache = get_current_regcache ();
1157 tmp_pc = regcache_read_pc (regcache);
1158 aspace = get_regcache_aspace (regcache);
1160 if (target_stopped_by_watchpoint ())
1162 /* Always interested in watchpoints. */
1164 else if (breakpoint_inserted_here_p (aspace, tmp_pc))
1166 /* There is a breakpoint here. Let the core
1168 if (software_breakpoint_inserted_here_p (aspace, tmp_pc))
1170 struct gdbarch *gdbarch
1171 = get_regcache_arch (regcache);
1172 CORE_ADDR decr_pc_after_break
1173 = gdbarch_decr_pc_after_break (gdbarch);
1174 if (decr_pc_after_break)
1175 regcache_write_pc (regcache,
1176 tmp_pc + decr_pc_after_break);
1181 /* This is a single-step trap. Record the
1182 insn and issue another step.
1183 FIXME: this part can be a random SIGTRAP too.
1184 But GDB cannot handle it. */
1187 if (!record_message_wrapper_safe (regcache,
1190 status->kind = TARGET_WAITKIND_STOPPED;
1191 status->value.sig = TARGET_SIGNAL_0;
1195 if (gdbarch_software_single_step_p (gdbarch))
1197 /* Try to insert the software single step breakpoint.
1198 If insert success, set step to 0. */
1199 set_executing (inferior_ptid, 0);
1200 reinit_frame_cache ();
1201 if (gdbarch_software_single_step (gdbarch,
1202 get_current_frame ()))
1204 set_executing (inferior_ptid, 1);
1207 record_beneath_to_resume (record_beneath_to_resume_ops,
1214 /* The inferior is broken by a breakpoint or a signal. */
1223 struct regcache *regcache = get_current_regcache ();
1224 struct gdbarch *gdbarch = get_regcache_arch (regcache);
1225 struct address_space *aspace = get_regcache_aspace (regcache);
1226 int continue_flag = 1;
1227 int first_record_end = 1;
1228 struct cleanup *old_cleanups = make_cleanup (record_wait_cleanups, 0);
1231 record_hw_watchpoint = 0;
1232 status->kind = TARGET_WAITKIND_STOPPED;
1234 /* Check breakpoint when forward execute. */
1235 if (execution_direction == EXEC_FORWARD)
1237 tmp_pc = regcache_read_pc (regcache);
1238 if (breakpoint_inserted_here_p (aspace, tmp_pc))
1240 int decr_pc_after_break = gdbarch_decr_pc_after_break (gdbarch);
1243 fprintf_unfiltered (gdb_stdlog,
1244 "Process record: break at %s.\n",
1245 paddress (gdbarch, tmp_pc));
1247 if (decr_pc_after_break
1248 && !record_resume_step
1249 && software_breakpoint_inserted_here_p (aspace, tmp_pc))
1250 regcache_write_pc (regcache,
1251 tmp_pc + decr_pc_after_break);
1256 /* If GDB is in terminal_inferior mode, it will not get the signal.
1257 And in GDB replay mode, GDB doesn't need to be in terminal_inferior
1258 mode, because inferior will not executed.
1259 Then set it to terminal_ours to make GDB get the signal. */
1260 target_terminal_ours ();
1262 /* In EXEC_FORWARD mode, record_list points to the tail of prev
1264 if (execution_direction == EXEC_FORWARD && record_list->next)
1265 record_list = record_list->next;
1267 /* Loop over the record_list, looking for the next place to
1271 /* Check for beginning and end of log. */
1272 if (execution_direction == EXEC_REVERSE
1273 && record_list == &record_first)
1275 /* Hit beginning of record log in reverse. */
1276 status->kind = TARGET_WAITKIND_NO_HISTORY;
1279 if (execution_direction != EXEC_REVERSE && !record_list->next)
1281 /* Hit end of record log going forward. */
1282 status->kind = TARGET_WAITKIND_NO_HISTORY;
1286 record_exec_insn (regcache, gdbarch, record_list);
1288 if (record_list->type == record_end)
1290 if (record_debug > 1)
1291 fprintf_unfiltered (gdb_stdlog,
1292 "Process record: record_end %s to "
1294 host_address_to_string (record_list));
1296 if (first_record_end && execution_direction == EXEC_REVERSE)
1298 /* When reverse excute, the first record_end is the part of
1299 current instruction. */
1300 first_record_end = 0;
1304 /* In EXEC_REVERSE mode, this is the record_end of prev
1306 In EXEC_FORWARD mode, this is the record_end of current
1309 if (record_resume_step)
1311 if (record_debug > 1)
1312 fprintf_unfiltered (gdb_stdlog,
1313 "Process record: step.\n");
1317 /* check breakpoint */
1318 tmp_pc = regcache_read_pc (regcache);
1319 if (breakpoint_inserted_here_p (aspace, tmp_pc))
1321 int decr_pc_after_break
1322 = gdbarch_decr_pc_after_break (gdbarch);
1325 fprintf_unfiltered (gdb_stdlog,
1326 "Process record: break "
1328 paddress (gdbarch, tmp_pc));
1329 if (decr_pc_after_break
1330 && execution_direction == EXEC_FORWARD
1331 && !record_resume_step
1332 && software_breakpoint_inserted_here_p (aspace,
1334 regcache_write_pc (regcache,
1335 tmp_pc + decr_pc_after_break);
1339 if (record_hw_watchpoint)
1342 fprintf_unfiltered (gdb_stdlog,
1343 "Process record: hit hw "
1347 /* Check target signal */
1348 if (record_list->u.end.sigval != TARGET_SIGNAL_0)
1349 /* FIXME: better way to check */
1356 if (execution_direction == EXEC_REVERSE)
1358 if (record_list->prev)
1359 record_list = record_list->prev;
1363 if (record_list->next)
1364 record_list = record_list->next;
1368 while (continue_flag);
1372 status->value.sig = TARGET_SIGNAL_INT;
1373 else if (record_list->u.end.sigval != TARGET_SIGNAL_0)
1374 /* FIXME: better way to check */
1375 status->value.sig = record_list->u.end.sigval;
1377 status->value.sig = TARGET_SIGNAL_TRAP;
1379 discard_cleanups (old_cleanups);
1382 signal (SIGINT, handle_sigint);
1384 do_cleanups (set_cleanups);
1385 return inferior_ptid;
1389 record_stopped_by_watchpoint (void)
1391 if (RECORD_IS_REPLAY)
1392 return record_hw_watchpoint;
1394 return record_beneath_to_stopped_by_watchpoint ();
1398 record_stopped_data_address (struct target_ops *ops, CORE_ADDR *addr_p)
1400 if (RECORD_IS_REPLAY)
1403 return record_beneath_to_stopped_data_address (ops, addr_p);
1406 /* "to_disconnect" method for process record target. */
1409 record_disconnect (struct target_ops *target, char *args, int from_tty)
1412 fprintf_unfiltered (gdb_stdlog, "Process record: record_disconnect\n");
1414 unpush_target (&record_ops);
1415 target_disconnect (args, from_tty);
1418 /* "to_detach" method for process record target. */
1421 record_detach (struct target_ops *ops, char *args, int from_tty)
1424 fprintf_unfiltered (gdb_stdlog, "Process record: record_detach\n");
1426 unpush_target (&record_ops);
1427 target_detach (args, from_tty);
1430 /* "to_mourn_inferior" method for process record target. */
1433 record_mourn_inferior (struct target_ops *ops)
1436 fprintf_unfiltered (gdb_stdlog, "Process record: "
1437 "record_mourn_inferior\n");
1439 unpush_target (&record_ops);
1440 target_mourn_inferior ();
1443 /* Close process record target before killing the inferior process. */
1446 record_kill (struct target_ops *ops)
1449 fprintf_unfiltered (gdb_stdlog, "Process record: record_kill\n");
1451 unpush_target (&record_ops);
1455 /* Record registers change (by user or by GDB) to list as an instruction. */
1458 record_registers_change (struct regcache *regcache, int regnum)
1460 /* Check record_insn_num. */
1461 record_check_insn_num (0);
1463 record_arch_list_head = NULL;
1464 record_arch_list_tail = NULL;
1470 for (i = 0; i < gdbarch_num_regs (get_regcache_arch (regcache)); i++)
1472 if (record_arch_list_add_reg (regcache, i))
1474 record_list_release (record_arch_list_tail);
1475 error (_("Process record: failed to record execution log."));
1481 if (record_arch_list_add_reg (regcache, regnum))
1483 record_list_release (record_arch_list_tail);
1484 error (_("Process record: failed to record execution log."));
1487 if (record_arch_list_add_end ())
1489 record_list_release (record_arch_list_tail);
1490 error (_("Process record: failed to record execution log."));
1492 record_list->next = record_arch_list_head;
1493 record_arch_list_head->prev = record_list;
1494 record_list = record_arch_list_tail;
1496 if (record_insn_num == record_insn_max_num && record_insn_max_num)
1497 record_list_release_first ();
1502 /* "to_store_registers" method for process record target. */
1505 record_store_registers (struct target_ops *ops, struct regcache *regcache,
1508 if (!record_gdb_operation_disable)
1510 if (RECORD_IS_REPLAY)
1514 /* Let user choose if he wants to write register or not. */
1517 query (_("Because GDB is in replay mode, changing the "
1518 "value of a register will make the execution "
1519 "log unusable from this point onward. "
1520 "Change all registers?"));
1523 query (_("Because GDB is in replay mode, changing the value "
1524 "of a register will make the execution log unusable "
1525 "from this point onward. Change register %s?"),
1526 gdbarch_register_name (get_regcache_arch (regcache),
1531 /* Invalidate the value of regcache that was set in function
1532 "regcache_raw_write". */
1538 i < gdbarch_num_regs (get_regcache_arch (regcache));
1540 regcache_invalidate (regcache, i);
1543 regcache_invalidate (regcache, regno);
1545 error (_("Process record canceled the operation."));
1548 /* Destroy the record from here forward. */
1549 record_list_release_following (record_list);
1552 record_registers_change (regcache, regno);
1554 record_beneath_to_store_registers (record_beneath_to_store_registers_ops,
1558 /* "to_xfer_partial" method. Behavior is conditional on RECORD_IS_REPLAY.
1559 In replay mode, we cannot write memory unles we are willing to
1560 invalidate the record/replay log from this point forward. */
1563 record_xfer_partial (struct target_ops *ops, enum target_object object,
1564 const char *annex, gdb_byte *readbuf,
1565 const gdb_byte *writebuf, ULONGEST offset, LONGEST len)
1567 if (!record_gdb_operation_disable
1568 && (object == TARGET_OBJECT_MEMORY
1569 || object == TARGET_OBJECT_RAW_MEMORY) && writebuf)
1571 if (RECORD_IS_REPLAY)
1573 /* Let user choose if he wants to write memory or not. */
1574 if (!query (_("Because GDB is in replay mode, writing to memory "
1575 "will make the execution log unusable from this "
1576 "point onward. Write memory at address %s?"),
1577 paddress (target_gdbarch, offset)))
1578 error (_("Process record canceled the operation."));
1580 /* Destroy the record from here forward. */
1581 record_list_release_following (record_list);
1584 /* Check record_insn_num */
1585 record_check_insn_num (0);
1587 /* Record registers change to list as an instruction. */
1588 record_arch_list_head = NULL;
1589 record_arch_list_tail = NULL;
1590 if (record_arch_list_add_mem (offset, len))
1592 record_list_release (record_arch_list_tail);
1594 fprintf_unfiltered (gdb_stdlog,
1595 "Process record: failed to record "
1599 if (record_arch_list_add_end ())
1601 record_list_release (record_arch_list_tail);
1603 fprintf_unfiltered (gdb_stdlog,
1604 "Process record: failed to record "
1608 record_list->next = record_arch_list_head;
1609 record_arch_list_head->prev = record_list;
1610 record_list = record_arch_list_tail;
1612 if (record_insn_num == record_insn_max_num && record_insn_max_num)
1613 record_list_release_first ();
1618 return record_beneath_to_xfer_partial (record_beneath_to_xfer_partial_ops,
1619 object, annex, readbuf, writebuf,
1623 /* Behavior is conditional on RECORD_IS_REPLAY.
1624 We will not actually insert or remove breakpoints when replaying,
1625 nor when recording. */
1628 record_insert_breakpoint (struct gdbarch *gdbarch,
1629 struct bp_target_info *bp_tgt)
1631 if (!RECORD_IS_REPLAY)
1633 struct cleanup *old_cleanups = record_gdb_operation_disable_set ();
1634 int ret = record_beneath_to_insert_breakpoint (gdbarch, bp_tgt);
1636 do_cleanups (old_cleanups);
1644 /* "to_remove_breakpoint" method for process record target. */
1647 record_remove_breakpoint (struct gdbarch *gdbarch,
1648 struct bp_target_info *bp_tgt)
1650 if (!RECORD_IS_REPLAY)
1652 struct cleanup *old_cleanups = record_gdb_operation_disable_set ();
1653 int ret = record_beneath_to_remove_breakpoint (gdbarch, bp_tgt);
1655 do_cleanups (old_cleanups);
1663 /* "to_can_execute_reverse" method for process record target. */
1666 record_can_execute_reverse (void)
1671 /* "to_get_bookmark" method for process record and prec over core. */
1674 record_get_bookmark (char *args, int from_tty)
1676 gdb_byte *ret = NULL;
1678 /* Return stringified form of instruction count. */
1679 if (record_list && record_list->type == record_end)
1680 ret = xstrdup (pulongest (record_list->u.end.insn_num));
1685 fprintf_unfiltered (gdb_stdlog,
1686 "record_get_bookmark returns %s\n", ret);
1688 fprintf_unfiltered (gdb_stdlog,
1689 "record_get_bookmark returns NULL\n");
1694 /* The implementation of the command "record goto". */
1695 static void cmd_record_goto (char *, int);
1697 /* "to_goto_bookmark" method for process record and prec over core. */
1700 record_goto_bookmark (gdb_byte *bookmark, int from_tty)
1703 fprintf_unfiltered (gdb_stdlog,
1704 "record_goto_bookmark receives %s\n", bookmark);
1706 if (bookmark[0] == '\'' || bookmark[0] == '\"')
1708 if (bookmark[strlen (bookmark) - 1] != bookmark[0])
1709 error (_("Unbalanced quotes: %s"), bookmark);
1711 /* Strip trailing quote. */
1712 bookmark[strlen (bookmark) - 1] = '\0';
1713 /* Strip leading quote. */
1715 /* Pass along to cmd_record_goto. */
1718 cmd_record_goto ((char *) bookmark, from_tty);
1723 init_record_ops (void)
1725 record_ops.to_shortname = "record";
1726 record_ops.to_longname = "Process record and replay target";
1728 "Log program while executing and replay execution from log.";
1729 record_ops.to_open = record_open;
1730 record_ops.to_close = record_close;
1731 record_ops.to_resume = record_resume;
1732 record_ops.to_wait = record_wait;
1733 record_ops.to_disconnect = record_disconnect;
1734 record_ops.to_detach = record_detach;
1735 record_ops.to_mourn_inferior = record_mourn_inferior;
1736 record_ops.to_kill = record_kill;
1737 record_ops.to_create_inferior = find_default_create_inferior;
1738 record_ops.to_store_registers = record_store_registers;
1739 record_ops.to_xfer_partial = record_xfer_partial;
1740 record_ops.to_insert_breakpoint = record_insert_breakpoint;
1741 record_ops.to_remove_breakpoint = record_remove_breakpoint;
1742 record_ops.to_stopped_by_watchpoint = record_stopped_by_watchpoint;
1743 record_ops.to_stopped_data_address = record_stopped_data_address;
1744 record_ops.to_can_execute_reverse = record_can_execute_reverse;
1745 record_ops.to_stratum = record_stratum;
1746 /* Add bookmark target methods. */
1747 record_ops.to_get_bookmark = record_get_bookmark;
1748 record_ops.to_goto_bookmark = record_goto_bookmark;
1749 record_ops.to_magic = OPS_MAGIC;
1752 /* "to_resume" method for prec over corefile. */
1755 record_core_resume (struct target_ops *ops, ptid_t ptid, int step,
1756 enum target_signal signal)
1758 record_resume_step = step;
1761 /* "to_kill" method for prec over corefile. */
1764 record_core_kill (struct target_ops *ops)
1767 fprintf_unfiltered (gdb_stdlog, "Process record: record_core_kill\n");
1769 unpush_target (&record_core_ops);
1772 /* "to_fetch_registers" method for prec over corefile. */
1775 record_core_fetch_registers (struct target_ops *ops,
1776 struct regcache *regcache,
1781 int num = gdbarch_num_regs (get_regcache_arch (regcache));
1784 for (i = 0; i < num; i ++)
1785 regcache_raw_supply (regcache, i,
1786 record_core_regbuf + MAX_REGISTER_SIZE * i);
1789 regcache_raw_supply (regcache, regno,
1790 record_core_regbuf + MAX_REGISTER_SIZE * regno);
1793 /* "to_prepare_to_store" method for prec over corefile. */
1796 record_core_prepare_to_store (struct regcache *regcache)
1800 /* "to_store_registers" method for prec over corefile. */
1803 record_core_store_registers (struct target_ops *ops,
1804 struct regcache *regcache,
1807 if (record_gdb_operation_disable)
1808 regcache_raw_collect (regcache, regno,
1809 record_core_regbuf + MAX_REGISTER_SIZE * regno);
1811 error (_("You can't do that without a process to debug."));
1814 /* "to_xfer_partial" method for prec over corefile. */
1817 record_core_xfer_partial (struct target_ops *ops, enum target_object object,
1818 const char *annex, gdb_byte *readbuf,
1819 const gdb_byte *writebuf, ULONGEST offset,
1822 if (object == TARGET_OBJECT_MEMORY)
1824 if (record_gdb_operation_disable || !writebuf)
1826 struct target_section *p;
1828 for (p = record_core_start; p < record_core_end; p++)
1830 if (offset >= p->addr)
1832 struct record_core_buf_entry *entry;
1833 ULONGEST sec_offset;
1835 if (offset >= p->endaddr)
1838 if (offset + len > p->endaddr)
1839 len = p->endaddr - offset;
1841 sec_offset = offset - p->addr;
1843 /* Read readbuf or write writebuf p, offset, len. */
1845 if (p->the_bfd_section->flags & SEC_CONSTRUCTOR
1846 || (p->the_bfd_section->flags & SEC_HAS_CONTENTS) == 0)
1849 memset (readbuf, 0, len);
1852 /* Get record_core_buf_entry. */
1853 for (entry = record_core_buf_list; entry;
1854 entry = entry->prev)
1861 /* Add a new entry. */
1862 entry = (struct record_core_buf_entry *)
1863 xmalloc (sizeof (struct record_core_buf_entry));
1865 if (!bfd_malloc_and_get_section (p->bfd,
1872 entry->prev = record_core_buf_list;
1873 record_core_buf_list = entry;
1876 memcpy (entry->buf + sec_offset, writebuf,
1882 return record_beneath_to_xfer_partial
1883 (record_beneath_to_xfer_partial_ops,
1884 object, annex, readbuf, writebuf,
1887 memcpy (readbuf, entry->buf + sec_offset,
1898 error (_("You can't do that without a process to debug."));
1901 return record_beneath_to_xfer_partial (record_beneath_to_xfer_partial_ops,
1902 object, annex, readbuf, writebuf,
1906 /* "to_insert_breakpoint" method for prec over corefile. */
1909 record_core_insert_breakpoint (struct gdbarch *gdbarch,
1910 struct bp_target_info *bp_tgt)
1915 /* "to_remove_breakpoint" method for prec over corefile. */
1918 record_core_remove_breakpoint (struct gdbarch *gdbarch,
1919 struct bp_target_info *bp_tgt)
1924 /* "to_has_execution" method for prec over corefile. */
1927 record_core_has_execution (struct target_ops *ops, ptid_t the_ptid)
1933 init_record_core_ops (void)
1935 record_core_ops.to_shortname = "record-core";
1936 record_core_ops.to_longname = "Process record and replay target";
1937 record_core_ops.to_doc =
1938 "Log program while executing and replay execution from log.";
1939 record_core_ops.to_open = record_open;
1940 record_core_ops.to_close = record_close;
1941 record_core_ops.to_resume = record_core_resume;
1942 record_core_ops.to_wait = record_wait;
1943 record_core_ops.to_kill = record_core_kill;
1944 record_core_ops.to_fetch_registers = record_core_fetch_registers;
1945 record_core_ops.to_prepare_to_store = record_core_prepare_to_store;
1946 record_core_ops.to_store_registers = record_core_store_registers;
1947 record_core_ops.to_xfer_partial = record_core_xfer_partial;
1948 record_core_ops.to_insert_breakpoint = record_core_insert_breakpoint;
1949 record_core_ops.to_remove_breakpoint = record_core_remove_breakpoint;
1950 record_core_ops.to_stopped_by_watchpoint = record_stopped_by_watchpoint;
1951 record_core_ops.to_stopped_data_address = record_stopped_data_address;
1952 record_core_ops.to_can_execute_reverse = record_can_execute_reverse;
1953 record_core_ops.to_has_execution = record_core_has_execution;
1954 record_core_ops.to_stratum = record_stratum;
1955 /* Add bookmark target methods. */
1956 record_core_ops.to_get_bookmark = record_get_bookmark;
1957 record_core_ops.to_goto_bookmark = record_goto_bookmark;
1958 record_core_ops.to_magic = OPS_MAGIC;
1961 /* Implement "show record debug" command. */
1964 show_record_debug (struct ui_file *file, int from_tty,
1965 struct cmd_list_element *c, const char *value)
1967 fprintf_filtered (file, _("Debugging of process record target is %s.\n"),
1971 /* Alias for "target record". */
1974 cmd_record_start (char *args, int from_tty)
1976 execute_command ("target record", from_tty);
1979 /* Truncate the record log from the present point
1980 of replay until the end. */
1983 cmd_record_delete (char *args, int from_tty)
1985 if (current_target.to_stratum == record_stratum)
1987 if (RECORD_IS_REPLAY)
1989 if (!from_tty || query (_("Delete the log from this point forward "
1990 "and begin to record the running message "
1992 record_list_release_following (record_list);
1995 printf_unfiltered (_("Already at end of record list.\n"));
1999 printf_unfiltered (_("Process record is not started.\n"));
2002 /* Implement the "stoprecord" or "record stop" command. */
2005 cmd_record_stop (char *args, int from_tty)
2007 if (current_target.to_stratum == record_stratum)
2009 unpush_target (&record_ops);
2010 printf_unfiltered (_("Process record is stopped and all execution "
2011 "logs are deleted.\n"));
2014 printf_unfiltered (_("Process record is not started.\n"));
2017 /* Set upper limit of record log size. */
2020 set_record_insn_max_num (char *args, int from_tty, struct cmd_list_element *c)
2022 if (record_insn_num > record_insn_max_num && record_insn_max_num)
2024 /* Count down record_insn_num while releasing records from list. */
2025 while (record_insn_num > record_insn_max_num)
2027 record_list_release_first ();
2033 static struct cmd_list_element *record_cmdlist, *set_record_cmdlist,
2034 *show_record_cmdlist, *info_record_cmdlist;
2037 set_record_command (char *args, int from_tty)
2039 printf_unfiltered (_("\"set record\" must be followed "
2040 "by an apporpriate subcommand.\n"));
2041 help_list (set_record_cmdlist, "set record ", all_commands, gdb_stdout);
2045 show_record_command (char *args, int from_tty)
2047 cmd_show_list (show_record_cmdlist, from_tty, "");
2050 /* Display some statistics about the execution log. */
2053 info_record_command (char *args, int from_tty)
2055 struct record_entry *p;
2057 if (current_target.to_stratum == record_stratum)
2059 if (RECORD_IS_REPLAY)
2060 printf_filtered (_("Replay mode:\n"));
2062 printf_filtered (_("Record mode:\n"));
2064 /* Find entry for first actual instruction in the log. */
2065 for (p = record_first.next;
2066 p != NULL && p->type != record_end;
2070 /* Do we have a log at all? */
2071 if (p != NULL && p->type == record_end)
2073 /* Display instruction number for first instruction in the log. */
2074 printf_filtered (_("Lowest recorded instruction number is %s.\n"),
2075 pulongest (p->u.end.insn_num));
2077 /* If in replay mode, display where we are in the log. */
2078 if (RECORD_IS_REPLAY)
2079 printf_filtered (_("Current instruction number is %s.\n"),
2080 pulongest (record_list->u.end.insn_num));
2082 /* Display instruction number for last instruction in the log. */
2083 printf_filtered (_("Highest recorded instruction number is %s.\n"),
2084 pulongest (record_insn_count));
2086 /* Display log count. */
2087 printf_filtered (_("Log contains %d instructions.\n"),
2092 printf_filtered (_("No instructions have been logged.\n"));
2097 printf_filtered (_("target record is not active.\n"));
2100 /* Display max log size. */
2101 printf_filtered (_("Max logged instructions is %d.\n"),
2102 record_insn_max_num);
2105 /* Record log save-file format
2106 Version 1 (never released)
2109 4 bytes: magic number htonl(0x20090829).
2110 NOTE: be sure to change whenever this file format changes!
2114 1 byte: record type (record_end, see enum record_type).
2116 1 byte: record type (record_reg, see enum record_type).
2117 8 bytes: register id (network byte order).
2118 MAX_REGISTER_SIZE bytes: register value.
2120 1 byte: record type (record_mem, see enum record_type).
2121 8 bytes: memory length (network byte order).
2122 8 bytes: memory address (network byte order).
2123 n bytes: memory value (n == memory length).
2126 4 bytes: magic number netorder32(0x20091016).
2127 NOTE: be sure to change whenever this file format changes!
2131 1 byte: record type (record_end, see enum record_type).
2133 4 bytes: instruction count
2135 1 byte: record type (record_reg, see enum record_type).
2136 4 bytes: register id (network byte order).
2137 n bytes: register value (n == actual register size).
2138 (eg. 4 bytes for x86 general registers).
2140 1 byte: record type (record_mem, see enum record_type).
2141 4 bytes: memory length (network byte order).
2142 8 bytes: memory address (network byte order).
2143 n bytes: memory value (n == memory length).
2147 /* bfdcore_read -- read bytes from a core file section. */
2150 bfdcore_read (bfd *obfd, asection *osec, void *buf, int len, int *offset)
2152 int ret = bfd_get_section_contents (obfd, osec, buf, *offset, len);
2157 error (_("Failed to read %d bytes from core file %s ('%s').\n"),
2158 len, bfd_get_filename (obfd),
2159 bfd_errmsg (bfd_get_error ()));
2162 static inline uint64_t
2163 netorder64 (uint64_t input)
2167 store_unsigned_integer ((gdb_byte *) &ret, sizeof (ret),
2168 BFD_ENDIAN_BIG, input);
2172 static inline uint32_t
2173 netorder32 (uint32_t input)
2177 store_unsigned_integer ((gdb_byte *) &ret, sizeof (ret),
2178 BFD_ENDIAN_BIG, input);
2182 static inline uint16_t
2183 netorder16 (uint16_t input)
2187 store_unsigned_integer ((gdb_byte *) &ret, sizeof (ret),
2188 BFD_ENDIAN_BIG, input);
2192 /* Restore the execution log from a core_bfd file. */
2194 record_restore (void)
2197 struct cleanup *old_cleanups;
2198 struct record_entry *rec;
2202 struct regcache *regcache;
2204 /* We restore the execution log from the open core bfd,
2206 if (core_bfd == NULL)
2209 /* "record_restore" can only be called when record list is empty. */
2210 gdb_assert (record_first.next == NULL);
2213 fprintf_unfiltered (gdb_stdlog, "Restoring recording from core file.\n");
2215 /* Now need to find our special note section. */
2216 osec = bfd_get_section_by_name (core_bfd, "null0");
2218 fprintf_unfiltered (gdb_stdlog, "Find precord section %s.\n",
2219 osec ? "succeeded" : "failed");
2222 osec_size = bfd_section_size (core_bfd, osec);
2224 fprintf_unfiltered (gdb_stdlog, "%s", bfd_section_name (core_bfd, osec));
2226 /* Check the magic code. */
2227 bfdcore_read (core_bfd, osec, &magic, sizeof (magic), &bfd_offset);
2228 if (magic != RECORD_FILE_MAGIC)
2229 error (_("Version mis-match or file format error in core file %s."),
2230 bfd_get_filename (core_bfd));
2232 fprintf_unfiltered (gdb_stdlog,
2233 " Reading 4-byte magic cookie "
2234 "RECORD_FILE_MAGIC (0x%s)\n",
2235 phex_nz (netorder32 (magic), 4));
2237 /* Restore the entries in recfd into record_arch_list_head and
2238 record_arch_list_tail. */
2239 record_arch_list_head = NULL;
2240 record_arch_list_tail = NULL;
2241 record_insn_num = 0;
2242 old_cleanups = make_cleanup (record_arch_list_cleanups, 0);
2243 regcache = get_current_regcache ();
2248 uint32_t regnum, len, signal, count;
2251 /* We are finished when offset reaches osec_size. */
2252 if (bfd_offset >= osec_size)
2254 bfdcore_read (core_bfd, osec, &rectype, sizeof (rectype), &bfd_offset);
2258 case record_reg: /* reg */
2259 /* Get register number to regnum. */
2260 bfdcore_read (core_bfd, osec, ®num,
2261 sizeof (regnum), &bfd_offset);
2262 regnum = netorder32 (regnum);
2264 rec = record_reg_alloc (regcache, regnum);
2267 bfdcore_read (core_bfd, osec, record_get_loc (rec),
2268 rec->u.reg.len, &bfd_offset);
2271 fprintf_unfiltered (gdb_stdlog,
2272 " Reading register %d (1 "
2273 "plus %lu plus %d bytes)\n",
2275 (unsigned long) sizeof (regnum),
2279 case record_mem: /* mem */
2281 bfdcore_read (core_bfd, osec, &len,
2282 sizeof (len), &bfd_offset);
2283 len = netorder32 (len);
2286 bfdcore_read (core_bfd, osec, &addr,
2287 sizeof (addr), &bfd_offset);
2288 addr = netorder64 (addr);
2290 rec = record_mem_alloc (addr, len);
2293 bfdcore_read (core_bfd, osec, record_get_loc (rec),
2294 rec->u.mem.len, &bfd_offset);
2297 fprintf_unfiltered (gdb_stdlog,
2298 " Reading memory %s (1 plus "
2299 "%lu plus %lu plus %d bytes)\n",
2300 paddress (get_current_arch (),
2302 (unsigned long) sizeof (addr),
2303 (unsigned long) sizeof (len),
2307 case record_end: /* end */
2308 rec = record_end_alloc ();
2311 /* Get signal value. */
2312 bfdcore_read (core_bfd, osec, &signal,
2313 sizeof (signal), &bfd_offset);
2314 signal = netorder32 (signal);
2315 rec->u.end.sigval = signal;
2317 /* Get insn count. */
2318 bfdcore_read (core_bfd, osec, &count,
2319 sizeof (count), &bfd_offset);
2320 count = netorder32 (count);
2321 rec->u.end.insn_num = count;
2322 record_insn_count = count + 1;
2324 fprintf_unfiltered (gdb_stdlog,
2325 " Reading record_end (1 + "
2326 "%lu + %lu bytes), offset == %s\n",
2327 (unsigned long) sizeof (signal),
2328 (unsigned long) sizeof (count),
2329 paddress (get_current_arch (),
2334 error (_("Bad entry type in core file %s."),
2335 bfd_get_filename (core_bfd));
2339 /* Add rec to record arch list. */
2340 record_arch_list_add (rec);
2343 discard_cleanups (old_cleanups);
2345 /* Add record_arch_list_head to the end of record list. */
2346 record_first.next = record_arch_list_head;
2347 record_arch_list_head->prev = &record_first;
2348 record_arch_list_tail->next = NULL;
2349 record_list = &record_first;
2351 /* Update record_insn_max_num. */
2352 if (record_insn_num > record_insn_max_num)
2354 record_insn_max_num = record_insn_num;
2355 warning (_("Auto increase record/replay buffer limit to %d."),
2356 record_insn_max_num);
2360 printf_filtered (_("Restored records from core file %s.\n"),
2361 bfd_get_filename (core_bfd));
2363 print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC);
2366 /* bfdcore_write -- write bytes into a core file section. */
2369 bfdcore_write (bfd *obfd, asection *osec, void *buf, int len, int *offset)
2371 int ret = bfd_set_section_contents (obfd, osec, buf, *offset, len);
2376 error (_("Failed to write %d bytes to core file %s ('%s').\n"),
2377 len, bfd_get_filename (obfd),
2378 bfd_errmsg (bfd_get_error ()));
2381 /* Restore the execution log from a file. We use a modified elf
2382 corefile format, with an extra section for our data. */
2385 cmd_record_restore (char *args, int from_tty)
2387 core_file_command (args, from_tty);
2388 record_open (args, from_tty);
2392 record_save_cleanups (void *data)
2395 char *pathname = xstrdup (bfd_get_filename (obfd));
2402 /* Save the execution log to a file. We use a modified elf corefile
2403 format, with an extra section for our data. */
2406 cmd_record_save (char *args, int from_tty)
2408 char *recfilename, recfilename_buffer[40];
2409 struct record_entry *cur_record_list;
2411 struct regcache *regcache;
2412 struct gdbarch *gdbarch;
2413 struct cleanup *old_cleanups;
2414 struct cleanup *set_cleanups;
2417 asection *osec = NULL;
2420 if (strcmp (current_target.to_shortname, "record") != 0)
2421 error (_("This command can only be used with target 'record'.\n"
2422 "Use 'target record' first.\n"));
2428 /* Default recfile name is "gdb_record.PID". */
2429 snprintf (recfilename_buffer, sizeof (recfilename_buffer),
2430 "gdb_record.%d", PIDGET (inferior_ptid));
2431 recfilename = recfilename_buffer;
2434 /* Open the save file. */
2436 fprintf_unfiltered (gdb_stdlog, "Saving execution log to core file '%s'\n",
2439 /* Open the output file. */
2440 obfd = create_gcore_bfd (recfilename);
2441 old_cleanups = make_cleanup (record_save_cleanups, obfd);
2443 /* Save the current record entry to "cur_record_list". */
2444 cur_record_list = record_list;
2446 /* Get the values of regcache and gdbarch. */
2447 regcache = get_current_regcache ();
2448 gdbarch = get_regcache_arch (regcache);
2450 /* Disable the GDB operation record. */
2451 set_cleanups = record_gdb_operation_disable_set ();
2453 /* Reverse execute to the begin of record list. */
2456 /* Check for beginning and end of log. */
2457 if (record_list == &record_first)
2460 record_exec_insn (regcache, gdbarch, record_list);
2462 if (record_list->prev)
2463 record_list = record_list->prev;
2466 /* Compute the size needed for the extra bfd section. */
2467 save_size = 4; /* magic cookie */
2468 for (record_list = record_first.next; record_list;
2469 record_list = record_list->next)
2470 switch (record_list->type)
2473 save_size += 1 + 4 + 4;
2476 save_size += 1 + 4 + record_list->u.reg.len;
2479 save_size += 1 + 4 + 8 + record_list->u.mem.len;
2483 /* Make the new bfd section. */
2484 osec = bfd_make_section_anyway_with_flags (obfd, "precord",
2488 error (_("Failed to create 'precord' section for corefile %s: %s"),
2490 bfd_errmsg (bfd_get_error ()));
2491 bfd_set_section_size (obfd, osec, save_size);
2492 bfd_set_section_vma (obfd, osec, 0);
2493 bfd_set_section_alignment (obfd, osec, 0);
2494 bfd_section_lma (obfd, osec) = 0;
2496 /* Save corefile state. */
2497 write_gcore_file (obfd);
2499 /* Write out the record log. */
2500 /* Write the magic code. */
2501 magic = RECORD_FILE_MAGIC;
2503 fprintf_unfiltered (gdb_stdlog,
2504 " Writing 4-byte magic cookie "
2505 "RECORD_FILE_MAGIC (0x%s)\n",
2506 phex_nz (magic, 4));
2507 bfdcore_write (obfd, osec, &magic, sizeof (magic), &bfd_offset);
2509 /* Save the entries to recfd and forward execute to the end of
2511 record_list = &record_first;
2515 if (record_list != &record_first)
2518 uint32_t regnum, len, signal, count;
2521 type = record_list->type;
2522 bfdcore_write (obfd, osec, &type, sizeof (type), &bfd_offset);
2524 switch (record_list->type)
2526 case record_reg: /* reg */
2528 fprintf_unfiltered (gdb_stdlog,
2529 " Writing register %d (1 "
2530 "plus %lu plus %d bytes)\n",
2531 record_list->u.reg.num,
2532 (unsigned long) sizeof (regnum),
2533 record_list->u.reg.len);
2536 regnum = netorder32 (record_list->u.reg.num);
2537 bfdcore_write (obfd, osec, ®num,
2538 sizeof (regnum), &bfd_offset);
2541 bfdcore_write (obfd, osec, record_get_loc (record_list),
2542 record_list->u.reg.len, &bfd_offset);
2545 case record_mem: /* mem */
2547 fprintf_unfiltered (gdb_stdlog,
2548 " Writing memory %s (1 plus "
2549 "%lu plus %lu plus %d bytes)\n",
2551 record_list->u.mem.addr),
2552 (unsigned long) sizeof (addr),
2553 (unsigned long) sizeof (len),
2554 record_list->u.mem.len);
2557 len = netorder32 (record_list->u.mem.len);
2558 bfdcore_write (obfd, osec, &len, sizeof (len), &bfd_offset);
2560 /* Write memaddr. */
2561 addr = netorder64 (record_list->u.mem.addr);
2562 bfdcore_write (obfd, osec, &addr,
2563 sizeof (addr), &bfd_offset);
2566 bfdcore_write (obfd, osec, record_get_loc (record_list),
2567 record_list->u.mem.len, &bfd_offset);
2572 fprintf_unfiltered (gdb_stdlog,
2573 " Writing record_end (1 + "
2574 "%lu + %lu bytes)\n",
2575 (unsigned long) sizeof (signal),
2576 (unsigned long) sizeof (count));
2577 /* Write signal value. */
2578 signal = netorder32 (record_list->u.end.sigval);
2579 bfdcore_write (obfd, osec, &signal,
2580 sizeof (signal), &bfd_offset);
2582 /* Write insn count. */
2583 count = netorder32 (record_list->u.end.insn_num);
2584 bfdcore_write (obfd, osec, &count,
2585 sizeof (count), &bfd_offset);
2590 /* Execute entry. */
2591 record_exec_insn (regcache, gdbarch, record_list);
2593 if (record_list->next)
2594 record_list = record_list->next;
2599 /* Reverse execute to cur_record_list. */
2602 /* Check for beginning and end of log. */
2603 if (record_list == cur_record_list)
2606 record_exec_insn (regcache, gdbarch, record_list);
2608 if (record_list->prev)
2609 record_list = record_list->prev;
2612 do_cleanups (set_cleanups);
2614 discard_cleanups (old_cleanups);
2617 printf_filtered (_("Saved core file %s with execution log.\n"),
2621 /* record_goto_insn -- rewind the record log (forward or backward,
2622 depending on DIR) to the given entry, changing the program state
2626 record_goto_insn (struct record_entry *entry,
2627 enum exec_direction_kind dir)
2629 struct cleanup *set_cleanups = record_gdb_operation_disable_set ();
2630 struct regcache *regcache = get_current_regcache ();
2631 struct gdbarch *gdbarch = get_regcache_arch (regcache);
2633 /* Assume everything is valid: we will hit the entry,
2634 and we will not hit the end of the recording. */
2636 if (dir == EXEC_FORWARD)
2637 record_list = record_list->next;
2641 record_exec_insn (regcache, gdbarch, record_list);
2642 if (dir == EXEC_REVERSE)
2643 record_list = record_list->prev;
2645 record_list = record_list->next;
2646 } while (record_list != entry);
2647 do_cleanups (set_cleanups);
2650 /* "record goto" command. Argument is an instruction number,
2651 as given by "info record".
2653 Rewinds the recording (forward or backward) to the given instruction. */
2656 cmd_record_goto (char *arg, int from_tty)
2658 struct record_entry *p = NULL;
2659 ULONGEST target_insn = 0;
2661 if (arg == NULL || *arg == '\0')
2662 error (_("Command requires an argument (insn number to go to)."));
2664 if (strncmp (arg, "start", strlen ("start")) == 0
2665 || strncmp (arg, "begin", strlen ("begin")) == 0)
2667 /* Special case. Find first insn. */
2668 for (p = &record_first; p != NULL; p = p->next)
2669 if (p->type == record_end)
2672 target_insn = p->u.end.insn_num;
2674 else if (strncmp (arg, "end", strlen ("end")) == 0)
2676 /* Special case. Find last insn. */
2677 for (p = record_list; p->next != NULL; p = p->next)
2679 for (; p!= NULL; p = p->prev)
2680 if (p->type == record_end)
2683 target_insn = p->u.end.insn_num;
2687 /* General case. Find designated insn. */
2688 target_insn = parse_and_eval_long (arg);
2690 for (p = &record_first; p != NULL; p = p->next)
2691 if (p->type == record_end && p->u.end.insn_num == target_insn)
2696 error (_("Target insn '%s' not found."), arg);
2697 else if (p == record_list)
2698 error (_("Already at insn '%s'."), arg);
2699 else if (p->u.end.insn_num > record_list->u.end.insn_num)
2701 printf_filtered (_("Go forward to insn number %s\n"),
2702 pulongest (target_insn));
2703 record_goto_insn (p, EXEC_FORWARD);
2707 printf_filtered (_("Go backward to insn number %s\n"),
2708 pulongest (target_insn));
2709 record_goto_insn (p, EXEC_REVERSE);
2711 registers_changed ();
2712 reinit_frame_cache ();
2713 print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC);
2717 _initialize_record (void)
2719 struct cmd_list_element *c;
2721 /* Init record_first. */
2722 record_first.prev = NULL;
2723 record_first.next = NULL;
2724 record_first.type = record_end;
2727 add_target (&record_ops);
2728 init_record_core_ops ();
2729 add_target (&record_core_ops);
2731 add_setshow_zinteger_cmd ("record", no_class, &record_debug,
2732 _("Set debugging of record/replay feature."),
2733 _("Show debugging of record/replay feature."),
2734 _("When enabled, debugging output for "
2735 "record/replay feature is displayed."),
2736 NULL, show_record_debug, &setdebuglist,
2739 c = add_prefix_cmd ("record", class_obscure, cmd_record_start,
2740 _("Abbreviated form of \"target record\" command."),
2741 &record_cmdlist, "record ", 0, &cmdlist);
2742 set_cmd_completer (c, filename_completer);
2744 add_com_alias ("rec", "record", class_obscure, 1);
2745 add_prefix_cmd ("record", class_support, set_record_command,
2746 _("Set record options"), &set_record_cmdlist,
2747 "set record ", 0, &setlist);
2748 add_alias_cmd ("rec", "record", class_obscure, 1, &setlist);
2749 add_prefix_cmd ("record", class_support, show_record_command,
2750 _("Show record options"), &show_record_cmdlist,
2751 "show record ", 0, &showlist);
2752 add_alias_cmd ("rec", "record", class_obscure, 1, &showlist);
2753 add_prefix_cmd ("record", class_support, info_record_command,
2754 _("Info record options"), &info_record_cmdlist,
2755 "info record ", 0, &infolist);
2756 add_alias_cmd ("rec", "record", class_obscure, 1, &infolist);
2758 c = add_cmd ("save", class_obscure, cmd_record_save,
2759 _("Save the execution log to a file.\n\
2760 Argument is optional filename.\n\
2761 Default filename is 'gdb_record.<process_id>'."),
2763 set_cmd_completer (c, filename_completer);
2765 c = add_cmd ("restore", class_obscure, cmd_record_restore,
2766 _("Restore the execution log from a file.\n\
2767 Argument is filename. File must be created with 'record save'."),
2769 set_cmd_completer (c, filename_completer);
2771 add_cmd ("delete", class_obscure, cmd_record_delete,
2772 _("Delete the rest of execution log and start recording it anew."),
2774 add_alias_cmd ("d", "delete", class_obscure, 1, &record_cmdlist);
2775 add_alias_cmd ("del", "delete", class_obscure, 1, &record_cmdlist);
2777 add_cmd ("stop", class_obscure, cmd_record_stop,
2778 _("Stop the record/replay target."),
2780 add_alias_cmd ("s", "stop", class_obscure, 1, &record_cmdlist);
2782 /* Record instructions number limit command. */
2783 add_setshow_boolean_cmd ("stop-at-limit", no_class,
2784 &record_stop_at_limit, _("\
2785 Set whether record/replay stops when record/replay buffer becomes full."), _("\
2786 Show whether record/replay stops when record/replay buffer becomes full."),
2787 _("Default is ON.\n\
2788 When ON, if the record/replay buffer becomes full, ask user what to do.\n\
2789 When OFF, if the record/replay buffer becomes full,\n\
2790 delete the oldest recorded instruction to make room for each new one."),
2792 &set_record_cmdlist, &show_record_cmdlist);
2793 add_setshow_uinteger_cmd ("insn-number-max", no_class,
2794 &record_insn_max_num,
2795 _("Set record/replay buffer limit."),
2796 _("Show record/replay buffer limit."), _("\
2797 Set the maximum number of instructions to be stored in the\n\
2798 record/replay buffer. Zero means unlimited. Default is 200000."),
2799 set_record_insn_max_num,
2800 NULL, &set_record_cmdlist, &show_record_cmdlist);
2802 add_cmd ("goto", class_obscure, cmd_record_goto, _("\
2803 Restore the program to its state at instruction number N.\n\
2804 Argument is instruction number, as shown by 'info record'."),
2807 add_setshow_boolean_cmd ("memory-query", no_class,
2808 &record_memory_query, _("\
2809 Set whether query if PREC cannot record memory change of next instruction."),
2811 Show whether query if PREC cannot record memory change of next instruction."),
2814 When ON, query if PREC cannot record memory change of next instruction."),
2816 &set_record_cmdlist, &show_record_cmdlist);