1 /* Process record and replay target for GDB, the GNU debugger.
3 Copyright (C) 2008, 2009 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include "gdbthread.h"
24 #include "event-top.h"
25 #include "exceptions.h"
30 #define DEFAULT_RECORD_INSN_MAX_NUM 200000
32 #define RECORD_IS_REPLAY \
33 (record_list->next || execution_direction == EXEC_REVERSE)
35 /* These are the core struct of record function.
37 An record_entry is a record of the value change of a register
38 ("record_reg") or a part of memory ("record_mem"). And each
39 instruction must has a struct record_entry ("record_end") that points out this
40 is the last struct record_entry of this instruction.
42 Each struct record_entry is linked to "record_list" by "prev" and "next". */
44 struct record_reg_entry
50 struct record_mem_entry
66 struct record_entry
*prev
;
67 struct record_entry
*next
;
68 enum record_type type
;
72 struct record_reg_entry reg
;
74 struct record_mem_entry mem
;
78 /* This is the debug switch for process record. */
81 /* These list is for execution log. */
82 static struct record_entry record_first
;
83 static struct record_entry
*record_list
= &record_first
;
84 static struct record_entry
*record_arch_list_head
= NULL
;
85 static struct record_entry
*record_arch_list_tail
= NULL
;
87 /* 1 ask user. 0 auto delete the last struct record_entry. */
88 static int record_stop_at_limit
= 1;
89 static int record_insn_max_num
= DEFAULT_RECORD_INSN_MAX_NUM
;
90 static int record_insn_num
= 0;
92 /* The target_ops of process record. */
93 static struct target_ops record_ops
;
95 /* The beneath function pointers. */
96 static struct target_ops
*record_beneath_to_resume_ops
;
97 static void (*record_beneath_to_resume
) (struct target_ops
*, ptid_t
, int,
99 static struct target_ops
*record_beneath_to_wait_ops
;
100 static ptid_t (*record_beneath_to_wait
) (struct target_ops
*, ptid_t
,
101 struct target_waitstatus
*,
103 static struct target_ops
*record_beneath_to_store_registers_ops
;
104 static void (*record_beneath_to_store_registers
) (struct target_ops
*,
107 static struct target_ops
*record_beneath_to_xfer_partial_ops
;
108 static LONGEST (*record_beneath_to_xfer_partial
) (struct target_ops
*ops
,
109 enum target_object object
,
112 const gdb_byte
*writebuf
,
115 static int (*record_beneath_to_insert_breakpoint
) (struct bp_target_info
*);
116 static int (*record_beneath_to_remove_breakpoint
) (struct bp_target_info
*);
119 record_list_release (struct record_entry
*rec
)
121 struct record_entry
*tmp
;
135 if (tmp
->type
== record_reg
)
136 xfree (tmp
->u
.reg
.val
);
137 else if (tmp
->type
== record_mem
)
138 xfree (tmp
->u
.mem
.val
);
142 if (rec
!= &record_first
)
147 record_list_release_next (void)
149 struct record_entry
*rec
= record_list
;
150 struct record_entry
*tmp
= rec
->next
;
155 if (tmp
->type
== record_reg
)
157 else if (tmp
->type
== record_reg
)
158 xfree (tmp
->u
.reg
.val
);
159 else if (tmp
->type
== record_mem
)
160 xfree (tmp
->u
.mem
.val
);
167 record_list_release_first (void)
169 struct record_entry
*tmp
= NULL
;
170 enum record_type type
;
172 if (!record_first
.next
)
177 type
= record_first
.next
->type
;
179 if (type
== record_reg
)
180 xfree (record_first
.next
->u
.reg
.val
);
181 else if (type
== record_mem
)
182 xfree (record_first
.next
->u
.mem
.val
);
183 tmp
= record_first
.next
;
184 record_first
.next
= tmp
->next
;
187 if (!record_first
.next
)
189 gdb_assert (record_insn_num
== 1);
193 record_first
.next
->prev
= &record_first
;
195 if (type
== record_end
)
202 /* Add a struct record_entry to record_arch_list. */
205 record_arch_list_add (struct record_entry
*rec
)
207 if (record_debug
> 1)
208 fprintf_unfiltered (gdb_stdlog
,
209 "Process record: record_arch_list_add %s.\n",
210 host_address_to_string (rec
));
212 if (record_arch_list_tail
)
214 record_arch_list_tail
->next
= rec
;
215 rec
->prev
= record_arch_list_tail
;
216 record_arch_list_tail
= rec
;
220 record_arch_list_head
= rec
;
221 record_arch_list_tail
= rec
;
225 /* Record the value of a register NUM to record_arch_list. */
228 record_arch_list_add_reg (struct regcache
*regcache
, int num
)
230 struct record_entry
*rec
;
232 if (record_debug
> 1)
233 fprintf_unfiltered (gdb_stdlog
,
234 "Process record: add register num = %d to "
238 rec
= (struct record_entry
*) xmalloc (sizeof (struct record_entry
));
239 rec
->u
.reg
.val
= (gdb_byte
*) xmalloc (MAX_REGISTER_SIZE
);
242 rec
->type
= record_reg
;
243 rec
->u
.reg
.num
= num
;
245 regcache_raw_read (regcache
, num
, rec
->u
.reg
.val
);
247 record_arch_list_add (rec
);
252 /* Record the value of a region of memory whose address is ADDR and
253 length is LEN to record_arch_list. */
256 record_arch_list_add_mem (CORE_ADDR addr
, int len
)
258 struct record_entry
*rec
;
260 if (record_debug
> 1)
261 fprintf_unfiltered (gdb_stdlog
,
262 "Process record: add mem addr = 0x%s len = %d to "
264 paddr_nz (addr
), len
);
269 rec
= (struct record_entry
*) xmalloc (sizeof (struct record_entry
));
270 rec
->u
.mem
.val
= (gdb_byte
*) xmalloc (len
);
273 rec
->type
= record_mem
;
274 rec
->u
.mem
.addr
= addr
;
275 rec
->u
.mem
.len
= len
;
277 if (target_read_memory (addr
, rec
->u
.mem
.val
, len
))
280 fprintf_unfiltered (gdb_stdlog
,
281 "Process record: error reading memory at "
282 "addr = 0x%s len = %d.\n",
283 paddr_nz (addr
), len
);
284 xfree (rec
->u
.mem
.val
);
289 record_arch_list_add (rec
);
294 /* Add a record_end type struct record_entry to record_arch_list. */
297 record_arch_list_add_end (void)
299 struct record_entry
*rec
;
301 if (record_debug
> 1)
302 fprintf_unfiltered (gdb_stdlog
,
303 "Process record: add end to arch list.\n");
305 rec
= (struct record_entry
*) xmalloc (sizeof (struct record_entry
));
308 rec
->type
= record_end
;
310 record_arch_list_add (rec
);
316 record_check_insn_num (int set_terminal
)
318 if (record_insn_max_num
)
320 gdb_assert (record_insn_num
<= record_insn_max_num
);
321 if (record_insn_num
== record_insn_max_num
)
323 /* Ask user what to do. */
324 if (record_stop_at_limit
)
328 target_terminal_ours ();
329 q
= yquery (_("Do you want to auto delete previous execution "
330 "log entries when record/replay buffer becomes "
331 "full (record stop-at-limit)?"));
333 target_terminal_inferior ();
335 record_stop_at_limit
= 0;
337 error (_("Process record: inferior program stopped."));
343 /* Before inferior step (when GDB record the running message, inferior
344 only can step), GDB will call this function to record the values to
345 record_list. This function will call gdbarch_process_record to
346 record the running message of inferior and set them to
347 record_arch_list, and add it to record_list. */
350 record_message_cleanups (void *ignore
)
352 record_list_release (record_arch_list_tail
);
356 record_message (void *args
)
359 struct regcache
*regcache
= args
;
360 struct cleanup
*old_cleanups
= make_cleanup (record_message_cleanups
, 0);
362 record_arch_list_head
= NULL
;
363 record_arch_list_tail
= NULL
;
365 /* Check record_insn_num. */
366 record_check_insn_num (1);
368 ret
= gdbarch_process_record (get_regcache_arch (regcache
),
370 regcache_read_pc (regcache
));
372 error (_("Process record: inferior program stopped."));
374 error (_("Process record: failed to record execution log."));
376 discard_cleanups (old_cleanups
);
378 record_list
->next
= record_arch_list_head
;
379 record_arch_list_head
->prev
= record_list
;
380 record_list
= record_arch_list_tail
;
382 if (record_insn_num
== record_insn_max_num
&& record_insn_max_num
)
383 record_list_release_first ();
391 do_record_message (struct regcache
*regcache
)
393 return catch_errors (record_message
, regcache
, NULL
, RETURN_MASK_ALL
);
396 /* Set to 1 if record_store_registers and record_xfer_partial
397 doesn't need record. */
399 static int record_gdb_operation_disable
= 0;
402 record_gdb_operation_disable_set (void)
404 struct cleanup
*old_cleanups
= NULL
;
407 make_cleanup_restore_integer (&record_gdb_operation_disable
);
408 record_gdb_operation_disable
= 1;
414 record_open (char *name
, int from_tty
)
416 struct target_ops
*t
;
419 fprintf_unfiltered (gdb_stdlog
, "Process record: record_open\n");
422 if (!target_has_execution
)
423 error (_("Process record: the program is not being run."));
425 error (_("Process record target can't debug inferior in non-stop mode "
427 if (target_async_permitted
)
428 error (_("Process record target can't debug inferior in asynchronous "
429 "mode (target-async)."));
431 if (!gdbarch_process_record_p (current_gdbarch
))
432 error (_("Process record: the current architecture doesn't support "
433 "record function."));
435 /* Check if record target is already running. */
436 if (current_target
.to_stratum
== record_stratum
)
439 (_("Process record target already running, do you want to delete "
440 "the old record log?")))
444 /*Reset the beneath function pointers. */
445 record_beneath_to_resume
= NULL
;
446 record_beneath_to_wait
= NULL
;
447 record_beneath_to_store_registers
= NULL
;
448 record_beneath_to_xfer_partial
= NULL
;
449 record_beneath_to_insert_breakpoint
= NULL
;
450 record_beneath_to_remove_breakpoint
= NULL
;
452 /* Set the beneath function pointers. */
453 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
455 if (!record_beneath_to_resume
)
457 record_beneath_to_resume
= t
->to_resume
;
458 record_beneath_to_resume_ops
= t
;
460 if (!record_beneath_to_wait
)
462 record_beneath_to_wait
= t
->to_wait
;
463 record_beneath_to_wait_ops
= t
;
465 if (!record_beneath_to_store_registers
)
467 record_beneath_to_store_registers
= t
->to_store_registers
;
468 record_beneath_to_store_registers_ops
= t
;
470 if (!record_beneath_to_xfer_partial
)
472 record_beneath_to_xfer_partial
= t
->to_xfer_partial
;
473 record_beneath_to_xfer_partial_ops
= t
;
475 if (!record_beneath_to_insert_breakpoint
)
476 record_beneath_to_insert_breakpoint
= t
->to_insert_breakpoint
;
477 if (!record_beneath_to_remove_breakpoint
)
478 record_beneath_to_remove_breakpoint
= t
->to_remove_breakpoint
;
480 if (!record_beneath_to_resume
)
481 error (_("Process record can't get to_resume."));
482 if (!record_beneath_to_wait
)
483 error (_("Process record can't get to_wait."));
484 if (!record_beneath_to_store_registers
)
485 error (_("Process record can't get to_store_registers."));
486 if (!record_beneath_to_xfer_partial
)
487 error (_("Process record can't get to_xfer_partial."));
488 if (!record_beneath_to_insert_breakpoint
)
489 error (_("Process record can't get to_insert_breakpoint."));
490 if (!record_beneath_to_remove_breakpoint
)
491 error (_("Process record can't get to_remove_breakpoint."));
493 push_target (&record_ops
);
497 record_list
= &record_first
;
498 record_list
->next
= NULL
;
502 record_close (int quitting
)
505 fprintf_unfiltered (gdb_stdlog
, "Process record: record_close\n");
507 record_list_release (record_list
);
510 static int record_resume_step
= 0;
511 static enum target_signal record_resume_siggnal
;
512 static int record_resume_error
;
515 record_resume (struct target_ops
*ops
, ptid_t ptid
, int step
,
516 enum target_signal siggnal
)
518 record_resume_step
= step
;
519 record_resume_siggnal
= siggnal
;
521 if (!RECORD_IS_REPLAY
)
523 if (do_record_message (get_current_regcache ()))
525 record_resume_error
= 0;
529 record_resume_error
= 1;
532 record_beneath_to_resume (record_beneath_to_resume_ops
, ptid
, 1,
537 static int record_get_sig
= 0;
540 record_sig_handler (int signo
)
543 fprintf_unfiltered (gdb_stdlog
, "Process record: get a signal\n");
545 /* It will break the running inferior in replay mode. */
546 record_resume_step
= 1;
548 /* It will let record_wait set inferior status to get the signal
554 record_wait_cleanups (void *ignore
)
556 if (execution_direction
== EXEC_REVERSE
)
558 if (record_list
->next
)
559 record_list
= record_list
->next
;
562 record_list
= record_list
->prev
;
565 /* In replay mode, this function examines the recorded log and
566 determines where to stop. */
569 record_wait (struct target_ops
*ops
,
570 ptid_t ptid
, struct target_waitstatus
*status
,
573 struct cleanup
*set_cleanups
= record_gdb_operation_disable_set ();
576 fprintf_unfiltered (gdb_stdlog
,
577 "Process record: record_wait "
578 "record_resume_step = %d\n",
581 if (!RECORD_IS_REPLAY
)
583 if (record_resume_error
)
585 /* If record_resume get error, return directly. */
586 status
->kind
= TARGET_WAITKIND_STOPPED
;
587 status
->value
.sig
= TARGET_SIGNAL_ABRT
;
588 return inferior_ptid
;
591 if (record_resume_step
)
593 /* This is a single step. */
594 return record_beneath_to_wait (record_beneath_to_wait_ops
,
599 /* This is not a single step. */
605 ret
= record_beneath_to_wait (record_beneath_to_wait_ops
,
608 if (status
->kind
== TARGET_WAITKIND_STOPPED
609 && status
->value
.sig
== TARGET_SIGNAL_TRAP
)
611 /* Check if there is a breakpoint. */
612 registers_changed ();
613 tmp_pc
= regcache_read_pc (get_current_regcache ());
614 if (breakpoint_inserted_here_p (tmp_pc
))
616 /* There is a breakpoint. */
617 CORE_ADDR decr_pc_after_break
=
618 gdbarch_decr_pc_after_break
619 (get_regcache_arch (get_current_regcache ()));
620 if (decr_pc_after_break
)
622 regcache_write_pc (get_thread_regcache (ret
),
623 tmp_pc
+ decr_pc_after_break
);
628 /* There is not a breakpoint. */
629 if (!do_record_message (get_current_regcache ()))
633 record_beneath_to_resume (record_beneath_to_resume_ops
,
635 record_resume_siggnal
);
640 /* The inferior is broken by a breakpoint or a signal. */
649 struct regcache
*regcache
= get_current_regcache ();
650 int continue_flag
= 1;
651 int first_record_end
= 1;
652 struct cleanup
*old_cleanups
= make_cleanup (record_wait_cleanups
, 0);
655 status
->kind
= TARGET_WAITKIND_STOPPED
;
657 /* Check breakpoint when forward execute. */
658 if (execution_direction
== EXEC_FORWARD
)
660 tmp_pc
= regcache_read_pc (regcache
);
661 if (breakpoint_inserted_here_p (tmp_pc
))
664 fprintf_unfiltered (gdb_stdlog
,
665 "Process record: break at 0x%s.\n",
667 if (gdbarch_decr_pc_after_break (get_regcache_arch (regcache
))
668 && !record_resume_step
)
669 regcache_write_pc (regcache
,
671 gdbarch_decr_pc_after_break
672 (get_regcache_arch (regcache
)));
678 signal (SIGINT
, record_sig_handler
);
679 /* If GDB is in terminal_inferior mode, it will not get the signal.
680 And in GDB replay mode, GDB doesn't need to be in terminal_inferior
681 mode, because inferior will not executed.
682 Then set it to terminal_ours to make GDB get the signal. */
683 target_terminal_ours ();
685 /* In EXEC_FORWARD mode, record_list points to the tail of prev
687 if (execution_direction
== EXEC_FORWARD
&& record_list
->next
)
688 record_list
= record_list
->next
;
690 /* Loop over the record_list, looking for the next place to
694 /* Check for beginning and end of log. */
695 if (execution_direction
== EXEC_REVERSE
696 && record_list
== &record_first
)
698 /* Hit beginning of record log in reverse. */
699 status
->kind
= TARGET_WAITKIND_NO_HISTORY
;
702 if (execution_direction
!= EXEC_REVERSE
&& !record_list
->next
)
704 /* Hit end of record log going forward. */
705 status
->kind
= TARGET_WAITKIND_NO_HISTORY
;
709 /* Set ptid, register and memory according to record_list. */
710 if (record_list
->type
== record_reg
)
713 gdb_byte reg
[MAX_REGISTER_SIZE
];
714 if (record_debug
> 1)
715 fprintf_unfiltered (gdb_stdlog
,
716 "Process record: record_reg %s to "
717 "inferior num = %d.\n",
718 host_address_to_string (record_list
),
719 record_list
->u
.reg
.num
);
720 regcache_cooked_read (regcache
, record_list
->u
.reg
.num
, reg
);
721 regcache_cooked_write (regcache
, record_list
->u
.reg
.num
,
722 record_list
->u
.reg
.val
);
723 memcpy (record_list
->u
.reg
.val
, reg
, MAX_REGISTER_SIZE
);
725 else if (record_list
->type
== record_mem
)
728 gdb_byte
*mem
= alloca (record_list
->u
.mem
.len
);
729 if (record_debug
> 1)
730 fprintf_unfiltered (gdb_stdlog
,
731 "Process record: record_mem %s to "
732 "inferior addr = 0x%s len = %d.\n",
733 host_address_to_string (record_list
),
734 paddr_nz (record_list
->u
.mem
.addr
),
735 record_list
->u
.mem
.len
);
737 if (target_read_memory
738 (record_list
->u
.mem
.addr
, mem
, record_list
->u
.mem
.len
))
739 error (_("Process record: error reading memory at "
740 "addr = 0x%s len = %d."),
741 paddr_nz (record_list
->u
.mem
.addr
),
742 record_list
->u
.mem
.len
);
744 if (target_write_memory
745 (record_list
->u
.mem
.addr
, record_list
->u
.mem
.val
,
746 record_list
->u
.mem
.len
))
748 ("Process record: error writing memory at "
749 "addr = 0x%s len = %d."),
750 paddr_nz (record_list
->u
.mem
.addr
),
751 record_list
->u
.mem
.len
);
753 memcpy (record_list
->u
.mem
.val
, mem
, record_list
->u
.mem
.len
);
757 if (record_debug
> 1)
758 fprintf_unfiltered (gdb_stdlog
,
759 "Process record: record_end %s to "
761 host_address_to_string (record_list
));
763 if (first_record_end
&& execution_direction
== EXEC_REVERSE
)
765 /* When reverse excute, the first record_end is the part of
766 current instruction. */
767 first_record_end
= 0;
771 /* In EXEC_REVERSE mode, this is the record_end of prev
773 In EXEC_FORWARD mode, this is the record_end of current
776 if (record_resume_step
)
778 if (record_debug
> 1)
779 fprintf_unfiltered (gdb_stdlog
,
780 "Process record: step.\n");
784 /* check breakpoint */
785 tmp_pc
= regcache_read_pc (regcache
);
786 if (breakpoint_inserted_here_p (tmp_pc
))
789 fprintf_unfiltered (gdb_stdlog
,
790 "Process record: break "
793 if (gdbarch_decr_pc_after_break (get_regcache_arch (regcache
))
794 && execution_direction
== EXEC_FORWARD
795 && !record_resume_step
)
796 regcache_write_pc (regcache
,
798 gdbarch_decr_pc_after_break
799 (get_regcache_arch (regcache
)));
807 if (execution_direction
== EXEC_REVERSE
)
809 if (record_list
->prev
)
810 record_list
= record_list
->prev
;
814 if (record_list
->next
)
815 record_list
= record_list
->next
;
819 while (continue_flag
);
821 signal (SIGINT
, handle_sigint
);
825 status
->value
.sig
= TARGET_SIGNAL_INT
;
827 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
829 discard_cleanups (old_cleanups
);
832 do_cleanups (set_cleanups
);
833 return inferior_ptid
;
837 record_disconnect (struct target_ops
*target
, char *args
, int from_tty
)
840 fprintf_unfiltered (gdb_stdlog
, "Process record: record_disconnect\n");
842 unpush_target (&record_ops
);
843 target_disconnect (args
, from_tty
);
847 record_detach (struct target_ops
*ops
, char *args
, int from_tty
)
850 fprintf_unfiltered (gdb_stdlog
, "Process record: record_detach\n");
852 unpush_target (&record_ops
);
853 target_detach (args
, from_tty
);
857 record_mourn_inferior (struct target_ops
*ops
)
860 fprintf_unfiltered (gdb_stdlog
, "Process record: "
861 "record_mourn_inferior\n");
863 unpush_target (&record_ops
);
864 target_mourn_inferior ();
867 /* Close process record target before killing the inferior process. */
870 record_kill (struct target_ops
*ops
)
873 fprintf_unfiltered (gdb_stdlog
, "Process record: record_kill\n");
875 unpush_target (&record_ops
);
879 /* Record registers change (by user or by GDB) to list as an instruction. */
882 record_registers_change (struct regcache
*regcache
, int regnum
)
884 /* Check record_insn_num. */
885 record_check_insn_num (0);
887 record_arch_list_head
= NULL
;
888 record_arch_list_tail
= NULL
;
893 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
895 if (record_arch_list_add_reg (regcache
, i
))
897 record_list_release (record_arch_list_tail
);
898 error (_("Process record: failed to record execution log."));
904 if (record_arch_list_add_reg (regcache
, regnum
))
906 record_list_release (record_arch_list_tail
);
907 error (_("Process record: failed to record execution log."));
910 if (record_arch_list_add_end ())
912 record_list_release (record_arch_list_tail
);
913 error (_("Process record: failed to record execution log."));
915 record_list
->next
= record_arch_list_head
;
916 record_arch_list_head
->prev
= record_list
;
917 record_list
= record_arch_list_tail
;
919 if (record_insn_num
== record_insn_max_num
&& record_insn_max_num
)
920 record_list_release_first ();
926 record_store_registers (struct target_ops
*ops
, struct regcache
*regcache
,
929 if (!record_gdb_operation_disable
)
931 if (RECORD_IS_REPLAY
)
934 struct cleanup
*old_cleanups
;
936 /* Let user choose if he wants to write register or not. */
939 nquery (_("Because GDB is in replay mode, changing the "
940 "value of a register will make the execution "
941 "log unusable from this point onward. "
942 "Change all registers?"));
945 nquery (_("Because GDB is in replay mode, changing the value "
946 "of a register will make the execution log unusable "
947 "from this point onward. Change register %s?"),
948 gdbarch_register_name (get_regcache_arch (regcache
),
953 /* Invalidate the value of regcache that was set in function
954 "regcache_raw_write". */
959 i
< gdbarch_num_regs (get_regcache_arch (regcache
));
961 regcache_invalidate (regcache
, i
);
964 regcache_invalidate (regcache
, regno
);
966 error (_("Process record canceled the operation."));
969 /* Destroy the record from here forward. */
970 record_list_release_next ();
973 record_registers_change (regcache
, regno
);
975 record_beneath_to_store_registers (record_beneath_to_store_registers_ops
,
979 /* Behavior is conditional on RECORD_IS_REPLAY.
980 In replay mode, we cannot write memory unles we are willing to
981 invalidate the record/replay log from this point forward. */
984 record_xfer_partial (struct target_ops
*ops
, enum target_object object
,
985 const char *annex
, gdb_byte
*readbuf
,
986 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
988 if (!record_gdb_operation_disable
989 && (object
== TARGET_OBJECT_MEMORY
990 || object
== TARGET_OBJECT_RAW_MEMORY
) && writebuf
)
992 if (RECORD_IS_REPLAY
)
994 /* Let user choose if he wants to write memory or not. */
995 if (!nquery (_("Because GDB is in replay mode, writing to memory "
996 "will make the execution log unusable from this "
997 "point onward. Write memory at address 0x%s?"),
1001 /* Destroy the record from here forward. */
1002 record_list_release_next ();
1005 /* Check record_insn_num */
1006 record_check_insn_num (0);
1008 /* Record registers change to list as an instruction. */
1009 record_arch_list_head
= NULL
;
1010 record_arch_list_tail
= NULL
;
1011 if (record_arch_list_add_mem (offset
, len
))
1013 record_list_release (record_arch_list_tail
);
1015 fprintf_unfiltered (gdb_stdlog
,
1016 _("Process record: failed to record "
1020 if (record_arch_list_add_end ())
1022 record_list_release (record_arch_list_tail
);
1024 fprintf_unfiltered (gdb_stdlog
,
1025 _("Process record: failed to record "
1029 record_list
->next
= record_arch_list_head
;
1030 record_arch_list_head
->prev
= record_list
;
1031 record_list
= record_arch_list_tail
;
1033 if (record_insn_num
== record_insn_max_num
&& record_insn_max_num
)
1034 record_list_release_first ();
1039 return record_beneath_to_xfer_partial (record_beneath_to_xfer_partial_ops
,
1040 object
, annex
, readbuf
, writebuf
,
1044 /* Behavior is conditional on RECORD_IS_REPLAY.
1045 We will not actually insert or remove breakpoints when replaying,
1046 nor when recording. */
1049 record_insert_breakpoint (struct bp_target_info
*bp_tgt
)
1051 if (!RECORD_IS_REPLAY
)
1053 struct cleanup
*old_cleanups
= record_gdb_operation_disable_set ();
1054 int ret
= record_beneath_to_insert_breakpoint (bp_tgt
);
1056 do_cleanups (old_cleanups
);
1065 record_remove_breakpoint (struct bp_target_info
*bp_tgt
)
1067 if (!RECORD_IS_REPLAY
)
1069 struct cleanup
*old_cleanups
= record_gdb_operation_disable_set ();
1070 int ret
= record_beneath_to_remove_breakpoint (bp_tgt
);
1072 do_cleanups (old_cleanups
);
1081 record_can_execute_reverse (void)
1087 init_record_ops (void)
1089 record_ops
.to_shortname
= "record";
1090 record_ops
.to_longname
= "Process record and replay target";
1092 "Log program while executing and replay execution from log.";
1093 record_ops
.to_open
= record_open
;
1094 record_ops
.to_close
= record_close
;
1095 record_ops
.to_resume
= record_resume
;
1096 record_ops
.to_wait
= record_wait
;
1097 record_ops
.to_disconnect
= record_disconnect
;
1098 record_ops
.to_detach
= record_detach
;
1099 record_ops
.to_mourn_inferior
= record_mourn_inferior
;
1100 record_ops
.to_kill
= record_kill
;
1101 record_ops
.to_create_inferior
= find_default_create_inferior
;
1102 record_ops
.to_store_registers
= record_store_registers
;
1103 record_ops
.to_xfer_partial
= record_xfer_partial
;
1104 record_ops
.to_insert_breakpoint
= record_insert_breakpoint
;
1105 record_ops
.to_remove_breakpoint
= record_remove_breakpoint
;
1106 record_ops
.to_can_execute_reverse
= record_can_execute_reverse
;
1107 record_ops
.to_stratum
= record_stratum
;
1108 record_ops
.to_magic
= OPS_MAGIC
;
1112 show_record_debug (struct ui_file
*file
, int from_tty
,
1113 struct cmd_list_element
*c
, const char *value
)
1115 fprintf_filtered (file
, _("Debugging of process record target is %s.\n"),
1119 /* Alias for "target record". */
1122 cmd_record_start (char *args
, int from_tty
)
1124 execute_command ("target record", from_tty
);
1127 /* Truncate the record log from the present point
1128 of replay until the end. */
1131 cmd_record_delete (char *args
, int from_tty
)
1133 if (current_target
.to_stratum
== record_stratum
)
1135 if (RECORD_IS_REPLAY
)
1137 if (!from_tty
|| query (_("Delete the log from this point forward "
1138 "and begin to record the running message "
1140 record_list_release_next ();
1143 printf_unfiltered (_("Already at end of record list.\n"));
1147 printf_unfiltered (_("Process record is not started.\n"));
1150 /* Implement the "stoprecord" command. */
1153 cmd_record_stop (char *args
, int from_tty
)
1155 if (current_target
.to_stratum
== record_stratum
)
1157 if (!record_list
|| !from_tty
|| query (_("Delete recorded log and "
1158 "stop recording?")))
1159 unpush_target (&record_ops
);
1162 printf_unfiltered (_("Process record is not started.\n"));
1165 /* Set upper limit of record log size. */
1168 set_record_insn_max_num (char *args
, int from_tty
, struct cmd_list_element
*c
)
1170 if (record_insn_num
> record_insn_max_num
&& record_insn_max_num
)
1172 printf_unfiltered (_("Record instructions number is bigger than "
1173 "record instructions max number. Auto delete "
1174 "the first ones?\n"));
1176 while (record_insn_num
> record_insn_max_num
)
1177 record_list_release_first ();
1181 /* Print the current index into the record log (number of insns recorded
1185 show_record_insn_number (char *ignore
, int from_tty
)
1187 printf_unfiltered (_("Record instruction number is %d.\n"),
1191 static struct cmd_list_element
*record_cmdlist
, *set_record_cmdlist
,
1192 *show_record_cmdlist
, *info_record_cmdlist
;
1195 set_record_command (char *args
, int from_tty
)
1197 printf_unfiltered (_("\
1198 \"set record\" must be followed by an apporpriate subcommand.\n"));
1199 help_list (set_record_cmdlist
, "set record ", all_commands
, gdb_stdout
);
1203 show_record_command (char *args
, int from_tty
)
1205 cmd_show_list (show_record_cmdlist
, from_tty
, "");
1209 info_record_command (char *args
, int from_tty
)
1211 cmd_show_list (info_record_cmdlist
, from_tty
, "");
1215 _initialize_record (void)
1217 /* Init record_first. */
1218 record_first
.prev
= NULL
;
1219 record_first
.next
= NULL
;
1220 record_first
.type
= record_end
;
1223 add_target (&record_ops
);
1225 add_setshow_zinteger_cmd ("record", no_class
, &record_debug
,
1226 _("Set debugging of record/replay feature."),
1227 _("Show debugging of record/replay feature."),
1228 _("When enabled, debugging output for "
1229 "record/replay feature is displayed."),
1230 NULL
, show_record_debug
, &setdebuglist
,
1233 add_prefix_cmd ("record", class_obscure
, cmd_record_start
,
1234 _("Abbreviated form of \"target record\" command."),
1235 &record_cmdlist
, "record ", 0, &cmdlist
);
1236 add_com_alias ("rec", "record", class_obscure
, 1);
1237 add_prefix_cmd ("record", class_support
, set_record_command
,
1238 _("Set record options"), &set_record_cmdlist
,
1239 "set record ", 0, &setlist
);
1240 add_alias_cmd ("rec", "record", class_obscure
, 1, &setlist
);
1241 add_prefix_cmd ("record", class_support
, show_record_command
,
1242 _("Show record options"), &show_record_cmdlist
,
1243 "show record ", 0, &showlist
);
1244 add_alias_cmd ("rec", "record", class_obscure
, 1, &showlist
);
1245 add_prefix_cmd ("record", class_support
, info_record_command
,
1246 _("Info record options"), &info_record_cmdlist
,
1247 "info record ", 0, &infolist
);
1248 add_alias_cmd ("rec", "record", class_obscure
, 1, &infolist
);
1251 add_cmd ("delete", class_obscure
, cmd_record_delete
,
1252 _("Delete the rest of execution log and start recording it anew."),
1254 add_alias_cmd ("d", "delete", class_obscure
, 1, &record_cmdlist
);
1255 add_alias_cmd ("del", "delete", class_obscure
, 1, &record_cmdlist
);
1257 add_cmd ("stop", class_obscure
, cmd_record_stop
,
1258 _("Stop the record/replay target."),
1260 add_alias_cmd ("s", "stop", class_obscure
, 1, &record_cmdlist
);
1262 /* Record instructions number limit command. */
1263 add_setshow_boolean_cmd ("stop-at-limit", no_class
,
1264 &record_stop_at_limit
, _("\
1265 Set whether record/replay stops when record/replay buffer becomes full."), _("\
1266 Show whether record/replay stops when record/replay buffer becomes full."), _("\
1268 When ON, if the record/replay buffer becomes full, ask user what to do.\n\
1269 When OFF, if the record/replay buffer becomes full,\n\
1270 delete the oldest recorded instruction to make room for each new one."),
1272 &set_record_cmdlist
, &show_record_cmdlist
);
1273 add_setshow_zinteger_cmd ("insn-number-max", no_class
,
1274 &record_insn_max_num
,
1275 _("Set record/replay buffer limit."),
1276 _("Show record/replay buffer limit."), _("\
1277 Set the maximum number of instructions to be stored in the\n\
1278 record/replay buffer. Zero means unlimited. Default is 200000."),
1279 set_record_insn_max_num
,
1280 NULL
, &set_record_cmdlist
, &show_record_cmdlist
);
1281 add_cmd ("insn-number", class_obscure
, show_record_insn_number
,
1282 _("Show the current number of instructions in the "
1283 "record/replay buffer."), &info_record_cmdlist
);