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 gdbarch
*,
116 struct bp_target_info
*);
117 static int (*record_beneath_to_remove_breakpoint
) (struct gdbarch
*,
118 struct bp_target_info
*);
121 record_list_release (struct record_entry
*rec
)
123 struct record_entry
*tmp
;
137 if (tmp
->type
== record_reg
)
138 xfree (tmp
->u
.reg
.val
);
139 else if (tmp
->type
== record_mem
)
140 xfree (tmp
->u
.mem
.val
);
144 if (rec
!= &record_first
)
149 record_list_release_next (void)
151 struct record_entry
*rec
= record_list
;
152 struct record_entry
*tmp
= rec
->next
;
157 if (tmp
->type
== record_reg
)
159 else if (tmp
->type
== record_reg
)
160 xfree (tmp
->u
.reg
.val
);
161 else if (tmp
->type
== record_mem
)
162 xfree (tmp
->u
.mem
.val
);
169 record_list_release_first (void)
171 struct record_entry
*tmp
= NULL
;
172 enum record_type type
;
174 if (!record_first
.next
)
179 type
= record_first
.next
->type
;
181 if (type
== record_reg
)
182 xfree (record_first
.next
->u
.reg
.val
);
183 else if (type
== record_mem
)
184 xfree (record_first
.next
->u
.mem
.val
);
185 tmp
= record_first
.next
;
186 record_first
.next
= tmp
->next
;
189 if (!record_first
.next
)
191 gdb_assert (record_insn_num
== 1);
195 record_first
.next
->prev
= &record_first
;
197 if (type
== record_end
)
204 /* Add a struct record_entry to record_arch_list. */
207 record_arch_list_add (struct record_entry
*rec
)
209 if (record_debug
> 1)
210 fprintf_unfiltered (gdb_stdlog
,
211 "Process record: record_arch_list_add %s.\n",
212 host_address_to_string (rec
));
214 if (record_arch_list_tail
)
216 record_arch_list_tail
->next
= rec
;
217 rec
->prev
= record_arch_list_tail
;
218 record_arch_list_tail
= rec
;
222 record_arch_list_head
= rec
;
223 record_arch_list_tail
= rec
;
227 /* Record the value of a register NUM to record_arch_list. */
230 record_arch_list_add_reg (struct regcache
*regcache
, int num
)
232 struct record_entry
*rec
;
234 if (record_debug
> 1)
235 fprintf_unfiltered (gdb_stdlog
,
236 "Process record: add register num = %d to "
240 rec
= (struct record_entry
*) xmalloc (sizeof (struct record_entry
));
241 rec
->u
.reg
.val
= (gdb_byte
*) xmalloc (MAX_REGISTER_SIZE
);
244 rec
->type
= record_reg
;
245 rec
->u
.reg
.num
= num
;
247 regcache_raw_read (regcache
, num
, rec
->u
.reg
.val
);
249 record_arch_list_add (rec
);
254 /* Record the value of a region of memory whose address is ADDR and
255 length is LEN to record_arch_list. */
258 record_arch_list_add_mem (CORE_ADDR addr
, int len
)
260 struct record_entry
*rec
;
262 if (record_debug
> 1)
263 fprintf_unfiltered (gdb_stdlog
,
264 "Process record: add mem addr = %s len = %d to "
266 paddress (target_gdbarch
, addr
), len
);
271 rec
= (struct record_entry
*) xmalloc (sizeof (struct record_entry
));
272 rec
->u
.mem
.val
= (gdb_byte
*) xmalloc (len
);
275 rec
->type
= record_mem
;
276 rec
->u
.mem
.addr
= addr
;
277 rec
->u
.mem
.len
= len
;
279 if (target_read_memory (addr
, rec
->u
.mem
.val
, len
))
282 fprintf_unfiltered (gdb_stdlog
,
283 "Process record: error reading memory at "
284 "addr = %s len = %d.\n",
285 paddress (target_gdbarch
, addr
), len
);
286 xfree (rec
->u
.mem
.val
);
291 record_arch_list_add (rec
);
296 /* Add a record_end type struct record_entry to record_arch_list. */
299 record_arch_list_add_end (void)
301 struct record_entry
*rec
;
303 if (record_debug
> 1)
304 fprintf_unfiltered (gdb_stdlog
,
305 "Process record: add end to arch list.\n");
307 rec
= (struct record_entry
*) xmalloc (sizeof (struct record_entry
));
310 rec
->type
= record_end
;
312 record_arch_list_add (rec
);
318 record_check_insn_num (int set_terminal
)
320 if (record_insn_max_num
)
322 gdb_assert (record_insn_num
<= record_insn_max_num
);
323 if (record_insn_num
== record_insn_max_num
)
325 /* Ask user what to do. */
326 if (record_stop_at_limit
)
330 target_terminal_ours ();
331 q
= yquery (_("Do you want to auto delete previous execution "
332 "log entries when record/replay buffer becomes "
333 "full (record stop-at-limit)?"));
335 target_terminal_inferior ();
337 record_stop_at_limit
= 0;
339 error (_("Process record: inferior program stopped."));
345 /* Before inferior step (when GDB record the running message, inferior
346 only can step), GDB will call this function to record the values to
347 record_list. This function will call gdbarch_process_record to
348 record the running message of inferior and set them to
349 record_arch_list, and add it to record_list. */
352 record_message_cleanups (void *ignore
)
354 record_list_release (record_arch_list_tail
);
358 record_message (void *args
)
361 struct regcache
*regcache
= args
;
362 struct cleanup
*old_cleanups
= make_cleanup (record_message_cleanups
, 0);
364 record_arch_list_head
= NULL
;
365 record_arch_list_tail
= NULL
;
367 /* Check record_insn_num. */
368 record_check_insn_num (1);
370 ret
= gdbarch_process_record (get_regcache_arch (regcache
),
372 regcache_read_pc (regcache
));
374 error (_("Process record: inferior program stopped."));
376 error (_("Process record: failed to record execution log."));
378 discard_cleanups (old_cleanups
);
380 record_list
->next
= record_arch_list_head
;
381 record_arch_list_head
->prev
= record_list
;
382 record_list
= record_arch_list_tail
;
384 if (record_insn_num
== record_insn_max_num
&& record_insn_max_num
)
385 record_list_release_first ();
393 do_record_message (struct regcache
*regcache
)
395 return catch_errors (record_message
, regcache
, NULL
, RETURN_MASK_ALL
);
398 /* Set to 1 if record_store_registers and record_xfer_partial
399 doesn't need record. */
401 static int record_gdb_operation_disable
= 0;
404 record_gdb_operation_disable_set (void)
406 struct cleanup
*old_cleanups
= NULL
;
409 make_cleanup_restore_integer (&record_gdb_operation_disable
);
410 record_gdb_operation_disable
= 1;
416 record_open (char *name
, int from_tty
)
418 struct target_ops
*t
;
421 fprintf_unfiltered (gdb_stdlog
, "Process record: record_open\n");
424 if (!target_has_execution
)
425 error (_("Process record: the program is not being run."));
427 error (_("Process record target can't debug inferior in non-stop mode "
429 if (target_async_permitted
)
430 error (_("Process record target can't debug inferior in asynchronous "
431 "mode (target-async)."));
433 if (!gdbarch_process_record_p (target_gdbarch
))
434 error (_("Process record: the current architecture doesn't support "
435 "record function."));
437 /* Check if record target is already running. */
438 if (current_target
.to_stratum
== record_stratum
)
441 (_("Process record target already running, do you want to delete "
442 "the old record log?")))
446 /*Reset the beneath function pointers. */
447 record_beneath_to_resume
= NULL
;
448 record_beneath_to_wait
= NULL
;
449 record_beneath_to_store_registers
= NULL
;
450 record_beneath_to_xfer_partial
= NULL
;
451 record_beneath_to_insert_breakpoint
= NULL
;
452 record_beneath_to_remove_breakpoint
= NULL
;
454 /* Set the beneath function pointers. */
455 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
457 if (!record_beneath_to_resume
)
459 record_beneath_to_resume
= t
->to_resume
;
460 record_beneath_to_resume_ops
= t
;
462 if (!record_beneath_to_wait
)
464 record_beneath_to_wait
= t
->to_wait
;
465 record_beneath_to_wait_ops
= t
;
467 if (!record_beneath_to_store_registers
)
469 record_beneath_to_store_registers
= t
->to_store_registers
;
470 record_beneath_to_store_registers_ops
= t
;
472 if (!record_beneath_to_xfer_partial
)
474 record_beneath_to_xfer_partial
= t
->to_xfer_partial
;
475 record_beneath_to_xfer_partial_ops
= t
;
477 if (!record_beneath_to_insert_breakpoint
)
478 record_beneath_to_insert_breakpoint
= t
->to_insert_breakpoint
;
479 if (!record_beneath_to_remove_breakpoint
)
480 record_beneath_to_remove_breakpoint
= t
->to_remove_breakpoint
;
482 if (!record_beneath_to_resume
)
483 error (_("Process record can't get to_resume."));
484 if (!record_beneath_to_wait
)
485 error (_("Process record can't get to_wait."));
486 if (!record_beneath_to_store_registers
)
487 error (_("Process record can't get to_store_registers."));
488 if (!record_beneath_to_xfer_partial
)
489 error (_("Process record can't get to_xfer_partial."));
490 if (!record_beneath_to_insert_breakpoint
)
491 error (_("Process record can't get to_insert_breakpoint."));
492 if (!record_beneath_to_remove_breakpoint
)
493 error (_("Process record can't get to_remove_breakpoint."));
495 push_target (&record_ops
);
499 record_list
= &record_first
;
500 record_list
->next
= NULL
;
504 record_close (int quitting
)
507 fprintf_unfiltered (gdb_stdlog
, "Process record: record_close\n");
509 record_list_release (record_list
);
512 static int record_resume_step
= 0;
513 static enum target_signal record_resume_siggnal
;
514 static int record_resume_error
;
517 record_resume (struct target_ops
*ops
, ptid_t ptid
, int step
,
518 enum target_signal siggnal
)
520 record_resume_step
= step
;
521 record_resume_siggnal
= siggnal
;
523 if (!RECORD_IS_REPLAY
)
525 if (do_record_message (get_current_regcache ()))
527 record_resume_error
= 0;
531 record_resume_error
= 1;
534 record_beneath_to_resume (record_beneath_to_resume_ops
, ptid
, 1,
539 static int record_get_sig
= 0;
542 record_sig_handler (int signo
)
545 fprintf_unfiltered (gdb_stdlog
, "Process record: get a signal\n");
547 /* It will break the running inferior in replay mode. */
548 record_resume_step
= 1;
550 /* It will let record_wait set inferior status to get the signal
556 record_wait_cleanups (void *ignore
)
558 if (execution_direction
== EXEC_REVERSE
)
560 if (record_list
->next
)
561 record_list
= record_list
->next
;
564 record_list
= record_list
->prev
;
567 /* In replay mode, this function examines the recorded log and
568 determines where to stop. */
571 record_wait (struct target_ops
*ops
,
572 ptid_t ptid
, struct target_waitstatus
*status
,
575 struct cleanup
*set_cleanups
= record_gdb_operation_disable_set ();
578 fprintf_unfiltered (gdb_stdlog
,
579 "Process record: record_wait "
580 "record_resume_step = %d\n",
583 if (!RECORD_IS_REPLAY
)
585 if (record_resume_error
)
587 /* If record_resume get error, return directly. */
588 status
->kind
= TARGET_WAITKIND_STOPPED
;
589 status
->value
.sig
= TARGET_SIGNAL_ABRT
;
590 return inferior_ptid
;
593 if (record_resume_step
)
595 /* This is a single step. */
596 return record_beneath_to_wait (record_beneath_to_wait_ops
,
601 /* This is not a single step. */
607 ret
= record_beneath_to_wait (record_beneath_to_wait_ops
,
610 if (status
->kind
== TARGET_WAITKIND_STOPPED
611 && status
->value
.sig
== TARGET_SIGNAL_TRAP
)
613 /* Check if there is a breakpoint. */
614 registers_changed ();
615 tmp_pc
= regcache_read_pc (get_current_regcache ());
616 if (breakpoint_inserted_here_p (tmp_pc
))
618 /* There is a breakpoint. */
619 CORE_ADDR decr_pc_after_break
=
620 gdbarch_decr_pc_after_break
621 (get_regcache_arch (get_current_regcache ()));
622 if (decr_pc_after_break
)
624 regcache_write_pc (get_thread_regcache (ret
),
625 tmp_pc
+ decr_pc_after_break
);
630 /* There is not a breakpoint. */
631 if (!do_record_message (get_current_regcache ()))
635 record_beneath_to_resume (record_beneath_to_resume_ops
,
637 record_resume_siggnal
);
642 /* The inferior is broken by a breakpoint or a signal. */
651 struct regcache
*regcache
= get_current_regcache ();
652 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
653 int continue_flag
= 1;
654 int first_record_end
= 1;
655 struct cleanup
*old_cleanups
= make_cleanup (record_wait_cleanups
, 0);
658 status
->kind
= TARGET_WAITKIND_STOPPED
;
660 /* Check breakpoint when forward execute. */
661 if (execution_direction
== EXEC_FORWARD
)
663 tmp_pc
= regcache_read_pc (regcache
);
664 if (breakpoint_inserted_here_p (tmp_pc
))
667 fprintf_unfiltered (gdb_stdlog
,
668 "Process record: break at %s.\n",
669 paddress (gdbarch
, tmp_pc
));
670 if (gdbarch_decr_pc_after_break (gdbarch
)
671 && !record_resume_step
)
672 regcache_write_pc (regcache
,
674 gdbarch_decr_pc_after_break (gdbarch
));
680 signal (SIGINT
, record_sig_handler
);
681 /* If GDB is in terminal_inferior mode, it will not get the signal.
682 And in GDB replay mode, GDB doesn't need to be in terminal_inferior
683 mode, because inferior will not executed.
684 Then set it to terminal_ours to make GDB get the signal. */
685 target_terminal_ours ();
687 /* In EXEC_FORWARD mode, record_list points to the tail of prev
689 if (execution_direction
== EXEC_FORWARD
&& record_list
->next
)
690 record_list
= record_list
->next
;
692 /* Loop over the record_list, looking for the next place to
696 /* Check for beginning and end of log. */
697 if (execution_direction
== EXEC_REVERSE
698 && record_list
== &record_first
)
700 /* Hit beginning of record log in reverse. */
701 status
->kind
= TARGET_WAITKIND_NO_HISTORY
;
704 if (execution_direction
!= EXEC_REVERSE
&& !record_list
->next
)
706 /* Hit end of record log going forward. */
707 status
->kind
= TARGET_WAITKIND_NO_HISTORY
;
711 /* Set ptid, register and memory according to record_list. */
712 if (record_list
->type
== record_reg
)
715 gdb_byte reg
[MAX_REGISTER_SIZE
];
716 if (record_debug
> 1)
717 fprintf_unfiltered (gdb_stdlog
,
718 "Process record: record_reg %s to "
719 "inferior num = %d.\n",
720 host_address_to_string (record_list
),
721 record_list
->u
.reg
.num
);
722 regcache_cooked_read (regcache
, record_list
->u
.reg
.num
, reg
);
723 regcache_cooked_write (regcache
, record_list
->u
.reg
.num
,
724 record_list
->u
.reg
.val
);
725 memcpy (record_list
->u
.reg
.val
, reg
, MAX_REGISTER_SIZE
);
727 else if (record_list
->type
== record_mem
)
730 gdb_byte
*mem
= alloca (record_list
->u
.mem
.len
);
731 if (record_debug
> 1)
732 fprintf_unfiltered (gdb_stdlog
,
733 "Process record: record_mem %s to "
734 "inferior addr = %s len = %d.\n",
735 host_address_to_string (record_list
),
736 paddress (gdbarch
, record_list
->u
.mem
.addr
),
737 record_list
->u
.mem
.len
);
739 if (target_read_memory
740 (record_list
->u
.mem
.addr
, mem
, record_list
->u
.mem
.len
))
741 error (_("Process record: error reading memory at "
742 "addr = %s len = %d."),
743 paddress (gdbarch
, record_list
->u
.mem
.addr
),
744 record_list
->u
.mem
.len
);
746 if (target_write_memory
747 (record_list
->u
.mem
.addr
, record_list
->u
.mem
.val
,
748 record_list
->u
.mem
.len
))
750 ("Process record: error writing memory at "
751 "addr = %s len = %d."),
752 paddress (gdbarch
, record_list
->u
.mem
.addr
),
753 record_list
->u
.mem
.len
);
755 memcpy (record_list
->u
.mem
.val
, mem
, record_list
->u
.mem
.len
);
759 if (record_debug
> 1)
760 fprintf_unfiltered (gdb_stdlog
,
761 "Process record: record_end %s to "
763 host_address_to_string (record_list
));
765 if (first_record_end
&& execution_direction
== EXEC_REVERSE
)
767 /* When reverse excute, the first record_end is the part of
768 current instruction. */
769 first_record_end
= 0;
773 /* In EXEC_REVERSE mode, this is the record_end of prev
775 In EXEC_FORWARD mode, this is the record_end of current
778 if (record_resume_step
)
780 if (record_debug
> 1)
781 fprintf_unfiltered (gdb_stdlog
,
782 "Process record: step.\n");
786 /* check breakpoint */
787 tmp_pc
= regcache_read_pc (regcache
);
788 if (breakpoint_inserted_here_p (tmp_pc
))
791 fprintf_unfiltered (gdb_stdlog
,
792 "Process record: break "
794 paddress (gdbarch
, tmp_pc
));
795 if (gdbarch_decr_pc_after_break (gdbarch
)
796 && execution_direction
== EXEC_FORWARD
797 && !record_resume_step
)
798 regcache_write_pc (regcache
,
800 gdbarch_decr_pc_after_break (gdbarch
));
808 if (execution_direction
== EXEC_REVERSE
)
810 if (record_list
->prev
)
811 record_list
= record_list
->prev
;
815 if (record_list
->next
)
816 record_list
= record_list
->next
;
820 while (continue_flag
);
822 signal (SIGINT
, handle_sigint
);
826 status
->value
.sig
= TARGET_SIGNAL_INT
;
828 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
830 discard_cleanups (old_cleanups
);
833 do_cleanups (set_cleanups
);
834 return inferior_ptid
;
838 record_disconnect (struct target_ops
*target
, char *args
, int from_tty
)
841 fprintf_unfiltered (gdb_stdlog
, "Process record: record_disconnect\n");
843 unpush_target (&record_ops
);
844 target_disconnect (args
, from_tty
);
848 record_detach (struct target_ops
*ops
, char *args
, int from_tty
)
851 fprintf_unfiltered (gdb_stdlog
, "Process record: record_detach\n");
853 unpush_target (&record_ops
);
854 target_detach (args
, from_tty
);
858 record_mourn_inferior (struct target_ops
*ops
)
861 fprintf_unfiltered (gdb_stdlog
, "Process record: "
862 "record_mourn_inferior\n");
864 unpush_target (&record_ops
);
865 target_mourn_inferior ();
868 /* Close process record target before killing the inferior process. */
871 record_kill (struct target_ops
*ops
)
874 fprintf_unfiltered (gdb_stdlog
, "Process record: record_kill\n");
876 unpush_target (&record_ops
);
880 /* Record registers change (by user or by GDB) to list as an instruction. */
883 record_registers_change (struct regcache
*regcache
, int regnum
)
885 /* Check record_insn_num. */
886 record_check_insn_num (0);
888 record_arch_list_head
= NULL
;
889 record_arch_list_tail
= NULL
;
894 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
896 if (record_arch_list_add_reg (regcache
, i
))
898 record_list_release (record_arch_list_tail
);
899 error (_("Process record: failed to record execution log."));
905 if (record_arch_list_add_reg (regcache
, regnum
))
907 record_list_release (record_arch_list_tail
);
908 error (_("Process record: failed to record execution log."));
911 if (record_arch_list_add_end ())
913 record_list_release (record_arch_list_tail
);
914 error (_("Process record: failed to record execution log."));
916 record_list
->next
= record_arch_list_head
;
917 record_arch_list_head
->prev
= record_list
;
918 record_list
= record_arch_list_tail
;
920 if (record_insn_num
== record_insn_max_num
&& record_insn_max_num
)
921 record_list_release_first ();
927 record_store_registers (struct target_ops
*ops
, struct regcache
*regcache
,
930 if (!record_gdb_operation_disable
)
932 if (RECORD_IS_REPLAY
)
935 struct cleanup
*old_cleanups
;
937 /* Let user choose if he wants to write register or not. */
940 nquery (_("Because GDB is in replay mode, changing the "
941 "value of a register will make the execution "
942 "log unusable from this point onward. "
943 "Change all registers?"));
946 nquery (_("Because GDB is in replay mode, changing the value "
947 "of a register will make the execution log unusable "
948 "from this point onward. Change register %s?"),
949 gdbarch_register_name (get_regcache_arch (regcache
),
954 /* Invalidate the value of regcache that was set in function
955 "regcache_raw_write". */
960 i
< gdbarch_num_regs (get_regcache_arch (regcache
));
962 regcache_invalidate (regcache
, i
);
965 regcache_invalidate (regcache
, regno
);
967 error (_("Process record canceled the operation."));
970 /* Destroy the record from here forward. */
971 record_list_release_next ();
974 record_registers_change (regcache
, regno
);
976 record_beneath_to_store_registers (record_beneath_to_store_registers_ops
,
980 /* Behavior is conditional on RECORD_IS_REPLAY.
981 In replay mode, we cannot write memory unles we are willing to
982 invalidate the record/replay log from this point forward. */
985 record_xfer_partial (struct target_ops
*ops
, enum target_object object
,
986 const char *annex
, gdb_byte
*readbuf
,
987 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
989 if (!record_gdb_operation_disable
990 && (object
== TARGET_OBJECT_MEMORY
991 || object
== TARGET_OBJECT_RAW_MEMORY
) && writebuf
)
993 if (RECORD_IS_REPLAY
)
995 /* Let user choose if he wants to write memory or not. */
996 if (!nquery (_("Because GDB is in replay mode, writing to memory "
997 "will make the execution log unusable from this "
998 "point onward. Write memory at address %s?"),
999 paddress (target_gdbarch
, offset
)))
1002 /* Destroy the record from here forward. */
1003 record_list_release_next ();
1006 /* Check record_insn_num */
1007 record_check_insn_num (0);
1009 /* Record registers change to list as an instruction. */
1010 record_arch_list_head
= NULL
;
1011 record_arch_list_tail
= NULL
;
1012 if (record_arch_list_add_mem (offset
, len
))
1014 record_list_release (record_arch_list_tail
);
1016 fprintf_unfiltered (gdb_stdlog
,
1017 _("Process record: failed to record "
1021 if (record_arch_list_add_end ())
1023 record_list_release (record_arch_list_tail
);
1025 fprintf_unfiltered (gdb_stdlog
,
1026 _("Process record: failed to record "
1030 record_list
->next
= record_arch_list_head
;
1031 record_arch_list_head
->prev
= record_list
;
1032 record_list
= record_arch_list_tail
;
1034 if (record_insn_num
== record_insn_max_num
&& record_insn_max_num
)
1035 record_list_release_first ();
1040 return record_beneath_to_xfer_partial (record_beneath_to_xfer_partial_ops
,
1041 object
, annex
, readbuf
, writebuf
,
1045 /* Behavior is conditional on RECORD_IS_REPLAY.
1046 We will not actually insert or remove breakpoints when replaying,
1047 nor when recording. */
1050 record_insert_breakpoint (struct gdbarch
*gdbarch
,
1051 struct bp_target_info
*bp_tgt
)
1053 if (!RECORD_IS_REPLAY
)
1055 struct cleanup
*old_cleanups
= record_gdb_operation_disable_set ();
1056 int ret
= record_beneath_to_insert_breakpoint (gdbarch
, bp_tgt
);
1058 do_cleanups (old_cleanups
);
1067 record_remove_breakpoint (struct gdbarch
*gdbarch
,
1068 struct bp_target_info
*bp_tgt
)
1070 if (!RECORD_IS_REPLAY
)
1072 struct cleanup
*old_cleanups
= record_gdb_operation_disable_set ();
1073 int ret
= record_beneath_to_remove_breakpoint (gdbarch
, bp_tgt
);
1075 do_cleanups (old_cleanups
);
1084 record_can_execute_reverse (void)
1090 init_record_ops (void)
1092 record_ops
.to_shortname
= "record";
1093 record_ops
.to_longname
= "Process record and replay target";
1095 "Log program while executing and replay execution from log.";
1096 record_ops
.to_open
= record_open
;
1097 record_ops
.to_close
= record_close
;
1098 record_ops
.to_resume
= record_resume
;
1099 record_ops
.to_wait
= record_wait
;
1100 record_ops
.to_disconnect
= record_disconnect
;
1101 record_ops
.to_detach
= record_detach
;
1102 record_ops
.to_mourn_inferior
= record_mourn_inferior
;
1103 record_ops
.to_kill
= record_kill
;
1104 record_ops
.to_create_inferior
= find_default_create_inferior
;
1105 record_ops
.to_store_registers
= record_store_registers
;
1106 record_ops
.to_xfer_partial
= record_xfer_partial
;
1107 record_ops
.to_insert_breakpoint
= record_insert_breakpoint
;
1108 record_ops
.to_remove_breakpoint
= record_remove_breakpoint
;
1109 record_ops
.to_can_execute_reverse
= record_can_execute_reverse
;
1110 record_ops
.to_stratum
= record_stratum
;
1111 record_ops
.to_magic
= OPS_MAGIC
;
1115 show_record_debug (struct ui_file
*file
, int from_tty
,
1116 struct cmd_list_element
*c
, const char *value
)
1118 fprintf_filtered (file
, _("Debugging of process record target is %s.\n"),
1122 /* Alias for "target record". */
1125 cmd_record_start (char *args
, int from_tty
)
1127 execute_command ("target record", from_tty
);
1130 /* Truncate the record log from the present point
1131 of replay until the end. */
1134 cmd_record_delete (char *args
, int from_tty
)
1136 if (current_target
.to_stratum
== record_stratum
)
1138 if (RECORD_IS_REPLAY
)
1140 if (!from_tty
|| query (_("Delete the log from this point forward "
1141 "and begin to record the running message "
1143 record_list_release_next ();
1146 printf_unfiltered (_("Already at end of record list.\n"));
1150 printf_unfiltered (_("Process record is not started.\n"));
1153 /* Implement the "stoprecord" command. */
1156 cmd_record_stop (char *args
, int from_tty
)
1158 if (current_target
.to_stratum
== record_stratum
)
1160 if (!record_list
|| !from_tty
|| query (_("Delete recorded log and "
1161 "stop recording?")))
1162 unpush_target (&record_ops
);
1165 printf_unfiltered (_("Process record is not started.\n"));
1168 /* Set upper limit of record log size. */
1171 set_record_insn_max_num (char *args
, int from_tty
, struct cmd_list_element
*c
)
1173 if (record_insn_num
> record_insn_max_num
&& record_insn_max_num
)
1175 printf_unfiltered (_("Record instructions number is bigger than "
1176 "record instructions max number. Auto delete "
1177 "the first ones?\n"));
1179 while (record_insn_num
> record_insn_max_num
)
1180 record_list_release_first ();
1184 /* Print the current index into the record log (number of insns recorded
1188 show_record_insn_number (char *ignore
, int from_tty
)
1190 printf_unfiltered (_("Record instruction number is %d.\n"),
1194 static struct cmd_list_element
*record_cmdlist
, *set_record_cmdlist
,
1195 *show_record_cmdlist
, *info_record_cmdlist
;
1198 set_record_command (char *args
, int from_tty
)
1200 printf_unfiltered (_("\
1201 \"set record\" must be followed by an apporpriate subcommand.\n"));
1202 help_list (set_record_cmdlist
, "set record ", all_commands
, gdb_stdout
);
1206 show_record_command (char *args
, int from_tty
)
1208 cmd_show_list (show_record_cmdlist
, from_tty
, "");
1212 info_record_command (char *args
, int from_tty
)
1214 cmd_show_list (info_record_cmdlist
, from_tty
, "");
1218 _initialize_record (void)
1220 /* Init record_first. */
1221 record_first
.prev
= NULL
;
1222 record_first
.next
= NULL
;
1223 record_first
.type
= record_end
;
1226 add_target (&record_ops
);
1228 add_setshow_zinteger_cmd ("record", no_class
, &record_debug
,
1229 _("Set debugging of record/replay feature."),
1230 _("Show debugging of record/replay feature."),
1231 _("When enabled, debugging output for "
1232 "record/replay feature is displayed."),
1233 NULL
, show_record_debug
, &setdebuglist
,
1236 add_prefix_cmd ("record", class_obscure
, cmd_record_start
,
1237 _("Abbreviated form of \"target record\" command."),
1238 &record_cmdlist
, "record ", 0, &cmdlist
);
1239 add_com_alias ("rec", "record", class_obscure
, 1);
1240 add_prefix_cmd ("record", class_support
, set_record_command
,
1241 _("Set record options"), &set_record_cmdlist
,
1242 "set record ", 0, &setlist
);
1243 add_alias_cmd ("rec", "record", class_obscure
, 1, &setlist
);
1244 add_prefix_cmd ("record", class_support
, show_record_command
,
1245 _("Show record options"), &show_record_cmdlist
,
1246 "show record ", 0, &showlist
);
1247 add_alias_cmd ("rec", "record", class_obscure
, 1, &showlist
);
1248 add_prefix_cmd ("record", class_support
, info_record_command
,
1249 _("Info record options"), &info_record_cmdlist
,
1250 "info record ", 0, &infolist
);
1251 add_alias_cmd ("rec", "record", class_obscure
, 1, &infolist
);
1254 add_cmd ("delete", class_obscure
, cmd_record_delete
,
1255 _("Delete the rest of execution log and start recording it anew."),
1257 add_alias_cmd ("d", "delete", class_obscure
, 1, &record_cmdlist
);
1258 add_alias_cmd ("del", "delete", class_obscure
, 1, &record_cmdlist
);
1260 add_cmd ("stop", class_obscure
, cmd_record_stop
,
1261 _("Stop the record/replay target."),
1263 add_alias_cmd ("s", "stop", class_obscure
, 1, &record_cmdlist
);
1265 /* Record instructions number limit command. */
1266 add_setshow_boolean_cmd ("stop-at-limit", no_class
,
1267 &record_stop_at_limit
, _("\
1268 Set whether record/replay stops when record/replay buffer becomes full."), _("\
1269 Show whether record/replay stops when record/replay buffer becomes full."), _("\
1271 When ON, if the record/replay buffer becomes full, ask user what to do.\n\
1272 When OFF, if the record/replay buffer becomes full,\n\
1273 delete the oldest recorded instruction to make room for each new one."),
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 stored in the\n\
1281 record/replay buffer. Zero means unlimited. Default is 200000."),
1282 set_record_insn_max_num
,
1283 NULL
, &set_record_cmdlist
, &show_record_cmdlist
);
1284 add_cmd ("insn-number", class_obscure
, show_record_insn_number
,
1285 _("Show the current number of instructions in the "
1286 "record/replay buffer."), &info_record_cmdlist
);