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 structs of the process record functionality.
37 A 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 have a struct record_entry ("record_end") that
40 indicates that this is the last struct record_entry of this
43 Each struct record_entry is linked to "record_list" by "prev" and
46 struct record_reg_entry
52 struct record_mem_entry
56 /* Set this flag if target memory for this entry
57 can no longer be accessed. */
58 int mem_entry_not_accessible
;
62 struct record_end_entry
64 enum target_signal sigval
;
76 struct record_entry
*prev
;
77 struct record_entry
*next
;
78 enum record_type type
;
82 struct record_reg_entry reg
;
84 struct record_mem_entry mem
;
86 struct record_end_entry end
;
90 /* This is the debug switch for process record. */
93 /* These list is for execution log. */
94 static struct record_entry record_first
;
95 static struct record_entry
*record_list
= &record_first
;
96 static struct record_entry
*record_arch_list_head
= NULL
;
97 static struct record_entry
*record_arch_list_tail
= NULL
;
99 /* 1 ask user. 0 auto delete the last struct record_entry. */
100 static int record_stop_at_limit
= 1;
101 static int record_insn_max_num
= DEFAULT_RECORD_INSN_MAX_NUM
;
102 static int record_insn_num
= 0;
104 /* The target_ops of process record. */
105 static struct target_ops record_ops
;
107 /* The beneath function pointers. */
108 static struct target_ops
*record_beneath_to_resume_ops
;
109 static void (*record_beneath_to_resume
) (struct target_ops
*, ptid_t
, int,
111 static struct target_ops
*record_beneath_to_wait_ops
;
112 static ptid_t (*record_beneath_to_wait
) (struct target_ops
*, ptid_t
,
113 struct target_waitstatus
*,
115 static struct target_ops
*record_beneath_to_store_registers_ops
;
116 static void (*record_beneath_to_store_registers
) (struct target_ops
*,
119 static struct target_ops
*record_beneath_to_xfer_partial_ops
;
120 static LONGEST (*record_beneath_to_xfer_partial
) (struct target_ops
*ops
,
121 enum target_object object
,
124 const gdb_byte
*writebuf
,
127 static int (*record_beneath_to_insert_breakpoint
) (struct gdbarch
*,
128 struct bp_target_info
*);
129 static int (*record_beneath_to_remove_breakpoint
) (struct gdbarch
*,
130 struct bp_target_info
*);
133 record_list_release (struct record_entry
*rec
)
135 struct record_entry
*tmp
;
149 if (tmp
->type
== record_reg
)
150 xfree (tmp
->u
.reg
.val
);
151 else if (tmp
->type
== record_mem
)
152 xfree (tmp
->u
.mem
.val
);
156 if (rec
!= &record_first
)
161 record_list_release_next (void)
163 struct record_entry
*rec
= record_list
;
164 struct record_entry
*tmp
= rec
->next
;
169 if (tmp
->type
== record_end
)
171 else if (tmp
->type
== record_reg
)
172 xfree (tmp
->u
.reg
.val
);
173 else if (tmp
->type
== record_mem
)
174 xfree (tmp
->u
.mem
.val
);
181 record_list_release_first (void)
183 struct record_entry
*tmp
= NULL
;
184 enum record_type type
;
186 if (!record_first
.next
)
191 type
= record_first
.next
->type
;
193 if (type
== record_reg
)
194 xfree (record_first
.next
->u
.reg
.val
);
195 else if (type
== record_mem
)
196 xfree (record_first
.next
->u
.mem
.val
);
197 tmp
= record_first
.next
;
198 record_first
.next
= tmp
->next
;
201 if (!record_first
.next
)
203 gdb_assert (record_insn_num
== 1);
207 record_first
.next
->prev
= &record_first
;
209 if (type
== record_end
)
216 /* Add a struct record_entry to record_arch_list. */
219 record_arch_list_add (struct record_entry
*rec
)
221 if (record_debug
> 1)
222 fprintf_unfiltered (gdb_stdlog
,
223 "Process record: record_arch_list_add %s.\n",
224 host_address_to_string (rec
));
226 if (record_arch_list_tail
)
228 record_arch_list_tail
->next
= rec
;
229 rec
->prev
= record_arch_list_tail
;
230 record_arch_list_tail
= rec
;
234 record_arch_list_head
= rec
;
235 record_arch_list_tail
= rec
;
239 /* Record the value of a register NUM to record_arch_list. */
242 record_arch_list_add_reg (struct regcache
*regcache
, int num
)
244 struct record_entry
*rec
;
246 if (record_debug
> 1)
247 fprintf_unfiltered (gdb_stdlog
,
248 "Process record: add register num = %d to "
252 rec
= (struct record_entry
*) xmalloc (sizeof (struct record_entry
));
253 rec
->u
.reg
.val
= (gdb_byte
*) xmalloc (MAX_REGISTER_SIZE
);
256 rec
->type
= record_reg
;
257 rec
->u
.reg
.num
= num
;
259 regcache_raw_read (regcache
, num
, rec
->u
.reg
.val
);
261 record_arch_list_add (rec
);
266 /* Record the value of a region of memory whose address is ADDR and
267 length is LEN to record_arch_list. */
270 record_arch_list_add_mem (CORE_ADDR addr
, int len
)
272 struct record_entry
*rec
;
274 if (record_debug
> 1)
275 fprintf_unfiltered (gdb_stdlog
,
276 "Process record: add mem addr = %s len = %d to "
278 paddress (target_gdbarch
, addr
), len
);
283 rec
= (struct record_entry
*) xmalloc (sizeof (struct record_entry
));
284 rec
->u
.mem
.val
= (gdb_byte
*) xmalloc (len
);
287 rec
->type
= record_mem
;
288 rec
->u
.mem
.addr
= addr
;
289 rec
->u
.mem
.len
= len
;
290 rec
->u
.mem
.mem_entry_not_accessible
= 0;
292 if (target_read_memory (addr
, rec
->u
.mem
.val
, len
))
295 fprintf_unfiltered (gdb_stdlog
,
296 "Process record: error reading memory at "
297 "addr = %s len = %d.\n",
298 paddress (target_gdbarch
, addr
), len
);
299 xfree (rec
->u
.mem
.val
);
304 record_arch_list_add (rec
);
309 /* Add a record_end type struct record_entry to record_arch_list. */
312 record_arch_list_add_end (void)
314 struct record_entry
*rec
;
316 if (record_debug
> 1)
317 fprintf_unfiltered (gdb_stdlog
,
318 "Process record: add end to arch list.\n");
320 rec
= (struct record_entry
*) xmalloc (sizeof (struct record_entry
));
323 rec
->type
= record_end
;
324 rec
->u
.end
.sigval
= TARGET_SIGNAL_0
;
326 record_arch_list_add (rec
);
332 record_check_insn_num (int set_terminal
)
334 if (record_insn_max_num
)
336 gdb_assert (record_insn_num
<= record_insn_max_num
);
337 if (record_insn_num
== record_insn_max_num
)
339 /* Ask user what to do. */
340 if (record_stop_at_limit
)
344 target_terminal_ours ();
345 q
= yquery (_("Do you want to auto delete previous execution "
346 "log entries when record/replay buffer becomes "
347 "full (record stop-at-limit)?"));
349 target_terminal_inferior ();
351 record_stop_at_limit
= 0;
353 error (_("Process record: inferior program stopped."));
359 /* Before inferior step (when GDB record the running message, inferior
360 only can step), GDB will call this function to record the values to
361 record_list. This function will call gdbarch_process_record to
362 record the running message of inferior and set them to
363 record_arch_list, and add it to record_list. */
366 record_message_cleanups (void *ignore
)
368 record_list_release (record_arch_list_tail
);
371 struct record_message_args
{
372 struct regcache
*regcache
;
373 enum target_signal signal
;
377 record_message (void *args
)
380 struct record_message_args
*myargs
= args
;
381 struct gdbarch
*gdbarch
= get_regcache_arch (myargs
->regcache
);
382 struct cleanup
*old_cleanups
= make_cleanup (record_message_cleanups
, 0);
384 record_arch_list_head
= NULL
;
385 record_arch_list_tail
= NULL
;
387 /* Check record_insn_num. */
388 record_check_insn_num (1);
390 /* If gdb sends a signal value to target_resume,
391 save it in the 'end' field of the previous instruction.
393 Maybe process record should record what really happened,
394 rather than what gdb pretends has happened.
396 So if Linux delivered the signal to the child process during
397 the record mode, we will record it and deliver it again in
400 If user says "ignore this signal" during the record mode, then
401 it will be ignored again during the replay mode (no matter if
402 the user says something different, like "deliver this signal"
403 during the replay mode).
405 User should understand that nothing he does during the replay
406 mode will change the behavior of the child. If he tries,
407 then that is a user error.
409 But we should still deliver the signal to gdb during the replay,
410 if we delivered it during the recording. Therefore we should
411 record the signal during record_wait, not record_resume. */
412 if (record_list
!= &record_first
) /* FIXME better way to check */
414 gdb_assert (record_list
->type
== record_end
);
415 record_list
->u
.end
.sigval
= myargs
->signal
;
418 if (myargs
->signal
== TARGET_SIGNAL_0
419 || !gdbarch_process_record_signal_p (gdbarch
))
420 ret
= gdbarch_process_record (gdbarch
,
422 regcache_read_pc (myargs
->regcache
));
424 ret
= gdbarch_process_record_signal (gdbarch
,
429 error (_("Process record: inferior program stopped."));
431 error (_("Process record: failed to record execution log."));
433 discard_cleanups (old_cleanups
);
435 record_list
->next
= record_arch_list_head
;
436 record_arch_list_head
->prev
= record_list
;
437 record_list
= record_arch_list_tail
;
439 if (record_insn_num
== record_insn_max_num
&& record_insn_max_num
)
440 record_list_release_first ();
448 do_record_message (struct regcache
*regcache
,
449 enum target_signal signal
)
451 struct record_message_args args
;
453 args
.regcache
= regcache
;
454 args
.signal
= signal
;
455 return catch_errors (record_message
, &args
, NULL
, RETURN_MASK_ALL
);
458 /* Set to 1 if record_store_registers and record_xfer_partial
459 doesn't need record. */
461 static int record_gdb_operation_disable
= 0;
464 record_gdb_operation_disable_set (void)
466 struct cleanup
*old_cleanups
= NULL
;
469 make_cleanup_restore_integer (&record_gdb_operation_disable
);
470 record_gdb_operation_disable
= 1;
476 record_open (char *name
, int from_tty
)
478 struct target_ops
*t
;
481 fprintf_unfiltered (gdb_stdlog
, "Process record: record_open\n");
484 if (!target_has_execution
)
485 error (_("Process record: the program is not being run."));
487 error (_("Process record target can't debug inferior in non-stop mode "
489 if (target_async_permitted
)
490 error (_("Process record target can't debug inferior in asynchronous "
491 "mode (target-async)."));
493 if (!gdbarch_process_record_p (target_gdbarch
))
494 error (_("Process record: the current architecture doesn't support "
495 "record function."));
497 /* Check if record target is already running. */
498 if (current_target
.to_stratum
== record_stratum
)
499 error (_("Process record target already running. Use \"record stop\" to "
500 "stop record target first."));
502 /*Reset the beneath function pointers. */
503 record_beneath_to_resume
= NULL
;
504 record_beneath_to_wait
= NULL
;
505 record_beneath_to_store_registers
= NULL
;
506 record_beneath_to_xfer_partial
= NULL
;
507 record_beneath_to_insert_breakpoint
= NULL
;
508 record_beneath_to_remove_breakpoint
= NULL
;
510 /* Set the beneath function pointers. */
511 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
513 if (!record_beneath_to_resume
)
515 record_beneath_to_resume
= t
->to_resume
;
516 record_beneath_to_resume_ops
= t
;
518 if (!record_beneath_to_wait
)
520 record_beneath_to_wait
= t
->to_wait
;
521 record_beneath_to_wait_ops
= t
;
523 if (!record_beneath_to_store_registers
)
525 record_beneath_to_store_registers
= t
->to_store_registers
;
526 record_beneath_to_store_registers_ops
= t
;
528 if (!record_beneath_to_xfer_partial
)
530 record_beneath_to_xfer_partial
= t
->to_xfer_partial
;
531 record_beneath_to_xfer_partial_ops
= t
;
533 if (!record_beneath_to_insert_breakpoint
)
534 record_beneath_to_insert_breakpoint
= t
->to_insert_breakpoint
;
535 if (!record_beneath_to_remove_breakpoint
)
536 record_beneath_to_remove_breakpoint
= t
->to_remove_breakpoint
;
538 if (!record_beneath_to_resume
)
539 error (_("Process record can't get to_resume."));
540 if (!record_beneath_to_wait
)
541 error (_("Process record can't get to_wait."));
542 if (!record_beneath_to_store_registers
)
543 error (_("Process record can't get to_store_registers."));
544 if (!record_beneath_to_xfer_partial
)
545 error (_("Process record can't get to_xfer_partial."));
546 if (!record_beneath_to_insert_breakpoint
)
547 error (_("Process record can't get to_insert_breakpoint."));
548 if (!record_beneath_to_remove_breakpoint
)
549 error (_("Process record can't get to_remove_breakpoint."));
551 push_target (&record_ops
);
555 record_list
= &record_first
;
556 record_list
->next
= NULL
;
560 record_close (int quitting
)
563 fprintf_unfiltered (gdb_stdlog
, "Process record: record_close\n");
565 record_list_release (record_list
);
568 static int record_resume_step
= 0;
569 static int record_resume_error
;
572 record_resume (struct target_ops
*ops
, ptid_t ptid
, int step
,
573 enum target_signal signal
)
575 record_resume_step
= step
;
577 if (!RECORD_IS_REPLAY
)
579 if (do_record_message (get_current_regcache (), signal
))
581 record_resume_error
= 0;
585 record_resume_error
= 1;
588 record_beneath_to_resume (record_beneath_to_resume_ops
, ptid
, 1,
593 static int record_get_sig
= 0;
596 record_sig_handler (int signo
)
599 fprintf_unfiltered (gdb_stdlog
, "Process record: get a signal\n");
601 /* It will break the running inferior in replay mode. */
602 record_resume_step
= 1;
604 /* It will let record_wait set inferior status to get the signal
610 record_wait_cleanups (void *ignore
)
612 if (execution_direction
== EXEC_REVERSE
)
614 if (record_list
->next
)
615 record_list
= record_list
->next
;
618 record_list
= record_list
->prev
;
621 /* In replay mode, this function examines the recorded log and
622 determines where to stop. */
625 record_wait (struct target_ops
*ops
,
626 ptid_t ptid
, struct target_waitstatus
*status
,
629 struct cleanup
*set_cleanups
= record_gdb_operation_disable_set ();
632 fprintf_unfiltered (gdb_stdlog
,
633 "Process record: record_wait "
634 "record_resume_step = %d\n",
637 if (!RECORD_IS_REPLAY
)
639 if (record_resume_error
)
641 /* If record_resume get error, return directly. */
642 status
->kind
= TARGET_WAITKIND_STOPPED
;
643 status
->value
.sig
= TARGET_SIGNAL_ABRT
;
644 return inferior_ptid
;
647 if (record_resume_step
)
649 /* This is a single step. */
650 return record_beneath_to_wait (record_beneath_to_wait_ops
,
651 ptid
, status
, options
);
655 /* This is not a single step. */
661 ret
= record_beneath_to_wait (record_beneath_to_wait_ops
,
662 ptid
, status
, options
);
664 /* Is this a SIGTRAP? */
665 if (status
->kind
== TARGET_WAITKIND_STOPPED
666 && status
->value
.sig
== TARGET_SIGNAL_TRAP
)
668 /* Yes -- check if there is a breakpoint. */
669 registers_changed ();
670 tmp_pc
= regcache_read_pc (get_current_regcache ());
671 if (breakpoint_inserted_here_p (tmp_pc
))
673 /* There is a breakpoint. GDB will want to stop. */
674 CORE_ADDR decr_pc_after_break
=
675 gdbarch_decr_pc_after_break
676 (get_regcache_arch (get_current_regcache ()));
677 if (decr_pc_after_break
)
679 regcache_write_pc (get_thread_regcache (ret
),
680 tmp_pc
+ decr_pc_after_break
);
685 /* There is not a breakpoint, and gdb is not
686 stepping, therefore gdb will not stop.
687 Therefore we will not return to gdb.
688 Record the insn and resume. */
689 if (!do_record_message (get_current_regcache (),
694 record_beneath_to_resume (record_beneath_to_resume_ops
,
701 /* The inferior is broken by a breakpoint or a signal. */
710 struct regcache
*regcache
= get_current_regcache ();
711 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
712 int continue_flag
= 1;
713 int first_record_end
= 1;
714 struct cleanup
*old_cleanups
= make_cleanup (record_wait_cleanups
, 0);
717 status
->kind
= TARGET_WAITKIND_STOPPED
;
719 /* Check breakpoint when forward execute. */
720 if (execution_direction
== EXEC_FORWARD
)
722 tmp_pc
= regcache_read_pc (regcache
);
723 if (breakpoint_inserted_here_p (tmp_pc
))
726 fprintf_unfiltered (gdb_stdlog
,
727 "Process record: break at %s.\n",
728 paddress (gdbarch
, tmp_pc
));
729 if (gdbarch_decr_pc_after_break (gdbarch
)
730 && !record_resume_step
)
731 regcache_write_pc (regcache
,
733 gdbarch_decr_pc_after_break (gdbarch
));
739 signal (SIGINT
, record_sig_handler
);
740 /* If GDB is in terminal_inferior mode, it will not get the signal.
741 And in GDB replay mode, GDB doesn't need to be in terminal_inferior
742 mode, because inferior will not executed.
743 Then set it to terminal_ours to make GDB get the signal. */
744 target_terminal_ours ();
746 /* In EXEC_FORWARD mode, record_list points to the tail of prev
748 if (execution_direction
== EXEC_FORWARD
&& record_list
->next
)
749 record_list
= record_list
->next
;
751 /* Loop over the record_list, looking for the next place to
755 /* Check for beginning and end of log. */
756 if (execution_direction
== EXEC_REVERSE
757 && record_list
== &record_first
)
759 /* Hit beginning of record log in reverse. */
760 status
->kind
= TARGET_WAITKIND_NO_HISTORY
;
763 if (execution_direction
!= EXEC_REVERSE
&& !record_list
->next
)
765 /* Hit end of record log going forward. */
766 status
->kind
= TARGET_WAITKIND_NO_HISTORY
;
770 /* Set ptid, register and memory according to record_list. */
771 if (record_list
->type
== record_reg
)
774 gdb_byte reg
[MAX_REGISTER_SIZE
];
775 if (record_debug
> 1)
776 fprintf_unfiltered (gdb_stdlog
,
777 "Process record: record_reg %s to "
778 "inferior num = %d.\n",
779 host_address_to_string (record_list
),
780 record_list
->u
.reg
.num
);
781 regcache_cooked_read (regcache
, record_list
->u
.reg
.num
, reg
);
782 regcache_cooked_write (regcache
, record_list
->u
.reg
.num
,
783 record_list
->u
.reg
.val
);
784 memcpy (record_list
->u
.reg
.val
, reg
, MAX_REGISTER_SIZE
);
786 else if (record_list
->type
== record_mem
)
789 /* Nothing to do if the entry is flagged not_accessible. */
790 if (!record_list
->u
.mem
.mem_entry_not_accessible
)
792 gdb_byte
*mem
= alloca (record_list
->u
.mem
.len
);
793 if (record_debug
> 1)
794 fprintf_unfiltered (gdb_stdlog
,
795 "Process record: record_mem %s to "
796 "inferior addr = %s len = %d.\n",
797 host_address_to_string (record_list
),
799 record_list
->u
.mem
.addr
),
800 record_list
->u
.mem
.len
);
802 if (target_read_memory (record_list
->u
.mem
.addr
, mem
,
803 record_list
->u
.mem
.len
))
805 if (execution_direction
!= EXEC_REVERSE
)
806 error (_("Process record: error reading memory at "
807 "addr = %s len = %d."),
808 paddress (gdbarch
, record_list
->u
.mem
.addr
),
809 record_list
->u
.mem
.len
);
812 flag entry as not_accessible. */
813 record_list
->u
.mem
.mem_entry_not_accessible
= 1;
817 if (target_write_memory (record_list
->u
.mem
.addr
,
818 record_list
->u
.mem
.val
,
819 record_list
->u
.mem
.len
))
821 if (execution_direction
!= EXEC_REVERSE
)
822 error (_("Process record: error writing memory at "
823 "addr = %s len = %d."),
824 paddress (gdbarch
, record_list
->u
.mem
.addr
),
825 record_list
->u
.mem
.len
);
828 flag entry as not_accessible. */
829 record_list
->u
.mem
.mem_entry_not_accessible
= 1;
833 memcpy (record_list
->u
.mem
.val
, mem
,
834 record_list
->u
.mem
.len
);
841 if (record_debug
> 1)
842 fprintf_unfiltered (gdb_stdlog
,
843 "Process record: record_end %s to "
845 host_address_to_string (record_list
));
847 if (first_record_end
&& execution_direction
== EXEC_REVERSE
)
849 /* When reverse excute, the first record_end is the part of
850 current instruction. */
851 first_record_end
= 0;
855 /* In EXEC_REVERSE mode, this is the record_end of prev
857 In EXEC_FORWARD mode, this is the record_end of current
860 if (record_resume_step
)
862 if (record_debug
> 1)
863 fprintf_unfiltered (gdb_stdlog
,
864 "Process record: step.\n");
868 /* check breakpoint */
869 tmp_pc
= regcache_read_pc (regcache
);
870 if (breakpoint_inserted_here_p (tmp_pc
))
873 fprintf_unfiltered (gdb_stdlog
,
874 "Process record: break "
876 paddress (gdbarch
, tmp_pc
));
877 if (gdbarch_decr_pc_after_break (gdbarch
)
878 && execution_direction
== EXEC_FORWARD
879 && !record_resume_step
)
880 regcache_write_pc (regcache
,
882 gdbarch_decr_pc_after_break (gdbarch
));
885 /* Check target signal */
886 if (record_list
->u
.end
.sigval
!= TARGET_SIGNAL_0
)
887 /* FIXME: better way to check */
894 if (execution_direction
== EXEC_REVERSE
)
896 if (record_list
->prev
)
897 record_list
= record_list
->prev
;
901 if (record_list
->next
)
902 record_list
= record_list
->next
;
906 while (continue_flag
);
908 signal (SIGINT
, handle_sigint
);
912 status
->value
.sig
= TARGET_SIGNAL_INT
;
913 else if (record_list
->u
.end
.sigval
!= TARGET_SIGNAL_0
)
914 /* FIXME: better way to check */
915 status
->value
.sig
= record_list
->u
.end
.sigval
;
917 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
919 discard_cleanups (old_cleanups
);
922 do_cleanups (set_cleanups
);
923 return inferior_ptid
;
927 record_disconnect (struct target_ops
*target
, char *args
, int from_tty
)
930 fprintf_unfiltered (gdb_stdlog
, "Process record: record_disconnect\n");
932 unpush_target (&record_ops
);
933 target_disconnect (args
, from_tty
);
937 record_detach (struct target_ops
*ops
, char *args
, int from_tty
)
940 fprintf_unfiltered (gdb_stdlog
, "Process record: record_detach\n");
942 unpush_target (&record_ops
);
943 target_detach (args
, from_tty
);
947 record_mourn_inferior (struct target_ops
*ops
)
950 fprintf_unfiltered (gdb_stdlog
, "Process record: "
951 "record_mourn_inferior\n");
953 unpush_target (&record_ops
);
954 target_mourn_inferior ();
957 /* Close process record target before killing the inferior process. */
960 record_kill (struct target_ops
*ops
)
963 fprintf_unfiltered (gdb_stdlog
, "Process record: record_kill\n");
965 unpush_target (&record_ops
);
969 /* Record registers change (by user or by GDB) to list as an instruction. */
972 record_registers_change (struct regcache
*regcache
, int regnum
)
974 /* Check record_insn_num. */
975 record_check_insn_num (0);
977 record_arch_list_head
= NULL
;
978 record_arch_list_tail
= NULL
;
983 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
985 if (record_arch_list_add_reg (regcache
, i
))
987 record_list_release (record_arch_list_tail
);
988 error (_("Process record: failed to record execution log."));
994 if (record_arch_list_add_reg (regcache
, regnum
))
996 record_list_release (record_arch_list_tail
);
997 error (_("Process record: failed to record execution log."));
1000 if (record_arch_list_add_end ())
1002 record_list_release (record_arch_list_tail
);
1003 error (_("Process record: failed to record execution log."));
1005 record_list
->next
= record_arch_list_head
;
1006 record_arch_list_head
->prev
= record_list
;
1007 record_list
= record_arch_list_tail
;
1009 if (record_insn_num
== record_insn_max_num
&& record_insn_max_num
)
1010 record_list_release_first ();
1016 record_store_registers (struct target_ops
*ops
, struct regcache
*regcache
,
1019 if (!record_gdb_operation_disable
)
1021 if (RECORD_IS_REPLAY
)
1025 /* Let user choose if he wants to write register or not. */
1028 query (_("Because GDB is in replay mode, changing the "
1029 "value of a register will make the execution "
1030 "log unusable from this point onward. "
1031 "Change all registers?"));
1034 query (_("Because GDB is in replay mode, changing the value "
1035 "of a register will make the execution log unusable "
1036 "from this point onward. Change register %s?"),
1037 gdbarch_register_name (get_regcache_arch (regcache
),
1042 /* Invalidate the value of regcache that was set in function
1043 "regcache_raw_write". */
1048 i
< gdbarch_num_regs (get_regcache_arch (regcache
));
1050 regcache_invalidate (regcache
, i
);
1053 regcache_invalidate (regcache
, regno
);
1055 error (_("Process record canceled the operation."));
1058 /* Destroy the record from here forward. */
1059 record_list_release_next ();
1062 record_registers_change (regcache
, regno
);
1064 record_beneath_to_store_registers (record_beneath_to_store_registers_ops
,
1068 /* Behavior is conditional on RECORD_IS_REPLAY.
1069 In replay mode, we cannot write memory unles we are willing to
1070 invalidate the record/replay log from this point forward. */
1073 record_xfer_partial (struct target_ops
*ops
, enum target_object object
,
1074 const char *annex
, gdb_byte
*readbuf
,
1075 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
1077 if (!record_gdb_operation_disable
1078 && (object
== TARGET_OBJECT_MEMORY
1079 || object
== TARGET_OBJECT_RAW_MEMORY
) && writebuf
)
1081 if (RECORD_IS_REPLAY
)
1083 /* Let user choose if he wants to write memory or not. */
1084 if (!query (_("Because GDB is in replay mode, writing to memory "
1085 "will make the execution log unusable from this "
1086 "point onward. Write memory at address %s?"),
1087 paddress (target_gdbarch
, offset
)))
1088 error (_("Process record canceled the operation."));
1090 /* Destroy the record from here forward. */
1091 record_list_release_next ();
1094 /* Check record_insn_num */
1095 record_check_insn_num (0);
1097 /* Record registers change to list as an instruction. */
1098 record_arch_list_head
= NULL
;
1099 record_arch_list_tail
= NULL
;
1100 if (record_arch_list_add_mem (offset
, len
))
1102 record_list_release (record_arch_list_tail
);
1104 fprintf_unfiltered (gdb_stdlog
,
1105 _("Process record: failed to record "
1109 if (record_arch_list_add_end ())
1111 record_list_release (record_arch_list_tail
);
1113 fprintf_unfiltered (gdb_stdlog
,
1114 _("Process record: failed to record "
1118 record_list
->next
= record_arch_list_head
;
1119 record_arch_list_head
->prev
= record_list
;
1120 record_list
= record_arch_list_tail
;
1122 if (record_insn_num
== record_insn_max_num
&& record_insn_max_num
)
1123 record_list_release_first ();
1128 return record_beneath_to_xfer_partial (record_beneath_to_xfer_partial_ops
,
1129 object
, annex
, readbuf
, writebuf
,
1133 /* Behavior is conditional on RECORD_IS_REPLAY.
1134 We will not actually insert or remove breakpoints when replaying,
1135 nor when recording. */
1138 record_insert_breakpoint (struct gdbarch
*gdbarch
,
1139 struct bp_target_info
*bp_tgt
)
1141 if (!RECORD_IS_REPLAY
)
1143 struct cleanup
*old_cleanups
= record_gdb_operation_disable_set ();
1144 int ret
= record_beneath_to_insert_breakpoint (gdbarch
, bp_tgt
);
1146 do_cleanups (old_cleanups
);
1155 record_remove_breakpoint (struct gdbarch
*gdbarch
,
1156 struct bp_target_info
*bp_tgt
)
1158 if (!RECORD_IS_REPLAY
)
1160 struct cleanup
*old_cleanups
= record_gdb_operation_disable_set ();
1161 int ret
= record_beneath_to_remove_breakpoint (gdbarch
, bp_tgt
);
1163 do_cleanups (old_cleanups
);
1172 record_can_execute_reverse (void)
1178 init_record_ops (void)
1180 record_ops
.to_shortname
= "record";
1181 record_ops
.to_longname
= "Process record and replay target";
1183 "Log program while executing and replay execution from log.";
1184 record_ops
.to_open
= record_open
;
1185 record_ops
.to_close
= record_close
;
1186 record_ops
.to_resume
= record_resume
;
1187 record_ops
.to_wait
= record_wait
;
1188 record_ops
.to_disconnect
= record_disconnect
;
1189 record_ops
.to_detach
= record_detach
;
1190 record_ops
.to_mourn_inferior
= record_mourn_inferior
;
1191 record_ops
.to_kill
= record_kill
;
1192 record_ops
.to_create_inferior
= find_default_create_inferior
;
1193 record_ops
.to_store_registers
= record_store_registers
;
1194 record_ops
.to_xfer_partial
= record_xfer_partial
;
1195 record_ops
.to_insert_breakpoint
= record_insert_breakpoint
;
1196 record_ops
.to_remove_breakpoint
= record_remove_breakpoint
;
1197 record_ops
.to_can_execute_reverse
= record_can_execute_reverse
;
1198 record_ops
.to_stratum
= record_stratum
;
1199 record_ops
.to_magic
= OPS_MAGIC
;
1203 show_record_debug (struct ui_file
*file
, int from_tty
,
1204 struct cmd_list_element
*c
, const char *value
)
1206 fprintf_filtered (file
, _("Debugging of process record target is %s.\n"),
1210 /* Alias for "target record". */
1213 cmd_record_start (char *args
, int from_tty
)
1215 execute_command ("target record", from_tty
);
1218 /* Truncate the record log from the present point
1219 of replay until the end. */
1222 cmd_record_delete (char *args
, int from_tty
)
1224 if (current_target
.to_stratum
== record_stratum
)
1226 if (RECORD_IS_REPLAY
)
1228 if (!from_tty
|| query (_("Delete the log from this point forward "
1229 "and begin to record the running message "
1231 record_list_release_next ();
1234 printf_unfiltered (_("Already at end of record list.\n"));
1238 printf_unfiltered (_("Process record is not started.\n"));
1241 /* Implement the "stoprecord" command. */
1244 cmd_record_stop (char *args
, int from_tty
)
1246 if (current_target
.to_stratum
== record_stratum
)
1248 unpush_target (&record_ops
);
1249 printf_unfiltered (_("Process record is stoped and all execution "
1250 "log is deleted.\n"));
1253 printf_unfiltered (_("Process record is not started.\n"));
1256 /* Set upper limit of record log size. */
1259 set_record_insn_max_num (char *args
, int from_tty
, struct cmd_list_element
*c
)
1261 if (record_insn_num
> record_insn_max_num
&& record_insn_max_num
)
1263 printf_unfiltered (_("Record instructions number is bigger than "
1264 "record instructions max number. Auto delete "
1265 "the first ones?\n"));
1267 while (record_insn_num
> record_insn_max_num
)
1268 record_list_release_first ();
1272 /* Print the current index into the record log (number of insns recorded
1276 show_record_insn_number (char *ignore
, int from_tty
)
1278 printf_unfiltered (_("Record instruction number is %d.\n"),
1282 static struct cmd_list_element
*record_cmdlist
, *set_record_cmdlist
,
1283 *show_record_cmdlist
, *info_record_cmdlist
;
1286 set_record_command (char *args
, int from_tty
)
1288 printf_unfiltered (_("\
1289 \"set record\" must be followed by an apporpriate subcommand.\n"));
1290 help_list (set_record_cmdlist
, "set record ", all_commands
, gdb_stdout
);
1294 show_record_command (char *args
, int from_tty
)
1296 cmd_show_list (show_record_cmdlist
, from_tty
, "");
1300 info_record_command (char *args
, int from_tty
)
1302 cmd_show_list (info_record_cmdlist
, from_tty
, "");
1306 _initialize_record (void)
1308 /* Init record_first. */
1309 record_first
.prev
= NULL
;
1310 record_first
.next
= NULL
;
1311 record_first
.type
= record_end
;
1314 add_target (&record_ops
);
1316 add_setshow_zinteger_cmd ("record", no_class
, &record_debug
,
1317 _("Set debugging of record/replay feature."),
1318 _("Show debugging of record/replay feature."),
1319 _("When enabled, debugging output for "
1320 "record/replay feature is displayed."),
1321 NULL
, show_record_debug
, &setdebuglist
,
1324 add_prefix_cmd ("record", class_obscure
, cmd_record_start
,
1325 _("Abbreviated form of \"target record\" command."),
1326 &record_cmdlist
, "record ", 0, &cmdlist
);
1327 add_com_alias ("rec", "record", class_obscure
, 1);
1328 add_prefix_cmd ("record", class_support
, set_record_command
,
1329 _("Set record options"), &set_record_cmdlist
,
1330 "set record ", 0, &setlist
);
1331 add_alias_cmd ("rec", "record", class_obscure
, 1, &setlist
);
1332 add_prefix_cmd ("record", class_support
, show_record_command
,
1333 _("Show record options"), &show_record_cmdlist
,
1334 "show record ", 0, &showlist
);
1335 add_alias_cmd ("rec", "record", class_obscure
, 1, &showlist
);
1336 add_prefix_cmd ("record", class_support
, info_record_command
,
1337 _("Info record options"), &info_record_cmdlist
,
1338 "info record ", 0, &infolist
);
1339 add_alias_cmd ("rec", "record", class_obscure
, 1, &infolist
);
1342 add_cmd ("delete", class_obscure
, cmd_record_delete
,
1343 _("Delete the rest of execution log and start recording it anew."),
1345 add_alias_cmd ("d", "delete", class_obscure
, 1, &record_cmdlist
);
1346 add_alias_cmd ("del", "delete", class_obscure
, 1, &record_cmdlist
);
1348 add_cmd ("stop", class_obscure
, cmd_record_stop
,
1349 _("Stop the record/replay target."),
1351 add_alias_cmd ("s", "stop", class_obscure
, 1, &record_cmdlist
);
1353 /* Record instructions number limit command. */
1354 add_setshow_boolean_cmd ("stop-at-limit", no_class
,
1355 &record_stop_at_limit
, _("\
1356 Set whether record/replay stops when record/replay buffer becomes full."), _("\
1357 Show whether record/replay stops when record/replay buffer becomes full."), _("\
1359 When ON, if the record/replay buffer becomes full, ask user what to do.\n\
1360 When OFF, if the record/replay buffer becomes full,\n\
1361 delete the oldest recorded instruction to make room for each new one."),
1363 &set_record_cmdlist
, &show_record_cmdlist
);
1364 add_setshow_zinteger_cmd ("insn-number-max", no_class
,
1365 &record_insn_max_num
,
1366 _("Set record/replay buffer limit."),
1367 _("Show record/replay buffer limit."), _("\
1368 Set the maximum number of instructions to be stored in the\n\
1369 record/replay buffer. Zero means unlimited. Default is 200000."),
1370 set_record_insn_max_num
,
1371 NULL
, &set_record_cmdlist
, &show_record_cmdlist
);
1372 add_cmd ("insn-number", class_obscure
, show_record_insn_number
,
1373 _("Show the current number of instructions in the "
1374 "record/replay buffer."), &info_record_cmdlist
);