1 /* Process record and replay target for GDB, the GNU debugger.
3 Copyright (C) 2008, 2009, 2010 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
*);
227 static int (*record_beneath_to_stopped_by_watchpoint
) (void);
228 static int (*record_beneath_to_stopped_data_address
) (struct target_ops
*,
231 /* Alloc and free functions for record_reg, record_mem, and record_end
234 /* Alloc a record_reg record entry. */
236 static inline struct record_entry
*
237 record_reg_alloc (struct regcache
*regcache
, int regnum
)
239 struct record_entry
*rec
;
240 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
242 rec
= (struct record_entry
*) xcalloc (1, sizeof (struct record_entry
));
243 rec
->type
= record_reg
;
244 rec
->u
.reg
.num
= regnum
;
245 rec
->u
.reg
.len
= register_size (gdbarch
, regnum
);
246 if (rec
->u
.reg
.len
> sizeof (rec
->u
.reg
.u
.buf
))
247 rec
->u
.reg
.u
.ptr
= (gdb_byte
*) xmalloc (rec
->u
.reg
.len
);
252 /* Free a record_reg record entry. */
255 record_reg_release (struct record_entry
*rec
)
257 gdb_assert (rec
->type
== record_reg
);
258 if (rec
->u
.reg
.len
> sizeof (rec
->u
.reg
.u
.buf
))
259 xfree (rec
->u
.reg
.u
.ptr
);
263 /* Alloc a record_mem record entry. */
265 static inline struct record_entry
*
266 record_mem_alloc (CORE_ADDR addr
, int len
)
268 struct record_entry
*rec
;
270 rec
= (struct record_entry
*) xcalloc (1, sizeof (struct record_entry
));
271 rec
->type
= record_mem
;
272 rec
->u
.mem
.addr
= addr
;
273 rec
->u
.mem
.len
= len
;
274 if (rec
->u
.mem
.len
> sizeof (rec
->u
.mem
.u
.buf
))
275 rec
->u
.mem
.u
.ptr
= (gdb_byte
*) xmalloc (len
);
280 /* Free a record_mem record entry. */
283 record_mem_release (struct record_entry
*rec
)
285 gdb_assert (rec
->type
== record_mem
);
286 if (rec
->u
.mem
.len
> sizeof (rec
->u
.mem
.u
.buf
))
287 xfree (rec
->u
.mem
.u
.ptr
);
291 /* Alloc a record_end record entry. */
293 static inline struct record_entry
*
294 record_end_alloc (void)
296 struct record_entry
*rec
;
298 rec
= (struct record_entry
*) xcalloc (1, sizeof (struct record_entry
));
299 rec
->type
= record_end
;
304 /* Free a record_end record entry. */
307 record_end_release (struct record_entry
*rec
)
312 /* Free one record entry, any type.
313 Return entry->type, in case caller wants to know. */
315 static inline enum record_type
316 record_entry_release (struct record_entry
*rec
)
318 enum record_type type
= rec
->type
;
322 record_reg_release (rec
);
325 record_mem_release (rec
);
328 record_end_release (rec
);
334 /* Free all record entries in list pointed to by REC. */
337 record_list_release (struct record_entry
*rec
)
348 record_entry_release (rec
->next
);
351 if (rec
== &record_first
)
354 record_first
.next
= NULL
;
357 record_entry_release (rec
);
360 /* Free all record entries forward of the given list position. */
363 record_list_release_following (struct record_entry
*rec
)
365 struct record_entry
*tmp
= rec
->next
;
371 if (record_entry_release (tmp
) == record_end
)
380 /* Delete the first instruction from the beginning of the log, to make
381 room for adding a new instruction at the end of the log.
383 Note -- this function does not modify record_insn_num. */
386 record_list_release_first (void)
388 struct record_entry
*tmp
;
390 if (!record_first
.next
)
393 /* Loop until a record_end. */
396 /* Cut record_first.next out of the linked list. */
397 tmp
= record_first
.next
;
398 record_first
.next
= tmp
->next
;
399 tmp
->next
->prev
= &record_first
;
401 /* tmp is now isolated, and can be deleted. */
402 if (record_entry_release (tmp
) == record_end
)
403 break; /* End loop at first record_end. */
405 if (!record_first
.next
)
407 gdb_assert (record_insn_num
== 1);
408 break; /* End loop when list is empty. */
413 /* Add a struct record_entry to record_arch_list. */
416 record_arch_list_add (struct record_entry
*rec
)
418 if (record_debug
> 1)
419 fprintf_unfiltered (gdb_stdlog
,
420 "Process record: record_arch_list_add %s.\n",
421 host_address_to_string (rec
));
423 if (record_arch_list_tail
)
425 record_arch_list_tail
->next
= rec
;
426 rec
->prev
= record_arch_list_tail
;
427 record_arch_list_tail
= rec
;
431 record_arch_list_head
= rec
;
432 record_arch_list_tail
= rec
;
436 /* Return the value storage location of a record entry. */
437 static inline gdb_byte
*
438 record_get_loc (struct record_entry
*rec
)
442 if (rec
->u
.mem
.len
> sizeof (rec
->u
.mem
.u
.buf
))
443 return rec
->u
.mem
.u
.ptr
;
445 return rec
->u
.mem
.u
.buf
;
447 if (rec
->u
.reg
.len
> sizeof (rec
->u
.reg
.u
.buf
))
448 return rec
->u
.reg
.u
.ptr
;
450 return rec
->u
.reg
.u
.buf
;
458 /* Record the value of a register NUM to record_arch_list. */
461 record_arch_list_add_reg (struct regcache
*regcache
, int regnum
)
463 struct record_entry
*rec
;
465 if (record_debug
> 1)
466 fprintf_unfiltered (gdb_stdlog
,
467 "Process record: add register num = %d to "
471 rec
= record_reg_alloc (regcache
, regnum
);
473 regcache_raw_read (regcache
, regnum
, record_get_loc (rec
));
475 record_arch_list_add (rec
);
480 /* Record the value of a region of memory whose address is ADDR and
481 length is LEN to record_arch_list. */
484 record_arch_list_add_mem (CORE_ADDR addr
, int len
)
486 struct record_entry
*rec
;
488 if (record_debug
> 1)
489 fprintf_unfiltered (gdb_stdlog
,
490 "Process record: add mem addr = %s len = %d to "
492 paddress (target_gdbarch
, addr
), len
);
494 if (!addr
) /* FIXME: Why? Some arch must permit it... */
497 rec
= record_mem_alloc (addr
, len
);
499 if (target_read_memory (addr
, record_get_loc (rec
), len
))
502 fprintf_unfiltered (gdb_stdlog
,
503 "Process record: error reading memory at "
504 "addr = %s len = %d.\n",
505 paddress (target_gdbarch
, addr
), len
);
506 record_mem_release (rec
);
510 record_arch_list_add (rec
);
515 /* Add a record_end type struct record_entry to record_arch_list. */
518 record_arch_list_add_end (void)
520 struct record_entry
*rec
;
522 if (record_debug
> 1)
523 fprintf_unfiltered (gdb_stdlog
,
524 "Process record: add end to arch list.\n");
526 rec
= record_end_alloc ();
527 rec
->u
.end
.sigval
= TARGET_SIGNAL_0
;
528 rec
->u
.end
.insn_num
= ++record_insn_count
;
530 record_arch_list_add (rec
);
536 record_check_insn_num (int set_terminal
)
538 if (record_insn_max_num
)
540 gdb_assert (record_insn_num
<= record_insn_max_num
);
541 if (record_insn_num
== record_insn_max_num
)
543 /* Ask user what to do. */
544 if (record_stop_at_limit
)
548 target_terminal_ours ();
549 q
= yquery (_("Do you want to auto delete previous execution "
550 "log entries when record/replay buffer becomes "
551 "full (record stop-at-limit)?"));
553 target_terminal_inferior ();
555 record_stop_at_limit
= 0;
557 error (_("Process record: stopped by user."));
564 record_arch_list_cleanups (void *ignore
)
566 record_list_release (record_arch_list_tail
);
569 /* Before inferior step (when GDB record the running message, inferior
570 only can step), GDB will call this function to record the values to
571 record_list. This function will call gdbarch_process_record to
572 record the running message of inferior and set them to
573 record_arch_list, and add it to record_list. */
576 record_message (struct regcache
*regcache
, enum target_signal signal
)
579 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
580 struct cleanup
*old_cleanups
= make_cleanup (record_arch_list_cleanups
, 0);
582 record_arch_list_head
= NULL
;
583 record_arch_list_tail
= NULL
;
585 /* Check record_insn_num. */
586 record_check_insn_num (1);
588 /* If gdb sends a signal value to target_resume,
589 save it in the 'end' field of the previous instruction.
591 Maybe process record should record what really happened,
592 rather than what gdb pretends has happened.
594 So if Linux delivered the signal to the child process during
595 the record mode, we will record it and deliver it again in
598 If user says "ignore this signal" during the record mode, then
599 it will be ignored again during the replay mode (no matter if
600 the user says something different, like "deliver this signal"
601 during the replay mode).
603 User should understand that nothing he does during the replay
604 mode will change the behavior of the child. If he tries,
605 then that is a user error.
607 But we should still deliver the signal to gdb during the replay,
608 if we delivered it during the recording. Therefore we should
609 record the signal during record_wait, not record_resume. */
610 if (record_list
!= &record_first
) /* FIXME better way to check */
612 gdb_assert (record_list
->type
== record_end
);
613 record_list
->u
.end
.sigval
= signal
;
616 if (signal
== TARGET_SIGNAL_0
617 || !gdbarch_process_record_signal_p (gdbarch
))
618 ret
= gdbarch_process_record (gdbarch
,
620 regcache_read_pc (regcache
));
622 ret
= gdbarch_process_record_signal (gdbarch
,
627 error (_("Process record: inferior program stopped."));
629 error (_("Process record: failed to record execution log."));
631 discard_cleanups (old_cleanups
);
633 record_list
->next
= record_arch_list_head
;
634 record_arch_list_head
->prev
= record_list
;
635 record_list
= record_arch_list_tail
;
637 if (record_insn_num
== record_insn_max_num
&& record_insn_max_num
)
638 record_list_release_first ();
645 struct record_message_args
{
646 struct regcache
*regcache
;
647 enum target_signal signal
;
651 record_message_wrapper (void *args
)
653 struct record_message_args
*record_args
= args
;
655 return record_message (record_args
->regcache
, record_args
->signal
);
659 record_message_wrapper_safe (struct regcache
*regcache
,
660 enum target_signal signal
)
662 struct record_message_args args
;
664 args
.regcache
= regcache
;
665 args
.signal
= signal
;
667 return catch_errors (record_message_wrapper
, &args
, NULL
, RETURN_MASK_ALL
);
670 /* Set to 1 if record_store_registers and record_xfer_partial
671 doesn't need record. */
673 static int record_gdb_operation_disable
= 0;
676 record_gdb_operation_disable_set (void)
678 struct cleanup
*old_cleanups
= NULL
;
681 make_cleanup_restore_integer (&record_gdb_operation_disable
);
682 record_gdb_operation_disable
= 1;
687 /* Flag set to TRUE for target_stopped_by_watchpoint. */
688 static int record_hw_watchpoint
= 0;
690 /* Execute one instruction from the record log. Each instruction in
691 the log will be represented by an arbitrary sequence of register
692 entries and memory entries, followed by an 'end' entry. */
695 record_exec_insn (struct regcache
*regcache
, struct gdbarch
*gdbarch
,
696 struct record_entry
*entry
)
700 case record_reg
: /* reg */
702 gdb_byte reg
[MAX_REGISTER_SIZE
];
704 if (record_debug
> 1)
705 fprintf_unfiltered (gdb_stdlog
,
706 "Process record: record_reg %s to "
707 "inferior num = %d.\n",
708 host_address_to_string (entry
),
711 regcache_cooked_read (regcache
, entry
->u
.reg
.num
, reg
);
712 regcache_cooked_write (regcache
, entry
->u
.reg
.num
,
713 record_get_loc (entry
));
714 memcpy (record_get_loc (entry
), reg
, entry
->u
.reg
.len
);
718 case record_mem
: /* mem */
720 /* Nothing to do if the entry is flagged not_accessible. */
721 if (!entry
->u
.mem
.mem_entry_not_accessible
)
723 gdb_byte
*mem
= alloca (entry
->u
.mem
.len
);
725 if (record_debug
> 1)
726 fprintf_unfiltered (gdb_stdlog
,
727 "Process record: record_mem %s to "
728 "inferior addr = %s len = %d.\n",
729 host_address_to_string (entry
),
730 paddress (gdbarch
, entry
->u
.mem
.addr
),
733 if (target_read_memory (entry
->u
.mem
.addr
, mem
, entry
->u
.mem
.len
))
735 entry
->u
.mem
.mem_entry_not_accessible
= 1;
737 warning ("Process record: error reading memory at "
738 "addr = %s len = %d.",
739 paddress (gdbarch
, entry
->u
.mem
.addr
),
744 if (target_write_memory (entry
->u
.mem
.addr
,
745 record_get_loc (entry
),
748 entry
->u
.mem
.mem_entry_not_accessible
= 1;
750 warning ("Process record: error writing memory at "
751 "addr = %s len = %d.",
752 paddress (gdbarch
, entry
->u
.mem
.addr
),
757 memcpy (record_get_loc (entry
), mem
, entry
->u
.mem
.len
);
759 /* We've changed memory --- check if a hardware
760 watchpoint should trap. Note that this
761 presently assumes the target beneath supports
762 continuable watchpoints. On non-continuable
763 watchpoints target, we'll want to check this
764 _before_ actually doing the memory change, and
765 not doing the change at all if the watchpoint
767 if (hardware_watchpoint_inserted_in_range
768 (get_regcache_aspace (regcache
),
769 entry
->u
.mem
.addr
, entry
->u
.mem
.len
))
770 record_hw_watchpoint
= 1;
779 static struct target_ops
*tmp_to_resume_ops
;
780 static void (*tmp_to_resume
) (struct target_ops
*, ptid_t
, int,
782 static struct target_ops
*tmp_to_wait_ops
;
783 static ptid_t (*tmp_to_wait
) (struct target_ops
*, ptid_t
,
784 struct target_waitstatus
*,
786 static struct target_ops
*tmp_to_store_registers_ops
;
787 static void (*tmp_to_store_registers
) (struct target_ops
*,
790 static struct target_ops
*tmp_to_xfer_partial_ops
;
791 static LONGEST (*tmp_to_xfer_partial
) (struct target_ops
*ops
,
792 enum target_object object
,
795 const gdb_byte
*writebuf
,
798 static int (*tmp_to_insert_breakpoint
) (struct gdbarch
*,
799 struct bp_target_info
*);
800 static int (*tmp_to_remove_breakpoint
) (struct gdbarch
*,
801 struct bp_target_info
*);
802 static int (*tmp_to_stopped_by_watchpoint
) (void);
803 static int (*tmp_to_stopped_data_address
) (struct target_ops
*, CORE_ADDR
*);
805 static void record_restore (void);
807 /* Open the process record target. */
810 record_core_open_1 (char *name
, int from_tty
)
812 struct regcache
*regcache
= get_current_regcache ();
813 int regnum
= gdbarch_num_regs (get_regcache_arch (regcache
));
816 /* Get record_core_regbuf. */
817 target_fetch_registers (regcache
, -1);
818 record_core_regbuf
= xmalloc (MAX_REGISTER_SIZE
* regnum
);
819 for (i
= 0; i
< regnum
; i
++)
820 regcache_raw_collect (regcache
, i
,
821 record_core_regbuf
+ MAX_REGISTER_SIZE
* i
);
823 /* Get record_core_start and record_core_end. */
824 if (build_section_table (core_bfd
, &record_core_start
, &record_core_end
))
826 xfree (record_core_regbuf
);
827 record_core_regbuf
= NULL
;
828 error (_("\"%s\": Can't find sections: %s"),
829 bfd_get_filename (core_bfd
), bfd_errmsg (bfd_get_error ()));
832 push_target (&record_core_ops
);
836 /* "to_open" target method for 'live' processes. */
839 record_open_1 (char *name
, int from_tty
)
841 struct target_ops
*t
;
844 fprintf_unfiltered (gdb_stdlog
, "Process record: record_open\n");
847 if (!target_has_execution
)
848 error (_("Process record: the program is not being run."));
850 error (_("Process record target can't debug inferior in non-stop mode "
852 if (target_async_permitted
)
853 error (_("Process record target can't debug inferior in asynchronous "
854 "mode (target-async)."));
856 if (!gdbarch_process_record_p (target_gdbarch
))
857 error (_("Process record: the current architecture doesn't support "
858 "record function."));
861 error (_("Could not find 'to_resume' method on the target stack."));
863 error (_("Could not find 'to_wait' method on the target stack."));
864 if (!tmp_to_store_registers
)
865 error (_("Could not find 'to_store_registers' method on the target stack."));
866 if (!tmp_to_insert_breakpoint
)
867 error (_("Could not find 'to_insert_breakpoint' method on the target stack."));
868 if (!tmp_to_remove_breakpoint
)
869 error (_("Could not find 'to_remove_breakpoint' method on the target stack."));
871 push_target (&record_ops
);
874 /* "to_open" target method. Open the process record target. */
877 record_open (char *name
, int from_tty
)
879 struct target_ops
*t
;
882 fprintf_unfiltered (gdb_stdlog
, "Process record: record_open\n");
884 /* Check if record target is already running. */
885 if (current_target
.to_stratum
== record_stratum
)
886 error (_("Process record target already running. Use \"record stop\" to "
887 "stop record target first."));
889 /* Reset the tmp beneath pointers. */
890 tmp_to_resume_ops
= NULL
;
891 tmp_to_resume
= NULL
;
892 tmp_to_wait_ops
= NULL
;
894 tmp_to_store_registers_ops
= NULL
;
895 tmp_to_store_registers
= NULL
;
896 tmp_to_xfer_partial_ops
= NULL
;
897 tmp_to_xfer_partial
= NULL
;
898 tmp_to_insert_breakpoint
= NULL
;
899 tmp_to_remove_breakpoint
= NULL
;
901 /* Set the beneath function pointers. */
902 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
906 tmp_to_resume
= t
->to_resume
;
907 tmp_to_resume_ops
= t
;
911 tmp_to_wait
= t
->to_wait
;
914 if (!tmp_to_store_registers
)
916 tmp_to_store_registers
= t
->to_store_registers
;
917 tmp_to_store_registers_ops
= t
;
919 if (!tmp_to_xfer_partial
)
921 tmp_to_xfer_partial
= t
->to_xfer_partial
;
922 tmp_to_xfer_partial_ops
= t
;
924 if (!tmp_to_insert_breakpoint
)
925 tmp_to_insert_breakpoint
= t
->to_insert_breakpoint
;
926 if (!tmp_to_remove_breakpoint
)
927 tmp_to_remove_breakpoint
= t
->to_remove_breakpoint
;
928 if (!tmp_to_stopped_by_watchpoint
)
929 tmp_to_stopped_by_watchpoint
= t
->to_stopped_by_watchpoint
;
930 if (!tmp_to_stopped_data_address
)
931 tmp_to_stopped_data_address
= t
->to_stopped_data_address
;
933 if (!tmp_to_xfer_partial
)
934 error (_("Could not find 'to_xfer_partial' method on the target stack."));
938 record_insn_count
= 0;
939 record_list
= &record_first
;
940 record_list
->next
= NULL
;
942 /* Set the tmp beneath pointers to beneath pointers. */
943 record_beneath_to_resume_ops
= tmp_to_resume_ops
;
944 record_beneath_to_resume
= tmp_to_resume
;
945 record_beneath_to_wait_ops
= tmp_to_wait_ops
;
946 record_beneath_to_wait
= tmp_to_wait
;
947 record_beneath_to_store_registers_ops
= tmp_to_store_registers_ops
;
948 record_beneath_to_store_registers
= tmp_to_store_registers
;
949 record_beneath_to_xfer_partial_ops
= tmp_to_xfer_partial_ops
;
950 record_beneath_to_xfer_partial
= tmp_to_xfer_partial
;
951 record_beneath_to_insert_breakpoint
= tmp_to_insert_breakpoint
;
952 record_beneath_to_remove_breakpoint
= tmp_to_remove_breakpoint
;
953 record_beneath_to_stopped_by_watchpoint
= tmp_to_stopped_by_watchpoint
;
954 record_beneath_to_stopped_data_address
= tmp_to_stopped_data_address
;
956 if (current_target
.to_stratum
== core_stratum
)
957 record_core_open_1 (name
, from_tty
);
959 record_open_1 (name
, from_tty
);
962 /* "to_close" target method. Close the process record target. */
965 record_close (int quitting
)
967 struct record_core_buf_entry
*entry
;
970 fprintf_unfiltered (gdb_stdlog
, "Process record: record_close\n");
972 record_list_release (record_list
);
974 /* Release record_core_regbuf. */
975 if (record_core_regbuf
)
977 xfree (record_core_regbuf
);
978 record_core_regbuf
= NULL
;
981 /* Release record_core_buf_list. */
982 if (record_core_buf_list
)
984 for (entry
= record_core_buf_list
->prev
; entry
; entry
= entry
->prev
)
986 xfree (record_core_buf_list
);
987 record_core_buf_list
= entry
;
989 record_core_buf_list
= NULL
;
993 static int record_resume_step
= 0;
995 /* "to_resume" target method. Resume the process record target. */
998 record_resume (struct target_ops
*ops
, ptid_t ptid
, int step
,
999 enum target_signal signal
)
1001 record_resume_step
= step
;
1003 if (!RECORD_IS_REPLAY
)
1005 record_message (get_current_regcache (), signal
);
1006 record_beneath_to_resume (record_beneath_to_resume_ops
, ptid
, 1,
1011 static int record_get_sig
= 0;
1013 /* SIGINT signal handler, registered by "to_wait" method. */
1016 record_sig_handler (int signo
)
1019 fprintf_unfiltered (gdb_stdlog
, "Process record: get a signal\n");
1021 /* It will break the running inferior in replay mode. */
1022 record_resume_step
= 1;
1024 /* It will let record_wait set inferior status to get the signal
1030 record_wait_cleanups (void *ignore
)
1032 if (execution_direction
== EXEC_REVERSE
)
1034 if (record_list
->next
)
1035 record_list
= record_list
->next
;
1038 record_list
= record_list
->prev
;
1041 /* "to_wait" target method for process record target.
1043 In record mode, the target is always run in singlestep mode
1044 (even when gdb says to continue). The to_wait method intercepts
1045 the stop events and determines which ones are to be passed on to
1046 gdb. Most stop events are just singlestep events that gdb is not
1047 to know about, so the to_wait method just records them and keeps
1050 In replay mode, this function emulates the recorded execution log,
1051 one instruction at a time (forward or backward), and determines
1055 record_wait (struct target_ops
*ops
,
1056 ptid_t ptid
, struct target_waitstatus
*status
,
1059 struct cleanup
*set_cleanups
= record_gdb_operation_disable_set ();
1062 fprintf_unfiltered (gdb_stdlog
,
1063 "Process record: record_wait "
1064 "record_resume_step = %d\n",
1065 record_resume_step
);
1067 if (!RECORD_IS_REPLAY
&& ops
!= &record_core_ops
)
1069 if (record_resume_step
)
1071 /* This is a single step. */
1072 return record_beneath_to_wait (record_beneath_to_wait_ops
,
1073 ptid
, status
, options
);
1077 /* This is not a single step. */
1083 ret
= record_beneath_to_wait (record_beneath_to_wait_ops
,
1084 ptid
, status
, options
);
1086 /* Is this a SIGTRAP? */
1087 if (status
->kind
== TARGET_WAITKIND_STOPPED
1088 && status
->value
.sig
== TARGET_SIGNAL_TRAP
)
1090 struct regcache
*regcache
;
1091 struct address_space
*aspace
;
1093 /* Yes -- this is likely our single-step finishing,
1094 but check if there's any reason the core would be
1095 interested in the event. */
1097 registers_changed ();
1098 regcache
= get_current_regcache ();
1099 tmp_pc
= regcache_read_pc (regcache
);
1100 aspace
= get_regcache_aspace (regcache
);
1102 if (target_stopped_by_watchpoint ())
1104 /* Always interested in watchpoints. */
1106 else if (breakpoint_inserted_here_p (aspace
, tmp_pc
))
1108 /* There is a breakpoint here. Let the core
1110 if (software_breakpoint_inserted_here_p (aspace
, tmp_pc
))
1112 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1113 CORE_ADDR decr_pc_after_break
1114 = gdbarch_decr_pc_after_break (gdbarch
);
1115 if (decr_pc_after_break
)
1116 regcache_write_pc (regcache
,
1117 tmp_pc
+ decr_pc_after_break
);
1122 /* This must be a single-step trap. Record the
1123 insn and issue another step. */
1124 if (!record_message_wrapper_safe (regcache
,
1127 status
->kind
= TARGET_WAITKIND_STOPPED
;
1128 status
->value
.sig
= TARGET_SIGNAL_0
;
1132 record_beneath_to_resume (record_beneath_to_resume_ops
,
1139 /* The inferior is broken by a breakpoint or a signal. */
1148 struct regcache
*regcache
= get_current_regcache ();
1149 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1150 struct address_space
*aspace
= get_regcache_aspace (regcache
);
1151 int continue_flag
= 1;
1152 int first_record_end
= 1;
1153 struct cleanup
*old_cleanups
= make_cleanup (record_wait_cleanups
, 0);
1156 record_hw_watchpoint
= 0;
1157 status
->kind
= TARGET_WAITKIND_STOPPED
;
1159 /* Check breakpoint when forward execute. */
1160 if (execution_direction
== EXEC_FORWARD
)
1162 tmp_pc
= regcache_read_pc (regcache
);
1163 if (breakpoint_inserted_here_p (aspace
, tmp_pc
))
1165 int decr_pc_after_break
= gdbarch_decr_pc_after_break (gdbarch
);
1168 fprintf_unfiltered (gdb_stdlog
,
1169 "Process record: break at %s.\n",
1170 paddress (gdbarch
, tmp_pc
));
1172 if (decr_pc_after_break
1173 && !record_resume_step
1174 && software_breakpoint_inserted_here_p (aspace
, tmp_pc
))
1175 regcache_write_pc (regcache
,
1176 tmp_pc
+ decr_pc_after_break
);
1182 signal (SIGINT
, record_sig_handler
);
1183 /* If GDB is in terminal_inferior mode, it will not get the signal.
1184 And in GDB replay mode, GDB doesn't need to be in terminal_inferior
1185 mode, because inferior will not executed.
1186 Then set it to terminal_ours to make GDB get the signal. */
1187 target_terminal_ours ();
1189 /* In EXEC_FORWARD mode, record_list points to the tail of prev
1191 if (execution_direction
== EXEC_FORWARD
&& record_list
->next
)
1192 record_list
= record_list
->next
;
1194 /* Loop over the record_list, looking for the next place to
1198 /* Check for beginning and end of log. */
1199 if (execution_direction
== EXEC_REVERSE
1200 && record_list
== &record_first
)
1202 /* Hit beginning of record log in reverse. */
1203 status
->kind
= TARGET_WAITKIND_NO_HISTORY
;
1206 if (execution_direction
!= EXEC_REVERSE
&& !record_list
->next
)
1208 /* Hit end of record log going forward. */
1209 status
->kind
= TARGET_WAITKIND_NO_HISTORY
;
1213 record_exec_insn (regcache
, gdbarch
, record_list
);
1215 if (record_list
->type
== record_end
)
1217 if (record_debug
> 1)
1218 fprintf_unfiltered (gdb_stdlog
,
1219 "Process record: record_end %s to "
1221 host_address_to_string (record_list
));
1223 if (first_record_end
&& execution_direction
== EXEC_REVERSE
)
1225 /* When reverse excute, the first record_end is the part of
1226 current instruction. */
1227 first_record_end
= 0;
1231 /* In EXEC_REVERSE mode, this is the record_end of prev
1233 In EXEC_FORWARD mode, this is the record_end of current
1236 if (record_resume_step
)
1238 if (record_debug
> 1)
1239 fprintf_unfiltered (gdb_stdlog
,
1240 "Process record: step.\n");
1244 /* check breakpoint */
1245 tmp_pc
= regcache_read_pc (regcache
);
1246 if (breakpoint_inserted_here_p (aspace
, tmp_pc
))
1248 int decr_pc_after_break
1249 = gdbarch_decr_pc_after_break (gdbarch
);
1252 fprintf_unfiltered (gdb_stdlog
,
1253 "Process record: break "
1255 paddress (gdbarch
, tmp_pc
));
1256 if (decr_pc_after_break
1257 && execution_direction
== EXEC_FORWARD
1258 && !record_resume_step
1259 && software_breakpoint_inserted_here_p (aspace
,
1261 regcache_write_pc (regcache
,
1262 tmp_pc
+ decr_pc_after_break
);
1266 if (record_hw_watchpoint
)
1269 fprintf_unfiltered (gdb_stdlog
, "\
1270 Process record: hit hw watchpoint.\n");
1273 /* Check target signal */
1274 if (record_list
->u
.end
.sigval
!= TARGET_SIGNAL_0
)
1275 /* FIXME: better way to check */
1282 if (execution_direction
== EXEC_REVERSE
)
1284 if (record_list
->prev
)
1285 record_list
= record_list
->prev
;
1289 if (record_list
->next
)
1290 record_list
= record_list
->next
;
1294 while (continue_flag
);
1296 signal (SIGINT
, handle_sigint
);
1300 status
->value
.sig
= TARGET_SIGNAL_INT
;
1301 else if (record_list
->u
.end
.sigval
!= TARGET_SIGNAL_0
)
1302 /* FIXME: better way to check */
1303 status
->value
.sig
= record_list
->u
.end
.sigval
;
1305 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
1307 discard_cleanups (old_cleanups
);
1310 do_cleanups (set_cleanups
);
1311 return inferior_ptid
;
1315 record_stopped_by_watchpoint (void)
1317 if (RECORD_IS_REPLAY
)
1318 return record_hw_watchpoint
;
1320 return record_beneath_to_stopped_by_watchpoint ();
1324 record_stopped_data_address (struct target_ops
*ops
, CORE_ADDR
*addr_p
)
1326 if (RECORD_IS_REPLAY
)
1329 return record_beneath_to_stopped_data_address (ops
, addr_p
);
1332 /* "to_disconnect" method for process record target. */
1335 record_disconnect (struct target_ops
*target
, char *args
, int from_tty
)
1338 fprintf_unfiltered (gdb_stdlog
, "Process record: record_disconnect\n");
1340 unpush_target (&record_ops
);
1341 target_disconnect (args
, from_tty
);
1344 /* "to_detach" method for process record target. */
1347 record_detach (struct target_ops
*ops
, char *args
, int from_tty
)
1350 fprintf_unfiltered (gdb_stdlog
, "Process record: record_detach\n");
1352 unpush_target (&record_ops
);
1353 target_detach (args
, from_tty
);
1356 /* "to_mourn_inferior" method for process record target. */
1359 record_mourn_inferior (struct target_ops
*ops
)
1362 fprintf_unfiltered (gdb_stdlog
, "Process record: "
1363 "record_mourn_inferior\n");
1365 unpush_target (&record_ops
);
1366 target_mourn_inferior ();
1369 /* Close process record target before killing the inferior process. */
1372 record_kill (struct target_ops
*ops
)
1375 fprintf_unfiltered (gdb_stdlog
, "Process record: record_kill\n");
1377 unpush_target (&record_ops
);
1381 /* Record registers change (by user or by GDB) to list as an instruction. */
1384 record_registers_change (struct regcache
*regcache
, int regnum
)
1386 /* Check record_insn_num. */
1387 record_check_insn_num (0);
1389 record_arch_list_head
= NULL
;
1390 record_arch_list_tail
= NULL
;
1395 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
1397 if (record_arch_list_add_reg (regcache
, i
))
1399 record_list_release (record_arch_list_tail
);
1400 error (_("Process record: failed to record execution log."));
1406 if (record_arch_list_add_reg (regcache
, regnum
))
1408 record_list_release (record_arch_list_tail
);
1409 error (_("Process record: failed to record execution log."));
1412 if (record_arch_list_add_end ())
1414 record_list_release (record_arch_list_tail
);
1415 error (_("Process record: failed to record execution log."));
1417 record_list
->next
= record_arch_list_head
;
1418 record_arch_list_head
->prev
= record_list
;
1419 record_list
= record_arch_list_tail
;
1421 if (record_insn_num
== record_insn_max_num
&& record_insn_max_num
)
1422 record_list_release_first ();
1427 /* "to_store_registers" method for process record target. */
1430 record_store_registers (struct target_ops
*ops
, struct regcache
*regcache
,
1433 if (!record_gdb_operation_disable
)
1435 if (RECORD_IS_REPLAY
)
1439 /* Let user choose if he wants to write register or not. */
1442 query (_("Because GDB is in replay mode, changing the "
1443 "value of a register will make the execution "
1444 "log unusable from this point onward. "
1445 "Change all registers?"));
1448 query (_("Because GDB is in replay mode, changing the value "
1449 "of a register will make the execution log unusable "
1450 "from this point onward. Change register %s?"),
1451 gdbarch_register_name (get_regcache_arch (regcache
),
1456 /* Invalidate the value of regcache that was set in function
1457 "regcache_raw_write". */
1462 i
< gdbarch_num_regs (get_regcache_arch (regcache
));
1464 regcache_invalidate (regcache
, i
);
1467 regcache_invalidate (regcache
, regno
);
1469 error (_("Process record canceled the operation."));
1472 /* Destroy the record from here forward. */
1473 record_list_release_following (record_list
);
1476 record_registers_change (regcache
, regno
);
1478 record_beneath_to_store_registers (record_beneath_to_store_registers_ops
,
1482 /* "to_xfer_partial" method. Behavior is conditional on RECORD_IS_REPLAY.
1483 In replay mode, we cannot write memory unles we are willing to
1484 invalidate the record/replay log from this point forward. */
1487 record_xfer_partial (struct target_ops
*ops
, enum target_object object
,
1488 const char *annex
, gdb_byte
*readbuf
,
1489 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
1491 if (!record_gdb_operation_disable
1492 && (object
== TARGET_OBJECT_MEMORY
1493 || object
== TARGET_OBJECT_RAW_MEMORY
) && writebuf
)
1495 if (RECORD_IS_REPLAY
)
1497 /* Let user choose if he wants to write memory or not. */
1498 if (!query (_("Because GDB is in replay mode, writing to memory "
1499 "will make the execution log unusable from this "
1500 "point onward. Write memory at address %s?"),
1501 paddress (target_gdbarch
, offset
)))
1502 error (_("Process record canceled the operation."));
1504 /* Destroy the record from here forward. */
1505 record_list_release_following (record_list
);
1508 /* Check record_insn_num */
1509 record_check_insn_num (0);
1511 /* Record registers change to list as an instruction. */
1512 record_arch_list_head
= NULL
;
1513 record_arch_list_tail
= NULL
;
1514 if (record_arch_list_add_mem (offset
, len
))
1516 record_list_release (record_arch_list_tail
);
1518 fprintf_unfiltered (gdb_stdlog
,
1519 "Process record: failed to record "
1523 if (record_arch_list_add_end ())
1525 record_list_release (record_arch_list_tail
);
1527 fprintf_unfiltered (gdb_stdlog
,
1528 "Process record: failed to record "
1532 record_list
->next
= record_arch_list_head
;
1533 record_arch_list_head
->prev
= record_list
;
1534 record_list
= record_arch_list_tail
;
1536 if (record_insn_num
== record_insn_max_num
&& record_insn_max_num
)
1537 record_list_release_first ();
1542 return record_beneath_to_xfer_partial (record_beneath_to_xfer_partial_ops
,
1543 object
, annex
, readbuf
, writebuf
,
1547 /* Behavior is conditional on RECORD_IS_REPLAY.
1548 We will not actually insert or remove breakpoints when replaying,
1549 nor when recording. */
1552 record_insert_breakpoint (struct gdbarch
*gdbarch
,
1553 struct bp_target_info
*bp_tgt
)
1555 if (!RECORD_IS_REPLAY
)
1557 struct cleanup
*old_cleanups
= record_gdb_operation_disable_set ();
1558 int ret
= record_beneath_to_insert_breakpoint (gdbarch
, bp_tgt
);
1560 do_cleanups (old_cleanups
);
1568 /* "to_remove_breakpoint" method for process record target. */
1571 record_remove_breakpoint (struct gdbarch
*gdbarch
,
1572 struct bp_target_info
*bp_tgt
)
1574 if (!RECORD_IS_REPLAY
)
1576 struct cleanup
*old_cleanups
= record_gdb_operation_disable_set ();
1577 int ret
= record_beneath_to_remove_breakpoint (gdbarch
, bp_tgt
);
1579 do_cleanups (old_cleanups
);
1587 /* "to_can_execute_reverse" method for process record target. */
1590 record_can_execute_reverse (void)
1595 /* "to_get_bookmark" method for process record and prec over core. */
1598 record_get_bookmark (char *args
, int from_tty
)
1600 gdb_byte
*ret
= NULL
;
1602 /* Return stringified form of instruction count. */
1603 if (record_list
&& record_list
->type
== record_end
)
1604 ret
= xstrdup (pulongest (record_list
->u
.end
.insn_num
));
1609 fprintf_unfiltered (gdb_stdlog
,
1610 "record_get_bookmark returns %s\n", ret
);
1612 fprintf_unfiltered (gdb_stdlog
,
1613 "record_get_bookmark returns NULL\n");
1618 /* The implementation of the command "record goto". */
1619 static void cmd_record_goto (char *, int);
1621 /* "to_goto_bookmark" method for process record and prec over core. */
1624 record_goto_bookmark (gdb_byte
*bookmark
, int from_tty
)
1627 fprintf_unfiltered (gdb_stdlog
,
1628 "record_goto_bookmark receives %s\n", bookmark
);
1630 if (bookmark
[0] == '\'' || bookmark
[0] == '\"')
1632 if (bookmark
[strlen (bookmark
) - 1] != bookmark
[0])
1633 error (_("Unbalanced quotes: %s"), bookmark
);
1635 /* Strip trailing quote. */
1636 bookmark
[strlen (bookmark
) - 1] = '\0';
1637 /* Strip leading quote. */
1639 /* Pass along to cmd_record_goto. */
1642 cmd_record_goto ((char *) bookmark
, from_tty
);
1647 init_record_ops (void)
1649 record_ops
.to_shortname
= "record";
1650 record_ops
.to_longname
= "Process record and replay target";
1652 "Log program while executing and replay execution from log.";
1653 record_ops
.to_open
= record_open
;
1654 record_ops
.to_close
= record_close
;
1655 record_ops
.to_resume
= record_resume
;
1656 record_ops
.to_wait
= record_wait
;
1657 record_ops
.to_disconnect
= record_disconnect
;
1658 record_ops
.to_detach
= record_detach
;
1659 record_ops
.to_mourn_inferior
= record_mourn_inferior
;
1660 record_ops
.to_kill
= record_kill
;
1661 record_ops
.to_create_inferior
= find_default_create_inferior
;
1662 record_ops
.to_store_registers
= record_store_registers
;
1663 record_ops
.to_xfer_partial
= record_xfer_partial
;
1664 record_ops
.to_insert_breakpoint
= record_insert_breakpoint
;
1665 record_ops
.to_remove_breakpoint
= record_remove_breakpoint
;
1666 record_ops
.to_stopped_by_watchpoint
= record_stopped_by_watchpoint
;
1667 record_ops
.to_stopped_data_address
= record_stopped_data_address
;
1668 record_ops
.to_can_execute_reverse
= record_can_execute_reverse
;
1669 record_ops
.to_stratum
= record_stratum
;
1670 /* Add bookmark target methods. */
1671 record_ops
.to_get_bookmark
= record_get_bookmark
;
1672 record_ops
.to_goto_bookmark
= record_goto_bookmark
;
1673 record_ops
.to_magic
= OPS_MAGIC
;
1676 /* "to_resume" method for prec over corefile. */
1679 record_core_resume (struct target_ops
*ops
, ptid_t ptid
, int step
,
1680 enum target_signal signal
)
1682 record_resume_step
= step
;
1685 /* "to_kill" method for prec over corefile. */
1688 record_core_kill (struct target_ops
*ops
)
1691 fprintf_unfiltered (gdb_stdlog
, "Process record: record_core_kill\n");
1693 unpush_target (&record_core_ops
);
1696 /* "to_fetch_registers" method for prec over corefile. */
1699 record_core_fetch_registers (struct target_ops
*ops
,
1700 struct regcache
*regcache
,
1705 int num
= gdbarch_num_regs (get_regcache_arch (regcache
));
1708 for (i
= 0; i
< num
; i
++)
1709 regcache_raw_supply (regcache
, i
,
1710 record_core_regbuf
+ MAX_REGISTER_SIZE
* i
);
1713 regcache_raw_supply (regcache
, regno
,
1714 record_core_regbuf
+ MAX_REGISTER_SIZE
* regno
);
1717 /* "to_prepare_to_store" method for prec over corefile. */
1720 record_core_prepare_to_store (struct regcache
*regcache
)
1724 /* "to_store_registers" method for prec over corefile. */
1727 record_core_store_registers (struct target_ops
*ops
,
1728 struct regcache
*regcache
,
1731 if (record_gdb_operation_disable
)
1732 regcache_raw_collect (regcache
, regno
,
1733 record_core_regbuf
+ MAX_REGISTER_SIZE
* regno
);
1735 error (_("You can't do that without a process to debug."));
1738 /* "to_xfer_partial" method for prec over corefile. */
1741 record_core_xfer_partial (struct target_ops
*ops
, enum target_object object
,
1742 const char *annex
, gdb_byte
*readbuf
,
1743 const gdb_byte
*writebuf
, ULONGEST offset
,
1746 if (object
== TARGET_OBJECT_MEMORY
)
1748 if (record_gdb_operation_disable
|| !writebuf
)
1750 struct target_section
*p
;
1751 for (p
= record_core_start
; p
< record_core_end
; p
++)
1753 if (offset
>= p
->addr
)
1755 struct record_core_buf_entry
*entry
;
1756 ULONGEST sec_offset
;
1758 if (offset
>= p
->endaddr
)
1761 if (offset
+ len
> p
->endaddr
)
1762 len
= p
->endaddr
- offset
;
1764 sec_offset
= offset
- p
->addr
;
1766 /* Read readbuf or write writebuf p, offset, len. */
1768 if (p
->the_bfd_section
->flags
& SEC_CONSTRUCTOR
1769 || (p
->the_bfd_section
->flags
& SEC_HAS_CONTENTS
) == 0)
1772 memset (readbuf
, 0, len
);
1775 /* Get record_core_buf_entry. */
1776 for (entry
= record_core_buf_list
; entry
;
1777 entry
= entry
->prev
)
1784 /* Add a new entry. */
1786 = (struct record_core_buf_entry
*)
1788 (sizeof (struct record_core_buf_entry
));
1790 if (!bfd_malloc_and_get_section (p
->bfd
,
1797 entry
->prev
= record_core_buf_list
;
1798 record_core_buf_list
= entry
;
1801 memcpy (entry
->buf
+ sec_offset
, writebuf
,
1807 return record_beneath_to_xfer_partial
1808 (record_beneath_to_xfer_partial_ops
,
1809 object
, annex
, readbuf
, writebuf
,
1812 memcpy (readbuf
, entry
->buf
+ sec_offset
,
1823 error (_("You can't do that without a process to debug."));
1826 return record_beneath_to_xfer_partial (record_beneath_to_xfer_partial_ops
,
1827 object
, annex
, readbuf
, writebuf
,
1831 /* "to_insert_breakpoint" method for prec over corefile. */
1834 record_core_insert_breakpoint (struct gdbarch
*gdbarch
,
1835 struct bp_target_info
*bp_tgt
)
1840 /* "to_remove_breakpoint" method for prec over corefile. */
1843 record_core_remove_breakpoint (struct gdbarch
*gdbarch
,
1844 struct bp_target_info
*bp_tgt
)
1849 /* "to_has_execution" method for prec over corefile. */
1852 record_core_has_execution (struct target_ops
*ops
)
1858 init_record_core_ops (void)
1860 record_core_ops
.to_shortname
= "record_core";
1861 record_core_ops
.to_longname
= "Process record and replay target";
1862 record_core_ops
.to_doc
=
1863 "Log program while executing and replay execution from log.";
1864 record_core_ops
.to_open
= record_open
;
1865 record_core_ops
.to_close
= record_close
;
1866 record_core_ops
.to_resume
= record_core_resume
;
1867 record_core_ops
.to_wait
= record_wait
;
1868 record_core_ops
.to_kill
= record_core_kill
;
1869 record_core_ops
.to_fetch_registers
= record_core_fetch_registers
;
1870 record_core_ops
.to_prepare_to_store
= record_core_prepare_to_store
;
1871 record_core_ops
.to_store_registers
= record_core_store_registers
;
1872 record_core_ops
.to_xfer_partial
= record_core_xfer_partial
;
1873 record_core_ops
.to_insert_breakpoint
= record_core_insert_breakpoint
;
1874 record_core_ops
.to_remove_breakpoint
= record_core_remove_breakpoint
;
1875 record_core_ops
.to_stopped_by_watchpoint
= record_stopped_by_watchpoint
;
1876 record_core_ops
.to_stopped_data_address
= record_stopped_data_address
;
1877 record_core_ops
.to_can_execute_reverse
= record_can_execute_reverse
;
1878 record_core_ops
.to_has_execution
= record_core_has_execution
;
1879 record_core_ops
.to_stratum
= record_stratum
;
1880 /* Add bookmark target methods. */
1881 record_core_ops
.to_get_bookmark
= record_get_bookmark
;
1882 record_core_ops
.to_goto_bookmark
= record_goto_bookmark
;
1883 record_core_ops
.to_magic
= OPS_MAGIC
;
1886 /* Implement "show record debug" command. */
1889 show_record_debug (struct ui_file
*file
, int from_tty
,
1890 struct cmd_list_element
*c
, const char *value
)
1892 fprintf_filtered (file
, _("Debugging of process record target is %s.\n"),
1896 /* Alias for "target record". */
1899 cmd_record_start (char *args
, int from_tty
)
1901 execute_command ("target record", from_tty
);
1904 /* Truncate the record log from the present point
1905 of replay until the end. */
1908 cmd_record_delete (char *args
, int from_tty
)
1910 if (current_target
.to_stratum
== record_stratum
)
1912 if (RECORD_IS_REPLAY
)
1914 if (!from_tty
|| query (_("Delete the log from this point forward "
1915 "and begin to record the running message "
1917 record_list_release_following (record_list
);
1920 printf_unfiltered (_("Already at end of record list.\n"));
1924 printf_unfiltered (_("Process record is not started.\n"));
1927 /* Implement the "stoprecord" or "record stop" command. */
1930 cmd_record_stop (char *args
, int from_tty
)
1932 if (current_target
.to_stratum
== record_stratum
)
1934 unpush_target (&record_ops
);
1935 printf_unfiltered (_("Process record is stopped and all execution "
1936 "logs are deleted.\n"));
1939 printf_unfiltered (_("Process record is not started.\n"));
1942 /* Set upper limit of record log size. */
1945 set_record_insn_max_num (char *args
, int from_tty
, struct cmd_list_element
*c
)
1947 if (record_insn_num
> record_insn_max_num
&& record_insn_max_num
)
1949 /* Count down record_insn_num while releasing records from list. */
1950 while (record_insn_num
> record_insn_max_num
)
1952 record_list_release_first ();
1958 static struct cmd_list_element
*record_cmdlist
, *set_record_cmdlist
,
1959 *show_record_cmdlist
, *info_record_cmdlist
;
1962 set_record_command (char *args
, int from_tty
)
1964 printf_unfiltered (_("\
1965 \"set record\" must be followed by an apporpriate subcommand.\n"));
1966 help_list (set_record_cmdlist
, "set record ", all_commands
, gdb_stdout
);
1970 show_record_command (char *args
, int from_tty
)
1972 cmd_show_list (show_record_cmdlist
, from_tty
, "");
1975 /* Display some statistics about the execution log. */
1978 info_record_command (char *args
, int from_tty
)
1980 struct record_entry
*p
;
1982 if (current_target
.to_stratum
== record_stratum
)
1984 if (RECORD_IS_REPLAY
)
1985 printf_filtered (_("Replay mode:\n"));
1987 printf_filtered (_("Record mode:\n"));
1989 /* Find entry for first actual instruction in the log. */
1990 for (p
= record_first
.next
;
1991 p
!= NULL
&& p
->type
!= record_end
;
1995 /* Do we have a log at all? */
1996 if (p
!= NULL
&& p
->type
== record_end
)
1998 /* Display instruction number for first instruction in the log. */
1999 printf_filtered (_("Lowest recorded instruction number is %s.\n"),
2000 pulongest (p
->u
.end
.insn_num
));
2002 /* If in replay mode, display where we are in the log. */
2003 if (RECORD_IS_REPLAY
)
2004 printf_filtered (_("Current instruction number is %s.\n"),
2005 pulongest (record_list
->u
.end
.insn_num
));
2007 /* Display instruction number for last instruction in the log. */
2008 printf_filtered (_("Highest recorded instruction number is %s.\n"),
2009 pulongest (record_insn_count
));
2011 /* Display log count. */
2012 printf_filtered (_("Log contains %d instructions.\n"),
2017 printf_filtered (_("No instructions have been logged.\n"));
2022 printf_filtered (_("target record is not active.\n"));
2025 /* Display max log size. */
2026 printf_filtered (_("Max logged instructions is %d.\n"),
2027 record_insn_max_num
);
2030 /* Record log save-file format
2031 Version 1 (never released)
2034 4 bytes: magic number htonl(0x20090829).
2035 NOTE: be sure to change whenever this file format changes!
2039 1 byte: record type (record_end, see enum record_type).
2041 1 byte: record type (record_reg, see enum record_type).
2042 8 bytes: register id (network byte order).
2043 MAX_REGISTER_SIZE bytes: register value.
2045 1 byte: record type (record_mem, see enum record_type).
2046 8 bytes: memory length (network byte order).
2047 8 bytes: memory address (network byte order).
2048 n bytes: memory value (n == memory length).
2051 4 bytes: magic number netorder32(0x20091016).
2052 NOTE: be sure to change whenever this file format changes!
2056 1 byte: record type (record_end, see enum record_type).
2058 4 bytes: instruction count
2060 1 byte: record type (record_reg, see enum record_type).
2061 4 bytes: register id (network byte order).
2062 n bytes: register value (n == actual register size).
2063 (eg. 4 bytes for x86 general registers).
2065 1 byte: record type (record_mem, see enum record_type).
2066 4 bytes: memory length (network byte order).
2067 8 bytes: memory address (network byte order).
2068 n bytes: memory value (n == memory length).
2072 /* bfdcore_read -- read bytes from a core file section. */
2075 bfdcore_read (bfd
*obfd
, asection
*osec
, void *buf
, int len
, int *offset
)
2077 int ret
= bfd_get_section_contents (obfd
, osec
, buf
, *offset
, len
);
2082 error (_("Failed to read %d bytes from core file %s ('%s').\n"),
2083 len
, bfd_get_filename (obfd
),
2084 bfd_errmsg (bfd_get_error ()));
2087 static inline uint64_t
2088 netorder64 (uint64_t input
)
2092 store_unsigned_integer ((gdb_byte
*) &ret
, sizeof (ret
),
2093 BFD_ENDIAN_BIG
, input
);
2097 static inline uint32_t
2098 netorder32 (uint32_t input
)
2102 store_unsigned_integer ((gdb_byte
*) &ret
, sizeof (ret
),
2103 BFD_ENDIAN_BIG
, input
);
2107 static inline uint16_t
2108 netorder16 (uint16_t input
)
2112 store_unsigned_integer ((gdb_byte
*) &ret
, sizeof (ret
),
2113 BFD_ENDIAN_BIG
, input
);
2117 /* Restore the execution log from a core_bfd file. */
2119 record_restore (void)
2122 struct cleanup
*old_cleanups
;
2123 struct record_entry
*rec
;
2127 struct regcache
*regcache
;
2129 /* We restore the execution log from the open core bfd,
2131 if (core_bfd
== NULL
)
2134 /* "record_restore" can only be called when record list is empty. */
2135 gdb_assert (record_first
.next
== NULL
);
2138 fprintf_unfiltered (gdb_stdlog
, "Restoring recording from core file.\n");
2140 /* Now need to find our special note section. */
2141 osec
= bfd_get_section_by_name (core_bfd
, "null0");
2142 osec_size
= bfd_section_size (core_bfd
, osec
);
2144 fprintf_unfiltered (gdb_stdlog
, "Find precord section %s.\n",
2145 osec
? "succeeded" : "failed");
2149 fprintf_unfiltered (gdb_stdlog
, "%s", bfd_section_name (core_bfd
, osec
));
2151 /* Check the magic code. */
2152 bfdcore_read (core_bfd
, osec
, &magic
, sizeof (magic
), &bfd_offset
);
2153 if (magic
!= RECORD_FILE_MAGIC
)
2154 error (_("Version mis-match or file format error in core file %s."),
2155 bfd_get_filename (core_bfd
));
2157 fprintf_unfiltered (gdb_stdlog
, "\
2158 Reading 4-byte magic cookie RECORD_FILE_MAGIC (0x%s)\n",
2159 phex_nz (netorder32 (magic
), 4));
2161 /* Restore the entries in recfd into record_arch_list_head and
2162 record_arch_list_tail. */
2163 record_arch_list_head
= NULL
;
2164 record_arch_list_tail
= NULL
;
2165 record_insn_num
= 0;
2166 old_cleanups
= make_cleanup (record_arch_list_cleanups
, 0);
2167 regcache
= get_current_regcache ();
2173 uint32_t regnum
, len
, signal
, count
;
2176 /* We are finished when offset reaches osec_size. */
2177 if (bfd_offset
>= osec_size
)
2179 bfdcore_read (core_bfd
, osec
, &tmpu8
, sizeof (tmpu8
), &bfd_offset
);
2183 case record_reg
: /* reg */
2184 /* Get register number to regnum. */
2185 bfdcore_read (core_bfd
, osec
, ®num
,
2186 sizeof (regnum
), &bfd_offset
);
2187 regnum
= netorder32 (regnum
);
2189 rec
= record_reg_alloc (regcache
, regnum
);
2192 bfdcore_read (core_bfd
, osec
, record_get_loc (rec
),
2193 rec
->u
.reg
.len
, &bfd_offset
);
2196 fprintf_unfiltered (gdb_stdlog
, "\
2197 Reading register %d (1 plus %lu plus %d bytes)\n",
2199 (unsigned long) sizeof (regnum
),
2203 case record_mem
: /* mem */
2205 bfdcore_read (core_bfd
, osec
, &len
,
2206 sizeof (len
), &bfd_offset
);
2207 len
= netorder32 (len
);
2210 bfdcore_read (core_bfd
, osec
, &addr
,
2211 sizeof (addr
), &bfd_offset
);
2212 addr
= netorder64 (addr
);
2214 rec
= record_mem_alloc (addr
, len
);
2217 bfdcore_read (core_bfd
, osec
, record_get_loc (rec
),
2218 rec
->u
.mem
.len
, &bfd_offset
);
2221 fprintf_unfiltered (gdb_stdlog
, "\
2222 Reading memory %s (1 plus %lu plus %lu plus %d bytes)\n",
2223 paddress (get_current_arch (),
2225 (unsigned long) sizeof (addr
),
2226 (unsigned long) sizeof (len
),
2230 case record_end
: /* end */
2231 rec
= record_end_alloc ();
2234 /* Get signal value. */
2235 bfdcore_read (core_bfd
, osec
, &signal
,
2236 sizeof (signal
), &bfd_offset
);
2237 signal
= netorder32 (signal
);
2238 rec
->u
.end
.sigval
= signal
;
2240 /* Get insn count. */
2241 bfdcore_read (core_bfd
, osec
, &count
,
2242 sizeof (count
), &bfd_offset
);
2243 count
= netorder32 (count
);
2244 rec
->u
.end
.insn_num
= count
;
2245 record_insn_count
= count
+ 1;
2247 fprintf_unfiltered (gdb_stdlog
, "\
2248 Reading record_end (1 + %lu + %lu bytes), offset == %s\n",
2249 (unsigned long) sizeof (signal
),
2250 (unsigned long) sizeof (count
),
2251 paddress (get_current_arch (),
2256 error (_("Bad entry type in core file %s."),
2257 bfd_get_filename (core_bfd
));
2261 /* Add rec to record arch list. */
2262 record_arch_list_add (rec
);
2265 discard_cleanups (old_cleanups
);
2267 /* Add record_arch_list_head to the end of record list. */
2268 record_first
.next
= record_arch_list_head
;
2269 record_arch_list_head
->prev
= &record_first
;
2270 record_arch_list_tail
->next
= NULL
;
2271 record_list
= &record_first
;
2273 /* Update record_insn_max_num. */
2274 if (record_insn_num
> record_insn_max_num
)
2276 record_insn_max_num
= record_insn_num
;
2277 warning (_("Auto increase record/replay buffer limit to %d."),
2278 record_insn_max_num
);
2282 printf_filtered (_("Restored records from core file %s.\n"),
2283 bfd_get_filename (core_bfd
));
2285 print_stack_frame (get_selected_frame (NULL
), 1, SRC_AND_LOC
);
2288 /* bfdcore_write -- write bytes into a core file section. */
2291 bfdcore_write (bfd
*obfd
, asection
*osec
, void *buf
, int len
, int *offset
)
2293 int ret
= bfd_set_section_contents (obfd
, osec
, buf
, *offset
, len
);
2298 error (_("Failed to write %d bytes to core file %s ('%s').\n"),
2299 len
, bfd_get_filename (obfd
),
2300 bfd_errmsg (bfd_get_error ()));
2303 /* Restore the execution log from a file. We use a modified elf
2304 corefile format, with an extra section for our data. */
2307 cmd_record_restore (char *args
, int from_tty
)
2309 core_file_command (args
, from_tty
);
2310 record_open (args
, from_tty
);
2314 record_save_cleanups (void *data
)
2317 char *pathname
= xstrdup (bfd_get_filename (obfd
));
2323 /* Save the execution log to a file. We use a modified elf corefile
2324 format, with an extra section for our data. */
2327 cmd_record_save (char *args
, int from_tty
)
2329 char *recfilename
, recfilename_buffer
[40];
2331 struct record_entry
*cur_record_list
;
2333 struct regcache
*regcache
;
2334 struct gdbarch
*gdbarch
;
2335 struct cleanup
*old_cleanups
;
2336 struct cleanup
*set_cleanups
;
2339 asection
*osec
= NULL
;
2342 if (strcmp (current_target
.to_shortname
, "record") != 0)
2343 error (_("This command can only be used with target 'record'.\n"
2344 "Use 'target record' first.\n"));
2350 /* Default recfile name is "gdb_record.PID". */
2351 snprintf (recfilename_buffer
, sizeof (recfilename_buffer
),
2352 "gdb_record.%d", PIDGET (inferior_ptid
));
2353 recfilename
= recfilename_buffer
;
2356 /* Open the save file. */
2358 fprintf_unfiltered (gdb_stdlog
, "Saving execution log to core file '%s'\n",
2361 /* Open the output file. */
2362 obfd
= create_gcore_bfd (recfilename
);
2363 old_cleanups
= make_cleanup (record_save_cleanups
, obfd
);
2365 /* Save the current record entry to "cur_record_list". */
2366 cur_record_list
= record_list
;
2368 /* Get the values of regcache and gdbarch. */
2369 regcache
= get_current_regcache ();
2370 gdbarch
= get_regcache_arch (regcache
);
2372 /* Disable the GDB operation record. */
2373 set_cleanups
= record_gdb_operation_disable_set ();
2375 /* Reverse execute to the begin of record list. */
2378 /* Check for beginning and end of log. */
2379 if (record_list
== &record_first
)
2382 record_exec_insn (regcache
, gdbarch
, record_list
);
2384 if (record_list
->prev
)
2385 record_list
= record_list
->prev
;
2388 /* Compute the size needed for the extra bfd section. */
2389 save_size
= 4; /* magic cookie */
2390 for (record_list
= record_first
.next
; record_list
;
2391 record_list
= record_list
->next
)
2392 switch (record_list
->type
)
2395 save_size
+= 1 + 4 + 4;
2398 save_size
+= 1 + 4 + record_list
->u
.reg
.len
;
2401 save_size
+= 1 + 4 + 8 + record_list
->u
.mem
.len
;
2405 /* Make the new bfd section. */
2406 osec
= bfd_make_section_anyway_with_flags (obfd
, "precord",
2410 error (_("Failed to create 'precord' section for corefile %s: %s"),
2412 bfd_errmsg (bfd_get_error ()));
2413 bfd_set_section_size (obfd
, osec
, save_size
);
2414 bfd_set_section_vma (obfd
, osec
, 0);
2415 bfd_set_section_alignment (obfd
, osec
, 0);
2416 bfd_section_lma (obfd
, osec
) = 0;
2418 /* Save corefile state. */
2419 write_gcore_file (obfd
);
2421 /* Write out the record log. */
2422 /* Write the magic code. */
2423 magic
= RECORD_FILE_MAGIC
;
2425 fprintf_unfiltered (gdb_stdlog
, "\
2426 Writing 4-byte magic cookie RECORD_FILE_MAGIC (0x%s)\n",
2427 phex_nz (magic
, 4));
2428 bfdcore_write (obfd
, osec
, &magic
, sizeof (magic
), &bfd_offset
);
2430 /* Save the entries to recfd and forward execute to the end of
2432 record_list
= &record_first
;
2436 if (record_list
!= &record_first
)
2439 uint32_t regnum
, len
, signal
, count
;
2442 type
= record_list
->type
;
2443 bfdcore_write (obfd
, osec
, &type
, sizeof (type
), &bfd_offset
);
2445 switch (record_list
->type
)
2447 case record_reg
: /* reg */
2449 fprintf_unfiltered (gdb_stdlog
, "\
2450 Writing register %d (1 plus %lu plus %d bytes)\n",
2451 record_list
->u
.reg
.num
,
2452 (unsigned long) sizeof (regnum
),
2453 record_list
->u
.reg
.len
);
2456 regnum
= netorder32 (record_list
->u
.reg
.num
);
2457 bfdcore_write (obfd
, osec
, ®num
,
2458 sizeof (regnum
), &bfd_offset
);
2461 bfdcore_write (obfd
, osec
, record_get_loc (record_list
),
2462 record_list
->u
.reg
.len
, &bfd_offset
);
2465 case record_mem
: /* mem */
2467 fprintf_unfiltered (gdb_stdlog
, "\
2468 Writing memory %s (1 plus %lu plus %lu plus %d bytes)\n",
2470 record_list
->u
.mem
.addr
),
2471 (unsigned long) sizeof (addr
),
2472 (unsigned long) sizeof (len
),
2473 record_list
->u
.mem
.len
);
2476 len
= netorder32 (record_list
->u
.mem
.len
);
2477 bfdcore_write (obfd
, osec
, &len
, sizeof (len
), &bfd_offset
);
2479 /* Write memaddr. */
2480 addr
= netorder64 (record_list
->u
.mem
.addr
);
2481 bfdcore_write (obfd
, osec
, &addr
,
2482 sizeof (addr
), &bfd_offset
);
2485 bfdcore_write (obfd
, osec
, record_get_loc (record_list
),
2486 record_list
->u
.mem
.len
, &bfd_offset
);
2491 fprintf_unfiltered (gdb_stdlog
, "\
2492 Writing record_end (1 + %lu + %lu bytes)\n",
2493 (unsigned long) sizeof (signal
),
2494 (unsigned long) sizeof (count
));
2495 /* Write signal value. */
2496 signal
= netorder32 (record_list
->u
.end
.sigval
);
2497 bfdcore_write (obfd
, osec
, &signal
,
2498 sizeof (signal
), &bfd_offset
);
2500 /* Write insn count. */
2501 count
= netorder32 (record_list
->u
.end
.insn_num
);
2502 bfdcore_write (obfd
, osec
, &count
,
2503 sizeof (count
), &bfd_offset
);
2508 /* Execute entry. */
2509 record_exec_insn (regcache
, gdbarch
, record_list
);
2511 if (record_list
->next
)
2512 record_list
= record_list
->next
;
2517 /* Reverse execute to cur_record_list. */
2520 /* Check for beginning and end of log. */
2521 if (record_list
== cur_record_list
)
2524 record_exec_insn (regcache
, gdbarch
, record_list
);
2526 if (record_list
->prev
)
2527 record_list
= record_list
->prev
;
2530 do_cleanups (set_cleanups
);
2532 discard_cleanups (old_cleanups
);
2535 printf_filtered (_("Saved core file %s with execution log.\n"),
2539 /* record_goto_insn -- rewind the record log (forward or backward,
2540 depending on DIR) to the given entry, changing the program state
2544 record_goto_insn (struct record_entry
*entry
,
2545 enum exec_direction_kind dir
)
2547 struct cleanup
*set_cleanups
= record_gdb_operation_disable_set ();
2548 struct regcache
*regcache
= get_current_regcache ();
2549 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
2551 /* Assume everything is valid: we will hit the entry,
2552 and we will not hit the end of the recording. */
2554 if (dir
== EXEC_FORWARD
)
2555 record_list
= record_list
->next
;
2559 record_exec_insn (regcache
, gdbarch
, record_list
);
2560 if (dir
== EXEC_REVERSE
)
2561 record_list
= record_list
->prev
;
2563 record_list
= record_list
->next
;
2564 } while (record_list
!= entry
);
2565 do_cleanups (set_cleanups
);
2568 /* "record goto" command. Argument is an instruction number,
2569 as given by "info record".
2571 Rewinds the recording (forward or backward) to the given instruction. */
2574 cmd_record_goto (char *arg
, int from_tty
)
2576 struct record_entry
*p
= NULL
;
2577 ULONGEST target_insn
= 0;
2579 if (arg
== NULL
|| *arg
== '\0')
2580 error (_("Command requires an argument (insn number to go to)."));
2582 if (strncmp (arg
, "start", strlen ("start")) == 0
2583 || strncmp (arg
, "begin", strlen ("begin")) == 0)
2585 /* Special case. Find first insn. */
2586 for (p
= &record_first
; p
!= NULL
; p
= p
->next
)
2587 if (p
->type
== record_end
)
2590 target_insn
= p
->u
.end
.insn_num
;
2592 else if (strncmp (arg
, "end", strlen ("end")) == 0)
2594 /* Special case. Find last insn. */
2595 for (p
= record_list
; p
->next
!= NULL
; p
= p
->next
)
2597 for (; p
!= NULL
; p
= p
->prev
)
2598 if (p
->type
== record_end
)
2601 target_insn
= p
->u
.end
.insn_num
;
2605 /* General case. Find designated insn. */
2606 target_insn
= parse_and_eval_long (arg
);
2608 for (p
= &record_first
; p
!= NULL
; p
= p
->next
)
2609 if (p
->type
== record_end
&& p
->u
.end
.insn_num
== target_insn
)
2614 error (_("Target insn '%s' not found."), arg
);
2615 else if (p
== record_list
)
2616 error (_("Already at insn '%s'."), arg
);
2617 else if (p
->u
.end
.insn_num
> record_list
->u
.end
.insn_num
)
2619 printf_filtered (_("Go forward to insn number %s\n"),
2620 pulongest (target_insn
));
2621 record_goto_insn (p
, EXEC_FORWARD
);
2625 printf_filtered (_("Go backward to insn number %s\n"),
2626 pulongest (target_insn
));
2627 record_goto_insn (p
, EXEC_REVERSE
);
2629 registers_changed ();
2630 reinit_frame_cache ();
2631 print_stack_frame (get_selected_frame (NULL
), 1, SRC_AND_LOC
);
2635 _initialize_record (void)
2637 struct cmd_list_element
*c
;
2639 /* Init record_first. */
2640 record_first
.prev
= NULL
;
2641 record_first
.next
= NULL
;
2642 record_first
.type
= record_end
;
2645 add_target (&record_ops
);
2646 init_record_core_ops ();
2647 add_target (&record_core_ops
);
2649 add_setshow_zinteger_cmd ("record", no_class
, &record_debug
,
2650 _("Set debugging of record/replay feature."),
2651 _("Show debugging of record/replay feature."),
2652 _("When enabled, debugging output for "
2653 "record/replay feature is displayed."),
2654 NULL
, show_record_debug
, &setdebuglist
,
2657 c
= add_prefix_cmd ("record", class_obscure
, cmd_record_start
,
2658 _("Abbreviated form of \"target record\" command."),
2659 &record_cmdlist
, "record ", 0, &cmdlist
);
2660 set_cmd_completer (c
, filename_completer
);
2662 add_com_alias ("rec", "record", class_obscure
, 1);
2663 add_prefix_cmd ("record", class_support
, set_record_command
,
2664 _("Set record options"), &set_record_cmdlist
,
2665 "set record ", 0, &setlist
);
2666 add_alias_cmd ("rec", "record", class_obscure
, 1, &setlist
);
2667 add_prefix_cmd ("record", class_support
, show_record_command
,
2668 _("Show record options"), &show_record_cmdlist
,
2669 "show record ", 0, &showlist
);
2670 add_alias_cmd ("rec", "record", class_obscure
, 1, &showlist
);
2671 add_prefix_cmd ("record", class_support
, info_record_command
,
2672 _("Info record options"), &info_record_cmdlist
,
2673 "info record ", 0, &infolist
);
2674 add_alias_cmd ("rec", "record", class_obscure
, 1, &infolist
);
2676 c
= add_cmd ("save", class_obscure
, cmd_record_save
,
2677 _("Save the execution log to a file.\n\
2678 Argument is optional filename.\n\
2679 Default filename is 'gdb_record.<process_id>'."),
2681 set_cmd_completer (c
, filename_completer
);
2683 c
= add_cmd ("restore", class_obscure
, cmd_record_restore
,
2684 _("Restore the execution log from a file.\n\
2685 Argument is filename. File must be created with 'record save'."),
2687 set_cmd_completer (c
, filename_completer
);
2689 add_cmd ("delete", class_obscure
, cmd_record_delete
,
2690 _("Delete the rest of execution log and start recording it anew."),
2692 add_alias_cmd ("d", "delete", class_obscure
, 1, &record_cmdlist
);
2693 add_alias_cmd ("del", "delete", class_obscure
, 1, &record_cmdlist
);
2695 add_cmd ("stop", class_obscure
, cmd_record_stop
,
2696 _("Stop the record/replay target."),
2698 add_alias_cmd ("s", "stop", class_obscure
, 1, &record_cmdlist
);
2700 /* Record instructions number limit command. */
2701 add_setshow_boolean_cmd ("stop-at-limit", no_class
,
2702 &record_stop_at_limit
, _("\
2703 Set whether record/replay stops when record/replay buffer becomes full."), _("\
2704 Show whether record/replay stops when record/replay buffer becomes full."), _("\
2706 When ON, if the record/replay buffer becomes full, ask user what to do.\n\
2707 When OFF, if the record/replay buffer becomes full,\n\
2708 delete the oldest recorded instruction to make room for each new one."),
2710 &set_record_cmdlist
, &show_record_cmdlist
);
2711 add_setshow_uinteger_cmd ("insn-number-max", no_class
,
2712 &record_insn_max_num
,
2713 _("Set record/replay buffer limit."),
2714 _("Show record/replay buffer limit."), _("\
2715 Set the maximum number of instructions to be stored in the\n\
2716 record/replay buffer. Zero means unlimited. Default is 200000."),
2717 set_record_insn_max_num
,
2718 NULL
, &set_record_cmdlist
, &show_record_cmdlist
);
2720 add_cmd ("goto", class_obscure
, cmd_record_goto
, _("\
2721 Restore the program to its state at instruction number N.\n\
2722 Argument is instruction number, as shown by 'info record'."),