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
*);
102 static struct target_ops
*record_beneath_to_store_registers_ops
;
103 static void (*record_beneath_to_store_registers
) (struct target_ops
*,
106 static struct target_ops
*record_beneath_to_xfer_partial_ops
;
107 static LONGEST (*record_beneath_to_xfer_partial
) (struct target_ops
*ops
,
108 enum target_object object
,
111 const gdb_byte
*writebuf
,
114 static int (*record_beneath_to_insert_breakpoint
) (struct bp_target_info
*);
115 static int (*record_beneath_to_remove_breakpoint
) (struct bp_target_info
*);
118 record_list_release (struct record_entry
*rec
)
120 struct record_entry
*tmp
;
134 if (tmp
->type
== record_reg
)
135 xfree (tmp
->u
.reg
.val
);
136 else if (tmp
->type
== record_mem
)
137 xfree (tmp
->u
.mem
.val
);
141 if (rec
!= &record_first
)
146 record_list_release_next (void)
148 struct record_entry
*rec
= record_list
;
149 struct record_entry
*tmp
= rec
->next
;
154 if (tmp
->type
== record_reg
)
156 else if (tmp
->type
== record_reg
)
157 xfree (tmp
->u
.reg
.val
);
158 else if (tmp
->type
== record_mem
)
159 xfree (tmp
->u
.mem
.val
);
166 record_list_release_first (void)
168 struct record_entry
*tmp
= NULL
;
169 enum record_type type
;
171 if (!record_first
.next
)
176 type
= record_first
.next
->type
;
178 if (type
== record_reg
)
179 xfree (record_first
.next
->u
.reg
.val
);
180 else if (type
== record_mem
)
181 xfree (record_first
.next
->u
.mem
.val
);
182 tmp
= record_first
.next
;
183 record_first
.next
= tmp
->next
;
186 if (!record_first
.next
)
188 gdb_assert (record_insn_num
== 1);
192 record_first
.next
->prev
= &record_first
;
194 if (type
== record_end
)
201 /* Add a struct record_entry to record_arch_list. */
204 record_arch_list_add (struct record_entry
*rec
)
206 if (record_debug
> 1)
207 fprintf_unfiltered (gdb_stdlog
,
208 "Process record: record_arch_list_add %s.\n",
209 host_address_to_string (rec
));
211 if (record_arch_list_tail
)
213 record_arch_list_tail
->next
= rec
;
214 rec
->prev
= record_arch_list_tail
;
215 record_arch_list_tail
= rec
;
219 record_arch_list_head
= rec
;
220 record_arch_list_tail
= rec
;
224 /* Record the value of a register NUM to record_arch_list. */
227 record_arch_list_add_reg (struct regcache
*regcache
, int num
)
229 struct record_entry
*rec
;
231 if (record_debug
> 1)
232 fprintf_unfiltered (gdb_stdlog
,
233 "Process record: add register num = %d to "
237 rec
= (struct record_entry
*) xmalloc (sizeof (struct record_entry
));
238 rec
->u
.reg
.val
= (gdb_byte
*) xmalloc (MAX_REGISTER_SIZE
);
241 rec
->type
= record_reg
;
242 rec
->u
.reg
.num
= num
;
244 regcache_raw_read (regcache
, num
, rec
->u
.reg
.val
);
246 record_arch_list_add (rec
);
251 /* Record the value of a region of memory whose address is ADDR and
252 length is LEN to record_arch_list. */
255 record_arch_list_add_mem (CORE_ADDR addr
, int len
)
257 struct record_entry
*rec
;
259 if (record_debug
> 1)
260 fprintf_unfiltered (gdb_stdlog
,
261 "Process record: add mem addr = 0x%s len = %d to "
263 paddr_nz (addr
), len
);
268 rec
= (struct record_entry
*) xmalloc (sizeof (struct record_entry
));
269 rec
->u
.mem
.val
= (gdb_byte
*) xmalloc (len
);
272 rec
->type
= record_mem
;
273 rec
->u
.mem
.addr
= addr
;
274 rec
->u
.mem
.len
= len
;
276 if (target_read_memory (addr
, rec
->u
.mem
.val
, len
))
279 fprintf_unfiltered (gdb_stdlog
,
280 "Process record: error reading memory at "
281 "addr = 0x%s len = %d.\n",
282 paddr_nz (addr
), len
);
283 xfree (rec
->u
.mem
.val
);
288 record_arch_list_add (rec
);
293 /* Add a record_end type struct record_entry to record_arch_list. */
296 record_arch_list_add_end (void)
298 struct record_entry
*rec
;
300 if (record_debug
> 1)
301 fprintf_unfiltered (gdb_stdlog
,
302 "Process record: add end to arch list.\n");
304 rec
= (struct record_entry
*) xmalloc (sizeof (struct record_entry
));
307 rec
->type
= record_end
;
309 record_arch_list_add (rec
);
315 record_check_insn_num (int set_terminal
)
317 if (record_insn_max_num
)
319 gdb_assert (record_insn_num
<= record_insn_max_num
);
320 if (record_insn_num
== record_insn_max_num
)
322 /* Ask user what to do. */
323 if (record_stop_at_limit
)
327 target_terminal_ours ();
328 q
= yquery (_("Do you want to auto delete previous execution "
329 "log entries when record/replay buffer becomes "
330 "full (record stop-at-limit)?"));
332 target_terminal_inferior ();
334 record_stop_at_limit
= 0;
336 error (_("Process record: inferior program stopped."));
342 /* Before inferior step (when GDB record the running message, inferior
343 only can step), GDB will call this function to record the values to
344 record_list. This function will call gdbarch_process_record to
345 record the running message of inferior and set them to
346 record_arch_list, and add it to record_list. */
349 record_message_cleanups (void *ignore
)
351 record_list_release (record_arch_list_tail
);
355 record_message (void *args
)
358 struct regcache
*regcache
= args
;
359 struct cleanup
*old_cleanups
= make_cleanup (record_message_cleanups
, 0);
361 record_arch_list_head
= NULL
;
362 record_arch_list_tail
= NULL
;
364 /* Check record_insn_num. */
365 record_check_insn_num (1);
367 ret
= gdbarch_process_record (get_regcache_arch (regcache
),
369 regcache_read_pc (regcache
));
371 error (_("Process record: inferior program stopped."));
373 error (_("Process record: failed to record execution log."));
375 discard_cleanups (old_cleanups
);
377 record_list
->next
= record_arch_list_head
;
378 record_arch_list_head
->prev
= record_list
;
379 record_list
= record_arch_list_tail
;
381 if (record_insn_num
== record_insn_max_num
&& record_insn_max_num
)
382 record_list_release_first ();
390 do_record_message (struct regcache
*regcache
)
392 return catch_errors (record_message
, regcache
, NULL
, RETURN_MASK_ALL
);
395 /* Set to 1 if record_store_registers and record_xfer_partial
396 doesn't need record. */
398 static int record_gdb_operation_disable
= 0;
401 record_gdb_operation_disable_set (void)
403 struct cleanup
*old_cleanups
= NULL
;
406 make_cleanup_restore_integer (&record_gdb_operation_disable
);
407 record_gdb_operation_disable
= 1;
413 record_open (char *name
, int from_tty
)
415 struct target_ops
*t
;
418 fprintf_unfiltered (gdb_stdlog
, "Process record: record_open\n");
421 if (!target_has_execution
)
422 error (_("Process record: the program is not being run."));
424 error (_("Process record target can't debug inferior in non-stop mode "
426 if (target_async_permitted
)
427 error (_("Process record target can't debug inferior in asynchronous "
428 "mode (target-async)."));
430 if (!gdbarch_process_record_p (current_gdbarch
))
431 error (_("Process record: the current architecture doesn't support "
432 "record function."));
434 /* Check if record target is already running. */
435 if (current_target
.to_stratum
== record_stratum
)
438 (_("Process record target already running, do you want to delete "
439 "the old record log?")))
443 /*Reset the beneath function pointers. */
444 record_beneath_to_resume
= NULL
;
445 record_beneath_to_wait
= NULL
;
446 record_beneath_to_store_registers
= NULL
;
447 record_beneath_to_xfer_partial
= NULL
;
448 record_beneath_to_insert_breakpoint
= NULL
;
449 record_beneath_to_remove_breakpoint
= NULL
;
451 /* Set the beneath function pointers. */
452 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
454 if (!record_beneath_to_resume
)
456 record_beneath_to_resume
= t
->to_resume
;
457 record_beneath_to_resume_ops
= t
;
459 if (!record_beneath_to_wait
)
461 record_beneath_to_wait
= t
->to_wait
;
462 record_beneath_to_wait_ops
= t
;
464 if (!record_beneath_to_store_registers
)
466 record_beneath_to_store_registers
= t
->to_store_registers
;
467 record_beneath_to_store_registers_ops
= t
;
469 if (!record_beneath_to_xfer_partial
)
471 record_beneath_to_xfer_partial
= t
->to_xfer_partial
;
472 record_beneath_to_xfer_partial_ops
= t
;
474 if (!record_beneath_to_insert_breakpoint
)
475 record_beneath_to_insert_breakpoint
= t
->to_insert_breakpoint
;
476 if (!record_beneath_to_remove_breakpoint
)
477 record_beneath_to_remove_breakpoint
= t
->to_remove_breakpoint
;
479 if (!record_beneath_to_resume
)
480 error (_("Process record can't get to_resume."));
481 if (!record_beneath_to_wait
)
482 error (_("Process record can't get to_wait."));
483 if (!record_beneath_to_store_registers
)
484 error (_("Process record can't get to_store_registers."));
485 if (!record_beneath_to_xfer_partial
)
486 error (_("Process record can't get to_xfer_partial."));
487 if (!record_beneath_to_insert_breakpoint
)
488 error (_("Process record can't get to_insert_breakpoint."));
489 if (!record_beneath_to_remove_breakpoint
)
490 error (_("Process record can't get to_remove_breakpoint."));
492 push_target (&record_ops
);
496 record_list
= &record_first
;
497 record_list
->next
= NULL
;
501 record_close (int quitting
)
504 fprintf_unfiltered (gdb_stdlog
, "Process record: record_close\n");
506 record_list_release (record_list
);
509 static int record_resume_step
= 0;
510 static enum target_signal record_resume_siggnal
;
511 static int record_resume_error
;
514 record_resume (struct target_ops
*ops
, ptid_t ptid
, int step
,
515 enum target_signal siggnal
)
517 record_resume_step
= step
;
518 record_resume_siggnal
= siggnal
;
520 if (!RECORD_IS_REPLAY
)
522 if (do_record_message (get_current_regcache ()))
524 record_resume_error
= 0;
528 record_resume_error
= 1;
531 record_beneath_to_resume (record_beneath_to_resume_ops
, ptid
, 1,
536 static int record_get_sig
= 0;
539 record_sig_handler (int signo
)
542 fprintf_unfiltered (gdb_stdlog
, "Process record: get a signal\n");
544 /* It will break the running inferior in replay mode. */
545 record_resume_step
= 1;
547 /* It will let record_wait set inferior status to get the signal
553 record_wait_cleanups (void *ignore
)
555 if (execution_direction
== EXEC_REVERSE
)
557 if (record_list
->next
)
558 record_list
= record_list
->next
;
561 record_list
= record_list
->prev
;
564 /* In replay mode, this function examines the recorded log and
565 determines where to stop. */
568 record_wait (struct target_ops
*ops
,
569 ptid_t ptid
, struct target_waitstatus
*status
)
571 struct cleanup
*set_cleanups
= record_gdb_operation_disable_set ();
574 fprintf_unfiltered (gdb_stdlog
,
575 "Process record: record_wait "
576 "record_resume_step = %d\n",
579 if (!RECORD_IS_REPLAY
)
581 if (record_resume_error
)
583 /* If record_resume get error, return directly. */
584 status
->kind
= TARGET_WAITKIND_STOPPED
;
585 status
->value
.sig
= TARGET_SIGNAL_ABRT
;
586 return inferior_ptid
;
589 if (record_resume_step
)
591 /* This is a single step. */
592 return record_beneath_to_wait (record_beneath_to_wait_ops
,
597 /* This is not a single step. */
603 ret
= record_beneath_to_wait (record_beneath_to_wait_ops
,
606 if (status
->kind
== TARGET_WAITKIND_STOPPED
607 && status
->value
.sig
== TARGET_SIGNAL_TRAP
)
609 /* Check if there is a breakpoint. */
610 registers_changed ();
612 if (breakpoint_inserted_here_p (tmp_pc
))
614 /* There is a breakpoint. */
615 CORE_ADDR decr_pc_after_break
=
616 gdbarch_decr_pc_after_break
617 (get_regcache_arch (get_current_regcache ()));
618 if (decr_pc_after_break
)
620 regcache_write_pc (get_thread_regcache (ret
),
621 tmp_pc
+ decr_pc_after_break
);
626 /* There is not a breakpoint. */
627 if (!do_record_message (get_current_regcache ()))
631 record_beneath_to_resume (record_beneath_to_resume_ops
,
633 record_resume_siggnal
);
638 /* The inferior is broken by a breakpoint or a signal. */
647 struct regcache
*regcache
= get_current_regcache ();
648 int continue_flag
= 1;
649 int first_record_end
= 1;
650 struct cleanup
*old_cleanups
= make_cleanup (record_wait_cleanups
, 0);
653 status
->kind
= TARGET_WAITKIND_STOPPED
;
655 /* Check breakpoint when forward execute. */
656 if (execution_direction
== EXEC_FORWARD
)
658 tmp_pc
= regcache_read_pc (regcache
);
659 if (breakpoint_inserted_here_p (tmp_pc
))
662 fprintf_unfiltered (gdb_stdlog
,
663 "Process record: break at 0x%s.\n",
665 if (gdbarch_decr_pc_after_break (get_regcache_arch (regcache
))
666 && !record_resume_step
)
667 regcache_write_pc (regcache
,
669 gdbarch_decr_pc_after_break
670 (get_regcache_arch (regcache
)));
676 signal (SIGINT
, record_sig_handler
);
677 /* If GDB is in terminal_inferior mode, it will not get the signal.
678 And in GDB replay mode, GDB doesn't need to be in terminal_inferior
679 mode, because inferior will not executed.
680 Then set it to terminal_ours to make GDB get the signal. */
681 target_terminal_ours ();
683 /* In EXEC_FORWARD mode, record_list points to the tail of prev
685 if (execution_direction
== EXEC_FORWARD
&& record_list
->next
)
686 record_list
= record_list
->next
;
688 /* Loop over the record_list, looking for the next place to
692 /* Check for beginning and end of log. */
693 if (execution_direction
== EXEC_REVERSE
694 && record_list
== &record_first
)
696 /* Hit beginning of record log in reverse. */
697 status
->kind
= TARGET_WAITKIND_NO_HISTORY
;
700 if (execution_direction
!= EXEC_REVERSE
&& !record_list
->next
)
702 /* Hit end of record log going forward. */
703 status
->kind
= TARGET_WAITKIND_NO_HISTORY
;
707 /* Set ptid, register and memory according to record_list. */
708 if (record_list
->type
== record_reg
)
711 gdb_byte reg
[MAX_REGISTER_SIZE
];
712 if (record_debug
> 1)
713 fprintf_unfiltered (gdb_stdlog
,
714 "Process record: record_reg %s to "
715 "inferior num = %d.\n",
716 host_address_to_string (record_list
),
717 record_list
->u
.reg
.num
);
718 regcache_cooked_read (regcache
, record_list
->u
.reg
.num
, reg
);
719 regcache_cooked_write (regcache
, record_list
->u
.reg
.num
,
720 record_list
->u
.reg
.val
);
721 memcpy (record_list
->u
.reg
.val
, reg
, MAX_REGISTER_SIZE
);
723 else if (record_list
->type
== record_mem
)
726 gdb_byte
*mem
= alloca (record_list
->u
.mem
.len
);
727 if (record_debug
> 1)
728 fprintf_unfiltered (gdb_stdlog
,
729 "Process record: record_mem %s to "
730 "inferior addr = 0x%s len = %d.\n",
731 host_address_to_string (record_list
),
732 paddr_nz (record_list
->u
.mem
.addr
),
733 record_list
->u
.mem
.len
);
735 if (target_read_memory
736 (record_list
->u
.mem
.addr
, mem
, record_list
->u
.mem
.len
))
737 error (_("Process record: error reading memory at "
738 "addr = 0x%s len = %d."),
739 paddr_nz (record_list
->u
.mem
.addr
),
740 record_list
->u
.mem
.len
);
742 if (target_write_memory
743 (record_list
->u
.mem
.addr
, record_list
->u
.mem
.val
,
744 record_list
->u
.mem
.len
))
746 ("Process record: error writing memory at "
747 "addr = 0x%s len = %d."),
748 paddr_nz (record_list
->u
.mem
.addr
),
749 record_list
->u
.mem
.len
);
751 memcpy (record_list
->u
.mem
.val
, mem
, record_list
->u
.mem
.len
);
755 if (record_debug
> 1)
756 fprintf_unfiltered (gdb_stdlog
,
757 "Process record: record_end %s to "
759 host_address_to_string (record_list
));
761 if (first_record_end
&& execution_direction
== EXEC_REVERSE
)
763 /* When reverse excute, the first record_end is the part of
764 current instruction. */
765 first_record_end
= 0;
769 /* In EXEC_REVERSE mode, this is the record_end of prev
771 In EXEC_FORWARD mode, this is the record_end of current
774 if (record_resume_step
)
776 if (record_debug
> 1)
777 fprintf_unfiltered (gdb_stdlog
,
778 "Process record: step.\n");
782 /* check breakpoint */
783 tmp_pc
= regcache_read_pc (regcache
);
784 if (breakpoint_inserted_here_p (tmp_pc
))
787 fprintf_unfiltered (gdb_stdlog
,
788 "Process record: break "
791 if (gdbarch_decr_pc_after_break (get_regcache_arch (regcache
))
792 && execution_direction
== EXEC_FORWARD
793 && !record_resume_step
)
794 regcache_write_pc (regcache
,
796 gdbarch_decr_pc_after_break
797 (get_regcache_arch (regcache
)));
805 if (execution_direction
== EXEC_REVERSE
)
807 if (record_list
->prev
)
808 record_list
= record_list
->prev
;
812 if (record_list
->next
)
813 record_list
= record_list
->next
;
817 while (continue_flag
);
819 signal (SIGINT
, handle_sigint
);
823 status
->value
.sig
= TARGET_SIGNAL_INT
;
825 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
827 discard_cleanups (old_cleanups
);
830 do_cleanups (set_cleanups
);
831 return inferior_ptid
;
835 record_disconnect (struct target_ops
*target
, char *args
, int from_tty
)
838 fprintf_unfiltered (gdb_stdlog
, "Process record: record_disconnect\n");
840 unpush_target (&record_ops
);
841 target_disconnect (args
, from_tty
);
845 record_detach (struct target_ops
*ops
, char *args
, int from_tty
)
848 fprintf_unfiltered (gdb_stdlog
, "Process record: record_detach\n");
850 unpush_target (&record_ops
);
851 target_detach (args
, from_tty
);
855 record_mourn_inferior (struct target_ops
*ops
)
858 fprintf_unfiltered (gdb_stdlog
, "Process record: "
859 "record_mourn_inferior\n");
861 unpush_target (&record_ops
);
862 target_mourn_inferior ();
865 /* Close process record target before killing the inferior process. */
868 record_kill (struct target_ops
*ops
)
871 fprintf_unfiltered (gdb_stdlog
, "Process record: record_kill\n");
873 unpush_target (&record_ops
);
877 /* Record registers change (by user or by GDB) to list as an instruction. */
880 record_registers_change (struct regcache
*regcache
, int regnum
)
882 /* Check record_insn_num. */
883 record_check_insn_num (0);
885 record_arch_list_head
= NULL
;
886 record_arch_list_tail
= NULL
;
891 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
893 if (record_arch_list_add_reg (regcache
, i
))
895 record_list_release (record_arch_list_tail
);
896 error (_("Process record: failed to record execution log."));
902 if (record_arch_list_add_reg (regcache
, regnum
))
904 record_list_release (record_arch_list_tail
);
905 error (_("Process record: failed to record execution log."));
908 if (record_arch_list_add_end ())
910 record_list_release (record_arch_list_tail
);
911 error (_("Process record: failed to record execution log."));
913 record_list
->next
= record_arch_list_head
;
914 record_arch_list_head
->prev
= record_list
;
915 record_list
= record_arch_list_tail
;
917 if (record_insn_num
== record_insn_max_num
&& record_insn_max_num
)
918 record_list_release_first ();
924 record_store_registers (struct target_ops
*ops
, struct regcache
*regcache
,
927 if (!record_gdb_operation_disable
)
929 if (RECORD_IS_REPLAY
)
932 struct cleanup
*old_cleanups
;
934 /* Let user choose if he wants to write register or not. */
937 nquery (_("Because GDB is in replay mode, changing the "
938 "value of a register will make the execution "
939 "log unusable from this point onward. "
940 "Change all registers?"));
943 nquery (_("Because GDB is in replay mode, changing the value "
944 "of a register will make the execution log unusable "
945 "from this point onward. Change register %s?"),
946 gdbarch_register_name (get_regcache_arch (regcache
),
951 /* Invalidate the value of regcache that was set in function
952 "regcache_raw_write". */
957 i
< gdbarch_num_regs (get_regcache_arch (regcache
));
959 regcache_invalidate (regcache
, i
);
962 regcache_invalidate (regcache
, regno
);
964 error (_("Process record canceled the operation."));
967 /* Destroy the record from here forward. */
968 record_list_release_next ();
971 record_registers_change (regcache
, regno
);
973 record_beneath_to_store_registers (record_beneath_to_store_registers_ops
,
977 /* Behavior is conditional on RECORD_IS_REPLAY.
978 In replay mode, we cannot write memory unles we are willing to
979 invalidate the record/replay log from this point forward. */
982 record_xfer_partial (struct target_ops
*ops
, enum target_object object
,
983 const char *annex
, gdb_byte
*readbuf
,
984 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
986 if (!record_gdb_operation_disable
987 && (object
== TARGET_OBJECT_MEMORY
988 || object
== TARGET_OBJECT_RAW_MEMORY
) && writebuf
)
990 if (RECORD_IS_REPLAY
)
992 /* Let user choose if he wants to write memory or not. */
993 if (!nquery (_("Because GDB is in replay mode, writing to memory "
994 "will make the execution log unusable from this "
995 "point onward. Write memory at address 0x%s?"),
999 /* Destroy the record from here forward. */
1000 record_list_release_next ();
1003 /* Check record_insn_num */
1004 record_check_insn_num (0);
1006 /* Record registers change to list as an instruction. */
1007 record_arch_list_head
= NULL
;
1008 record_arch_list_tail
= NULL
;
1009 if (record_arch_list_add_mem (offset
, len
))
1011 record_list_release (record_arch_list_tail
);
1013 fprintf_unfiltered (gdb_stdlog
,
1014 _("Process record: failed to record "
1018 if (record_arch_list_add_end ())
1020 record_list_release (record_arch_list_tail
);
1022 fprintf_unfiltered (gdb_stdlog
,
1023 _("Process record: failed to record "
1027 record_list
->next
= record_arch_list_head
;
1028 record_arch_list_head
->prev
= record_list
;
1029 record_list
= record_arch_list_tail
;
1031 if (record_insn_num
== record_insn_max_num
&& record_insn_max_num
)
1032 record_list_release_first ();
1037 return record_beneath_to_xfer_partial (record_beneath_to_xfer_partial_ops
,
1038 object
, annex
, readbuf
, writebuf
,
1042 /* Behavior is conditional on RECORD_IS_REPLAY.
1043 We will not actually insert or remove breakpoints when replaying,
1044 nor when recording. */
1047 record_insert_breakpoint (struct bp_target_info
*bp_tgt
)
1049 if (!RECORD_IS_REPLAY
)
1051 struct cleanup
*old_cleanups
= record_gdb_operation_disable_set ();
1052 int ret
= record_beneath_to_insert_breakpoint (bp_tgt
);
1054 do_cleanups (old_cleanups
);
1063 record_remove_breakpoint (struct bp_target_info
*bp_tgt
)
1065 if (!RECORD_IS_REPLAY
)
1067 struct cleanup
*old_cleanups
= record_gdb_operation_disable_set ();
1068 int ret
= record_beneath_to_remove_breakpoint (bp_tgt
);
1070 do_cleanups (old_cleanups
);
1079 record_can_execute_reverse (void)
1085 init_record_ops (void)
1087 record_ops
.to_shortname
= "record";
1088 record_ops
.to_longname
= "Process record and replay target";
1090 "Log program while executing and replay execution from log.";
1091 record_ops
.to_open
= record_open
;
1092 record_ops
.to_close
= record_close
;
1093 record_ops
.to_resume
= record_resume
;
1094 record_ops
.to_wait
= record_wait
;
1095 record_ops
.to_disconnect
= record_disconnect
;
1096 record_ops
.to_detach
= record_detach
;
1097 record_ops
.to_mourn_inferior
= record_mourn_inferior
;
1098 record_ops
.to_kill
= record_kill
;
1099 record_ops
.to_create_inferior
= find_default_create_inferior
;
1100 record_ops
.to_store_registers
= record_store_registers
;
1101 record_ops
.to_xfer_partial
= record_xfer_partial
;
1102 record_ops
.to_insert_breakpoint
= record_insert_breakpoint
;
1103 record_ops
.to_remove_breakpoint
= record_remove_breakpoint
;
1104 record_ops
.to_can_execute_reverse
= record_can_execute_reverse
;
1105 record_ops
.to_stratum
= record_stratum
;
1106 record_ops
.to_magic
= OPS_MAGIC
;
1110 show_record_debug (struct ui_file
*file
, int from_tty
,
1111 struct cmd_list_element
*c
, const char *value
)
1113 fprintf_filtered (file
, _("Debugging of process record target is %s.\n"),
1117 /* Alias for "target record". */
1120 cmd_record_start (char *args
, int from_tty
)
1122 execute_command ("target record", from_tty
);
1125 /* Truncate the record log from the present point
1126 of replay until the end. */
1129 cmd_record_delete (char *args
, int from_tty
)
1131 if (current_target
.to_stratum
== record_stratum
)
1133 if (RECORD_IS_REPLAY
)
1135 if (!from_tty
|| query (_("Delete the log from this point forward "
1136 "and begin to record the running message "
1138 record_list_release_next ();
1141 printf_unfiltered (_("Already at end of record list.\n"));
1145 printf_unfiltered (_("Process record is not started.\n"));
1148 /* Implement the "stoprecord" command. */
1151 cmd_record_stop (char *args
, int from_tty
)
1153 if (current_target
.to_stratum
== record_stratum
)
1155 if (!record_list
|| !from_tty
|| query (_("Delete recorded log and "
1156 "stop recording?")))
1157 unpush_target (&record_ops
);
1160 printf_unfiltered (_("Process record is not started.\n"));
1163 /* Set upper limit of record log size. */
1166 set_record_insn_max_num (char *args
, int from_tty
, struct cmd_list_element
*c
)
1168 if (record_insn_num
> record_insn_max_num
&& record_insn_max_num
)
1170 printf_unfiltered (_("Record instructions number is bigger than "
1171 "record instructions max number. Auto delete "
1172 "the first ones?\n"));
1174 while (record_insn_num
> record_insn_max_num
)
1175 record_list_release_first ();
1179 /* Print the current index into the record log (number of insns recorded
1183 show_record_insn_number (char *ignore
, int from_tty
)
1185 printf_unfiltered (_("Record instruction number is %d.\n"),
1189 static struct cmd_list_element
*record_cmdlist
, *set_record_cmdlist
,
1190 *show_record_cmdlist
, *info_record_cmdlist
;
1193 set_record_command (char *args
, int from_tty
)
1195 printf_unfiltered (_("\
1196 \"set record\" must be followed by an apporpriate subcommand.\n"));
1197 help_list (set_record_cmdlist
, "set record ", all_commands
, gdb_stdout
);
1201 show_record_command (char *args
, int from_tty
)
1203 cmd_show_list (show_record_cmdlist
, from_tty
, "");
1207 info_record_command (char *args
, int from_tty
)
1209 cmd_show_list (info_record_cmdlist
, from_tty
, "");
1213 _initialize_record (void)
1215 /* Init record_first. */
1216 record_first
.prev
= NULL
;
1217 record_first
.next
= NULL
;
1218 record_first
.type
= record_end
;
1221 add_target (&record_ops
);
1223 add_setshow_zinteger_cmd ("record", no_class
, &record_debug
,
1224 _("Set debugging of record/replay feature."),
1225 _("Show debugging of record/replay feature."),
1226 _("When enabled, debugging output for "
1227 "record/replay feature is displayed."),
1228 NULL
, show_record_debug
, &setdebuglist
,
1231 add_prefix_cmd ("record", class_obscure
, cmd_record_start
,
1232 _("Abbreviated form of \"target record\" command."),
1233 &record_cmdlist
, "record ", 0, &cmdlist
);
1234 add_com_alias ("rec", "record", class_obscure
, 1);
1235 add_prefix_cmd ("record", class_support
, set_record_command
,
1236 _("Set record options"), &set_record_cmdlist
,
1237 "set record ", 0, &setlist
);
1238 add_alias_cmd ("rec", "record", class_obscure
, 1, &setlist
);
1239 add_prefix_cmd ("record", class_support
, show_record_command
,
1240 _("Show record options"), &show_record_cmdlist
,
1241 "show record ", 0, &showlist
);
1242 add_alias_cmd ("rec", "record", class_obscure
, 1, &showlist
);
1243 add_prefix_cmd ("record", class_support
, info_record_command
,
1244 _("Info record options"), &info_record_cmdlist
,
1245 "info record ", 0, &infolist
);
1246 add_alias_cmd ("rec", "record", class_obscure
, 1, &infolist
);
1249 add_cmd ("delete", class_obscure
, cmd_record_delete
,
1250 _("Delete the rest of execution log and start recording it anew."),
1252 add_alias_cmd ("d", "delete", class_obscure
, 1, &record_cmdlist
);
1253 add_alias_cmd ("del", "delete", class_obscure
, 1, &record_cmdlist
);
1255 add_cmd ("stop", class_obscure
, cmd_record_stop
,
1256 _("Stop the record/replay target."),
1258 add_alias_cmd ("s", "stop", class_obscure
, 1, &record_cmdlist
);
1260 /* Record instructions number limit command. */
1261 add_setshow_boolean_cmd ("stop-at-limit", no_class
,
1262 &record_stop_at_limit
,
1263 _("Set whether record/replay stop when "
1264 "record/replay buffer becomes full."),
1265 _("Show whether record/replay stop when "
1266 "record/replay buffer becomes full."),
1267 _("Enable is default value.\n"
1268 "When enabled, if the record/replay buffer "
1270 "ask user what to do.\n"
1271 "When disabled, if the record/replay buffer "
1273 "delete it and start new recording."),
1275 &set_record_cmdlist
, &show_record_cmdlist
);
1276 add_setshow_zinteger_cmd ("insn-number-max", no_class
,
1277 &record_insn_max_num
,
1278 _("Set record/replay buffer limit."),
1279 _("Show record/replay buffer limit."),
1280 _("Set the maximum number of instructions to be "
1282 "record/replay buffer. "
1283 "Zero means unlimited (default 200000)."),
1284 set_record_insn_max_num
,
1285 NULL
, &set_record_cmdlist
, &show_record_cmdlist
);
1286 add_cmd ("insn-number", class_obscure
, show_record_insn_number
,
1287 _("Show the current number of instructions in the "
1288 "record/replay buffer."), &info_record_cmdlist
);