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 (void)
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 (gdb_byte *raw_bookmark, int from_tty)
1729 char *bookmark = (char *) raw_bookmark;
1732 fprintf_unfiltered (gdb_stdlog,
1733 "record_full_goto_bookmark receives %s\n", bookmark);
1735 if (bookmark[0] == '\'' || bookmark[0] == '\"')
1737 if (bookmark[strlen (bookmark) - 1] != bookmark[0])
1738 error (_("Unbalanced quotes: %s"), bookmark);
1740 /* Strip trailing quote. */
1741 bookmark[strlen (bookmark) - 1] = '\0';
1742 /* Strip leading quote. */
1744 /* Pass along to cmd_record_full_goto. */
1747 cmd_record_goto (bookmark, from_tty);
1752 record_full_can_async_p (struct target_ops *ops)
1754 /* We only enable async when the user specifically asks for it. */
1755 return target_async_permitted;
1759 record_full_is_async_p (struct target_ops *ops)
1761 /* We only enable async when the user specifically asks for it. */
1762 return target_async_permitted;
1765 static enum exec_direction_kind
1766 record_full_execution_direction (void)
1768 return record_full_execution_dir;
1772 record_full_info (void)
1774 struct record_full_entry *p;
1776 if (RECORD_FULL_IS_REPLAY)
1777 printf_filtered (_("Replay mode:\n"));
1779 printf_filtered (_("Record mode:\n"));
1781 /* Find entry for first actual instruction in the log. */
1782 for (p = record_full_first.next;
1783 p != NULL && p->type != record_full_end;
1787 /* Do we have a log at all? */
1788 if (p != NULL && p->type == record_full_end)
1790 /* Display instruction number for first instruction in the log. */
1791 printf_filtered (_("Lowest recorded instruction number is %s.\n"),
1792 pulongest (p->u.end.insn_num));
1794 /* If in replay mode, display where we are in the log. */
1795 if (RECORD_FULL_IS_REPLAY)
1796 printf_filtered (_("Current instruction number is %s.\n"),
1797 pulongest (record_full_list->u.end.insn_num));
1799 /* Display instruction number for last instruction in the log. */
1800 printf_filtered (_("Highest recorded instruction number is %s.\n"),
1801 pulongest (record_full_insn_count));
1803 /* Display log count. */
1804 printf_filtered (_("Log contains %u instructions.\n"),
1805 record_full_insn_num);
1808 printf_filtered (_("No instructions have been logged.\n"));
1810 /* Display max log size. */
1811 printf_filtered (_("Max logged instructions is %u.\n"),
1812 record_full_insn_max_num);
1815 /* The "to_record_delete" target method. */
1818 record_full_delete (void)
1820 record_full_list_release_following (record_full_list);
1823 /* The "to_record_is_replaying" target method. */
1826 record_full_is_replaying (void)
1828 return RECORD_FULL_IS_REPLAY;
1831 /* Go to a specific entry. */
1834 record_full_goto_entry (struct record_full_entry *p)
1837 error (_("Target insn not found."));
1838 else if (p == record_full_list)
1839 error (_("Already at target insn."));
1840 else if (p->u.end.insn_num > record_full_list->u.end.insn_num)
1842 printf_filtered (_("Go forward to insn number %s\n"),
1843 pulongest (p->u.end.insn_num));
1844 record_full_goto_insn (p, EXEC_FORWARD);
1848 printf_filtered (_("Go backward to insn number %s\n"),
1849 pulongest (p->u.end.insn_num));
1850 record_full_goto_insn (p, EXEC_REVERSE);
1853 registers_changed ();
1854 reinit_frame_cache ();
1855 print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1);
1858 /* The "to_goto_record_begin" target method. */
1861 record_full_goto_begin (void)
1863 struct record_full_entry *p = NULL;
1865 for (p = &record_full_first; p != NULL; p = p->next)
1866 if (p->type == record_full_end)
1869 record_full_goto_entry (p);
1872 /* The "to_goto_record_end" target method. */
1875 record_full_goto_end (void)
1877 struct record_full_entry *p = NULL;
1879 for (p = record_full_list; p->next != NULL; p = p->next)
1881 for (; p!= NULL; p = p->prev)
1882 if (p->type == record_full_end)
1885 record_full_goto_entry (p);
1888 /* The "to_goto_record" target method. */
1891 record_full_goto (ULONGEST target_insn)
1893 struct record_full_entry *p = NULL;
1895 for (p = &record_full_first; p != NULL; p = p->next)
1896 if (p->type == record_full_end && p->u.end.insn_num == target_insn)
1899 record_full_goto_entry (p);
1903 init_record_full_ops (void)
1905 record_full_ops.to_shortname = "record-full";
1906 record_full_ops.to_longname = "Process record and replay target";
1907 record_full_ops.to_doc =
1908 "Log program while executing and replay execution from log.";
1909 record_full_ops.to_open = record_full_open;
1910 record_full_ops.to_close = record_full_close;
1911 record_full_ops.to_resume = record_full_resume;
1912 record_full_ops.to_wait = record_full_wait;
1913 record_full_ops.to_disconnect = record_disconnect;
1914 record_full_ops.to_detach = record_detach;
1915 record_full_ops.to_mourn_inferior = record_mourn_inferior;
1916 record_full_ops.to_kill = record_kill;
1917 record_full_ops.to_create_inferior = find_default_create_inferior;
1918 record_full_ops.to_store_registers = record_full_store_registers;
1919 record_full_ops.to_xfer_partial = record_full_xfer_partial;
1920 record_full_ops.to_insert_breakpoint = record_full_insert_breakpoint;
1921 record_full_ops.to_remove_breakpoint = record_full_remove_breakpoint;
1922 record_full_ops.to_stopped_by_watchpoint = record_full_stopped_by_watchpoint;
1923 record_full_ops.to_stopped_data_address = record_full_stopped_data_address;
1924 record_full_ops.to_can_execute_reverse = record_full_can_execute_reverse;
1925 record_full_ops.to_stratum = record_stratum;
1926 /* Add bookmark target methods. */
1927 record_full_ops.to_get_bookmark = record_full_get_bookmark;
1928 record_full_ops.to_goto_bookmark = record_full_goto_bookmark;
1929 record_full_ops.to_can_async_p = record_full_can_async_p;
1930 record_full_ops.to_is_async_p = record_full_is_async_p;
1931 record_full_ops.to_execution_direction = record_full_execution_direction;
1932 record_full_ops.to_info_record = record_full_info;
1933 record_full_ops.to_save_record = record_full_save;
1934 record_full_ops.to_delete_record = record_full_delete;
1935 record_full_ops.to_record_is_replaying = record_full_is_replaying;
1936 record_full_ops.to_goto_record_begin = record_full_goto_begin;
1937 record_full_ops.to_goto_record_end = record_full_goto_end;
1938 record_full_ops.to_goto_record = record_full_goto;
1939 record_full_ops.to_magic = OPS_MAGIC;
1942 /* "to_resume" method for prec over corefile. */
1945 record_full_core_resume (struct target_ops *ops, ptid_t ptid, int step,
1946 enum gdb_signal signal)
1948 record_full_resume_step = step;
1949 record_full_resumed = 1;
1950 record_full_execution_dir = execution_direction;
1952 /* We are about to start executing the inferior (or simulate it),
1953 let's register it with the event loop. */
1954 if (target_can_async_p ())
1956 target_async (inferior_event_handler, 0);
1958 /* Notify the event loop there's an event to wait for. */
1959 mark_async_event_handler (record_full_async_inferior_event_token);
1963 /* "to_kill" method for prec over corefile. */
1966 record_full_core_kill (struct target_ops *ops)
1969 fprintf_unfiltered (gdb_stdlog, "Process record: record_full_core_kill\n");
1971 unpush_target (&record_full_core_ops);
1974 /* "to_fetch_registers" method for prec over corefile. */
1977 record_full_core_fetch_registers (struct target_ops *ops,
1978 struct regcache *regcache,
1983 int num = gdbarch_num_regs (get_regcache_arch (regcache));
1986 for (i = 0; i < num; i ++)
1987 regcache_raw_supply (regcache, i,
1988 record_full_core_regbuf + MAX_REGISTER_SIZE * i);
1991 regcache_raw_supply (regcache, regno,
1992 record_full_core_regbuf + MAX_REGISTER_SIZE * regno);
1995 /* "to_prepare_to_store" method for prec over corefile. */
1998 record_full_core_prepare_to_store (struct target_ops *self,
1999 struct regcache *regcache)
2003 /* "to_store_registers" method for prec over corefile. */
2006 record_full_core_store_registers (struct target_ops *ops,
2007 struct regcache *regcache,
2010 if (record_full_gdb_operation_disable)
2011 regcache_raw_collect (regcache, regno,
2012 record_full_core_regbuf + MAX_REGISTER_SIZE * regno);
2014 error (_("You can't do that without a process to debug."));
2017 /* "to_xfer_partial" method for prec over corefile. */
2019 static enum target_xfer_status
2020 record_full_core_xfer_partial (struct target_ops *ops,
2021 enum target_object object,
2022 const char *annex, gdb_byte *readbuf,
2023 const gdb_byte *writebuf, ULONGEST offset,
2024 ULONGEST len, ULONGEST *xfered_len)
2026 if (object == TARGET_OBJECT_MEMORY)
2028 if (record_full_gdb_operation_disable || !writebuf)
2030 struct target_section *p;
2032 for (p = record_full_core_start; p < record_full_core_end; p++)
2034 if (offset >= p->addr)
2036 struct record_full_core_buf_entry *entry;
2037 ULONGEST sec_offset;
2039 if (offset >= p->endaddr)
2042 if (offset + len > p->endaddr)
2043 len = p->endaddr - offset;
2045 sec_offset = offset - p->addr;
2047 /* Read readbuf or write writebuf p, offset, len. */
2049 if (p->the_bfd_section->flags & SEC_CONSTRUCTOR
2050 || (p->the_bfd_section->flags & SEC_HAS_CONTENTS) == 0)
2053 memset (readbuf, 0, len);
2056 return TARGET_XFER_OK;
2058 /* Get record_full_core_buf_entry. */
2059 for (entry = record_full_core_buf_list; entry;
2060 entry = entry->prev)
2067 /* Add a new entry. */
2068 entry = (struct record_full_core_buf_entry *)
2070 (sizeof (struct record_full_core_buf_entry));
2072 if (!bfd_malloc_and_get_section
2073 (p->the_bfd_section->owner,
2078 return TARGET_XFER_EOF;
2080 entry->prev = record_full_core_buf_list;
2081 record_full_core_buf_list = entry;
2084 memcpy (entry->buf + sec_offset, writebuf,
2090 return ops->beneath->to_xfer_partial (ops->beneath,
2096 memcpy (readbuf, entry->buf + sec_offset,
2101 return TARGET_XFER_OK;
2105 return TARGET_XFER_E_IO;
2108 error (_("You can't do that without a process to debug."));
2111 return ops->beneath->to_xfer_partial (ops->beneath, object, annex,
2112 readbuf, writebuf, offset, len,
2116 /* "to_insert_breakpoint" method for prec over corefile. */
2119 record_full_core_insert_breakpoint (struct target_ops *ops,
2120 struct gdbarch *gdbarch,
2121 struct bp_target_info *bp_tgt)
2126 /* "to_remove_breakpoint" method for prec over corefile. */
2129 record_full_core_remove_breakpoint (struct target_ops *ops,
2130 struct gdbarch *gdbarch,
2131 struct bp_target_info *bp_tgt)
2136 /* "to_has_execution" method for prec over corefile. */
2139 record_full_core_has_execution (struct target_ops *ops, ptid_t the_ptid)
2145 init_record_full_core_ops (void)
2147 record_full_core_ops.to_shortname = "record-core";
2148 record_full_core_ops.to_longname = "Process record and replay target";
2149 record_full_core_ops.to_doc =
2150 "Log program while executing and replay execution from log.";
2151 record_full_core_ops.to_open = record_full_open;
2152 record_full_core_ops.to_close = record_full_close;
2153 record_full_core_ops.to_resume = record_full_core_resume;
2154 record_full_core_ops.to_wait = record_full_wait;
2155 record_full_core_ops.to_kill = record_full_core_kill;
2156 record_full_core_ops.to_fetch_registers = record_full_core_fetch_registers;
2157 record_full_core_ops.to_prepare_to_store = record_full_core_prepare_to_store;
2158 record_full_core_ops.to_store_registers = record_full_core_store_registers;
2159 record_full_core_ops.to_xfer_partial = record_full_core_xfer_partial;
2160 record_full_core_ops.to_insert_breakpoint
2161 = record_full_core_insert_breakpoint;
2162 record_full_core_ops.to_remove_breakpoint
2163 = record_full_core_remove_breakpoint;
2164 record_full_core_ops.to_stopped_by_watchpoint
2165 = record_full_stopped_by_watchpoint;
2166 record_full_core_ops.to_stopped_data_address
2167 = record_full_stopped_data_address;
2168 record_full_core_ops.to_can_execute_reverse
2169 = record_full_can_execute_reverse;
2170 record_full_core_ops.to_has_execution = record_full_core_has_execution;
2171 record_full_core_ops.to_stratum = record_stratum;
2172 /* Add bookmark target methods. */
2173 record_full_core_ops.to_get_bookmark = record_full_get_bookmark;
2174 record_full_core_ops.to_goto_bookmark = record_full_goto_bookmark;
2175 record_full_core_ops.to_can_async_p = record_full_can_async_p;
2176 record_full_core_ops.to_is_async_p = record_full_is_async_p;
2177 record_full_core_ops.to_execution_direction
2178 = record_full_execution_direction;
2179 record_full_core_ops.to_info_record = record_full_info;
2180 record_full_core_ops.to_delete_record = record_full_delete;
2181 record_full_core_ops.to_record_is_replaying = record_full_is_replaying;
2182 record_full_core_ops.to_goto_record_begin = record_full_goto_begin;
2183 record_full_core_ops.to_goto_record_end = record_full_goto_end;
2184 record_full_core_ops.to_goto_record = record_full_goto;
2185 record_full_core_ops.to_magic = OPS_MAGIC;
2188 /* Record log save-file format
2189 Version 1 (never released)
2192 4 bytes: magic number htonl(0x20090829).
2193 NOTE: be sure to change whenever this file format changes!
2197 1 byte: record type (record_full_end, see enum record_full_type).
2199 1 byte: record type (record_full_reg, see enum record_full_type).
2200 8 bytes: register id (network byte order).
2201 MAX_REGISTER_SIZE bytes: register value.
2203 1 byte: record type (record_full_mem, see enum record_full_type).
2204 8 bytes: memory length (network byte order).
2205 8 bytes: memory address (network byte order).
2206 n bytes: memory value (n == memory length).
2209 4 bytes: magic number netorder32(0x20091016).
2210 NOTE: be sure to change whenever this file format changes!
2214 1 byte: record type (record_full_end, see enum record_full_type).
2216 4 bytes: instruction count
2218 1 byte: record type (record_full_reg, see enum record_full_type).
2219 4 bytes: register id (network byte order).
2220 n bytes: register value (n == actual register size).
2221 (eg. 4 bytes for x86 general registers).
2223 1 byte: record type (record_full_mem, see enum record_full_type).
2224 4 bytes: memory length (network byte order).
2225 8 bytes: memory address (network byte order).
2226 n bytes: memory value (n == memory length).
2230 /* bfdcore_read -- read bytes from a core file section. */
2233 bfdcore_read (bfd *obfd, asection *osec, void *buf, int len, int *offset)
2235 int ret = bfd_get_section_contents (obfd, osec, buf, *offset, len);
2240 error (_("Failed to read %d bytes from core file %s ('%s')."),
2241 len, bfd_get_filename (obfd),
2242 bfd_errmsg (bfd_get_error ()));
2245 static inline uint64_t
2246 netorder64 (uint64_t input)
2250 store_unsigned_integer ((gdb_byte *) &ret, sizeof (ret),
2251 BFD_ENDIAN_BIG, input);
2255 static inline uint32_t
2256 netorder32 (uint32_t input)
2260 store_unsigned_integer ((gdb_byte *) &ret, sizeof (ret),
2261 BFD_ENDIAN_BIG, input);
2265 static inline uint16_t
2266 netorder16 (uint16_t input)
2270 store_unsigned_integer ((gdb_byte *) &ret, sizeof (ret),
2271 BFD_ENDIAN_BIG, input);
2275 /* Restore the execution log from a core_bfd file. */
2277 record_full_restore (void)
2280 struct cleanup *old_cleanups;
2281 struct record_full_entry *rec;
2285 struct regcache *regcache;
2287 /* We restore the execution log from the open core bfd,
2289 if (core_bfd == NULL)
2292 /* "record_full_restore" can only be called when record list is empty. */
2293 gdb_assert (record_full_first.next == NULL);
2296 fprintf_unfiltered (gdb_stdlog, "Restoring recording from core file.\n");
2298 /* Now need to find our special note section. */
2299 osec = bfd_get_section_by_name (core_bfd, "null0");
2301 fprintf_unfiltered (gdb_stdlog, "Find precord section %s.\n",
2302 osec ? "succeeded" : "failed");
2305 osec_size = bfd_section_size (core_bfd, osec);
2307 fprintf_unfiltered (gdb_stdlog, "%s", bfd_section_name (core_bfd, osec));
2309 /* Check the magic code. */
2310 bfdcore_read (core_bfd, osec, &magic, sizeof (magic), &bfd_offset);
2311 if (magic != RECORD_FULL_FILE_MAGIC)
2312 error (_("Version mis-match or file format error in core file %s."),
2313 bfd_get_filename (core_bfd));
2315 fprintf_unfiltered (gdb_stdlog,
2316 " Reading 4-byte magic cookie "
2317 "RECORD_FULL_FILE_MAGIC (0x%s)\n",
2318 phex_nz (netorder32 (magic), 4));
2320 /* Restore the entries in recfd into record_full_arch_list_head and
2321 record_full_arch_list_tail. */
2322 record_full_arch_list_head = NULL;
2323 record_full_arch_list_tail = NULL;
2324 record_full_insn_num = 0;
2325 old_cleanups = make_cleanup (record_full_arch_list_cleanups, 0);
2326 regcache = get_current_regcache ();
2331 uint32_t regnum, len, signal, count;
2334 /* We are finished when offset reaches osec_size. */
2335 if (bfd_offset >= osec_size)
2337 bfdcore_read (core_bfd, osec, &rectype, sizeof (rectype), &bfd_offset);
2341 case record_full_reg: /* reg */
2342 /* Get register number to regnum. */
2343 bfdcore_read (core_bfd, osec, ®num,
2344 sizeof (regnum), &bfd_offset);
2345 regnum = netorder32 (regnum);
2347 rec = record_full_reg_alloc (regcache, regnum);
2350 bfdcore_read (core_bfd, osec, record_full_get_loc (rec),
2351 rec->u.reg.len, &bfd_offset);
2354 fprintf_unfiltered (gdb_stdlog,
2355 " Reading register %d (1 "
2356 "plus %lu plus %d bytes)\n",
2358 (unsigned long) sizeof (regnum),
2362 case record_full_mem: /* mem */
2364 bfdcore_read (core_bfd, osec, &len,
2365 sizeof (len), &bfd_offset);
2366 len = netorder32 (len);
2369 bfdcore_read (core_bfd, osec, &addr,
2370 sizeof (addr), &bfd_offset);
2371 addr = netorder64 (addr);
2373 rec = record_full_mem_alloc (addr, len);
2376 bfdcore_read (core_bfd, osec, record_full_get_loc (rec),
2377 rec->u.mem.len, &bfd_offset);
2380 fprintf_unfiltered (gdb_stdlog,
2381 " Reading memory %s (1 plus "
2382 "%lu plus %lu plus %d bytes)\n",
2383 paddress (get_current_arch (),
2385 (unsigned long) sizeof (addr),
2386 (unsigned long) sizeof (len),
2390 case record_full_end: /* end */
2391 rec = record_full_end_alloc ();
2392 record_full_insn_num ++;
2394 /* Get signal value. */
2395 bfdcore_read (core_bfd, osec, &signal,
2396 sizeof (signal), &bfd_offset);
2397 signal = netorder32 (signal);
2398 rec->u.end.sigval = signal;
2400 /* Get insn count. */
2401 bfdcore_read (core_bfd, osec, &count,
2402 sizeof (count), &bfd_offset);
2403 count = netorder32 (count);
2404 rec->u.end.insn_num = count;
2405 record_full_insn_count = count + 1;
2407 fprintf_unfiltered (gdb_stdlog,
2408 " Reading record_full_end (1 + "
2409 "%lu + %lu bytes), offset == %s\n",
2410 (unsigned long) sizeof (signal),
2411 (unsigned long) sizeof (count),
2412 paddress (get_current_arch (),
2417 error (_("Bad entry type in core file %s."),
2418 bfd_get_filename (core_bfd));
2422 /* Add rec to record arch list. */
2423 record_full_arch_list_add (rec);
2426 discard_cleanups (old_cleanups);
2428 /* Add record_full_arch_list_head to the end of record list. */
2429 record_full_first.next = record_full_arch_list_head;
2430 record_full_arch_list_head->prev = &record_full_first;
2431 record_full_arch_list_tail->next = NULL;
2432 record_full_list = &record_full_first;
2434 /* Update record_full_insn_max_num. */
2435 if (record_full_insn_num > record_full_insn_max_num)
2437 record_full_insn_max_num = record_full_insn_num;
2438 warning (_("Auto increase record/replay buffer limit to %u."),
2439 record_full_insn_max_num);
2443 printf_filtered (_("Restored records from core file %s.\n"),
2444 bfd_get_filename (core_bfd));
2446 print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1);
2449 /* bfdcore_write -- write bytes into a core file section. */
2452 bfdcore_write (bfd *obfd, asection *osec, void *buf, int len, int *offset)
2454 int ret = bfd_set_section_contents (obfd, osec, buf, *offset, len);
2459 error (_("Failed to write %d bytes to core file %s ('%s')."),
2460 len, bfd_get_filename (obfd),
2461 bfd_errmsg (bfd_get_error ()));
2464 /* Restore the execution log from a file. We use a modified elf
2465 corefile format, with an extra section for our data. */
2468 cmd_record_full_restore (char *args, int from_tty)
2470 core_file_command (args, from_tty);
2471 record_full_open (args, from_tty);
2475 record_full_save_cleanups (void *data)
2478 char *pathname = xstrdup (bfd_get_filename (obfd));
2480 gdb_bfd_unref (obfd);
2485 /* Save the execution log to a file. We use a modified elf corefile
2486 format, with an extra section for our data. */
2489 record_full_save (const char *recfilename)
2491 struct record_full_entry *cur_record_full_list;
2493 struct regcache *regcache;
2494 struct gdbarch *gdbarch;
2495 struct cleanup *old_cleanups;
2496 struct cleanup *set_cleanups;
2499 asection *osec = NULL;
2502 /* Open the save file. */
2504 fprintf_unfiltered (gdb_stdlog, "Saving execution log to core file '%s'\n",
2507 /* Open the output file. */
2508 obfd = create_gcore_bfd (recfilename);
2509 old_cleanups = make_cleanup (record_full_save_cleanups, obfd);
2511 /* Save the current record entry to "cur_record_full_list". */
2512 cur_record_full_list = record_full_list;
2514 /* Get the values of regcache and gdbarch. */
2515 regcache = get_current_regcache ();
2516 gdbarch = get_regcache_arch (regcache);
2518 /* Disable the GDB operation record. */
2519 set_cleanups = record_full_gdb_operation_disable_set ();
2521 /* Reverse execute to the begin of record list. */
2524 /* Check for beginning and end of log. */
2525 if (record_full_list == &record_full_first)
2528 record_full_exec_insn (regcache, gdbarch, record_full_list);
2530 if (record_full_list->prev)
2531 record_full_list = record_full_list->prev;
2534 /* Compute the size needed for the extra bfd section. */
2535 save_size = 4; /* magic cookie */
2536 for (record_full_list = record_full_first.next; record_full_list;
2537 record_full_list = record_full_list->next)
2538 switch (record_full_list->type)
2540 case record_full_end:
2541 save_size += 1 + 4 + 4;
2543 case record_full_reg:
2544 save_size += 1 + 4 + record_full_list->u.reg.len;
2546 case record_full_mem:
2547 save_size += 1 + 4 + 8 + record_full_list->u.mem.len;
2551 /* Make the new bfd section. */
2552 osec = bfd_make_section_anyway_with_flags (obfd, "precord",
2556 error (_("Failed to create 'precord' section for corefile %s: %s"),
2558 bfd_errmsg (bfd_get_error ()));
2559 bfd_set_section_size (obfd, osec, save_size);
2560 bfd_set_section_vma (obfd, osec, 0);
2561 bfd_set_section_alignment (obfd, osec, 0);
2562 bfd_section_lma (obfd, osec) = 0;
2564 /* Save corefile state. */
2565 write_gcore_file (obfd);
2567 /* Write out the record log. */
2568 /* Write the magic code. */
2569 magic = RECORD_FULL_FILE_MAGIC;
2571 fprintf_unfiltered (gdb_stdlog,
2572 " Writing 4-byte magic cookie "
2573 "RECORD_FULL_FILE_MAGIC (0x%s)\n",
2574 phex_nz (magic, 4));
2575 bfdcore_write (obfd, osec, &magic, sizeof (magic), &bfd_offset);
2577 /* Save the entries to recfd and forward execute to the end of
2579 record_full_list = &record_full_first;
2583 if (record_full_list != &record_full_first)
2586 uint32_t regnum, len, signal, count;
2589 type = record_full_list->type;
2590 bfdcore_write (obfd, osec, &type, sizeof (type), &bfd_offset);
2592 switch (record_full_list->type)
2594 case record_full_reg: /* reg */
2596 fprintf_unfiltered (gdb_stdlog,
2597 " Writing register %d (1 "
2598 "plus %lu plus %d bytes)\n",
2599 record_full_list->u.reg.num,
2600 (unsigned long) sizeof (regnum),
2601 record_full_list->u.reg.len);
2604 regnum = netorder32 (record_full_list->u.reg.num);
2605 bfdcore_write (obfd, osec, ®num,
2606 sizeof (regnum), &bfd_offset);
2609 bfdcore_write (obfd, osec,
2610 record_full_get_loc (record_full_list),
2611 record_full_list->u.reg.len, &bfd_offset);
2614 case record_full_mem: /* mem */
2616 fprintf_unfiltered (gdb_stdlog,
2617 " Writing memory %s (1 plus "
2618 "%lu plus %lu plus %d bytes)\n",
2620 record_full_list->u.mem.addr),
2621 (unsigned long) sizeof (addr),
2622 (unsigned long) sizeof (len),
2623 record_full_list->u.mem.len);
2626 len = netorder32 (record_full_list->u.mem.len);
2627 bfdcore_write (obfd, osec, &len, sizeof (len), &bfd_offset);
2629 /* Write memaddr. */
2630 addr = netorder64 (record_full_list->u.mem.addr);
2631 bfdcore_write (obfd, osec, &addr,
2632 sizeof (addr), &bfd_offset);
2635 bfdcore_write (obfd, osec,
2636 record_full_get_loc (record_full_list),
2637 record_full_list->u.mem.len, &bfd_offset);
2640 case record_full_end:
2642 fprintf_unfiltered (gdb_stdlog,
2643 " Writing record_full_end (1 + "
2644 "%lu + %lu bytes)\n",
2645 (unsigned long) sizeof (signal),
2646 (unsigned long) sizeof (count));
2647 /* Write signal value. */
2648 signal = netorder32 (record_full_list->u.end.sigval);
2649 bfdcore_write (obfd, osec, &signal,
2650 sizeof (signal), &bfd_offset);
2652 /* Write insn count. */
2653 count = netorder32 (record_full_list->u.end.insn_num);
2654 bfdcore_write (obfd, osec, &count,
2655 sizeof (count), &bfd_offset);
2660 /* Execute entry. */
2661 record_full_exec_insn (regcache, gdbarch, record_full_list);
2663 if (record_full_list->next)
2664 record_full_list = record_full_list->next;
2669 /* Reverse execute to cur_record_full_list. */
2672 /* Check for beginning and end of log. */
2673 if (record_full_list == cur_record_full_list)
2676 record_full_exec_insn (regcache, gdbarch, record_full_list);
2678 if (record_full_list->prev)
2679 record_full_list = record_full_list->prev;
2682 do_cleanups (set_cleanups);
2683 gdb_bfd_unref (obfd);
2684 discard_cleanups (old_cleanups);
2687 printf_filtered (_("Saved core file %s with execution log.\n"),
2691 /* record_full_goto_insn -- rewind the record log (forward or backward,
2692 depending on DIR) to the given entry, changing the program state
2696 record_full_goto_insn (struct record_full_entry *entry,
2697 enum exec_direction_kind dir)
2699 struct cleanup *set_cleanups = record_full_gdb_operation_disable_set ();
2700 struct regcache *regcache = get_current_regcache ();
2701 struct gdbarch *gdbarch = get_regcache_arch (regcache);
2703 /* Assume everything is valid: we will hit the entry,
2704 and we will not hit the end of the recording. */
2706 if (dir == EXEC_FORWARD)
2707 record_full_list = record_full_list->next;
2711 record_full_exec_insn (regcache, gdbarch, record_full_list);
2712 if (dir == EXEC_REVERSE)
2713 record_full_list = record_full_list->prev;
2715 record_full_list = record_full_list->next;
2716 } while (record_full_list != entry);
2717 do_cleanups (set_cleanups);
2720 /* Alias for "target record-full". */
2723 cmd_record_full_start (char *args, int from_tty)
2725 execute_command ("target record-full", from_tty);
2729 set_record_full_insn_max_num (char *args, int from_tty,
2730 struct cmd_list_element *c)
2732 if (record_full_insn_num > record_full_insn_max_num)
2734 /* Count down record_full_insn_num while releasing records from list. */
2735 while (record_full_insn_num > record_full_insn_max_num)
2737 record_full_list_release_first ();
2738 record_full_insn_num--;
2743 /* The "set record full" command. */
2746 set_record_full_command (char *args, int from_tty)
2748 printf_unfiltered (_("\"set record full\" must be followed "
2749 "by an apporpriate subcommand.\n"));
2750 help_list (set_record_full_cmdlist, "set record full ", all_commands,
2754 /* The "show record full" command. */
2757 show_record_full_command (char *args, int from_tty)
2759 cmd_show_list (show_record_full_cmdlist, from_tty, "");
2762 /* Provide a prototype to silence -Wmissing-prototypes. */
2763 extern initialize_file_ftype _initialize_record_full;
2766 _initialize_record_full (void)
2768 struct cmd_list_element *c;
2770 /* Init record_full_first. */
2771 record_full_first.prev = NULL;
2772 record_full_first.next = NULL;
2773 record_full_first.type = record_full_end;
2775 init_record_full_ops ();
2776 add_target (&record_full_ops);
2777 add_deprecated_target_alias (&record_full_ops, "record");
2778 init_record_full_core_ops ();
2779 add_target (&record_full_core_ops);
2781 add_prefix_cmd ("full", class_obscure, cmd_record_full_start,
2782 _("Start full execution recording."), &record_full_cmdlist,
2783 "record full ", 0, &record_cmdlist);
2785 c = add_cmd ("restore", class_obscure, cmd_record_full_restore,
2786 _("Restore the execution log from a file.\n\
2787 Argument is filename. File must be created with 'record save'."),
2788 &record_full_cmdlist);
2789 set_cmd_completer (c, filename_completer);
2791 /* Deprecate the old version without "full" prefix. */
2792 c = add_alias_cmd ("restore", "full restore", class_obscure, 1,
2794 set_cmd_completer (c, filename_completer);
2795 deprecate_cmd (c, "record full restore");
2797 add_prefix_cmd ("full", class_support, set_record_full_command,
2798 _("Set record options"), &set_record_full_cmdlist,
2799 "set record full ", 0, &set_record_cmdlist);
2801 add_prefix_cmd ("full", class_support, show_record_full_command,
2802 _("Show record options"), &show_record_full_cmdlist,
2803 "show record full ", 0, &show_record_cmdlist);
2805 /* Record instructions number limit command. */
2806 add_setshow_boolean_cmd ("stop-at-limit", no_class,
2807 &record_full_stop_at_limit, _("\
2808 Set whether record/replay stops when record/replay buffer becomes full."), _("\
2809 Show whether record/replay stops when record/replay buffer becomes full."),
2810 _("Default is ON.\n\
2811 When ON, if the record/replay buffer becomes full, ask user what to do.\n\
2812 When OFF, if the record/replay buffer becomes full,\n\
2813 delete the oldest recorded instruction to make room for each new one."),
2815 &set_record_full_cmdlist, &show_record_full_cmdlist);
2817 c = add_alias_cmd ("stop-at-limit", "full stop-at-limit", no_class, 1,
2818 &set_record_cmdlist);
2819 deprecate_cmd (c, "set record full stop-at-limit");
2821 c = add_alias_cmd ("stop-at-limit", "full stop-at-limit", no_class, 1,
2822 &show_record_cmdlist);
2823 deprecate_cmd (c, "show record full stop-at-limit");
2825 add_setshow_uinteger_cmd ("insn-number-max", no_class,
2826 &record_full_insn_max_num,
2827 _("Set record/replay buffer limit."),
2828 _("Show record/replay buffer limit."), _("\
2829 Set the maximum number of instructions to be stored in the\n\
2830 record/replay buffer. A value of either \"unlimited\" or zero means no\n\
2831 limit. Default is 200000."),
2832 set_record_full_insn_max_num,
2833 NULL, &set_record_full_cmdlist,
2834 &show_record_full_cmdlist);
2836 c = add_alias_cmd ("insn-number-max", "full insn-number-max", no_class, 1,
2837 &set_record_cmdlist);
2838 deprecate_cmd (c, "set record full insn-number-max");
2840 c = add_alias_cmd ("insn-number-max", "full insn-number-max", no_class, 1,
2841 &show_record_cmdlist);
2842 deprecate_cmd (c, "show record full insn-number-max");
2844 add_setshow_boolean_cmd ("memory-query", no_class,
2845 &record_full_memory_query, _("\
2846 Set whether query if PREC cannot record memory change of next instruction."),
2848 Show whether query if PREC cannot record memory change of next instruction."),
2851 When ON, query if PREC cannot record memory change of next instruction."),
2853 &set_record_full_cmdlist,
2854 &show_record_full_cmdlist);
2856 c = add_alias_cmd ("memory-query", "full memory-query", no_class, 1,
2857 &set_record_cmdlist);
2858 deprecate_cmd (c, "set record full memory-query");
2860 c = add_alias_cmd ("memory-query", "full memory-query", no_class, 1,
2861 &show_record_cmdlist);
2862 deprecate_cmd (c, "show record full memory-query");