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
)
549 target_terminal_ours ();
550 q
= yquery (_("Do you want to auto delete previous execution "
551 "log entries when record/replay buffer becomes "
552 "full (record stop-at-limit)?"));
554 target_terminal_inferior ();
556 record_stop_at_limit
= 0;
558 error (_("Process record: stopped by user."));
565 record_arch_list_cleanups (void *ignore
)
567 record_list_release (record_arch_list_tail
);
570 /* Before inferior step (when GDB record the running message, inferior
571 only can step), GDB will call this function to record the values to
572 record_list. This function will call gdbarch_process_record to
573 record the running message of inferior and set them to
574 record_arch_list, and add it to record_list. */
577 record_message (struct regcache
*regcache
, enum target_signal signal
)
580 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
581 struct cleanup
*old_cleanups
= make_cleanup (record_arch_list_cleanups
, 0);
583 record_arch_list_head
= NULL
;
584 record_arch_list_tail
= NULL
;
586 /* Check record_insn_num. */
587 record_check_insn_num (1);
589 /* If gdb sends a signal value to target_resume,
590 save it in the 'end' field of the previous instruction.
592 Maybe process record should record what really happened,
593 rather than what gdb pretends has happened.
595 So if Linux delivered the signal to the child process during
596 the record mode, we will record it and deliver it again in
599 If user says "ignore this signal" during the record mode, then
600 it will be ignored again during the replay mode (no matter if
601 the user says something different, like "deliver this signal"
602 during the replay mode).
604 User should understand that nothing he does during the replay
605 mode will change the behavior of the child. If he tries,
606 then that is a user error.
608 But we should still deliver the signal to gdb during the replay,
609 if we delivered it during the recording. Therefore we should
610 record the signal during record_wait, not record_resume. */
611 if (record_list
!= &record_first
) /* FIXME better way to check */
613 gdb_assert (record_list
->type
== record_end
);
614 record_list
->u
.end
.sigval
= signal
;
617 if (signal
== TARGET_SIGNAL_0
618 || !gdbarch_process_record_signal_p (gdbarch
))
619 ret
= gdbarch_process_record (gdbarch
,
621 regcache_read_pc (regcache
));
623 ret
= gdbarch_process_record_signal (gdbarch
,
628 error (_("Process record: inferior program stopped."));
630 error (_("Process record: failed to record execution log."));
632 discard_cleanups (old_cleanups
);
634 record_list
->next
= record_arch_list_head
;
635 record_arch_list_head
->prev
= record_list
;
636 record_list
= record_arch_list_tail
;
638 if (record_insn_num
== record_insn_max_num
&& record_insn_max_num
)
639 record_list_release_first ();
646 struct record_message_args
{
647 struct regcache
*regcache
;
648 enum target_signal signal
;
652 record_message_wrapper (void *args
)
654 struct record_message_args
*record_args
= args
;
656 return record_message (record_args
->regcache
, record_args
->signal
);
660 record_message_wrapper_safe (struct regcache
*regcache
,
661 enum target_signal signal
)
663 struct record_message_args args
;
665 args
.regcache
= regcache
;
666 args
.signal
= signal
;
668 return catch_errors (record_message_wrapper
, &args
, NULL
, RETURN_MASK_ALL
);
671 /* Set to 1 if record_store_registers and record_xfer_partial
672 doesn't need record. */
674 static int record_gdb_operation_disable
= 0;
677 record_gdb_operation_disable_set (void)
679 struct cleanup
*old_cleanups
= NULL
;
682 make_cleanup_restore_integer (&record_gdb_operation_disable
);
683 record_gdb_operation_disable
= 1;
688 /* Flag set to TRUE for target_stopped_by_watchpoint. */
689 static int record_hw_watchpoint
= 0;
691 /* Execute one instruction from the record log. Each instruction in
692 the log will be represented by an arbitrary sequence of register
693 entries and memory entries, followed by an 'end' entry. */
696 record_exec_insn (struct regcache
*regcache
, struct gdbarch
*gdbarch
,
697 struct record_entry
*entry
)
701 case record_reg
: /* reg */
703 gdb_byte reg
[MAX_REGISTER_SIZE
];
705 if (record_debug
> 1)
706 fprintf_unfiltered (gdb_stdlog
,
707 "Process record: record_reg %s to "
708 "inferior num = %d.\n",
709 host_address_to_string (entry
),
712 regcache_cooked_read (regcache
, entry
->u
.reg
.num
, reg
);
713 regcache_cooked_write (regcache
, entry
->u
.reg
.num
,
714 record_get_loc (entry
));
715 memcpy (record_get_loc (entry
), reg
, entry
->u
.reg
.len
);
719 case record_mem
: /* mem */
721 /* Nothing to do if the entry is flagged not_accessible. */
722 if (!entry
->u
.mem
.mem_entry_not_accessible
)
724 gdb_byte
*mem
= alloca (entry
->u
.mem
.len
);
726 if (record_debug
> 1)
727 fprintf_unfiltered (gdb_stdlog
,
728 "Process record: record_mem %s to "
729 "inferior addr = %s len = %d.\n",
730 host_address_to_string (entry
),
731 paddress (gdbarch
, entry
->u
.mem
.addr
),
734 if (target_read_memory (entry
->u
.mem
.addr
, mem
, entry
->u
.mem
.len
))
736 entry
->u
.mem
.mem_entry_not_accessible
= 1;
738 warning ("Process record: error reading memory at "
739 "addr = %s len = %d.",
740 paddress (gdbarch
, entry
->u
.mem
.addr
),
745 if (target_write_memory (entry
->u
.mem
.addr
,
746 record_get_loc (entry
),
749 entry
->u
.mem
.mem_entry_not_accessible
= 1;
751 warning ("Process record: error writing memory at "
752 "addr = %s len = %d.",
753 paddress (gdbarch
, entry
->u
.mem
.addr
),
758 memcpy (record_get_loc (entry
), mem
, entry
->u
.mem
.len
);
760 /* We've changed memory --- check if a hardware
761 watchpoint should trap. Note that this
762 presently assumes the target beneath supports
763 continuable watchpoints. On non-continuable
764 watchpoints target, we'll want to check this
765 _before_ actually doing the memory change, and
766 not doing the change at all if the watchpoint
768 if (hardware_watchpoint_inserted_in_range
769 (get_regcache_aspace (regcache
),
770 entry
->u
.mem
.addr
, entry
->u
.mem
.len
))
771 record_hw_watchpoint
= 1;
780 static struct target_ops
*tmp_to_resume_ops
;
781 static void (*tmp_to_resume
) (struct target_ops
*, ptid_t
, int,
783 static struct target_ops
*tmp_to_wait_ops
;
784 static ptid_t (*tmp_to_wait
) (struct target_ops
*, ptid_t
,
785 struct target_waitstatus
*,
787 static struct target_ops
*tmp_to_store_registers_ops
;
788 static void (*tmp_to_store_registers
) (struct target_ops
*,
791 static struct target_ops
*tmp_to_xfer_partial_ops
;
792 static LONGEST (*tmp_to_xfer_partial
) (struct target_ops
*ops
,
793 enum target_object object
,
796 const gdb_byte
*writebuf
,
799 static int (*tmp_to_insert_breakpoint
) (struct gdbarch
*,
800 struct bp_target_info
*);
801 static int (*tmp_to_remove_breakpoint
) (struct gdbarch
*,
802 struct bp_target_info
*);
803 static int (*tmp_to_stopped_by_watchpoint
) (void);
804 static int (*tmp_to_stopped_data_address
) (struct target_ops
*, CORE_ADDR
*);
806 static void record_restore (void);
808 /* Open the process record target. */
811 record_core_open_1 (char *name
, int from_tty
)
813 struct regcache
*regcache
= get_current_regcache ();
814 int regnum
= gdbarch_num_regs (get_regcache_arch (regcache
));
817 /* Get record_core_regbuf. */
818 target_fetch_registers (regcache
, -1);
819 record_core_regbuf
= xmalloc (MAX_REGISTER_SIZE
* regnum
);
820 for (i
= 0; i
< regnum
; i
++)
821 regcache_raw_collect (regcache
, i
,
822 record_core_regbuf
+ MAX_REGISTER_SIZE
* i
);
824 /* Get record_core_start and record_core_end. */
825 if (build_section_table (core_bfd
, &record_core_start
, &record_core_end
))
827 xfree (record_core_regbuf
);
828 record_core_regbuf
= NULL
;
829 error (_("\"%s\": Can't find sections: %s"),
830 bfd_get_filename (core_bfd
), bfd_errmsg (bfd_get_error ()));
833 push_target (&record_core_ops
);
837 /* "to_open" target method for 'live' processes. */
840 record_open_1 (char *name
, int from_tty
)
843 fprintf_unfiltered (gdb_stdlog
, "Process record: record_open\n");
846 if (!target_has_execution
)
847 error (_("Process record: the program is not being run."));
849 error (_("Process record target can't debug inferior in non-stop mode "
851 if (target_async_permitted
)
852 error (_("Process record target can't debug inferior in asynchronous "
853 "mode (target-async)."));
855 if (!gdbarch_process_record_p (target_gdbarch
))
856 error (_("Process record: the current architecture doesn't support "
857 "record function."));
860 error (_("Could not find 'to_resume' method on the target stack."));
862 error (_("Could not find 'to_wait' method on the target stack."));
863 if (!tmp_to_store_registers
)
864 error (_("Could not find 'to_store_registers' method on the target stack."));
865 if (!tmp_to_insert_breakpoint
)
866 error (_("Could not find 'to_insert_breakpoint' method on the target stack."));
867 if (!tmp_to_remove_breakpoint
)
868 error (_("Could not find 'to_remove_breakpoint' method on the target stack."));
869 if (!tmp_to_stopped_by_watchpoint
)
870 error (_("Could not find 'to_stopped_by_watchpoint' method on the target stack."));
871 if (!tmp_to_stopped_data_address
)
872 error (_("Could not find 'to_stopped_data_address' method on the target stack."));
874 push_target (&record_ops
);
877 /* "to_open" target method. Open the process record target. */
880 record_open (char *name
, int from_tty
)
882 struct target_ops
*t
;
885 fprintf_unfiltered (gdb_stdlog
, "Process record: record_open\n");
887 /* Check if record target is already running. */
888 if (current_target
.to_stratum
== record_stratum
)
889 error (_("Process record target already running. Use \"record stop\" to "
890 "stop record target first."));
892 /* Reset the tmp beneath pointers. */
893 tmp_to_resume_ops
= NULL
;
894 tmp_to_resume
= NULL
;
895 tmp_to_wait_ops
= NULL
;
897 tmp_to_store_registers_ops
= NULL
;
898 tmp_to_store_registers
= NULL
;
899 tmp_to_xfer_partial_ops
= NULL
;
900 tmp_to_xfer_partial
= NULL
;
901 tmp_to_insert_breakpoint
= NULL
;
902 tmp_to_remove_breakpoint
= NULL
;
903 tmp_to_stopped_by_watchpoint
= NULL
;
904 tmp_to_stopped_data_address
= NULL
;
906 /* Set the beneath function pointers. */
907 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
911 tmp_to_resume
= t
->to_resume
;
912 tmp_to_resume_ops
= t
;
916 tmp_to_wait
= t
->to_wait
;
919 if (!tmp_to_store_registers
)
921 tmp_to_store_registers
= t
->to_store_registers
;
922 tmp_to_store_registers_ops
= t
;
924 if (!tmp_to_xfer_partial
)
926 tmp_to_xfer_partial
= t
->to_xfer_partial
;
927 tmp_to_xfer_partial_ops
= t
;
929 if (!tmp_to_insert_breakpoint
)
930 tmp_to_insert_breakpoint
= t
->to_insert_breakpoint
;
931 if (!tmp_to_remove_breakpoint
)
932 tmp_to_remove_breakpoint
= t
->to_remove_breakpoint
;
933 if (!tmp_to_stopped_by_watchpoint
)
934 tmp_to_stopped_by_watchpoint
= t
->to_stopped_by_watchpoint
;
935 if (!tmp_to_stopped_data_address
)
936 tmp_to_stopped_data_address
= t
->to_stopped_data_address
;
938 if (!tmp_to_xfer_partial
)
939 error (_("Could not find 'to_xfer_partial' method on the target stack."));
943 record_insn_count
= 0;
944 record_list
= &record_first
;
945 record_list
->next
= NULL
;
947 /* Set the tmp beneath pointers to beneath pointers. */
948 record_beneath_to_resume_ops
= tmp_to_resume_ops
;
949 record_beneath_to_resume
= tmp_to_resume
;
950 record_beneath_to_wait_ops
= tmp_to_wait_ops
;
951 record_beneath_to_wait
= tmp_to_wait
;
952 record_beneath_to_store_registers_ops
= tmp_to_store_registers_ops
;
953 record_beneath_to_store_registers
= tmp_to_store_registers
;
954 record_beneath_to_xfer_partial_ops
= tmp_to_xfer_partial_ops
;
955 record_beneath_to_xfer_partial
= tmp_to_xfer_partial
;
956 record_beneath_to_insert_breakpoint
= tmp_to_insert_breakpoint
;
957 record_beneath_to_remove_breakpoint
= tmp_to_remove_breakpoint
;
958 record_beneath_to_stopped_by_watchpoint
= tmp_to_stopped_by_watchpoint
;
959 record_beneath_to_stopped_data_address
= tmp_to_stopped_data_address
;
961 if (current_target
.to_stratum
== core_stratum
)
962 record_core_open_1 (name
, from_tty
);
964 record_open_1 (name
, from_tty
);
967 /* "to_close" target method. Close the process record target. */
970 record_close (int quitting
)
972 struct record_core_buf_entry
*entry
;
975 fprintf_unfiltered (gdb_stdlog
, "Process record: record_close\n");
977 record_list_release (record_list
);
979 /* Release record_core_regbuf. */
980 if (record_core_regbuf
)
982 xfree (record_core_regbuf
);
983 record_core_regbuf
= NULL
;
986 /* Release record_core_buf_list. */
987 if (record_core_buf_list
)
989 for (entry
= record_core_buf_list
->prev
; entry
; entry
= entry
->prev
)
991 xfree (record_core_buf_list
);
992 record_core_buf_list
= entry
;
994 record_core_buf_list
= NULL
;
998 static int record_resume_step
= 0;
1000 /* "to_resume" target method. Resume the process record target. */
1003 record_resume (struct target_ops
*ops
, ptid_t ptid
, int step
,
1004 enum target_signal signal
)
1006 record_resume_step
= step
;
1008 if (!RECORD_IS_REPLAY
)
1010 record_message (get_current_regcache (), signal
);
1011 record_beneath_to_resume (record_beneath_to_resume_ops
, ptid
, 1,
1016 static int record_get_sig
= 0;
1018 /* SIGINT signal handler, registered by "to_wait" method. */
1021 record_sig_handler (int signo
)
1024 fprintf_unfiltered (gdb_stdlog
, "Process record: get a signal\n");
1026 /* It will break the running inferior in replay mode. */
1027 record_resume_step
= 1;
1029 /* It will let record_wait set inferior status to get the signal
1035 record_wait_cleanups (void *ignore
)
1037 if (execution_direction
== EXEC_REVERSE
)
1039 if (record_list
->next
)
1040 record_list
= record_list
->next
;
1043 record_list
= record_list
->prev
;
1046 /* "to_wait" target method for process record target.
1048 In record mode, the target is always run in singlestep mode
1049 (even when gdb says to continue). The to_wait method intercepts
1050 the stop events and determines which ones are to be passed on to
1051 gdb. Most stop events are just singlestep events that gdb is not
1052 to know about, so the to_wait method just records them and keeps
1055 In replay mode, this function emulates the recorded execution log,
1056 one instruction at a time (forward or backward), and determines
1060 record_wait (struct target_ops
*ops
,
1061 ptid_t ptid
, struct target_waitstatus
*status
,
1064 struct cleanup
*set_cleanups
= record_gdb_operation_disable_set ();
1067 fprintf_unfiltered (gdb_stdlog
,
1068 "Process record: record_wait "
1069 "record_resume_step = %d\n",
1070 record_resume_step
);
1072 if (!RECORD_IS_REPLAY
&& ops
!= &record_core_ops
)
1074 if (record_resume_step
)
1076 /* This is a single step. */
1077 return record_beneath_to_wait (record_beneath_to_wait_ops
,
1078 ptid
, status
, options
);
1082 /* This is not a single step. */
1088 ret
= record_beneath_to_wait (record_beneath_to_wait_ops
,
1089 ptid
, status
, options
);
1091 /* Is this a SIGTRAP? */
1092 if (status
->kind
== TARGET_WAITKIND_STOPPED
1093 && status
->value
.sig
== TARGET_SIGNAL_TRAP
)
1095 struct regcache
*regcache
;
1096 struct address_space
*aspace
;
1098 /* Yes -- this is likely our single-step finishing,
1099 but check if there's any reason the core would be
1100 interested in the event. */
1102 registers_changed ();
1103 regcache
= get_current_regcache ();
1104 tmp_pc
= regcache_read_pc (regcache
);
1105 aspace
= get_regcache_aspace (regcache
);
1107 if (target_stopped_by_watchpoint ())
1109 /* Always interested in watchpoints. */
1111 else if (breakpoint_inserted_here_p (aspace
, tmp_pc
))
1113 /* There is a breakpoint here. Let the core
1115 if (software_breakpoint_inserted_here_p (aspace
, tmp_pc
))
1117 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1118 CORE_ADDR decr_pc_after_break
1119 = gdbarch_decr_pc_after_break (gdbarch
);
1120 if (decr_pc_after_break
)
1121 regcache_write_pc (regcache
,
1122 tmp_pc
+ decr_pc_after_break
);
1127 /* This must be a single-step trap. Record the
1128 insn and issue another step. */
1129 if (!record_message_wrapper_safe (regcache
,
1132 status
->kind
= TARGET_WAITKIND_STOPPED
;
1133 status
->value
.sig
= TARGET_SIGNAL_0
;
1137 record_beneath_to_resume (record_beneath_to_resume_ops
,
1144 /* The inferior is broken by a breakpoint or a signal. */
1153 struct regcache
*regcache
= get_current_regcache ();
1154 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1155 struct address_space
*aspace
= get_regcache_aspace (regcache
);
1156 int continue_flag
= 1;
1157 int first_record_end
= 1;
1158 struct cleanup
*old_cleanups
= make_cleanup (record_wait_cleanups
, 0);
1161 record_hw_watchpoint
= 0;
1162 status
->kind
= TARGET_WAITKIND_STOPPED
;
1164 /* Check breakpoint when forward execute. */
1165 if (execution_direction
== EXEC_FORWARD
)
1167 tmp_pc
= regcache_read_pc (regcache
);
1168 if (breakpoint_inserted_here_p (aspace
, tmp_pc
))
1170 int decr_pc_after_break
= gdbarch_decr_pc_after_break (gdbarch
);
1173 fprintf_unfiltered (gdb_stdlog
,
1174 "Process record: break at %s.\n",
1175 paddress (gdbarch
, tmp_pc
));
1177 if (decr_pc_after_break
1178 && !record_resume_step
1179 && software_breakpoint_inserted_here_p (aspace
, tmp_pc
))
1180 regcache_write_pc (regcache
,
1181 tmp_pc
+ decr_pc_after_break
);
1187 signal (SIGINT
, record_sig_handler
);
1188 /* If GDB is in terminal_inferior mode, it will not get the signal.
1189 And in GDB replay mode, GDB doesn't need to be in terminal_inferior
1190 mode, because inferior will not executed.
1191 Then set it to terminal_ours to make GDB get the signal. */
1192 target_terminal_ours ();
1194 /* In EXEC_FORWARD mode, record_list points to the tail of prev
1196 if (execution_direction
== EXEC_FORWARD
&& record_list
->next
)
1197 record_list
= record_list
->next
;
1199 /* Loop over the record_list, looking for the next place to
1203 /* Check for beginning and end of log. */
1204 if (execution_direction
== EXEC_REVERSE
1205 && record_list
== &record_first
)
1207 /* Hit beginning of record log in reverse. */
1208 status
->kind
= TARGET_WAITKIND_NO_HISTORY
;
1211 if (execution_direction
!= EXEC_REVERSE
&& !record_list
->next
)
1213 /* Hit end of record log going forward. */
1214 status
->kind
= TARGET_WAITKIND_NO_HISTORY
;
1218 record_exec_insn (regcache
, gdbarch
, record_list
);
1220 if (record_list
->type
== record_end
)
1222 if (record_debug
> 1)
1223 fprintf_unfiltered (gdb_stdlog
,
1224 "Process record: record_end %s to "
1226 host_address_to_string (record_list
));
1228 if (first_record_end
&& execution_direction
== EXEC_REVERSE
)
1230 /* When reverse excute, the first record_end is the part of
1231 current instruction. */
1232 first_record_end
= 0;
1236 /* In EXEC_REVERSE mode, this is the record_end of prev
1238 In EXEC_FORWARD mode, this is the record_end of current
1241 if (record_resume_step
)
1243 if (record_debug
> 1)
1244 fprintf_unfiltered (gdb_stdlog
,
1245 "Process record: step.\n");
1249 /* check breakpoint */
1250 tmp_pc
= regcache_read_pc (regcache
);
1251 if (breakpoint_inserted_here_p (aspace
, tmp_pc
))
1253 int decr_pc_after_break
1254 = gdbarch_decr_pc_after_break (gdbarch
);
1257 fprintf_unfiltered (gdb_stdlog
,
1258 "Process record: break "
1260 paddress (gdbarch
, tmp_pc
));
1261 if (decr_pc_after_break
1262 && execution_direction
== EXEC_FORWARD
1263 && !record_resume_step
1264 && software_breakpoint_inserted_here_p (aspace
,
1266 regcache_write_pc (regcache
,
1267 tmp_pc
+ decr_pc_after_break
);
1271 if (record_hw_watchpoint
)
1274 fprintf_unfiltered (gdb_stdlog
, "\
1275 Process record: hit hw watchpoint.\n");
1278 /* Check target signal */
1279 if (record_list
->u
.end
.sigval
!= TARGET_SIGNAL_0
)
1280 /* FIXME: better way to check */
1287 if (execution_direction
== EXEC_REVERSE
)
1289 if (record_list
->prev
)
1290 record_list
= record_list
->prev
;
1294 if (record_list
->next
)
1295 record_list
= record_list
->next
;
1299 while (continue_flag
);
1301 signal (SIGINT
, handle_sigint
);
1305 status
->value
.sig
= TARGET_SIGNAL_INT
;
1306 else if (record_list
->u
.end
.sigval
!= TARGET_SIGNAL_0
)
1307 /* FIXME: better way to check */
1308 status
->value
.sig
= record_list
->u
.end
.sigval
;
1310 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
1312 discard_cleanups (old_cleanups
);
1315 do_cleanups (set_cleanups
);
1316 return inferior_ptid
;
1320 record_stopped_by_watchpoint (void)
1322 if (RECORD_IS_REPLAY
)
1323 return record_hw_watchpoint
;
1325 return record_beneath_to_stopped_by_watchpoint ();
1329 record_stopped_data_address (struct target_ops
*ops
, CORE_ADDR
*addr_p
)
1331 if (RECORD_IS_REPLAY
)
1334 return record_beneath_to_stopped_data_address (ops
, addr_p
);
1337 /* "to_disconnect" method for process record target. */
1340 record_disconnect (struct target_ops
*target
, char *args
, int from_tty
)
1343 fprintf_unfiltered (gdb_stdlog
, "Process record: record_disconnect\n");
1345 unpush_target (&record_ops
);
1346 target_disconnect (args
, from_tty
);
1349 /* "to_detach" method for process record target. */
1352 record_detach (struct target_ops
*ops
, char *args
, int from_tty
)
1355 fprintf_unfiltered (gdb_stdlog
, "Process record: record_detach\n");
1357 unpush_target (&record_ops
);
1358 target_detach (args
, from_tty
);
1361 /* "to_mourn_inferior" method for process record target. */
1364 record_mourn_inferior (struct target_ops
*ops
)
1367 fprintf_unfiltered (gdb_stdlog
, "Process record: "
1368 "record_mourn_inferior\n");
1370 unpush_target (&record_ops
);
1371 target_mourn_inferior ();
1374 /* Close process record target before killing the inferior process. */
1377 record_kill (struct target_ops
*ops
)
1380 fprintf_unfiltered (gdb_stdlog
, "Process record: record_kill\n");
1382 unpush_target (&record_ops
);
1386 /* Record registers change (by user or by GDB) to list as an instruction. */
1389 record_registers_change (struct regcache
*regcache
, int regnum
)
1391 /* Check record_insn_num. */
1392 record_check_insn_num (0);
1394 record_arch_list_head
= NULL
;
1395 record_arch_list_tail
= NULL
;
1401 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
1403 if (record_arch_list_add_reg (regcache
, i
))
1405 record_list_release (record_arch_list_tail
);
1406 error (_("Process record: failed to record execution log."));
1412 if (record_arch_list_add_reg (regcache
, regnum
))
1414 record_list_release (record_arch_list_tail
);
1415 error (_("Process record: failed to record execution log."));
1418 if (record_arch_list_add_end ())
1420 record_list_release (record_arch_list_tail
);
1421 error (_("Process record: failed to record execution log."));
1423 record_list
->next
= record_arch_list_head
;
1424 record_arch_list_head
->prev
= record_list
;
1425 record_list
= record_arch_list_tail
;
1427 if (record_insn_num
== record_insn_max_num
&& record_insn_max_num
)
1428 record_list_release_first ();
1433 /* "to_store_registers" method for process record target. */
1436 record_store_registers (struct target_ops
*ops
, struct regcache
*regcache
,
1439 if (!record_gdb_operation_disable
)
1441 if (RECORD_IS_REPLAY
)
1445 /* Let user choose if he wants to write register or not. */
1448 query (_("Because GDB is in replay mode, changing the "
1449 "value of a register will make the execution "
1450 "log unusable from this point onward. "
1451 "Change all registers?"));
1454 query (_("Because GDB is in replay mode, changing the value "
1455 "of a register will make the execution log unusable "
1456 "from this point onward. Change register %s?"),
1457 gdbarch_register_name (get_regcache_arch (regcache
),
1462 /* Invalidate the value of regcache that was set in function
1463 "regcache_raw_write". */
1469 i
< gdbarch_num_regs (get_regcache_arch (regcache
));
1471 regcache_invalidate (regcache
, i
);
1474 regcache_invalidate (regcache
, regno
);
1476 error (_("Process record canceled the operation."));
1479 /* Destroy the record from here forward. */
1480 record_list_release_following (record_list
);
1483 record_registers_change (regcache
, regno
);
1485 record_beneath_to_store_registers (record_beneath_to_store_registers_ops
,
1489 /* "to_xfer_partial" method. Behavior is conditional on RECORD_IS_REPLAY.
1490 In replay mode, we cannot write memory unles we are willing to
1491 invalidate the record/replay log from this point forward. */
1494 record_xfer_partial (struct target_ops
*ops
, enum target_object object
,
1495 const char *annex
, gdb_byte
*readbuf
,
1496 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
1498 if (!record_gdb_operation_disable
1499 && (object
== TARGET_OBJECT_MEMORY
1500 || object
== TARGET_OBJECT_RAW_MEMORY
) && writebuf
)
1502 if (RECORD_IS_REPLAY
)
1504 /* Let user choose if he wants to write memory or not. */
1505 if (!query (_("Because GDB is in replay mode, writing to memory "
1506 "will make the execution log unusable from this "
1507 "point onward. Write memory at address %s?"),
1508 paddress (target_gdbarch
, offset
)))
1509 error (_("Process record canceled the operation."));
1511 /* Destroy the record from here forward. */
1512 record_list_release_following (record_list
);
1515 /* Check record_insn_num */
1516 record_check_insn_num (0);
1518 /* Record registers change to list as an instruction. */
1519 record_arch_list_head
= NULL
;
1520 record_arch_list_tail
= NULL
;
1521 if (record_arch_list_add_mem (offset
, len
))
1523 record_list_release (record_arch_list_tail
);
1525 fprintf_unfiltered (gdb_stdlog
,
1526 "Process record: failed to record "
1530 if (record_arch_list_add_end ())
1532 record_list_release (record_arch_list_tail
);
1534 fprintf_unfiltered (gdb_stdlog
,
1535 "Process record: failed to record "
1539 record_list
->next
= record_arch_list_head
;
1540 record_arch_list_head
->prev
= record_list
;
1541 record_list
= record_arch_list_tail
;
1543 if (record_insn_num
== record_insn_max_num
&& record_insn_max_num
)
1544 record_list_release_first ();
1549 return record_beneath_to_xfer_partial (record_beneath_to_xfer_partial_ops
,
1550 object
, annex
, readbuf
, writebuf
,
1554 /* Behavior is conditional on RECORD_IS_REPLAY.
1555 We will not actually insert or remove breakpoints when replaying,
1556 nor when recording. */
1559 record_insert_breakpoint (struct gdbarch
*gdbarch
,
1560 struct bp_target_info
*bp_tgt
)
1562 if (!RECORD_IS_REPLAY
)
1564 struct cleanup
*old_cleanups
= record_gdb_operation_disable_set ();
1565 int ret
= record_beneath_to_insert_breakpoint (gdbarch
, bp_tgt
);
1567 do_cleanups (old_cleanups
);
1575 /* "to_remove_breakpoint" method for process record target. */
1578 record_remove_breakpoint (struct gdbarch
*gdbarch
,
1579 struct bp_target_info
*bp_tgt
)
1581 if (!RECORD_IS_REPLAY
)
1583 struct cleanup
*old_cleanups
= record_gdb_operation_disable_set ();
1584 int ret
= record_beneath_to_remove_breakpoint (gdbarch
, bp_tgt
);
1586 do_cleanups (old_cleanups
);
1594 /* "to_can_execute_reverse" method for process record target. */
1597 record_can_execute_reverse (void)
1602 /* "to_get_bookmark" method for process record and prec over core. */
1605 record_get_bookmark (char *args
, int from_tty
)
1607 gdb_byte
*ret
= NULL
;
1609 /* Return stringified form of instruction count. */
1610 if (record_list
&& record_list
->type
== record_end
)
1611 ret
= xstrdup (pulongest (record_list
->u
.end
.insn_num
));
1616 fprintf_unfiltered (gdb_stdlog
,
1617 "record_get_bookmark returns %s\n", ret
);
1619 fprintf_unfiltered (gdb_stdlog
,
1620 "record_get_bookmark returns NULL\n");
1625 /* The implementation of the command "record goto". */
1626 static void cmd_record_goto (char *, int);
1628 /* "to_goto_bookmark" method for process record and prec over core. */
1631 record_goto_bookmark (gdb_byte
*bookmark
, int from_tty
)
1634 fprintf_unfiltered (gdb_stdlog
,
1635 "record_goto_bookmark receives %s\n", bookmark
);
1637 if (bookmark
[0] == '\'' || bookmark
[0] == '\"')
1639 if (bookmark
[strlen (bookmark
) - 1] != bookmark
[0])
1640 error (_("Unbalanced quotes: %s"), bookmark
);
1642 /* Strip trailing quote. */
1643 bookmark
[strlen (bookmark
) - 1] = '\0';
1644 /* Strip leading quote. */
1646 /* Pass along to cmd_record_goto. */
1649 cmd_record_goto ((char *) bookmark
, from_tty
);
1654 init_record_ops (void)
1656 record_ops
.to_shortname
= "record";
1657 record_ops
.to_longname
= "Process record and replay target";
1659 "Log program while executing and replay execution from log.";
1660 record_ops
.to_open
= record_open
;
1661 record_ops
.to_close
= record_close
;
1662 record_ops
.to_resume
= record_resume
;
1663 record_ops
.to_wait
= record_wait
;
1664 record_ops
.to_disconnect
= record_disconnect
;
1665 record_ops
.to_detach
= record_detach
;
1666 record_ops
.to_mourn_inferior
= record_mourn_inferior
;
1667 record_ops
.to_kill
= record_kill
;
1668 record_ops
.to_create_inferior
= find_default_create_inferior
;
1669 record_ops
.to_store_registers
= record_store_registers
;
1670 record_ops
.to_xfer_partial
= record_xfer_partial
;
1671 record_ops
.to_insert_breakpoint
= record_insert_breakpoint
;
1672 record_ops
.to_remove_breakpoint
= record_remove_breakpoint
;
1673 record_ops
.to_stopped_by_watchpoint
= record_stopped_by_watchpoint
;
1674 record_ops
.to_stopped_data_address
= record_stopped_data_address
;
1675 record_ops
.to_can_execute_reverse
= record_can_execute_reverse
;
1676 record_ops
.to_stratum
= record_stratum
;
1677 /* Add bookmark target methods. */
1678 record_ops
.to_get_bookmark
= record_get_bookmark
;
1679 record_ops
.to_goto_bookmark
= record_goto_bookmark
;
1680 record_ops
.to_magic
= OPS_MAGIC
;
1683 /* "to_resume" method for prec over corefile. */
1686 record_core_resume (struct target_ops
*ops
, ptid_t ptid
, int step
,
1687 enum target_signal signal
)
1689 record_resume_step
= step
;
1692 /* "to_kill" method for prec over corefile. */
1695 record_core_kill (struct target_ops
*ops
)
1698 fprintf_unfiltered (gdb_stdlog
, "Process record: record_core_kill\n");
1700 unpush_target (&record_core_ops
);
1703 /* "to_fetch_registers" method for prec over corefile. */
1706 record_core_fetch_registers (struct target_ops
*ops
,
1707 struct regcache
*regcache
,
1712 int num
= gdbarch_num_regs (get_regcache_arch (regcache
));
1715 for (i
= 0; i
< num
; i
++)
1716 regcache_raw_supply (regcache
, i
,
1717 record_core_regbuf
+ MAX_REGISTER_SIZE
* i
);
1720 regcache_raw_supply (regcache
, regno
,
1721 record_core_regbuf
+ MAX_REGISTER_SIZE
* regno
);
1724 /* "to_prepare_to_store" method for prec over corefile. */
1727 record_core_prepare_to_store (struct regcache
*regcache
)
1731 /* "to_store_registers" method for prec over corefile. */
1734 record_core_store_registers (struct target_ops
*ops
,
1735 struct regcache
*regcache
,
1738 if (record_gdb_operation_disable
)
1739 regcache_raw_collect (regcache
, regno
,
1740 record_core_regbuf
+ MAX_REGISTER_SIZE
* regno
);
1742 error (_("You can't do that without a process to debug."));
1745 /* "to_xfer_partial" method for prec over corefile. */
1748 record_core_xfer_partial (struct target_ops
*ops
, enum target_object object
,
1749 const char *annex
, gdb_byte
*readbuf
,
1750 const gdb_byte
*writebuf
, ULONGEST offset
,
1753 if (object
== TARGET_OBJECT_MEMORY
)
1755 if (record_gdb_operation_disable
|| !writebuf
)
1757 struct target_section
*p
;
1759 for (p
= record_core_start
; p
< record_core_end
; p
++)
1761 if (offset
>= p
->addr
)
1763 struct record_core_buf_entry
*entry
;
1764 ULONGEST sec_offset
;
1766 if (offset
>= p
->endaddr
)
1769 if (offset
+ len
> p
->endaddr
)
1770 len
= p
->endaddr
- offset
;
1772 sec_offset
= offset
- p
->addr
;
1774 /* Read readbuf or write writebuf p, offset, len. */
1776 if (p
->the_bfd_section
->flags
& SEC_CONSTRUCTOR
1777 || (p
->the_bfd_section
->flags
& SEC_HAS_CONTENTS
) == 0)
1780 memset (readbuf
, 0, len
);
1783 /* Get record_core_buf_entry. */
1784 for (entry
= record_core_buf_list
; entry
;
1785 entry
= entry
->prev
)
1792 /* Add a new entry. */
1793 entry
= (struct record_core_buf_entry
*)
1794 xmalloc (sizeof (struct record_core_buf_entry
));
1796 if (!bfd_malloc_and_get_section (p
->bfd
,
1803 entry
->prev
= record_core_buf_list
;
1804 record_core_buf_list
= entry
;
1807 memcpy (entry
->buf
+ sec_offset
, writebuf
,
1813 return record_beneath_to_xfer_partial
1814 (record_beneath_to_xfer_partial_ops
,
1815 object
, annex
, readbuf
, writebuf
,
1818 memcpy (readbuf
, entry
->buf
+ sec_offset
,
1829 error (_("You can't do that without a process to debug."));
1832 return record_beneath_to_xfer_partial (record_beneath_to_xfer_partial_ops
,
1833 object
, annex
, readbuf
, writebuf
,
1837 /* "to_insert_breakpoint" method for prec over corefile. */
1840 record_core_insert_breakpoint (struct gdbarch
*gdbarch
,
1841 struct bp_target_info
*bp_tgt
)
1846 /* "to_remove_breakpoint" method for prec over corefile. */
1849 record_core_remove_breakpoint (struct gdbarch
*gdbarch
,
1850 struct bp_target_info
*bp_tgt
)
1855 /* "to_has_execution" method for prec over corefile. */
1858 record_core_has_execution (struct target_ops
*ops
)
1864 init_record_core_ops (void)
1866 record_core_ops
.to_shortname
= "record-core";
1867 record_core_ops
.to_longname
= "Process record and replay target";
1868 record_core_ops
.to_doc
=
1869 "Log program while executing and replay execution from log.";
1870 record_core_ops
.to_open
= record_open
;
1871 record_core_ops
.to_close
= record_close
;
1872 record_core_ops
.to_resume
= record_core_resume
;
1873 record_core_ops
.to_wait
= record_wait
;
1874 record_core_ops
.to_kill
= record_core_kill
;
1875 record_core_ops
.to_fetch_registers
= record_core_fetch_registers
;
1876 record_core_ops
.to_prepare_to_store
= record_core_prepare_to_store
;
1877 record_core_ops
.to_store_registers
= record_core_store_registers
;
1878 record_core_ops
.to_xfer_partial
= record_core_xfer_partial
;
1879 record_core_ops
.to_insert_breakpoint
= record_core_insert_breakpoint
;
1880 record_core_ops
.to_remove_breakpoint
= record_core_remove_breakpoint
;
1881 record_core_ops
.to_stopped_by_watchpoint
= record_stopped_by_watchpoint
;
1882 record_core_ops
.to_stopped_data_address
= record_stopped_data_address
;
1883 record_core_ops
.to_can_execute_reverse
= record_can_execute_reverse
;
1884 record_core_ops
.to_has_execution
= record_core_has_execution
;
1885 record_core_ops
.to_stratum
= record_stratum
;
1886 /* Add bookmark target methods. */
1887 record_core_ops
.to_get_bookmark
= record_get_bookmark
;
1888 record_core_ops
.to_goto_bookmark
= record_goto_bookmark
;
1889 record_core_ops
.to_magic
= OPS_MAGIC
;
1892 /* Implement "show record debug" command. */
1895 show_record_debug (struct ui_file
*file
, int from_tty
,
1896 struct cmd_list_element
*c
, const char *value
)
1898 fprintf_filtered (file
, _("Debugging of process record target is %s.\n"),
1902 /* Alias for "target record". */
1905 cmd_record_start (char *args
, int from_tty
)
1907 execute_command ("target record", from_tty
);
1910 /* Truncate the record log from the present point
1911 of replay until the end. */
1914 cmd_record_delete (char *args
, int from_tty
)
1916 if (current_target
.to_stratum
== record_stratum
)
1918 if (RECORD_IS_REPLAY
)
1920 if (!from_tty
|| query (_("Delete the log from this point forward "
1921 "and begin to record the running message "
1923 record_list_release_following (record_list
);
1926 printf_unfiltered (_("Already at end of record list.\n"));
1930 printf_unfiltered (_("Process record is not started.\n"));
1933 /* Implement the "stoprecord" or "record stop" command. */
1936 cmd_record_stop (char *args
, int from_tty
)
1938 if (current_target
.to_stratum
== record_stratum
)
1940 unpush_target (&record_ops
);
1941 printf_unfiltered (_("Process record is stopped and all execution "
1942 "logs are deleted.\n"));
1945 printf_unfiltered (_("Process record is not started.\n"));
1948 /* Set upper limit of record log size. */
1951 set_record_insn_max_num (char *args
, int from_tty
, struct cmd_list_element
*c
)
1953 if (record_insn_num
> record_insn_max_num
&& record_insn_max_num
)
1955 /* Count down record_insn_num while releasing records from list. */
1956 while (record_insn_num
> record_insn_max_num
)
1958 record_list_release_first ();
1964 static struct cmd_list_element
*record_cmdlist
, *set_record_cmdlist
,
1965 *show_record_cmdlist
, *info_record_cmdlist
;
1968 set_record_command (char *args
, int from_tty
)
1970 printf_unfiltered (_("\
1971 \"set record\" must be followed by an apporpriate subcommand.\n"));
1972 help_list (set_record_cmdlist
, "set record ", all_commands
, gdb_stdout
);
1976 show_record_command (char *args
, int from_tty
)
1978 cmd_show_list (show_record_cmdlist
, from_tty
, "");
1981 /* Display some statistics about the execution log. */
1984 info_record_command (char *args
, int from_tty
)
1986 struct record_entry
*p
;
1988 if (current_target
.to_stratum
== record_stratum
)
1990 if (RECORD_IS_REPLAY
)
1991 printf_filtered (_("Replay mode:\n"));
1993 printf_filtered (_("Record mode:\n"));
1995 /* Find entry for first actual instruction in the log. */
1996 for (p
= record_first
.next
;
1997 p
!= NULL
&& p
->type
!= record_end
;
2001 /* Do we have a log at all? */
2002 if (p
!= NULL
&& p
->type
== record_end
)
2004 /* Display instruction number for first instruction in the log. */
2005 printf_filtered (_("Lowest recorded instruction number is %s.\n"),
2006 pulongest (p
->u
.end
.insn_num
));
2008 /* If in replay mode, display where we are in the log. */
2009 if (RECORD_IS_REPLAY
)
2010 printf_filtered (_("Current instruction number is %s.\n"),
2011 pulongest (record_list
->u
.end
.insn_num
));
2013 /* Display instruction number for last instruction in the log. */
2014 printf_filtered (_("Highest recorded instruction number is %s.\n"),
2015 pulongest (record_insn_count
));
2017 /* Display log count. */
2018 printf_filtered (_("Log contains %d instructions.\n"),
2023 printf_filtered (_("No instructions have been logged.\n"));
2028 printf_filtered (_("target record is not active.\n"));
2031 /* Display max log size. */
2032 printf_filtered (_("Max logged instructions is %d.\n"),
2033 record_insn_max_num
);
2036 /* Record log save-file format
2037 Version 1 (never released)
2040 4 bytes: magic number htonl(0x20090829).
2041 NOTE: be sure to change whenever this file format changes!
2045 1 byte: record type (record_end, see enum record_type).
2047 1 byte: record type (record_reg, see enum record_type).
2048 8 bytes: register id (network byte order).
2049 MAX_REGISTER_SIZE bytes: register value.
2051 1 byte: record type (record_mem, see enum record_type).
2052 8 bytes: memory length (network byte order).
2053 8 bytes: memory address (network byte order).
2054 n bytes: memory value (n == memory length).
2057 4 bytes: magic number netorder32(0x20091016).
2058 NOTE: be sure to change whenever this file format changes!
2062 1 byte: record type (record_end, see enum record_type).
2064 4 bytes: instruction count
2066 1 byte: record type (record_reg, see enum record_type).
2067 4 bytes: register id (network byte order).
2068 n bytes: register value (n == actual register size).
2069 (eg. 4 bytes for x86 general registers).
2071 1 byte: record type (record_mem, see enum record_type).
2072 4 bytes: memory length (network byte order).
2073 8 bytes: memory address (network byte order).
2074 n bytes: memory value (n == memory length).
2078 /* bfdcore_read -- read bytes from a core file section. */
2081 bfdcore_read (bfd
*obfd
, asection
*osec
, void *buf
, int len
, int *offset
)
2083 int ret
= bfd_get_section_contents (obfd
, osec
, buf
, *offset
, len
);
2088 error (_("Failed to read %d bytes from core file %s ('%s').\n"),
2089 len
, bfd_get_filename (obfd
),
2090 bfd_errmsg (bfd_get_error ()));
2093 static inline uint64_t
2094 netorder64 (uint64_t input
)
2098 store_unsigned_integer ((gdb_byte
*) &ret
, sizeof (ret
),
2099 BFD_ENDIAN_BIG
, input
);
2103 static inline uint32_t
2104 netorder32 (uint32_t input
)
2108 store_unsigned_integer ((gdb_byte
*) &ret
, sizeof (ret
),
2109 BFD_ENDIAN_BIG
, input
);
2113 static inline uint16_t
2114 netorder16 (uint16_t input
)
2118 store_unsigned_integer ((gdb_byte
*) &ret
, sizeof (ret
),
2119 BFD_ENDIAN_BIG
, input
);
2123 /* Restore the execution log from a core_bfd file. */
2125 record_restore (void)
2128 struct cleanup
*old_cleanups
;
2129 struct record_entry
*rec
;
2133 struct regcache
*regcache
;
2135 /* We restore the execution log from the open core bfd,
2137 if (core_bfd
== NULL
)
2140 /* "record_restore" can only be called when record list is empty. */
2141 gdb_assert (record_first
.next
== NULL
);
2144 fprintf_unfiltered (gdb_stdlog
, "Restoring recording from core file.\n");
2146 /* Now need to find our special note section. */
2147 osec
= bfd_get_section_by_name (core_bfd
, "null0");
2148 osec_size
= bfd_section_size (core_bfd
, osec
);
2150 fprintf_unfiltered (gdb_stdlog
, "Find precord section %s.\n",
2151 osec
? "succeeded" : "failed");
2155 fprintf_unfiltered (gdb_stdlog
, "%s", bfd_section_name (core_bfd
, osec
));
2157 /* Check the magic code. */
2158 bfdcore_read (core_bfd
, osec
, &magic
, sizeof (magic
), &bfd_offset
);
2159 if (magic
!= RECORD_FILE_MAGIC
)
2160 error (_("Version mis-match or file format error in core file %s."),
2161 bfd_get_filename (core_bfd
));
2163 fprintf_unfiltered (gdb_stdlog
, "\
2164 Reading 4-byte magic cookie RECORD_FILE_MAGIC (0x%s)\n",
2165 phex_nz (netorder32 (magic
), 4));
2167 /* Restore the entries in recfd into record_arch_list_head and
2168 record_arch_list_tail. */
2169 record_arch_list_head
= NULL
;
2170 record_arch_list_tail
= NULL
;
2171 record_insn_num
= 0;
2172 old_cleanups
= make_cleanup (record_arch_list_cleanups
, 0);
2173 regcache
= get_current_regcache ();
2178 uint32_t regnum
, len
, signal
, count
;
2181 /* We are finished when offset reaches osec_size. */
2182 if (bfd_offset
>= osec_size
)
2184 bfdcore_read (core_bfd
, osec
, &rectype
, sizeof (rectype
), &bfd_offset
);
2188 case record_reg
: /* reg */
2189 /* Get register number to regnum. */
2190 bfdcore_read (core_bfd
, osec
, ®num
,
2191 sizeof (regnum
), &bfd_offset
);
2192 regnum
= netorder32 (regnum
);
2194 rec
= record_reg_alloc (regcache
, regnum
);
2197 bfdcore_read (core_bfd
, osec
, record_get_loc (rec
),
2198 rec
->u
.reg
.len
, &bfd_offset
);
2201 fprintf_unfiltered (gdb_stdlog
, "\
2202 Reading register %d (1 plus %lu plus %d bytes)\n",
2204 (unsigned long) sizeof (regnum
),
2208 case record_mem
: /* mem */
2210 bfdcore_read (core_bfd
, osec
, &len
,
2211 sizeof (len
), &bfd_offset
);
2212 len
= netorder32 (len
);
2215 bfdcore_read (core_bfd
, osec
, &addr
,
2216 sizeof (addr
), &bfd_offset
);
2217 addr
= netorder64 (addr
);
2219 rec
= record_mem_alloc (addr
, len
);
2222 bfdcore_read (core_bfd
, osec
, record_get_loc (rec
),
2223 rec
->u
.mem
.len
, &bfd_offset
);
2226 fprintf_unfiltered (gdb_stdlog
, "\
2227 Reading memory %s (1 plus %lu plus %lu plus %d bytes)\n",
2228 paddress (get_current_arch (),
2230 (unsigned long) sizeof (addr
),
2231 (unsigned long) sizeof (len
),
2235 case record_end
: /* end */
2236 rec
= record_end_alloc ();
2239 /* Get signal value. */
2240 bfdcore_read (core_bfd
, osec
, &signal
,
2241 sizeof (signal
), &bfd_offset
);
2242 signal
= netorder32 (signal
);
2243 rec
->u
.end
.sigval
= signal
;
2245 /* Get insn count. */
2246 bfdcore_read (core_bfd
, osec
, &count
,
2247 sizeof (count
), &bfd_offset
);
2248 count
= netorder32 (count
);
2249 rec
->u
.end
.insn_num
= count
;
2250 record_insn_count
= count
+ 1;
2252 fprintf_unfiltered (gdb_stdlog
, "\
2253 Reading record_end (1 + %lu + %lu bytes), offset == %s\n",
2254 (unsigned long) sizeof (signal
),
2255 (unsigned long) sizeof (count
),
2256 paddress (get_current_arch (),
2261 error (_("Bad entry type in core file %s."),
2262 bfd_get_filename (core_bfd
));
2266 /* Add rec to record arch list. */
2267 record_arch_list_add (rec
);
2270 discard_cleanups (old_cleanups
);
2272 /* Add record_arch_list_head to the end of record list. */
2273 record_first
.next
= record_arch_list_head
;
2274 record_arch_list_head
->prev
= &record_first
;
2275 record_arch_list_tail
->next
= NULL
;
2276 record_list
= &record_first
;
2278 /* Update record_insn_max_num. */
2279 if (record_insn_num
> record_insn_max_num
)
2281 record_insn_max_num
= record_insn_num
;
2282 warning (_("Auto increase record/replay buffer limit to %d."),
2283 record_insn_max_num
);
2287 printf_filtered (_("Restored records from core file %s.\n"),
2288 bfd_get_filename (core_bfd
));
2290 print_stack_frame (get_selected_frame (NULL
), 1, SRC_AND_LOC
);
2293 /* bfdcore_write -- write bytes into a core file section. */
2296 bfdcore_write (bfd
*obfd
, asection
*osec
, void *buf
, int len
, int *offset
)
2298 int ret
= bfd_set_section_contents (obfd
, osec
, buf
, *offset
, len
);
2303 error (_("Failed to write %d bytes to core file %s ('%s').\n"),
2304 len
, bfd_get_filename (obfd
),
2305 bfd_errmsg (bfd_get_error ()));
2308 /* Restore the execution log from a file. We use a modified elf
2309 corefile format, with an extra section for our data. */
2312 cmd_record_restore (char *args
, int from_tty
)
2314 core_file_command (args
, from_tty
);
2315 record_open (args
, from_tty
);
2319 record_save_cleanups (void *data
)
2322 char *pathname
= xstrdup (bfd_get_filename (obfd
));
2329 /* Save the execution log to a file. We use a modified elf corefile
2330 format, with an extra section for our data. */
2333 cmd_record_save (char *args
, int from_tty
)
2335 char *recfilename
, recfilename_buffer
[40];
2336 struct record_entry
*cur_record_list
;
2338 struct regcache
*regcache
;
2339 struct gdbarch
*gdbarch
;
2340 struct cleanup
*old_cleanups
;
2341 struct cleanup
*set_cleanups
;
2344 asection
*osec
= NULL
;
2347 if (strcmp (current_target
.to_shortname
, "record") != 0)
2348 error (_("This command can only be used with target 'record'.\n"
2349 "Use 'target record' first.\n"));
2355 /* Default recfile name is "gdb_record.PID". */
2356 snprintf (recfilename_buffer
, sizeof (recfilename_buffer
),
2357 "gdb_record.%d", PIDGET (inferior_ptid
));
2358 recfilename
= recfilename_buffer
;
2361 /* Open the save file. */
2363 fprintf_unfiltered (gdb_stdlog
, "Saving execution log to core file '%s'\n",
2366 /* Open the output file. */
2367 obfd
= create_gcore_bfd (recfilename
);
2368 old_cleanups
= make_cleanup (record_save_cleanups
, obfd
);
2370 /* Save the current record entry to "cur_record_list". */
2371 cur_record_list
= record_list
;
2373 /* Get the values of regcache and gdbarch. */
2374 regcache
= get_current_regcache ();
2375 gdbarch
= get_regcache_arch (regcache
);
2377 /* Disable the GDB operation record. */
2378 set_cleanups
= record_gdb_operation_disable_set ();
2380 /* Reverse execute to the begin of record list. */
2383 /* Check for beginning and end of log. */
2384 if (record_list
== &record_first
)
2387 record_exec_insn (regcache
, gdbarch
, record_list
);
2389 if (record_list
->prev
)
2390 record_list
= record_list
->prev
;
2393 /* Compute the size needed for the extra bfd section. */
2394 save_size
= 4; /* magic cookie */
2395 for (record_list
= record_first
.next
; record_list
;
2396 record_list
= record_list
->next
)
2397 switch (record_list
->type
)
2400 save_size
+= 1 + 4 + 4;
2403 save_size
+= 1 + 4 + record_list
->u
.reg
.len
;
2406 save_size
+= 1 + 4 + 8 + record_list
->u
.mem
.len
;
2410 /* Make the new bfd section. */
2411 osec
= bfd_make_section_anyway_with_flags (obfd
, "precord",
2415 error (_("Failed to create 'precord' section for corefile %s: %s"),
2417 bfd_errmsg (bfd_get_error ()));
2418 bfd_set_section_size (obfd
, osec
, save_size
);
2419 bfd_set_section_vma (obfd
, osec
, 0);
2420 bfd_set_section_alignment (obfd
, osec
, 0);
2421 bfd_section_lma (obfd
, osec
) = 0;
2423 /* Save corefile state. */
2424 write_gcore_file (obfd
);
2426 /* Write out the record log. */
2427 /* Write the magic code. */
2428 magic
= RECORD_FILE_MAGIC
;
2430 fprintf_unfiltered (gdb_stdlog
, "\
2431 Writing 4-byte magic cookie RECORD_FILE_MAGIC (0x%s)\n",
2432 phex_nz (magic
, 4));
2433 bfdcore_write (obfd
, osec
, &magic
, sizeof (magic
), &bfd_offset
);
2435 /* Save the entries to recfd and forward execute to the end of
2437 record_list
= &record_first
;
2441 if (record_list
!= &record_first
)
2444 uint32_t regnum
, len
, signal
, count
;
2447 type
= record_list
->type
;
2448 bfdcore_write (obfd
, osec
, &type
, sizeof (type
), &bfd_offset
);
2450 switch (record_list
->type
)
2452 case record_reg
: /* reg */
2454 fprintf_unfiltered (gdb_stdlog
, "\
2455 Writing register %d (1 plus %lu plus %d bytes)\n",
2456 record_list
->u
.reg
.num
,
2457 (unsigned long) sizeof (regnum
),
2458 record_list
->u
.reg
.len
);
2461 regnum
= netorder32 (record_list
->u
.reg
.num
);
2462 bfdcore_write (obfd
, osec
, ®num
,
2463 sizeof (regnum
), &bfd_offset
);
2466 bfdcore_write (obfd
, osec
, record_get_loc (record_list
),
2467 record_list
->u
.reg
.len
, &bfd_offset
);
2470 case record_mem
: /* mem */
2472 fprintf_unfiltered (gdb_stdlog
, "\
2473 Writing memory %s (1 plus %lu plus %lu plus %d bytes)\n",
2475 record_list
->u
.mem
.addr
),
2476 (unsigned long) sizeof (addr
),
2477 (unsigned long) sizeof (len
),
2478 record_list
->u
.mem
.len
);
2481 len
= netorder32 (record_list
->u
.mem
.len
);
2482 bfdcore_write (obfd
, osec
, &len
, sizeof (len
), &bfd_offset
);
2484 /* Write memaddr. */
2485 addr
= netorder64 (record_list
->u
.mem
.addr
);
2486 bfdcore_write (obfd
, osec
, &addr
,
2487 sizeof (addr
), &bfd_offset
);
2490 bfdcore_write (obfd
, osec
, record_get_loc (record_list
),
2491 record_list
->u
.mem
.len
, &bfd_offset
);
2496 fprintf_unfiltered (gdb_stdlog
, "\
2497 Writing record_end (1 + %lu + %lu bytes)\n",
2498 (unsigned long) sizeof (signal
),
2499 (unsigned long) sizeof (count
));
2500 /* Write signal value. */
2501 signal
= netorder32 (record_list
->u
.end
.sigval
);
2502 bfdcore_write (obfd
, osec
, &signal
,
2503 sizeof (signal
), &bfd_offset
);
2505 /* Write insn count. */
2506 count
= netorder32 (record_list
->u
.end
.insn_num
);
2507 bfdcore_write (obfd
, osec
, &count
,
2508 sizeof (count
), &bfd_offset
);
2513 /* Execute entry. */
2514 record_exec_insn (regcache
, gdbarch
, record_list
);
2516 if (record_list
->next
)
2517 record_list
= record_list
->next
;
2522 /* Reverse execute to cur_record_list. */
2525 /* Check for beginning and end of log. */
2526 if (record_list
== cur_record_list
)
2529 record_exec_insn (regcache
, gdbarch
, record_list
);
2531 if (record_list
->prev
)
2532 record_list
= record_list
->prev
;
2535 do_cleanups (set_cleanups
);
2537 discard_cleanups (old_cleanups
);
2540 printf_filtered (_("Saved core file %s with execution log.\n"),
2544 /* record_goto_insn -- rewind the record log (forward or backward,
2545 depending on DIR) to the given entry, changing the program state
2549 record_goto_insn (struct record_entry
*entry
,
2550 enum exec_direction_kind dir
)
2552 struct cleanup
*set_cleanups
= record_gdb_operation_disable_set ();
2553 struct regcache
*regcache
= get_current_regcache ();
2554 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
2556 /* Assume everything is valid: we will hit the entry,
2557 and we will not hit the end of the recording. */
2559 if (dir
== EXEC_FORWARD
)
2560 record_list
= record_list
->next
;
2564 record_exec_insn (regcache
, gdbarch
, record_list
);
2565 if (dir
== EXEC_REVERSE
)
2566 record_list
= record_list
->prev
;
2568 record_list
= record_list
->next
;
2569 } while (record_list
!= entry
);
2570 do_cleanups (set_cleanups
);
2573 /* "record goto" command. Argument is an instruction number,
2574 as given by "info record".
2576 Rewinds the recording (forward or backward) to the given instruction. */
2579 cmd_record_goto (char *arg
, int from_tty
)
2581 struct record_entry
*p
= NULL
;
2582 ULONGEST target_insn
= 0;
2584 if (arg
== NULL
|| *arg
== '\0')
2585 error (_("Command requires an argument (insn number to go to)."));
2587 if (strncmp (arg
, "start", strlen ("start")) == 0
2588 || strncmp (arg
, "begin", strlen ("begin")) == 0)
2590 /* Special case. Find first insn. */
2591 for (p
= &record_first
; p
!= NULL
; p
= p
->next
)
2592 if (p
->type
== record_end
)
2595 target_insn
= p
->u
.end
.insn_num
;
2597 else if (strncmp (arg
, "end", strlen ("end")) == 0)
2599 /* Special case. Find last insn. */
2600 for (p
= record_list
; p
->next
!= NULL
; p
= p
->next
)
2602 for (; p
!= NULL
; p
= p
->prev
)
2603 if (p
->type
== record_end
)
2606 target_insn
= p
->u
.end
.insn_num
;
2610 /* General case. Find designated insn. */
2611 target_insn
= parse_and_eval_long (arg
);
2613 for (p
= &record_first
; p
!= NULL
; p
= p
->next
)
2614 if (p
->type
== record_end
&& p
->u
.end
.insn_num
== target_insn
)
2619 error (_("Target insn '%s' not found."), arg
);
2620 else if (p
== record_list
)
2621 error (_("Already at insn '%s'."), arg
);
2622 else if (p
->u
.end
.insn_num
> record_list
->u
.end
.insn_num
)
2624 printf_filtered (_("Go forward to insn number %s\n"),
2625 pulongest (target_insn
));
2626 record_goto_insn (p
, EXEC_FORWARD
);
2630 printf_filtered (_("Go backward to insn number %s\n"),
2631 pulongest (target_insn
));
2632 record_goto_insn (p
, EXEC_REVERSE
);
2634 registers_changed ();
2635 reinit_frame_cache ();
2636 print_stack_frame (get_selected_frame (NULL
), 1, SRC_AND_LOC
);
2640 _initialize_record (void)
2642 struct cmd_list_element
*c
;
2644 /* Init record_first. */
2645 record_first
.prev
= NULL
;
2646 record_first
.next
= NULL
;
2647 record_first
.type
= record_end
;
2650 add_target (&record_ops
);
2651 init_record_core_ops ();
2652 add_target (&record_core_ops
);
2654 add_setshow_zinteger_cmd ("record", no_class
, &record_debug
,
2655 _("Set debugging of record/replay feature."),
2656 _("Show debugging of record/replay feature."),
2657 _("When enabled, debugging output for "
2658 "record/replay feature is displayed."),
2659 NULL
, show_record_debug
, &setdebuglist
,
2662 c
= add_prefix_cmd ("record", class_obscure
, cmd_record_start
,
2663 _("Abbreviated form of \"target record\" command."),
2664 &record_cmdlist
, "record ", 0, &cmdlist
);
2665 set_cmd_completer (c
, filename_completer
);
2667 add_com_alias ("rec", "record", class_obscure
, 1);
2668 add_prefix_cmd ("record", class_support
, set_record_command
,
2669 _("Set record options"), &set_record_cmdlist
,
2670 "set record ", 0, &setlist
);
2671 add_alias_cmd ("rec", "record", class_obscure
, 1, &setlist
);
2672 add_prefix_cmd ("record", class_support
, show_record_command
,
2673 _("Show record options"), &show_record_cmdlist
,
2674 "show record ", 0, &showlist
);
2675 add_alias_cmd ("rec", "record", class_obscure
, 1, &showlist
);
2676 add_prefix_cmd ("record", class_support
, info_record_command
,
2677 _("Info record options"), &info_record_cmdlist
,
2678 "info record ", 0, &infolist
);
2679 add_alias_cmd ("rec", "record", class_obscure
, 1, &infolist
);
2681 c
= add_cmd ("save", class_obscure
, cmd_record_save
,
2682 _("Save the execution log to a file.\n\
2683 Argument is optional filename.\n\
2684 Default filename is 'gdb_record.<process_id>'."),
2686 set_cmd_completer (c
, filename_completer
);
2688 c
= add_cmd ("restore", class_obscure
, cmd_record_restore
,
2689 _("Restore the execution log from a file.\n\
2690 Argument is filename. File must be created with 'record save'."),
2692 set_cmd_completer (c
, filename_completer
);
2694 add_cmd ("delete", class_obscure
, cmd_record_delete
,
2695 _("Delete the rest of execution log and start recording it anew."),
2697 add_alias_cmd ("d", "delete", class_obscure
, 1, &record_cmdlist
);
2698 add_alias_cmd ("del", "delete", class_obscure
, 1, &record_cmdlist
);
2700 add_cmd ("stop", class_obscure
, cmd_record_stop
,
2701 _("Stop the record/replay target."),
2703 add_alias_cmd ("s", "stop", class_obscure
, 1, &record_cmdlist
);
2705 /* Record instructions number limit command. */
2706 add_setshow_boolean_cmd ("stop-at-limit", no_class
,
2707 &record_stop_at_limit
, _("\
2708 Set whether record/replay stops when record/replay buffer becomes full."), _("\
2709 Show whether record/replay stops when record/replay buffer becomes full."), _("\
2711 When ON, if the record/replay buffer becomes full, ask user what to do.\n\
2712 When OFF, if the record/replay buffer becomes full,\n\
2713 delete the oldest recorded instruction to make room for each new one."),
2715 &set_record_cmdlist
, &show_record_cmdlist
);
2716 add_setshow_uinteger_cmd ("insn-number-max", no_class
,
2717 &record_insn_max_num
,
2718 _("Set record/replay buffer limit."),
2719 _("Show record/replay buffer limit."), _("\
2720 Set the maximum number of instructions to be stored in the\n\
2721 record/replay buffer. Zero means unlimited. Default is 200000."),
2722 set_record_insn_max_num
,
2723 NULL
, &set_record_cmdlist
, &show_record_cmdlist
);
2725 add_cmd ("goto", class_obscure
, cmd_record_goto
, _("\
2726 Restore the program to its state at instruction number N.\n\
2727 Argument is instruction number, as shown by 'info record'."),