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"
41 /* This module implements "target record-full", also known as "process
42 record and replay". This target sits on top of a "normal" target
43 (a target that "has execution"), and provides a record and replay
44 functionality, including reverse debugging.
46 Target record has two modes: recording, and replaying.
48 In record mode, we intercept the to_resume and to_wait methods.
49 Whenever gdb resumes the target, we run the target in single step
50 mode, and we build up an execution log in which, for each executed
51 instruction, we record all changes in memory and register state.
52 This is invisible to the user, to whom it just looks like an
53 ordinary debugging session (except for performance degredation).
55 In replay mode, instead of actually letting the inferior run as a
56 process, we simulate its execution by playing back the recorded
57 execution log. For each instruction in the log, we simulate the
58 instruction's side effects by duplicating the changes that it would
59 have made on memory and registers. */
61 #define DEFAULT_RECORD_FULL_INSN_MAX_NUM 200000
63 #define RECORD_FULL_IS_REPLAY \
64 (record_full_list->next || execution_direction == EXEC_REVERSE)
66 #define RECORD_FULL_FILE_MAGIC netorder32(0x20091016)
68 /* These are the core structs of the process record functionality.
70 A record_full_entry is a record of the value change of a register
71 ("record_full_reg") or a part of memory ("record_full_mem"). And each
72 instruction must have a struct record_full_entry ("record_full_end")
73 that indicates that this is the last struct record_full_entry of this
76 Each struct record_full_entry is linked to "record_full_list" by "prev"
77 and "next" pointers. */
79 struct record_full_mem_entry
83 /* Set this flag if target memory for this entry
84 can no longer be accessed. */
85 int mem_entry_not_accessible;
89 gdb_byte buf[sizeof (gdb_byte *)];
93 struct record_full_reg_entry
100 gdb_byte buf[2 * sizeof (gdb_byte *)];
104 struct record_full_end_entry
106 enum gdb_signal sigval;
110 enum record_full_type
117 /* This is the data structure that makes up the execution log.
119 The execution log consists of a single linked list of entries
120 of type "struct record_full_entry". It is doubly linked so that it
121 can be traversed in either direction.
123 The start of the list is anchored by a struct called
124 "record_full_first". The pointer "record_full_list" either points
125 to the last entry that was added to the list (in record mode), or to
126 the next entry in the list that will be executed (in replay mode).
128 Each list element (struct record_full_entry), in addition to next
129 and prev pointers, consists of a union of three entry types: mem,
130 reg, and end. A field called "type" determines which entry type is
131 represented by a given list element.
133 Each instruction that is added to the execution log is represented
134 by a variable number of list elements ('entries'). The instruction
135 will have one "reg" entry for each register that is changed by
136 executing the instruction (including the PC in every case). It
137 will also have one "mem" entry for each memory change. Finally,
138 each instruction will have an "end" entry that separates it from
139 the changes associated with the next instruction. */
141 struct record_full_entry
143 struct record_full_entry *prev;
144 struct record_full_entry *next;
145 enum record_full_type type;
149 struct record_full_reg_entry reg;
151 struct record_full_mem_entry mem;
153 struct record_full_end_entry end;
157 /* If true, query if PREC cannot record memory
158 change of next instruction. */
159 int record_full_memory_query = 0;
161 struct record_full_core_buf_entry
163 struct record_full_core_buf_entry *prev;
164 struct target_section *p;
168 /* Record buf with core target. */
169 static gdb_byte *record_full_core_regbuf = NULL;
170 static struct target_section *record_full_core_start;
171 static struct target_section *record_full_core_end;
172 static struct record_full_core_buf_entry *record_full_core_buf_list = NULL;
174 /* The following variables are used for managing the linked list that
175 represents the execution log.
177 record_full_first is the anchor that holds down the beginning of
180 record_full_list serves two functions:
181 1) In record mode, it anchors the end of the list.
182 2) In replay mode, it traverses the list and points to
183 the next instruction that must be emulated.
185 record_full_arch_list_head and record_full_arch_list_tail are used
186 to manage a separate list, which is used to build up the change
187 elements of the currently executing instruction during record mode.
188 When this instruction has been completely annotated in the "arch
189 list", it will be appended to the main execution log. */
191 static struct record_full_entry record_full_first;
192 static struct record_full_entry *record_full_list = &record_full_first;
193 static struct record_full_entry *record_full_arch_list_head = NULL;
194 static struct record_full_entry *record_full_arch_list_tail = NULL;
196 /* 1 ask user. 0 auto delete the last struct record_full_entry. */
197 static int record_full_stop_at_limit = 1;
198 /* Maximum allowed number of insns in execution log. */
199 static unsigned int record_full_insn_max_num
200 = DEFAULT_RECORD_FULL_INSN_MAX_NUM;
201 /* Actual count of insns presently in execution log. */
202 static unsigned int record_full_insn_num = 0;
203 /* Count of insns logged so far (may be larger
204 than count of insns presently in execution log). */
205 static ULONGEST record_full_insn_count;
207 /* The target_ops of process record. */
208 static struct target_ops record_full_ops;
209 static struct target_ops record_full_core_ops;
211 /* See record-full.h. */
214 record_full_is_used (void)
216 struct target_ops *t;
218 t = find_record_target ();
219 return (t == &record_full_ops
220 || t == &record_full_core_ops);
224 /* Command lists for "set/show record full". */
225 static struct cmd_list_element *set_record_full_cmdlist;
226 static struct cmd_list_element *show_record_full_cmdlist;
228 /* Command list for "record full". */
229 static struct cmd_list_element *record_full_cmdlist;
231 static void record_full_goto_insn (struct record_full_entry *entry,
232 enum exec_direction_kind dir);
233 static void record_full_save (const char *recfilename);
235 /* Alloc and free functions for record_full_reg, record_full_mem, and
236 record_full_end entries. */
238 /* Alloc a record_full_reg record entry. */
240 static inline struct record_full_entry *
241 record_full_reg_alloc (struct regcache *regcache, int regnum)
243 struct record_full_entry *rec;
244 struct gdbarch *gdbarch = get_regcache_arch (regcache);
246 rec = xcalloc (1, sizeof (struct record_full_entry));
247 rec->type = record_full_reg;
248 rec->u.reg.num = regnum;
249 rec->u.reg.len = register_size (gdbarch, regnum);
250 if (rec->u.reg.len > sizeof (rec->u.reg.u.buf))
251 rec->u.reg.u.ptr = (gdb_byte *) xmalloc (rec->u.reg.len);
256 /* Free a record_full_reg record entry. */
259 record_full_reg_release (struct record_full_entry *rec)
261 gdb_assert (rec->type == record_full_reg);
262 if (rec->u.reg.len > sizeof (rec->u.reg.u.buf))
263 xfree (rec->u.reg.u.ptr);
267 /* Alloc a record_full_mem record entry. */
269 static inline struct record_full_entry *
270 record_full_mem_alloc (CORE_ADDR addr, int len)
272 struct record_full_entry *rec;
274 rec = xcalloc (1, sizeof (struct record_full_entry));
275 rec->type = record_full_mem;
276 rec->u.mem.addr = addr;
277 rec->u.mem.len = len;
278 if (rec->u.mem.len > sizeof (rec->u.mem.u.buf))
279 rec->u.mem.u.ptr = (gdb_byte *) xmalloc (len);
284 /* Free a record_full_mem record entry. */
287 record_full_mem_release (struct record_full_entry *rec)
289 gdb_assert (rec->type == record_full_mem);
290 if (rec->u.mem.len > sizeof (rec->u.mem.u.buf))
291 xfree (rec->u.mem.u.ptr);
295 /* Alloc a record_full_end record entry. */
297 static inline struct record_full_entry *
298 record_full_end_alloc (void)
300 struct record_full_entry *rec;
302 rec = xcalloc (1, sizeof (struct record_full_entry));
303 rec->type = record_full_end;
308 /* Free a record_full_end record entry. */
311 record_full_end_release (struct record_full_entry *rec)
316 /* Free one record entry, any type.
317 Return entry->type, in case caller wants to know. */
319 static inline enum record_full_type
320 record_full_entry_release (struct record_full_entry *rec)
322 enum record_full_type type = rec->type;
325 case record_full_reg:
326 record_full_reg_release (rec);
328 case record_full_mem:
329 record_full_mem_release (rec);
331 case record_full_end:
332 record_full_end_release (rec);
338 /* Free all record entries in list pointed to by REC. */
341 record_full_list_release (struct record_full_entry *rec)
352 record_full_entry_release (rec->next);
355 if (rec == &record_full_first)
357 record_full_insn_num = 0;
358 record_full_first.next = NULL;
361 record_full_entry_release (rec);
364 /* Free all record entries forward of the given list position. */
367 record_full_list_release_following (struct record_full_entry *rec)
369 struct record_full_entry *tmp = rec->next;
375 if (record_full_entry_release (tmp) == record_full_end)
377 record_full_insn_num--;
378 record_full_insn_count--;
384 /* Delete the first instruction from the beginning of the log, to make
385 room for adding a new instruction at the end of the log.
387 Note -- this function does not modify record_full_insn_num. */
390 record_full_list_release_first (void)
392 struct record_full_entry *tmp;
394 if (!record_full_first.next)
397 /* Loop until a record_full_end. */
400 /* Cut record_full_first.next out of the linked list. */
401 tmp = record_full_first.next;
402 record_full_first.next = tmp->next;
403 tmp->next->prev = &record_full_first;
405 /* tmp is now isolated, and can be deleted. */
406 if (record_full_entry_release (tmp) == record_full_end)
407 break; /* End loop at first record_full_end. */
409 if (!record_full_first.next)
411 gdb_assert (record_full_insn_num == 1);
412 break; /* End loop when list is empty. */
417 /* Add a struct record_full_entry to record_full_arch_list. */
420 record_full_arch_list_add (struct record_full_entry *rec)
422 if (record_debug > 1)
423 fprintf_unfiltered (gdb_stdlog,
424 "Process record: record_full_arch_list_add %s.\n",
425 host_address_to_string (rec));
427 if (record_full_arch_list_tail)
429 record_full_arch_list_tail->next = rec;
430 rec->prev = record_full_arch_list_tail;
431 record_full_arch_list_tail = rec;
435 record_full_arch_list_head = rec;
436 record_full_arch_list_tail = rec;
440 /* Return the value storage location of a record entry. */
441 static inline gdb_byte *
442 record_full_get_loc (struct record_full_entry *rec)
445 case record_full_mem:
446 if (rec->u.mem.len > sizeof (rec->u.mem.u.buf))
447 return rec->u.mem.u.ptr;
449 return rec->u.mem.u.buf;
450 case record_full_reg:
451 if (rec->u.reg.len > sizeof (rec->u.reg.u.buf))
452 return rec->u.reg.u.ptr;
454 return rec->u.reg.u.buf;
455 case record_full_end:
457 gdb_assert_not_reached ("unexpected record_full_entry type");
462 /* Record the value of a register NUM to record_full_arch_list. */
465 record_full_arch_list_add_reg (struct regcache *regcache, int regnum)
467 struct record_full_entry *rec;
469 if (record_debug > 1)
470 fprintf_unfiltered (gdb_stdlog,
471 "Process record: add register num = %d to "
475 rec = record_full_reg_alloc (regcache, regnum);
477 regcache_raw_read (regcache, regnum, record_full_get_loc (rec));
479 record_full_arch_list_add (rec);
484 /* Record the value of a region of memory whose address is ADDR and
485 length is LEN to record_full_arch_list. */
488 record_full_arch_list_add_mem (CORE_ADDR addr, int len)
490 struct record_full_entry *rec;
492 if (record_debug > 1)
493 fprintf_unfiltered (gdb_stdlog,
494 "Process record: add mem addr = %s len = %d to "
496 paddress (target_gdbarch (), addr), len);
498 if (!addr) /* FIXME: Why? Some arch must permit it... */
501 rec = record_full_mem_alloc (addr, len);
503 if (record_read_memory (target_gdbarch (), addr,
504 record_full_get_loc (rec), len))
506 record_full_mem_release (rec);
510 record_full_arch_list_add (rec);
515 /* Add a record_full_end type struct record_full_entry to
516 record_full_arch_list. */
519 record_full_arch_list_add_end (void)
521 struct record_full_entry *rec;
523 if (record_debug > 1)
524 fprintf_unfiltered (gdb_stdlog,
525 "Process record: add end to arch list.\n");
527 rec = record_full_end_alloc ();
528 rec->u.end.sigval = GDB_SIGNAL_0;
529 rec->u.end.insn_num = ++record_full_insn_count;
531 record_full_arch_list_add (rec);
537 record_full_check_insn_num (int set_terminal)
539 if (record_full_insn_num == record_full_insn_max_num)
541 /* Ask user what to do. */
542 if (record_full_stop_at_limit)
547 target_terminal_ours ();
548 q = yquery (_("Do you want to auto delete previous execution "
549 "log entries when record/replay buffer becomes "
550 "full (record full stop-at-limit)?"));
552 target_terminal_inferior ();
554 record_full_stop_at_limit = 0;
556 error (_("Process record: stopped by user."));
562 record_full_arch_list_cleanups (void *ignore)
564 record_full_list_release (record_full_arch_list_tail);
567 /* Before inferior step (when GDB record the running message, inferior
568 only can step), GDB will call this function to record the values to
569 record_full_list. This function will call gdbarch_process_record to
570 record the running message of inferior and set them to
571 record_full_arch_list, and add it to record_full_list. */
574 record_full_message (struct regcache *regcache, enum gdb_signal signal)
577 struct gdbarch *gdbarch = get_regcache_arch (regcache);
578 struct cleanup *old_cleanups
579 = make_cleanup (record_full_arch_list_cleanups, 0);
581 record_full_arch_list_head = NULL;
582 record_full_arch_list_tail = NULL;
584 /* Check record_full_insn_num. */
585 record_full_check_insn_num (1);
587 /* If gdb sends a signal value to target_resume,
588 save it in the 'end' field of the previous instruction.
590 Maybe process record should record what really happened,
591 rather than what gdb pretends has happened.
593 So if Linux delivered the signal to the child process during
594 the record mode, we will record it and deliver it again in
597 If user says "ignore this signal" during the record mode, then
598 it will be ignored again during the replay mode (no matter if
599 the user says something different, like "deliver this signal"
600 during the replay mode).
602 User should understand that nothing he does during the replay
603 mode will change the behavior of the child. If he tries,
604 then that is a user error.
606 But we should still deliver the signal to gdb during the replay,
607 if we delivered it during the recording. Therefore we should
608 record the signal during record_full_wait, not
609 record_full_resume. */
610 if (record_full_list != &record_full_first) /* FIXME better way to check */
612 gdb_assert (record_full_list->type == record_full_end);
613 record_full_list->u.end.sigval = signal;
616 if (signal == GDB_SIGNAL_0
617 || !gdbarch_process_record_signal_p (gdbarch))
618 ret = gdbarch_process_record (gdbarch,
620 regcache_read_pc (regcache));
622 ret = gdbarch_process_record_signal (gdbarch,
627 error (_("Process record: inferior program stopped."));
629 error (_("Process record: failed to record execution log."));
631 discard_cleanups (old_cleanups);
633 record_full_list->next = record_full_arch_list_head;
634 record_full_arch_list_head->prev = record_full_list;
635 record_full_list = record_full_arch_list_tail;
637 if (record_full_insn_num == record_full_insn_max_num)
638 record_full_list_release_first ();
640 record_full_insn_num++;
645 struct record_full_message_args {
646 struct regcache *regcache;
647 enum gdb_signal signal;
651 record_full_message_wrapper (void *args)
653 struct record_full_message_args *record_full_args = args;
655 return record_full_message (record_full_args->regcache,
656 record_full_args->signal);
660 record_full_message_wrapper_safe (struct regcache *regcache,
661 enum gdb_signal signal)
663 struct record_full_message_args args;
665 args.regcache = regcache;
666 args.signal = signal;
668 return catch_errors (record_full_message_wrapper, &args, NULL,
672 /* Set to 1 if record_full_store_registers and record_full_xfer_partial
673 doesn't need record. */
675 static int record_full_gdb_operation_disable = 0;
678 record_full_gdb_operation_disable_set (void)
680 struct cleanup *old_cleanups = NULL;
683 make_cleanup_restore_integer (&record_full_gdb_operation_disable);
684 record_full_gdb_operation_disable = 1;
689 /* Flag set to TRUE for target_stopped_by_watchpoint. */
690 static int record_full_hw_watchpoint = 0;
692 /* Execute one instruction from the record log. Each instruction in
693 the log will be represented by an arbitrary sequence of register
694 entries and memory entries, followed by an 'end' entry. */
697 record_full_exec_insn (struct regcache *regcache,
698 struct gdbarch *gdbarch,
699 struct record_full_entry *entry)
703 case record_full_reg: /* reg */
705 gdb_byte reg[MAX_REGISTER_SIZE];
707 if (record_debug > 1)
708 fprintf_unfiltered (gdb_stdlog,
709 "Process record: record_full_reg %s to "
710 "inferior num = %d.\n",
711 host_address_to_string (entry),
714 regcache_cooked_read (regcache, entry->u.reg.num, reg);
715 regcache_cooked_write (regcache, entry->u.reg.num,
716 record_full_get_loc (entry));
717 memcpy (record_full_get_loc (entry), reg, entry->u.reg.len);
721 case record_full_mem: /* mem */
723 /* Nothing to do if the entry is flagged not_accessible. */
724 if (!entry->u.mem.mem_entry_not_accessible)
726 gdb_byte *mem = alloca (entry->u.mem.len);
728 if (record_debug > 1)
729 fprintf_unfiltered (gdb_stdlog,
730 "Process record: record_full_mem %s to "
731 "inferior addr = %s len = %d.\n",
732 host_address_to_string (entry),
733 paddress (gdbarch, entry->u.mem.addr),
736 if (record_read_memory (gdbarch,
737 entry->u.mem.addr, mem, entry->u.mem.len))
738 entry->u.mem.mem_entry_not_accessible = 1;
741 if (target_write_memory (entry->u.mem.addr,
742 record_full_get_loc (entry),
745 entry->u.mem.mem_entry_not_accessible = 1;
747 warning (_("Process record: error writing memory at "
748 "addr = %s len = %d."),
749 paddress (gdbarch, entry->u.mem.addr),
754 memcpy (record_full_get_loc (entry), mem,
757 /* We've changed memory --- check if a hardware
758 watchpoint should trap. Note that this
759 presently assumes the target beneath supports
760 continuable watchpoints. On non-continuable
761 watchpoints target, we'll want to check this
762 _before_ actually doing the memory change, and
763 not doing the change at all if the watchpoint
765 if (hardware_watchpoint_inserted_in_range
766 (get_regcache_aspace (regcache),
767 entry->u.mem.addr, entry->u.mem.len))
768 record_full_hw_watchpoint = 1;
777 static void record_full_restore (void);
779 /* Asynchronous signal handle registered as event loop source for when
780 we have pending events ready to be passed to the core. */
782 static struct async_event_handler *record_full_async_inferior_event_token;
785 record_full_async_inferior_event_handler (gdb_client_data data)
787 inferior_event_handler (INF_REG_EVENT, NULL);
790 /* Open the process record target. */
793 record_full_core_open_1 (char *name, int from_tty)
795 struct regcache *regcache = get_current_regcache ();
796 int regnum = gdbarch_num_regs (get_regcache_arch (regcache));
799 /* Get record_full_core_regbuf. */
800 target_fetch_registers (regcache, -1);
801 record_full_core_regbuf = xmalloc (MAX_REGISTER_SIZE * regnum);
802 for (i = 0; i < regnum; i ++)
803 regcache_raw_collect (regcache, i,
804 record_full_core_regbuf + MAX_REGISTER_SIZE * i);
806 /* Get record_full_core_start and record_full_core_end. */
807 if (build_section_table (core_bfd, &record_full_core_start,
808 &record_full_core_end))
810 xfree (record_full_core_regbuf);
811 record_full_core_regbuf = NULL;
812 error (_("\"%s\": Can't find sections: %s"),
813 bfd_get_filename (core_bfd), bfd_errmsg (bfd_get_error ()));
816 push_target (&record_full_core_ops);
817 record_full_restore ();
820 /* "to_open" target method for 'live' processes. */
823 record_full_open_1 (char *name, int from_tty)
826 fprintf_unfiltered (gdb_stdlog, "Process record: record_full_open\n");
829 if (!target_has_execution)
830 error (_("Process record: the program is not being run."));
832 error (_("Process record target can't debug inferior in non-stop mode "
835 if (!gdbarch_process_record_p (target_gdbarch ()))
836 error (_("Process record: the current architecture doesn't support "
837 "record function."));
839 push_target (&record_full_ops);
842 static void record_full_init_record_breakpoints (void);
844 /* "to_open" target method. Open the process record target. */
847 record_full_open (char *name, int from_tty)
849 struct target_ops *t;
852 fprintf_unfiltered (gdb_stdlog, "Process record: record_full_open\n");
857 record_full_insn_num = 0;
858 record_full_insn_count = 0;
859 record_full_list = &record_full_first;
860 record_full_list->next = NULL;
863 record_full_core_open_1 (name, from_tty);
865 record_full_open_1 (name, from_tty);
867 /* Register extra event sources in the event loop. */
868 record_full_async_inferior_event_token
869 = create_async_event_handler (record_full_async_inferior_event_handler,
872 record_full_init_record_breakpoints ();
874 observer_notify_record_changed (current_inferior (), 1);
877 /* "to_close" target method. Close the process record target. */
880 record_full_close (struct target_ops *self)
882 struct record_full_core_buf_entry *entry;
885 fprintf_unfiltered (gdb_stdlog, "Process record: record_full_close\n");
887 record_full_list_release (record_full_list);
889 /* Release record_full_core_regbuf. */
890 if (record_full_core_regbuf)
892 xfree (record_full_core_regbuf);
893 record_full_core_regbuf = NULL;
896 /* Release record_full_core_buf_list. */
897 if (record_full_core_buf_list)
899 for (entry = record_full_core_buf_list->prev; entry;
902 xfree (record_full_core_buf_list);
903 record_full_core_buf_list = entry;
905 record_full_core_buf_list = NULL;
908 if (record_full_async_inferior_event_token)
909 delete_async_event_handler (&record_full_async_inferior_event_token);
912 static int record_full_resume_step = 0;
914 /* True if we've been resumed, and so each record_full_wait call should
915 advance execution. If this is false, record_full_wait will return a
916 TARGET_WAITKIND_IGNORE. */
917 static int record_full_resumed = 0;
919 /* The execution direction of the last resume we got. This is
920 necessary for async mode. Vis (order is not strictly accurate):
922 1. user has the global execution direction set to forward
923 2. user does a reverse-step command
924 3. record_full_resume is called with global execution direction
925 temporarily switched to reverse
926 4. GDB's execution direction is reverted back to forward
927 5. target record notifies event loop there's an event to handle
928 6. infrun asks the target which direction was it going, and switches
929 the global execution direction accordingly (to reverse)
930 7. infrun polls an event out of the record target, and handles it
931 8. GDB goes back to the event loop, and goto #4.
933 static enum exec_direction_kind record_full_execution_dir = EXEC_FORWARD;
935 /* "to_resume" target method. Resume the process record target. */
938 record_full_resume (struct target_ops *ops, ptid_t ptid, int step,
939 enum gdb_signal signal)
941 record_full_resume_step = step;
942 record_full_resumed = 1;
943 record_full_execution_dir = execution_direction;
945 if (!RECORD_FULL_IS_REPLAY)
947 struct gdbarch *gdbarch = target_thread_architecture (ptid);
949 record_full_message (get_current_regcache (), signal);
953 /* This is not hard single step. */
954 if (!gdbarch_software_single_step_p (gdbarch))
956 /* This is a normal continue. */
961 /* This arch support soft sigle step. */
962 if (single_step_breakpoints_inserted ())
964 /* This is a soft single step. */
965 record_full_resume_step = 1;
969 /* This is a continue.
970 Try to insert a soft single step breakpoint. */
971 if (!gdbarch_software_single_step (gdbarch,
972 get_current_frame ()))
974 /* This system don't want use soft single step.
975 Use hard sigle step. */
982 /* Make sure the target beneath reports all signals. */
983 target_pass_signals (0, NULL);
985 ops->beneath->to_resume (ops->beneath, ptid, step, signal);
988 /* We are about to start executing the inferior (or simulate it),
989 let's register it with the event loop. */
990 if (target_can_async_p ())
992 target_async (inferior_event_handler, 0);
993 /* Notify the event loop there's an event to wait for. We do
994 most of the work in record_full_wait. */
995 mark_async_event_handler (record_full_async_inferior_event_token);
999 static int record_full_get_sig = 0;
1001 /* SIGINT signal handler, registered by "to_wait" method. */
1004 record_full_sig_handler (int signo)
1007 fprintf_unfiltered (gdb_stdlog, "Process record: get a signal\n");
1009 /* It will break the running inferior in replay mode. */
1010 record_full_resume_step = 1;
1012 /* It will let record_full_wait set inferior status to get the signal
1014 record_full_get_sig = 1;
1018 record_full_wait_cleanups (void *ignore)
1020 if (execution_direction == EXEC_REVERSE)
1022 if (record_full_list->next)
1023 record_full_list = record_full_list->next;
1026 record_full_list = record_full_list->prev;
1029 /* "to_wait" target method for process record target.
1031 In record mode, the target is always run in singlestep mode
1032 (even when gdb says to continue). The to_wait method intercepts
1033 the stop events and determines which ones are to be passed on to
1034 gdb. Most stop events are just singlestep events that gdb is not
1035 to know about, so the to_wait method just records them and keeps
1038 In replay mode, this function emulates the recorded execution log,
1039 one instruction at a time (forward or backward), and determines
1043 record_full_wait_1 (struct target_ops *ops,
1044 ptid_t ptid, struct target_waitstatus *status,
1047 struct cleanup *set_cleanups = record_full_gdb_operation_disable_set ();
1050 fprintf_unfiltered (gdb_stdlog,
1051 "Process record: record_full_wait "
1052 "record_full_resume_step = %d, "
1053 "record_full_resumed = %d, direction=%s\n",
1054 record_full_resume_step, record_full_resumed,
1055 record_full_execution_dir == EXEC_FORWARD
1056 ? "forward" : "reverse");
1058 if (!record_full_resumed)
1060 gdb_assert ((options & TARGET_WNOHANG) != 0);
1062 /* No interesting event. */
1063 status->kind = TARGET_WAITKIND_IGNORE;
1064 return minus_one_ptid;
1067 record_full_get_sig = 0;
1068 signal (SIGINT, record_full_sig_handler);
1070 if (!RECORD_FULL_IS_REPLAY && ops != &record_full_core_ops)
1072 if (record_full_resume_step)
1074 /* This is a single step. */
1075 return ops->beneath->to_wait (ops->beneath, ptid, status, options);
1079 /* This is not a single step. */
1082 struct gdbarch *gdbarch = target_thread_architecture (inferior_ptid);
1086 ret = ops->beneath->to_wait (ops->beneath, ptid, status, options);
1087 if (status->kind == TARGET_WAITKIND_IGNORE)
1090 fprintf_unfiltered (gdb_stdlog,
1091 "Process record: record_full_wait "
1092 "target beneath not done yet\n");
1096 if (single_step_breakpoints_inserted ())
1097 remove_single_step_breakpoints ();
1099 if (record_full_resume_step)
1102 /* Is this a SIGTRAP? */
1103 if (status->kind == TARGET_WAITKIND_STOPPED
1104 && status->value.sig == GDB_SIGNAL_TRAP)
1106 struct regcache *regcache;
1107 struct address_space *aspace;
1109 /* Yes -- this is likely our single-step finishing,
1110 but check if there's any reason the core would be
1111 interested in the event. */
1113 registers_changed ();
1114 regcache = get_current_regcache ();
1115 tmp_pc = regcache_read_pc (regcache);
1116 aspace = get_regcache_aspace (regcache);
1118 if (target_stopped_by_watchpoint ())
1120 /* Always interested in watchpoints. */
1122 else if (breakpoint_inserted_here_p (aspace, tmp_pc))
1124 /* There is a breakpoint here. Let the core
1126 if (software_breakpoint_inserted_here_p (aspace, tmp_pc))
1128 struct gdbarch *gdbarch
1129 = get_regcache_arch (regcache);
1130 CORE_ADDR decr_pc_after_break
1131 = target_decr_pc_after_break (gdbarch);
1132 if (decr_pc_after_break)
1133 regcache_write_pc (regcache,
1134 tmp_pc + decr_pc_after_break);
1139 /* This is a single-step trap. Record the
1140 insn and issue another step.
1141 FIXME: this part can be a random SIGTRAP too.
1142 But GDB cannot handle it. */
1145 if (!record_full_message_wrapper_safe (regcache,
1148 status->kind = TARGET_WAITKIND_STOPPED;
1149 status->value.sig = GDB_SIGNAL_0;
1153 if (gdbarch_software_single_step_p (gdbarch))
1155 /* Try to insert the software single step breakpoint.
1156 If insert success, set step to 0. */
1157 set_executing (inferior_ptid, 0);
1158 reinit_frame_cache ();
1159 if (gdbarch_software_single_step (gdbarch,
1160 get_current_frame ()))
1162 set_executing (inferior_ptid, 1);
1166 fprintf_unfiltered (gdb_stdlog,
1167 "Process record: record_full_wait "
1168 "issuing one more step in the "
1169 "target beneath\n");
1170 ops->beneath->to_resume (ops->beneath, ptid, step,
1176 /* The inferior is broken by a breakpoint or a signal. */
1185 struct regcache *regcache = get_current_regcache ();
1186 struct gdbarch *gdbarch = get_regcache_arch (regcache);
1187 struct address_space *aspace = get_regcache_aspace (regcache);
1188 int continue_flag = 1;
1189 int first_record_full_end = 1;
1190 struct cleanup *old_cleanups
1191 = make_cleanup (record_full_wait_cleanups, 0);
1194 record_full_hw_watchpoint = 0;
1195 status->kind = TARGET_WAITKIND_STOPPED;
1197 /* Check breakpoint when forward execute. */
1198 if (execution_direction == EXEC_FORWARD)
1200 tmp_pc = regcache_read_pc (regcache);
1201 if (breakpoint_inserted_here_p (aspace, tmp_pc))
1203 int decr_pc_after_break = target_decr_pc_after_break (gdbarch);
1206 fprintf_unfiltered (gdb_stdlog,
1207 "Process record: break at %s.\n",
1208 paddress (gdbarch, tmp_pc));
1210 if (decr_pc_after_break
1211 && !record_full_resume_step
1212 && software_breakpoint_inserted_here_p (aspace, tmp_pc))
1213 regcache_write_pc (regcache,
1214 tmp_pc + decr_pc_after_break);
1219 /* If GDB is in terminal_inferior mode, it will not get the signal.
1220 And in GDB replay mode, GDB doesn't need to be in terminal_inferior
1221 mode, because inferior will not executed.
1222 Then set it to terminal_ours to make GDB get the signal. */
1223 target_terminal_ours ();
1225 /* In EXEC_FORWARD mode, record_full_list points to the tail of prev
1227 if (execution_direction == EXEC_FORWARD && record_full_list->next)
1228 record_full_list = record_full_list->next;
1230 /* Loop over the record_full_list, looking for the next place to
1234 /* Check for beginning and end of log. */
1235 if (execution_direction == EXEC_REVERSE
1236 && record_full_list == &record_full_first)
1238 /* Hit beginning of record log in reverse. */
1239 status->kind = TARGET_WAITKIND_NO_HISTORY;
1242 if (execution_direction != EXEC_REVERSE && !record_full_list->next)
1244 /* Hit end of record log going forward. */
1245 status->kind = TARGET_WAITKIND_NO_HISTORY;
1249 record_full_exec_insn (regcache, gdbarch, record_full_list);
1251 if (record_full_list->type == record_full_end)
1253 if (record_debug > 1)
1254 fprintf_unfiltered (gdb_stdlog,
1255 "Process record: record_full_end %s to "
1257 host_address_to_string (record_full_list));
1259 if (first_record_full_end && execution_direction == EXEC_REVERSE)
1261 /* When reverse excute, the first record_full_end is the
1262 part of current instruction. */
1263 first_record_full_end = 0;
1267 /* In EXEC_REVERSE mode, this is the record_full_end of prev
1269 In EXEC_FORWARD mode, this is the record_full_end of
1270 current instruction. */
1272 if (record_full_resume_step)
1274 if (record_debug > 1)
1275 fprintf_unfiltered (gdb_stdlog,
1276 "Process record: step.\n");
1280 /* check breakpoint */
1281 tmp_pc = regcache_read_pc (regcache);
1282 if (breakpoint_inserted_here_p (aspace, tmp_pc))
1284 int decr_pc_after_break
1285 = target_decr_pc_after_break (gdbarch);
1288 fprintf_unfiltered (gdb_stdlog,
1289 "Process record: break "
1291 paddress (gdbarch, tmp_pc));
1292 if (decr_pc_after_break
1293 && execution_direction == EXEC_FORWARD
1294 && !record_full_resume_step
1295 && software_breakpoint_inserted_here_p (aspace,
1297 regcache_write_pc (regcache,
1298 tmp_pc + decr_pc_after_break);
1302 if (record_full_hw_watchpoint)
1305 fprintf_unfiltered (gdb_stdlog,
1306 "Process record: hit hw "
1310 /* Check target signal */
1311 if (record_full_list->u.end.sigval != GDB_SIGNAL_0)
1312 /* FIXME: better way to check */
1319 if (execution_direction == EXEC_REVERSE)
1321 if (record_full_list->prev)
1322 record_full_list = record_full_list->prev;
1326 if (record_full_list->next)
1327 record_full_list = record_full_list->next;
1331 while (continue_flag);
1334 if (record_full_get_sig)
1335 status->value.sig = GDB_SIGNAL_INT;
1336 else if (record_full_list->u.end.sigval != GDB_SIGNAL_0)
1337 /* FIXME: better way to check */
1338 status->value.sig = record_full_list->u.end.sigval;
1340 status->value.sig = GDB_SIGNAL_TRAP;
1342 discard_cleanups (old_cleanups);
1345 signal (SIGINT, handle_sigint);
1347 do_cleanups (set_cleanups);
1348 return inferior_ptid;
1352 record_full_wait (struct target_ops *ops,
1353 ptid_t ptid, struct target_waitstatus *status,
1358 return_ptid = record_full_wait_1 (ops, ptid, status, options);
1359 if (status->kind != TARGET_WAITKIND_IGNORE)
1361 /* We're reporting a stop. Make sure any spurious
1362 target_wait(WNOHANG) doesn't advance the target until the
1363 core wants us resumed again. */
1364 record_full_resumed = 0;
1370 record_full_stopped_by_watchpoint (struct target_ops *ops)
1372 if (RECORD_FULL_IS_REPLAY)
1373 return record_full_hw_watchpoint;
1375 return ops->beneath->to_stopped_by_watchpoint (ops->beneath);
1379 record_full_stopped_data_address (struct target_ops *ops, CORE_ADDR *addr_p)
1381 if (RECORD_FULL_IS_REPLAY)
1384 return ops->beneath->to_stopped_data_address (ops->beneath, addr_p);
1387 /* Record registers change (by user or by GDB) to list as an instruction. */
1390 record_full_registers_change (struct regcache *regcache, int regnum)
1392 /* Check record_full_insn_num. */
1393 record_full_check_insn_num (0);
1395 record_full_arch_list_head = NULL;
1396 record_full_arch_list_tail = NULL;
1402 for (i = 0; i < gdbarch_num_regs (get_regcache_arch (regcache)); i++)
1404 if (record_full_arch_list_add_reg (regcache, i))
1406 record_full_list_release (record_full_arch_list_tail);
1407 error (_("Process record: failed to record execution log."));
1413 if (record_full_arch_list_add_reg (regcache, regnum))
1415 record_full_list_release (record_full_arch_list_tail);
1416 error (_("Process record: failed to record execution log."));
1419 if (record_full_arch_list_add_end ())
1421 record_full_list_release (record_full_arch_list_tail);
1422 error (_("Process record: failed to record execution log."));
1424 record_full_list->next = record_full_arch_list_head;
1425 record_full_arch_list_head->prev = record_full_list;
1426 record_full_list = record_full_arch_list_tail;
1428 if (record_full_insn_num == record_full_insn_max_num)
1429 record_full_list_release_first ();
1431 record_full_insn_num++;
1434 /* "to_store_registers" method for process record target. */
1437 record_full_store_registers (struct target_ops *ops,
1438 struct regcache *regcache,
1441 if (!record_full_gdb_operation_disable)
1443 if (RECORD_FULL_IS_REPLAY)
1447 /* Let user choose if he wants to write register or not. */
1450 query (_("Because GDB is in replay mode, changing the "
1451 "value of a register will make the execution "
1452 "log unusable from this point onward. "
1453 "Change all registers?"));
1456 query (_("Because GDB is in replay mode, changing the value "
1457 "of a register will make the execution log unusable "
1458 "from this point onward. Change register %s?"),
1459 gdbarch_register_name (get_regcache_arch (regcache),
1464 /* Invalidate the value of regcache that was set in function
1465 "regcache_raw_write". */
1471 i < gdbarch_num_regs (get_regcache_arch (regcache));
1473 regcache_invalidate (regcache, i);
1476 regcache_invalidate (regcache, regno);
1478 error (_("Process record canceled the operation."));
1481 /* Destroy the record from here forward. */
1482 record_full_list_release_following (record_full_list);
1485 record_full_registers_change (regcache, regno);
1487 ops->beneath->to_store_registers (ops->beneath, regcache, regno);
1490 /* "to_xfer_partial" method. Behavior is conditional on
1491 RECORD_FULL_IS_REPLAY.
1492 In replay mode, we cannot write memory unles we are willing to
1493 invalidate the record/replay log from this point forward. */
1495 static enum target_xfer_status
1496 record_full_xfer_partial (struct target_ops *ops, enum target_object object,
1497 const char *annex, gdb_byte *readbuf,
1498 const gdb_byte *writebuf, ULONGEST offset,
1499 ULONGEST len, ULONGEST *xfered_len)
1501 if (!record_full_gdb_operation_disable
1502 && (object == TARGET_OBJECT_MEMORY
1503 || object == TARGET_OBJECT_RAW_MEMORY) && writebuf)
1505 if (RECORD_FULL_IS_REPLAY)
1507 /* Let user choose if he wants to write memory or not. */
1508 if (!query (_("Because GDB is in replay mode, writing to memory "
1509 "will make the execution log unusable from this "
1510 "point onward. Write memory at address %s?"),
1511 paddress (target_gdbarch (), offset)))
1512 error (_("Process record canceled the operation."));
1514 /* Destroy the record from here forward. */
1515 record_full_list_release_following (record_full_list);
1518 /* Check record_full_insn_num */
1519 record_full_check_insn_num (0);
1521 /* Record registers change to list as an instruction. */
1522 record_full_arch_list_head = NULL;
1523 record_full_arch_list_tail = NULL;
1524 if (record_full_arch_list_add_mem (offset, len))
1526 record_full_list_release (record_full_arch_list_tail);
1528 fprintf_unfiltered (gdb_stdlog,
1529 "Process record: failed to record "
1531 return TARGET_XFER_E_IO;
1533 if (record_full_arch_list_add_end ())
1535 record_full_list_release (record_full_arch_list_tail);
1537 fprintf_unfiltered (gdb_stdlog,
1538 "Process record: failed to record "
1540 return TARGET_XFER_E_IO;
1542 record_full_list->next = record_full_arch_list_head;
1543 record_full_arch_list_head->prev = record_full_list;
1544 record_full_list = record_full_arch_list_tail;
1546 if (record_full_insn_num == record_full_insn_max_num)
1547 record_full_list_release_first ();
1549 record_full_insn_num++;
1552 return ops->beneath->to_xfer_partial (ops->beneath, object, annex,
1553 readbuf, writebuf, offset,
1557 /* This structure represents a breakpoint inserted while the record
1558 target is active. We use this to know when to install/remove
1559 breakpoints in/from the target beneath. For example, a breakpoint
1560 may be inserted while recording, but removed when not replaying nor
1561 recording. In that case, the breakpoint had not been inserted on
1562 the target beneath, so we should not try to remove it there. */
1564 struct record_full_breakpoint
1566 /* The address and address space the breakpoint was set at. */
1567 struct address_space *address_space;
1570 /* True when the breakpoint has been also installed in the target
1571 beneath. This will be false for breakpoints set during replay or
1573 int in_target_beneath;
1576 typedef struct record_full_breakpoint *record_full_breakpoint_p;
1577 DEF_VEC_P(record_full_breakpoint_p);
1579 /* The list of breakpoints inserted while the record target is
1581 VEC(record_full_breakpoint_p) *record_full_breakpoints = NULL;
1584 record_full_sync_record_breakpoints (struct bp_location *loc, void *data)
1586 if (loc->loc_type != bp_loc_software_breakpoint)
1591 struct record_full_breakpoint *bp = XNEW (struct record_full_breakpoint);
1593 bp->addr = loc->target_info.placed_address;
1594 bp->address_space = loc->target_info.placed_address_space;
1596 bp->in_target_beneath = 1;
1598 VEC_safe_push (record_full_breakpoint_p, record_full_breakpoints, bp);
1602 /* Sync existing breakpoints to record_full_breakpoints. */
1605 record_full_init_record_breakpoints (void)
1607 VEC_free (record_full_breakpoint_p, record_full_breakpoints);
1609 iterate_over_bp_locations (record_full_sync_record_breakpoints);
1612 /* Behavior is conditional on RECORD_FULL_IS_REPLAY. We will not actually
1613 insert or remove breakpoints in the real target when replaying, nor
1617 record_full_insert_breakpoint (struct target_ops *ops,
1618 struct gdbarch *gdbarch,
1619 struct bp_target_info *bp_tgt)
1621 struct record_full_breakpoint *bp;
1622 int in_target_beneath = 0;
1624 if (!RECORD_FULL_IS_REPLAY)
1626 /* When recording, we currently always single-step, so we don't
1627 really need to install regular breakpoints in the inferior.
1628 However, we do have to insert software single-step
1629 breakpoints, in case the target can't hardware step. To keep
1630 things single, we always insert. */
1631 struct cleanup *old_cleanups;
1634 old_cleanups = record_full_gdb_operation_disable_set ();
1635 ret = ops->beneath->to_insert_breakpoint (ops->beneath, gdbarch, bp_tgt);
1636 do_cleanups (old_cleanups);
1641 in_target_beneath = 1;
1644 bp = XNEW (struct record_full_breakpoint);
1645 bp->addr = bp_tgt->placed_address;
1646 bp->address_space = bp_tgt->placed_address_space;
1647 bp->in_target_beneath = in_target_beneath;
1648 VEC_safe_push (record_full_breakpoint_p, record_full_breakpoints, bp);
1652 /* "to_remove_breakpoint" method for process record target. */
1655 record_full_remove_breakpoint (struct target_ops *ops,
1656 struct gdbarch *gdbarch,
1657 struct bp_target_info *bp_tgt)
1659 struct record_full_breakpoint *bp;
1663 VEC_iterate (record_full_breakpoint_p,
1664 record_full_breakpoints, ix, bp);
1667 if (bp->addr == bp_tgt->placed_address
1668 && bp->address_space == bp_tgt->placed_address_space)
1670 if (bp->in_target_beneath)
1672 struct cleanup *old_cleanups;
1675 old_cleanups = record_full_gdb_operation_disable_set ();
1676 ret = ops->beneath->to_remove_breakpoint (ops->beneath, gdbarch,
1678 do_cleanups (old_cleanups);
1684 VEC_unordered_remove (record_full_breakpoint_p,
1685 record_full_breakpoints, ix);
1690 gdb_assert_not_reached ("removing unknown breakpoint");
1693 /* "to_can_execute_reverse" method for process record target. */
1696 record_full_can_execute_reverse (struct target_ops *self)
1701 /* "to_get_bookmark" method for process record and prec over core. */
1704 record_full_get_bookmark (struct target_ops *self, char *args, int from_tty)
1708 /* Return stringified form of instruction count. */
1709 if (record_full_list && record_full_list->type == record_full_end)
1710 ret = xstrdup (pulongest (record_full_list->u.end.insn_num));
1715 fprintf_unfiltered (gdb_stdlog,
1716 "record_full_get_bookmark returns %s\n", ret);
1718 fprintf_unfiltered (gdb_stdlog,
1719 "record_full_get_bookmark returns NULL\n");
1721 return (gdb_byte *) ret;
1724 /* "to_goto_bookmark" method for process record and prec over core. */
1727 record_full_goto_bookmark (struct target_ops *self,
1728 gdb_byte *raw_bookmark, int from_tty)
1730 char *bookmark = (char *) raw_bookmark;
1733 fprintf_unfiltered (gdb_stdlog,
1734 "record_full_goto_bookmark receives %s\n", bookmark);
1736 if (bookmark[0] == '\'' || bookmark[0] == '\"')
1738 if (bookmark[strlen (bookmark) - 1] != bookmark[0])
1739 error (_("Unbalanced quotes: %s"), bookmark);
1741 /* Strip trailing quote. */
1742 bookmark[strlen (bookmark) - 1] = '\0';
1743 /* Strip leading quote. */
1745 /* Pass along to cmd_record_full_goto. */
1748 cmd_record_goto (bookmark, from_tty);
1753 record_full_can_async_p (struct target_ops *ops)
1755 /* We only enable async when the user specifically asks for it. */
1756 return target_async_permitted;
1760 record_full_is_async_p (struct target_ops *ops)
1762 /* We only enable async when the user specifically asks for it. */
1763 return target_async_permitted;
1766 static enum exec_direction_kind
1767 record_full_execution_direction (void)
1769 return record_full_execution_dir;
1773 record_full_info (void)
1775 struct record_full_entry *p;
1777 if (RECORD_FULL_IS_REPLAY)
1778 printf_filtered (_("Replay mode:\n"));
1780 printf_filtered (_("Record mode:\n"));
1782 /* Find entry for first actual instruction in the log. */
1783 for (p = record_full_first.next;
1784 p != NULL && p->type != record_full_end;
1788 /* Do we have a log at all? */
1789 if (p != NULL && p->type == record_full_end)
1791 /* Display instruction number for first instruction in the log. */
1792 printf_filtered (_("Lowest recorded instruction number is %s.\n"),
1793 pulongest (p->u.end.insn_num));
1795 /* If in replay mode, display where we are in the log. */
1796 if (RECORD_FULL_IS_REPLAY)
1797 printf_filtered (_("Current instruction number is %s.\n"),
1798 pulongest (record_full_list->u.end.insn_num));
1800 /* Display instruction number for last instruction in the log. */
1801 printf_filtered (_("Highest recorded instruction number is %s.\n"),
1802 pulongest (record_full_insn_count));
1804 /* Display log count. */
1805 printf_filtered (_("Log contains %u instructions.\n"),
1806 record_full_insn_num);
1809 printf_filtered (_("No instructions have been logged.\n"));
1811 /* Display max log size. */
1812 printf_filtered (_("Max logged instructions is %u.\n"),
1813 record_full_insn_max_num);
1816 /* The "to_record_delete" target method. */
1819 record_full_delete (void)
1821 record_full_list_release_following (record_full_list);
1824 /* The "to_record_is_replaying" target method. */
1827 record_full_is_replaying (void)
1829 return RECORD_FULL_IS_REPLAY;
1832 /* Go to a specific entry. */
1835 record_full_goto_entry (struct record_full_entry *p)
1838 error (_("Target insn not found."));
1839 else if (p == record_full_list)
1840 error (_("Already at target insn."));
1841 else if (p->u.end.insn_num > record_full_list->u.end.insn_num)
1843 printf_filtered (_("Go forward to insn number %s\n"),
1844 pulongest (p->u.end.insn_num));
1845 record_full_goto_insn (p, EXEC_FORWARD);
1849 printf_filtered (_("Go backward to insn number %s\n"),
1850 pulongest (p->u.end.insn_num));
1851 record_full_goto_insn (p, EXEC_REVERSE);
1854 registers_changed ();
1855 reinit_frame_cache ();
1856 print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1);
1859 /* The "to_goto_record_begin" target method. */
1862 record_full_goto_begin (void)
1864 struct record_full_entry *p = NULL;
1866 for (p = &record_full_first; p != NULL; p = p->next)
1867 if (p->type == record_full_end)
1870 record_full_goto_entry (p);
1873 /* The "to_goto_record_end" target method. */
1876 record_full_goto_end (void)
1878 struct record_full_entry *p = NULL;
1880 for (p = record_full_list; p->next != NULL; p = p->next)
1882 for (; p!= NULL; p = p->prev)
1883 if (p->type == record_full_end)
1886 record_full_goto_entry (p);
1889 /* The "to_goto_record" target method. */
1892 record_full_goto (ULONGEST target_insn)
1894 struct record_full_entry *p = NULL;
1896 for (p = &record_full_first; p != NULL; p = p->next)
1897 if (p->type == record_full_end && p->u.end.insn_num == target_insn)
1900 record_full_goto_entry (p);
1904 init_record_full_ops (void)
1906 record_full_ops.to_shortname = "record-full";
1907 record_full_ops.to_longname = "Process record and replay target";
1908 record_full_ops.to_doc =
1909 "Log program while executing and replay execution from log.";
1910 record_full_ops.to_open = record_full_open;
1911 record_full_ops.to_close = record_full_close;
1912 record_full_ops.to_resume = record_full_resume;
1913 record_full_ops.to_wait = record_full_wait;
1914 record_full_ops.to_disconnect = record_disconnect;
1915 record_full_ops.to_detach = record_detach;
1916 record_full_ops.to_mourn_inferior = record_mourn_inferior;
1917 record_full_ops.to_kill = record_kill;
1918 record_full_ops.to_create_inferior = find_default_create_inferior;
1919 record_full_ops.to_store_registers = record_full_store_registers;
1920 record_full_ops.to_xfer_partial = record_full_xfer_partial;
1921 record_full_ops.to_insert_breakpoint = record_full_insert_breakpoint;
1922 record_full_ops.to_remove_breakpoint = record_full_remove_breakpoint;
1923 record_full_ops.to_stopped_by_watchpoint = record_full_stopped_by_watchpoint;
1924 record_full_ops.to_stopped_data_address = record_full_stopped_data_address;
1925 record_full_ops.to_can_execute_reverse = record_full_can_execute_reverse;
1926 record_full_ops.to_stratum = record_stratum;
1927 /* Add bookmark target methods. */
1928 record_full_ops.to_get_bookmark = record_full_get_bookmark;
1929 record_full_ops.to_goto_bookmark = record_full_goto_bookmark;
1930 record_full_ops.to_can_async_p = record_full_can_async_p;
1931 record_full_ops.to_is_async_p = record_full_is_async_p;
1932 record_full_ops.to_execution_direction = record_full_execution_direction;
1933 record_full_ops.to_info_record = record_full_info;
1934 record_full_ops.to_save_record = record_full_save;
1935 record_full_ops.to_delete_record = record_full_delete;
1936 record_full_ops.to_record_is_replaying = record_full_is_replaying;
1937 record_full_ops.to_goto_record_begin = record_full_goto_begin;
1938 record_full_ops.to_goto_record_end = record_full_goto_end;
1939 record_full_ops.to_goto_record = record_full_goto;
1940 record_full_ops.to_magic = OPS_MAGIC;
1943 /* "to_resume" method for prec over corefile. */
1946 record_full_core_resume (struct target_ops *ops, ptid_t ptid, int step,
1947 enum gdb_signal signal)
1949 record_full_resume_step = step;
1950 record_full_resumed = 1;
1951 record_full_execution_dir = execution_direction;
1953 /* We are about to start executing the inferior (or simulate it),
1954 let's register it with the event loop. */
1955 if (target_can_async_p ())
1957 target_async (inferior_event_handler, 0);
1959 /* Notify the event loop there's an event to wait for. */
1960 mark_async_event_handler (record_full_async_inferior_event_token);
1964 /* "to_kill" method for prec over corefile. */
1967 record_full_core_kill (struct target_ops *ops)
1970 fprintf_unfiltered (gdb_stdlog, "Process record: record_full_core_kill\n");
1972 unpush_target (&record_full_core_ops);
1975 /* "to_fetch_registers" method for prec over corefile. */
1978 record_full_core_fetch_registers (struct target_ops *ops,
1979 struct regcache *regcache,
1984 int num = gdbarch_num_regs (get_regcache_arch (regcache));
1987 for (i = 0; i < num; i ++)
1988 regcache_raw_supply (regcache, i,
1989 record_full_core_regbuf + MAX_REGISTER_SIZE * i);
1992 regcache_raw_supply (regcache, regno,
1993 record_full_core_regbuf + MAX_REGISTER_SIZE * regno);
1996 /* "to_prepare_to_store" method for prec over corefile. */
1999 record_full_core_prepare_to_store (struct target_ops *self,
2000 struct regcache *regcache)
2004 /* "to_store_registers" method for prec over corefile. */
2007 record_full_core_store_registers (struct target_ops *ops,
2008 struct regcache *regcache,
2011 if (record_full_gdb_operation_disable)
2012 regcache_raw_collect (regcache, regno,
2013 record_full_core_regbuf + MAX_REGISTER_SIZE * regno);
2015 error (_("You can't do that without a process to debug."));
2018 /* "to_xfer_partial" method for prec over corefile. */
2020 static enum target_xfer_status
2021 record_full_core_xfer_partial (struct target_ops *ops,
2022 enum target_object object,
2023 const char *annex, gdb_byte *readbuf,
2024 const gdb_byte *writebuf, ULONGEST offset,
2025 ULONGEST len, ULONGEST *xfered_len)
2027 if (object == TARGET_OBJECT_MEMORY)
2029 if (record_full_gdb_operation_disable || !writebuf)
2031 struct target_section *p;
2033 for (p = record_full_core_start; p < record_full_core_end; p++)
2035 if (offset >= p->addr)
2037 struct record_full_core_buf_entry *entry;
2038 ULONGEST sec_offset;
2040 if (offset >= p->endaddr)
2043 if (offset + len > p->endaddr)
2044 len = p->endaddr - offset;
2046 sec_offset = offset - p->addr;
2048 /* Read readbuf or write writebuf p, offset, len. */
2050 if (p->the_bfd_section->flags & SEC_CONSTRUCTOR
2051 || (p->the_bfd_section->flags & SEC_HAS_CONTENTS) == 0)
2054 memset (readbuf, 0, len);
2057 return TARGET_XFER_OK;
2059 /* Get record_full_core_buf_entry. */
2060 for (entry = record_full_core_buf_list; entry;
2061 entry = entry->prev)
2068 /* Add a new entry. */
2069 entry = (struct record_full_core_buf_entry *)
2071 (sizeof (struct record_full_core_buf_entry));
2073 if (!bfd_malloc_and_get_section
2074 (p->the_bfd_section->owner,
2079 return TARGET_XFER_EOF;
2081 entry->prev = record_full_core_buf_list;
2082 record_full_core_buf_list = entry;
2085 memcpy (entry->buf + sec_offset, writebuf,
2091 return ops->beneath->to_xfer_partial (ops->beneath,
2097 memcpy (readbuf, entry->buf + sec_offset,
2102 return TARGET_XFER_OK;
2106 return TARGET_XFER_E_IO;
2109 error (_("You can't do that without a process to debug."));
2112 return ops->beneath->to_xfer_partial (ops->beneath, object, annex,
2113 readbuf, writebuf, offset, len,
2117 /* "to_insert_breakpoint" method for prec over corefile. */
2120 record_full_core_insert_breakpoint (struct target_ops *ops,
2121 struct gdbarch *gdbarch,
2122 struct bp_target_info *bp_tgt)
2127 /* "to_remove_breakpoint" method for prec over corefile. */
2130 record_full_core_remove_breakpoint (struct target_ops *ops,
2131 struct gdbarch *gdbarch,
2132 struct bp_target_info *bp_tgt)
2137 /* "to_has_execution" method for prec over corefile. */
2140 record_full_core_has_execution (struct target_ops *ops, ptid_t the_ptid)
2146 init_record_full_core_ops (void)
2148 record_full_core_ops.to_shortname = "record-core";
2149 record_full_core_ops.to_longname = "Process record and replay target";
2150 record_full_core_ops.to_doc =
2151 "Log program while executing and replay execution from log.";
2152 record_full_core_ops.to_open = record_full_open;
2153 record_full_core_ops.to_close = record_full_close;
2154 record_full_core_ops.to_resume = record_full_core_resume;
2155 record_full_core_ops.to_wait = record_full_wait;
2156 record_full_core_ops.to_kill = record_full_core_kill;
2157 record_full_core_ops.to_fetch_registers = record_full_core_fetch_registers;
2158 record_full_core_ops.to_prepare_to_store = record_full_core_prepare_to_store;
2159 record_full_core_ops.to_store_registers = record_full_core_store_registers;
2160 record_full_core_ops.to_xfer_partial = record_full_core_xfer_partial;
2161 record_full_core_ops.to_insert_breakpoint
2162 = record_full_core_insert_breakpoint;
2163 record_full_core_ops.to_remove_breakpoint
2164 = record_full_core_remove_breakpoint;
2165 record_full_core_ops.to_stopped_by_watchpoint
2166 = record_full_stopped_by_watchpoint;
2167 record_full_core_ops.to_stopped_data_address
2168 = record_full_stopped_data_address;
2169 record_full_core_ops.to_can_execute_reverse
2170 = record_full_can_execute_reverse;
2171 record_full_core_ops.to_has_execution = record_full_core_has_execution;
2172 record_full_core_ops.to_stratum = record_stratum;
2173 /* Add bookmark target methods. */
2174 record_full_core_ops.to_get_bookmark = record_full_get_bookmark;
2175 record_full_core_ops.to_goto_bookmark = record_full_goto_bookmark;
2176 record_full_core_ops.to_can_async_p = record_full_can_async_p;
2177 record_full_core_ops.to_is_async_p = record_full_is_async_p;
2178 record_full_core_ops.to_execution_direction
2179 = record_full_execution_direction;
2180 record_full_core_ops.to_info_record = record_full_info;
2181 record_full_core_ops.to_delete_record = record_full_delete;
2182 record_full_core_ops.to_record_is_replaying = record_full_is_replaying;
2183 record_full_core_ops.to_goto_record_begin = record_full_goto_begin;
2184 record_full_core_ops.to_goto_record_end = record_full_goto_end;
2185 record_full_core_ops.to_goto_record = record_full_goto;
2186 record_full_core_ops.to_magic = OPS_MAGIC;
2189 /* Record log save-file format
2190 Version 1 (never released)
2193 4 bytes: magic number htonl(0x20090829).
2194 NOTE: be sure to change whenever this file format changes!
2198 1 byte: record type (record_full_end, see enum record_full_type).
2200 1 byte: record type (record_full_reg, see enum record_full_type).
2201 8 bytes: register id (network byte order).
2202 MAX_REGISTER_SIZE bytes: register value.
2204 1 byte: record type (record_full_mem, see enum record_full_type).
2205 8 bytes: memory length (network byte order).
2206 8 bytes: memory address (network byte order).
2207 n bytes: memory value (n == memory length).
2210 4 bytes: magic number netorder32(0x20091016).
2211 NOTE: be sure to change whenever this file format changes!
2215 1 byte: record type (record_full_end, see enum record_full_type).
2217 4 bytes: instruction count
2219 1 byte: record type (record_full_reg, see enum record_full_type).
2220 4 bytes: register id (network byte order).
2221 n bytes: register value (n == actual register size).
2222 (eg. 4 bytes for x86 general registers).
2224 1 byte: record type (record_full_mem, see enum record_full_type).
2225 4 bytes: memory length (network byte order).
2226 8 bytes: memory address (network byte order).
2227 n bytes: memory value (n == memory length).
2231 /* bfdcore_read -- read bytes from a core file section. */
2234 bfdcore_read (bfd *obfd, asection *osec, void *buf, int len, int *offset)
2236 int ret = bfd_get_section_contents (obfd, osec, buf, *offset, len);
2241 error (_("Failed to read %d bytes from core file %s ('%s')."),
2242 len, bfd_get_filename (obfd),
2243 bfd_errmsg (bfd_get_error ()));
2246 static inline uint64_t
2247 netorder64 (uint64_t input)
2251 store_unsigned_integer ((gdb_byte *) &ret, sizeof (ret),
2252 BFD_ENDIAN_BIG, input);
2256 static inline uint32_t
2257 netorder32 (uint32_t input)
2261 store_unsigned_integer ((gdb_byte *) &ret, sizeof (ret),
2262 BFD_ENDIAN_BIG, input);
2266 static inline uint16_t
2267 netorder16 (uint16_t input)
2271 store_unsigned_integer ((gdb_byte *) &ret, sizeof (ret),
2272 BFD_ENDIAN_BIG, input);
2276 /* Restore the execution log from a core_bfd file. */
2278 record_full_restore (void)
2281 struct cleanup *old_cleanups;
2282 struct record_full_entry *rec;
2286 struct regcache *regcache;
2288 /* We restore the execution log from the open core bfd,
2290 if (core_bfd == NULL)
2293 /* "record_full_restore" can only be called when record list is empty. */
2294 gdb_assert (record_full_first.next == NULL);
2297 fprintf_unfiltered (gdb_stdlog, "Restoring recording from core file.\n");
2299 /* Now need to find our special note section. */
2300 osec = bfd_get_section_by_name (core_bfd, "null0");
2302 fprintf_unfiltered (gdb_stdlog, "Find precord section %s.\n",
2303 osec ? "succeeded" : "failed");
2306 osec_size = bfd_section_size (core_bfd, osec);
2308 fprintf_unfiltered (gdb_stdlog, "%s", bfd_section_name (core_bfd, osec));
2310 /* Check the magic code. */
2311 bfdcore_read (core_bfd, osec, &magic, sizeof (magic), &bfd_offset);
2312 if (magic != RECORD_FULL_FILE_MAGIC)
2313 error (_("Version mis-match or file format error in core file %s."),
2314 bfd_get_filename (core_bfd));
2316 fprintf_unfiltered (gdb_stdlog,
2317 " Reading 4-byte magic cookie "
2318 "RECORD_FULL_FILE_MAGIC (0x%s)\n",
2319 phex_nz (netorder32 (magic), 4));
2321 /* Restore the entries in recfd into record_full_arch_list_head and
2322 record_full_arch_list_tail. */
2323 record_full_arch_list_head = NULL;
2324 record_full_arch_list_tail = NULL;
2325 record_full_insn_num = 0;
2326 old_cleanups = make_cleanup (record_full_arch_list_cleanups, 0);
2327 regcache = get_current_regcache ();
2332 uint32_t regnum, len, signal, count;
2335 /* We are finished when offset reaches osec_size. */
2336 if (bfd_offset >= osec_size)
2338 bfdcore_read (core_bfd, osec, &rectype, sizeof (rectype), &bfd_offset);
2342 case record_full_reg: /* reg */
2343 /* Get register number to regnum. */
2344 bfdcore_read (core_bfd, osec, ®num,
2345 sizeof (regnum), &bfd_offset);
2346 regnum = netorder32 (regnum);
2348 rec = record_full_reg_alloc (regcache, regnum);
2351 bfdcore_read (core_bfd, osec, record_full_get_loc (rec),
2352 rec->u.reg.len, &bfd_offset);
2355 fprintf_unfiltered (gdb_stdlog,
2356 " Reading register %d (1 "
2357 "plus %lu plus %d bytes)\n",
2359 (unsigned long) sizeof (regnum),
2363 case record_full_mem: /* mem */
2365 bfdcore_read (core_bfd, osec, &len,
2366 sizeof (len), &bfd_offset);
2367 len = netorder32 (len);
2370 bfdcore_read (core_bfd, osec, &addr,
2371 sizeof (addr), &bfd_offset);
2372 addr = netorder64 (addr);
2374 rec = record_full_mem_alloc (addr, len);
2377 bfdcore_read (core_bfd, osec, record_full_get_loc (rec),
2378 rec->u.mem.len, &bfd_offset);
2381 fprintf_unfiltered (gdb_stdlog,
2382 " Reading memory %s (1 plus "
2383 "%lu plus %lu plus %d bytes)\n",
2384 paddress (get_current_arch (),
2386 (unsigned long) sizeof (addr),
2387 (unsigned long) sizeof (len),
2391 case record_full_end: /* end */
2392 rec = record_full_end_alloc ();
2393 record_full_insn_num ++;
2395 /* Get signal value. */
2396 bfdcore_read (core_bfd, osec, &signal,
2397 sizeof (signal), &bfd_offset);
2398 signal = netorder32 (signal);
2399 rec->u.end.sigval = signal;
2401 /* Get insn count. */
2402 bfdcore_read (core_bfd, osec, &count,
2403 sizeof (count), &bfd_offset);
2404 count = netorder32 (count);
2405 rec->u.end.insn_num = count;
2406 record_full_insn_count = count + 1;
2408 fprintf_unfiltered (gdb_stdlog,
2409 " Reading record_full_end (1 + "
2410 "%lu + %lu bytes), offset == %s\n",
2411 (unsigned long) sizeof (signal),
2412 (unsigned long) sizeof (count),
2413 paddress (get_current_arch (),
2418 error (_("Bad entry type in core file %s."),
2419 bfd_get_filename (core_bfd));
2423 /* Add rec to record arch list. */
2424 record_full_arch_list_add (rec);
2427 discard_cleanups (old_cleanups);
2429 /* Add record_full_arch_list_head to the end of record list. */
2430 record_full_first.next = record_full_arch_list_head;
2431 record_full_arch_list_head->prev = &record_full_first;
2432 record_full_arch_list_tail->next = NULL;
2433 record_full_list = &record_full_first;
2435 /* Update record_full_insn_max_num. */
2436 if (record_full_insn_num > record_full_insn_max_num)
2438 record_full_insn_max_num = record_full_insn_num;
2439 warning (_("Auto increase record/replay buffer limit to %u."),
2440 record_full_insn_max_num);
2444 printf_filtered (_("Restored records from core file %s.\n"),
2445 bfd_get_filename (core_bfd));
2447 print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1);
2450 /* bfdcore_write -- write bytes into a core file section. */
2453 bfdcore_write (bfd *obfd, asection *osec, void *buf, int len, int *offset)
2455 int ret = bfd_set_section_contents (obfd, osec, buf, *offset, len);
2460 error (_("Failed to write %d bytes to core file %s ('%s')."),
2461 len, bfd_get_filename (obfd),
2462 bfd_errmsg (bfd_get_error ()));
2465 /* Restore the execution log from a file. We use a modified elf
2466 corefile format, with an extra section for our data. */
2469 cmd_record_full_restore (char *args, int from_tty)
2471 core_file_command (args, from_tty);
2472 record_full_open (args, from_tty);
2476 record_full_save_cleanups (void *data)
2479 char *pathname = xstrdup (bfd_get_filename (obfd));
2481 gdb_bfd_unref (obfd);
2486 /* Save the execution log to a file. We use a modified elf corefile
2487 format, with an extra section for our data. */
2490 record_full_save (const char *recfilename)
2492 struct record_full_entry *cur_record_full_list;
2494 struct regcache *regcache;
2495 struct gdbarch *gdbarch;
2496 struct cleanup *old_cleanups;
2497 struct cleanup *set_cleanups;
2500 asection *osec = NULL;
2503 /* Open the save file. */
2505 fprintf_unfiltered (gdb_stdlog, "Saving execution log to core file '%s'\n",
2508 /* Open the output file. */
2509 obfd = create_gcore_bfd (recfilename);
2510 old_cleanups = make_cleanup (record_full_save_cleanups, obfd);
2512 /* Save the current record entry to "cur_record_full_list". */
2513 cur_record_full_list = record_full_list;
2515 /* Get the values of regcache and gdbarch. */
2516 regcache = get_current_regcache ();
2517 gdbarch = get_regcache_arch (regcache);
2519 /* Disable the GDB operation record. */
2520 set_cleanups = record_full_gdb_operation_disable_set ();
2522 /* Reverse execute to the begin of record list. */
2525 /* Check for beginning and end of log. */
2526 if (record_full_list == &record_full_first)
2529 record_full_exec_insn (regcache, gdbarch, record_full_list);
2531 if (record_full_list->prev)
2532 record_full_list = record_full_list->prev;
2535 /* Compute the size needed for the extra bfd section. */
2536 save_size = 4; /* magic cookie */
2537 for (record_full_list = record_full_first.next; record_full_list;
2538 record_full_list = record_full_list->next)
2539 switch (record_full_list->type)
2541 case record_full_end:
2542 save_size += 1 + 4 + 4;
2544 case record_full_reg:
2545 save_size += 1 + 4 + record_full_list->u.reg.len;
2547 case record_full_mem:
2548 save_size += 1 + 4 + 8 + record_full_list->u.mem.len;
2552 /* Make the new bfd section. */
2553 osec = bfd_make_section_anyway_with_flags (obfd, "precord",
2557 error (_("Failed to create 'precord' section for corefile %s: %s"),
2559 bfd_errmsg (bfd_get_error ()));
2560 bfd_set_section_size (obfd, osec, save_size);
2561 bfd_set_section_vma (obfd, osec, 0);
2562 bfd_set_section_alignment (obfd, osec, 0);
2563 bfd_section_lma (obfd, osec) = 0;
2565 /* Save corefile state. */
2566 write_gcore_file (obfd);
2568 /* Write out the record log. */
2569 /* Write the magic code. */
2570 magic = RECORD_FULL_FILE_MAGIC;
2572 fprintf_unfiltered (gdb_stdlog,
2573 " Writing 4-byte magic cookie "
2574 "RECORD_FULL_FILE_MAGIC (0x%s)\n",
2575 phex_nz (magic, 4));
2576 bfdcore_write (obfd, osec, &magic, sizeof (magic), &bfd_offset);
2578 /* Save the entries to recfd and forward execute to the end of
2580 record_full_list = &record_full_first;
2584 if (record_full_list != &record_full_first)
2587 uint32_t regnum, len, signal, count;
2590 type = record_full_list->type;
2591 bfdcore_write (obfd, osec, &type, sizeof (type), &bfd_offset);
2593 switch (record_full_list->type)
2595 case record_full_reg: /* reg */
2597 fprintf_unfiltered (gdb_stdlog,
2598 " Writing register %d (1 "
2599 "plus %lu plus %d bytes)\n",
2600 record_full_list->u.reg.num,
2601 (unsigned long) sizeof (regnum),
2602 record_full_list->u.reg.len);
2605 regnum = netorder32 (record_full_list->u.reg.num);
2606 bfdcore_write (obfd, osec, ®num,
2607 sizeof (regnum), &bfd_offset);
2610 bfdcore_write (obfd, osec,
2611 record_full_get_loc (record_full_list),
2612 record_full_list->u.reg.len, &bfd_offset);
2615 case record_full_mem: /* mem */
2617 fprintf_unfiltered (gdb_stdlog,
2618 " Writing memory %s (1 plus "
2619 "%lu plus %lu plus %d bytes)\n",
2621 record_full_list->u.mem.addr),
2622 (unsigned long) sizeof (addr),
2623 (unsigned long) sizeof (len),
2624 record_full_list->u.mem.len);
2627 len = netorder32 (record_full_list->u.mem.len);
2628 bfdcore_write (obfd, osec, &len, sizeof (len), &bfd_offset);
2630 /* Write memaddr. */
2631 addr = netorder64 (record_full_list->u.mem.addr);
2632 bfdcore_write (obfd, osec, &addr,
2633 sizeof (addr), &bfd_offset);
2636 bfdcore_write (obfd, osec,
2637 record_full_get_loc (record_full_list),
2638 record_full_list->u.mem.len, &bfd_offset);
2641 case record_full_end:
2643 fprintf_unfiltered (gdb_stdlog,
2644 " Writing record_full_end (1 + "
2645 "%lu + %lu bytes)\n",
2646 (unsigned long) sizeof (signal),
2647 (unsigned long) sizeof (count));
2648 /* Write signal value. */
2649 signal = netorder32 (record_full_list->u.end.sigval);
2650 bfdcore_write (obfd, osec, &signal,
2651 sizeof (signal), &bfd_offset);
2653 /* Write insn count. */
2654 count = netorder32 (record_full_list->u.end.insn_num);
2655 bfdcore_write (obfd, osec, &count,
2656 sizeof (count), &bfd_offset);
2661 /* Execute entry. */
2662 record_full_exec_insn (regcache, gdbarch, record_full_list);
2664 if (record_full_list->next)
2665 record_full_list = record_full_list->next;
2670 /* Reverse execute to cur_record_full_list. */
2673 /* Check for beginning and end of log. */
2674 if (record_full_list == cur_record_full_list)
2677 record_full_exec_insn (regcache, gdbarch, record_full_list);
2679 if (record_full_list->prev)
2680 record_full_list = record_full_list->prev;
2683 do_cleanups (set_cleanups);
2684 gdb_bfd_unref (obfd);
2685 discard_cleanups (old_cleanups);
2688 printf_filtered (_("Saved core file %s with execution log.\n"),
2692 /* record_full_goto_insn -- rewind the record log (forward or backward,
2693 depending on DIR) to the given entry, changing the program state
2697 record_full_goto_insn (struct record_full_entry *entry,
2698 enum exec_direction_kind dir)
2700 struct cleanup *set_cleanups = record_full_gdb_operation_disable_set ();
2701 struct regcache *regcache = get_current_regcache ();
2702 struct gdbarch *gdbarch = get_regcache_arch (regcache);
2704 /* Assume everything is valid: we will hit the entry,
2705 and we will not hit the end of the recording. */
2707 if (dir == EXEC_FORWARD)
2708 record_full_list = record_full_list->next;
2712 record_full_exec_insn (regcache, gdbarch, record_full_list);
2713 if (dir == EXEC_REVERSE)
2714 record_full_list = record_full_list->prev;
2716 record_full_list = record_full_list->next;
2717 } while (record_full_list != entry);
2718 do_cleanups (set_cleanups);
2721 /* Alias for "target record-full". */
2724 cmd_record_full_start (char *args, int from_tty)
2726 execute_command ("target record-full", from_tty);
2730 set_record_full_insn_max_num (char *args, int from_tty,
2731 struct cmd_list_element *c)
2733 if (record_full_insn_num > record_full_insn_max_num)
2735 /* Count down record_full_insn_num while releasing records from list. */
2736 while (record_full_insn_num > record_full_insn_max_num)
2738 record_full_list_release_first ();
2739 record_full_insn_num--;
2744 /* The "set record full" command. */
2747 set_record_full_command (char *args, int from_tty)
2749 printf_unfiltered (_("\"set record full\" must be followed "
2750 "by an apporpriate subcommand.\n"));
2751 help_list (set_record_full_cmdlist, "set record full ", all_commands,
2755 /* The "show record full" command. */
2758 show_record_full_command (char *args, int from_tty)
2760 cmd_show_list (show_record_full_cmdlist, from_tty, "");
2763 /* Provide a prototype to silence -Wmissing-prototypes. */
2764 extern initialize_file_ftype _initialize_record_full;
2767 _initialize_record_full (void)
2769 struct cmd_list_element *c;
2771 /* Init record_full_first. */
2772 record_full_first.prev = NULL;
2773 record_full_first.next = NULL;
2774 record_full_first.type = record_full_end;
2776 init_record_full_ops ();
2777 add_target (&record_full_ops);
2778 add_deprecated_target_alias (&record_full_ops, "record");
2779 init_record_full_core_ops ();
2780 add_target (&record_full_core_ops);
2782 add_prefix_cmd ("full", class_obscure, cmd_record_full_start,
2783 _("Start full execution recording."), &record_full_cmdlist,
2784 "record full ", 0, &record_cmdlist);
2786 c = add_cmd ("restore", class_obscure, cmd_record_full_restore,
2787 _("Restore the execution log from a file.\n\
2788 Argument is filename. File must be created with 'record save'."),
2789 &record_full_cmdlist);
2790 set_cmd_completer (c, filename_completer);
2792 /* Deprecate the old version without "full" prefix. */
2793 c = add_alias_cmd ("restore", "full restore", class_obscure, 1,
2795 set_cmd_completer (c, filename_completer);
2796 deprecate_cmd (c, "record full restore");
2798 add_prefix_cmd ("full", class_support, set_record_full_command,
2799 _("Set record options"), &set_record_full_cmdlist,
2800 "set record full ", 0, &set_record_cmdlist);
2802 add_prefix_cmd ("full", class_support, show_record_full_command,
2803 _("Show record options"), &show_record_full_cmdlist,
2804 "show record full ", 0, &show_record_cmdlist);
2806 /* Record instructions number limit command. */
2807 add_setshow_boolean_cmd ("stop-at-limit", no_class,
2808 &record_full_stop_at_limit, _("\
2809 Set whether record/replay stops when record/replay buffer becomes full."), _("\
2810 Show whether record/replay stops when record/replay buffer becomes full."),
2811 _("Default is ON.\n\
2812 When ON, if the record/replay buffer becomes full, ask user what to do.\n\
2813 When OFF, if the record/replay buffer becomes full,\n\
2814 delete the oldest recorded instruction to make room for each new one."),
2816 &set_record_full_cmdlist, &show_record_full_cmdlist);
2818 c = add_alias_cmd ("stop-at-limit", "full stop-at-limit", no_class, 1,
2819 &set_record_cmdlist);
2820 deprecate_cmd (c, "set record full stop-at-limit");
2822 c = add_alias_cmd ("stop-at-limit", "full stop-at-limit", no_class, 1,
2823 &show_record_cmdlist);
2824 deprecate_cmd (c, "show record full stop-at-limit");
2826 add_setshow_uinteger_cmd ("insn-number-max", no_class,
2827 &record_full_insn_max_num,
2828 _("Set record/replay buffer limit."),
2829 _("Show record/replay buffer limit."), _("\
2830 Set the maximum number of instructions to be stored in the\n\
2831 record/replay buffer. A value of either \"unlimited\" or zero means no\n\
2832 limit. Default is 200000."),
2833 set_record_full_insn_max_num,
2834 NULL, &set_record_full_cmdlist,
2835 &show_record_full_cmdlist);
2837 c = add_alias_cmd ("insn-number-max", "full insn-number-max", no_class, 1,
2838 &set_record_cmdlist);
2839 deprecate_cmd (c, "set record full insn-number-max");
2841 c = add_alias_cmd ("insn-number-max", "full insn-number-max", no_class, 1,
2842 &show_record_cmdlist);
2843 deprecate_cmd (c, "show record full insn-number-max");
2845 add_setshow_boolean_cmd ("memory-query", no_class,
2846 &record_full_memory_query, _("\
2847 Set whether query if PREC cannot record memory change of next instruction."),
2849 Show whether query if PREC cannot record memory change of next instruction."),
2852 When ON, query if PREC cannot record memory change of next instruction."),
2854 &set_record_full_cmdlist,
2855 &show_record_full_cmdlist);
2857 c = add_alias_cmd ("memory-query", "full memory-query", no_class, 1,
2858 &set_record_cmdlist);
2859 deprecate_cmd (c, "set record full memory-query");
2861 c = add_alias_cmd ("memory-query", "full memory-query", no_class, 1,
2862 &show_record_cmdlist);
2863 deprecate_cmd (c, "show record full memory-query");