1 /* Process record and replay target for GDB, the GNU debugger.
3 Copyright (C) 2013-2014 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"
26 #include "completer.h"
27 #include "arch-utils.h"
31 #include "record-full.h"
34 #include "event-loop.h"
42 /* This module implements "target record-full", also known as "process
43 record and replay". This target sits on top of a "normal" target
44 (a target that "has execution"), and provides a record and replay
45 functionality, including reverse debugging.
47 Target record has two modes: recording, and replaying.
49 In record mode, we intercept the to_resume and to_wait methods.
50 Whenever gdb resumes the target, we run the target in single step
51 mode, and we build up an execution log in which, for each executed
52 instruction, we record all changes in memory and register state.
53 This is invisible to the user, to whom it just looks like an
54 ordinary debugging session (except for performance degredation).
56 In replay mode, instead of actually letting the inferior run as a
57 process, we simulate its execution by playing back the recorded
58 execution log. For each instruction in the log, we simulate the
59 instruction's side effects by duplicating the changes that it would
60 have made on memory and registers. */
62 #define DEFAULT_RECORD_FULL_INSN_MAX_NUM 200000
64 #define RECORD_FULL_IS_REPLAY \
65 (record_full_list->next || execution_direction == EXEC_REVERSE)
67 #define RECORD_FULL_FILE_MAGIC netorder32(0x20091016)
69 /* These are the core structs of the process record functionality.
71 A record_full_entry is a record of the value change of a register
72 ("record_full_reg") or a part of memory ("record_full_mem"). And each
73 instruction must have a struct record_full_entry ("record_full_end")
74 that indicates that this is the last struct record_full_entry of this
77 Each struct record_full_entry is linked to "record_full_list" by "prev"
78 and "next" pointers. */
80 struct record_full_mem_entry
84 /* Set this flag if target memory for this entry
85 can no longer be accessed. */
86 int mem_entry_not_accessible;
90 gdb_byte buf[sizeof (gdb_byte *)];
94 struct record_full_reg_entry
101 gdb_byte buf[2 * sizeof (gdb_byte *)];
105 struct record_full_end_entry
107 enum gdb_signal sigval;
111 enum record_full_type
118 /* This is the data structure that makes up the execution log.
120 The execution log consists of a single linked list of entries
121 of type "struct record_full_entry". It is doubly linked so that it
122 can be traversed in either direction.
124 The start of the list is anchored by a struct called
125 "record_full_first". The pointer "record_full_list" either points
126 to the last entry that was added to the list (in record mode), or to
127 the next entry in the list that will be executed (in replay mode).
129 Each list element (struct record_full_entry), in addition to next
130 and prev pointers, consists of a union of three entry types: mem,
131 reg, and end. A field called "type" determines which entry type is
132 represented by a given list element.
134 Each instruction that is added to the execution log is represented
135 by a variable number of list elements ('entries'). The instruction
136 will have one "reg" entry for each register that is changed by
137 executing the instruction (including the PC in every case). It
138 will also have one "mem" entry for each memory change. Finally,
139 each instruction will have an "end" entry that separates it from
140 the changes associated with the next instruction. */
142 struct record_full_entry
144 struct record_full_entry *prev;
145 struct record_full_entry *next;
146 enum record_full_type type;
150 struct record_full_reg_entry reg;
152 struct record_full_mem_entry mem;
154 struct record_full_end_entry end;
158 /* If true, query if PREC cannot record memory
159 change of next instruction. */
160 int record_full_memory_query = 0;
162 struct record_full_core_buf_entry
164 struct record_full_core_buf_entry *prev;
165 struct target_section *p;
169 /* Record buf with core target. */
170 static gdb_byte *record_full_core_regbuf = NULL;
171 static struct target_section *record_full_core_start;
172 static struct target_section *record_full_core_end;
173 static struct record_full_core_buf_entry *record_full_core_buf_list = NULL;
175 /* The following variables are used for managing the linked list that
176 represents the execution log.
178 record_full_first is the anchor that holds down the beginning of
181 record_full_list serves two functions:
182 1) In record mode, it anchors the end of the list.
183 2) In replay mode, it traverses the list and points to
184 the next instruction that must be emulated.
186 record_full_arch_list_head and record_full_arch_list_tail are used
187 to manage a separate list, which is used to build up the change
188 elements of the currently executing instruction during record mode.
189 When this instruction has been completely annotated in the "arch
190 list", it will be appended to the main execution log. */
192 static struct record_full_entry record_full_first;
193 static struct record_full_entry *record_full_list = &record_full_first;
194 static struct record_full_entry *record_full_arch_list_head = NULL;
195 static struct record_full_entry *record_full_arch_list_tail = NULL;
197 /* 1 ask user. 0 auto delete the last struct record_full_entry. */
198 static int record_full_stop_at_limit = 1;
199 /* Maximum allowed number of insns in execution log. */
200 static unsigned int record_full_insn_max_num
201 = DEFAULT_RECORD_FULL_INSN_MAX_NUM;
202 /* Actual count of insns presently in execution log. */
203 static unsigned int record_full_insn_num = 0;
204 /* Count of insns logged so far (may be larger
205 than count of insns presently in execution log). */
206 static ULONGEST record_full_insn_count;
208 /* The target_ops of process record. */
209 static struct target_ops record_full_ops;
210 static struct target_ops record_full_core_ops;
212 /* See record-full.h. */
215 record_full_is_used (void)
217 struct target_ops *t;
219 t = find_record_target ();
220 return (t == &record_full_ops
221 || t == &record_full_core_ops);
225 /* Command lists for "set/show record full". */
226 static struct cmd_list_element *set_record_full_cmdlist;
227 static struct cmd_list_element *show_record_full_cmdlist;
229 /* Command list for "record full". */
230 static struct cmd_list_element *record_full_cmdlist;
232 static void record_full_goto_insn (struct record_full_entry *entry,
233 enum exec_direction_kind dir);
234 static void record_full_save (struct target_ops *self,
235 const char *recfilename);
237 /* Alloc and free functions for record_full_reg, record_full_mem, and
238 record_full_end entries. */
240 /* Alloc a record_full_reg record entry. */
242 static inline struct record_full_entry *
243 record_full_reg_alloc (struct regcache *regcache, int regnum)
245 struct record_full_entry *rec;
246 struct gdbarch *gdbarch = get_regcache_arch (regcache);
248 rec = xcalloc (1, sizeof (struct record_full_entry));
249 rec->type = record_full_reg;
250 rec->u.reg.num = regnum;
251 rec->u.reg.len = register_size (gdbarch, regnum);
252 if (rec->u.reg.len > sizeof (rec->u.reg.u.buf))
253 rec->u.reg.u.ptr = (gdb_byte *) xmalloc (rec->u.reg.len);
258 /* Free a record_full_reg record entry. */
261 record_full_reg_release (struct record_full_entry *rec)
263 gdb_assert (rec->type == record_full_reg);
264 if (rec->u.reg.len > sizeof (rec->u.reg.u.buf))
265 xfree (rec->u.reg.u.ptr);
269 /* Alloc a record_full_mem record entry. */
271 static inline struct record_full_entry *
272 record_full_mem_alloc (CORE_ADDR addr, int len)
274 struct record_full_entry *rec;
276 rec = xcalloc (1, sizeof (struct record_full_entry));
277 rec->type = record_full_mem;
278 rec->u.mem.addr = addr;
279 rec->u.mem.len = len;
280 if (rec->u.mem.len > sizeof (rec->u.mem.u.buf))
281 rec->u.mem.u.ptr = (gdb_byte *) xmalloc (len);
286 /* Free a record_full_mem record entry. */
289 record_full_mem_release (struct record_full_entry *rec)
291 gdb_assert (rec->type == record_full_mem);
292 if (rec->u.mem.len > sizeof (rec->u.mem.u.buf))
293 xfree (rec->u.mem.u.ptr);
297 /* Alloc a record_full_end record entry. */
299 static inline struct record_full_entry *
300 record_full_end_alloc (void)
302 struct record_full_entry *rec;
304 rec = xcalloc (1, sizeof (struct record_full_entry));
305 rec->type = record_full_end;
310 /* Free a record_full_end record entry. */
313 record_full_end_release (struct record_full_entry *rec)
318 /* Free one record entry, any type.
319 Return entry->type, in case caller wants to know. */
321 static inline enum record_full_type
322 record_full_entry_release (struct record_full_entry *rec)
324 enum record_full_type type = rec->type;
327 case record_full_reg:
328 record_full_reg_release (rec);
330 case record_full_mem:
331 record_full_mem_release (rec);
333 case record_full_end:
334 record_full_end_release (rec);
340 /* Free all record entries in list pointed to by REC. */
343 record_full_list_release (struct record_full_entry *rec)
354 record_full_entry_release (rec->next);
357 if (rec == &record_full_first)
359 record_full_insn_num = 0;
360 record_full_first.next = NULL;
363 record_full_entry_release (rec);
366 /* Free all record entries forward of the given list position. */
369 record_full_list_release_following (struct record_full_entry *rec)
371 struct record_full_entry *tmp = rec->next;
377 if (record_full_entry_release (tmp) == record_full_end)
379 record_full_insn_num--;
380 record_full_insn_count--;
386 /* Delete the first instruction from the beginning of the log, to make
387 room for adding a new instruction at the end of the log.
389 Note -- this function does not modify record_full_insn_num. */
392 record_full_list_release_first (void)
394 struct record_full_entry *tmp;
396 if (!record_full_first.next)
399 /* Loop until a record_full_end. */
402 /* Cut record_full_first.next out of the linked list. */
403 tmp = record_full_first.next;
404 record_full_first.next = tmp->next;
405 tmp->next->prev = &record_full_first;
407 /* tmp is now isolated, and can be deleted. */
408 if (record_full_entry_release (tmp) == record_full_end)
409 break; /* End loop at first record_full_end. */
411 if (!record_full_first.next)
413 gdb_assert (record_full_insn_num == 1);
414 break; /* End loop when list is empty. */
419 /* Add a struct record_full_entry to record_full_arch_list. */
422 record_full_arch_list_add (struct record_full_entry *rec)
424 if (record_debug > 1)
425 fprintf_unfiltered (gdb_stdlog,
426 "Process record: record_full_arch_list_add %s.\n",
427 host_address_to_string (rec));
429 if (record_full_arch_list_tail)
431 record_full_arch_list_tail->next = rec;
432 rec->prev = record_full_arch_list_tail;
433 record_full_arch_list_tail = rec;
437 record_full_arch_list_head = rec;
438 record_full_arch_list_tail = rec;
442 /* Return the value storage location of a record entry. */
443 static inline gdb_byte *
444 record_full_get_loc (struct record_full_entry *rec)
447 case record_full_mem:
448 if (rec->u.mem.len > sizeof (rec->u.mem.u.buf))
449 return rec->u.mem.u.ptr;
451 return rec->u.mem.u.buf;
452 case record_full_reg:
453 if (rec->u.reg.len > sizeof (rec->u.reg.u.buf))
454 return rec->u.reg.u.ptr;
456 return rec->u.reg.u.buf;
457 case record_full_end:
459 gdb_assert_not_reached ("unexpected record_full_entry type");
464 /* Record the value of a register NUM to record_full_arch_list. */
467 record_full_arch_list_add_reg (struct regcache *regcache, int regnum)
469 struct record_full_entry *rec;
471 if (record_debug > 1)
472 fprintf_unfiltered (gdb_stdlog,
473 "Process record: add register num = %d to "
477 rec = record_full_reg_alloc (regcache, regnum);
479 regcache_raw_read (regcache, regnum, record_full_get_loc (rec));
481 record_full_arch_list_add (rec);
486 /* Record the value of a region of memory whose address is ADDR and
487 length is LEN to record_full_arch_list. */
490 record_full_arch_list_add_mem (CORE_ADDR addr, int len)
492 struct record_full_entry *rec;
494 if (record_debug > 1)
495 fprintf_unfiltered (gdb_stdlog,
496 "Process record: add mem addr = %s len = %d to "
498 paddress (target_gdbarch (), addr), len);
500 if (!addr) /* FIXME: Why? Some arch must permit it... */
503 rec = record_full_mem_alloc (addr, len);
505 if (record_read_memory (target_gdbarch (), addr,
506 record_full_get_loc (rec), len))
508 record_full_mem_release (rec);
512 record_full_arch_list_add (rec);
517 /* Add a record_full_end type struct record_full_entry to
518 record_full_arch_list. */
521 record_full_arch_list_add_end (void)
523 struct record_full_entry *rec;
525 if (record_debug > 1)
526 fprintf_unfiltered (gdb_stdlog,
527 "Process record: add end to arch list.\n");
529 rec = record_full_end_alloc ();
530 rec->u.end.sigval = GDB_SIGNAL_0;
531 rec->u.end.insn_num = ++record_full_insn_count;
533 record_full_arch_list_add (rec);
539 record_full_check_insn_num (int set_terminal)
541 if (record_full_insn_num == record_full_insn_max_num)
543 /* Ask user what to do. */
544 if (record_full_stop_at_limit)
549 target_terminal_ours ();
550 q = yquery (_("Do you want to auto delete previous execution "
551 "log entries when record/replay buffer becomes "
552 "full (record full stop-at-limit)?"));
554 target_terminal_inferior ();
556 record_full_stop_at_limit = 0;
558 error (_("Process record: stopped by user."));
564 record_full_arch_list_cleanups (void *ignore)
566 record_full_list_release (record_full_arch_list_tail);
569 /* Before inferior step (when GDB record the running message, inferior
570 only can step), GDB will call this function to record the values to
571 record_full_list. This function will call gdbarch_process_record to
572 record the running message of inferior and set them to
573 record_full_arch_list, and add it to record_full_list. */
576 record_full_message (struct regcache *regcache, enum gdb_signal signal)
579 struct gdbarch *gdbarch = get_regcache_arch (regcache);
580 struct cleanup *old_cleanups
581 = make_cleanup (record_full_arch_list_cleanups, 0);
583 record_full_arch_list_head = NULL;
584 record_full_arch_list_tail = NULL;
586 /* Check record_full_insn_num. */
587 record_full_check_insn_num (1);
589 /* If gdb sends a signal value to target_resume,
590 save it in the 'end' field of the previous instruction.
592 Maybe process record should record what really happened,
593 rather than what gdb pretends has happened.
595 So if Linux delivered the signal to the child process during
596 the record mode, we will record it and deliver it again in
599 If user says "ignore this signal" during the record mode, then
600 it will be ignored again during the replay mode (no matter if
601 the user says something different, like "deliver this signal"
602 during the replay mode).
604 User should understand that nothing he does during the replay
605 mode will change the behavior of the child. If he tries,
606 then that is a user error.
608 But we should still deliver the signal to gdb during the replay,
609 if we delivered it during the recording. Therefore we should
610 record the signal during record_full_wait, not
611 record_full_resume. */
612 if (record_full_list != &record_full_first) /* FIXME better way to check */
614 gdb_assert (record_full_list->type == record_full_end);
615 record_full_list->u.end.sigval = signal;
618 if (signal == GDB_SIGNAL_0
619 || !gdbarch_process_record_signal_p (gdbarch))
620 ret = gdbarch_process_record (gdbarch,
622 regcache_read_pc (regcache));
624 ret = gdbarch_process_record_signal (gdbarch,
629 error (_("Process record: inferior program stopped."));
631 error (_("Process record: failed to record execution log."));
633 discard_cleanups (old_cleanups);
635 record_full_list->next = record_full_arch_list_head;
636 record_full_arch_list_head->prev = record_full_list;
637 record_full_list = record_full_arch_list_tail;
639 if (record_full_insn_num == record_full_insn_max_num)
640 record_full_list_release_first ();
642 record_full_insn_num++;
647 struct record_full_message_args {
648 struct regcache *regcache;
649 enum gdb_signal signal;
653 record_full_message_wrapper (void *args)
655 struct record_full_message_args *record_full_args = args;
657 return record_full_message (record_full_args->regcache,
658 record_full_args->signal);
662 record_full_message_wrapper_safe (struct regcache *regcache,
663 enum gdb_signal signal)
665 struct record_full_message_args args;
667 args.regcache = regcache;
668 args.signal = signal;
670 return catch_errors (record_full_message_wrapper, &args, NULL,
674 /* Set to 1 if record_full_store_registers and record_full_xfer_partial
675 doesn't need record. */
677 static int record_full_gdb_operation_disable = 0;
680 record_full_gdb_operation_disable_set (void)
682 struct cleanup *old_cleanups = NULL;
685 make_cleanup_restore_integer (&record_full_gdb_operation_disable);
686 record_full_gdb_operation_disable = 1;
691 /* Flag set to TRUE for target_stopped_by_watchpoint. */
692 static int record_full_hw_watchpoint = 0;
694 /* Execute one instruction from the record log. Each instruction in
695 the log will be represented by an arbitrary sequence of register
696 entries and memory entries, followed by an 'end' entry. */
699 record_full_exec_insn (struct regcache *regcache,
700 struct gdbarch *gdbarch,
701 struct record_full_entry *entry)
705 case record_full_reg: /* reg */
707 gdb_byte reg[MAX_REGISTER_SIZE];
709 if (record_debug > 1)
710 fprintf_unfiltered (gdb_stdlog,
711 "Process record: record_full_reg %s to "
712 "inferior num = %d.\n",
713 host_address_to_string (entry),
716 regcache_cooked_read (regcache, entry->u.reg.num, reg);
717 regcache_cooked_write (regcache, entry->u.reg.num,
718 record_full_get_loc (entry));
719 memcpy (record_full_get_loc (entry), reg, entry->u.reg.len);
723 case record_full_mem: /* mem */
725 /* Nothing to do if the entry is flagged not_accessible. */
726 if (!entry->u.mem.mem_entry_not_accessible)
728 gdb_byte *mem = alloca (entry->u.mem.len);
730 if (record_debug > 1)
731 fprintf_unfiltered (gdb_stdlog,
732 "Process record: record_full_mem %s to "
733 "inferior addr = %s len = %d.\n",
734 host_address_to_string (entry),
735 paddress (gdbarch, entry->u.mem.addr),
738 if (record_read_memory (gdbarch,
739 entry->u.mem.addr, mem, entry->u.mem.len))
740 entry->u.mem.mem_entry_not_accessible = 1;
743 if (target_write_memory (entry->u.mem.addr,
744 record_full_get_loc (entry),
747 entry->u.mem.mem_entry_not_accessible = 1;
749 warning (_("Process record: error writing memory at "
750 "addr = %s len = %d."),
751 paddress (gdbarch, entry->u.mem.addr),
756 memcpy (record_full_get_loc (entry), mem,
759 /* We've changed memory --- check if a hardware
760 watchpoint should trap. Note that this
761 presently assumes the target beneath supports
762 continuable watchpoints. On non-continuable
763 watchpoints target, we'll want to check this
764 _before_ actually doing the memory change, and
765 not doing the change at all if the watchpoint
767 if (hardware_watchpoint_inserted_in_range
768 (get_regcache_aspace (regcache),
769 entry->u.mem.addr, entry->u.mem.len))
770 record_full_hw_watchpoint = 1;
779 static void record_full_restore (void);
781 /* Asynchronous signal handle registered as event loop source for when
782 we have pending events ready to be passed to the core. */
784 static struct async_event_handler *record_full_async_inferior_event_token;
787 record_full_async_inferior_event_handler (gdb_client_data data)
789 inferior_event_handler (INF_REG_EVENT, NULL);
792 /* Open the process record target. */
795 record_full_core_open_1 (const char *name, int from_tty)
797 struct regcache *regcache = get_current_regcache ();
798 int regnum = gdbarch_num_regs (get_regcache_arch (regcache));
801 /* Get record_full_core_regbuf. */
802 target_fetch_registers (regcache, -1);
803 record_full_core_regbuf = xmalloc (MAX_REGISTER_SIZE * regnum);
804 for (i = 0; i < regnum; i ++)
805 regcache_raw_collect (regcache, i,
806 record_full_core_regbuf + MAX_REGISTER_SIZE * i);
808 /* Get record_full_core_start and record_full_core_end. */
809 if (build_section_table (core_bfd, &record_full_core_start,
810 &record_full_core_end))
812 xfree (record_full_core_regbuf);
813 record_full_core_regbuf = NULL;
814 error (_("\"%s\": Can't find sections: %s"),
815 bfd_get_filename (core_bfd), bfd_errmsg (bfd_get_error ()));
818 push_target (&record_full_core_ops);
819 record_full_restore ();
822 /* "to_open" target method for 'live' processes. */
825 record_full_open_1 (const char *name, int from_tty)
828 fprintf_unfiltered (gdb_stdlog, "Process record: record_full_open\n");
831 if (!target_has_execution)
832 error (_("Process record: the program is not being run."));
834 error (_("Process record target can't debug inferior in non-stop mode "
837 if (!gdbarch_process_record_p (target_gdbarch ()))
838 error (_("Process record: the current architecture doesn't support "
839 "record function."));
841 push_target (&record_full_ops);
844 static void record_full_init_record_breakpoints (void);
846 /* "to_open" target method. Open the process record target. */
849 record_full_open (const char *name, int from_tty)
851 struct target_ops *t;
854 fprintf_unfiltered (gdb_stdlog, "Process record: record_full_open\n");
859 record_full_insn_num = 0;
860 record_full_insn_count = 0;
861 record_full_list = &record_full_first;
862 record_full_list->next = NULL;
865 record_full_core_open_1 (name, from_tty);
867 record_full_open_1 (name, from_tty);
869 /* Register extra event sources in the event loop. */
870 record_full_async_inferior_event_token
871 = create_async_event_handler (record_full_async_inferior_event_handler,
874 record_full_init_record_breakpoints ();
876 observer_notify_record_changed (current_inferior (), 1);
879 /* "to_close" target method. Close the process record target. */
882 record_full_close (struct target_ops *self)
884 struct record_full_core_buf_entry *entry;
887 fprintf_unfiltered (gdb_stdlog, "Process record: record_full_close\n");
889 record_full_list_release (record_full_list);
891 /* Release record_full_core_regbuf. */
892 if (record_full_core_regbuf)
894 xfree (record_full_core_regbuf);
895 record_full_core_regbuf = NULL;
898 /* Release record_full_core_buf_list. */
899 if (record_full_core_buf_list)
901 for (entry = record_full_core_buf_list->prev; entry;
904 xfree (record_full_core_buf_list);
905 record_full_core_buf_list = entry;
907 record_full_core_buf_list = NULL;
910 if (record_full_async_inferior_event_token)
911 delete_async_event_handler (&record_full_async_inferior_event_token);
914 static int record_full_resume_step = 0;
916 /* True if we've been resumed, and so each record_full_wait call should
917 advance execution. If this is false, record_full_wait will return a
918 TARGET_WAITKIND_IGNORE. */
919 static int record_full_resumed = 0;
921 /* The execution direction of the last resume we got. This is
922 necessary for async mode. Vis (order is not strictly accurate):
924 1. user has the global execution direction set to forward
925 2. user does a reverse-step command
926 3. record_full_resume is called with global execution direction
927 temporarily switched to reverse
928 4. GDB's execution direction is reverted back to forward
929 5. target record notifies event loop there's an event to handle
930 6. infrun asks the target which direction was it going, and switches
931 the global execution direction accordingly (to reverse)
932 7. infrun polls an event out of the record target, and handles it
933 8. GDB goes back to the event loop, and goto #4.
935 static enum exec_direction_kind record_full_execution_dir = EXEC_FORWARD;
937 /* "to_resume" target method. Resume the process record target. */
940 record_full_resume (struct target_ops *ops, ptid_t ptid, int step,
941 enum gdb_signal signal)
943 record_full_resume_step = step;
944 record_full_resumed = 1;
945 record_full_execution_dir = execution_direction;
947 if (!RECORD_FULL_IS_REPLAY)
949 struct gdbarch *gdbarch = target_thread_architecture (ptid);
951 record_full_message (get_current_regcache (), signal);
955 /* This is not hard single step. */
956 if (!gdbarch_software_single_step_p (gdbarch))
958 /* This is a normal continue. */
963 /* This arch support soft sigle step. */
964 if (single_step_breakpoints_inserted ())
966 /* This is a soft single step. */
967 record_full_resume_step = 1;
971 /* This is a continue.
972 Try to insert a soft single step breakpoint. */
973 if (!gdbarch_software_single_step (gdbarch,
974 get_current_frame ()))
976 /* This system don't want use soft single step.
977 Use hard sigle step. */
984 /* Make sure the target beneath reports all signals. */
985 target_pass_signals (0, NULL);
987 ops->beneath->to_resume (ops->beneath, ptid, step, signal);
990 /* We are about to start executing the inferior (or simulate it),
991 let's register it with the event loop. */
992 if (target_can_async_p ())
994 target_async (inferior_event_handler, 0);
995 /* Notify the event loop there's an event to wait for. We do
996 most of the work in record_full_wait. */
997 mark_async_event_handler (record_full_async_inferior_event_token);
1001 static int record_full_get_sig = 0;
1003 /* SIGINT signal handler, registered by "to_wait" method. */
1006 record_full_sig_handler (int signo)
1009 fprintf_unfiltered (gdb_stdlog, "Process record: get a signal\n");
1011 /* It will break the running inferior in replay mode. */
1012 record_full_resume_step = 1;
1014 /* It will let record_full_wait set inferior status to get the signal
1016 record_full_get_sig = 1;
1020 record_full_wait_cleanups (void *ignore)
1022 if (execution_direction == EXEC_REVERSE)
1024 if (record_full_list->next)
1025 record_full_list = record_full_list->next;
1028 record_full_list = record_full_list->prev;
1031 /* "to_wait" target method for process record target.
1033 In record mode, the target is always run in singlestep mode
1034 (even when gdb says to continue). The to_wait method intercepts
1035 the stop events and determines which ones are to be passed on to
1036 gdb. Most stop events are just singlestep events that gdb is not
1037 to know about, so the to_wait method just records them and keeps
1040 In replay mode, this function emulates the recorded execution log,
1041 one instruction at a time (forward or backward), and determines
1045 record_full_wait_1 (struct target_ops *ops,
1046 ptid_t ptid, struct target_waitstatus *status,
1049 struct cleanup *set_cleanups = record_full_gdb_operation_disable_set ();
1052 fprintf_unfiltered (gdb_stdlog,
1053 "Process record: record_full_wait "
1054 "record_full_resume_step = %d, "
1055 "record_full_resumed = %d, direction=%s\n",
1056 record_full_resume_step, record_full_resumed,
1057 record_full_execution_dir == EXEC_FORWARD
1058 ? "forward" : "reverse");
1060 if (!record_full_resumed)
1062 gdb_assert ((options & TARGET_WNOHANG) != 0);
1064 /* No interesting event. */
1065 status->kind = TARGET_WAITKIND_IGNORE;
1066 return minus_one_ptid;
1069 record_full_get_sig = 0;
1070 signal (SIGINT, record_full_sig_handler);
1072 if (!RECORD_FULL_IS_REPLAY && ops != &record_full_core_ops)
1074 if (record_full_resume_step)
1076 /* This is a single step. */
1077 return ops->beneath->to_wait (ops->beneath, ptid, status, options);
1081 /* This is not a single step. */
1084 struct gdbarch *gdbarch = target_thread_architecture (inferior_ptid);
1088 ret = ops->beneath->to_wait (ops->beneath, ptid, status, options);
1089 if (status->kind == TARGET_WAITKIND_IGNORE)
1092 fprintf_unfiltered (gdb_stdlog,
1093 "Process record: record_full_wait "
1094 "target beneath not done yet\n");
1098 if (single_step_breakpoints_inserted ())
1099 remove_single_step_breakpoints ();
1101 if (record_full_resume_step)
1104 /* Is this a SIGTRAP? */
1105 if (status->kind == TARGET_WAITKIND_STOPPED
1106 && status->value.sig == GDB_SIGNAL_TRAP)
1108 struct regcache *regcache;
1109 struct address_space *aspace;
1111 /* Yes -- this is likely our single-step finishing,
1112 but check if there's any reason the core would be
1113 interested in the event. */
1115 registers_changed ();
1116 regcache = get_current_regcache ();
1117 tmp_pc = regcache_read_pc (regcache);
1118 aspace = get_regcache_aspace (regcache);
1120 if (target_stopped_by_watchpoint ())
1122 /* Always interested in watchpoints. */
1124 else if (breakpoint_inserted_here_p (aspace, tmp_pc))
1126 /* There is a breakpoint here. Let the core
1128 if (software_breakpoint_inserted_here_p (aspace, tmp_pc))
1130 struct gdbarch *gdbarch
1131 = get_regcache_arch (regcache);
1132 CORE_ADDR decr_pc_after_break
1133 = target_decr_pc_after_break (gdbarch);
1134 if (decr_pc_after_break)
1135 regcache_write_pc (regcache,
1136 tmp_pc + decr_pc_after_break);
1141 /* This is a single-step trap. Record the
1142 insn and issue another step.
1143 FIXME: this part can be a random SIGTRAP too.
1144 But GDB cannot handle it. */
1147 if (!record_full_message_wrapper_safe (regcache,
1150 status->kind = TARGET_WAITKIND_STOPPED;
1151 status->value.sig = GDB_SIGNAL_0;
1155 if (gdbarch_software_single_step_p (gdbarch))
1157 /* Try to insert the software single step breakpoint.
1158 If insert success, set step to 0. */
1159 set_executing (inferior_ptid, 0);
1160 reinit_frame_cache ();
1161 if (gdbarch_software_single_step (gdbarch,
1162 get_current_frame ()))
1164 set_executing (inferior_ptid, 1);
1168 fprintf_unfiltered (gdb_stdlog,
1169 "Process record: record_full_wait "
1170 "issuing one more step in the "
1171 "target beneath\n");
1172 ops->beneath->to_resume (ops->beneath, ptid, step,
1178 /* The inferior is broken by a breakpoint or a signal. */
1187 struct regcache *regcache = get_current_regcache ();
1188 struct gdbarch *gdbarch = get_regcache_arch (regcache);
1189 struct address_space *aspace = get_regcache_aspace (regcache);
1190 int continue_flag = 1;
1191 int first_record_full_end = 1;
1192 struct cleanup *old_cleanups
1193 = make_cleanup (record_full_wait_cleanups, 0);
1196 record_full_hw_watchpoint = 0;
1197 status->kind = TARGET_WAITKIND_STOPPED;
1199 /* Check breakpoint when forward execute. */
1200 if (execution_direction == EXEC_FORWARD)
1202 tmp_pc = regcache_read_pc (regcache);
1203 if (breakpoint_inserted_here_p (aspace, tmp_pc))
1205 int decr_pc_after_break = target_decr_pc_after_break (gdbarch);
1208 fprintf_unfiltered (gdb_stdlog,
1209 "Process record: break at %s.\n",
1210 paddress (gdbarch, tmp_pc));
1212 if (decr_pc_after_break
1213 && !record_full_resume_step
1214 && software_breakpoint_inserted_here_p (aspace, tmp_pc))
1215 regcache_write_pc (regcache,
1216 tmp_pc + decr_pc_after_break);
1221 /* If GDB is in terminal_inferior mode, it will not get the signal.
1222 And in GDB replay mode, GDB doesn't need to be in terminal_inferior
1223 mode, because inferior will not executed.
1224 Then set it to terminal_ours to make GDB get the signal. */
1225 target_terminal_ours ();
1227 /* In EXEC_FORWARD mode, record_full_list points to the tail of prev
1229 if (execution_direction == EXEC_FORWARD && record_full_list->next)
1230 record_full_list = record_full_list->next;
1232 /* Loop over the record_full_list, looking for the next place to
1236 /* Check for beginning and end of log. */
1237 if (execution_direction == EXEC_REVERSE
1238 && record_full_list == &record_full_first)
1240 /* Hit beginning of record log in reverse. */
1241 status->kind = TARGET_WAITKIND_NO_HISTORY;
1244 if (execution_direction != EXEC_REVERSE && !record_full_list->next)
1246 /* Hit end of record log going forward. */
1247 status->kind = TARGET_WAITKIND_NO_HISTORY;
1251 record_full_exec_insn (regcache, gdbarch, record_full_list);
1253 if (record_full_list->type == record_full_end)
1255 if (record_debug > 1)
1256 fprintf_unfiltered (gdb_stdlog,
1257 "Process record: record_full_end %s to "
1259 host_address_to_string (record_full_list));
1261 if (first_record_full_end && execution_direction == EXEC_REVERSE)
1263 /* When reverse excute, the first record_full_end is the
1264 part of current instruction. */
1265 first_record_full_end = 0;
1269 /* In EXEC_REVERSE mode, this is the record_full_end of prev
1271 In EXEC_FORWARD mode, this is the record_full_end of
1272 current instruction. */
1274 if (record_full_resume_step)
1276 if (record_debug > 1)
1277 fprintf_unfiltered (gdb_stdlog,
1278 "Process record: step.\n");
1282 /* check breakpoint */
1283 tmp_pc = regcache_read_pc (regcache);
1284 if (breakpoint_inserted_here_p (aspace, tmp_pc))
1286 int decr_pc_after_break
1287 = target_decr_pc_after_break (gdbarch);
1290 fprintf_unfiltered (gdb_stdlog,
1291 "Process record: break "
1293 paddress (gdbarch, tmp_pc));
1294 if (decr_pc_after_break
1295 && execution_direction == EXEC_FORWARD
1296 && !record_full_resume_step
1297 && software_breakpoint_inserted_here_p (aspace,
1299 regcache_write_pc (regcache,
1300 tmp_pc + decr_pc_after_break);
1304 if (record_full_hw_watchpoint)
1307 fprintf_unfiltered (gdb_stdlog,
1308 "Process record: hit hw "
1312 /* Check target signal */
1313 if (record_full_list->u.end.sigval != GDB_SIGNAL_0)
1314 /* FIXME: better way to check */
1321 if (execution_direction == EXEC_REVERSE)
1323 if (record_full_list->prev)
1324 record_full_list = record_full_list->prev;
1328 if (record_full_list->next)
1329 record_full_list = record_full_list->next;
1333 while (continue_flag);
1336 if (record_full_get_sig)
1337 status->value.sig = GDB_SIGNAL_INT;
1338 else if (record_full_list->u.end.sigval != GDB_SIGNAL_0)
1339 /* FIXME: better way to check */
1340 status->value.sig = record_full_list->u.end.sigval;
1342 status->value.sig = GDB_SIGNAL_TRAP;
1344 discard_cleanups (old_cleanups);
1347 signal (SIGINT, handle_sigint);
1349 do_cleanups (set_cleanups);
1350 return inferior_ptid;
1354 record_full_wait (struct target_ops *ops,
1355 ptid_t ptid, struct target_waitstatus *status,
1360 return_ptid = record_full_wait_1 (ops, ptid, status, options);
1361 if (status->kind != TARGET_WAITKIND_IGNORE)
1363 /* We're reporting a stop. Make sure any spurious
1364 target_wait(WNOHANG) doesn't advance the target until the
1365 core wants us resumed again. */
1366 record_full_resumed = 0;
1372 record_full_stopped_by_watchpoint (struct target_ops *ops)
1374 if (RECORD_FULL_IS_REPLAY)
1375 return record_full_hw_watchpoint;
1377 return ops->beneath->to_stopped_by_watchpoint (ops->beneath);
1381 record_full_stopped_data_address (struct target_ops *ops, CORE_ADDR *addr_p)
1383 if (RECORD_FULL_IS_REPLAY)
1386 return ops->beneath->to_stopped_data_address (ops->beneath, addr_p);
1389 /* Record registers change (by user or by GDB) to list as an instruction. */
1392 record_full_registers_change (struct regcache *regcache, int regnum)
1394 /* Check record_full_insn_num. */
1395 record_full_check_insn_num (0);
1397 record_full_arch_list_head = NULL;
1398 record_full_arch_list_tail = NULL;
1404 for (i = 0; i < gdbarch_num_regs (get_regcache_arch (regcache)); i++)
1406 if (record_full_arch_list_add_reg (regcache, i))
1408 record_full_list_release (record_full_arch_list_tail);
1409 error (_("Process record: failed to record execution log."));
1415 if (record_full_arch_list_add_reg (regcache, regnum))
1417 record_full_list_release (record_full_arch_list_tail);
1418 error (_("Process record: failed to record execution log."));
1421 if (record_full_arch_list_add_end ())
1423 record_full_list_release (record_full_arch_list_tail);
1424 error (_("Process record: failed to record execution log."));
1426 record_full_list->next = record_full_arch_list_head;
1427 record_full_arch_list_head->prev = record_full_list;
1428 record_full_list = record_full_arch_list_tail;
1430 if (record_full_insn_num == record_full_insn_max_num)
1431 record_full_list_release_first ();
1433 record_full_insn_num++;
1436 /* "to_store_registers" method for process record target. */
1439 record_full_store_registers (struct target_ops *ops,
1440 struct regcache *regcache,
1443 if (!record_full_gdb_operation_disable)
1445 if (RECORD_FULL_IS_REPLAY)
1449 /* Let user choose if he wants to write register or not. */
1452 query (_("Because GDB is in replay mode, changing the "
1453 "value of a register will make the execution "
1454 "log unusable from this point onward. "
1455 "Change all registers?"));
1458 query (_("Because GDB is in replay mode, changing the value "
1459 "of a register will make the execution log unusable "
1460 "from this point onward. Change register %s?"),
1461 gdbarch_register_name (get_regcache_arch (regcache),
1466 /* Invalidate the value of regcache that was set in function
1467 "regcache_raw_write". */
1473 i < gdbarch_num_regs (get_regcache_arch (regcache));
1475 regcache_invalidate (regcache, i);
1478 regcache_invalidate (regcache, regno);
1480 error (_("Process record canceled the operation."));
1483 /* Destroy the record from here forward. */
1484 record_full_list_release_following (record_full_list);
1487 record_full_registers_change (regcache, regno);
1489 ops->beneath->to_store_registers (ops->beneath, regcache, regno);
1492 /* "to_xfer_partial" method. Behavior is conditional on
1493 RECORD_FULL_IS_REPLAY.
1494 In replay mode, we cannot write memory unles we are willing to
1495 invalidate the record/replay log from this point forward. */
1497 static enum target_xfer_status
1498 record_full_xfer_partial (struct target_ops *ops, enum target_object object,
1499 const char *annex, gdb_byte *readbuf,
1500 const gdb_byte *writebuf, ULONGEST offset,
1501 ULONGEST len, ULONGEST *xfered_len)
1503 if (!record_full_gdb_operation_disable
1504 && (object == TARGET_OBJECT_MEMORY
1505 || object == TARGET_OBJECT_RAW_MEMORY) && writebuf)
1507 if (RECORD_FULL_IS_REPLAY)
1509 /* Let user choose if he wants to write memory or not. */
1510 if (!query (_("Because GDB is in replay mode, writing to memory "
1511 "will make the execution log unusable from this "
1512 "point onward. Write memory at address %s?"),
1513 paddress (target_gdbarch (), offset)))
1514 error (_("Process record canceled the operation."));
1516 /* Destroy the record from here forward. */
1517 record_full_list_release_following (record_full_list);
1520 /* Check record_full_insn_num */
1521 record_full_check_insn_num (0);
1523 /* Record registers change to list as an instruction. */
1524 record_full_arch_list_head = NULL;
1525 record_full_arch_list_tail = NULL;
1526 if (record_full_arch_list_add_mem (offset, len))
1528 record_full_list_release (record_full_arch_list_tail);
1530 fprintf_unfiltered (gdb_stdlog,
1531 "Process record: failed to record "
1533 return TARGET_XFER_E_IO;
1535 if (record_full_arch_list_add_end ())
1537 record_full_list_release (record_full_arch_list_tail);
1539 fprintf_unfiltered (gdb_stdlog,
1540 "Process record: failed to record "
1542 return TARGET_XFER_E_IO;
1544 record_full_list->next = record_full_arch_list_head;
1545 record_full_arch_list_head->prev = record_full_list;
1546 record_full_list = record_full_arch_list_tail;
1548 if (record_full_insn_num == record_full_insn_max_num)
1549 record_full_list_release_first ();
1551 record_full_insn_num++;
1554 return ops->beneath->to_xfer_partial (ops->beneath, object, annex,
1555 readbuf, writebuf, offset,
1559 /* This structure represents a breakpoint inserted while the record
1560 target is active. We use this to know when to install/remove
1561 breakpoints in/from the target beneath. For example, a breakpoint
1562 may be inserted while recording, but removed when not replaying nor
1563 recording. In that case, the breakpoint had not been inserted on
1564 the target beneath, so we should not try to remove it there. */
1566 struct record_full_breakpoint
1568 /* The address and address space the breakpoint was set at. */
1569 struct address_space *address_space;
1572 /* True when the breakpoint has been also installed in the target
1573 beneath. This will be false for breakpoints set during replay or
1575 int in_target_beneath;
1578 typedef struct record_full_breakpoint *record_full_breakpoint_p;
1579 DEF_VEC_P(record_full_breakpoint_p);
1581 /* The list of breakpoints inserted while the record target is
1583 VEC(record_full_breakpoint_p) *record_full_breakpoints = NULL;
1586 record_full_sync_record_breakpoints (struct bp_location *loc, void *data)
1588 if (loc->loc_type != bp_loc_software_breakpoint)
1593 struct record_full_breakpoint *bp = XNEW (struct record_full_breakpoint);
1595 bp->addr = loc->target_info.placed_address;
1596 bp->address_space = loc->target_info.placed_address_space;
1598 bp->in_target_beneath = 1;
1600 VEC_safe_push (record_full_breakpoint_p, record_full_breakpoints, bp);
1604 /* Sync existing breakpoints to record_full_breakpoints. */
1607 record_full_init_record_breakpoints (void)
1609 VEC_free (record_full_breakpoint_p, record_full_breakpoints);
1611 iterate_over_bp_locations (record_full_sync_record_breakpoints);
1614 /* Behavior is conditional on RECORD_FULL_IS_REPLAY. We will not actually
1615 insert or remove breakpoints in the real target when replaying, nor
1619 record_full_insert_breakpoint (struct target_ops *ops,
1620 struct gdbarch *gdbarch,
1621 struct bp_target_info *bp_tgt)
1623 struct record_full_breakpoint *bp;
1624 int in_target_beneath = 0;
1626 if (!RECORD_FULL_IS_REPLAY)
1628 /* When recording, we currently always single-step, so we don't
1629 really need to install regular breakpoints in the inferior.
1630 However, we do have to insert software single-step
1631 breakpoints, in case the target can't hardware step. To keep
1632 things single, we always insert. */
1633 struct cleanup *old_cleanups;
1636 old_cleanups = record_full_gdb_operation_disable_set ();
1637 ret = ops->beneath->to_insert_breakpoint (ops->beneath, gdbarch, bp_tgt);
1638 do_cleanups (old_cleanups);
1643 in_target_beneath = 1;
1646 bp = XNEW (struct record_full_breakpoint);
1647 bp->addr = bp_tgt->placed_address;
1648 bp->address_space = bp_tgt->placed_address_space;
1649 bp->in_target_beneath = in_target_beneath;
1650 VEC_safe_push (record_full_breakpoint_p, record_full_breakpoints, bp);
1654 /* "to_remove_breakpoint" method for process record target. */
1657 record_full_remove_breakpoint (struct target_ops *ops,
1658 struct gdbarch *gdbarch,
1659 struct bp_target_info *bp_tgt)
1661 struct record_full_breakpoint *bp;
1665 VEC_iterate (record_full_breakpoint_p,
1666 record_full_breakpoints, ix, bp);
1669 if (bp->addr == bp_tgt->placed_address
1670 && bp->address_space == bp_tgt->placed_address_space)
1672 if (bp->in_target_beneath)
1674 struct cleanup *old_cleanups;
1677 old_cleanups = record_full_gdb_operation_disable_set ();
1678 ret = ops->beneath->to_remove_breakpoint (ops->beneath, gdbarch,
1680 do_cleanups (old_cleanups);
1686 VEC_unordered_remove (record_full_breakpoint_p,
1687 record_full_breakpoints, ix);
1692 gdb_assert_not_reached ("removing unknown breakpoint");
1695 /* "to_can_execute_reverse" method for process record target. */
1698 record_full_can_execute_reverse (struct target_ops *self)
1703 /* "to_get_bookmark" method for process record and prec over core. */
1706 record_full_get_bookmark (struct target_ops *self, const char *args,
1711 /* Return stringified form of instruction count. */
1712 if (record_full_list && record_full_list->type == record_full_end)
1713 ret = xstrdup (pulongest (record_full_list->u.end.insn_num));
1718 fprintf_unfiltered (gdb_stdlog,
1719 "record_full_get_bookmark returns %s\n", ret);
1721 fprintf_unfiltered (gdb_stdlog,
1722 "record_full_get_bookmark returns NULL\n");
1724 return (gdb_byte *) ret;
1727 /* "to_goto_bookmark" method for process record and prec over core. */
1730 record_full_goto_bookmark (struct target_ops *self,
1731 const gdb_byte *raw_bookmark, int from_tty)
1733 const char *bookmark = (const char *) raw_bookmark;
1734 struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
1737 fprintf_unfiltered (gdb_stdlog,
1738 "record_full_goto_bookmark receives %s\n", bookmark);
1740 if (bookmark[0] == '\'' || bookmark[0] == '\"')
1744 if (bookmark[strlen (bookmark) - 1] != bookmark[0])
1745 error (_("Unbalanced quotes: %s"), bookmark);
1748 copy = savestring (bookmark + 1, strlen (bookmark) - 2);
1749 make_cleanup (xfree, copy);
1753 record_goto (bookmark);
1755 do_cleanups (cleanup);
1758 static enum exec_direction_kind
1759 record_full_execution_direction (struct target_ops *self)
1761 return record_full_execution_dir;
1765 record_full_info (struct target_ops *self)
1767 struct record_full_entry *p;
1769 if (RECORD_FULL_IS_REPLAY)
1770 printf_filtered (_("Replay mode:\n"));
1772 printf_filtered (_("Record mode:\n"));
1774 /* Find entry for first actual instruction in the log. */
1775 for (p = record_full_first.next;
1776 p != NULL && p->type != record_full_end;
1780 /* Do we have a log at all? */
1781 if (p != NULL && p->type == record_full_end)
1783 /* Display instruction number for first instruction in the log. */
1784 printf_filtered (_("Lowest recorded instruction number is %s.\n"),
1785 pulongest (p->u.end.insn_num));
1787 /* If in replay mode, display where we are in the log. */
1788 if (RECORD_FULL_IS_REPLAY)
1789 printf_filtered (_("Current instruction number is %s.\n"),
1790 pulongest (record_full_list->u.end.insn_num));
1792 /* Display instruction number for last instruction in the log. */
1793 printf_filtered (_("Highest recorded instruction number is %s.\n"),
1794 pulongest (record_full_insn_count));
1796 /* Display log count. */
1797 printf_filtered (_("Log contains %u instructions.\n"),
1798 record_full_insn_num);
1801 printf_filtered (_("No instructions have been logged.\n"));
1803 /* Display max log size. */
1804 printf_filtered (_("Max logged instructions is %u.\n"),
1805 record_full_insn_max_num);
1808 /* The "to_record_delete" target method. */
1811 record_full_delete (struct target_ops *self)
1813 record_full_list_release_following (record_full_list);
1816 /* The "to_record_is_replaying" target method. */
1819 record_full_is_replaying (struct target_ops *self)
1821 return RECORD_FULL_IS_REPLAY;
1824 /* Go to a specific entry. */
1827 record_full_goto_entry (struct record_full_entry *p)
1830 error (_("Target insn not found."));
1831 else if (p == record_full_list)
1832 error (_("Already at target insn."));
1833 else if (p->u.end.insn_num > record_full_list->u.end.insn_num)
1835 printf_filtered (_("Go forward to insn number %s\n"),
1836 pulongest (p->u.end.insn_num));
1837 record_full_goto_insn (p, EXEC_FORWARD);
1841 printf_filtered (_("Go backward to insn number %s\n"),
1842 pulongest (p->u.end.insn_num));
1843 record_full_goto_insn (p, EXEC_REVERSE);
1846 registers_changed ();
1847 reinit_frame_cache ();
1848 print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1);
1851 /* The "to_goto_record_begin" target method. */
1854 record_full_goto_begin (struct target_ops *self)
1856 struct record_full_entry *p = NULL;
1858 for (p = &record_full_first; p != NULL; p = p->next)
1859 if (p->type == record_full_end)
1862 record_full_goto_entry (p);
1865 /* The "to_goto_record_end" target method. */
1868 record_full_goto_end (struct target_ops *self)
1870 struct record_full_entry *p = NULL;
1872 for (p = record_full_list; p->next != NULL; p = p->next)
1874 for (; p!= NULL; p = p->prev)
1875 if (p->type == record_full_end)
1878 record_full_goto_entry (p);
1881 /* The "to_goto_record" target method. */
1884 record_full_goto (struct target_ops *self, ULONGEST target_insn)
1886 struct record_full_entry *p = NULL;
1888 for (p = &record_full_first; p != NULL; p = p->next)
1889 if (p->type == record_full_end && p->u.end.insn_num == target_insn)
1892 record_full_goto_entry (p);
1896 init_record_full_ops (void)
1898 record_full_ops.to_shortname = "record-full";
1899 record_full_ops.to_longname = "Process record and replay target";
1900 record_full_ops.to_doc =
1901 "Log program while executing and replay execution from log.";
1902 record_full_ops.to_open = record_full_open;
1903 record_full_ops.to_close = record_full_close;
1904 record_full_ops.to_resume = record_full_resume;
1905 record_full_ops.to_wait = record_full_wait;
1906 record_full_ops.to_disconnect = record_disconnect;
1907 record_full_ops.to_detach = record_detach;
1908 record_full_ops.to_mourn_inferior = record_mourn_inferior;
1909 record_full_ops.to_kill = record_kill;
1910 record_full_ops.to_store_registers = record_full_store_registers;
1911 record_full_ops.to_xfer_partial = record_full_xfer_partial;
1912 record_full_ops.to_insert_breakpoint = record_full_insert_breakpoint;
1913 record_full_ops.to_remove_breakpoint = record_full_remove_breakpoint;
1914 record_full_ops.to_stopped_by_watchpoint = record_full_stopped_by_watchpoint;
1915 record_full_ops.to_stopped_data_address = record_full_stopped_data_address;
1916 record_full_ops.to_can_execute_reverse = record_full_can_execute_reverse;
1917 record_full_ops.to_stratum = record_stratum;
1918 /* Add bookmark target methods. */
1919 record_full_ops.to_get_bookmark = record_full_get_bookmark;
1920 record_full_ops.to_goto_bookmark = record_full_goto_bookmark;
1921 record_full_ops.to_execution_direction = record_full_execution_direction;
1922 record_full_ops.to_info_record = record_full_info;
1923 record_full_ops.to_save_record = record_full_save;
1924 record_full_ops.to_delete_record = record_full_delete;
1925 record_full_ops.to_record_is_replaying = record_full_is_replaying;
1926 record_full_ops.to_goto_record_begin = record_full_goto_begin;
1927 record_full_ops.to_goto_record_end = record_full_goto_end;
1928 record_full_ops.to_goto_record = record_full_goto;
1929 record_full_ops.to_magic = OPS_MAGIC;
1932 /* "to_resume" method for prec over corefile. */
1935 record_full_core_resume (struct target_ops *ops, ptid_t ptid, int step,
1936 enum gdb_signal signal)
1938 record_full_resume_step = step;
1939 record_full_resumed = 1;
1940 record_full_execution_dir = execution_direction;
1942 /* We are about to start executing the inferior (or simulate it),
1943 let's register it with the event loop. */
1944 if (target_can_async_p ())
1946 target_async (inferior_event_handler, 0);
1948 /* Notify the event loop there's an event to wait for. */
1949 mark_async_event_handler (record_full_async_inferior_event_token);
1953 /* "to_kill" method for prec over corefile. */
1956 record_full_core_kill (struct target_ops *ops)
1959 fprintf_unfiltered (gdb_stdlog, "Process record: record_full_core_kill\n");
1961 unpush_target (&record_full_core_ops);
1964 /* "to_fetch_registers" method for prec over corefile. */
1967 record_full_core_fetch_registers (struct target_ops *ops,
1968 struct regcache *regcache,
1973 int num = gdbarch_num_regs (get_regcache_arch (regcache));
1976 for (i = 0; i < num; i ++)
1977 regcache_raw_supply (regcache, i,
1978 record_full_core_regbuf + MAX_REGISTER_SIZE * i);
1981 regcache_raw_supply (regcache, regno,
1982 record_full_core_regbuf + MAX_REGISTER_SIZE * regno);
1985 /* "to_prepare_to_store" method for prec over corefile. */
1988 record_full_core_prepare_to_store (struct target_ops *self,
1989 struct regcache *regcache)
1993 /* "to_store_registers" method for prec over corefile. */
1996 record_full_core_store_registers (struct target_ops *ops,
1997 struct regcache *regcache,
2000 if (record_full_gdb_operation_disable)
2001 regcache_raw_collect (regcache, regno,
2002 record_full_core_regbuf + MAX_REGISTER_SIZE * regno);
2004 error (_("You can't do that without a process to debug."));
2007 /* "to_xfer_partial" method for prec over corefile. */
2009 static enum target_xfer_status
2010 record_full_core_xfer_partial (struct target_ops *ops,
2011 enum target_object object,
2012 const char *annex, gdb_byte *readbuf,
2013 const gdb_byte *writebuf, ULONGEST offset,
2014 ULONGEST len, ULONGEST *xfered_len)
2016 if (object == TARGET_OBJECT_MEMORY)
2018 if (record_full_gdb_operation_disable || !writebuf)
2020 struct target_section *p;
2022 for (p = record_full_core_start; p < record_full_core_end; p++)
2024 if (offset >= p->addr)
2026 struct record_full_core_buf_entry *entry;
2027 ULONGEST sec_offset;
2029 if (offset >= p->endaddr)
2032 if (offset + len > p->endaddr)
2033 len = p->endaddr - offset;
2035 sec_offset = offset - p->addr;
2037 /* Read readbuf or write writebuf p, offset, len. */
2039 if (p->the_bfd_section->flags & SEC_CONSTRUCTOR
2040 || (p->the_bfd_section->flags & SEC_HAS_CONTENTS) == 0)
2043 memset (readbuf, 0, len);
2046 return TARGET_XFER_OK;
2048 /* Get record_full_core_buf_entry. */
2049 for (entry = record_full_core_buf_list; entry;
2050 entry = entry->prev)
2057 /* Add a new entry. */
2058 entry = (struct record_full_core_buf_entry *)
2060 (sizeof (struct record_full_core_buf_entry));
2062 if (!bfd_malloc_and_get_section
2063 (p->the_bfd_section->owner,
2068 return TARGET_XFER_EOF;
2070 entry->prev = record_full_core_buf_list;
2071 record_full_core_buf_list = entry;
2074 memcpy (entry->buf + sec_offset, writebuf,
2080 return ops->beneath->to_xfer_partial (ops->beneath,
2086 memcpy (readbuf, entry->buf + sec_offset,
2091 return TARGET_XFER_OK;
2095 return TARGET_XFER_E_IO;
2098 error (_("You can't do that without a process to debug."));
2101 return ops->beneath->to_xfer_partial (ops->beneath, object, annex,
2102 readbuf, writebuf, offset, len,
2106 /* "to_insert_breakpoint" method for prec over corefile. */
2109 record_full_core_insert_breakpoint (struct target_ops *ops,
2110 struct gdbarch *gdbarch,
2111 struct bp_target_info *bp_tgt)
2116 /* "to_remove_breakpoint" method for prec over corefile. */
2119 record_full_core_remove_breakpoint (struct target_ops *ops,
2120 struct gdbarch *gdbarch,
2121 struct bp_target_info *bp_tgt)
2126 /* "to_has_execution" method for prec over corefile. */
2129 record_full_core_has_execution (struct target_ops *ops, ptid_t the_ptid)
2135 init_record_full_core_ops (void)
2137 record_full_core_ops.to_shortname = "record-core";
2138 record_full_core_ops.to_longname = "Process record and replay target";
2139 record_full_core_ops.to_doc =
2140 "Log program while executing and replay execution from log.";
2141 record_full_core_ops.to_open = record_full_open;
2142 record_full_core_ops.to_close = record_full_close;
2143 record_full_core_ops.to_resume = record_full_core_resume;
2144 record_full_core_ops.to_wait = record_full_wait;
2145 record_full_core_ops.to_kill = record_full_core_kill;
2146 record_full_core_ops.to_fetch_registers = record_full_core_fetch_registers;
2147 record_full_core_ops.to_prepare_to_store = record_full_core_prepare_to_store;
2148 record_full_core_ops.to_store_registers = record_full_core_store_registers;
2149 record_full_core_ops.to_xfer_partial = record_full_core_xfer_partial;
2150 record_full_core_ops.to_insert_breakpoint
2151 = record_full_core_insert_breakpoint;
2152 record_full_core_ops.to_remove_breakpoint
2153 = record_full_core_remove_breakpoint;
2154 record_full_core_ops.to_stopped_by_watchpoint
2155 = record_full_stopped_by_watchpoint;
2156 record_full_core_ops.to_stopped_data_address
2157 = record_full_stopped_data_address;
2158 record_full_core_ops.to_can_execute_reverse
2159 = record_full_can_execute_reverse;
2160 record_full_core_ops.to_has_execution = record_full_core_has_execution;
2161 record_full_core_ops.to_stratum = record_stratum;
2162 /* Add bookmark target methods. */
2163 record_full_core_ops.to_get_bookmark = record_full_get_bookmark;
2164 record_full_core_ops.to_goto_bookmark = record_full_goto_bookmark;
2165 record_full_core_ops.to_execution_direction
2166 = record_full_execution_direction;
2167 record_full_core_ops.to_info_record = record_full_info;
2168 record_full_core_ops.to_delete_record = record_full_delete;
2169 record_full_core_ops.to_record_is_replaying = record_full_is_replaying;
2170 record_full_core_ops.to_goto_record_begin = record_full_goto_begin;
2171 record_full_core_ops.to_goto_record_end = record_full_goto_end;
2172 record_full_core_ops.to_goto_record = record_full_goto;
2173 record_full_core_ops.to_magic = OPS_MAGIC;
2176 /* Record log save-file format
2177 Version 1 (never released)
2180 4 bytes: magic number htonl(0x20090829).
2181 NOTE: be sure to change whenever this file format changes!
2185 1 byte: record type (record_full_end, see enum record_full_type).
2187 1 byte: record type (record_full_reg, see enum record_full_type).
2188 8 bytes: register id (network byte order).
2189 MAX_REGISTER_SIZE bytes: register value.
2191 1 byte: record type (record_full_mem, see enum record_full_type).
2192 8 bytes: memory length (network byte order).
2193 8 bytes: memory address (network byte order).
2194 n bytes: memory value (n == memory length).
2197 4 bytes: magic number netorder32(0x20091016).
2198 NOTE: be sure to change whenever this file format changes!
2202 1 byte: record type (record_full_end, see enum record_full_type).
2204 4 bytes: instruction count
2206 1 byte: record type (record_full_reg, see enum record_full_type).
2207 4 bytes: register id (network byte order).
2208 n bytes: register value (n == actual register size).
2209 (eg. 4 bytes for x86 general registers).
2211 1 byte: record type (record_full_mem, see enum record_full_type).
2212 4 bytes: memory length (network byte order).
2213 8 bytes: memory address (network byte order).
2214 n bytes: memory value (n == memory length).
2218 /* bfdcore_read -- read bytes from a core file section. */
2221 bfdcore_read (bfd *obfd, asection *osec, void *buf, int len, int *offset)
2223 int ret = bfd_get_section_contents (obfd, osec, buf, *offset, len);
2228 error (_("Failed to read %d bytes from core file %s ('%s')."),
2229 len, bfd_get_filename (obfd),
2230 bfd_errmsg (bfd_get_error ()));
2233 static inline uint64_t
2234 netorder64 (uint64_t input)
2238 store_unsigned_integer ((gdb_byte *) &ret, sizeof (ret),
2239 BFD_ENDIAN_BIG, input);
2243 static inline uint32_t
2244 netorder32 (uint32_t input)
2248 store_unsigned_integer ((gdb_byte *) &ret, sizeof (ret),
2249 BFD_ENDIAN_BIG, input);
2253 static inline uint16_t
2254 netorder16 (uint16_t input)
2258 store_unsigned_integer ((gdb_byte *) &ret, sizeof (ret),
2259 BFD_ENDIAN_BIG, input);
2263 /* Restore the execution log from a core_bfd file. */
2265 record_full_restore (void)
2268 struct cleanup *old_cleanups;
2269 struct record_full_entry *rec;
2273 struct regcache *regcache;
2275 /* We restore the execution log from the open core bfd,
2277 if (core_bfd == NULL)
2280 /* "record_full_restore" can only be called when record list is empty. */
2281 gdb_assert (record_full_first.next == NULL);
2284 fprintf_unfiltered (gdb_stdlog, "Restoring recording from core file.\n");
2286 /* Now need to find our special note section. */
2287 osec = bfd_get_section_by_name (core_bfd, "null0");
2289 fprintf_unfiltered (gdb_stdlog, "Find precord section %s.\n",
2290 osec ? "succeeded" : "failed");
2293 osec_size = bfd_section_size (core_bfd, osec);
2295 fprintf_unfiltered (gdb_stdlog, "%s", bfd_section_name (core_bfd, osec));
2297 /* Check the magic code. */
2298 bfdcore_read (core_bfd, osec, &magic, sizeof (magic), &bfd_offset);
2299 if (magic != RECORD_FULL_FILE_MAGIC)
2300 error (_("Version mis-match or file format error in core file %s."),
2301 bfd_get_filename (core_bfd));
2303 fprintf_unfiltered (gdb_stdlog,
2304 " Reading 4-byte magic cookie "
2305 "RECORD_FULL_FILE_MAGIC (0x%s)\n",
2306 phex_nz (netorder32 (magic), 4));
2308 /* Restore the entries in recfd into record_full_arch_list_head and
2309 record_full_arch_list_tail. */
2310 record_full_arch_list_head = NULL;
2311 record_full_arch_list_tail = NULL;
2312 record_full_insn_num = 0;
2313 old_cleanups = make_cleanup (record_full_arch_list_cleanups, 0);
2314 regcache = get_current_regcache ();
2319 uint32_t regnum, len, signal, count;
2322 /* We are finished when offset reaches osec_size. */
2323 if (bfd_offset >= osec_size)
2325 bfdcore_read (core_bfd, osec, &rectype, sizeof (rectype), &bfd_offset);
2329 case record_full_reg: /* reg */
2330 /* Get register number to regnum. */
2331 bfdcore_read (core_bfd, osec, ®num,
2332 sizeof (regnum), &bfd_offset);
2333 regnum = netorder32 (regnum);
2335 rec = record_full_reg_alloc (regcache, regnum);
2338 bfdcore_read (core_bfd, osec, record_full_get_loc (rec),
2339 rec->u.reg.len, &bfd_offset);
2342 fprintf_unfiltered (gdb_stdlog,
2343 " Reading register %d (1 "
2344 "plus %lu plus %d bytes)\n",
2346 (unsigned long) sizeof (regnum),
2350 case record_full_mem: /* mem */
2352 bfdcore_read (core_bfd, osec, &len,
2353 sizeof (len), &bfd_offset);
2354 len = netorder32 (len);
2357 bfdcore_read (core_bfd, osec, &addr,
2358 sizeof (addr), &bfd_offset);
2359 addr = netorder64 (addr);
2361 rec = record_full_mem_alloc (addr, len);
2364 bfdcore_read (core_bfd, osec, record_full_get_loc (rec),
2365 rec->u.mem.len, &bfd_offset);
2368 fprintf_unfiltered (gdb_stdlog,
2369 " Reading memory %s (1 plus "
2370 "%lu plus %lu plus %d bytes)\n",
2371 paddress (get_current_arch (),
2373 (unsigned long) sizeof (addr),
2374 (unsigned long) sizeof (len),
2378 case record_full_end: /* end */
2379 rec = record_full_end_alloc ();
2380 record_full_insn_num ++;
2382 /* Get signal value. */
2383 bfdcore_read (core_bfd, osec, &signal,
2384 sizeof (signal), &bfd_offset);
2385 signal = netorder32 (signal);
2386 rec->u.end.sigval = signal;
2388 /* Get insn count. */
2389 bfdcore_read (core_bfd, osec, &count,
2390 sizeof (count), &bfd_offset);
2391 count = netorder32 (count);
2392 rec->u.end.insn_num = count;
2393 record_full_insn_count = count + 1;
2395 fprintf_unfiltered (gdb_stdlog,
2396 " Reading record_full_end (1 + "
2397 "%lu + %lu bytes), offset == %s\n",
2398 (unsigned long) sizeof (signal),
2399 (unsigned long) sizeof (count),
2400 paddress (get_current_arch (),
2405 error (_("Bad entry type in core file %s."),
2406 bfd_get_filename (core_bfd));
2410 /* Add rec to record arch list. */
2411 record_full_arch_list_add (rec);
2414 discard_cleanups (old_cleanups);
2416 /* Add record_full_arch_list_head to the end of record list. */
2417 record_full_first.next = record_full_arch_list_head;
2418 record_full_arch_list_head->prev = &record_full_first;
2419 record_full_arch_list_tail->next = NULL;
2420 record_full_list = &record_full_first;
2422 /* Update record_full_insn_max_num. */
2423 if (record_full_insn_num > record_full_insn_max_num)
2425 record_full_insn_max_num = record_full_insn_num;
2426 warning (_("Auto increase record/replay buffer limit to %u."),
2427 record_full_insn_max_num);
2431 printf_filtered (_("Restored records from core file %s.\n"),
2432 bfd_get_filename (core_bfd));
2434 print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1);
2437 /* bfdcore_write -- write bytes into a core file section. */
2440 bfdcore_write (bfd *obfd, asection *osec, void *buf, int len, int *offset)
2442 int ret = bfd_set_section_contents (obfd, osec, buf, *offset, len);
2447 error (_("Failed to write %d bytes to core file %s ('%s')."),
2448 len, bfd_get_filename (obfd),
2449 bfd_errmsg (bfd_get_error ()));
2452 /* Restore the execution log from a file. We use a modified elf
2453 corefile format, with an extra section for our data. */
2456 cmd_record_full_restore (char *args, int from_tty)
2458 core_file_command (args, from_tty);
2459 record_full_open (args, from_tty);
2463 record_full_save_cleanups (void *data)
2466 char *pathname = xstrdup (bfd_get_filename (obfd));
2468 gdb_bfd_unref (obfd);
2473 /* Save the execution log to a file. We use a modified elf corefile
2474 format, with an extra section for our data. */
2477 record_full_save (struct target_ops *self, const char *recfilename)
2479 struct record_full_entry *cur_record_full_list;
2481 struct regcache *regcache;
2482 struct gdbarch *gdbarch;
2483 struct cleanup *old_cleanups;
2484 struct cleanup *set_cleanups;
2487 asection *osec = NULL;
2490 /* Open the save file. */
2492 fprintf_unfiltered (gdb_stdlog, "Saving execution log to core file '%s'\n",
2495 /* Open the output file. */
2496 obfd = create_gcore_bfd (recfilename);
2497 old_cleanups = make_cleanup (record_full_save_cleanups, obfd);
2499 /* Save the current record entry to "cur_record_full_list". */
2500 cur_record_full_list = record_full_list;
2502 /* Get the values of regcache and gdbarch. */
2503 regcache = get_current_regcache ();
2504 gdbarch = get_regcache_arch (regcache);
2506 /* Disable the GDB operation record. */
2507 set_cleanups = record_full_gdb_operation_disable_set ();
2509 /* Reverse execute to the begin of record list. */
2512 /* Check for beginning and end of log. */
2513 if (record_full_list == &record_full_first)
2516 record_full_exec_insn (regcache, gdbarch, record_full_list);
2518 if (record_full_list->prev)
2519 record_full_list = record_full_list->prev;
2522 /* Compute the size needed for the extra bfd section. */
2523 save_size = 4; /* magic cookie */
2524 for (record_full_list = record_full_first.next; record_full_list;
2525 record_full_list = record_full_list->next)
2526 switch (record_full_list->type)
2528 case record_full_end:
2529 save_size += 1 + 4 + 4;
2531 case record_full_reg:
2532 save_size += 1 + 4 + record_full_list->u.reg.len;
2534 case record_full_mem:
2535 save_size += 1 + 4 + 8 + record_full_list->u.mem.len;
2539 /* Make the new bfd section. */
2540 osec = bfd_make_section_anyway_with_flags (obfd, "precord",
2544 error (_("Failed to create 'precord' section for corefile %s: %s"),
2546 bfd_errmsg (bfd_get_error ()));
2547 bfd_set_section_size (obfd, osec, save_size);
2548 bfd_set_section_vma (obfd, osec, 0);
2549 bfd_set_section_alignment (obfd, osec, 0);
2550 bfd_section_lma (obfd, osec) = 0;
2552 /* Save corefile state. */
2553 write_gcore_file (obfd);
2555 /* Write out the record log. */
2556 /* Write the magic code. */
2557 magic = RECORD_FULL_FILE_MAGIC;
2559 fprintf_unfiltered (gdb_stdlog,
2560 " Writing 4-byte magic cookie "
2561 "RECORD_FULL_FILE_MAGIC (0x%s)\n",
2562 phex_nz (magic, 4));
2563 bfdcore_write (obfd, osec, &magic, sizeof (magic), &bfd_offset);
2565 /* Save the entries to recfd and forward execute to the end of
2567 record_full_list = &record_full_first;
2571 if (record_full_list != &record_full_first)
2574 uint32_t regnum, len, signal, count;
2577 type = record_full_list->type;
2578 bfdcore_write (obfd, osec, &type, sizeof (type), &bfd_offset);
2580 switch (record_full_list->type)
2582 case record_full_reg: /* reg */
2584 fprintf_unfiltered (gdb_stdlog,
2585 " Writing register %d (1 "
2586 "plus %lu plus %d bytes)\n",
2587 record_full_list->u.reg.num,
2588 (unsigned long) sizeof (regnum),
2589 record_full_list->u.reg.len);
2592 regnum = netorder32 (record_full_list->u.reg.num);
2593 bfdcore_write (obfd, osec, ®num,
2594 sizeof (regnum), &bfd_offset);
2597 bfdcore_write (obfd, osec,
2598 record_full_get_loc (record_full_list),
2599 record_full_list->u.reg.len, &bfd_offset);
2602 case record_full_mem: /* mem */
2604 fprintf_unfiltered (gdb_stdlog,
2605 " Writing memory %s (1 plus "
2606 "%lu plus %lu plus %d bytes)\n",
2608 record_full_list->u.mem.addr),
2609 (unsigned long) sizeof (addr),
2610 (unsigned long) sizeof (len),
2611 record_full_list->u.mem.len);
2614 len = netorder32 (record_full_list->u.mem.len);
2615 bfdcore_write (obfd, osec, &len, sizeof (len), &bfd_offset);
2617 /* Write memaddr. */
2618 addr = netorder64 (record_full_list->u.mem.addr);
2619 bfdcore_write (obfd, osec, &addr,
2620 sizeof (addr), &bfd_offset);
2623 bfdcore_write (obfd, osec,
2624 record_full_get_loc (record_full_list),
2625 record_full_list->u.mem.len, &bfd_offset);
2628 case record_full_end:
2630 fprintf_unfiltered (gdb_stdlog,
2631 " Writing record_full_end (1 + "
2632 "%lu + %lu bytes)\n",
2633 (unsigned long) sizeof (signal),
2634 (unsigned long) sizeof (count));
2635 /* Write signal value. */
2636 signal = netorder32 (record_full_list->u.end.sigval);
2637 bfdcore_write (obfd, osec, &signal,
2638 sizeof (signal), &bfd_offset);
2640 /* Write insn count. */
2641 count = netorder32 (record_full_list->u.end.insn_num);
2642 bfdcore_write (obfd, osec, &count,
2643 sizeof (count), &bfd_offset);
2648 /* Execute entry. */
2649 record_full_exec_insn (regcache, gdbarch, record_full_list);
2651 if (record_full_list->next)
2652 record_full_list = record_full_list->next;
2657 /* Reverse execute to cur_record_full_list. */
2660 /* Check for beginning and end of log. */
2661 if (record_full_list == cur_record_full_list)
2664 record_full_exec_insn (regcache, gdbarch, record_full_list);
2666 if (record_full_list->prev)
2667 record_full_list = record_full_list->prev;
2670 do_cleanups (set_cleanups);
2671 gdb_bfd_unref (obfd);
2672 discard_cleanups (old_cleanups);
2675 printf_filtered (_("Saved core file %s with execution log.\n"),
2679 /* record_full_goto_insn -- rewind the record log (forward or backward,
2680 depending on DIR) to the given entry, changing the program state
2684 record_full_goto_insn (struct record_full_entry *entry,
2685 enum exec_direction_kind dir)
2687 struct cleanup *set_cleanups = record_full_gdb_operation_disable_set ();
2688 struct regcache *regcache = get_current_regcache ();
2689 struct gdbarch *gdbarch = get_regcache_arch (regcache);
2691 /* Assume everything is valid: we will hit the entry,
2692 and we will not hit the end of the recording. */
2694 if (dir == EXEC_FORWARD)
2695 record_full_list = record_full_list->next;
2699 record_full_exec_insn (regcache, gdbarch, record_full_list);
2700 if (dir == EXEC_REVERSE)
2701 record_full_list = record_full_list->prev;
2703 record_full_list = record_full_list->next;
2704 } while (record_full_list != entry);
2705 do_cleanups (set_cleanups);
2708 /* Alias for "target record-full". */
2711 cmd_record_full_start (char *args, int from_tty)
2713 execute_command ("target record-full", from_tty);
2717 set_record_full_insn_max_num (char *args, int from_tty,
2718 struct cmd_list_element *c)
2720 if (record_full_insn_num > record_full_insn_max_num)
2722 /* Count down record_full_insn_num while releasing records from list. */
2723 while (record_full_insn_num > record_full_insn_max_num)
2725 record_full_list_release_first ();
2726 record_full_insn_num--;
2731 /* The "set record full" command. */
2734 set_record_full_command (char *args, int from_tty)
2736 printf_unfiltered (_("\"set record full\" must be followed "
2737 "by an apporpriate subcommand.\n"));
2738 help_list (set_record_full_cmdlist, "set record full ", all_commands,
2742 /* The "show record full" command. */
2745 show_record_full_command (char *args, int from_tty)
2747 cmd_show_list (show_record_full_cmdlist, from_tty, "");
2750 /* Provide a prototype to silence -Wmissing-prototypes. */
2751 extern initialize_file_ftype _initialize_record_full;
2754 _initialize_record_full (void)
2756 struct cmd_list_element *c;
2758 /* Init record_full_first. */
2759 record_full_first.prev = NULL;
2760 record_full_first.next = NULL;
2761 record_full_first.type = record_full_end;
2763 init_record_full_ops ();
2764 add_target (&record_full_ops);
2765 add_deprecated_target_alias (&record_full_ops, "record");
2766 init_record_full_core_ops ();
2767 add_target (&record_full_core_ops);
2769 add_prefix_cmd ("full", class_obscure, cmd_record_full_start,
2770 _("Start full execution recording."), &record_full_cmdlist,
2771 "record full ", 0, &record_cmdlist);
2773 c = add_cmd ("restore", class_obscure, cmd_record_full_restore,
2774 _("Restore the execution log from a file.\n\
2775 Argument is filename. File must be created with 'record save'."),
2776 &record_full_cmdlist);
2777 set_cmd_completer (c, filename_completer);
2779 /* Deprecate the old version without "full" prefix. */
2780 c = add_alias_cmd ("restore", "full restore", class_obscure, 1,
2782 set_cmd_completer (c, filename_completer);
2783 deprecate_cmd (c, "record full restore");
2785 add_prefix_cmd ("full", class_support, set_record_full_command,
2786 _("Set record options"), &set_record_full_cmdlist,
2787 "set record full ", 0, &set_record_cmdlist);
2789 add_prefix_cmd ("full", class_support, show_record_full_command,
2790 _("Show record options"), &show_record_full_cmdlist,
2791 "show record full ", 0, &show_record_cmdlist);
2793 /* Record instructions number limit command. */
2794 add_setshow_boolean_cmd ("stop-at-limit", no_class,
2795 &record_full_stop_at_limit, _("\
2796 Set whether record/replay stops when record/replay buffer becomes full."), _("\
2797 Show whether record/replay stops when record/replay buffer becomes full."),
2798 _("Default is ON.\n\
2799 When ON, if the record/replay buffer becomes full, ask user what to do.\n\
2800 When OFF, if the record/replay buffer becomes full,\n\
2801 delete the oldest recorded instruction to make room for each new one."),
2803 &set_record_full_cmdlist, &show_record_full_cmdlist);
2805 c = add_alias_cmd ("stop-at-limit", "full stop-at-limit", no_class, 1,
2806 &set_record_cmdlist);
2807 deprecate_cmd (c, "set record full stop-at-limit");
2809 c = add_alias_cmd ("stop-at-limit", "full stop-at-limit", no_class, 1,
2810 &show_record_cmdlist);
2811 deprecate_cmd (c, "show record full stop-at-limit");
2813 add_setshow_uinteger_cmd ("insn-number-max", no_class,
2814 &record_full_insn_max_num,
2815 _("Set record/replay buffer limit."),
2816 _("Show record/replay buffer limit."), _("\
2817 Set the maximum number of instructions to be stored in the\n\
2818 record/replay buffer. A value of either \"unlimited\" or zero means no\n\
2819 limit. Default is 200000."),
2820 set_record_full_insn_max_num,
2821 NULL, &set_record_full_cmdlist,
2822 &show_record_full_cmdlist);
2824 c = add_alias_cmd ("insn-number-max", "full insn-number-max", no_class, 1,
2825 &set_record_cmdlist);
2826 deprecate_cmd (c, "set record full insn-number-max");
2828 c = add_alias_cmd ("insn-number-max", "full insn-number-max", no_class, 1,
2829 &show_record_cmdlist);
2830 deprecate_cmd (c, "show record full insn-number-max");
2832 add_setshow_boolean_cmd ("memory-query", no_class,
2833 &record_full_memory_query, _("\
2834 Set whether query if PREC cannot record memory change of next instruction."),
2836 Show whether query if PREC cannot record memory change of next instruction."),
2839 When ON, query if PREC cannot record memory change of next instruction."),
2841 &set_record_full_cmdlist,
2842 &show_record_full_cmdlist);
2844 c = add_alias_cmd ("memory-query", "full memory-query", no_class, 1,
2845 &set_record_cmdlist);
2846 deprecate_cmd (c, "set record full memory-query");
2848 c = add_alias_cmd ("memory-query", "full memory-query", no_class, 1,
2849 &show_record_cmdlist);
2850 deprecate_cmd (c, "show record full memory-query");