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 /* If true, query if PREC cannot record memory
156 change of next instruction. */
157 int record_memory_query
= 0;
159 struct record_core_buf_entry
161 struct record_core_buf_entry
*prev
;
162 struct target_section
*p
;
166 /* Record buf with core target. */
167 static gdb_byte
*record_core_regbuf
= NULL
;
168 static struct target_section
*record_core_start
;
169 static struct target_section
*record_core_end
;
170 static struct record_core_buf_entry
*record_core_buf_list
= NULL
;
172 /* The following variables are used for managing the linked list that
173 represents the execution log.
175 record_first is the anchor that holds down the beginning of the list.
177 record_list serves two functions:
178 1) In record mode, it anchors the end of the list.
179 2) In replay mode, it traverses the list and points to
180 the next instruction that must be emulated.
182 record_arch_list_head and record_arch_list_tail are used to manage
183 a separate list, which is used to build up the change elements of
184 the currently executing instruction during record mode. When this
185 instruction has been completely annotated in the "arch list", it
186 will be appended to the main execution log. */
188 static struct record_entry record_first
;
189 static struct record_entry
*record_list
= &record_first
;
190 static struct record_entry
*record_arch_list_head
= NULL
;
191 static struct record_entry
*record_arch_list_tail
= NULL
;
193 /* 1 ask user. 0 auto delete the last struct record_entry. */
194 static int record_stop_at_limit
= 1;
195 /* Maximum allowed number of insns in execution log. */
196 static unsigned int record_insn_max_num
= DEFAULT_RECORD_INSN_MAX_NUM
;
197 /* Actual count of insns presently in execution log. */
198 static int record_insn_num
= 0;
199 /* Count of insns logged so far (may be larger
200 than count of insns presently in execution log). */
201 static ULONGEST record_insn_count
;
203 /* The target_ops of process record. */
204 static struct target_ops record_ops
;
205 static struct target_ops record_core_ops
;
207 /* The beneath function pointers. */
208 static struct target_ops
*record_beneath_to_resume_ops
;
209 static void (*record_beneath_to_resume
) (struct target_ops
*, ptid_t
, int,
211 static struct target_ops
*record_beneath_to_wait_ops
;
212 static ptid_t (*record_beneath_to_wait
) (struct target_ops
*, ptid_t
,
213 struct target_waitstatus
*,
215 static struct target_ops
*record_beneath_to_store_registers_ops
;
216 static void (*record_beneath_to_store_registers
) (struct target_ops
*,
219 static struct target_ops
*record_beneath_to_xfer_partial_ops
;
220 static LONGEST (*record_beneath_to_xfer_partial
) (struct target_ops
*ops
,
221 enum target_object object
,
224 const gdb_byte
*writebuf
,
227 static int (*record_beneath_to_insert_breakpoint
) (struct gdbarch
*,
228 struct bp_target_info
*);
229 static int (*record_beneath_to_remove_breakpoint
) (struct gdbarch
*,
230 struct bp_target_info
*);
231 static int (*record_beneath_to_stopped_by_watchpoint
) (void);
232 static int (*record_beneath_to_stopped_data_address
) (struct target_ops
*,
235 /* Alloc and free functions for record_reg, record_mem, and record_end
238 /* Alloc a record_reg record entry. */
240 static inline struct record_entry
*
241 record_reg_alloc (struct regcache
*regcache
, int regnum
)
243 struct record_entry
*rec
;
244 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
246 rec
= (struct record_entry
*) xcalloc (1, sizeof (struct record_entry
));
247 rec
->type
= record_reg
;
248 rec
->u
.reg
.num
= regnum
;
249 rec
->u
.reg
.len
= register_size (gdbarch
, regnum
);
250 if (rec
->u
.reg
.len
> sizeof (rec
->u
.reg
.u
.buf
))
251 rec
->u
.reg
.u
.ptr
= (gdb_byte
*) xmalloc (rec
->u
.reg
.len
);
256 /* Free a record_reg record entry. */
259 record_reg_release (struct record_entry
*rec
)
261 gdb_assert (rec
->type
== record_reg
);
262 if (rec
->u
.reg
.len
> sizeof (rec
->u
.reg
.u
.buf
))
263 xfree (rec
->u
.reg
.u
.ptr
);
267 /* Alloc a record_mem record entry. */
269 static inline struct record_entry
*
270 record_mem_alloc (CORE_ADDR addr
, int len
)
272 struct record_entry
*rec
;
274 rec
= (struct record_entry
*) xcalloc (1, sizeof (struct record_entry
));
275 rec
->type
= record_mem
;
276 rec
->u
.mem
.addr
= addr
;
277 rec
->u
.mem
.len
= len
;
278 if (rec
->u
.mem
.len
> sizeof (rec
->u
.mem
.u
.buf
))
279 rec
->u
.mem
.u
.ptr
= (gdb_byte
*) xmalloc (len
);
284 /* Free a record_mem record entry. */
287 record_mem_release (struct record_entry
*rec
)
289 gdb_assert (rec
->type
== record_mem
);
290 if (rec
->u
.mem
.len
> sizeof (rec
->u
.mem
.u
.buf
))
291 xfree (rec
->u
.mem
.u
.ptr
);
295 /* Alloc a record_end record entry. */
297 static inline struct record_entry
*
298 record_end_alloc (void)
300 struct record_entry
*rec
;
302 rec
= (struct record_entry
*) xcalloc (1, sizeof (struct record_entry
));
303 rec
->type
= record_end
;
308 /* Free a record_end record entry. */
311 record_end_release (struct record_entry
*rec
)
316 /* Free one record entry, any type.
317 Return entry->type, in case caller wants to know. */
319 static inline enum record_type
320 record_entry_release (struct record_entry
*rec
)
322 enum record_type type
= rec
->type
;
326 record_reg_release (rec
);
329 record_mem_release (rec
);
332 record_end_release (rec
);
338 /* Free all record entries in list pointed to by REC. */
341 record_list_release (struct record_entry
*rec
)
352 record_entry_release (rec
->next
);
355 if (rec
== &record_first
)
358 record_first
.next
= NULL
;
361 record_entry_release (rec
);
364 /* Free all record entries forward of the given list position. */
367 record_list_release_following (struct record_entry
*rec
)
369 struct record_entry
*tmp
= rec
->next
;
375 if (record_entry_release (tmp
) == record_end
)
384 /* Delete the first instruction from the beginning of the log, to make
385 room for adding a new instruction at the end of the log.
387 Note -- this function does not modify record_insn_num. */
390 record_list_release_first (void)
392 struct record_entry
*tmp
;
394 if (!record_first
.next
)
397 /* Loop until a record_end. */
400 /* Cut record_first.next out of the linked list. */
401 tmp
= record_first
.next
;
402 record_first
.next
= tmp
->next
;
403 tmp
->next
->prev
= &record_first
;
405 /* tmp is now isolated, and can be deleted. */
406 if (record_entry_release (tmp
) == record_end
)
407 break; /* End loop at first record_end. */
409 if (!record_first
.next
)
411 gdb_assert (record_insn_num
== 1);
412 break; /* End loop when list is empty. */
417 /* Add a struct record_entry to record_arch_list. */
420 record_arch_list_add (struct record_entry
*rec
)
422 if (record_debug
> 1)
423 fprintf_unfiltered (gdb_stdlog
,
424 "Process record: record_arch_list_add %s.\n",
425 host_address_to_string (rec
));
427 if (record_arch_list_tail
)
429 record_arch_list_tail
->next
= rec
;
430 rec
->prev
= record_arch_list_tail
;
431 record_arch_list_tail
= rec
;
435 record_arch_list_head
= rec
;
436 record_arch_list_tail
= rec
;
440 /* Return the value storage location of a record entry. */
441 static inline gdb_byte
*
442 record_get_loc (struct record_entry
*rec
)
446 if (rec
->u
.mem
.len
> sizeof (rec
->u
.mem
.u
.buf
))
447 return rec
->u
.mem
.u
.ptr
;
449 return rec
->u
.mem
.u
.buf
;
451 if (rec
->u
.reg
.len
> sizeof (rec
->u
.reg
.u
.buf
))
452 return rec
->u
.reg
.u
.ptr
;
454 return rec
->u
.reg
.u
.buf
;
457 gdb_assert_not_reached ("unexpected record_entry type");
462 /* Record the value of a register NUM to record_arch_list. */
465 record_arch_list_add_reg (struct regcache
*regcache
, int regnum
)
467 struct record_entry
*rec
;
469 if (record_debug
> 1)
470 fprintf_unfiltered (gdb_stdlog
,
471 "Process record: add register num = %d to "
475 rec
= record_reg_alloc (regcache
, regnum
);
477 regcache_raw_read (regcache
, regnum
, record_get_loc (rec
));
479 record_arch_list_add (rec
);
484 /* Record the value of a region of memory whose address is ADDR and
485 length is LEN to record_arch_list. */
488 record_arch_list_add_mem (CORE_ADDR addr
, int len
)
490 struct record_entry
*rec
;
492 if (record_debug
> 1)
493 fprintf_unfiltered (gdb_stdlog
,
494 "Process record: add mem addr = %s len = %d to "
496 paddress (target_gdbarch
, addr
), len
);
498 if (!addr
) /* FIXME: Why? Some arch must permit it... */
501 rec
= record_mem_alloc (addr
, len
);
503 if (target_read_memory (addr
, record_get_loc (rec
), len
))
506 fprintf_unfiltered (gdb_stdlog
,
507 "Process record: error reading memory at "
508 "addr = %s len = %d.\n",
509 paddress (target_gdbarch
, addr
), len
);
510 record_mem_release (rec
);
514 record_arch_list_add (rec
);
519 /* Add a record_end type struct record_entry to record_arch_list. */
522 record_arch_list_add_end (void)
524 struct record_entry
*rec
;
526 if (record_debug
> 1)
527 fprintf_unfiltered (gdb_stdlog
,
528 "Process record: add end to arch list.\n");
530 rec
= record_end_alloc ();
531 rec
->u
.end
.sigval
= TARGET_SIGNAL_0
;
532 rec
->u
.end
.insn_num
= ++record_insn_count
;
534 record_arch_list_add (rec
);
540 record_check_insn_num (int set_terminal
)
542 if (record_insn_max_num
)
544 gdb_assert (record_insn_num
<= record_insn_max_num
);
545 if (record_insn_num
== record_insn_max_num
)
547 /* Ask user what to do. */
548 if (record_stop_at_limit
)
553 target_terminal_ours ();
554 q
= yquery (_("Do you want to auto delete previous execution "
555 "log entries when record/replay buffer becomes "
556 "full (record stop-at-limit)?"));
558 target_terminal_inferior ();
560 record_stop_at_limit
= 0;
562 error (_("Process record: stopped by user."));
569 record_arch_list_cleanups (void *ignore
)
571 record_list_release (record_arch_list_tail
);
574 /* Before inferior step (when GDB record the running message, inferior
575 only can step), GDB will call this function to record the values to
576 record_list. This function will call gdbarch_process_record to
577 record the running message of inferior and set them to
578 record_arch_list, and add it to record_list. */
581 record_message (struct regcache
*regcache
, enum target_signal signal
)
584 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
585 struct cleanup
*old_cleanups
= make_cleanup (record_arch_list_cleanups
, 0);
587 record_arch_list_head
= NULL
;
588 record_arch_list_tail
= NULL
;
590 /* Check record_insn_num. */
591 record_check_insn_num (1);
593 /* If gdb sends a signal value to target_resume,
594 save it in the 'end' field of the previous instruction.
596 Maybe process record should record what really happened,
597 rather than what gdb pretends has happened.
599 So if Linux delivered the signal to the child process during
600 the record mode, we will record it and deliver it again in
603 If user says "ignore this signal" during the record mode, then
604 it will be ignored again during the replay mode (no matter if
605 the user says something different, like "deliver this signal"
606 during the replay mode).
608 User should understand that nothing he does during the replay
609 mode will change the behavior of the child. If he tries,
610 then that is a user error.
612 But we should still deliver the signal to gdb during the replay,
613 if we delivered it during the recording. Therefore we should
614 record the signal during record_wait, not record_resume. */
615 if (record_list
!= &record_first
) /* FIXME better way to check */
617 gdb_assert (record_list
->type
== record_end
);
618 record_list
->u
.end
.sigval
= signal
;
621 if (signal
== TARGET_SIGNAL_0
622 || !gdbarch_process_record_signal_p (gdbarch
))
623 ret
= gdbarch_process_record (gdbarch
,
625 regcache_read_pc (regcache
));
627 ret
= gdbarch_process_record_signal (gdbarch
,
632 error (_("Process record: inferior program stopped."));
634 error (_("Process record: failed to record execution log."));
636 discard_cleanups (old_cleanups
);
638 record_list
->next
= record_arch_list_head
;
639 record_arch_list_head
->prev
= record_list
;
640 record_list
= record_arch_list_tail
;
642 if (record_insn_num
== record_insn_max_num
&& record_insn_max_num
)
643 record_list_release_first ();
650 struct record_message_args
{
651 struct regcache
*regcache
;
652 enum target_signal signal
;
656 record_message_wrapper (void *args
)
658 struct record_message_args
*record_args
= args
;
660 return record_message (record_args
->regcache
, record_args
->signal
);
664 record_message_wrapper_safe (struct regcache
*regcache
,
665 enum target_signal signal
)
667 struct record_message_args args
;
669 args
.regcache
= regcache
;
670 args
.signal
= signal
;
672 return catch_errors (record_message_wrapper
, &args
, NULL
, RETURN_MASK_ALL
);
675 /* Set to 1 if record_store_registers and record_xfer_partial
676 doesn't need record. */
678 static int record_gdb_operation_disable
= 0;
681 record_gdb_operation_disable_set (void)
683 struct cleanup
*old_cleanups
= NULL
;
686 make_cleanup_restore_integer (&record_gdb_operation_disable
);
687 record_gdb_operation_disable
= 1;
692 /* Flag set to TRUE for target_stopped_by_watchpoint. */
693 static int record_hw_watchpoint
= 0;
695 /* Execute one instruction from the record log. Each instruction in
696 the log will be represented by an arbitrary sequence of register
697 entries and memory entries, followed by an 'end' entry. */
700 record_exec_insn (struct regcache
*regcache
, struct gdbarch
*gdbarch
,
701 struct record_entry
*entry
)
705 case record_reg
: /* reg */
707 gdb_byte reg
[MAX_REGISTER_SIZE
];
709 if (record_debug
> 1)
710 fprintf_unfiltered (gdb_stdlog
,
711 "Process record: record_reg %s to "
712 "inferior num = %d.\n",
713 host_address_to_string (entry
),
716 regcache_cooked_read (regcache
, entry
->u
.reg
.num
, reg
);
717 regcache_cooked_write (regcache
, entry
->u
.reg
.num
,
718 record_get_loc (entry
));
719 memcpy (record_get_loc (entry
), reg
, entry
->u
.reg
.len
);
723 case record_mem
: /* mem */
725 /* Nothing to do if the entry is flagged not_accessible. */
726 if (!entry
->u
.mem
.mem_entry_not_accessible
)
728 gdb_byte
*mem
= alloca (entry
->u
.mem
.len
);
730 if (record_debug
> 1)
731 fprintf_unfiltered (gdb_stdlog
,
732 "Process record: record_mem %s to "
733 "inferior addr = %s len = %d.\n",
734 host_address_to_string (entry
),
735 paddress (gdbarch
, entry
->u
.mem
.addr
),
738 if (target_read_memory (entry
->u
.mem
.addr
, mem
, entry
->u
.mem
.len
))
740 entry
->u
.mem
.mem_entry_not_accessible
= 1;
742 warning ("Process record: error reading memory at "
743 "addr = %s len = %d.",
744 paddress (gdbarch
, entry
->u
.mem
.addr
),
749 if (target_write_memory (entry
->u
.mem
.addr
,
750 record_get_loc (entry
),
753 entry
->u
.mem
.mem_entry_not_accessible
= 1;
755 warning ("Process record: error writing memory at "
756 "addr = %s len = %d.",
757 paddress (gdbarch
, entry
->u
.mem
.addr
),
762 memcpy (record_get_loc (entry
), mem
, entry
->u
.mem
.len
);
764 /* We've changed memory --- check if a hardware
765 watchpoint should trap. Note that this
766 presently assumes the target beneath supports
767 continuable watchpoints. On non-continuable
768 watchpoints target, we'll want to check this
769 _before_ actually doing the memory change, and
770 not doing the change at all if the watchpoint
772 if (hardware_watchpoint_inserted_in_range
773 (get_regcache_aspace (regcache
),
774 entry
->u
.mem
.addr
, entry
->u
.mem
.len
))
775 record_hw_watchpoint
= 1;
784 static struct target_ops
*tmp_to_resume_ops
;
785 static void (*tmp_to_resume
) (struct target_ops
*, ptid_t
, int,
787 static struct target_ops
*tmp_to_wait_ops
;
788 static ptid_t (*tmp_to_wait
) (struct target_ops
*, ptid_t
,
789 struct target_waitstatus
*,
791 static struct target_ops
*tmp_to_store_registers_ops
;
792 static void (*tmp_to_store_registers
) (struct target_ops
*,
795 static struct target_ops
*tmp_to_xfer_partial_ops
;
796 static LONGEST (*tmp_to_xfer_partial
) (struct target_ops
*ops
,
797 enum target_object object
,
800 const gdb_byte
*writebuf
,
803 static int (*tmp_to_insert_breakpoint
) (struct gdbarch
*,
804 struct bp_target_info
*);
805 static int (*tmp_to_remove_breakpoint
) (struct gdbarch
*,
806 struct bp_target_info
*);
807 static int (*tmp_to_stopped_by_watchpoint
) (void);
808 static int (*tmp_to_stopped_data_address
) (struct target_ops
*, CORE_ADDR
*);
810 static void record_restore (void);
812 /* Open the process record target. */
815 record_core_open_1 (char *name
, int from_tty
)
817 struct regcache
*regcache
= get_current_regcache ();
818 int regnum
= gdbarch_num_regs (get_regcache_arch (regcache
));
821 /* Get record_core_regbuf. */
822 target_fetch_registers (regcache
, -1);
823 record_core_regbuf
= xmalloc (MAX_REGISTER_SIZE
* regnum
);
824 for (i
= 0; i
< regnum
; i
++)
825 regcache_raw_collect (regcache
, i
,
826 record_core_regbuf
+ MAX_REGISTER_SIZE
* i
);
828 /* Get record_core_start and record_core_end. */
829 if (build_section_table (core_bfd
, &record_core_start
, &record_core_end
))
831 xfree (record_core_regbuf
);
832 record_core_regbuf
= NULL
;
833 error (_("\"%s\": Can't find sections: %s"),
834 bfd_get_filename (core_bfd
), bfd_errmsg (bfd_get_error ()));
837 push_target (&record_core_ops
);
841 /* "to_open" target method for 'live' processes. */
844 record_open_1 (char *name
, int from_tty
)
847 fprintf_unfiltered (gdb_stdlog
, "Process record: record_open\n");
850 if (!target_has_execution
)
851 error (_("Process record: the program is not being run."));
853 error (_("Process record target can't debug inferior in non-stop mode "
855 if (target_async_permitted
)
856 error (_("Process record target can't debug inferior in asynchronous "
857 "mode (target-async)."));
859 if (!gdbarch_process_record_p (target_gdbarch
))
860 error (_("Process record: the current architecture doesn't support "
861 "record function."));
864 error (_("Could not find 'to_resume' method on the target stack."));
866 error (_("Could not find 'to_wait' method on the target stack."));
867 if (!tmp_to_store_registers
)
868 error (_("Could not find 'to_store_registers' method on the target stack."));
869 if (!tmp_to_insert_breakpoint
)
870 error (_("Could not find 'to_insert_breakpoint' method on the target stack."));
871 if (!tmp_to_remove_breakpoint
)
872 error (_("Could not find 'to_remove_breakpoint' method on the target stack."));
873 if (!tmp_to_stopped_by_watchpoint
)
874 error (_("Could not find 'to_stopped_by_watchpoint' method on the target stack."));
875 if (!tmp_to_stopped_data_address
)
876 error (_("Could not find 'to_stopped_data_address' method on the target stack."));
878 push_target (&record_ops
);
881 /* "to_open" target method. Open the process record target. */
884 record_open (char *name
, int from_tty
)
886 struct target_ops
*t
;
889 fprintf_unfiltered (gdb_stdlog
, "Process record: record_open\n");
891 /* Check if record target is already running. */
892 if (current_target
.to_stratum
== record_stratum
)
893 error (_("Process record target already running. Use \"record stop\" to "
894 "stop record target first."));
896 /* Reset the tmp beneath pointers. */
897 tmp_to_resume_ops
= NULL
;
898 tmp_to_resume
= NULL
;
899 tmp_to_wait_ops
= NULL
;
901 tmp_to_store_registers_ops
= NULL
;
902 tmp_to_store_registers
= NULL
;
903 tmp_to_xfer_partial_ops
= NULL
;
904 tmp_to_xfer_partial
= NULL
;
905 tmp_to_insert_breakpoint
= NULL
;
906 tmp_to_remove_breakpoint
= NULL
;
907 tmp_to_stopped_by_watchpoint
= NULL
;
908 tmp_to_stopped_data_address
= NULL
;
910 /* Set the beneath function pointers. */
911 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
915 tmp_to_resume
= t
->to_resume
;
916 tmp_to_resume_ops
= t
;
920 tmp_to_wait
= t
->to_wait
;
923 if (!tmp_to_store_registers
)
925 tmp_to_store_registers
= t
->to_store_registers
;
926 tmp_to_store_registers_ops
= t
;
928 if (!tmp_to_xfer_partial
)
930 tmp_to_xfer_partial
= t
->to_xfer_partial
;
931 tmp_to_xfer_partial_ops
= t
;
933 if (!tmp_to_insert_breakpoint
)
934 tmp_to_insert_breakpoint
= t
->to_insert_breakpoint
;
935 if (!tmp_to_remove_breakpoint
)
936 tmp_to_remove_breakpoint
= t
->to_remove_breakpoint
;
937 if (!tmp_to_stopped_by_watchpoint
)
938 tmp_to_stopped_by_watchpoint
= t
->to_stopped_by_watchpoint
;
939 if (!tmp_to_stopped_data_address
)
940 tmp_to_stopped_data_address
= t
->to_stopped_data_address
;
942 if (!tmp_to_xfer_partial
)
943 error (_("Could not find 'to_xfer_partial' method on the target stack."));
947 record_insn_count
= 0;
948 record_list
= &record_first
;
949 record_list
->next
= NULL
;
951 /* Set the tmp beneath pointers to beneath pointers. */
952 record_beneath_to_resume_ops
= tmp_to_resume_ops
;
953 record_beneath_to_resume
= tmp_to_resume
;
954 record_beneath_to_wait_ops
= tmp_to_wait_ops
;
955 record_beneath_to_wait
= tmp_to_wait
;
956 record_beneath_to_store_registers_ops
= tmp_to_store_registers_ops
;
957 record_beneath_to_store_registers
= tmp_to_store_registers
;
958 record_beneath_to_xfer_partial_ops
= tmp_to_xfer_partial_ops
;
959 record_beneath_to_xfer_partial
= tmp_to_xfer_partial
;
960 record_beneath_to_insert_breakpoint
= tmp_to_insert_breakpoint
;
961 record_beneath_to_remove_breakpoint
= tmp_to_remove_breakpoint
;
962 record_beneath_to_stopped_by_watchpoint
= tmp_to_stopped_by_watchpoint
;
963 record_beneath_to_stopped_data_address
= tmp_to_stopped_data_address
;
966 record_core_open_1 (name
, from_tty
);
968 record_open_1 (name
, from_tty
);
971 /* "to_close" target method. Close the process record target. */
974 record_close (int quitting
)
976 struct record_core_buf_entry
*entry
;
979 fprintf_unfiltered (gdb_stdlog
, "Process record: record_close\n");
981 record_list_release (record_list
);
983 /* Release record_core_regbuf. */
984 if (record_core_regbuf
)
986 xfree (record_core_regbuf
);
987 record_core_regbuf
= NULL
;
990 /* Release record_core_buf_list. */
991 if (record_core_buf_list
)
993 for (entry
= record_core_buf_list
->prev
; entry
; entry
= entry
->prev
)
995 xfree (record_core_buf_list
);
996 record_core_buf_list
= entry
;
998 record_core_buf_list
= NULL
;
1002 static int record_resume_step
= 0;
1004 /* "to_resume" target method. Resume the process record target. */
1007 record_resume (struct target_ops
*ops
, ptid_t ptid
, int step
,
1008 enum target_signal signal
)
1010 record_resume_step
= step
;
1012 if (!RECORD_IS_REPLAY
)
1014 struct gdbarch
*gdbarch
= target_thread_architecture (ptid
);
1016 record_message (get_current_regcache (), signal
);
1020 /* This is not hard single step. */
1021 if (!gdbarch_software_single_step_p (gdbarch
))
1023 /* This is a normal continue. */
1028 /* This arch support soft sigle step. */
1029 if (single_step_breakpoints_inserted ())
1031 /* This is a soft single step. */
1032 record_resume_step
= 1;
1036 /* This is a continue.
1037 Try to insert a soft single step breakpoint. */
1038 if (!gdbarch_software_single_step (gdbarch
,
1039 get_current_frame ()))
1041 /* This system don't want use soft single step.
1042 Use hard sigle step. */
1049 record_beneath_to_resume (record_beneath_to_resume_ops
,
1050 ptid
, step
, signal
);
1054 static int record_get_sig
= 0;
1056 /* SIGINT signal handler, registered by "to_wait" method. */
1059 record_sig_handler (int signo
)
1062 fprintf_unfiltered (gdb_stdlog
, "Process record: get a signal\n");
1064 /* It will break the running inferior in replay mode. */
1065 record_resume_step
= 1;
1067 /* It will let record_wait set inferior status to get the signal
1073 record_wait_cleanups (void *ignore
)
1075 if (execution_direction
== EXEC_REVERSE
)
1077 if (record_list
->next
)
1078 record_list
= record_list
->next
;
1081 record_list
= record_list
->prev
;
1084 /* "to_wait" target method for process record target.
1086 In record mode, the target is always run in singlestep mode
1087 (even when gdb says to continue). The to_wait method intercepts
1088 the stop events and determines which ones are to be passed on to
1089 gdb. Most stop events are just singlestep events that gdb is not
1090 to know about, so the to_wait method just records them and keeps
1093 In replay mode, this function emulates the recorded execution log,
1094 one instruction at a time (forward or backward), and determines
1098 record_wait (struct target_ops
*ops
,
1099 ptid_t ptid
, struct target_waitstatus
*status
,
1102 struct cleanup
*set_cleanups
= record_gdb_operation_disable_set ();
1105 fprintf_unfiltered (gdb_stdlog
,
1106 "Process record: record_wait "
1107 "record_resume_step = %d\n",
1108 record_resume_step
);
1111 signal (SIGINT
, record_sig_handler
);
1113 if (!RECORD_IS_REPLAY
&& ops
!= &record_core_ops
)
1115 if (record_resume_step
)
1117 /* This is a single step. */
1118 return record_beneath_to_wait (record_beneath_to_wait_ops
,
1119 ptid
, status
, options
);
1123 /* This is not a single step. */
1126 struct gdbarch
*gdbarch
= target_thread_architecture (inferior_ptid
);
1130 ret
= record_beneath_to_wait (record_beneath_to_wait_ops
,
1131 ptid
, status
, options
);
1133 if (single_step_breakpoints_inserted ())
1134 remove_single_step_breakpoints ();
1136 if (record_resume_step
)
1139 /* Is this a SIGTRAP? */
1140 if (status
->kind
== TARGET_WAITKIND_STOPPED
1141 && status
->value
.sig
== TARGET_SIGNAL_TRAP
)
1143 struct regcache
*regcache
;
1144 struct address_space
*aspace
;
1146 /* Yes -- this is likely our single-step finishing,
1147 but check if there's any reason the core would be
1148 interested in the event. */
1150 registers_changed ();
1151 regcache
= get_current_regcache ();
1152 tmp_pc
= regcache_read_pc (regcache
);
1153 aspace
= get_regcache_aspace (regcache
);
1155 if (target_stopped_by_watchpoint ())
1157 /* Always interested in watchpoints. */
1159 else if (breakpoint_inserted_here_p (aspace
, tmp_pc
))
1161 /* There is a breakpoint here. Let the core
1163 if (software_breakpoint_inserted_here_p (aspace
, tmp_pc
))
1165 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1166 CORE_ADDR decr_pc_after_break
1167 = gdbarch_decr_pc_after_break (gdbarch
);
1168 if (decr_pc_after_break
)
1169 regcache_write_pc (regcache
,
1170 tmp_pc
+ decr_pc_after_break
);
1175 /* This is a single-step trap. Record the
1176 insn and issue another step.
1177 FIXME: this part can be a random SIGTRAP too.
1178 But GDB cannot handle it. */
1181 if (!record_message_wrapper_safe (regcache
,
1184 status
->kind
= TARGET_WAITKIND_STOPPED
;
1185 status
->value
.sig
= TARGET_SIGNAL_0
;
1189 if (gdbarch_software_single_step_p (gdbarch
))
1191 /* Try to insert the software single step breakpoint.
1192 If insert success, set step to 0. */
1193 set_executing (inferior_ptid
, 0);
1194 reinit_frame_cache ();
1195 if (gdbarch_software_single_step (gdbarch
,
1196 get_current_frame ()))
1198 set_executing (inferior_ptid
, 1);
1201 record_beneath_to_resume (record_beneath_to_resume_ops
,
1208 /* The inferior is broken by a breakpoint or a signal. */
1217 struct regcache
*regcache
= get_current_regcache ();
1218 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1219 struct address_space
*aspace
= get_regcache_aspace (regcache
);
1220 int continue_flag
= 1;
1221 int first_record_end
= 1;
1222 struct cleanup
*old_cleanups
= make_cleanup (record_wait_cleanups
, 0);
1225 record_hw_watchpoint
= 0;
1226 status
->kind
= TARGET_WAITKIND_STOPPED
;
1228 /* Check breakpoint when forward execute. */
1229 if (execution_direction
== EXEC_FORWARD
)
1231 tmp_pc
= regcache_read_pc (regcache
);
1232 if (breakpoint_inserted_here_p (aspace
, tmp_pc
))
1234 int decr_pc_after_break
= gdbarch_decr_pc_after_break (gdbarch
);
1237 fprintf_unfiltered (gdb_stdlog
,
1238 "Process record: break at %s.\n",
1239 paddress (gdbarch
, tmp_pc
));
1241 if (decr_pc_after_break
1242 && !record_resume_step
1243 && software_breakpoint_inserted_here_p (aspace
, tmp_pc
))
1244 regcache_write_pc (regcache
,
1245 tmp_pc
+ decr_pc_after_break
);
1250 /* If GDB is in terminal_inferior mode, it will not get the signal.
1251 And in GDB replay mode, GDB doesn't need to be in terminal_inferior
1252 mode, because inferior will not executed.
1253 Then set it to terminal_ours to make GDB get the signal. */
1254 target_terminal_ours ();
1256 /* In EXEC_FORWARD mode, record_list points to the tail of prev
1258 if (execution_direction
== EXEC_FORWARD
&& record_list
->next
)
1259 record_list
= record_list
->next
;
1261 /* Loop over the record_list, looking for the next place to
1265 /* Check for beginning and end of log. */
1266 if (execution_direction
== EXEC_REVERSE
1267 && record_list
== &record_first
)
1269 /* Hit beginning of record log in reverse. */
1270 status
->kind
= TARGET_WAITKIND_NO_HISTORY
;
1273 if (execution_direction
!= EXEC_REVERSE
&& !record_list
->next
)
1275 /* Hit end of record log going forward. */
1276 status
->kind
= TARGET_WAITKIND_NO_HISTORY
;
1280 record_exec_insn (regcache
, gdbarch
, record_list
);
1282 if (record_list
->type
== record_end
)
1284 if (record_debug
> 1)
1285 fprintf_unfiltered (gdb_stdlog
,
1286 "Process record: record_end %s to "
1288 host_address_to_string (record_list
));
1290 if (first_record_end
&& execution_direction
== EXEC_REVERSE
)
1292 /* When reverse excute, the first record_end is the part of
1293 current instruction. */
1294 first_record_end
= 0;
1298 /* In EXEC_REVERSE mode, this is the record_end of prev
1300 In EXEC_FORWARD mode, this is the record_end of current
1303 if (record_resume_step
)
1305 if (record_debug
> 1)
1306 fprintf_unfiltered (gdb_stdlog
,
1307 "Process record: step.\n");
1311 /* check breakpoint */
1312 tmp_pc
= regcache_read_pc (regcache
);
1313 if (breakpoint_inserted_here_p (aspace
, tmp_pc
))
1315 int decr_pc_after_break
1316 = gdbarch_decr_pc_after_break (gdbarch
);
1319 fprintf_unfiltered (gdb_stdlog
,
1320 "Process record: break "
1322 paddress (gdbarch
, tmp_pc
));
1323 if (decr_pc_after_break
1324 && execution_direction
== EXEC_FORWARD
1325 && !record_resume_step
1326 && software_breakpoint_inserted_here_p (aspace
,
1328 regcache_write_pc (regcache
,
1329 tmp_pc
+ decr_pc_after_break
);
1333 if (record_hw_watchpoint
)
1336 fprintf_unfiltered (gdb_stdlog
, "\
1337 Process record: hit hw watchpoint.\n");
1340 /* Check target signal */
1341 if (record_list
->u
.end
.sigval
!= TARGET_SIGNAL_0
)
1342 /* FIXME: better way to check */
1349 if (execution_direction
== EXEC_REVERSE
)
1351 if (record_list
->prev
)
1352 record_list
= record_list
->prev
;
1356 if (record_list
->next
)
1357 record_list
= record_list
->next
;
1361 while (continue_flag
);
1365 status
->value
.sig
= TARGET_SIGNAL_INT
;
1366 else if (record_list
->u
.end
.sigval
!= TARGET_SIGNAL_0
)
1367 /* FIXME: better way to check */
1368 status
->value
.sig
= record_list
->u
.end
.sigval
;
1370 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
1372 discard_cleanups (old_cleanups
);
1375 signal (SIGINT
, handle_sigint
);
1377 do_cleanups (set_cleanups
);
1378 return inferior_ptid
;
1382 record_stopped_by_watchpoint (void)
1384 if (RECORD_IS_REPLAY
)
1385 return record_hw_watchpoint
;
1387 return record_beneath_to_stopped_by_watchpoint ();
1391 record_stopped_data_address (struct target_ops
*ops
, CORE_ADDR
*addr_p
)
1393 if (RECORD_IS_REPLAY
)
1396 return record_beneath_to_stopped_data_address (ops
, addr_p
);
1399 /* "to_disconnect" method for process record target. */
1402 record_disconnect (struct target_ops
*target
, char *args
, int from_tty
)
1405 fprintf_unfiltered (gdb_stdlog
, "Process record: record_disconnect\n");
1407 unpush_target (&record_ops
);
1408 target_disconnect (args
, from_tty
);
1411 /* "to_detach" method for process record target. */
1414 record_detach (struct target_ops
*ops
, char *args
, int from_tty
)
1417 fprintf_unfiltered (gdb_stdlog
, "Process record: record_detach\n");
1419 unpush_target (&record_ops
);
1420 target_detach (args
, from_tty
);
1423 /* "to_mourn_inferior" method for process record target. */
1426 record_mourn_inferior (struct target_ops
*ops
)
1429 fprintf_unfiltered (gdb_stdlog
, "Process record: "
1430 "record_mourn_inferior\n");
1432 unpush_target (&record_ops
);
1433 target_mourn_inferior ();
1436 /* Close process record target before killing the inferior process. */
1439 record_kill (struct target_ops
*ops
)
1442 fprintf_unfiltered (gdb_stdlog
, "Process record: record_kill\n");
1444 unpush_target (&record_ops
);
1448 /* Record registers change (by user or by GDB) to list as an instruction. */
1451 record_registers_change (struct regcache
*regcache
, int regnum
)
1453 /* Check record_insn_num. */
1454 record_check_insn_num (0);
1456 record_arch_list_head
= NULL
;
1457 record_arch_list_tail
= NULL
;
1463 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
1465 if (record_arch_list_add_reg (regcache
, i
))
1467 record_list_release (record_arch_list_tail
);
1468 error (_("Process record: failed to record execution log."));
1474 if (record_arch_list_add_reg (regcache
, regnum
))
1476 record_list_release (record_arch_list_tail
);
1477 error (_("Process record: failed to record execution log."));
1480 if (record_arch_list_add_end ())
1482 record_list_release (record_arch_list_tail
);
1483 error (_("Process record: failed to record execution log."));
1485 record_list
->next
= record_arch_list_head
;
1486 record_arch_list_head
->prev
= record_list
;
1487 record_list
= record_arch_list_tail
;
1489 if (record_insn_num
== record_insn_max_num
&& record_insn_max_num
)
1490 record_list_release_first ();
1495 /* "to_store_registers" method for process record target. */
1498 record_store_registers (struct target_ops
*ops
, struct regcache
*regcache
,
1501 if (!record_gdb_operation_disable
)
1503 if (RECORD_IS_REPLAY
)
1507 /* Let user choose if he wants to write register or not. */
1510 query (_("Because GDB is in replay mode, changing the "
1511 "value of a register will make the execution "
1512 "log unusable from this point onward. "
1513 "Change all registers?"));
1516 query (_("Because GDB is in replay mode, changing the value "
1517 "of a register will make the execution log unusable "
1518 "from this point onward. Change register %s?"),
1519 gdbarch_register_name (get_regcache_arch (regcache
),
1524 /* Invalidate the value of regcache that was set in function
1525 "regcache_raw_write". */
1531 i
< gdbarch_num_regs (get_regcache_arch (regcache
));
1533 regcache_invalidate (regcache
, i
);
1536 regcache_invalidate (regcache
, regno
);
1538 error (_("Process record canceled the operation."));
1541 /* Destroy the record from here forward. */
1542 record_list_release_following (record_list
);
1545 record_registers_change (regcache
, regno
);
1547 record_beneath_to_store_registers (record_beneath_to_store_registers_ops
,
1551 /* "to_xfer_partial" method. Behavior is conditional on RECORD_IS_REPLAY.
1552 In replay mode, we cannot write memory unles we are willing to
1553 invalidate the record/replay log from this point forward. */
1556 record_xfer_partial (struct target_ops
*ops
, enum target_object object
,
1557 const char *annex
, gdb_byte
*readbuf
,
1558 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
1560 if (!record_gdb_operation_disable
1561 && (object
== TARGET_OBJECT_MEMORY
1562 || object
== TARGET_OBJECT_RAW_MEMORY
) && writebuf
)
1564 if (RECORD_IS_REPLAY
)
1566 /* Let user choose if he wants to write memory or not. */
1567 if (!query (_("Because GDB is in replay mode, writing to memory "
1568 "will make the execution log unusable from this "
1569 "point onward. Write memory at address %s?"),
1570 paddress (target_gdbarch
, offset
)))
1571 error (_("Process record canceled the operation."));
1573 /* Destroy the record from here forward. */
1574 record_list_release_following (record_list
);
1577 /* Check record_insn_num */
1578 record_check_insn_num (0);
1580 /* Record registers change to list as an instruction. */
1581 record_arch_list_head
= NULL
;
1582 record_arch_list_tail
= NULL
;
1583 if (record_arch_list_add_mem (offset
, len
))
1585 record_list_release (record_arch_list_tail
);
1587 fprintf_unfiltered (gdb_stdlog
,
1588 "Process record: failed to record "
1592 if (record_arch_list_add_end ())
1594 record_list_release (record_arch_list_tail
);
1596 fprintf_unfiltered (gdb_stdlog
,
1597 "Process record: failed to record "
1601 record_list
->next
= record_arch_list_head
;
1602 record_arch_list_head
->prev
= record_list
;
1603 record_list
= record_arch_list_tail
;
1605 if (record_insn_num
== record_insn_max_num
&& record_insn_max_num
)
1606 record_list_release_first ();
1611 return record_beneath_to_xfer_partial (record_beneath_to_xfer_partial_ops
,
1612 object
, annex
, readbuf
, writebuf
,
1616 /* Behavior is conditional on RECORD_IS_REPLAY.
1617 We will not actually insert or remove breakpoints when replaying,
1618 nor when recording. */
1621 record_insert_breakpoint (struct gdbarch
*gdbarch
,
1622 struct bp_target_info
*bp_tgt
)
1624 if (!RECORD_IS_REPLAY
)
1626 struct cleanup
*old_cleanups
= record_gdb_operation_disable_set ();
1627 int ret
= record_beneath_to_insert_breakpoint (gdbarch
, bp_tgt
);
1629 do_cleanups (old_cleanups
);
1637 /* "to_remove_breakpoint" method for process record target. */
1640 record_remove_breakpoint (struct gdbarch
*gdbarch
,
1641 struct bp_target_info
*bp_tgt
)
1643 if (!RECORD_IS_REPLAY
)
1645 struct cleanup
*old_cleanups
= record_gdb_operation_disable_set ();
1646 int ret
= record_beneath_to_remove_breakpoint (gdbarch
, bp_tgt
);
1648 do_cleanups (old_cleanups
);
1656 /* "to_can_execute_reverse" method for process record target. */
1659 record_can_execute_reverse (void)
1664 /* "to_get_bookmark" method for process record and prec over core. */
1667 record_get_bookmark (char *args
, int from_tty
)
1669 gdb_byte
*ret
= NULL
;
1671 /* Return stringified form of instruction count. */
1672 if (record_list
&& record_list
->type
== record_end
)
1673 ret
= xstrdup (pulongest (record_list
->u
.end
.insn_num
));
1678 fprintf_unfiltered (gdb_stdlog
,
1679 "record_get_bookmark returns %s\n", ret
);
1681 fprintf_unfiltered (gdb_stdlog
,
1682 "record_get_bookmark returns NULL\n");
1687 /* The implementation of the command "record goto". */
1688 static void cmd_record_goto (char *, int);
1690 /* "to_goto_bookmark" method for process record and prec over core. */
1693 record_goto_bookmark (gdb_byte
*bookmark
, int from_tty
)
1696 fprintf_unfiltered (gdb_stdlog
,
1697 "record_goto_bookmark receives %s\n", bookmark
);
1699 if (bookmark
[0] == '\'' || bookmark
[0] == '\"')
1701 if (bookmark
[strlen (bookmark
) - 1] != bookmark
[0])
1702 error (_("Unbalanced quotes: %s"), bookmark
);
1704 /* Strip trailing quote. */
1705 bookmark
[strlen (bookmark
) - 1] = '\0';
1706 /* Strip leading quote. */
1708 /* Pass along to cmd_record_goto. */
1711 cmd_record_goto ((char *) bookmark
, from_tty
);
1716 init_record_ops (void)
1718 record_ops
.to_shortname
= "record";
1719 record_ops
.to_longname
= "Process record and replay target";
1721 "Log program while executing and replay execution from log.";
1722 record_ops
.to_open
= record_open
;
1723 record_ops
.to_close
= record_close
;
1724 record_ops
.to_resume
= record_resume
;
1725 record_ops
.to_wait
= record_wait
;
1726 record_ops
.to_disconnect
= record_disconnect
;
1727 record_ops
.to_detach
= record_detach
;
1728 record_ops
.to_mourn_inferior
= record_mourn_inferior
;
1729 record_ops
.to_kill
= record_kill
;
1730 record_ops
.to_create_inferior
= find_default_create_inferior
;
1731 record_ops
.to_store_registers
= record_store_registers
;
1732 record_ops
.to_xfer_partial
= record_xfer_partial
;
1733 record_ops
.to_insert_breakpoint
= record_insert_breakpoint
;
1734 record_ops
.to_remove_breakpoint
= record_remove_breakpoint
;
1735 record_ops
.to_stopped_by_watchpoint
= record_stopped_by_watchpoint
;
1736 record_ops
.to_stopped_data_address
= record_stopped_data_address
;
1737 record_ops
.to_can_execute_reverse
= record_can_execute_reverse
;
1738 record_ops
.to_stratum
= record_stratum
;
1739 /* Add bookmark target methods. */
1740 record_ops
.to_get_bookmark
= record_get_bookmark
;
1741 record_ops
.to_goto_bookmark
= record_goto_bookmark
;
1742 record_ops
.to_magic
= OPS_MAGIC
;
1745 /* "to_resume" method for prec over corefile. */
1748 record_core_resume (struct target_ops
*ops
, ptid_t ptid
, int step
,
1749 enum target_signal signal
)
1751 record_resume_step
= step
;
1754 /* "to_kill" method for prec over corefile. */
1757 record_core_kill (struct target_ops
*ops
)
1760 fprintf_unfiltered (gdb_stdlog
, "Process record: record_core_kill\n");
1762 unpush_target (&record_core_ops
);
1765 /* "to_fetch_registers" method for prec over corefile. */
1768 record_core_fetch_registers (struct target_ops
*ops
,
1769 struct regcache
*regcache
,
1774 int num
= gdbarch_num_regs (get_regcache_arch (regcache
));
1777 for (i
= 0; i
< num
; i
++)
1778 regcache_raw_supply (regcache
, i
,
1779 record_core_regbuf
+ MAX_REGISTER_SIZE
* i
);
1782 regcache_raw_supply (regcache
, regno
,
1783 record_core_regbuf
+ MAX_REGISTER_SIZE
* regno
);
1786 /* "to_prepare_to_store" method for prec over corefile. */
1789 record_core_prepare_to_store (struct regcache
*regcache
)
1793 /* "to_store_registers" method for prec over corefile. */
1796 record_core_store_registers (struct target_ops
*ops
,
1797 struct regcache
*regcache
,
1800 if (record_gdb_operation_disable
)
1801 regcache_raw_collect (regcache
, regno
,
1802 record_core_regbuf
+ MAX_REGISTER_SIZE
* regno
);
1804 error (_("You can't do that without a process to debug."));
1807 /* "to_xfer_partial" method for prec over corefile. */
1810 record_core_xfer_partial (struct target_ops
*ops
, enum target_object object
,
1811 const char *annex
, gdb_byte
*readbuf
,
1812 const gdb_byte
*writebuf
, ULONGEST offset
,
1815 if (object
== TARGET_OBJECT_MEMORY
)
1817 if (record_gdb_operation_disable
|| !writebuf
)
1819 struct target_section
*p
;
1821 for (p
= record_core_start
; p
< record_core_end
; p
++)
1823 if (offset
>= p
->addr
)
1825 struct record_core_buf_entry
*entry
;
1826 ULONGEST sec_offset
;
1828 if (offset
>= p
->endaddr
)
1831 if (offset
+ len
> p
->endaddr
)
1832 len
= p
->endaddr
- offset
;
1834 sec_offset
= offset
- p
->addr
;
1836 /* Read readbuf or write writebuf p, offset, len. */
1838 if (p
->the_bfd_section
->flags
& SEC_CONSTRUCTOR
1839 || (p
->the_bfd_section
->flags
& SEC_HAS_CONTENTS
) == 0)
1842 memset (readbuf
, 0, len
);
1845 /* Get record_core_buf_entry. */
1846 for (entry
= record_core_buf_list
; entry
;
1847 entry
= entry
->prev
)
1854 /* Add a new entry. */
1855 entry
= (struct record_core_buf_entry
*)
1856 xmalloc (sizeof (struct record_core_buf_entry
));
1858 if (!bfd_malloc_and_get_section (p
->bfd
,
1865 entry
->prev
= record_core_buf_list
;
1866 record_core_buf_list
= entry
;
1869 memcpy (entry
->buf
+ sec_offset
, writebuf
,
1875 return record_beneath_to_xfer_partial
1876 (record_beneath_to_xfer_partial_ops
,
1877 object
, annex
, readbuf
, writebuf
,
1880 memcpy (readbuf
, entry
->buf
+ sec_offset
,
1891 error (_("You can't do that without a process to debug."));
1894 return record_beneath_to_xfer_partial (record_beneath_to_xfer_partial_ops
,
1895 object
, annex
, readbuf
, writebuf
,
1899 /* "to_insert_breakpoint" method for prec over corefile. */
1902 record_core_insert_breakpoint (struct gdbarch
*gdbarch
,
1903 struct bp_target_info
*bp_tgt
)
1908 /* "to_remove_breakpoint" method for prec over corefile. */
1911 record_core_remove_breakpoint (struct gdbarch
*gdbarch
,
1912 struct bp_target_info
*bp_tgt
)
1917 /* "to_has_execution" method for prec over corefile. */
1920 record_core_has_execution (struct target_ops
*ops
)
1926 init_record_core_ops (void)
1928 record_core_ops
.to_shortname
= "record-core";
1929 record_core_ops
.to_longname
= "Process record and replay target";
1930 record_core_ops
.to_doc
=
1931 "Log program while executing and replay execution from log.";
1932 record_core_ops
.to_open
= record_open
;
1933 record_core_ops
.to_close
= record_close
;
1934 record_core_ops
.to_resume
= record_core_resume
;
1935 record_core_ops
.to_wait
= record_wait
;
1936 record_core_ops
.to_kill
= record_core_kill
;
1937 record_core_ops
.to_fetch_registers
= record_core_fetch_registers
;
1938 record_core_ops
.to_prepare_to_store
= record_core_prepare_to_store
;
1939 record_core_ops
.to_store_registers
= record_core_store_registers
;
1940 record_core_ops
.to_xfer_partial
= record_core_xfer_partial
;
1941 record_core_ops
.to_insert_breakpoint
= record_core_insert_breakpoint
;
1942 record_core_ops
.to_remove_breakpoint
= record_core_remove_breakpoint
;
1943 record_core_ops
.to_stopped_by_watchpoint
= record_stopped_by_watchpoint
;
1944 record_core_ops
.to_stopped_data_address
= record_stopped_data_address
;
1945 record_core_ops
.to_can_execute_reverse
= record_can_execute_reverse
;
1946 record_core_ops
.to_has_execution
= record_core_has_execution
;
1947 record_core_ops
.to_stratum
= record_stratum
;
1948 /* Add bookmark target methods. */
1949 record_core_ops
.to_get_bookmark
= record_get_bookmark
;
1950 record_core_ops
.to_goto_bookmark
= record_goto_bookmark
;
1951 record_core_ops
.to_magic
= OPS_MAGIC
;
1954 /* Implement "show record debug" command. */
1957 show_record_debug (struct ui_file
*file
, int from_tty
,
1958 struct cmd_list_element
*c
, const char *value
)
1960 fprintf_filtered (file
, _("Debugging of process record target is %s.\n"),
1964 /* Alias for "target record". */
1967 cmd_record_start (char *args
, int from_tty
)
1969 execute_command ("target record", from_tty
);
1972 /* Truncate the record log from the present point
1973 of replay until the end. */
1976 cmd_record_delete (char *args
, int from_tty
)
1978 if (current_target
.to_stratum
== record_stratum
)
1980 if (RECORD_IS_REPLAY
)
1982 if (!from_tty
|| query (_("Delete the log from this point forward "
1983 "and begin to record the running message "
1985 record_list_release_following (record_list
);
1988 printf_unfiltered (_("Already at end of record list.\n"));
1992 printf_unfiltered (_("Process record is not started.\n"));
1995 /* Implement the "stoprecord" or "record stop" command. */
1998 cmd_record_stop (char *args
, int from_tty
)
2000 if (current_target
.to_stratum
== record_stratum
)
2002 unpush_target (&record_ops
);
2003 printf_unfiltered (_("Process record is stopped and all execution "
2004 "logs are deleted.\n"));
2007 printf_unfiltered (_("Process record is not started.\n"));
2010 /* Set upper limit of record log size. */
2013 set_record_insn_max_num (char *args
, int from_tty
, struct cmd_list_element
*c
)
2015 if (record_insn_num
> record_insn_max_num
&& record_insn_max_num
)
2017 /* Count down record_insn_num while releasing records from list. */
2018 while (record_insn_num
> record_insn_max_num
)
2020 record_list_release_first ();
2026 static struct cmd_list_element
*record_cmdlist
, *set_record_cmdlist
,
2027 *show_record_cmdlist
, *info_record_cmdlist
;
2030 set_record_command (char *args
, int from_tty
)
2032 printf_unfiltered (_("\
2033 \"set record\" must be followed by an apporpriate subcommand.\n"));
2034 help_list (set_record_cmdlist
, "set record ", all_commands
, gdb_stdout
);
2038 show_record_command (char *args
, int from_tty
)
2040 cmd_show_list (show_record_cmdlist
, from_tty
, "");
2043 /* Display some statistics about the execution log. */
2046 info_record_command (char *args
, int from_tty
)
2048 struct record_entry
*p
;
2050 if (current_target
.to_stratum
== record_stratum
)
2052 if (RECORD_IS_REPLAY
)
2053 printf_filtered (_("Replay mode:\n"));
2055 printf_filtered (_("Record mode:\n"));
2057 /* Find entry for first actual instruction in the log. */
2058 for (p
= record_first
.next
;
2059 p
!= NULL
&& p
->type
!= record_end
;
2063 /* Do we have a log at all? */
2064 if (p
!= NULL
&& p
->type
== record_end
)
2066 /* Display instruction number for first instruction in the log. */
2067 printf_filtered (_("Lowest recorded instruction number is %s.\n"),
2068 pulongest (p
->u
.end
.insn_num
));
2070 /* If in replay mode, display where we are in the log. */
2071 if (RECORD_IS_REPLAY
)
2072 printf_filtered (_("Current instruction number is %s.\n"),
2073 pulongest (record_list
->u
.end
.insn_num
));
2075 /* Display instruction number for last instruction in the log. */
2076 printf_filtered (_("Highest recorded instruction number is %s.\n"),
2077 pulongest (record_insn_count
));
2079 /* Display log count. */
2080 printf_filtered (_("Log contains %d instructions.\n"),
2085 printf_filtered (_("No instructions have been logged.\n"));
2090 printf_filtered (_("target record is not active.\n"));
2093 /* Display max log size. */
2094 printf_filtered (_("Max logged instructions is %d.\n"),
2095 record_insn_max_num
);
2098 /* Record log save-file format
2099 Version 1 (never released)
2102 4 bytes: magic number htonl(0x20090829).
2103 NOTE: be sure to change whenever this file format changes!
2107 1 byte: record type (record_end, see enum record_type).
2109 1 byte: record type (record_reg, see enum record_type).
2110 8 bytes: register id (network byte order).
2111 MAX_REGISTER_SIZE bytes: register value.
2113 1 byte: record type (record_mem, see enum record_type).
2114 8 bytes: memory length (network byte order).
2115 8 bytes: memory address (network byte order).
2116 n bytes: memory value (n == memory length).
2119 4 bytes: magic number netorder32(0x20091016).
2120 NOTE: be sure to change whenever this file format changes!
2124 1 byte: record type (record_end, see enum record_type).
2126 4 bytes: instruction count
2128 1 byte: record type (record_reg, see enum record_type).
2129 4 bytes: register id (network byte order).
2130 n bytes: register value (n == actual register size).
2131 (eg. 4 bytes for x86 general registers).
2133 1 byte: record type (record_mem, see enum record_type).
2134 4 bytes: memory length (network byte order).
2135 8 bytes: memory address (network byte order).
2136 n bytes: memory value (n == memory length).
2140 /* bfdcore_read -- read bytes from a core file section. */
2143 bfdcore_read (bfd
*obfd
, asection
*osec
, void *buf
, int len
, int *offset
)
2145 int ret
= bfd_get_section_contents (obfd
, osec
, buf
, *offset
, len
);
2150 error (_("Failed to read %d bytes from core file %s ('%s').\n"),
2151 len
, bfd_get_filename (obfd
),
2152 bfd_errmsg (bfd_get_error ()));
2155 static inline uint64_t
2156 netorder64 (uint64_t input
)
2160 store_unsigned_integer ((gdb_byte
*) &ret
, sizeof (ret
),
2161 BFD_ENDIAN_BIG
, input
);
2165 static inline uint32_t
2166 netorder32 (uint32_t input
)
2170 store_unsigned_integer ((gdb_byte
*) &ret
, sizeof (ret
),
2171 BFD_ENDIAN_BIG
, input
);
2175 static inline uint16_t
2176 netorder16 (uint16_t input
)
2180 store_unsigned_integer ((gdb_byte
*) &ret
, sizeof (ret
),
2181 BFD_ENDIAN_BIG
, input
);
2185 /* Restore the execution log from a core_bfd file. */
2187 record_restore (void)
2190 struct cleanup
*old_cleanups
;
2191 struct record_entry
*rec
;
2195 struct regcache
*regcache
;
2197 /* We restore the execution log from the open core bfd,
2199 if (core_bfd
== NULL
)
2202 /* "record_restore" can only be called when record list is empty. */
2203 gdb_assert (record_first
.next
== NULL
);
2206 fprintf_unfiltered (gdb_stdlog
, "Restoring recording from core file.\n");
2208 /* Now need to find our special note section. */
2209 osec
= bfd_get_section_by_name (core_bfd
, "null0");
2210 osec_size
= bfd_section_size (core_bfd
, osec
);
2212 fprintf_unfiltered (gdb_stdlog
, "Find precord section %s.\n",
2213 osec
? "succeeded" : "failed");
2217 fprintf_unfiltered (gdb_stdlog
, "%s", bfd_section_name (core_bfd
, osec
));
2219 /* Check the magic code. */
2220 bfdcore_read (core_bfd
, osec
, &magic
, sizeof (magic
), &bfd_offset
);
2221 if (magic
!= RECORD_FILE_MAGIC
)
2222 error (_("Version mis-match or file format error in core file %s."),
2223 bfd_get_filename (core_bfd
));
2225 fprintf_unfiltered (gdb_stdlog
, "\
2226 Reading 4-byte magic cookie RECORD_FILE_MAGIC (0x%s)\n",
2227 phex_nz (netorder32 (magic
), 4));
2229 /* Restore the entries in recfd into record_arch_list_head and
2230 record_arch_list_tail. */
2231 record_arch_list_head
= NULL
;
2232 record_arch_list_tail
= NULL
;
2233 record_insn_num
= 0;
2234 old_cleanups
= make_cleanup (record_arch_list_cleanups
, 0);
2235 regcache
= get_current_regcache ();
2240 uint32_t regnum
, len
, signal
, count
;
2243 /* We are finished when offset reaches osec_size. */
2244 if (bfd_offset
>= osec_size
)
2246 bfdcore_read (core_bfd
, osec
, &rectype
, sizeof (rectype
), &bfd_offset
);
2250 case record_reg
: /* reg */
2251 /* Get register number to regnum. */
2252 bfdcore_read (core_bfd
, osec
, ®num
,
2253 sizeof (regnum
), &bfd_offset
);
2254 regnum
= netorder32 (regnum
);
2256 rec
= record_reg_alloc (regcache
, regnum
);
2259 bfdcore_read (core_bfd
, osec
, record_get_loc (rec
),
2260 rec
->u
.reg
.len
, &bfd_offset
);
2263 fprintf_unfiltered (gdb_stdlog
, "\
2264 Reading register %d (1 plus %lu plus %d bytes)\n",
2266 (unsigned long) sizeof (regnum
),
2270 case record_mem
: /* mem */
2272 bfdcore_read (core_bfd
, osec
, &len
,
2273 sizeof (len
), &bfd_offset
);
2274 len
= netorder32 (len
);
2277 bfdcore_read (core_bfd
, osec
, &addr
,
2278 sizeof (addr
), &bfd_offset
);
2279 addr
= netorder64 (addr
);
2281 rec
= record_mem_alloc (addr
, len
);
2284 bfdcore_read (core_bfd
, osec
, record_get_loc (rec
),
2285 rec
->u
.mem
.len
, &bfd_offset
);
2288 fprintf_unfiltered (gdb_stdlog
, "\
2289 Reading memory %s (1 plus %lu plus %lu plus %d bytes)\n",
2290 paddress (get_current_arch (),
2292 (unsigned long) sizeof (addr
),
2293 (unsigned long) sizeof (len
),
2297 case record_end
: /* end */
2298 rec
= record_end_alloc ();
2301 /* Get signal value. */
2302 bfdcore_read (core_bfd
, osec
, &signal
,
2303 sizeof (signal
), &bfd_offset
);
2304 signal
= netorder32 (signal
);
2305 rec
->u
.end
.sigval
= signal
;
2307 /* Get insn count. */
2308 bfdcore_read (core_bfd
, osec
, &count
,
2309 sizeof (count
), &bfd_offset
);
2310 count
= netorder32 (count
);
2311 rec
->u
.end
.insn_num
= count
;
2312 record_insn_count
= count
+ 1;
2314 fprintf_unfiltered (gdb_stdlog
, "\
2315 Reading record_end (1 + %lu + %lu bytes), offset == %s\n",
2316 (unsigned long) sizeof (signal
),
2317 (unsigned long) sizeof (count
),
2318 paddress (get_current_arch (),
2323 error (_("Bad entry type in core file %s."),
2324 bfd_get_filename (core_bfd
));
2328 /* Add rec to record arch list. */
2329 record_arch_list_add (rec
);
2332 discard_cleanups (old_cleanups
);
2334 /* Add record_arch_list_head to the end of record list. */
2335 record_first
.next
= record_arch_list_head
;
2336 record_arch_list_head
->prev
= &record_first
;
2337 record_arch_list_tail
->next
= NULL
;
2338 record_list
= &record_first
;
2340 /* Update record_insn_max_num. */
2341 if (record_insn_num
> record_insn_max_num
)
2343 record_insn_max_num
= record_insn_num
;
2344 warning (_("Auto increase record/replay buffer limit to %d."),
2345 record_insn_max_num
);
2349 printf_filtered (_("Restored records from core file %s.\n"),
2350 bfd_get_filename (core_bfd
));
2352 print_stack_frame (get_selected_frame (NULL
), 1, SRC_AND_LOC
);
2355 /* bfdcore_write -- write bytes into a core file section. */
2358 bfdcore_write (bfd
*obfd
, asection
*osec
, void *buf
, int len
, int *offset
)
2360 int ret
= bfd_set_section_contents (obfd
, osec
, buf
, *offset
, len
);
2365 error (_("Failed to write %d bytes to core file %s ('%s').\n"),
2366 len
, bfd_get_filename (obfd
),
2367 bfd_errmsg (bfd_get_error ()));
2370 /* Restore the execution log from a file. We use a modified elf
2371 corefile format, with an extra section for our data. */
2374 cmd_record_restore (char *args
, int from_tty
)
2376 core_file_command (args
, from_tty
);
2377 record_open (args
, from_tty
);
2381 record_save_cleanups (void *data
)
2384 char *pathname
= xstrdup (bfd_get_filename (obfd
));
2391 /* Save the execution log to a file. We use a modified elf corefile
2392 format, with an extra section for our data. */
2395 cmd_record_save (char *args
, int from_tty
)
2397 char *recfilename
, recfilename_buffer
[40];
2398 struct record_entry
*cur_record_list
;
2400 struct regcache
*regcache
;
2401 struct gdbarch
*gdbarch
;
2402 struct cleanup
*old_cleanups
;
2403 struct cleanup
*set_cleanups
;
2406 asection
*osec
= NULL
;
2409 if (strcmp (current_target
.to_shortname
, "record") != 0)
2410 error (_("This command can only be used with target 'record'.\n"
2411 "Use 'target record' first.\n"));
2417 /* Default recfile name is "gdb_record.PID". */
2418 snprintf (recfilename_buffer
, sizeof (recfilename_buffer
),
2419 "gdb_record.%d", PIDGET (inferior_ptid
));
2420 recfilename
= recfilename_buffer
;
2423 /* Open the save file. */
2425 fprintf_unfiltered (gdb_stdlog
, "Saving execution log to core file '%s'\n",
2428 /* Open the output file. */
2429 obfd
= create_gcore_bfd (recfilename
);
2430 old_cleanups
= make_cleanup (record_save_cleanups
, obfd
);
2432 /* Save the current record entry to "cur_record_list". */
2433 cur_record_list
= record_list
;
2435 /* Get the values of regcache and gdbarch. */
2436 regcache
= get_current_regcache ();
2437 gdbarch
= get_regcache_arch (regcache
);
2439 /* Disable the GDB operation record. */
2440 set_cleanups
= record_gdb_operation_disable_set ();
2442 /* Reverse execute to the begin of record list. */
2445 /* Check for beginning and end of log. */
2446 if (record_list
== &record_first
)
2449 record_exec_insn (regcache
, gdbarch
, record_list
);
2451 if (record_list
->prev
)
2452 record_list
= record_list
->prev
;
2455 /* Compute the size needed for the extra bfd section. */
2456 save_size
= 4; /* magic cookie */
2457 for (record_list
= record_first
.next
; record_list
;
2458 record_list
= record_list
->next
)
2459 switch (record_list
->type
)
2462 save_size
+= 1 + 4 + 4;
2465 save_size
+= 1 + 4 + record_list
->u
.reg
.len
;
2468 save_size
+= 1 + 4 + 8 + record_list
->u
.mem
.len
;
2472 /* Make the new bfd section. */
2473 osec
= bfd_make_section_anyway_with_flags (obfd
, "precord",
2477 error (_("Failed to create 'precord' section for corefile %s: %s"),
2479 bfd_errmsg (bfd_get_error ()));
2480 bfd_set_section_size (obfd
, osec
, save_size
);
2481 bfd_set_section_vma (obfd
, osec
, 0);
2482 bfd_set_section_alignment (obfd
, osec
, 0);
2483 bfd_section_lma (obfd
, osec
) = 0;
2485 /* Save corefile state. */
2486 write_gcore_file (obfd
);
2488 /* Write out the record log. */
2489 /* Write the magic code. */
2490 magic
= RECORD_FILE_MAGIC
;
2492 fprintf_unfiltered (gdb_stdlog
, "\
2493 Writing 4-byte magic cookie RECORD_FILE_MAGIC (0x%s)\n",
2494 phex_nz (magic
, 4));
2495 bfdcore_write (obfd
, osec
, &magic
, sizeof (magic
), &bfd_offset
);
2497 /* Save the entries to recfd and forward execute to the end of
2499 record_list
= &record_first
;
2503 if (record_list
!= &record_first
)
2506 uint32_t regnum
, len
, signal
, count
;
2509 type
= record_list
->type
;
2510 bfdcore_write (obfd
, osec
, &type
, sizeof (type
), &bfd_offset
);
2512 switch (record_list
->type
)
2514 case record_reg
: /* reg */
2516 fprintf_unfiltered (gdb_stdlog
, "\
2517 Writing register %d (1 plus %lu plus %d bytes)\n",
2518 record_list
->u
.reg
.num
,
2519 (unsigned long) sizeof (regnum
),
2520 record_list
->u
.reg
.len
);
2523 regnum
= netorder32 (record_list
->u
.reg
.num
);
2524 bfdcore_write (obfd
, osec
, ®num
,
2525 sizeof (regnum
), &bfd_offset
);
2528 bfdcore_write (obfd
, osec
, record_get_loc (record_list
),
2529 record_list
->u
.reg
.len
, &bfd_offset
);
2532 case record_mem
: /* mem */
2534 fprintf_unfiltered (gdb_stdlog
, "\
2535 Writing memory %s (1 plus %lu plus %lu plus %d bytes)\n",
2537 record_list
->u
.mem
.addr
),
2538 (unsigned long) sizeof (addr
),
2539 (unsigned long) sizeof (len
),
2540 record_list
->u
.mem
.len
);
2543 len
= netorder32 (record_list
->u
.mem
.len
);
2544 bfdcore_write (obfd
, osec
, &len
, sizeof (len
), &bfd_offset
);
2546 /* Write memaddr. */
2547 addr
= netorder64 (record_list
->u
.mem
.addr
);
2548 bfdcore_write (obfd
, osec
, &addr
,
2549 sizeof (addr
), &bfd_offset
);
2552 bfdcore_write (obfd
, osec
, record_get_loc (record_list
),
2553 record_list
->u
.mem
.len
, &bfd_offset
);
2558 fprintf_unfiltered (gdb_stdlog
, "\
2559 Writing record_end (1 + %lu + %lu bytes)\n",
2560 (unsigned long) sizeof (signal
),
2561 (unsigned long) sizeof (count
));
2562 /* Write signal value. */
2563 signal
= netorder32 (record_list
->u
.end
.sigval
);
2564 bfdcore_write (obfd
, osec
, &signal
,
2565 sizeof (signal
), &bfd_offset
);
2567 /* Write insn count. */
2568 count
= netorder32 (record_list
->u
.end
.insn_num
);
2569 bfdcore_write (obfd
, osec
, &count
,
2570 sizeof (count
), &bfd_offset
);
2575 /* Execute entry. */
2576 record_exec_insn (regcache
, gdbarch
, record_list
);
2578 if (record_list
->next
)
2579 record_list
= record_list
->next
;
2584 /* Reverse execute to cur_record_list. */
2587 /* Check for beginning and end of log. */
2588 if (record_list
== cur_record_list
)
2591 record_exec_insn (regcache
, gdbarch
, record_list
);
2593 if (record_list
->prev
)
2594 record_list
= record_list
->prev
;
2597 do_cleanups (set_cleanups
);
2599 discard_cleanups (old_cleanups
);
2602 printf_filtered (_("Saved core file %s with execution log.\n"),
2606 /* record_goto_insn -- rewind the record log (forward or backward,
2607 depending on DIR) to the given entry, changing the program state
2611 record_goto_insn (struct record_entry
*entry
,
2612 enum exec_direction_kind dir
)
2614 struct cleanup
*set_cleanups
= record_gdb_operation_disable_set ();
2615 struct regcache
*regcache
= get_current_regcache ();
2616 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
2618 /* Assume everything is valid: we will hit the entry,
2619 and we will not hit the end of the recording. */
2621 if (dir
== EXEC_FORWARD
)
2622 record_list
= record_list
->next
;
2626 record_exec_insn (regcache
, gdbarch
, record_list
);
2627 if (dir
== EXEC_REVERSE
)
2628 record_list
= record_list
->prev
;
2630 record_list
= record_list
->next
;
2631 } while (record_list
!= entry
);
2632 do_cleanups (set_cleanups
);
2635 /* "record goto" command. Argument is an instruction number,
2636 as given by "info record".
2638 Rewinds the recording (forward or backward) to the given instruction. */
2641 cmd_record_goto (char *arg
, int from_tty
)
2643 struct record_entry
*p
= NULL
;
2644 ULONGEST target_insn
= 0;
2646 if (arg
== NULL
|| *arg
== '\0')
2647 error (_("Command requires an argument (insn number to go to)."));
2649 if (strncmp (arg
, "start", strlen ("start")) == 0
2650 || strncmp (arg
, "begin", strlen ("begin")) == 0)
2652 /* Special case. Find first insn. */
2653 for (p
= &record_first
; p
!= NULL
; p
= p
->next
)
2654 if (p
->type
== record_end
)
2657 target_insn
= p
->u
.end
.insn_num
;
2659 else if (strncmp (arg
, "end", strlen ("end")) == 0)
2661 /* Special case. Find last insn. */
2662 for (p
= record_list
; p
->next
!= NULL
; p
= p
->next
)
2664 for (; p
!= NULL
; p
= p
->prev
)
2665 if (p
->type
== record_end
)
2668 target_insn
= p
->u
.end
.insn_num
;
2672 /* General case. Find designated insn. */
2673 target_insn
= parse_and_eval_long (arg
);
2675 for (p
= &record_first
; p
!= NULL
; p
= p
->next
)
2676 if (p
->type
== record_end
&& p
->u
.end
.insn_num
== target_insn
)
2681 error (_("Target insn '%s' not found."), arg
);
2682 else if (p
== record_list
)
2683 error (_("Already at insn '%s'."), arg
);
2684 else if (p
->u
.end
.insn_num
> record_list
->u
.end
.insn_num
)
2686 printf_filtered (_("Go forward to insn number %s\n"),
2687 pulongest (target_insn
));
2688 record_goto_insn (p
, EXEC_FORWARD
);
2692 printf_filtered (_("Go backward to insn number %s\n"),
2693 pulongest (target_insn
));
2694 record_goto_insn (p
, EXEC_REVERSE
);
2696 registers_changed ();
2697 reinit_frame_cache ();
2698 print_stack_frame (get_selected_frame (NULL
), 1, SRC_AND_LOC
);
2702 _initialize_record (void)
2704 struct cmd_list_element
*c
;
2706 /* Init record_first. */
2707 record_first
.prev
= NULL
;
2708 record_first
.next
= NULL
;
2709 record_first
.type
= record_end
;
2712 add_target (&record_ops
);
2713 init_record_core_ops ();
2714 add_target (&record_core_ops
);
2716 add_setshow_zinteger_cmd ("record", no_class
, &record_debug
,
2717 _("Set debugging of record/replay feature."),
2718 _("Show debugging of record/replay feature."),
2719 _("When enabled, debugging output for "
2720 "record/replay feature is displayed."),
2721 NULL
, show_record_debug
, &setdebuglist
,
2724 c
= add_prefix_cmd ("record", class_obscure
, cmd_record_start
,
2725 _("Abbreviated form of \"target record\" command."),
2726 &record_cmdlist
, "record ", 0, &cmdlist
);
2727 set_cmd_completer (c
, filename_completer
);
2729 add_com_alias ("rec", "record", class_obscure
, 1);
2730 add_prefix_cmd ("record", class_support
, set_record_command
,
2731 _("Set record options"), &set_record_cmdlist
,
2732 "set record ", 0, &setlist
);
2733 add_alias_cmd ("rec", "record", class_obscure
, 1, &setlist
);
2734 add_prefix_cmd ("record", class_support
, show_record_command
,
2735 _("Show record options"), &show_record_cmdlist
,
2736 "show record ", 0, &showlist
);
2737 add_alias_cmd ("rec", "record", class_obscure
, 1, &showlist
);
2738 add_prefix_cmd ("record", class_support
, info_record_command
,
2739 _("Info record options"), &info_record_cmdlist
,
2740 "info record ", 0, &infolist
);
2741 add_alias_cmd ("rec", "record", class_obscure
, 1, &infolist
);
2743 c
= add_cmd ("save", class_obscure
, cmd_record_save
,
2744 _("Save the execution log to a file.\n\
2745 Argument is optional filename.\n\
2746 Default filename is 'gdb_record.<process_id>'."),
2748 set_cmd_completer (c
, filename_completer
);
2750 c
= add_cmd ("restore", class_obscure
, cmd_record_restore
,
2751 _("Restore the execution log from a file.\n\
2752 Argument is filename. File must be created with 'record save'."),
2754 set_cmd_completer (c
, filename_completer
);
2756 add_cmd ("delete", class_obscure
, cmd_record_delete
,
2757 _("Delete the rest of execution log and start recording it anew."),
2759 add_alias_cmd ("d", "delete", class_obscure
, 1, &record_cmdlist
);
2760 add_alias_cmd ("del", "delete", class_obscure
, 1, &record_cmdlist
);
2762 add_cmd ("stop", class_obscure
, cmd_record_stop
,
2763 _("Stop the record/replay target."),
2765 add_alias_cmd ("s", "stop", class_obscure
, 1, &record_cmdlist
);
2767 /* Record instructions number limit command. */
2768 add_setshow_boolean_cmd ("stop-at-limit", no_class
,
2769 &record_stop_at_limit
, _("\
2770 Set whether record/replay stops when record/replay buffer becomes full."), _("\
2771 Show whether record/replay stops when record/replay buffer becomes full."), _("\
2773 When ON, if the record/replay buffer becomes full, ask user what to do.\n\
2774 When OFF, if the record/replay buffer becomes full,\n\
2775 delete the oldest recorded instruction to make room for each new one."),
2777 &set_record_cmdlist
, &show_record_cmdlist
);
2778 add_setshow_uinteger_cmd ("insn-number-max", no_class
,
2779 &record_insn_max_num
,
2780 _("Set record/replay buffer limit."),
2781 _("Show record/replay buffer limit."), _("\
2782 Set the maximum number of instructions to be stored in the\n\
2783 record/replay buffer. Zero means unlimited. Default is 200000."),
2784 set_record_insn_max_num
,
2785 NULL
, &set_record_cmdlist
, &show_record_cmdlist
);
2787 add_cmd ("goto", class_obscure
, cmd_record_goto
, _("\
2788 Restore the program to its state at instruction number N.\n\
2789 Argument is instruction number, as shown by 'info record'."),
2792 add_setshow_boolean_cmd ("memory-query", no_class
,
2793 &record_memory_query
, _("\
2794 Set whether query if PREC cannot record memory change of next instruction."),
2796 Show whether query if PREC cannot record memory change of next instruction."),
2799 When ON, query if PREC cannot record memory change of next instruction."),
2801 &set_record_cmdlist
, &show_record_cmdlist
);