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
;
71 struct record_entry
*prev
;
72 struct record_entry
*next
;
73 enum record_type type
;
77 struct record_reg_entry reg
;
79 struct record_mem_entry mem
;
83 /* This is the debug switch for process record. */
86 /* These list is for execution log. */
87 static struct record_entry record_first
;
88 static struct record_entry
*record_list
= &record_first
;
89 static struct record_entry
*record_arch_list_head
= NULL
;
90 static struct record_entry
*record_arch_list_tail
= NULL
;
92 /* 1 ask user. 0 auto delete the last struct record_entry. */
93 static int record_stop_at_limit
= 1;
94 static int record_insn_max_num
= DEFAULT_RECORD_INSN_MAX_NUM
;
95 static int record_insn_num
= 0;
97 /* The target_ops of process record. */
98 static struct target_ops record_ops
;
100 /* The beneath function pointers. */
101 static struct target_ops
*record_beneath_to_resume_ops
;
102 static void (*record_beneath_to_resume
) (struct target_ops
*, ptid_t
, int,
104 static struct target_ops
*record_beneath_to_wait_ops
;
105 static ptid_t (*record_beneath_to_wait
) (struct target_ops
*, ptid_t
,
106 struct target_waitstatus
*,
108 static struct target_ops
*record_beneath_to_store_registers_ops
;
109 static void (*record_beneath_to_store_registers
) (struct target_ops
*,
112 static struct target_ops
*record_beneath_to_xfer_partial_ops
;
113 static LONGEST (*record_beneath_to_xfer_partial
) (struct target_ops
*ops
,
114 enum target_object object
,
117 const gdb_byte
*writebuf
,
120 static int (*record_beneath_to_insert_breakpoint
) (struct gdbarch
*,
121 struct bp_target_info
*);
122 static int (*record_beneath_to_remove_breakpoint
) (struct gdbarch
*,
123 struct bp_target_info
*);
126 record_list_release (struct record_entry
*rec
)
128 struct record_entry
*tmp
;
142 if (tmp
->type
== record_reg
)
143 xfree (tmp
->u
.reg
.val
);
144 else if (tmp
->type
== record_mem
)
145 xfree (tmp
->u
.mem
.val
);
149 if (rec
!= &record_first
)
154 record_list_release_next (void)
156 struct record_entry
*rec
= record_list
;
157 struct record_entry
*tmp
= rec
->next
;
162 if (tmp
->type
== record_end
)
164 else if (tmp
->type
== record_reg
)
165 xfree (tmp
->u
.reg
.val
);
166 else if (tmp
->type
== record_mem
)
167 xfree (tmp
->u
.mem
.val
);
174 record_list_release_first (void)
176 struct record_entry
*tmp
= NULL
;
177 enum record_type type
;
179 if (!record_first
.next
)
184 type
= record_first
.next
->type
;
186 if (type
== record_reg
)
187 xfree (record_first
.next
->u
.reg
.val
);
188 else if (type
== record_mem
)
189 xfree (record_first
.next
->u
.mem
.val
);
190 tmp
= record_first
.next
;
191 record_first
.next
= tmp
->next
;
194 if (!record_first
.next
)
196 gdb_assert (record_insn_num
== 1);
200 record_first
.next
->prev
= &record_first
;
202 if (type
== record_end
)
209 /* Add a struct record_entry to record_arch_list. */
212 record_arch_list_add (struct record_entry
*rec
)
214 if (record_debug
> 1)
215 fprintf_unfiltered (gdb_stdlog
,
216 "Process record: record_arch_list_add %s.\n",
217 host_address_to_string (rec
));
219 if (record_arch_list_tail
)
221 record_arch_list_tail
->next
= rec
;
222 rec
->prev
= record_arch_list_tail
;
223 record_arch_list_tail
= rec
;
227 record_arch_list_head
= rec
;
228 record_arch_list_tail
= rec
;
232 /* Record the value of a register NUM to record_arch_list. */
235 record_arch_list_add_reg (struct regcache
*regcache
, int num
)
237 struct record_entry
*rec
;
239 if (record_debug
> 1)
240 fprintf_unfiltered (gdb_stdlog
,
241 "Process record: add register num = %d to "
245 rec
= (struct record_entry
*) xmalloc (sizeof (struct record_entry
));
246 rec
->u
.reg
.val
= (gdb_byte
*) xmalloc (MAX_REGISTER_SIZE
);
249 rec
->type
= record_reg
;
250 rec
->u
.reg
.num
= num
;
252 regcache_raw_read (regcache
, num
, rec
->u
.reg
.val
);
254 record_arch_list_add (rec
);
259 /* Record the value of a region of memory whose address is ADDR and
260 length is LEN to record_arch_list. */
263 record_arch_list_add_mem (CORE_ADDR addr
, int len
)
265 struct record_entry
*rec
;
267 if (record_debug
> 1)
268 fprintf_unfiltered (gdb_stdlog
,
269 "Process record: add mem addr = %s len = %d to "
271 paddress (target_gdbarch
, addr
), len
);
276 rec
= (struct record_entry
*) xmalloc (sizeof (struct record_entry
));
277 rec
->u
.mem
.val
= (gdb_byte
*) xmalloc (len
);
280 rec
->type
= record_mem
;
281 rec
->u
.mem
.addr
= addr
;
282 rec
->u
.mem
.len
= len
;
283 rec
->u
.mem
.mem_entry_not_accessible
= 0;
285 if (target_read_memory (addr
, rec
->u
.mem
.val
, len
))
288 fprintf_unfiltered (gdb_stdlog
,
289 "Process record: error reading memory at "
290 "addr = %s len = %d.\n",
291 paddress (target_gdbarch
, addr
), len
);
292 xfree (rec
->u
.mem
.val
);
297 record_arch_list_add (rec
);
302 /* Add a record_end type struct record_entry to record_arch_list. */
305 record_arch_list_add_end (void)
307 struct record_entry
*rec
;
309 if (record_debug
> 1)
310 fprintf_unfiltered (gdb_stdlog
,
311 "Process record: add end to arch list.\n");
313 rec
= (struct record_entry
*) xmalloc (sizeof (struct record_entry
));
316 rec
->type
= record_end
;
318 record_arch_list_add (rec
);
324 record_check_insn_num (int set_terminal
)
326 if (record_insn_max_num
)
328 gdb_assert (record_insn_num
<= record_insn_max_num
);
329 if (record_insn_num
== record_insn_max_num
)
331 /* Ask user what to do. */
332 if (record_stop_at_limit
)
336 target_terminal_ours ();
337 q
= yquery (_("Do you want to auto delete previous execution "
338 "log entries when record/replay buffer becomes "
339 "full (record stop-at-limit)?"));
341 target_terminal_inferior ();
343 record_stop_at_limit
= 0;
345 error (_("Process record: inferior program stopped."));
351 /* Before inferior step (when GDB record the running message, inferior
352 only can step), GDB will call this function to record the values to
353 record_list. This function will call gdbarch_process_record to
354 record the running message of inferior and set them to
355 record_arch_list, and add it to record_list. */
358 record_message_cleanups (void *ignore
)
360 record_list_release (record_arch_list_tail
);
364 record_message (void *args
)
367 struct regcache
*regcache
= args
;
368 struct cleanup
*old_cleanups
= make_cleanup (record_message_cleanups
, 0);
370 record_arch_list_head
= NULL
;
371 record_arch_list_tail
= NULL
;
373 /* Check record_insn_num. */
374 record_check_insn_num (1);
376 ret
= gdbarch_process_record (get_regcache_arch (regcache
),
378 regcache_read_pc (regcache
));
380 error (_("Process record: inferior program stopped."));
382 error (_("Process record: failed to record execution log."));
384 discard_cleanups (old_cleanups
);
386 record_list
->next
= record_arch_list_head
;
387 record_arch_list_head
->prev
= record_list
;
388 record_list
= record_arch_list_tail
;
390 if (record_insn_num
== record_insn_max_num
&& record_insn_max_num
)
391 record_list_release_first ();
399 do_record_message (struct regcache
*regcache
)
401 return catch_errors (record_message
, regcache
, NULL
, RETURN_MASK_ALL
);
404 /* Set to 1 if record_store_registers and record_xfer_partial
405 doesn't need record. */
407 static int record_gdb_operation_disable
= 0;
410 record_gdb_operation_disable_set (void)
412 struct cleanup
*old_cleanups
= NULL
;
415 make_cleanup_restore_integer (&record_gdb_operation_disable
);
416 record_gdb_operation_disable
= 1;
422 record_open (char *name
, int from_tty
)
424 struct target_ops
*t
;
427 fprintf_unfiltered (gdb_stdlog
, "Process record: record_open\n");
430 if (!target_has_execution
)
431 error (_("Process record: the program is not being run."));
433 error (_("Process record target can't debug inferior in non-stop mode "
435 if (target_async_permitted
)
436 error (_("Process record target can't debug inferior in asynchronous "
437 "mode (target-async)."));
439 if (!gdbarch_process_record_p (target_gdbarch
))
440 error (_("Process record: the current architecture doesn't support "
441 "record function."));
443 /* Check if record target is already running. */
444 if (current_target
.to_stratum
== record_stratum
)
447 (_("Process record target already running, do you want to delete "
448 "the old record log?")))
452 /*Reset the beneath function pointers. */
453 record_beneath_to_resume
= NULL
;
454 record_beneath_to_wait
= NULL
;
455 record_beneath_to_store_registers
= NULL
;
456 record_beneath_to_xfer_partial
= NULL
;
457 record_beneath_to_insert_breakpoint
= NULL
;
458 record_beneath_to_remove_breakpoint
= NULL
;
460 /* Set the beneath function pointers. */
461 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
463 if (!record_beneath_to_resume
)
465 record_beneath_to_resume
= t
->to_resume
;
466 record_beneath_to_resume_ops
= t
;
468 if (!record_beneath_to_wait
)
470 record_beneath_to_wait
= t
->to_wait
;
471 record_beneath_to_wait_ops
= t
;
473 if (!record_beneath_to_store_registers
)
475 record_beneath_to_store_registers
= t
->to_store_registers
;
476 record_beneath_to_store_registers_ops
= t
;
478 if (!record_beneath_to_xfer_partial
)
480 record_beneath_to_xfer_partial
= t
->to_xfer_partial
;
481 record_beneath_to_xfer_partial_ops
= t
;
483 if (!record_beneath_to_insert_breakpoint
)
484 record_beneath_to_insert_breakpoint
= t
->to_insert_breakpoint
;
485 if (!record_beneath_to_remove_breakpoint
)
486 record_beneath_to_remove_breakpoint
= t
->to_remove_breakpoint
;
488 if (!record_beneath_to_resume
)
489 error (_("Process record can't get to_resume."));
490 if (!record_beneath_to_wait
)
491 error (_("Process record can't get to_wait."));
492 if (!record_beneath_to_store_registers
)
493 error (_("Process record can't get to_store_registers."));
494 if (!record_beneath_to_xfer_partial
)
495 error (_("Process record can't get to_xfer_partial."));
496 if (!record_beneath_to_insert_breakpoint
)
497 error (_("Process record can't get to_insert_breakpoint."));
498 if (!record_beneath_to_remove_breakpoint
)
499 error (_("Process record can't get to_remove_breakpoint."));
501 push_target (&record_ops
);
505 record_list
= &record_first
;
506 record_list
->next
= NULL
;
510 record_close (int quitting
)
513 fprintf_unfiltered (gdb_stdlog
, "Process record: record_close\n");
515 record_list_release (record_list
);
518 static int record_resume_step
= 0;
519 static int record_resume_error
;
522 record_resume (struct target_ops
*ops
, ptid_t ptid
, int step
,
523 enum target_signal siggnal
)
525 record_resume_step
= step
;
527 if (!RECORD_IS_REPLAY
)
529 if (do_record_message (get_current_regcache ()))
531 record_resume_error
= 0;
535 record_resume_error
= 1;
538 record_beneath_to_resume (record_beneath_to_resume_ops
, ptid
, 1,
543 static int record_get_sig
= 0;
546 record_sig_handler (int signo
)
549 fprintf_unfiltered (gdb_stdlog
, "Process record: get a signal\n");
551 /* It will break the running inferior in replay mode. */
552 record_resume_step
= 1;
554 /* It will let record_wait set inferior status to get the signal
560 record_wait_cleanups (void *ignore
)
562 if (execution_direction
== EXEC_REVERSE
)
564 if (record_list
->next
)
565 record_list
= record_list
->next
;
568 record_list
= record_list
->prev
;
571 /* In replay mode, this function examines the recorded log and
572 determines where to stop. */
575 record_wait (struct target_ops
*ops
,
576 ptid_t ptid
, struct target_waitstatus
*status
,
579 struct cleanup
*set_cleanups
= record_gdb_operation_disable_set ();
582 fprintf_unfiltered (gdb_stdlog
,
583 "Process record: record_wait "
584 "record_resume_step = %d\n",
587 if (!RECORD_IS_REPLAY
)
589 if (record_resume_error
)
591 /* If record_resume get error, return directly. */
592 status
->kind
= TARGET_WAITKIND_STOPPED
;
593 status
->value
.sig
= TARGET_SIGNAL_ABRT
;
594 return inferior_ptid
;
597 if (record_resume_step
)
599 /* This is a single step. */
600 return record_beneath_to_wait (record_beneath_to_wait_ops
,
601 ptid
, status
, options
);
605 /* This is not a single step. */
611 ret
= record_beneath_to_wait (record_beneath_to_wait_ops
,
612 ptid
, status
, options
);
614 if (status
->kind
== TARGET_WAITKIND_STOPPED
615 && status
->value
.sig
== TARGET_SIGNAL_TRAP
)
617 /* Check if there is a breakpoint. */
618 registers_changed ();
619 tmp_pc
= regcache_read_pc (get_current_regcache ());
620 if (breakpoint_inserted_here_p (tmp_pc
))
622 /* There is a breakpoint. */
623 CORE_ADDR decr_pc_after_break
=
624 gdbarch_decr_pc_after_break
625 (get_regcache_arch (get_current_regcache ()));
626 if (decr_pc_after_break
)
628 regcache_write_pc (get_thread_regcache (ret
),
629 tmp_pc
+ decr_pc_after_break
);
634 /* There is not a breakpoint. */
635 if (!do_record_message (get_current_regcache ()))
639 record_beneath_to_resume (record_beneath_to_resume_ops
,
646 /* The inferior is broken by a breakpoint or a signal. */
655 struct regcache
*regcache
= get_current_regcache ();
656 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
657 int continue_flag
= 1;
658 int first_record_end
= 1;
659 struct cleanup
*old_cleanups
= make_cleanup (record_wait_cleanups
, 0);
662 status
->kind
= TARGET_WAITKIND_STOPPED
;
664 /* Check breakpoint when forward execute. */
665 if (execution_direction
== EXEC_FORWARD
)
667 tmp_pc
= regcache_read_pc (regcache
);
668 if (breakpoint_inserted_here_p (tmp_pc
))
671 fprintf_unfiltered (gdb_stdlog
,
672 "Process record: break at %s.\n",
673 paddress (gdbarch
, tmp_pc
));
674 if (gdbarch_decr_pc_after_break (gdbarch
)
675 && !record_resume_step
)
676 regcache_write_pc (regcache
,
678 gdbarch_decr_pc_after_break (gdbarch
));
684 signal (SIGINT
, record_sig_handler
);
685 /* If GDB is in terminal_inferior mode, it will not get the signal.
686 And in GDB replay mode, GDB doesn't need to be in terminal_inferior
687 mode, because inferior will not executed.
688 Then set it to terminal_ours to make GDB get the signal. */
689 target_terminal_ours ();
691 /* In EXEC_FORWARD mode, record_list points to the tail of prev
693 if (execution_direction
== EXEC_FORWARD
&& record_list
->next
)
694 record_list
= record_list
->next
;
696 /* Loop over the record_list, looking for the next place to
700 /* Check for beginning and end of log. */
701 if (execution_direction
== EXEC_REVERSE
702 && record_list
== &record_first
)
704 /* Hit beginning of record log in reverse. */
705 status
->kind
= TARGET_WAITKIND_NO_HISTORY
;
708 if (execution_direction
!= EXEC_REVERSE
&& !record_list
->next
)
710 /* Hit end of record log going forward. */
711 status
->kind
= TARGET_WAITKIND_NO_HISTORY
;
715 /* Set ptid, register and memory according to record_list. */
716 if (record_list
->type
== record_reg
)
719 gdb_byte reg
[MAX_REGISTER_SIZE
];
720 if (record_debug
> 1)
721 fprintf_unfiltered (gdb_stdlog
,
722 "Process record: record_reg %s to "
723 "inferior num = %d.\n",
724 host_address_to_string (record_list
),
725 record_list
->u
.reg
.num
);
726 regcache_cooked_read (regcache
, record_list
->u
.reg
.num
, reg
);
727 regcache_cooked_write (regcache
, record_list
->u
.reg
.num
,
728 record_list
->u
.reg
.val
);
729 memcpy (record_list
->u
.reg
.val
, reg
, MAX_REGISTER_SIZE
);
731 else if (record_list
->type
== record_mem
)
734 /* Nothing to do if the entry is flagged not_accessible. */
735 if (!record_list
->u
.mem
.mem_entry_not_accessible
)
737 gdb_byte
*mem
= alloca (record_list
->u
.mem
.len
);
738 if (record_debug
> 1)
739 fprintf_unfiltered (gdb_stdlog
,
740 "Process record: record_mem %s to "
741 "inferior addr = %s len = %d.\n",
742 host_address_to_string (record_list
),
744 record_list
->u
.mem
.addr
),
745 record_list
->u
.mem
.len
);
747 if (target_read_memory (record_list
->u
.mem
.addr
, mem
,
748 record_list
->u
.mem
.len
))
750 if (execution_direction
!= EXEC_REVERSE
)
751 error (_("Process record: error reading memory at "
752 "addr = %s len = %d."),
753 paddress (gdbarch
, record_list
->u
.mem
.addr
),
754 record_list
->u
.mem
.len
);
757 flag entry as not_accessible. */
758 record_list
->u
.mem
.mem_entry_not_accessible
= 1;
762 if (target_write_memory (record_list
->u
.mem
.addr
,
763 record_list
->u
.mem
.val
,
764 record_list
->u
.mem
.len
))
766 if (execution_direction
!= EXEC_REVERSE
)
767 error (_("Process record: error writing memory at "
768 "addr = %s len = %d."),
769 paddress (gdbarch
, record_list
->u
.mem
.addr
),
770 record_list
->u
.mem
.len
);
773 flag entry as not_accessible. */
774 record_list
->u
.mem
.mem_entry_not_accessible
= 1;
778 memcpy (record_list
->u
.mem
.val
, mem
,
779 record_list
->u
.mem
.len
);
786 if (record_debug
> 1)
787 fprintf_unfiltered (gdb_stdlog
,
788 "Process record: record_end %s to "
790 host_address_to_string (record_list
));
792 if (first_record_end
&& execution_direction
== EXEC_REVERSE
)
794 /* When reverse excute, the first record_end is the part of
795 current instruction. */
796 first_record_end
= 0;
800 /* In EXEC_REVERSE mode, this is the record_end of prev
802 In EXEC_FORWARD mode, this is the record_end of current
805 if (record_resume_step
)
807 if (record_debug
> 1)
808 fprintf_unfiltered (gdb_stdlog
,
809 "Process record: step.\n");
813 /* check breakpoint */
814 tmp_pc
= regcache_read_pc (regcache
);
815 if (breakpoint_inserted_here_p (tmp_pc
))
818 fprintf_unfiltered (gdb_stdlog
,
819 "Process record: break "
821 paddress (gdbarch
, tmp_pc
));
822 if (gdbarch_decr_pc_after_break (gdbarch
)
823 && execution_direction
== EXEC_FORWARD
824 && !record_resume_step
)
825 regcache_write_pc (regcache
,
827 gdbarch_decr_pc_after_break (gdbarch
));
835 if (execution_direction
== EXEC_REVERSE
)
837 if (record_list
->prev
)
838 record_list
= record_list
->prev
;
842 if (record_list
->next
)
843 record_list
= record_list
->next
;
847 while (continue_flag
);
849 signal (SIGINT
, handle_sigint
);
853 status
->value
.sig
= TARGET_SIGNAL_INT
;
855 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
857 discard_cleanups (old_cleanups
);
860 do_cleanups (set_cleanups
);
861 return inferior_ptid
;
865 record_disconnect (struct target_ops
*target
, char *args
, int from_tty
)
868 fprintf_unfiltered (gdb_stdlog
, "Process record: record_disconnect\n");
870 unpush_target (&record_ops
);
871 target_disconnect (args
, from_tty
);
875 record_detach (struct target_ops
*ops
, char *args
, int from_tty
)
878 fprintf_unfiltered (gdb_stdlog
, "Process record: record_detach\n");
880 unpush_target (&record_ops
);
881 target_detach (args
, from_tty
);
885 record_mourn_inferior (struct target_ops
*ops
)
888 fprintf_unfiltered (gdb_stdlog
, "Process record: "
889 "record_mourn_inferior\n");
891 unpush_target (&record_ops
);
892 target_mourn_inferior ();
895 /* Close process record target before killing the inferior process. */
898 record_kill (struct target_ops
*ops
)
901 fprintf_unfiltered (gdb_stdlog
, "Process record: record_kill\n");
903 unpush_target (&record_ops
);
907 /* Record registers change (by user or by GDB) to list as an instruction. */
910 record_registers_change (struct regcache
*regcache
, int regnum
)
912 /* Check record_insn_num. */
913 record_check_insn_num (0);
915 record_arch_list_head
= NULL
;
916 record_arch_list_tail
= NULL
;
921 for (i
= 0; i
< gdbarch_num_regs (get_regcache_arch (regcache
)); i
++)
923 if (record_arch_list_add_reg (regcache
, i
))
925 record_list_release (record_arch_list_tail
);
926 error (_("Process record: failed to record execution log."));
932 if (record_arch_list_add_reg (regcache
, regnum
))
934 record_list_release (record_arch_list_tail
);
935 error (_("Process record: failed to record execution log."));
938 if (record_arch_list_add_end ())
940 record_list_release (record_arch_list_tail
);
941 error (_("Process record: failed to record execution log."));
943 record_list
->next
= record_arch_list_head
;
944 record_arch_list_head
->prev
= record_list
;
945 record_list
= record_arch_list_tail
;
947 if (record_insn_num
== record_insn_max_num
&& record_insn_max_num
)
948 record_list_release_first ();
954 record_store_registers (struct target_ops
*ops
, struct regcache
*regcache
,
957 if (!record_gdb_operation_disable
)
959 if (RECORD_IS_REPLAY
)
963 /* Let user choose if he wants to write register or not. */
966 nquery (_("Because GDB is in replay mode, changing the "
967 "value of a register will make the execution "
968 "log unusable from this point onward. "
969 "Change all registers?"));
972 nquery (_("Because GDB is in replay mode, changing the value "
973 "of a register will make the execution log unusable "
974 "from this point onward. Change register %s?"),
975 gdbarch_register_name (get_regcache_arch (regcache
),
980 /* Invalidate the value of regcache that was set in function
981 "regcache_raw_write". */
986 i
< gdbarch_num_regs (get_regcache_arch (regcache
));
988 regcache_invalidate (regcache
, i
);
991 regcache_invalidate (regcache
, regno
);
993 error (_("Process record canceled the operation."));
996 /* Destroy the record from here forward. */
997 record_list_release_next ();
1000 record_registers_change (regcache
, regno
);
1002 record_beneath_to_store_registers (record_beneath_to_store_registers_ops
,
1006 /* Behavior is conditional on RECORD_IS_REPLAY.
1007 In replay mode, we cannot write memory unles we are willing to
1008 invalidate the record/replay log from this point forward. */
1011 record_xfer_partial (struct target_ops
*ops
, enum target_object object
,
1012 const char *annex
, gdb_byte
*readbuf
,
1013 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
1015 if (!record_gdb_operation_disable
1016 && (object
== TARGET_OBJECT_MEMORY
1017 || object
== TARGET_OBJECT_RAW_MEMORY
) && writebuf
)
1019 if (RECORD_IS_REPLAY
)
1021 /* Let user choose if he wants to write memory or not. */
1022 if (!nquery (_("Because GDB is in replay mode, writing to memory "
1023 "will make the execution log unusable from this "
1024 "point onward. Write memory at address %s?"),
1025 paddress (target_gdbarch
, offset
)))
1026 error (_("Process record canceled the operation."));
1028 /* Destroy the record from here forward. */
1029 record_list_release_next ();
1032 /* Check record_insn_num */
1033 record_check_insn_num (0);
1035 /* Record registers change to list as an instruction. */
1036 record_arch_list_head
= NULL
;
1037 record_arch_list_tail
= NULL
;
1038 if (record_arch_list_add_mem (offset
, len
))
1040 record_list_release (record_arch_list_tail
);
1042 fprintf_unfiltered (gdb_stdlog
,
1043 _("Process record: failed to record "
1047 if (record_arch_list_add_end ())
1049 record_list_release (record_arch_list_tail
);
1051 fprintf_unfiltered (gdb_stdlog
,
1052 _("Process record: failed to record "
1056 record_list
->next
= record_arch_list_head
;
1057 record_arch_list_head
->prev
= record_list
;
1058 record_list
= record_arch_list_tail
;
1060 if (record_insn_num
== record_insn_max_num
&& record_insn_max_num
)
1061 record_list_release_first ();
1066 return record_beneath_to_xfer_partial (record_beneath_to_xfer_partial_ops
,
1067 object
, annex
, readbuf
, writebuf
,
1071 /* Behavior is conditional on RECORD_IS_REPLAY.
1072 We will not actually insert or remove breakpoints when replaying,
1073 nor when recording. */
1076 record_insert_breakpoint (struct gdbarch
*gdbarch
,
1077 struct bp_target_info
*bp_tgt
)
1079 if (!RECORD_IS_REPLAY
)
1081 struct cleanup
*old_cleanups
= record_gdb_operation_disable_set ();
1082 int ret
= record_beneath_to_insert_breakpoint (gdbarch
, bp_tgt
);
1084 do_cleanups (old_cleanups
);
1093 record_remove_breakpoint (struct gdbarch
*gdbarch
,
1094 struct bp_target_info
*bp_tgt
)
1096 if (!RECORD_IS_REPLAY
)
1098 struct cleanup
*old_cleanups
= record_gdb_operation_disable_set ();
1099 int ret
= record_beneath_to_remove_breakpoint (gdbarch
, bp_tgt
);
1101 do_cleanups (old_cleanups
);
1110 record_can_execute_reverse (void)
1116 init_record_ops (void)
1118 record_ops
.to_shortname
= "record";
1119 record_ops
.to_longname
= "Process record and replay target";
1121 "Log program while executing and replay execution from log.";
1122 record_ops
.to_open
= record_open
;
1123 record_ops
.to_close
= record_close
;
1124 record_ops
.to_resume
= record_resume
;
1125 record_ops
.to_wait
= record_wait
;
1126 record_ops
.to_disconnect
= record_disconnect
;
1127 record_ops
.to_detach
= record_detach
;
1128 record_ops
.to_mourn_inferior
= record_mourn_inferior
;
1129 record_ops
.to_kill
= record_kill
;
1130 record_ops
.to_create_inferior
= find_default_create_inferior
;
1131 record_ops
.to_store_registers
= record_store_registers
;
1132 record_ops
.to_xfer_partial
= record_xfer_partial
;
1133 record_ops
.to_insert_breakpoint
= record_insert_breakpoint
;
1134 record_ops
.to_remove_breakpoint
= record_remove_breakpoint
;
1135 record_ops
.to_can_execute_reverse
= record_can_execute_reverse
;
1136 record_ops
.to_stratum
= record_stratum
;
1137 record_ops
.to_magic
= OPS_MAGIC
;
1141 show_record_debug (struct ui_file
*file
, int from_tty
,
1142 struct cmd_list_element
*c
, const char *value
)
1144 fprintf_filtered (file
, _("Debugging of process record target is %s.\n"),
1148 /* Alias for "target record". */
1151 cmd_record_start (char *args
, int from_tty
)
1153 execute_command ("target record", from_tty
);
1156 /* Truncate the record log from the present point
1157 of replay until the end. */
1160 cmd_record_delete (char *args
, int from_tty
)
1162 if (current_target
.to_stratum
== record_stratum
)
1164 if (RECORD_IS_REPLAY
)
1166 if (!from_tty
|| query (_("Delete the log from this point forward "
1167 "and begin to record the running message "
1169 record_list_release_next ();
1172 printf_unfiltered (_("Already at end of record list.\n"));
1176 printf_unfiltered (_("Process record is not started.\n"));
1179 /* Implement the "stoprecord" command. */
1182 cmd_record_stop (char *args
, int from_tty
)
1184 if (current_target
.to_stratum
== record_stratum
)
1186 if (!record_list
|| !from_tty
|| query (_("Delete recorded log and "
1187 "stop recording?")))
1188 unpush_target (&record_ops
);
1191 printf_unfiltered (_("Process record is not started.\n"));
1194 /* Set upper limit of record log size. */
1197 set_record_insn_max_num (char *args
, int from_tty
, struct cmd_list_element
*c
)
1199 if (record_insn_num
> record_insn_max_num
&& record_insn_max_num
)
1201 printf_unfiltered (_("Record instructions number is bigger than "
1202 "record instructions max number. Auto delete "
1203 "the first ones?\n"));
1205 while (record_insn_num
> record_insn_max_num
)
1206 record_list_release_first ();
1210 /* Print the current index into the record log (number of insns recorded
1214 show_record_insn_number (char *ignore
, int from_tty
)
1216 printf_unfiltered (_("Record instruction number is %d.\n"),
1220 static struct cmd_list_element
*record_cmdlist
, *set_record_cmdlist
,
1221 *show_record_cmdlist
, *info_record_cmdlist
;
1224 set_record_command (char *args
, int from_tty
)
1226 printf_unfiltered (_("\
1227 \"set record\" must be followed by an apporpriate subcommand.\n"));
1228 help_list (set_record_cmdlist
, "set record ", all_commands
, gdb_stdout
);
1232 show_record_command (char *args
, int from_tty
)
1234 cmd_show_list (show_record_cmdlist
, from_tty
, "");
1238 info_record_command (char *args
, int from_tty
)
1240 cmd_show_list (info_record_cmdlist
, from_tty
, "");
1244 _initialize_record (void)
1246 /* Init record_first. */
1247 record_first
.prev
= NULL
;
1248 record_first
.next
= NULL
;
1249 record_first
.type
= record_end
;
1252 add_target (&record_ops
);
1254 add_setshow_zinteger_cmd ("record", no_class
, &record_debug
,
1255 _("Set debugging of record/replay feature."),
1256 _("Show debugging of record/replay feature."),
1257 _("When enabled, debugging output for "
1258 "record/replay feature is displayed."),
1259 NULL
, show_record_debug
, &setdebuglist
,
1262 add_prefix_cmd ("record", class_obscure
, cmd_record_start
,
1263 _("Abbreviated form of \"target record\" command."),
1264 &record_cmdlist
, "record ", 0, &cmdlist
);
1265 add_com_alias ("rec", "record", class_obscure
, 1);
1266 add_prefix_cmd ("record", class_support
, set_record_command
,
1267 _("Set record options"), &set_record_cmdlist
,
1268 "set record ", 0, &setlist
);
1269 add_alias_cmd ("rec", "record", class_obscure
, 1, &setlist
);
1270 add_prefix_cmd ("record", class_support
, show_record_command
,
1271 _("Show record options"), &show_record_cmdlist
,
1272 "show record ", 0, &showlist
);
1273 add_alias_cmd ("rec", "record", class_obscure
, 1, &showlist
);
1274 add_prefix_cmd ("record", class_support
, info_record_command
,
1275 _("Info record options"), &info_record_cmdlist
,
1276 "info record ", 0, &infolist
);
1277 add_alias_cmd ("rec", "record", class_obscure
, 1, &infolist
);
1280 add_cmd ("delete", class_obscure
, cmd_record_delete
,
1281 _("Delete the rest of execution log and start recording it anew."),
1283 add_alias_cmd ("d", "delete", class_obscure
, 1, &record_cmdlist
);
1284 add_alias_cmd ("del", "delete", class_obscure
, 1, &record_cmdlist
);
1286 add_cmd ("stop", class_obscure
, cmd_record_stop
,
1287 _("Stop the record/replay target."),
1289 add_alias_cmd ("s", "stop", class_obscure
, 1, &record_cmdlist
);
1291 /* Record instructions number limit command. */
1292 add_setshow_boolean_cmd ("stop-at-limit", no_class
,
1293 &record_stop_at_limit
, _("\
1294 Set whether record/replay stops when record/replay buffer becomes full."), _("\
1295 Show whether record/replay stops when record/replay buffer becomes full."), _("\
1297 When ON, if the record/replay buffer becomes full, ask user what to do.\n\
1298 When OFF, if the record/replay buffer becomes full,\n\
1299 delete the oldest recorded instruction to make room for each new one."),
1301 &set_record_cmdlist
, &show_record_cmdlist
);
1302 add_setshow_zinteger_cmd ("insn-number-max", no_class
,
1303 &record_insn_max_num
,
1304 _("Set record/replay buffer limit."),
1305 _("Show record/replay buffer limit."), _("\
1306 Set the maximum number of instructions to be stored in the\n\
1307 record/replay buffer. Zero means unlimited. Default is 200000."),
1308 set_record_insn_max_num
,
1309 NULL
, &set_record_cmdlist
, &show_record_cmdlist
);
1310 add_cmd ("insn-number", class_obscure
, show_record_insn_number
,
1311 _("Show the current number of instructions in the "
1312 "record/replay buffer."), &info_record_cmdlist
);