1 /* Process record and replay target for GDB, the GNU debugger.
3 Copyright (C) 2008, 2009 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 struct record_core_buf_entry
157 struct record_core_buf_entry
*prev
;
158 struct target_section
*p
;
162 /* Record buf with core target. */
163 static gdb_byte
*record_core_regbuf
= NULL
;
164 static struct target_section
*record_core_start
;
165 static struct target_section
*record_core_end
;
166 static struct record_core_buf_entry
*record_core_buf_list
= NULL
;
168 /* The following variables are used for managing the linked list that
169 represents the execution log.
171 record_first is the anchor that holds down the beginning of the list.
173 record_list serves two functions:
174 1) In record mode, it anchors the end of the list.
175 2) In replay mode, it traverses the list and points to
176 the next instruction that must be emulated.
178 record_arch_list_head and record_arch_list_tail are used to manage
179 a separate list, which is used to build up the change elements of
180 the currently executing instruction during record mode. When this
181 instruction has been completely annotated in the "arch list", it
182 will be appended to the main execution log. */
184 static struct record_entry record_first
;
185 static struct record_entry
*record_list
= &record_first
;
186 static struct record_entry
*record_arch_list_head
= NULL
;
187 static struct record_entry
*record_arch_list_tail
= NULL
;
189 /* 1 ask user. 0 auto delete the last struct record_entry. */
190 static int record_stop_at_limit
= 1;
191 /* Maximum allowed number of insns in execution log. */
192 static unsigned int record_insn_max_num
= DEFAULT_RECORD_INSN_MAX_NUM
;
193 /* Actual count of insns presently in execution log. */
194 static int record_insn_num
= 0;
195 /* Count of insns logged so far (may be larger
196 than count of insns presently in execution log). */
197 static ULONGEST record_insn_count
;
199 /* The target_ops of process record. */
200 static struct target_ops record_ops
;
201 static struct target_ops record_core_ops
;
203 /* The beneath function pointers. */
204 static struct target_ops
*record_beneath_to_resume_ops
;
205 static void (*record_beneath_to_resume
) (struct target_ops
*, ptid_t
, int,
207 static struct target_ops
*record_beneath_to_wait_ops
;
208 static ptid_t (*record_beneath_to_wait
) (struct target_ops
*, ptid_t
,
209 struct target_waitstatus
*,
211 static struct target_ops
*record_beneath_to_store_registers_ops
;
212 static void (*record_beneath_to_store_registers
) (struct target_ops
*,
215 static struct target_ops
*record_beneath_to_xfer_partial_ops
;
216 static LONGEST (*record_beneath_to_xfer_partial
) (struct target_ops
*ops
,
217 enum target_object object
,
220 const gdb_byte
*writebuf
,
223 static int (*record_beneath_to_insert_breakpoint
) (struct gdbarch
*,
224 struct bp_target_info
*);
225 static int (*record_beneath_to_remove_breakpoint
) (struct gdbarch
*,
226 struct bp_target_info
*);
228 /* Alloc and free functions for record_reg, record_mem, and record_end
231 /* Alloc a record_reg record entry. */
233 static inline struct record_entry
*
234 record_reg_alloc (struct regcache
*regcache
, int regnum
)
236 struct record_entry
*rec
;
237 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
239 rec
= (struct record_entry
*) xcalloc (1, sizeof (struct record_entry
));
240 rec
->type
= record_reg
;
241 rec
->u
.reg
.num
= regnum
;
242 rec
->u
.reg
.len
= register_size (gdbarch
, regnum
);
243 if (rec
->u
.reg
.len
> sizeof (rec
->u
.reg
.u
.buf
))
244 rec
->u
.reg
.u
.ptr
= (gdb_byte
*) xmalloc (rec
->u
.reg
.len
);
249 /* Free a record_reg record entry. */
252 record_reg_release (struct record_entry
*rec
)
254 gdb_assert (rec
->type
== record_reg
);
255 if (rec
->u
.reg
.len
> sizeof (rec
->u
.reg
.u
.buf
))
256 xfree (rec
->u
.reg
.u
.ptr
);
260 /* Alloc a record_mem record entry. */
262 static inline struct record_entry
*
263 record_mem_alloc (CORE_ADDR addr
, int len
)
265 struct record_entry
*rec
;
267 rec
= (struct record_entry
*) xcalloc (1, sizeof (struct record_entry
));
268 rec
->type
= record_mem
;
269 rec
->u
.mem
.addr
= addr
;
270 rec
->u
.mem
.len
= len
;
271 if (rec
->u
.mem
.len
> sizeof (rec
->u
.mem
.u
.buf
))
272 rec
->u
.mem
.u
.ptr
= (gdb_byte
*) xmalloc (len
);
277 /* Free a record_mem record entry. */
280 record_mem_release (struct record_entry
*rec
)
282 gdb_assert (rec
->type
== record_mem
);
283 if (rec
->u
.mem
.len
> sizeof (rec
->u
.mem
.u
.buf
))
284 xfree (rec
->u
.mem
.u
.ptr
);
288 /* Alloc a record_end record entry. */
290 static inline struct record_entry
*
291 record_end_alloc (void)
293 struct record_entry
*rec
;
295 rec
= (struct record_entry
*) xcalloc (1, sizeof (struct record_entry
));
296 rec
->type
= record_end
;
301 /* Free a record_end record entry. */
304 record_end_release (struct record_entry
*rec
)
309 /* Free one record entry, any type.
310 Return entry->type, in case caller wants to know. */
312 static inline enum record_type
313 record_entry_release (struct record_entry
*rec
)
315 enum record_type type
= rec
->type
;
319 record_reg_release (rec
);
322 record_mem_release (rec
);
325 record_end_release (rec
);
331 /* Free all record entries in list pointed to by REC. */
334 record_list_release (struct record_entry
*rec
)
345 record_entry_release (rec
->next
);
348 if (rec
== &record_first
)
351 record_first
.next
= NULL
;
354 record_entry_release (rec
);
357 /* Free all record entries forward of the given list position. */
360 record_list_release_following (struct record_entry
*rec
)
362 struct record_entry
*tmp
= rec
->next
;
368 if (record_entry_release (tmp
) == record_end
)
377 /* Delete the first instruction from the beginning of the log, to make
378 room for adding a new instruction at the end of the log.
380 Note -- this function does not modify record_insn_num. */
383 record_list_release_first (void)
385 struct record_entry
*tmp
;
387 if (!record_first
.next
)
390 /* Loop until a record_end. */
393 /* Cut record_first.next out of the linked list. */
394 tmp
= record_first
.next
;
395 record_first
.next
= tmp
->next
;
396 tmp
->next
->prev
= &record_first
;
398 /* tmp is now isolated, and can be deleted. */
399 if (record_entry_release (tmp
) == record_end
)
400 break; /* End loop at first record_end. */
402 if (!record_first
.next
)
404 gdb_assert (record_insn_num
== 1);
405 break; /* End loop when list is empty. */
410 /* Add a struct record_entry to record_arch_list. */
413 record_arch_list_add (struct record_entry
*rec
)
415 if (record_debug
> 1)
416 fprintf_unfiltered (gdb_stdlog
,
417 "Process record: record_arch_list_add %s.\n",
418 host_address_to_string (rec
));
420 if (record_arch_list_tail
)
422 record_arch_list_tail
->next
= rec
;
423 rec
->prev
= record_arch_list_tail
;
424 record_arch_list_tail
= rec
;
428 record_arch_list_head
= rec
;
429 record_arch_list_tail
= rec
;
433 /* Return the value storage location of a record entry. */
434 static inline gdb_byte
*
435 record_get_loc (struct record_entry
*rec
)
439 if (rec
->u
.mem
.len
> sizeof (rec
->u
.mem
.u
.buf
))
440 return rec
->u
.mem
.u
.ptr
;
442 return rec
->u
.mem
.u
.buf
;
444 if (rec
->u
.reg
.len
> sizeof (rec
->u
.reg
.u
.buf
))
445 return rec
->u
.reg
.u
.ptr
;
447 return rec
->u
.reg
.u
.buf
;
455 /* Record the value of a register NUM to record_arch_list. */
458 record_arch_list_add_reg (struct regcache
*regcache
, int regnum
)
460 struct record_entry
*rec
;
462 if (record_debug
> 1)
463 fprintf_unfiltered (gdb_stdlog
,
464 "Process record: add register num = %d to "
468 rec
= record_reg_alloc (regcache
, regnum
);
470 regcache_raw_read (regcache
, regnum
, record_get_loc (rec
));
472 record_arch_list_add (rec
);
477 /* Record the value of a region of memory whose address is ADDR and
478 length is LEN to record_arch_list. */
481 record_arch_list_add_mem (CORE_ADDR addr
, int len
)
483 struct record_entry
*rec
;
485 if (record_debug
> 1)
486 fprintf_unfiltered (gdb_stdlog
,
487 "Process record: add mem addr = %s len = %d to "
489 paddress (target_gdbarch
, addr
), len
);
491 if (!addr
) /* FIXME: Why? Some arch must permit it... */
494 rec
= record_mem_alloc (addr
, len
);
496 if (target_read_memory (addr
, record_get_loc (rec
), len
))
499 fprintf_unfiltered (gdb_stdlog
,
500 "Process record: error reading memory at "
501 "addr = %s len = %d.\n",
502 paddress (target_gdbarch
, addr
), len
);
503 record_mem_release (rec
);
507 record_arch_list_add (rec
);
512 /* Add a record_end type struct record_entry to record_arch_list. */
515 record_arch_list_add_end (void)
517 struct record_entry
*rec
;
519 if (record_debug
> 1)
520 fprintf_unfiltered (gdb_stdlog
,
521 "Process record: add end to arch list.\n");
523 rec
= record_end_alloc ();
524 rec
->u
.end
.sigval
= TARGET_SIGNAL_0
;
525 rec
->u
.end
.insn_num
= ++record_insn_count
;
527 record_arch_list_add (rec
);
533 record_check_insn_num (int set_terminal
)
535 if (record_insn_max_num
)
537 gdb_assert (record_insn_num
<= record_insn_max_num
);
538 if (record_insn_num
== record_insn_max_num
)
540 /* Ask user what to do. */
541 if (record_stop_at_limit
)
545 target_terminal_ours ();
546 q
= yquery (_("Do you want to auto delete previous execution "
547 "log entries when record/replay buffer becomes "
548 "full (record stop-at-limit)?"));
550 target_terminal_inferior ();
552 record_stop_at_limit
= 0;
554 error (_("Process record: stopped by user."));
561 record_arch_list_cleanups (void *ignore
)
563 record_list_release (record_arch_list_tail
);
566 /* Before inferior step (when GDB record the running message, inferior
567 only can step), GDB will call this function to record the values to
568 record_list. This function will call gdbarch_process_record to
569 record the running message of inferior and set them to
570 record_arch_list, and add it to record_list. */
572 struct record_message_args
{
573 struct regcache
*regcache
;
574 enum target_signal signal
;
578 record_message (void *args
)
581 struct record_message_args
*myargs
= args
;
582 struct gdbarch
*gdbarch
= get_regcache_arch (myargs
->regcache
);
583 struct cleanup
*old_cleanups
= make_cleanup (record_arch_list_cleanups
, 0);
585 record_arch_list_head
= NULL
;
586 record_arch_list_tail
= NULL
;
588 /* Check record_insn_num. */
589 record_check_insn_num (1);
591 /* If gdb sends a signal value to target_resume,
592 save it in the 'end' field of the previous instruction.
594 Maybe process record should record what really happened,
595 rather than what gdb pretends has happened.
597 So if Linux delivered the signal to the child process during
598 the record mode, we will record it and deliver it again in
601 If user says "ignore this signal" during the record mode, then
602 it will be ignored again during the replay mode (no matter if
603 the user says something different, like "deliver this signal"
604 during the replay mode).
606 User should understand that nothing he does during the replay
607 mode will change the behavior of the child. If he tries,
608 then that is a user error.
610 But we should still deliver the signal to gdb during the replay,
611 if we delivered it during the recording. Therefore we should
612 record the signal during record_wait, not record_resume. */
613 if (record_list
!= &record_first
) /* FIXME better way to check */
615 gdb_assert (record_list
->type
== record_end
);
616 record_list
->u
.end
.sigval
= myargs
->signal
;
619 if (myargs
->signal
== TARGET_SIGNAL_0
620 || !gdbarch_process_record_signal_p (gdbarch
))
621 ret
= gdbarch_process_record (gdbarch
,
623 regcache_read_pc (myargs
->regcache
));
625 ret
= gdbarch_process_record_signal (gdbarch
,
630 error (_("Process record: inferior program stopped."));
632 error (_("Process record: failed to record execution log."));
634 discard_cleanups (old_cleanups
);
636 record_list
->next
= record_arch_list_head
;
637 record_arch_list_head
->prev
= record_list
;
638 record_list
= record_arch_list_tail
;
640 if (record_insn_num
== record_insn_max_num
&& record_insn_max_num
)
641 record_list_release_first ();
649 do_record_message (struct regcache
*regcache
,
650 enum target_signal signal
)
652 struct record_message_args args
;
654 args
.regcache
= regcache
;
655 args
.signal
= signal
;
656 return catch_errors (record_message
, &args
, NULL
, RETURN_MASK_ALL
);
659 /* Set to 1 if record_store_registers and record_xfer_partial
660 doesn't need record. */
662 static int record_gdb_operation_disable
= 0;
665 record_gdb_operation_disable_set (void)
667 struct cleanup
*old_cleanups
= NULL
;
670 make_cleanup_restore_integer (&record_gdb_operation_disable
);
671 record_gdb_operation_disable
= 1;
676 /* Execute one instruction from the record log. Each instruction in
677 the log will be represented by an arbitrary sequence of register
678 entries and memory entries, followed by an 'end' entry. */
681 record_exec_insn (struct regcache
*regcache
, struct gdbarch
*gdbarch
,
682 struct record_entry
*entry
)
686 case record_reg
: /* reg */
688 gdb_byte reg
[MAX_REGISTER_SIZE
];
690 if (record_debug
> 1)
691 fprintf_unfiltered (gdb_stdlog
,
692 "Process record: record_reg %s to "
693 "inferior num = %d.\n",
694 host_address_to_string (entry
),
697 regcache_cooked_read (regcache
, entry
->u
.reg
.num
, reg
);
698 regcache_cooked_write (regcache
, entry
->u
.reg
.num
,
699 record_get_loc (entry
));
700 memcpy (record_get_loc (entry
), reg
, entry
->u
.reg
.len
);
704 case record_mem
: /* mem */
706 /* Nothing to do if the entry is flagged not_accessible. */
707 if (!entry
->u
.mem
.mem_entry_not_accessible
)
709 gdb_byte
*mem
= alloca (entry
->u
.mem
.len
);
711 if (record_debug
> 1)
712 fprintf_unfiltered (gdb_stdlog
,
713 "Process record: record_mem %s to "
714 "inferior addr = %s len = %d.\n",
715 host_address_to_string (entry
),
716 paddress (gdbarch
, entry
->u
.mem
.addr
),
719 if (target_read_memory (entry
->u
.mem
.addr
, mem
, entry
->u
.mem
.len
))
721 entry
->u
.mem
.mem_entry_not_accessible
= 1;
723 warning ("Process record: error reading memory at "
724 "addr = %s len = %d.",
725 paddress (gdbarch
, entry
->u
.mem
.addr
),
730 if (target_write_memory (entry
->u
.mem
.addr
,
731 record_get_loc (entry
),
734 entry
->u
.mem
.mem_entry_not_accessible
= 1;
736 warning ("Process record: error writing memory at "
737 "addr = %s len = %d.",
738 paddress (gdbarch
, entry
->u
.mem
.addr
),
742 memcpy (record_get_loc (entry
), mem
, entry
->u
.mem
.len
);
750 static struct target_ops
*tmp_to_resume_ops
;
751 static void (*tmp_to_resume
) (struct target_ops
*, ptid_t
, int,
753 static struct target_ops
*tmp_to_wait_ops
;
754 static ptid_t (*tmp_to_wait
) (struct target_ops
*, ptid_t
,
755 struct target_waitstatus
*,
757 static struct target_ops
*tmp_to_store_registers_ops
;
758 static void (*tmp_to_store_registers
) (struct target_ops
*,
761 static struct target_ops
*tmp_to_xfer_partial_ops
;
762 static LONGEST (*tmp_to_xfer_partial
) (struct target_ops
*ops
,
763 enum target_object object
,
766 const gdb_byte
*writebuf
,
769 static int (*tmp_to_insert_breakpoint
) (struct gdbarch
*,
770 struct bp_target_info
*);
771 static int (*tmp_to_remove_breakpoint
) (struct gdbarch
*,
772 struct bp_target_info
*);
774 static void record_restore (void);
776 /* Open the process record target. */
779 record_core_open_1 (char *name
, int from_tty
)
781 struct regcache
*regcache
= get_current_regcache ();
782 int regnum
= gdbarch_num_regs (get_regcache_arch (regcache
));
785 /* Get record_core_regbuf. */
786 target_fetch_registers (regcache
, -1);
787 record_core_regbuf
= xmalloc (MAX_REGISTER_SIZE
* regnum
);
788 for (i
= 0; i
< regnum
; i
++)
789 regcache_raw_collect (regcache
, i
,
790 record_core_regbuf
+ MAX_REGISTER_SIZE
* i
);
792 /* Get record_core_start and record_core_end. */
793 if (build_section_table (core_bfd
, &record_core_start
, &record_core_end
))
795 xfree (record_core_regbuf
);
796 record_core_regbuf
= NULL
;
797 error (_("\"%s\": Can't find sections: %s"),
798 bfd_get_filename (core_bfd
), bfd_errmsg (bfd_get_error ()));
801 push_target (&record_core_ops
);
805 /* "to_open" target method for 'live' processes. */
808 record_open_1 (char *name
, int from_tty
)
810 struct target_ops
*t
;
813 fprintf_unfiltered (gdb_stdlog
, "Process record: record_open\n");
816 if (!target_has_execution
)
817 error (_("Process record: the program is not being run."));
819 error (_("Process record target can't debug inferior in non-stop mode "
821 if (target_async_permitted
)
822 error (_("Process record target can't debug inferior in asynchronous "
823 "mode (target-async)."));
825 if (!gdbarch_process_record_p (target_gdbarch
))
826 error (_("Process record: the current architecture doesn't support "
827 "record function."));
830 error (_("Could not find 'to_resume' method on the target stack."));
832 error (_("Could not find 'to_wait' method on the target stack."));
833 if (!tmp_to_store_registers
)
834 error (_("Could not find 'to_store_registers' method on the target stack."));
835 if (!tmp_to_insert_breakpoint
)
836 error (_("Could not find 'to_insert_breakpoint' method on the target stack."));
837 if (!tmp_to_remove_breakpoint
)
838 error (_("Could not find 'to_remove_breakpoint' method on the target stack."));
840 push_target (&record_ops
);
843 /* "to_open" target method. Open the process record target. */
846 record_open (char *name
, int from_tty
)
848 struct target_ops
*t
;
851 fprintf_unfiltered (gdb_stdlog
, "Process record: record_open\n");
853 /* Check if record target is already running. */
854 if (current_target
.to_stratum
== record_stratum
)
855 error (_("Process record target already running. Use \"record stop\" to "
856 "stop record target first."));
858 /* Reset the tmp beneath pointers. */
859 tmp_to_resume_ops
= NULL
;
860 tmp_to_resume
= NULL
;
861 tmp_to_wait_ops
= NULL
;
863 tmp_to_store_registers_ops
= NULL
;
864 tmp_to_store_registers
= NULL
;
865 tmp_to_xfer_partial_ops
= NULL
;
866 tmp_to_xfer_partial
= NULL
;
867 tmp_to_insert_breakpoint
= NULL
;
868 tmp_to_remove_breakpoint
= NULL
;
870 /* Set the beneath function pointers. */
871 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
875 tmp_to_resume
= t
->to_resume
;
876 tmp_to_resume_ops
= t
;
880 tmp_to_wait
= t
->to_wait
;
883 if (!tmp_to_store_registers
)
885 tmp_to_store_registers
= t
->to_store_registers
;
886 tmp_to_store_registers_ops
= t
;
888 if (!tmp_to_xfer_partial
)
890 tmp_to_xfer_partial
= t
->to_xfer_partial
;
891 tmp_to_xfer_partial_ops
= t
;
893 if (!tmp_to_insert_breakpoint
)
894 tmp_to_insert_breakpoint
= t
->to_insert_breakpoint
;
895 if (!tmp_to_remove_breakpoint
)
896 tmp_to_remove_breakpoint
= t
->to_remove_breakpoint
;
898 if (!tmp_to_xfer_partial
)
899 error (_("Could not find 'to_xfer_partial' method on the target stack."));
903 record_insn_count
= 0;
904 record_list
= &record_first
;
905 record_list
->next
= NULL
;
907 /* Set the tmp beneath pointers to beneath pointers. */
908 record_beneath_to_resume_ops
= tmp_to_resume_ops
;
909 record_beneath_to_resume
= tmp_to_resume
;
910 record_beneath_to_wait_ops
= tmp_to_wait_ops
;
911 record_beneath_to_wait
= tmp_to_wait
;
912 record_beneath_to_store_registers_ops
= tmp_to_store_registers_ops
;
913 record_beneath_to_store_registers
= tmp_to_store_registers
;
914 record_beneath_to_xfer_partial_ops
= tmp_to_xfer_partial_ops
;
915 record_beneath_to_xfer_partial
= tmp_to_xfer_partial
;
916 record_beneath_to_insert_breakpoint
= tmp_to_insert_breakpoint
;
917 record_beneath_to_remove_breakpoint
= tmp_to_remove_breakpoint
;
919 if (current_target
.to_stratum
== core_stratum
)
920 record_core_open_1 (name
, from_tty
);
922 record_open_1 (name
, from_tty
);
925 /* "to_close" target method. Close the process record target. */
928 record_close (int quitting
)
930 struct record_core_buf_entry
*entry
;
933 fprintf_unfiltered (gdb_stdlog
, "Process record: record_close\n");
935 record_list_release (record_list
);
937 /* Release record_core_regbuf. */
938 if (record_core_regbuf
)
940 xfree (record_core_regbuf
);
941 record_core_regbuf
= NULL
;
944 /* Release record_core_buf_list. */
945 if (record_core_buf_list
)
947 for (entry
= record_core_buf_list
->prev
; entry
; entry
= entry
->prev
)
949 xfree (record_core_buf_list
);
950 record_core_buf_list
= entry
;
952 record_core_buf_list
= NULL
;
956 static int record_resume_step
= 0;
957 static int record_resume_error
;
959 /* "to_resume" target method. Resume the process record target. */
962 record_resume (struct target_ops
*ops
, ptid_t ptid
, int step
,
963 enum target_signal signal
)
965 record_resume_step
= step
;
967 if (!RECORD_IS_REPLAY
)
969 if (do_record_message (get_current_regcache (), signal
))
971 record_resume_error
= 0;
975 record_resume_error
= 1;
978 record_beneath_to_resume (record_beneath_to_resume_ops
, ptid
, 1,
983 static int record_get_sig
= 0;
985 /* SIGINT signal handler, registered by "to_wait" method. */
988 record_sig_handler (int signo
)
991 fprintf_unfiltered (gdb_stdlog
, "Process record: get a signal\n");
993 /* It will break the running inferior in replay mode. */
994 record_resume_step
= 1;
996 /* It will let record_wait set inferior status to get the signal
1002 record_wait_cleanups (void *ignore
)
1004 if (execution_direction
== EXEC_REVERSE
)
1006 if (record_list
->next
)
1007 record_list
= record_list
->next
;
1010 record_list
= record_list
->prev
;
1013 /* "to_wait" target method for process record target.
1015 In record mode, the target is always run in singlestep mode
1016 (even when gdb says to continue). The to_wait method intercepts
1017 the stop events and determines which ones are to be passed on to
1018 gdb. Most stop events are just singlestep events that gdb is not
1019 to know about, so the to_wait method just records them and keeps
1022 In replay mode, this function emulates the recorded execution log,
1023 one instruction at a time (forward or backward), and determines
1027 record_wait (struct target_ops
*ops
,
1028 ptid_t ptid
, struct target_waitstatus
*status
,
1031 struct cleanup
*set_cleanups
= record_gdb_operation_disable_set ();
1034 fprintf_unfiltered (gdb_stdlog
,
1035 "Process record: record_wait "
1036 "record_resume_step = %d\n",
1037 record_resume_step
);
1039 if (!RECORD_IS_REPLAY
&& ops
!= &record_core_ops
)
1041 if (record_resume_error
)
1043 /* If record_resume get error, return directly. */
1044 status
->kind
= TARGET_WAITKIND_STOPPED
;
1045 status
->value
.sig
= TARGET_SIGNAL_ABRT
;
1046 return inferior_ptid
;
1049 if (record_resume_step
)
1051 /* This is a single step. */
1052 return record_beneath_to_wait (record_beneath_to_wait_ops
,
1053 ptid
, status
, options
);
1057 /* This is not a single step. */
1063 ret
= record_beneath_to_wait (record_beneath_to_wait_ops
,
1064 ptid
, status
, options
);
1066 /* Is this a SIGTRAP? */
1067 if (status
->kind
== TARGET_WAITKIND_STOPPED
1068 && status
->value
.sig
== TARGET_SIGNAL_TRAP
)
1070 struct regcache
*regcache
;
1072 /* Yes -- check if there is a breakpoint. */
1073 registers_changed ();
1074 regcache
= get_current_regcache ();
1075 tmp_pc
= regcache_read_pc (regcache
);
1076 if (breakpoint_inserted_here_p (get_regcache_aspace (regcache
),
1079 /* There is a breakpoint. GDB will want to stop. */
1080 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1081 CORE_ADDR decr_pc_after_break
1082 = gdbarch_decr_pc_after_break (gdbarch
);
1083 if (decr_pc_after_break
)
1084 regcache_write_pc (regcache
,
1085 tmp_pc
+ decr_pc_after_break
);
1089 /* There is not a breakpoint, and gdb is not
1090 stepping, therefore gdb will not stop.
1091 Therefore we will not return to gdb.
1092 Record the insn and resume. */
1093 if (!do_record_message (regcache
, TARGET_SIGNAL_0
))
1096 record_beneath_to_resume (record_beneath_to_resume_ops
,
1103 /* The inferior is broken by a breakpoint or a signal. */
1112 struct regcache
*regcache
= get_current_regcache ();
1113 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1114 int continue_flag
= 1;
1115 int first_record_end
= 1;
1116 struct cleanup
*old_cleanups
= make_cleanup (record_wait_cleanups
, 0);
1119 status
->kind
= TARGET_WAITKIND_STOPPED
;
1121 /* Check breakpoint when forward execute. */
1122 if (execution_direction
== EXEC_FORWARD
)
1124 tmp_pc
= regcache_read_pc (regcache
);
1125 if (breakpoint_inserted_here_p (get_regcache_aspace (regcache
),
1129 fprintf_unfiltered (gdb_stdlog
,
1130 "Process record: break at %s.\n",
1131 paddress (gdbarch
, tmp_pc
));
1132 if (gdbarch_decr_pc_after_break (gdbarch
)
1133 && !record_resume_step
)
1134 regcache_write_pc (regcache
,
1136 gdbarch_decr_pc_after_break (gdbarch
));
1142 signal (SIGINT
, record_sig_handler
);
1143 /* If GDB is in terminal_inferior mode, it will not get the signal.
1144 And in GDB replay mode, GDB doesn't need to be in terminal_inferior
1145 mode, because inferior will not executed.
1146 Then set it to terminal_ours to make GDB get the signal. */
1147 target_terminal_ours ();
1149 /* In EXEC_FORWARD mode, record_list points to the tail of prev
1151 if (execution_direction
== EXEC_FORWARD
&& record_list
->next
)
1152 record_list
= record_list
->next
;
1154 /* Loop over the record_list, looking for the next place to
1158 /* Check for beginning and end of log. */
1159 if (execution_direction
== EXEC_REVERSE
1160 && record_list
== &record_first
)
1162 /* Hit beginning of record log in reverse. */
1163 status
->kind
= TARGET_WAITKIND_NO_HISTORY
;
1166 if (execution_direction
!= EXEC_REVERSE
&& !record_list
->next
)
1168 /* Hit end of record log going forward. */
1169 status
->kind
= TARGET_WAITKIND_NO_HISTORY
;
1173 record_exec_insn (regcache
, gdbarch
, record_list
);
1175 if (record_list
->type
== record_end
)
1177 if (record_debug
> 1)
1178 fprintf_unfiltered (gdb_stdlog
,
1179 "Process record: record_end %s to "
1181 host_address_to_string (record_list
));
1183 if (first_record_end
&& execution_direction
== EXEC_REVERSE
)
1185 /* When reverse excute, the first record_end is the part of
1186 current instruction. */
1187 first_record_end
= 0;
1191 /* In EXEC_REVERSE mode, this is the record_end of prev
1193 In EXEC_FORWARD mode, this is the record_end of current
1196 if (record_resume_step
)
1198 if (record_debug
> 1)
1199 fprintf_unfiltered (gdb_stdlog
,
1200 "Process record: step.\n");
1204 /* check breakpoint */
1205 tmp_pc
= regcache_read_pc (regcache
);
1206 if (breakpoint_inserted_here_p (get_regcache_aspace (regcache
),
1210 fprintf_unfiltered (gdb_stdlog
,
1211 "Process record: break "
1213 paddress (gdbarch
, tmp_pc
));
1214 if (gdbarch_decr_pc_after_break (gdbarch
)
1215 && execution_direction
== EXEC_FORWARD
1216 && !record_resume_step
)
1217 regcache_write_pc (regcache
,
1219 gdbarch_decr_pc_after_break (gdbarch
));
1222 /* Check target signal */
1223 if (record_list
->u
.end
.sigval
!= TARGET_SIGNAL_0
)
1224 /* FIXME: better way to check */
1231 if (execution_direction
== EXEC_REVERSE
)
1233 if (record_list
->prev
)
1234 record_list
= record_list
->prev
;
1238 if (record_list
->next
)
1239 record_list
= record_list
->next
;
1243 while (continue_flag
);
1245 signal (SIGINT
, handle_sigint
);
1249 status
->value
.sig
= TARGET_SIGNAL_INT
;
1250 else if (record_list
->u
.end
.sigval
!= TARGET_SIGNAL_0
)
1251 /* FIXME: better way to check */
1252 status
->value
.sig
= record_list
->u
.end
.sigval
;
1254 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
1256 discard_cleanups (old_cleanups
);
1259 do_cleanups (set_cleanups
);
1260 return inferior_ptid
;
1263 /* "to_disconnect" method for process record target. */
1266 record_disconnect (struct target_ops
*target
, char *args
, int from_tty
)
1269 fprintf_unfiltered (gdb_stdlog
, "Process record: record_disconnect\n");
1271 unpush_target (&record_ops
);
1272 target_disconnect (args
, from_tty
);
1275 /* "to_detach" method for process record target. */
1278 record_detach (struct target_ops
*ops
, char *args
, int from_tty
)
1281 fprintf_unfiltered (gdb_stdlog
, "Process record: record_detach\n");
1283 unpush_target (&record_ops
);
1284 target_detach (args
, from_tty
);
1287 /* "to_mourn_inferior" method for process record target. */
1290 record_mourn_inferior (struct target_ops
*ops
)
1293 fprintf_unfiltered (gdb_stdlog
, "Process record: "
1294 "record_mourn_inferior\n");
1296 unpush_target (&record_ops
);
1297 target_mourn_inferior ();
1300 /* Close process record target before killing the inferior process. */
1303 record_kill (struct target_ops
*ops
)
1306 fprintf_unfiltered (gdb_stdlog
, "Process record: record_kill\n");
1308 unpush_target (&record_ops
);
1312 /* Record registers change (by user or by GDB) to list as an instruction. */
1315 record_registers_change (struct regcache
*regcache
, int regnum
)
1317 /* Check record_insn_num. */
1318 record_check_insn_num (0);
1320 record_arch_list_head
= NULL
;
1321 record_arch_list_tail
= NULL
;
1326 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
1328 if (record_arch_list_add_reg (regcache
, i
))
1330 record_list_release (record_arch_list_tail
);
1331 error (_("Process record: failed to record execution log."));
1337 if (record_arch_list_add_reg (regcache
, regnum
))
1339 record_list_release (record_arch_list_tail
);
1340 error (_("Process record: failed to record execution log."));
1343 if (record_arch_list_add_end ())
1345 record_list_release (record_arch_list_tail
);
1346 error (_("Process record: failed to record execution log."));
1348 record_list
->next
= record_arch_list_head
;
1349 record_arch_list_head
->prev
= record_list
;
1350 record_list
= record_arch_list_tail
;
1352 if (record_insn_num
== record_insn_max_num
&& record_insn_max_num
)
1353 record_list_release_first ();
1358 /* "to_store_registers" method for process record target. */
1361 record_store_registers (struct target_ops
*ops
, struct regcache
*regcache
,
1364 if (!record_gdb_operation_disable
)
1366 if (RECORD_IS_REPLAY
)
1370 /* Let user choose if he wants to write register or not. */
1373 query (_("Because GDB is in replay mode, changing the "
1374 "value of a register will make the execution "
1375 "log unusable from this point onward. "
1376 "Change all registers?"));
1379 query (_("Because GDB is in replay mode, changing the value "
1380 "of a register will make the execution log unusable "
1381 "from this point onward. Change register %s?"),
1382 gdbarch_register_name (get_regcache_arch (regcache
),
1387 /* Invalidate the value of regcache that was set in function
1388 "regcache_raw_write". */
1393 i
< gdbarch_num_regs (get_regcache_arch (regcache
));
1395 regcache_invalidate (regcache
, i
);
1398 regcache_invalidate (regcache
, regno
);
1400 error (_("Process record canceled the operation."));
1403 /* Destroy the record from here forward. */
1404 record_list_release_following (record_list
);
1407 record_registers_change (regcache
, regno
);
1409 record_beneath_to_store_registers (record_beneath_to_store_registers_ops
,
1413 /* "to_xfer_partial" method. Behavior is conditional on RECORD_IS_REPLAY.
1414 In replay mode, we cannot write memory unles we are willing to
1415 invalidate the record/replay log from this point forward. */
1418 record_xfer_partial (struct target_ops
*ops
, enum target_object object
,
1419 const char *annex
, gdb_byte
*readbuf
,
1420 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
1422 if (!record_gdb_operation_disable
1423 && (object
== TARGET_OBJECT_MEMORY
1424 || object
== TARGET_OBJECT_RAW_MEMORY
) && writebuf
)
1426 if (RECORD_IS_REPLAY
)
1428 /* Let user choose if he wants to write memory or not. */
1429 if (!query (_("Because GDB is in replay mode, writing to memory "
1430 "will make the execution log unusable from this "
1431 "point onward. Write memory at address %s?"),
1432 paddress (target_gdbarch
, offset
)))
1433 error (_("Process record canceled the operation."));
1435 /* Destroy the record from here forward. */
1436 record_list_release_following (record_list
);
1439 /* Check record_insn_num */
1440 record_check_insn_num (0);
1442 /* Record registers change to list as an instruction. */
1443 record_arch_list_head
= NULL
;
1444 record_arch_list_tail
= NULL
;
1445 if (record_arch_list_add_mem (offset
, len
))
1447 record_list_release (record_arch_list_tail
);
1449 fprintf_unfiltered (gdb_stdlog
,
1450 "Process record: failed to record "
1454 if (record_arch_list_add_end ())
1456 record_list_release (record_arch_list_tail
);
1458 fprintf_unfiltered (gdb_stdlog
,
1459 "Process record: failed to record "
1463 record_list
->next
= record_arch_list_head
;
1464 record_arch_list_head
->prev
= record_list
;
1465 record_list
= record_arch_list_tail
;
1467 if (record_insn_num
== record_insn_max_num
&& record_insn_max_num
)
1468 record_list_release_first ();
1473 return record_beneath_to_xfer_partial (record_beneath_to_xfer_partial_ops
,
1474 object
, annex
, readbuf
, writebuf
,
1478 /* Behavior is conditional on RECORD_IS_REPLAY.
1479 We will not actually insert or remove breakpoints when replaying,
1480 nor when recording. */
1483 record_insert_breakpoint (struct gdbarch
*gdbarch
,
1484 struct bp_target_info
*bp_tgt
)
1486 if (!RECORD_IS_REPLAY
)
1488 struct cleanup
*old_cleanups
= record_gdb_operation_disable_set ();
1489 int ret
= record_beneath_to_insert_breakpoint (gdbarch
, bp_tgt
);
1491 do_cleanups (old_cleanups
);
1499 /* "to_remove_breakpoint" method for process record target. */
1502 record_remove_breakpoint (struct gdbarch
*gdbarch
,
1503 struct bp_target_info
*bp_tgt
)
1505 if (!RECORD_IS_REPLAY
)
1507 struct cleanup
*old_cleanups
= record_gdb_operation_disable_set ();
1508 int ret
= record_beneath_to_remove_breakpoint (gdbarch
, bp_tgt
);
1510 do_cleanups (old_cleanups
);
1518 /* "to_can_execute_reverse" method for process record target. */
1521 record_can_execute_reverse (void)
1526 /* "to_get_bookmark" method for process record and prec over core. */
1529 record_get_bookmark (char *args
, int from_tty
)
1531 gdb_byte
*ret
= NULL
;
1533 /* Return stringified form of instruction count. */
1534 if (record_list
&& record_list
->type
== record_end
)
1535 ret
= xstrdup (pulongest (record_list
->u
.end
.insn_num
));
1540 fprintf_unfiltered (gdb_stdlog
,
1541 "record_get_bookmark returns %s\n", ret
);
1543 fprintf_unfiltered (gdb_stdlog
,
1544 "record_get_bookmark returns NULL\n");
1549 /* The implementation of the command "record goto". */
1550 static void cmd_record_goto (char *, int);
1552 /* "to_goto_bookmark" method for process record and prec over core. */
1555 record_goto_bookmark (gdb_byte
*bookmark
, int from_tty
)
1558 fprintf_unfiltered (gdb_stdlog
,
1559 "record_goto_bookmark receives %s\n", bookmark
);
1561 if (bookmark
[0] == '\'' || bookmark
[0] == '\"')
1563 if (bookmark
[strlen (bookmark
) - 1] != bookmark
[0])
1564 error (_("Unbalanced quotes: %s"), bookmark
);
1566 /* Strip trailing quote. */
1567 bookmark
[strlen (bookmark
) - 1] = '\0';
1568 /* Strip leading quote. */
1570 /* Pass along to cmd_record_goto. */
1573 cmd_record_goto ((char *) bookmark
, from_tty
);
1578 init_record_ops (void)
1580 record_ops
.to_shortname
= "record";
1581 record_ops
.to_longname
= "Process record and replay target";
1583 "Log program while executing and replay execution from log.";
1584 record_ops
.to_open
= record_open
;
1585 record_ops
.to_close
= record_close
;
1586 record_ops
.to_resume
= record_resume
;
1587 record_ops
.to_wait
= record_wait
;
1588 record_ops
.to_disconnect
= record_disconnect
;
1589 record_ops
.to_detach
= record_detach
;
1590 record_ops
.to_mourn_inferior
= record_mourn_inferior
;
1591 record_ops
.to_kill
= record_kill
;
1592 record_ops
.to_create_inferior
= find_default_create_inferior
;
1593 record_ops
.to_store_registers
= record_store_registers
;
1594 record_ops
.to_xfer_partial
= record_xfer_partial
;
1595 record_ops
.to_insert_breakpoint
= record_insert_breakpoint
;
1596 record_ops
.to_remove_breakpoint
= record_remove_breakpoint
;
1597 record_ops
.to_can_execute_reverse
= record_can_execute_reverse
;
1598 record_ops
.to_stratum
= record_stratum
;
1599 /* Add bookmark target methods. */
1600 record_ops
.to_get_bookmark
= record_get_bookmark
;
1601 record_ops
.to_goto_bookmark
= record_goto_bookmark
;
1602 record_ops
.to_magic
= OPS_MAGIC
;
1605 /* "to_resume" method for prec over corefile. */
1608 record_core_resume (struct target_ops
*ops
, ptid_t ptid
, int step
,
1609 enum target_signal signal
)
1611 record_resume_step
= step
;
1614 /* "to_kill" method for prec over corefile. */
1617 record_core_kill (struct target_ops
*ops
)
1620 fprintf_unfiltered (gdb_stdlog
, "Process record: record_core_kill\n");
1622 unpush_target (&record_core_ops
);
1625 /* "to_fetch_registers" method for prec over corefile. */
1628 record_core_fetch_registers (struct target_ops
*ops
,
1629 struct regcache
*regcache
,
1634 int num
= gdbarch_num_regs (get_regcache_arch (regcache
));
1637 for (i
= 0; i
< num
; i
++)
1638 regcache_raw_supply (regcache
, i
,
1639 record_core_regbuf
+ MAX_REGISTER_SIZE
* i
);
1642 regcache_raw_supply (regcache
, regno
,
1643 record_core_regbuf
+ MAX_REGISTER_SIZE
* regno
);
1646 /* "to_prepare_to_store" method for prec over corefile. */
1649 record_core_prepare_to_store (struct regcache
*regcache
)
1653 /* "to_store_registers" method for prec over corefile. */
1656 record_core_store_registers (struct target_ops
*ops
,
1657 struct regcache
*regcache
,
1660 if (record_gdb_operation_disable
)
1661 regcache_raw_collect (regcache
, regno
,
1662 record_core_regbuf
+ MAX_REGISTER_SIZE
* regno
);
1664 error (_("You can't do that without a process to debug."));
1667 /* "to_xfer_partial" method for prec over corefile. */
1670 record_core_xfer_partial (struct target_ops
*ops
, enum target_object object
,
1671 const char *annex
, gdb_byte
*readbuf
,
1672 const gdb_byte
*writebuf
, ULONGEST offset
,
1675 if (object
== TARGET_OBJECT_MEMORY
)
1677 if (record_gdb_operation_disable
|| !writebuf
)
1679 struct target_section
*p
;
1680 for (p
= record_core_start
; p
< record_core_end
; p
++)
1682 if (offset
>= p
->addr
)
1684 struct record_core_buf_entry
*entry
;
1685 ULONGEST sec_offset
;
1687 if (offset
>= p
->endaddr
)
1690 if (offset
+ len
> p
->endaddr
)
1691 len
= p
->endaddr
- offset
;
1693 sec_offset
= offset
- p
->addr
;
1695 /* Read readbuf or write writebuf p, offset, len. */
1697 if (p
->the_bfd_section
->flags
& SEC_CONSTRUCTOR
1698 || (p
->the_bfd_section
->flags
& SEC_HAS_CONTENTS
) == 0)
1701 memset (readbuf
, 0, len
);
1704 /* Get record_core_buf_entry. */
1705 for (entry
= record_core_buf_list
; entry
;
1706 entry
= entry
->prev
)
1713 /* Add a new entry. */
1715 = (struct record_core_buf_entry
*)
1717 (sizeof (struct record_core_buf_entry
));
1719 if (!bfd_malloc_and_get_section (p
->bfd
,
1726 entry
->prev
= record_core_buf_list
;
1727 record_core_buf_list
= entry
;
1730 memcpy (entry
->buf
+ sec_offset
, writebuf
,
1736 return record_beneath_to_xfer_partial
1737 (record_beneath_to_xfer_partial_ops
,
1738 object
, annex
, readbuf
, writebuf
,
1741 memcpy (readbuf
, entry
->buf
+ sec_offset
,
1752 error (_("You can't do that without a process to debug."));
1755 return record_beneath_to_xfer_partial (record_beneath_to_xfer_partial_ops
,
1756 object
, annex
, readbuf
, writebuf
,
1760 /* "to_insert_breakpoint" method for prec over corefile. */
1763 record_core_insert_breakpoint (struct gdbarch
*gdbarch
,
1764 struct bp_target_info
*bp_tgt
)
1769 /* "to_remove_breakpoint" method for prec over corefile. */
1772 record_core_remove_breakpoint (struct gdbarch
*gdbarch
,
1773 struct bp_target_info
*bp_tgt
)
1778 /* "to_has_execution" method for prec over corefile. */
1781 record_core_has_execution (struct target_ops
*ops
)
1787 init_record_core_ops (void)
1789 record_core_ops
.to_shortname
= "record_core";
1790 record_core_ops
.to_longname
= "Process record and replay target";
1791 record_core_ops
.to_doc
=
1792 "Log program while executing and replay execution from log.";
1793 record_core_ops
.to_open
= record_open
;
1794 record_core_ops
.to_close
= record_close
;
1795 record_core_ops
.to_resume
= record_core_resume
;
1796 record_core_ops
.to_wait
= record_wait
;
1797 record_core_ops
.to_kill
= record_core_kill
;
1798 record_core_ops
.to_fetch_registers
= record_core_fetch_registers
;
1799 record_core_ops
.to_prepare_to_store
= record_core_prepare_to_store
;
1800 record_core_ops
.to_store_registers
= record_core_store_registers
;
1801 record_core_ops
.to_xfer_partial
= record_core_xfer_partial
;
1802 record_core_ops
.to_insert_breakpoint
= record_core_insert_breakpoint
;
1803 record_core_ops
.to_remove_breakpoint
= record_core_remove_breakpoint
;
1804 record_core_ops
.to_can_execute_reverse
= record_can_execute_reverse
;
1805 record_core_ops
.to_has_execution
= record_core_has_execution
;
1806 record_core_ops
.to_stratum
= record_stratum
;
1807 /* Add bookmark target methods. */
1808 record_core_ops
.to_get_bookmark
= record_get_bookmark
;
1809 record_core_ops
.to_goto_bookmark
= record_goto_bookmark
;
1810 record_core_ops
.to_magic
= OPS_MAGIC
;
1813 /* Implement "show record debug" command. */
1816 show_record_debug (struct ui_file
*file
, int from_tty
,
1817 struct cmd_list_element
*c
, const char *value
)
1819 fprintf_filtered (file
, _("Debugging of process record target is %s.\n"),
1823 /* Alias for "target record". */
1826 cmd_record_start (char *args
, int from_tty
)
1828 execute_command ("target record", from_tty
);
1831 /* Truncate the record log from the present point
1832 of replay until the end. */
1835 cmd_record_delete (char *args
, int from_tty
)
1837 if (current_target
.to_stratum
== record_stratum
)
1839 if (RECORD_IS_REPLAY
)
1841 if (!from_tty
|| query (_("Delete the log from this point forward "
1842 "and begin to record the running message "
1844 record_list_release_following (record_list
);
1847 printf_unfiltered (_("Already at end of record list.\n"));
1851 printf_unfiltered (_("Process record is not started.\n"));
1854 /* Implement the "stoprecord" or "record stop" command. */
1857 cmd_record_stop (char *args
, int from_tty
)
1859 if (current_target
.to_stratum
== record_stratum
)
1861 unpush_target (&record_ops
);
1862 printf_unfiltered (_("Process record is stopped and all execution "
1863 "logs are deleted.\n"));
1866 printf_unfiltered (_("Process record is not started.\n"));
1869 /* Set upper limit of record log size. */
1872 set_record_insn_max_num (char *args
, int from_tty
, struct cmd_list_element
*c
)
1874 if (record_insn_num
> record_insn_max_num
&& record_insn_max_num
)
1876 /* Count down record_insn_num while releasing records from list. */
1877 while (record_insn_num
> record_insn_max_num
)
1879 record_list_release_first ();
1885 static struct cmd_list_element
*record_cmdlist
, *set_record_cmdlist
,
1886 *show_record_cmdlist
, *info_record_cmdlist
;
1889 set_record_command (char *args
, int from_tty
)
1891 printf_unfiltered (_("\
1892 \"set record\" must be followed by an apporpriate subcommand.\n"));
1893 help_list (set_record_cmdlist
, "set record ", all_commands
, gdb_stdout
);
1897 show_record_command (char *args
, int from_tty
)
1899 cmd_show_list (show_record_cmdlist
, from_tty
, "");
1902 /* Display some statistics about the execution log. */
1905 info_record_command (char *args
, int from_tty
)
1907 struct record_entry
*p
;
1909 if (current_target
.to_stratum
== record_stratum
)
1911 if (RECORD_IS_REPLAY
)
1912 printf_filtered (_("Replay mode:\n"));
1914 printf_filtered (_("Record mode:\n"));
1916 /* Find entry for first actual instruction in the log. */
1917 for (p
= record_first
.next
;
1918 p
!= NULL
&& p
->type
!= record_end
;
1922 /* Do we have a log at all? */
1923 if (p
!= NULL
&& p
->type
== record_end
)
1925 /* Display instruction number for first instruction in the log. */
1926 printf_filtered (_("Lowest recorded instruction number is %s.\n"),
1927 pulongest (p
->u
.end
.insn_num
));
1929 /* If in replay mode, display where we are in the log. */
1930 if (RECORD_IS_REPLAY
)
1931 printf_filtered (_("Current instruction number is %s.\n"),
1932 pulongest (record_list
->u
.end
.insn_num
));
1934 /* Display instruction number for last instruction in the log. */
1935 printf_filtered (_("Highest recorded instruction number is %s.\n"),
1936 pulongest (record_insn_count
));
1938 /* Display log count. */
1939 printf_filtered (_("Log contains %d instructions.\n"),
1944 printf_filtered (_("No instructions have been logged.\n"));
1949 printf_filtered (_("target record is not active.\n"));
1952 /* Display max log size. */
1953 printf_filtered (_("Max logged instructions is %d.\n"),
1954 record_insn_max_num
);
1957 /* Record log save-file format
1958 Version 1 (never released)
1961 4 bytes: magic number htonl(0x20090829).
1962 NOTE: be sure to change whenever this file format changes!
1966 1 byte: record type (record_end, see enum record_type).
1968 1 byte: record type (record_reg, see enum record_type).
1969 8 bytes: register id (network byte order).
1970 MAX_REGISTER_SIZE bytes: register value.
1972 1 byte: record type (record_mem, see enum record_type).
1973 8 bytes: memory length (network byte order).
1974 8 bytes: memory address (network byte order).
1975 n bytes: memory value (n == memory length).
1978 4 bytes: magic number netorder32(0x20091016).
1979 NOTE: be sure to change whenever this file format changes!
1983 1 byte: record type (record_end, see enum record_type).
1985 4 bytes: instruction count
1987 1 byte: record type (record_reg, see enum record_type).
1988 4 bytes: register id (network byte order).
1989 n bytes: register value (n == actual register size).
1990 (eg. 4 bytes for x86 general registers).
1992 1 byte: record type (record_mem, see enum record_type).
1993 4 bytes: memory length (network byte order).
1994 8 bytes: memory address (network byte order).
1995 n bytes: memory value (n == memory length).
1999 /* bfdcore_read -- read bytes from a core file section. */
2002 bfdcore_read (bfd
*obfd
, asection
*osec
, void *buf
, int len
, int *offset
)
2004 int ret
= bfd_get_section_contents (obfd
, osec
, buf
, *offset
, len
);
2009 error (_("Failed to read %d bytes from core file %s ('%s').\n"),
2010 len
, bfd_get_filename (obfd
),
2011 bfd_errmsg (bfd_get_error ()));
2014 static inline uint64_t
2015 netorder64 (uint64_t input
)
2019 store_unsigned_integer ((gdb_byte
*) &ret
, sizeof (ret
),
2020 BFD_ENDIAN_BIG
, input
);
2024 static inline uint32_t
2025 netorder32 (uint32_t input
)
2029 store_unsigned_integer ((gdb_byte
*) &ret
, sizeof (ret
),
2030 BFD_ENDIAN_BIG
, input
);
2034 static inline uint16_t
2035 netorder16 (uint16_t input
)
2039 store_unsigned_integer ((gdb_byte
*) &ret
, sizeof (ret
),
2040 BFD_ENDIAN_BIG
, input
);
2044 /* Restore the execution log from a core_bfd file. */
2046 record_restore (void)
2049 struct cleanup
*old_cleanups
;
2050 struct record_entry
*rec
;
2054 struct regcache
*regcache
;
2056 /* We restore the execution log from the open core bfd,
2058 if (core_bfd
== NULL
)
2061 /* "record_restore" can only be called when record list is empty. */
2062 gdb_assert (record_first
.next
== NULL
);
2065 fprintf_unfiltered (gdb_stdlog
, "Restoring recording from core file.\n");
2067 /* Now need to find our special note section. */
2068 osec
= bfd_get_section_by_name (core_bfd
, "null0");
2069 osec_size
= bfd_section_size (core_bfd
, osec
);
2071 fprintf_unfiltered (gdb_stdlog
, "Find precord section %s.\n",
2072 osec
? "succeeded" : "failed");
2076 fprintf_unfiltered (gdb_stdlog
, "%s", bfd_section_name (core_bfd
, osec
));
2078 /* Check the magic code. */
2079 bfdcore_read (core_bfd
, osec
, &magic
, sizeof (magic
), &bfd_offset
);
2080 if (magic
!= RECORD_FILE_MAGIC
)
2081 error (_("Version mis-match or file format error in core file %s."),
2082 bfd_get_filename (core_bfd
));
2084 fprintf_unfiltered (gdb_stdlog
, "\
2085 Reading 4-byte magic cookie RECORD_FILE_MAGIC (0x%s)\n",
2086 phex_nz (netorder32 (magic
), 4));
2088 /* Restore the entries in recfd into record_arch_list_head and
2089 record_arch_list_tail. */
2090 record_arch_list_head
= NULL
;
2091 record_arch_list_tail
= NULL
;
2092 record_insn_num
= 0;
2093 old_cleanups
= make_cleanup (record_arch_list_cleanups
, 0);
2094 regcache
= get_current_regcache ();
2100 uint32_t regnum
, len
, signal
, count
;
2103 /* We are finished when offset reaches osec_size. */
2104 if (bfd_offset
>= osec_size
)
2106 bfdcore_read (core_bfd
, osec
, &tmpu8
, sizeof (tmpu8
), &bfd_offset
);
2110 case record_reg
: /* reg */
2111 /* Get register number to regnum. */
2112 bfdcore_read (core_bfd
, osec
, ®num
,
2113 sizeof (regnum
), &bfd_offset
);
2114 regnum
= netorder32 (regnum
);
2116 rec
= record_reg_alloc (regcache
, regnum
);
2119 bfdcore_read (core_bfd
, osec
, record_get_loc (rec
),
2120 rec
->u
.reg
.len
, &bfd_offset
);
2123 fprintf_unfiltered (gdb_stdlog
, "\
2124 Reading register %d (1 plus %lu plus %d bytes)\n",
2126 (unsigned long) sizeof (regnum
),
2130 case record_mem
: /* mem */
2132 bfdcore_read (core_bfd
, osec
, &len
,
2133 sizeof (len
), &bfd_offset
);
2134 len
= netorder32 (len
);
2137 bfdcore_read (core_bfd
, osec
, &addr
,
2138 sizeof (addr
), &bfd_offset
);
2139 addr
= netorder64 (addr
);
2141 rec
= record_mem_alloc (addr
, len
);
2144 bfdcore_read (core_bfd
, osec
, record_get_loc (rec
),
2145 rec
->u
.mem
.len
, &bfd_offset
);
2148 fprintf_unfiltered (gdb_stdlog
, "\
2149 Reading memory %s (1 plus %lu plus %lu plus %d bytes)\n",
2150 paddress (get_current_arch (),
2152 (unsigned long) sizeof (addr
),
2153 (unsigned long) sizeof (len
),
2157 case record_end
: /* end */
2158 rec
= record_end_alloc ();
2161 /* Get signal value. */
2162 bfdcore_read (core_bfd
, osec
, &signal
,
2163 sizeof (signal
), &bfd_offset
);
2164 signal
= netorder32 (signal
);
2165 rec
->u
.end
.sigval
= signal
;
2167 /* Get insn count. */
2168 bfdcore_read (core_bfd
, osec
, &count
,
2169 sizeof (count
), &bfd_offset
);
2170 count
= netorder32 (count
);
2171 rec
->u
.end
.insn_num
= count
;
2172 record_insn_count
= count
+ 1;
2174 fprintf_unfiltered (gdb_stdlog
, "\
2175 Reading record_end (1 + %lu + %lu bytes), offset == %s\n",
2176 (unsigned long) sizeof (signal
),
2177 (unsigned long) sizeof (count
),
2178 paddress (get_current_arch (),
2183 error (_("Bad entry type in core file %s."),
2184 bfd_get_filename (core_bfd
));
2188 /* Add rec to record arch list. */
2189 record_arch_list_add (rec
);
2192 discard_cleanups (old_cleanups
);
2194 /* Add record_arch_list_head to the end of record list. */
2195 record_first
.next
= record_arch_list_head
;
2196 record_arch_list_head
->prev
= &record_first
;
2197 record_arch_list_tail
->next
= NULL
;
2198 record_list
= &record_first
;
2200 /* Update record_insn_max_num. */
2201 if (record_insn_num
> record_insn_max_num
)
2203 record_insn_max_num
= record_insn_num
;
2204 warning (_("Auto increase record/replay buffer limit to %d."),
2205 record_insn_max_num
);
2209 printf_filtered (_("Restored records from core file %s.\n"),
2210 bfd_get_filename (core_bfd
));
2212 print_stack_frame (get_selected_frame (NULL
), 1, SRC_AND_LOC
);
2215 /* bfdcore_write -- write bytes into a core file section. */
2218 bfdcore_write (bfd
*obfd
, asection
*osec
, void *buf
, int len
, int *offset
)
2220 int ret
= bfd_set_section_contents (obfd
, osec
, buf
, *offset
, len
);
2225 error (_("Failed to write %d bytes to core file %s ('%s').\n"),
2226 len
, bfd_get_filename (obfd
),
2227 bfd_errmsg (bfd_get_error ()));
2230 /* Restore the execution log from a file. We use a modified elf
2231 corefile format, with an extra section for our data. */
2234 cmd_record_restore (char *args
, int from_tty
)
2236 core_file_command (args
, from_tty
);
2237 record_open (args
, from_tty
);
2241 record_save_cleanups (void *data
)
2244 char *pathname
= xstrdup (bfd_get_filename (obfd
));
2250 /* Save the execution log to a file. We use a modified elf corefile
2251 format, with an extra section for our data. */
2254 cmd_record_save (char *args
, int from_tty
)
2256 char *recfilename
, recfilename_buffer
[40];
2258 struct record_entry
*cur_record_list
;
2260 struct regcache
*regcache
;
2261 struct gdbarch
*gdbarch
;
2262 struct cleanup
*old_cleanups
;
2263 struct cleanup
*set_cleanups
;
2266 asection
*osec
= NULL
;
2269 if (strcmp (current_target
.to_shortname
, "record") != 0)
2270 error (_("This command can only be used with target 'record'.\n"
2271 "Use 'target record' first.\n"));
2277 /* Default recfile name is "gdb_record.PID". */
2278 snprintf (recfilename_buffer
, sizeof (recfilename_buffer
),
2279 "gdb_record.%d", PIDGET (inferior_ptid
));
2280 recfilename
= recfilename_buffer
;
2283 /* Open the save file. */
2285 fprintf_unfiltered (gdb_stdlog
, "Saving execution log to core file '%s'\n",
2288 /* Open the output file. */
2289 obfd
= create_gcore_bfd (recfilename
);
2290 old_cleanups
= make_cleanup (record_save_cleanups
, obfd
);
2292 /* Save the current record entry to "cur_record_list". */
2293 cur_record_list
= record_list
;
2295 /* Get the values of regcache and gdbarch. */
2296 regcache
= get_current_regcache ();
2297 gdbarch
= get_regcache_arch (regcache
);
2299 /* Disable the GDB operation record. */
2300 set_cleanups
= record_gdb_operation_disable_set ();
2302 /* Reverse execute to the begin of record list. */
2305 /* Check for beginning and end of log. */
2306 if (record_list
== &record_first
)
2309 record_exec_insn (regcache
, gdbarch
, record_list
);
2311 if (record_list
->prev
)
2312 record_list
= record_list
->prev
;
2315 /* Compute the size needed for the extra bfd section. */
2316 save_size
= 4; /* magic cookie */
2317 for (record_list
= record_first
.next
; record_list
;
2318 record_list
= record_list
->next
)
2319 switch (record_list
->type
)
2322 save_size
+= 1 + 4 + 4;
2325 save_size
+= 1 + 4 + record_list
->u
.reg
.len
;
2328 save_size
+= 1 + 4 + 8 + record_list
->u
.mem
.len
;
2332 /* Make the new bfd section. */
2333 osec
= bfd_make_section_anyway_with_flags (obfd
, "precord",
2337 error (_("Failed to create 'precord' section for corefile %s: %s"),
2339 bfd_errmsg (bfd_get_error ()));
2340 bfd_set_section_size (obfd
, osec
, save_size
);
2341 bfd_set_section_vma (obfd
, osec
, 0);
2342 bfd_set_section_alignment (obfd
, osec
, 0);
2343 bfd_section_lma (obfd
, osec
) = 0;
2345 /* Save corefile state. */
2346 write_gcore_file (obfd
);
2348 /* Write out the record log. */
2349 /* Write the magic code. */
2350 magic
= RECORD_FILE_MAGIC
;
2352 fprintf_unfiltered (gdb_stdlog
, "\
2353 Writing 4-byte magic cookie RECORD_FILE_MAGIC (0x%s)\n",
2354 phex_nz (magic
, 4));
2355 bfdcore_write (obfd
, osec
, &magic
, sizeof (magic
), &bfd_offset
);
2357 /* Save the entries to recfd and forward execute to the end of
2359 record_list
= &record_first
;
2363 if (record_list
!= &record_first
)
2366 uint32_t regnum
, len
, signal
, count
;
2369 type
= record_list
->type
;
2370 bfdcore_write (obfd
, osec
, &type
, sizeof (type
), &bfd_offset
);
2372 switch (record_list
->type
)
2374 case record_reg
: /* reg */
2376 fprintf_unfiltered (gdb_stdlog
, "\
2377 Writing register %d (1 plus %lu plus %d bytes)\n",
2378 record_list
->u
.reg
.num
,
2379 (unsigned long) sizeof (regnum
),
2380 record_list
->u
.reg
.len
);
2383 regnum
= netorder32 (record_list
->u
.reg
.num
);
2384 bfdcore_write (obfd
, osec
, ®num
,
2385 sizeof (regnum
), &bfd_offset
);
2388 bfdcore_write (obfd
, osec
, record_get_loc (record_list
),
2389 record_list
->u
.reg
.len
, &bfd_offset
);
2392 case record_mem
: /* mem */
2394 fprintf_unfiltered (gdb_stdlog
, "\
2395 Writing memory %s (1 plus %lu plus %lu plus %d bytes)\n",
2397 record_list
->u
.mem
.addr
),
2398 (unsigned long) sizeof (addr
),
2399 (unsigned long) sizeof (len
),
2400 record_list
->u
.mem
.len
);
2403 len
= netorder32 (record_list
->u
.mem
.len
);
2404 bfdcore_write (obfd
, osec
, &len
, sizeof (len
), &bfd_offset
);
2406 /* Write memaddr. */
2407 addr
= netorder64 (record_list
->u
.mem
.addr
);
2408 bfdcore_write (obfd
, osec
, &addr
,
2409 sizeof (addr
), &bfd_offset
);
2412 bfdcore_write (obfd
, osec
, record_get_loc (record_list
),
2413 record_list
->u
.mem
.len
, &bfd_offset
);
2418 fprintf_unfiltered (gdb_stdlog
, "\
2419 Writing record_end (1 + %lu + %lu bytes)\n",
2420 (unsigned long) sizeof (signal
),
2421 (unsigned long) sizeof (count
));
2422 /* Write signal value. */
2423 signal
= netorder32 (record_list
->u
.end
.sigval
);
2424 bfdcore_write (obfd
, osec
, &signal
,
2425 sizeof (signal
), &bfd_offset
);
2427 /* Write insn count. */
2428 count
= netorder32 (record_list
->u
.end
.insn_num
);
2429 bfdcore_write (obfd
, osec
, &count
,
2430 sizeof (count
), &bfd_offset
);
2435 /* Execute entry. */
2436 record_exec_insn (regcache
, gdbarch
, record_list
);
2438 if (record_list
->next
)
2439 record_list
= record_list
->next
;
2444 /* Reverse execute to cur_record_list. */
2447 /* Check for beginning and end of log. */
2448 if (record_list
== cur_record_list
)
2451 record_exec_insn (regcache
, gdbarch
, record_list
);
2453 if (record_list
->prev
)
2454 record_list
= record_list
->prev
;
2457 do_cleanups (set_cleanups
);
2459 discard_cleanups (old_cleanups
);
2462 printf_filtered (_("Saved core file %s with execution log.\n"),
2466 /* record_goto_insn -- rewind the record log (forward or backward,
2467 depending on DIR) to the given entry, changing the program state
2471 record_goto_insn (struct record_entry
*entry
,
2472 enum exec_direction_kind dir
)
2474 struct cleanup
*set_cleanups
= record_gdb_operation_disable_set ();
2475 struct regcache
*regcache
= get_current_regcache ();
2476 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
2478 /* Assume everything is valid: we will hit the entry,
2479 and we will not hit the end of the recording. */
2481 if (dir
== EXEC_FORWARD
)
2482 record_list
= record_list
->next
;
2486 record_exec_insn (regcache
, gdbarch
, record_list
);
2487 if (dir
== EXEC_REVERSE
)
2488 record_list
= record_list
->prev
;
2490 record_list
= record_list
->next
;
2491 } while (record_list
!= entry
);
2492 do_cleanups (set_cleanups
);
2495 /* "record goto" command. Argument is an instruction number,
2496 as given by "info record".
2498 Rewinds the recording (forward or backward) to the given instruction. */
2501 cmd_record_goto (char *arg
, int from_tty
)
2503 struct record_entry
*p
= NULL
;
2504 ULONGEST target_insn
= 0;
2506 if (arg
== NULL
|| *arg
== '\0')
2507 error (_("Command requires an argument (insn number to go to)."));
2509 if (strncmp (arg
, "start", strlen ("start")) == 0
2510 || strncmp (arg
, "begin", strlen ("begin")) == 0)
2512 /* Special case. Find first insn. */
2513 for (p
= &record_first
; p
!= NULL
; p
= p
->next
)
2514 if (p
->type
== record_end
)
2517 target_insn
= p
->u
.end
.insn_num
;
2519 else if (strncmp (arg
, "end", strlen ("end")) == 0)
2521 /* Special case. Find last insn. */
2522 for (p
= record_list
; p
->next
!= NULL
; p
= p
->next
)
2524 for (; p
!= NULL
; p
= p
->prev
)
2525 if (p
->type
== record_end
)
2528 target_insn
= p
->u
.end
.insn_num
;
2532 /* General case. Find designated insn. */
2533 target_insn
= parse_and_eval_long (arg
);
2535 for (p
= &record_first
; p
!= NULL
; p
= p
->next
)
2536 if (p
->type
== record_end
&& p
->u
.end
.insn_num
== target_insn
)
2541 error (_("Target insn '%s' not found."), arg
);
2542 else if (p
== record_list
)
2543 error (_("Already at insn '%s'."), arg
);
2544 else if (p
->u
.end
.insn_num
> record_list
->u
.end
.insn_num
)
2546 printf_filtered (_("Go forward to insn number %s\n"),
2547 pulongest (target_insn
));
2548 record_goto_insn (p
, EXEC_FORWARD
);
2552 printf_filtered (_("Go backward to insn number %s\n"),
2553 pulongest (target_insn
));
2554 record_goto_insn (p
, EXEC_REVERSE
);
2556 registers_changed ();
2557 reinit_frame_cache ();
2558 print_stack_frame (get_selected_frame (NULL
), 1, SRC_AND_LOC
);
2562 _initialize_record (void)
2564 struct cmd_list_element
*c
;
2566 /* Init record_first. */
2567 record_first
.prev
= NULL
;
2568 record_first
.next
= NULL
;
2569 record_first
.type
= record_end
;
2572 add_target (&record_ops
);
2573 init_record_core_ops ();
2574 add_target (&record_core_ops
);
2576 add_setshow_zinteger_cmd ("record", no_class
, &record_debug
,
2577 _("Set debugging of record/replay feature."),
2578 _("Show debugging of record/replay feature."),
2579 _("When enabled, debugging output for "
2580 "record/replay feature is displayed."),
2581 NULL
, show_record_debug
, &setdebuglist
,
2584 c
= add_prefix_cmd ("record", class_obscure
, cmd_record_start
,
2585 _("Abbreviated form of \"target record\" command."),
2586 &record_cmdlist
, "record ", 0, &cmdlist
);
2587 set_cmd_completer (c
, filename_completer
);
2589 add_com_alias ("rec", "record", class_obscure
, 1);
2590 add_prefix_cmd ("record", class_support
, set_record_command
,
2591 _("Set record options"), &set_record_cmdlist
,
2592 "set record ", 0, &setlist
);
2593 add_alias_cmd ("rec", "record", class_obscure
, 1, &setlist
);
2594 add_prefix_cmd ("record", class_support
, show_record_command
,
2595 _("Show record options"), &show_record_cmdlist
,
2596 "show record ", 0, &showlist
);
2597 add_alias_cmd ("rec", "record", class_obscure
, 1, &showlist
);
2598 add_prefix_cmd ("record", class_support
, info_record_command
,
2599 _("Info record options"), &info_record_cmdlist
,
2600 "info record ", 0, &infolist
);
2601 add_alias_cmd ("rec", "record", class_obscure
, 1, &infolist
);
2603 c
= add_cmd ("save", class_obscure
, cmd_record_save
,
2604 _("Save the execution log to a file.\n\
2605 Argument is optional filename.\n\
2606 Default filename is 'gdb_record.<process_id>'."),
2608 set_cmd_completer (c
, filename_completer
);
2610 c
= add_cmd ("restore", class_obscure
, cmd_record_restore
,
2611 _("Restore the execution log from a file.\n\
2612 Argument is filename. File must be created with 'record save'."),
2614 set_cmd_completer (c
, filename_completer
);
2616 add_cmd ("delete", class_obscure
, cmd_record_delete
,
2617 _("Delete the rest of execution log and start recording it anew."),
2619 add_alias_cmd ("d", "delete", class_obscure
, 1, &record_cmdlist
);
2620 add_alias_cmd ("del", "delete", class_obscure
, 1, &record_cmdlist
);
2622 add_cmd ("stop", class_obscure
, cmd_record_stop
,
2623 _("Stop the record/replay target."),
2625 add_alias_cmd ("s", "stop", class_obscure
, 1, &record_cmdlist
);
2627 /* Record instructions number limit command. */
2628 add_setshow_boolean_cmd ("stop-at-limit", no_class
,
2629 &record_stop_at_limit
, _("\
2630 Set whether record/replay stops when record/replay buffer becomes full."), _("\
2631 Show whether record/replay stops when record/replay buffer becomes full."), _("\
2633 When ON, if the record/replay buffer becomes full, ask user what to do.\n\
2634 When OFF, if the record/replay buffer becomes full,\n\
2635 delete the oldest recorded instruction to make room for each new one."),
2637 &set_record_cmdlist
, &show_record_cmdlist
);
2638 add_setshow_uinteger_cmd ("insn-number-max", no_class
,
2639 &record_insn_max_num
,
2640 _("Set record/replay buffer limit."),
2641 _("Show record/replay buffer limit."), _("\
2642 Set the maximum number of instructions to be stored in the\n\
2643 record/replay buffer. Zero means unlimited. Default is 200000."),
2644 set_record_insn_max_num
,
2645 NULL
, &set_record_cmdlist
, &show_record_cmdlist
);
2647 add_cmd ("goto", class_obscure
, cmd_record_goto
, _("\
2648 Restore the program to its state at instruction number N.\n\
2649 Argument is instruction number, as shown by 'info record'."),