1 /* Process record and replay target for GDB, the GNU debugger.
3 Copyright (C) 2013-2017 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 "completer.h"
26 #include "arch-utils.h"
30 #include "record-full.h"
33 #include "event-loop.h"
38 #include "common/gdb_unlinker.h"
42 /* This module implements "target record-full", also known as "process
43 record and replay". This target sits on top of a "normal" target
44 (a target that "has execution"), and provides a record and replay
45 functionality, including reverse debugging.
47 Target record has two modes: recording, and replaying.
49 In record mode, we intercept the to_resume and to_wait methods.
50 Whenever gdb resumes the target, we run the target in single step
51 mode, and we build up an execution log in which, for each executed
52 instruction, we record all changes in memory and register state.
53 This is invisible to the user, to whom it just looks like an
54 ordinary debugging session (except for performance degredation).
56 In replay mode, instead of actually letting the inferior run as a
57 process, we simulate its execution by playing back the recorded
58 execution log. For each instruction in the log, we simulate the
59 instruction's side effects by duplicating the changes that it would
60 have made on memory and registers. */
62 #define DEFAULT_RECORD_FULL_INSN_MAX_NUM 200000
64 #define RECORD_FULL_IS_REPLAY \
65 (record_full_list->next || execution_direction == EXEC_REVERSE)
67 #define RECORD_FULL_FILE_MAGIC netorder32(0x20091016)
69 /* These are the core structs of the process record functionality.
71 A record_full_entry is a record of the value change of a register
72 ("record_full_reg") or a part of memory ("record_full_mem"). And each
73 instruction must have a struct record_full_entry ("record_full_end")
74 that indicates that this is the last struct record_full_entry of this
77 Each struct record_full_entry is linked to "record_full_list" by "prev"
78 and "next" pointers. */
80 struct record_full_mem_entry
84 /* Set this flag if target memory for this entry
85 can no longer be accessed. */
86 int mem_entry_not_accessible;
90 gdb_byte buf[sizeof (gdb_byte *)];
94 struct record_full_reg_entry
101 gdb_byte buf[2 * sizeof (gdb_byte *)];
105 struct record_full_end_entry
107 enum gdb_signal sigval;
111 enum record_full_type
118 /* This is the data structure that makes up the execution log.
120 The execution log consists of a single linked list of entries
121 of type "struct record_full_entry". It is doubly linked so that it
122 can be traversed in either direction.
124 The start of the list is anchored by a struct called
125 "record_full_first". The pointer "record_full_list" either points
126 to the last entry that was added to the list (in record mode), or to
127 the next entry in the list that will be executed (in replay mode).
129 Each list element (struct record_full_entry), in addition to next
130 and prev pointers, consists of a union of three entry types: mem,
131 reg, and end. A field called "type" determines which entry type is
132 represented by a given list element.
134 Each instruction that is added to the execution log is represented
135 by a variable number of list elements ('entries'). The instruction
136 will have one "reg" entry for each register that is changed by
137 executing the instruction (including the PC in every case). It
138 will also have one "mem" entry for each memory change. Finally,
139 each instruction will have an "end" entry that separates it from
140 the changes associated with the next instruction. */
142 struct record_full_entry
144 struct record_full_entry *prev;
145 struct record_full_entry *next;
146 enum record_full_type type;
150 struct record_full_reg_entry reg;
152 struct record_full_mem_entry mem;
154 struct record_full_end_entry end;
158 /* If true, query if PREC cannot record memory
159 change of next instruction. */
160 int record_full_memory_query = 0;
162 struct record_full_core_buf_entry
164 struct record_full_core_buf_entry *prev;
165 struct target_section *p;
169 /* Record buf with core target. */
170 static gdb_byte *record_full_core_regbuf = NULL;
171 static struct target_section *record_full_core_start;
172 static struct target_section *record_full_core_end;
173 static struct record_full_core_buf_entry *record_full_core_buf_list = NULL;
175 /* The following variables are used for managing the linked list that
176 represents the execution log.
178 record_full_first is the anchor that holds down the beginning of
181 record_full_list serves two functions:
182 1) In record mode, it anchors the end of the list.
183 2) In replay mode, it traverses the list and points to
184 the next instruction that must be emulated.
186 record_full_arch_list_head and record_full_arch_list_tail are used
187 to manage a separate list, which is used to build up the change
188 elements of the currently executing instruction during record mode.
189 When this instruction has been completely annotated in the "arch
190 list", it will be appended to the main execution log. */
192 static struct record_full_entry record_full_first;
193 static struct record_full_entry *record_full_list = &record_full_first;
194 static struct record_full_entry *record_full_arch_list_head = NULL;
195 static struct record_full_entry *record_full_arch_list_tail = NULL;
197 /* 1 ask user. 0 auto delete the last struct record_full_entry. */
198 static int record_full_stop_at_limit = 1;
199 /* Maximum allowed number of insns in execution log. */
200 static unsigned int record_full_insn_max_num
201 = DEFAULT_RECORD_FULL_INSN_MAX_NUM;
202 /* Actual count of insns presently in execution log. */
203 static unsigned int record_full_insn_num = 0;
204 /* Count of insns logged so far (may be larger
205 than count of insns presently in execution log). */
206 static ULONGEST record_full_insn_count;
208 /* The target_ops of process record. */
209 static struct target_ops record_full_ops;
210 static struct target_ops record_full_core_ops;
212 /* See record-full.h. */
215 record_full_is_used (void)
217 struct target_ops *t;
219 t = find_record_target ();
220 return (t == &record_full_ops
221 || t == &record_full_core_ops);
225 /* Command lists for "set/show record full". */
226 static struct cmd_list_element *set_record_full_cmdlist;
227 static struct cmd_list_element *show_record_full_cmdlist;
229 /* Command list for "record full". */
230 static struct cmd_list_element *record_full_cmdlist;
232 static void record_full_goto_insn (struct record_full_entry *entry,
233 enum exec_direction_kind dir);
234 static void record_full_save (struct target_ops *self,
235 const char *recfilename);
237 /* Alloc and free functions for record_full_reg, record_full_mem, and
238 record_full_end entries. */
240 /* Alloc a record_full_reg record entry. */
242 static inline struct record_full_entry *
243 record_full_reg_alloc (struct regcache *regcache, int regnum)
245 struct record_full_entry *rec;
246 struct gdbarch *gdbarch = get_regcache_arch (regcache);
248 rec = XCNEW (struct record_full_entry);
249 rec->type = record_full_reg;
250 rec->u.reg.num = regnum;
251 rec->u.reg.len = register_size (gdbarch, regnum);
252 if (rec->u.reg.len > sizeof (rec->u.reg.u.buf))
253 rec->u.reg.u.ptr = (gdb_byte *) xmalloc (rec->u.reg.len);
258 /* Free a record_full_reg record entry. */
261 record_full_reg_release (struct record_full_entry *rec)
263 gdb_assert (rec->type == record_full_reg);
264 if (rec->u.reg.len > sizeof (rec->u.reg.u.buf))
265 xfree (rec->u.reg.u.ptr);
269 /* Alloc a record_full_mem record entry. */
271 static inline struct record_full_entry *
272 record_full_mem_alloc (CORE_ADDR addr, int len)
274 struct record_full_entry *rec;
276 rec = XCNEW (struct record_full_entry);
277 rec->type = record_full_mem;
278 rec->u.mem.addr = addr;
279 rec->u.mem.len = len;
280 if (rec->u.mem.len > sizeof (rec->u.mem.u.buf))
281 rec->u.mem.u.ptr = (gdb_byte *) xmalloc (len);
286 /* Free a record_full_mem record entry. */
289 record_full_mem_release (struct record_full_entry *rec)
291 gdb_assert (rec->type == record_full_mem);
292 if (rec->u.mem.len > sizeof (rec->u.mem.u.buf))
293 xfree (rec->u.mem.u.ptr);
297 /* Alloc a record_full_end record entry. */
299 static inline struct record_full_entry *
300 record_full_end_alloc (void)
302 struct record_full_entry *rec;
304 rec = XCNEW (struct record_full_entry);
305 rec->type = record_full_end;
310 /* Free a record_full_end record entry. */
313 record_full_end_release (struct record_full_entry *rec)
318 /* Free one record entry, any type.
319 Return entry->type, in case caller wants to know. */
321 static inline enum record_full_type
322 record_full_entry_release (struct record_full_entry *rec)
324 enum record_full_type type = rec->type;
327 case record_full_reg:
328 record_full_reg_release (rec);
330 case record_full_mem:
331 record_full_mem_release (rec);
333 case record_full_end:
334 record_full_end_release (rec);
340 /* Free all record entries in list pointed to by REC. */
343 record_full_list_release (struct record_full_entry *rec)
354 record_full_entry_release (rec->next);
357 if (rec == &record_full_first)
359 record_full_insn_num = 0;
360 record_full_first.next = NULL;
363 record_full_entry_release (rec);
366 /* Free all record entries forward of the given list position. */
369 record_full_list_release_following (struct record_full_entry *rec)
371 struct record_full_entry *tmp = rec->next;
377 if (record_full_entry_release (tmp) == record_full_end)
379 record_full_insn_num--;
380 record_full_insn_count--;
386 /* Delete the first instruction from the beginning of the log, to make
387 room for adding a new instruction at the end of the log.
389 Note -- this function does not modify record_full_insn_num. */
392 record_full_list_release_first (void)
394 struct record_full_entry *tmp;
396 if (!record_full_first.next)
399 /* Loop until a record_full_end. */
402 /* Cut record_full_first.next out of the linked list. */
403 tmp = record_full_first.next;
404 record_full_first.next = tmp->next;
405 tmp->next->prev = &record_full_first;
407 /* tmp is now isolated, and can be deleted. */
408 if (record_full_entry_release (tmp) == record_full_end)
409 break; /* End loop at first record_full_end. */
411 if (!record_full_first.next)
413 gdb_assert (record_full_insn_num == 1);
414 break; /* End loop when list is empty. */
419 /* Add a struct record_full_entry to record_full_arch_list. */
422 record_full_arch_list_add (struct record_full_entry *rec)
424 if (record_debug > 1)
425 fprintf_unfiltered (gdb_stdlog,
426 "Process record: record_full_arch_list_add %s.\n",
427 host_address_to_string (rec));
429 if (record_full_arch_list_tail)
431 record_full_arch_list_tail->next = rec;
432 rec->prev = record_full_arch_list_tail;
433 record_full_arch_list_tail = rec;
437 record_full_arch_list_head = rec;
438 record_full_arch_list_tail = rec;
442 /* Return the value storage location of a record entry. */
443 static inline gdb_byte *
444 record_full_get_loc (struct record_full_entry *rec)
447 case record_full_mem:
448 if (rec->u.mem.len > sizeof (rec->u.mem.u.buf))
449 return rec->u.mem.u.ptr;
451 return rec->u.mem.u.buf;
452 case record_full_reg:
453 if (rec->u.reg.len > sizeof (rec->u.reg.u.buf))
454 return rec->u.reg.u.ptr;
456 return rec->u.reg.u.buf;
457 case record_full_end:
459 gdb_assert_not_reached ("unexpected record_full_entry type");
464 /* Record the value of a register NUM to record_full_arch_list. */
467 record_full_arch_list_add_reg (struct regcache *regcache, int regnum)
469 struct record_full_entry *rec;
471 if (record_debug > 1)
472 fprintf_unfiltered (gdb_stdlog,
473 "Process record: add register num = %d to "
477 rec = record_full_reg_alloc (regcache, regnum);
479 regcache_raw_read (regcache, regnum, record_full_get_loc (rec));
481 record_full_arch_list_add (rec);
486 /* Record the value of a region of memory whose address is ADDR and
487 length is LEN to record_full_arch_list. */
490 record_full_arch_list_add_mem (CORE_ADDR addr, int len)
492 struct record_full_entry *rec;
494 if (record_debug > 1)
495 fprintf_unfiltered (gdb_stdlog,
496 "Process record: add mem addr = %s len = %d to "
498 paddress (target_gdbarch (), addr), len);
500 if (!addr) /* FIXME: Why? Some arch must permit it... */
503 rec = record_full_mem_alloc (addr, len);
505 if (record_read_memory (target_gdbarch (), addr,
506 record_full_get_loc (rec), len))
508 record_full_mem_release (rec);
512 record_full_arch_list_add (rec);
517 /* Add a record_full_end type struct record_full_entry to
518 record_full_arch_list. */
521 record_full_arch_list_add_end (void)
523 struct record_full_entry *rec;
525 if (record_debug > 1)
526 fprintf_unfiltered (gdb_stdlog,
527 "Process record: add end to arch list.\n");
529 rec = record_full_end_alloc ();
530 rec->u.end.sigval = GDB_SIGNAL_0;
531 rec->u.end.insn_num = ++record_full_insn_count;
533 record_full_arch_list_add (rec);
539 record_full_check_insn_num (void)
541 if (record_full_insn_num == record_full_insn_max_num)
543 /* Ask user what to do. */
544 if (record_full_stop_at_limit)
546 if (!yquery (_("Do you want to auto delete previous execution "
547 "log entries when record/replay buffer becomes "
548 "full (record full stop-at-limit)?")))
549 error (_("Process record: stopped by user."));
550 record_full_stop_at_limit = 0;
556 record_full_arch_list_cleanups (void *ignore)
558 record_full_list_release (record_full_arch_list_tail);
561 /* Before inferior step (when GDB record the running message, inferior
562 only can step), GDB will call this function to record the values to
563 record_full_list. This function will call gdbarch_process_record to
564 record the running message of inferior and set them to
565 record_full_arch_list, and add it to record_full_list. */
568 record_full_message (struct regcache *regcache, enum gdb_signal signal)
571 struct gdbarch *gdbarch = get_regcache_arch (regcache);
572 struct cleanup *old_cleanups
573 = make_cleanup (record_full_arch_list_cleanups, 0);
575 record_full_arch_list_head = NULL;
576 record_full_arch_list_tail = NULL;
578 /* Check record_full_insn_num. */
579 record_full_check_insn_num ();
581 /* If gdb sends a signal value to target_resume,
582 save it in the 'end' field of the previous instruction.
584 Maybe process record should record what really happened,
585 rather than what gdb pretends has happened.
587 So if Linux delivered the signal to the child process during
588 the record mode, we will record it and deliver it again in
591 If user says "ignore this signal" during the record mode, then
592 it will be ignored again during the replay mode (no matter if
593 the user says something different, like "deliver this signal"
594 during the replay mode).
596 User should understand that nothing he does during the replay
597 mode will change the behavior of the child. If he tries,
598 then that is a user error.
600 But we should still deliver the signal to gdb during the replay,
601 if we delivered it during the recording. Therefore we should
602 record the signal during record_full_wait, not
603 record_full_resume. */
604 if (record_full_list != &record_full_first) /* FIXME better way to check */
606 gdb_assert (record_full_list->type == record_full_end);
607 record_full_list->u.end.sigval = signal;
610 if (signal == GDB_SIGNAL_0
611 || !gdbarch_process_record_signal_p (gdbarch))
612 ret = gdbarch_process_record (gdbarch,
614 regcache_read_pc (regcache));
616 ret = gdbarch_process_record_signal (gdbarch,
621 error (_("Process record: inferior program stopped."));
623 error (_("Process record: failed to record execution log."));
625 discard_cleanups (old_cleanups);
627 record_full_list->next = record_full_arch_list_head;
628 record_full_arch_list_head->prev = record_full_list;
629 record_full_list = record_full_arch_list_tail;
631 if (record_full_insn_num == record_full_insn_max_num)
632 record_full_list_release_first ();
634 record_full_insn_num++;
639 struct record_full_message_args {
640 struct regcache *regcache;
641 enum gdb_signal signal;
645 record_full_message_wrapper (void *args)
647 struct record_full_message_args *record_full_args
648 = (struct record_full_message_args *) args;
650 return record_full_message (record_full_args->regcache,
651 record_full_args->signal);
655 record_full_message_wrapper_safe (struct regcache *regcache,
656 enum gdb_signal signal)
658 struct record_full_message_args args;
660 args.regcache = regcache;
661 args.signal = signal;
663 return catch_errors (record_full_message_wrapper, &args, "",
667 /* Set to 1 if record_full_store_registers and record_full_xfer_partial
668 doesn't need record. */
670 static int record_full_gdb_operation_disable = 0;
673 record_full_gdb_operation_disable_set (void)
675 struct cleanup *old_cleanups = NULL;
678 make_cleanup_restore_integer (&record_full_gdb_operation_disable);
679 record_full_gdb_operation_disable = 1;
684 /* Flag set to TRUE for target_stopped_by_watchpoint. */
685 static enum target_stop_reason record_full_stop_reason
686 = TARGET_STOPPED_BY_NO_REASON;
688 /* Execute one instruction from the record log. Each instruction in
689 the log will be represented by an arbitrary sequence of register
690 entries and memory entries, followed by an 'end' entry. */
693 record_full_exec_insn (struct regcache *regcache,
694 struct gdbarch *gdbarch,
695 struct record_full_entry *entry)
699 case record_full_reg: /* reg */
701 gdb_byte reg[MAX_REGISTER_SIZE];
703 if (record_debug > 1)
704 fprintf_unfiltered (gdb_stdlog,
705 "Process record: record_full_reg %s to "
706 "inferior num = %d.\n",
707 host_address_to_string (entry),
710 regcache_cooked_read (regcache, entry->u.reg.num, reg);
711 regcache_cooked_write (regcache, entry->u.reg.num,
712 record_full_get_loc (entry));
713 memcpy (record_full_get_loc (entry), reg, entry->u.reg.len);
717 case record_full_mem: /* mem */
719 /* Nothing to do if the entry is flagged not_accessible. */
720 if (!entry->u.mem.mem_entry_not_accessible)
722 gdb_byte *mem = (gdb_byte *) xmalloc (entry->u.mem.len);
723 struct cleanup *cleanup = make_cleanup (xfree, mem);
725 if (record_debug > 1)
726 fprintf_unfiltered (gdb_stdlog,
727 "Process record: record_full_mem %s to "
728 "inferior addr = %s len = %d.\n",
729 host_address_to_string (entry),
730 paddress (gdbarch, entry->u.mem.addr),
733 if (record_read_memory (gdbarch,
734 entry->u.mem.addr, mem, entry->u.mem.len))
735 entry->u.mem.mem_entry_not_accessible = 1;
738 if (target_write_memory (entry->u.mem.addr,
739 record_full_get_loc (entry),
742 entry->u.mem.mem_entry_not_accessible = 1;
744 warning (_("Process record: error writing memory at "
745 "addr = %s len = %d."),
746 paddress (gdbarch, entry->u.mem.addr),
751 memcpy (record_full_get_loc (entry), mem,
754 /* We've changed memory --- check if a hardware
755 watchpoint should trap. Note that this
756 presently assumes the target beneath supports
757 continuable watchpoints. On non-continuable
758 watchpoints target, we'll want to check this
759 _before_ actually doing the memory change, and
760 not doing the change at all if the watchpoint
762 if (hardware_watchpoint_inserted_in_range
763 (get_regcache_aspace (regcache),
764 entry->u.mem.addr, entry->u.mem.len))
765 record_full_stop_reason = TARGET_STOPPED_BY_WATCHPOINT;
769 do_cleanups (cleanup);
776 static void record_full_restore (void);
778 /* Asynchronous signal handle registered as event loop source for when
779 we have pending events ready to be passed to the core. */
781 static struct async_event_handler *record_full_async_inferior_event_token;
784 record_full_async_inferior_event_handler (gdb_client_data data)
786 inferior_event_handler (INF_REG_EVENT, NULL);
789 /* Open the process record target. */
792 record_full_core_open_1 (const char *name, int from_tty)
794 struct regcache *regcache = get_current_regcache ();
795 int regnum = gdbarch_num_regs (get_regcache_arch (regcache));
798 /* Get record_full_core_regbuf. */
799 target_fetch_registers (regcache, -1);
800 record_full_core_regbuf = (gdb_byte *) xmalloc (MAX_REGISTER_SIZE * regnum);
801 for (i = 0; i < regnum; i ++)
802 regcache_raw_collect (regcache, i,
803 record_full_core_regbuf + MAX_REGISTER_SIZE * i);
805 /* Get record_full_core_start and record_full_core_end. */
806 if (build_section_table (core_bfd, &record_full_core_start,
807 &record_full_core_end))
809 xfree (record_full_core_regbuf);
810 record_full_core_regbuf = NULL;
811 error (_("\"%s\": Can't find sections: %s"),
812 bfd_get_filename (core_bfd), bfd_errmsg (bfd_get_error ()));
815 push_target (&record_full_core_ops);
816 record_full_restore ();
819 /* "to_open" target method for 'live' processes. */
822 record_full_open_1 (const char *name, int from_tty)
825 fprintf_unfiltered (gdb_stdlog, "Process record: record_full_open_1\n");
828 if (!target_has_execution)
829 error (_("Process record: the program is not being run."));
831 error (_("Process record target can't debug inferior in non-stop mode "
834 if (!gdbarch_process_record_p (target_gdbarch ()))
835 error (_("Process record: the current architecture doesn't support "
836 "record function."));
838 push_target (&record_full_ops);
841 static void record_full_init_record_breakpoints (void);
843 /* "to_open" target method. Open the process record target. */
846 record_full_open (const char *name, int from_tty)
848 struct target_ops *t;
851 fprintf_unfiltered (gdb_stdlog, "Process record: record_full_open\n");
856 record_full_insn_num = 0;
857 record_full_insn_count = 0;
858 record_full_list = &record_full_first;
859 record_full_list->next = NULL;
862 record_full_core_open_1 (name, from_tty);
864 record_full_open_1 (name, from_tty);
866 /* Register extra event sources in the event loop. */
867 record_full_async_inferior_event_token
868 = create_async_event_handler (record_full_async_inferior_event_handler,
871 record_full_init_record_breakpoints ();
873 observer_notify_record_changed (current_inferior (), 1, "full", NULL);
876 /* "to_close" target method. Close the process record target. */
879 record_full_close (struct target_ops *self)
881 struct record_full_core_buf_entry *entry;
884 fprintf_unfiltered (gdb_stdlog, "Process record: record_full_close\n");
886 record_full_list_release (record_full_list);
888 /* Release record_full_core_regbuf. */
889 if (record_full_core_regbuf)
891 xfree (record_full_core_regbuf);
892 record_full_core_regbuf = NULL;
895 /* Release record_full_core_buf_list. */
896 if (record_full_core_buf_list)
898 for (entry = record_full_core_buf_list->prev; entry;
901 xfree (record_full_core_buf_list);
902 record_full_core_buf_list = entry;
904 record_full_core_buf_list = NULL;
907 if (record_full_async_inferior_event_token)
908 delete_async_event_handler (&record_full_async_inferior_event_token);
911 /* "to_async" target method. */
914 record_full_async (struct target_ops *ops, int enable)
917 mark_async_event_handler (record_full_async_inferior_event_token);
919 clear_async_event_handler (record_full_async_inferior_event_token);
921 ops->beneath->to_async (ops->beneath, enable);
924 static int record_full_resume_step = 0;
926 /* True if we've been resumed, and so each record_full_wait call should
927 advance execution. If this is false, record_full_wait will return a
928 TARGET_WAITKIND_IGNORE. */
929 static int record_full_resumed = 0;
931 /* The execution direction of the last resume we got. This is
932 necessary for async mode. Vis (order is not strictly accurate):
934 1. user has the global execution direction set to forward
935 2. user does a reverse-step command
936 3. record_full_resume is called with global execution direction
937 temporarily switched to reverse
938 4. GDB's execution direction is reverted back to forward
939 5. target record notifies event loop there's an event to handle
940 6. infrun asks the target which direction was it going, and switches
941 the global execution direction accordingly (to reverse)
942 7. infrun polls an event out of the record target, and handles it
943 8. GDB goes back to the event loop, and goto #4.
945 static enum exec_direction_kind record_full_execution_dir = EXEC_FORWARD;
947 /* "to_resume" target method. Resume the process record target. */
950 record_full_resume (struct target_ops *ops, ptid_t ptid, int step,
951 enum gdb_signal signal)
953 record_full_resume_step = step;
954 record_full_resumed = 1;
955 record_full_execution_dir = execution_direction;
957 if (!RECORD_FULL_IS_REPLAY)
959 struct gdbarch *gdbarch = target_thread_architecture (ptid);
961 record_full_message (get_current_regcache (), signal);
965 /* This is not hard single step. */
966 if (!gdbarch_software_single_step_p (gdbarch))
968 /* This is a normal continue. */
973 /* This arch supports soft single step. */
974 if (thread_has_single_step_breakpoints_set (inferior_thread ()))
976 /* This is a soft single step. */
977 record_full_resume_step = 1;
980 step = !insert_single_step_breakpoints (gdbarch);
984 /* Make sure the target beneath reports all signals. */
985 target_pass_signals (0, NULL);
987 ops->beneath->to_resume (ops->beneath, ptid, step, signal);
990 /* We are about to start executing the inferior (or simulate it),
991 let's register it with the event loop. */
992 if (target_can_async_p ())
996 /* "to_commit_resume" method for process record target. */
999 record_full_commit_resume (struct target_ops *ops)
1001 if (!RECORD_FULL_IS_REPLAY)
1002 ops->beneath->to_commit_resume (ops->beneath);
1005 static int record_full_get_sig = 0;
1007 /* SIGINT signal handler, registered by "to_wait" method. */
1010 record_full_sig_handler (int signo)
1013 fprintf_unfiltered (gdb_stdlog, "Process record: get a signal\n");
1015 /* It will break the running inferior in replay mode. */
1016 record_full_resume_step = 1;
1018 /* It will let record_full_wait set inferior status to get the signal
1020 record_full_get_sig = 1;
1024 record_full_wait_cleanups (void *ignore)
1026 if (execution_direction == EXEC_REVERSE)
1028 if (record_full_list->next)
1029 record_full_list = record_full_list->next;
1032 record_full_list = record_full_list->prev;
1035 /* "to_wait" target method for process record target.
1037 In record mode, the target is always run in singlestep mode
1038 (even when gdb says to continue). The to_wait method intercepts
1039 the stop events and determines which ones are to be passed on to
1040 gdb. Most stop events are just singlestep events that gdb is not
1041 to know about, so the to_wait method just records them and keeps
1044 In replay mode, this function emulates the recorded execution log,
1045 one instruction at a time (forward or backward), and determines
1049 record_full_wait_1 (struct target_ops *ops,
1050 ptid_t ptid, struct target_waitstatus *status,
1053 struct cleanup *set_cleanups = record_full_gdb_operation_disable_set ();
1056 fprintf_unfiltered (gdb_stdlog,
1057 "Process record: record_full_wait "
1058 "record_full_resume_step = %d, "
1059 "record_full_resumed = %d, direction=%s\n",
1060 record_full_resume_step, record_full_resumed,
1061 record_full_execution_dir == EXEC_FORWARD
1062 ? "forward" : "reverse");
1064 if (!record_full_resumed)
1066 gdb_assert ((options & TARGET_WNOHANG) != 0);
1068 /* No interesting event. */
1069 status->kind = TARGET_WAITKIND_IGNORE;
1070 return minus_one_ptid;
1073 record_full_get_sig = 0;
1074 signal (SIGINT, record_full_sig_handler);
1076 record_full_stop_reason = TARGET_STOPPED_BY_NO_REASON;
1078 if (!RECORD_FULL_IS_REPLAY && ops != &record_full_core_ops)
1080 if (record_full_resume_step)
1082 /* This is a single step. */
1083 return ops->beneath->to_wait (ops->beneath, ptid, status, options);
1087 /* This is not a single step. */
1090 struct gdbarch *gdbarch = target_thread_architecture (inferior_ptid);
1094 struct thread_info *tp;
1096 ret = ops->beneath->to_wait (ops->beneath, ptid, status, options);
1097 if (status->kind == TARGET_WAITKIND_IGNORE)
1100 fprintf_unfiltered (gdb_stdlog,
1101 "Process record: record_full_wait "
1102 "target beneath not done yet\n");
1106 ALL_NON_EXITED_THREADS (tp)
1107 delete_single_step_breakpoints (tp);
1109 if (record_full_resume_step)
1112 /* Is this a SIGTRAP? */
1113 if (status->kind == TARGET_WAITKIND_STOPPED
1114 && status->value.sig == GDB_SIGNAL_TRAP)
1116 struct regcache *regcache;
1117 struct address_space *aspace;
1118 enum target_stop_reason *stop_reason_p
1119 = &record_full_stop_reason;
1121 /* Yes -- this is likely our single-step finishing,
1122 but check if there's any reason the core would be
1123 interested in the event. */
1125 registers_changed ();
1126 regcache = get_current_regcache ();
1127 tmp_pc = regcache_read_pc (regcache);
1128 aspace = get_regcache_aspace (regcache);
1130 if (target_stopped_by_watchpoint ())
1132 /* Always interested in watchpoints. */
1134 else if (record_check_stopped_by_breakpoint (aspace, tmp_pc,
1137 /* There is a breakpoint here. Let the core
1142 /* This is a single-step trap. Record the
1143 insn and issue another step.
1144 FIXME: this part can be a random SIGTRAP too.
1145 But GDB cannot handle it. */
1148 if (!record_full_message_wrapper_safe (regcache,
1151 status->kind = TARGET_WAITKIND_STOPPED;
1152 status->value.sig = GDB_SIGNAL_0;
1156 if (gdbarch_software_single_step_p (gdbarch))
1158 /* Try to insert the software single step breakpoint.
1159 If insert success, set step to 0. */
1160 set_executing (inferior_ptid, 0);
1161 reinit_frame_cache ();
1163 step = !insert_single_step_breakpoints (gdbarch);
1165 set_executing (inferior_ptid, 1);
1169 fprintf_unfiltered (gdb_stdlog,
1170 "Process record: record_full_wait "
1171 "issuing one more step in the "
1172 "target beneath\n");
1173 ops->beneath->to_resume (ops->beneath, ptid, step,
1175 ops->beneath->to_commit_resume (ops->beneath);
1180 /* The inferior is broken by a breakpoint or a signal. */
1189 struct regcache *regcache = get_current_regcache ();
1190 struct gdbarch *gdbarch = get_regcache_arch (regcache);
1191 struct address_space *aspace = get_regcache_aspace (regcache);
1192 int continue_flag = 1;
1193 int first_record_full_end = 1;
1194 struct cleanup *old_cleanups
1195 = make_cleanup (record_full_wait_cleanups, 0);
1198 record_full_stop_reason = TARGET_STOPPED_BY_NO_REASON;
1199 status->kind = TARGET_WAITKIND_STOPPED;
1201 /* Check breakpoint when forward execute. */
1202 if (execution_direction == EXEC_FORWARD)
1204 tmp_pc = regcache_read_pc (regcache);
1205 if (record_check_stopped_by_breakpoint (aspace, tmp_pc,
1206 &record_full_stop_reason))
1209 fprintf_unfiltered (gdb_stdlog,
1210 "Process record: break at %s.\n",
1211 paddress (gdbarch, tmp_pc));
1216 /* If GDB is in terminal_inferior mode, it will not get the signal.
1217 And in GDB replay mode, GDB doesn't need to be in terminal_inferior
1218 mode, because inferior will not executed.
1219 Then set it to terminal_ours to make GDB get the signal. */
1220 target_terminal_ours ();
1222 /* In EXEC_FORWARD mode, record_full_list points to the tail of prev
1224 if (execution_direction == EXEC_FORWARD && record_full_list->next)
1225 record_full_list = record_full_list->next;
1227 /* Loop over the record_full_list, looking for the next place to
1231 /* Check for beginning and end of log. */
1232 if (execution_direction == EXEC_REVERSE
1233 && record_full_list == &record_full_first)
1235 /* Hit beginning of record log in reverse. */
1236 status->kind = TARGET_WAITKIND_NO_HISTORY;
1239 if (execution_direction != EXEC_REVERSE && !record_full_list->next)
1241 /* Hit end of record log going forward. */
1242 status->kind = TARGET_WAITKIND_NO_HISTORY;
1246 record_full_exec_insn (regcache, gdbarch, record_full_list);
1248 if (record_full_list->type == record_full_end)
1250 if (record_debug > 1)
1251 fprintf_unfiltered (gdb_stdlog,
1252 "Process record: record_full_end %s to "
1254 host_address_to_string (record_full_list));
1256 if (first_record_full_end && execution_direction == EXEC_REVERSE)
1258 /* When reverse excute, the first record_full_end is the
1259 part of current instruction. */
1260 first_record_full_end = 0;
1264 /* In EXEC_REVERSE mode, this is the record_full_end of prev
1266 In EXEC_FORWARD mode, this is the record_full_end of
1267 current instruction. */
1269 if (record_full_resume_step)
1271 if (record_debug > 1)
1272 fprintf_unfiltered (gdb_stdlog,
1273 "Process record: step.\n");
1277 /* check breakpoint */
1278 tmp_pc = regcache_read_pc (regcache);
1279 if (record_check_stopped_by_breakpoint (aspace, tmp_pc,
1280 &record_full_stop_reason))
1283 fprintf_unfiltered (gdb_stdlog,
1284 "Process record: break "
1286 paddress (gdbarch, tmp_pc));
1291 if (record_full_stop_reason == TARGET_STOPPED_BY_WATCHPOINT)
1294 fprintf_unfiltered (gdb_stdlog,
1295 "Process record: hit hw "
1299 /* Check target signal */
1300 if (record_full_list->u.end.sigval != GDB_SIGNAL_0)
1301 /* FIXME: better way to check */
1308 if (execution_direction == EXEC_REVERSE)
1310 if (record_full_list->prev)
1311 record_full_list = record_full_list->prev;
1315 if (record_full_list->next)
1316 record_full_list = record_full_list->next;
1320 while (continue_flag);
1323 if (record_full_get_sig)
1324 status->value.sig = GDB_SIGNAL_INT;
1325 else if (record_full_list->u.end.sigval != GDB_SIGNAL_0)
1326 /* FIXME: better way to check */
1327 status->value.sig = record_full_list->u.end.sigval;
1329 status->value.sig = GDB_SIGNAL_TRAP;
1331 discard_cleanups (old_cleanups);
1334 signal (SIGINT, handle_sigint);
1336 do_cleanups (set_cleanups);
1337 return inferior_ptid;
1341 record_full_wait (struct target_ops *ops,
1342 ptid_t ptid, struct target_waitstatus *status,
1347 return_ptid = record_full_wait_1 (ops, ptid, status, options);
1348 if (status->kind != TARGET_WAITKIND_IGNORE)
1350 /* We're reporting a stop. Make sure any spurious
1351 target_wait(WNOHANG) doesn't advance the target until the
1352 core wants us resumed again. */
1353 record_full_resumed = 0;
1359 record_full_stopped_by_watchpoint (struct target_ops *ops)
1361 if (RECORD_FULL_IS_REPLAY)
1362 return record_full_stop_reason == TARGET_STOPPED_BY_WATCHPOINT;
1364 return ops->beneath->to_stopped_by_watchpoint (ops->beneath);
1368 record_full_stopped_data_address (struct target_ops *ops, CORE_ADDR *addr_p)
1370 if (RECORD_FULL_IS_REPLAY)
1373 return ops->beneath->to_stopped_data_address (ops->beneath, addr_p);
1376 /* The to_stopped_by_sw_breakpoint method of target record-full. */
1379 record_full_stopped_by_sw_breakpoint (struct target_ops *ops)
1381 return record_full_stop_reason == TARGET_STOPPED_BY_SW_BREAKPOINT;
1384 /* The to_supports_stopped_by_sw_breakpoint method of target
1388 record_full_supports_stopped_by_sw_breakpoint (struct target_ops *ops)
1393 /* The to_stopped_by_hw_breakpoint method of target record-full. */
1396 record_full_stopped_by_hw_breakpoint (struct target_ops *ops)
1398 return record_full_stop_reason == TARGET_STOPPED_BY_HW_BREAKPOINT;
1401 /* The to_supports_stopped_by_sw_breakpoint method of target
1405 record_full_supports_stopped_by_hw_breakpoint (struct target_ops *ops)
1410 /* Record registers change (by user or by GDB) to list as an instruction. */
1413 record_full_registers_change (struct regcache *regcache, int regnum)
1415 /* Check record_full_insn_num. */
1416 record_full_check_insn_num ();
1418 record_full_arch_list_head = NULL;
1419 record_full_arch_list_tail = NULL;
1425 for (i = 0; i < gdbarch_num_regs (get_regcache_arch (regcache)); i++)
1427 if (record_full_arch_list_add_reg (regcache, i))
1429 record_full_list_release (record_full_arch_list_tail);
1430 error (_("Process record: failed to record execution log."));
1436 if (record_full_arch_list_add_reg (regcache, regnum))
1438 record_full_list_release (record_full_arch_list_tail);
1439 error (_("Process record: failed to record execution log."));
1442 if (record_full_arch_list_add_end ())
1444 record_full_list_release (record_full_arch_list_tail);
1445 error (_("Process record: failed to record execution log."));
1447 record_full_list->next = record_full_arch_list_head;
1448 record_full_arch_list_head->prev = record_full_list;
1449 record_full_list = record_full_arch_list_tail;
1451 if (record_full_insn_num == record_full_insn_max_num)
1452 record_full_list_release_first ();
1454 record_full_insn_num++;
1457 /* "to_store_registers" method for process record target. */
1460 record_full_store_registers (struct target_ops *ops,
1461 struct regcache *regcache,
1464 if (!record_full_gdb_operation_disable)
1466 if (RECORD_FULL_IS_REPLAY)
1470 /* Let user choose if he wants to write register or not. */
1473 query (_("Because GDB is in replay mode, changing the "
1474 "value of a register will make the execution "
1475 "log unusable from this point onward. "
1476 "Change all registers?"));
1479 query (_("Because GDB is in replay mode, changing the value "
1480 "of a register will make the execution log unusable "
1481 "from this point onward. Change register %s?"),
1482 gdbarch_register_name (get_regcache_arch (regcache),
1487 /* Invalidate the value of regcache that was set in function
1488 "regcache_raw_write". */
1494 i < gdbarch_num_regs (get_regcache_arch (regcache));
1496 regcache_invalidate (regcache, i);
1499 regcache_invalidate (regcache, regno);
1501 error (_("Process record canceled the operation."));
1504 /* Destroy the record from here forward. */
1505 record_full_list_release_following (record_full_list);
1508 record_full_registers_change (regcache, regno);
1510 ops->beneath->to_store_registers (ops->beneath, regcache, regno);
1513 /* "to_xfer_partial" method. Behavior is conditional on
1514 RECORD_FULL_IS_REPLAY.
1515 In replay mode, we cannot write memory unles we are willing to
1516 invalidate the record/replay log from this point forward. */
1518 static enum target_xfer_status
1519 record_full_xfer_partial (struct target_ops *ops, enum target_object object,
1520 const char *annex, gdb_byte *readbuf,
1521 const gdb_byte *writebuf, ULONGEST offset,
1522 ULONGEST len, ULONGEST *xfered_len)
1524 if (!record_full_gdb_operation_disable
1525 && (object == TARGET_OBJECT_MEMORY
1526 || object == TARGET_OBJECT_RAW_MEMORY) && writebuf)
1528 if (RECORD_FULL_IS_REPLAY)
1530 /* Let user choose if he wants to write memory or not. */
1531 if (!query (_("Because GDB is in replay mode, writing to memory "
1532 "will make the execution log unusable from this "
1533 "point onward. Write memory at address %s?"),
1534 paddress (target_gdbarch (), offset)))
1535 error (_("Process record canceled the operation."));
1537 /* Destroy the record from here forward. */
1538 record_full_list_release_following (record_full_list);
1541 /* Check record_full_insn_num */
1542 record_full_check_insn_num ();
1544 /* Record registers change to list as an instruction. */
1545 record_full_arch_list_head = NULL;
1546 record_full_arch_list_tail = NULL;
1547 if (record_full_arch_list_add_mem (offset, len))
1549 record_full_list_release (record_full_arch_list_tail);
1551 fprintf_unfiltered (gdb_stdlog,
1552 "Process record: failed to record "
1554 return TARGET_XFER_E_IO;
1556 if (record_full_arch_list_add_end ())
1558 record_full_list_release (record_full_arch_list_tail);
1560 fprintf_unfiltered (gdb_stdlog,
1561 "Process record: failed to record "
1563 return TARGET_XFER_E_IO;
1565 record_full_list->next = record_full_arch_list_head;
1566 record_full_arch_list_head->prev = record_full_list;
1567 record_full_list = record_full_arch_list_tail;
1569 if (record_full_insn_num == record_full_insn_max_num)
1570 record_full_list_release_first ();
1572 record_full_insn_num++;
1575 return ops->beneath->to_xfer_partial (ops->beneath, object, annex,
1576 readbuf, writebuf, offset,
1580 /* This structure represents a breakpoint inserted while the record
1581 target is active. We use this to know when to install/remove
1582 breakpoints in/from the target beneath. For example, a breakpoint
1583 may be inserted while recording, but removed when not replaying nor
1584 recording. In that case, the breakpoint had not been inserted on
1585 the target beneath, so we should not try to remove it there. */
1587 struct record_full_breakpoint
1589 /* The address and address space the breakpoint was set at. */
1590 struct address_space *address_space;
1593 /* True when the breakpoint has been also installed in the target
1594 beneath. This will be false for breakpoints set during replay or
1596 int in_target_beneath;
1599 typedef struct record_full_breakpoint *record_full_breakpoint_p;
1600 DEF_VEC_P(record_full_breakpoint_p);
1602 /* The list of breakpoints inserted while the record target is
1604 VEC(record_full_breakpoint_p) *record_full_breakpoints = NULL;
1607 record_full_sync_record_breakpoints (struct bp_location *loc, void *data)
1609 if (loc->loc_type != bp_loc_software_breakpoint)
1614 struct record_full_breakpoint *bp = XNEW (struct record_full_breakpoint);
1616 bp->addr = loc->target_info.placed_address;
1617 bp->address_space = loc->target_info.placed_address_space;
1619 bp->in_target_beneath = 1;
1621 VEC_safe_push (record_full_breakpoint_p, record_full_breakpoints, bp);
1625 /* Sync existing breakpoints to record_full_breakpoints. */
1628 record_full_init_record_breakpoints (void)
1630 VEC_free (record_full_breakpoint_p, record_full_breakpoints);
1632 iterate_over_bp_locations (record_full_sync_record_breakpoints);
1635 /* Behavior is conditional on RECORD_FULL_IS_REPLAY. We will not actually
1636 insert or remove breakpoints in the real target when replaying, nor
1640 record_full_insert_breakpoint (struct target_ops *ops,
1641 struct gdbarch *gdbarch,
1642 struct bp_target_info *bp_tgt)
1644 struct record_full_breakpoint *bp;
1645 int in_target_beneath = 0;
1648 if (!RECORD_FULL_IS_REPLAY)
1650 /* When recording, we currently always single-step, so we don't
1651 really need to install regular breakpoints in the inferior.
1652 However, we do have to insert software single-step
1653 breakpoints, in case the target can't hardware step. To keep
1654 things simple, we always insert. */
1655 struct cleanup *old_cleanups;
1658 old_cleanups = record_full_gdb_operation_disable_set ();
1659 ret = ops->beneath->to_insert_breakpoint (ops->beneath, gdbarch, bp_tgt);
1660 do_cleanups (old_cleanups);
1665 in_target_beneath = 1;
1668 /* Use the existing entries if found in order to avoid duplication
1669 in record_full_breakpoints. */
1672 VEC_iterate (record_full_breakpoint_p,
1673 record_full_breakpoints, ix, bp);
1676 if (bp->addr == bp_tgt->placed_address
1677 && bp->address_space == bp_tgt->placed_address_space)
1679 gdb_assert (bp->in_target_beneath == in_target_beneath);
1684 bp = XNEW (struct record_full_breakpoint);
1685 bp->addr = bp_tgt->placed_address;
1686 bp->address_space = bp_tgt->placed_address_space;
1687 bp->in_target_beneath = in_target_beneath;
1688 VEC_safe_push (record_full_breakpoint_p, record_full_breakpoints, bp);
1692 /* "to_remove_breakpoint" method for process record target. */
1695 record_full_remove_breakpoint (struct target_ops *ops,
1696 struct gdbarch *gdbarch,
1697 struct bp_target_info *bp_tgt,
1698 enum remove_bp_reason reason)
1700 struct record_full_breakpoint *bp;
1704 VEC_iterate (record_full_breakpoint_p,
1705 record_full_breakpoints, ix, bp);
1708 if (bp->addr == bp_tgt->placed_address
1709 && bp->address_space == bp_tgt->placed_address_space)
1711 if (bp->in_target_beneath)
1713 struct cleanup *old_cleanups;
1716 old_cleanups = record_full_gdb_operation_disable_set ();
1717 ret = ops->beneath->to_remove_breakpoint (ops->beneath, gdbarch,
1719 do_cleanups (old_cleanups);
1725 if (reason == REMOVE_BREAKPOINT)
1727 VEC_unordered_remove (record_full_breakpoint_p,
1728 record_full_breakpoints, ix);
1734 gdb_assert_not_reached ("removing unknown breakpoint");
1737 /* "to_can_execute_reverse" method for process record target. */
1740 record_full_can_execute_reverse (struct target_ops *self)
1745 /* "to_get_bookmark" method for process record and prec over core. */
1748 record_full_get_bookmark (struct target_ops *self, const char *args,
1753 /* Return stringified form of instruction count. */
1754 if (record_full_list && record_full_list->type == record_full_end)
1755 ret = xstrdup (pulongest (record_full_list->u.end.insn_num));
1760 fprintf_unfiltered (gdb_stdlog,
1761 "record_full_get_bookmark returns %s\n", ret);
1763 fprintf_unfiltered (gdb_stdlog,
1764 "record_full_get_bookmark returns NULL\n");
1766 return (gdb_byte *) ret;
1769 /* "to_goto_bookmark" method for process record and prec over core. */
1772 record_full_goto_bookmark (struct target_ops *self,
1773 const gdb_byte *raw_bookmark, int from_tty)
1775 const char *bookmark = (const char *) raw_bookmark;
1776 struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
1779 fprintf_unfiltered (gdb_stdlog,
1780 "record_full_goto_bookmark receives %s\n", bookmark);
1782 if (bookmark[0] == '\'' || bookmark[0] == '\"')
1786 if (bookmark[strlen (bookmark) - 1] != bookmark[0])
1787 error (_("Unbalanced quotes: %s"), bookmark);
1790 copy = savestring (bookmark + 1, strlen (bookmark) - 2);
1791 make_cleanup (xfree, copy);
1795 record_goto (bookmark);
1797 do_cleanups (cleanup);
1800 static enum exec_direction_kind
1801 record_full_execution_direction (struct target_ops *self)
1803 return record_full_execution_dir;
1807 record_full_info (struct target_ops *self)
1809 struct record_full_entry *p;
1811 if (RECORD_FULL_IS_REPLAY)
1812 printf_filtered (_("Replay mode:\n"));
1814 printf_filtered (_("Record mode:\n"));
1816 /* Find entry for first actual instruction in the log. */
1817 for (p = record_full_first.next;
1818 p != NULL && p->type != record_full_end;
1822 /* Do we have a log at all? */
1823 if (p != NULL && p->type == record_full_end)
1825 /* Display instruction number for first instruction in the log. */
1826 printf_filtered (_("Lowest recorded instruction number is %s.\n"),
1827 pulongest (p->u.end.insn_num));
1829 /* If in replay mode, display where we are in the log. */
1830 if (RECORD_FULL_IS_REPLAY)
1831 printf_filtered (_("Current instruction number is %s.\n"),
1832 pulongest (record_full_list->u.end.insn_num));
1834 /* Display instruction number for last instruction in the log. */
1835 printf_filtered (_("Highest recorded instruction number is %s.\n"),
1836 pulongest (record_full_insn_count));
1838 /* Display log count. */
1839 printf_filtered (_("Log contains %u instructions.\n"),
1840 record_full_insn_num);
1843 printf_filtered (_("No instructions have been logged.\n"));
1845 /* Display max log size. */
1846 printf_filtered (_("Max logged instructions is %u.\n"),
1847 record_full_insn_max_num);
1850 /* The "to_record_delete" target method. */
1853 record_full_delete (struct target_ops *self)
1855 record_full_list_release_following (record_full_list);
1858 /* The "to_record_is_replaying" target method. */
1861 record_full_is_replaying (struct target_ops *self, ptid_t ptid)
1863 return RECORD_FULL_IS_REPLAY;
1866 /* The "to_record_will_replay" target method. */
1869 record_full_will_replay (struct target_ops *self, ptid_t ptid, int dir)
1871 /* We can currently only record when executing forwards. Should we be able
1872 to record when executing backwards on targets that support reverse
1873 execution, this needs to be changed. */
1875 return RECORD_FULL_IS_REPLAY || dir == EXEC_REVERSE;
1878 /* Go to a specific entry. */
1881 record_full_goto_entry (struct record_full_entry *p)
1884 error (_("Target insn not found."));
1885 else if (p == record_full_list)
1886 error (_("Already at target insn."));
1887 else if (p->u.end.insn_num > record_full_list->u.end.insn_num)
1889 printf_filtered (_("Go forward to insn number %s\n"),
1890 pulongest (p->u.end.insn_num));
1891 record_full_goto_insn (p, EXEC_FORWARD);
1895 printf_filtered (_("Go backward to insn number %s\n"),
1896 pulongest (p->u.end.insn_num));
1897 record_full_goto_insn (p, EXEC_REVERSE);
1900 registers_changed ();
1901 reinit_frame_cache ();
1902 stop_pc = regcache_read_pc (get_current_regcache ());
1903 print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1);
1906 /* The "to_goto_record_begin" target method. */
1909 record_full_goto_begin (struct target_ops *self)
1911 struct record_full_entry *p = NULL;
1913 for (p = &record_full_first; p != NULL; p = p->next)
1914 if (p->type == record_full_end)
1917 record_full_goto_entry (p);
1920 /* The "to_goto_record_end" target method. */
1923 record_full_goto_end (struct target_ops *self)
1925 struct record_full_entry *p = NULL;
1927 for (p = record_full_list; p->next != NULL; p = p->next)
1929 for (; p!= NULL; p = p->prev)
1930 if (p->type == record_full_end)
1933 record_full_goto_entry (p);
1936 /* The "to_goto_record" target method. */
1939 record_full_goto (struct target_ops *self, ULONGEST target_insn)
1941 struct record_full_entry *p = NULL;
1943 for (p = &record_full_first; p != NULL; p = p->next)
1944 if (p->type == record_full_end && p->u.end.insn_num == target_insn)
1947 record_full_goto_entry (p);
1950 /* The "to_record_stop_replaying" target method. */
1953 record_full_stop_replaying (struct target_ops *self)
1955 record_full_goto_end (self);
1959 init_record_full_ops (void)
1961 record_full_ops.to_shortname = "record-full";
1962 record_full_ops.to_longname = "Process record and replay target";
1963 record_full_ops.to_doc =
1964 "Log program while executing and replay execution from log.";
1965 record_full_ops.to_open = record_full_open;
1966 record_full_ops.to_close = record_full_close;
1967 record_full_ops.to_async = record_full_async;
1968 record_full_ops.to_resume = record_full_resume;
1969 record_full_ops.to_commit_resume = record_full_commit_resume;
1970 record_full_ops.to_wait = record_full_wait;
1971 record_full_ops.to_disconnect = record_disconnect;
1972 record_full_ops.to_detach = record_detach;
1973 record_full_ops.to_mourn_inferior = record_mourn_inferior;
1974 record_full_ops.to_kill = record_kill;
1975 record_full_ops.to_store_registers = record_full_store_registers;
1976 record_full_ops.to_xfer_partial = record_full_xfer_partial;
1977 record_full_ops.to_insert_breakpoint = record_full_insert_breakpoint;
1978 record_full_ops.to_remove_breakpoint = record_full_remove_breakpoint;
1979 record_full_ops.to_stopped_by_watchpoint = record_full_stopped_by_watchpoint;
1980 record_full_ops.to_stopped_data_address = record_full_stopped_data_address;
1981 record_full_ops.to_stopped_by_sw_breakpoint
1982 = record_full_stopped_by_sw_breakpoint;
1983 record_full_ops.to_supports_stopped_by_sw_breakpoint
1984 = record_full_supports_stopped_by_sw_breakpoint;
1985 record_full_ops.to_stopped_by_hw_breakpoint
1986 = record_full_stopped_by_hw_breakpoint;
1987 record_full_ops.to_supports_stopped_by_hw_breakpoint
1988 = record_full_supports_stopped_by_hw_breakpoint;
1989 record_full_ops.to_can_execute_reverse = record_full_can_execute_reverse;
1990 record_full_ops.to_stratum = record_stratum;
1991 /* Add bookmark target methods. */
1992 record_full_ops.to_get_bookmark = record_full_get_bookmark;
1993 record_full_ops.to_goto_bookmark = record_full_goto_bookmark;
1994 record_full_ops.to_execution_direction = record_full_execution_direction;
1995 record_full_ops.to_info_record = record_full_info;
1996 record_full_ops.to_save_record = record_full_save;
1997 record_full_ops.to_delete_record = record_full_delete;
1998 record_full_ops.to_record_is_replaying = record_full_is_replaying;
1999 record_full_ops.to_record_will_replay = record_full_will_replay;
2000 record_full_ops.to_record_stop_replaying = record_full_stop_replaying;
2001 record_full_ops.to_goto_record_begin = record_full_goto_begin;
2002 record_full_ops.to_goto_record_end = record_full_goto_end;
2003 record_full_ops.to_goto_record = record_full_goto;
2004 record_full_ops.to_magic = OPS_MAGIC;
2007 /* "to_resume" method for prec over corefile. */
2010 record_full_core_resume (struct target_ops *ops, ptid_t ptid, int step,
2011 enum gdb_signal signal)
2013 record_full_resume_step = step;
2014 record_full_resumed = 1;
2015 record_full_execution_dir = execution_direction;
2017 /* We are about to start executing the inferior (or simulate it),
2018 let's register it with the event loop. */
2019 if (target_can_async_p ())
2023 /* "to_kill" method for prec over corefile. */
2026 record_full_core_kill (struct target_ops *ops)
2029 fprintf_unfiltered (gdb_stdlog, "Process record: record_full_core_kill\n");
2031 unpush_target (&record_full_core_ops);
2034 /* "to_fetch_registers" method for prec over corefile. */
2037 record_full_core_fetch_registers (struct target_ops *ops,
2038 struct regcache *regcache,
2043 int num = gdbarch_num_regs (get_regcache_arch (regcache));
2046 for (i = 0; i < num; i ++)
2047 regcache_raw_supply (regcache, i,
2048 record_full_core_regbuf + MAX_REGISTER_SIZE * i);
2051 regcache_raw_supply (regcache, regno,
2052 record_full_core_regbuf + MAX_REGISTER_SIZE * regno);
2055 /* "to_prepare_to_store" method for prec over corefile. */
2058 record_full_core_prepare_to_store (struct target_ops *self,
2059 struct regcache *regcache)
2063 /* "to_store_registers" method for prec over corefile. */
2066 record_full_core_store_registers (struct target_ops *ops,
2067 struct regcache *regcache,
2070 if (record_full_gdb_operation_disable)
2071 regcache_raw_collect (regcache, regno,
2072 record_full_core_regbuf + MAX_REGISTER_SIZE * regno);
2074 error (_("You can't do that without a process to debug."));
2077 /* "to_xfer_partial" method for prec over corefile. */
2079 static enum target_xfer_status
2080 record_full_core_xfer_partial (struct target_ops *ops,
2081 enum target_object object,
2082 const char *annex, gdb_byte *readbuf,
2083 const gdb_byte *writebuf, ULONGEST offset,
2084 ULONGEST len, ULONGEST *xfered_len)
2086 if (object == TARGET_OBJECT_MEMORY)
2088 if (record_full_gdb_operation_disable || !writebuf)
2090 struct target_section *p;
2092 for (p = record_full_core_start; p < record_full_core_end; p++)
2094 if (offset >= p->addr)
2096 struct record_full_core_buf_entry *entry;
2097 ULONGEST sec_offset;
2099 if (offset >= p->endaddr)
2102 if (offset + len > p->endaddr)
2103 len = p->endaddr - offset;
2105 sec_offset = offset - p->addr;
2107 /* Read readbuf or write writebuf p, offset, len. */
2109 if (p->the_bfd_section->flags & SEC_CONSTRUCTOR
2110 || (p->the_bfd_section->flags & SEC_HAS_CONTENTS) == 0)
2113 memset (readbuf, 0, len);
2116 return TARGET_XFER_OK;
2118 /* Get record_full_core_buf_entry. */
2119 for (entry = record_full_core_buf_list; entry;
2120 entry = entry->prev)
2127 /* Add a new entry. */
2128 entry = XNEW (struct record_full_core_buf_entry);
2130 if (!bfd_malloc_and_get_section
2131 (p->the_bfd_section->owner,
2136 return TARGET_XFER_EOF;
2138 entry->prev = record_full_core_buf_list;
2139 record_full_core_buf_list = entry;
2142 memcpy (entry->buf + sec_offset, writebuf,
2148 return ops->beneath->to_xfer_partial (ops->beneath,
2154 memcpy (readbuf, entry->buf + sec_offset,
2159 return TARGET_XFER_OK;
2163 return TARGET_XFER_E_IO;
2166 error (_("You can't do that without a process to debug."));
2169 return ops->beneath->to_xfer_partial (ops->beneath, object, annex,
2170 readbuf, writebuf, offset, len,
2174 /* "to_insert_breakpoint" method for prec over corefile. */
2177 record_full_core_insert_breakpoint (struct target_ops *ops,
2178 struct gdbarch *gdbarch,
2179 struct bp_target_info *bp_tgt)
2184 /* "to_remove_breakpoint" method for prec over corefile. */
2187 record_full_core_remove_breakpoint (struct target_ops *ops,
2188 struct gdbarch *gdbarch,
2189 struct bp_target_info *bp_tgt,
2190 enum remove_bp_reason reason)
2195 /* "to_has_execution" method for prec over corefile. */
2198 record_full_core_has_execution (struct target_ops *ops, ptid_t the_ptid)
2204 init_record_full_core_ops (void)
2206 record_full_core_ops.to_shortname = "record-core";
2207 record_full_core_ops.to_longname = "Process record and replay target";
2208 record_full_core_ops.to_doc =
2209 "Log program while executing and replay execution from log.";
2210 record_full_core_ops.to_open = record_full_open;
2211 record_full_core_ops.to_close = record_full_close;
2212 record_full_core_ops.to_async = record_full_async;
2213 record_full_core_ops.to_resume = record_full_core_resume;
2214 record_full_core_ops.to_wait = record_full_wait;
2215 record_full_core_ops.to_kill = record_full_core_kill;
2216 record_full_core_ops.to_fetch_registers = record_full_core_fetch_registers;
2217 record_full_core_ops.to_prepare_to_store = record_full_core_prepare_to_store;
2218 record_full_core_ops.to_store_registers = record_full_core_store_registers;
2219 record_full_core_ops.to_xfer_partial = record_full_core_xfer_partial;
2220 record_full_core_ops.to_insert_breakpoint
2221 = record_full_core_insert_breakpoint;
2222 record_full_core_ops.to_remove_breakpoint
2223 = record_full_core_remove_breakpoint;
2224 record_full_core_ops.to_stopped_by_watchpoint
2225 = record_full_stopped_by_watchpoint;
2226 record_full_core_ops.to_stopped_data_address
2227 = record_full_stopped_data_address;
2228 record_full_core_ops.to_stopped_by_sw_breakpoint
2229 = record_full_stopped_by_sw_breakpoint;
2230 record_full_core_ops.to_supports_stopped_by_sw_breakpoint
2231 = record_full_supports_stopped_by_sw_breakpoint;
2232 record_full_core_ops.to_stopped_by_hw_breakpoint
2233 = record_full_stopped_by_hw_breakpoint;
2234 record_full_core_ops.to_supports_stopped_by_hw_breakpoint
2235 = record_full_supports_stopped_by_hw_breakpoint;
2236 record_full_core_ops.to_can_execute_reverse
2237 = record_full_can_execute_reverse;
2238 record_full_core_ops.to_has_execution = record_full_core_has_execution;
2239 record_full_core_ops.to_stratum = record_stratum;
2240 /* Add bookmark target methods. */
2241 record_full_core_ops.to_get_bookmark = record_full_get_bookmark;
2242 record_full_core_ops.to_goto_bookmark = record_full_goto_bookmark;
2243 record_full_core_ops.to_execution_direction
2244 = record_full_execution_direction;
2245 record_full_core_ops.to_info_record = record_full_info;
2246 record_full_core_ops.to_delete_record = record_full_delete;
2247 record_full_core_ops.to_record_is_replaying = record_full_is_replaying;
2248 record_full_core_ops.to_record_will_replay = record_full_will_replay;
2249 record_full_core_ops.to_goto_record_begin = record_full_goto_begin;
2250 record_full_core_ops.to_goto_record_end = record_full_goto_end;
2251 record_full_core_ops.to_goto_record = record_full_goto;
2252 record_full_core_ops.to_magic = OPS_MAGIC;
2255 /* Record log save-file format
2256 Version 1 (never released)
2259 4 bytes: magic number htonl(0x20090829).
2260 NOTE: be sure to change whenever this file format changes!
2264 1 byte: record type (record_full_end, see enum record_full_type).
2266 1 byte: record type (record_full_reg, see enum record_full_type).
2267 8 bytes: register id (network byte order).
2268 MAX_REGISTER_SIZE bytes: register value.
2270 1 byte: record type (record_full_mem, see enum record_full_type).
2271 8 bytes: memory length (network byte order).
2272 8 bytes: memory address (network byte order).
2273 n bytes: memory value (n == memory length).
2276 4 bytes: magic number netorder32(0x20091016).
2277 NOTE: be sure to change whenever this file format changes!
2281 1 byte: record type (record_full_end, see enum record_full_type).
2283 4 bytes: instruction count
2285 1 byte: record type (record_full_reg, see enum record_full_type).
2286 4 bytes: register id (network byte order).
2287 n bytes: register value (n == actual register size).
2288 (eg. 4 bytes for x86 general registers).
2290 1 byte: record type (record_full_mem, see enum record_full_type).
2291 4 bytes: memory length (network byte order).
2292 8 bytes: memory address (network byte order).
2293 n bytes: memory value (n == memory length).
2297 /* bfdcore_read -- read bytes from a core file section. */
2300 bfdcore_read (bfd *obfd, asection *osec, void *buf, int len, int *offset)
2302 int ret = bfd_get_section_contents (obfd, osec, buf, *offset, len);
2307 error (_("Failed to read %d bytes from core file %s ('%s')."),
2308 len, bfd_get_filename (obfd),
2309 bfd_errmsg (bfd_get_error ()));
2312 static inline uint64_t
2313 netorder64 (uint64_t input)
2317 store_unsigned_integer ((gdb_byte *) &ret, sizeof (ret),
2318 BFD_ENDIAN_BIG, input);
2322 static inline uint32_t
2323 netorder32 (uint32_t input)
2327 store_unsigned_integer ((gdb_byte *) &ret, sizeof (ret),
2328 BFD_ENDIAN_BIG, input);
2332 static inline uint16_t
2333 netorder16 (uint16_t input)
2337 store_unsigned_integer ((gdb_byte *) &ret, sizeof (ret),
2338 BFD_ENDIAN_BIG, input);
2342 /* Restore the execution log from a core_bfd file. */
2344 record_full_restore (void)
2347 struct cleanup *old_cleanups;
2348 struct record_full_entry *rec;
2352 struct regcache *regcache;
2354 /* We restore the execution log from the open core bfd,
2356 if (core_bfd == NULL)
2359 /* "record_full_restore" can only be called when record list is empty. */
2360 gdb_assert (record_full_first.next == NULL);
2363 fprintf_unfiltered (gdb_stdlog, "Restoring recording from core file.\n");
2365 /* Now need to find our special note section. */
2366 osec = bfd_get_section_by_name (core_bfd, "null0");
2368 fprintf_unfiltered (gdb_stdlog, "Find precord section %s.\n",
2369 osec ? "succeeded" : "failed");
2372 osec_size = bfd_section_size (core_bfd, osec);
2374 fprintf_unfiltered (gdb_stdlog, "%s", bfd_section_name (core_bfd, osec));
2376 /* Check the magic code. */
2377 bfdcore_read (core_bfd, osec, &magic, sizeof (magic), &bfd_offset);
2378 if (magic != RECORD_FULL_FILE_MAGIC)
2379 error (_("Version mis-match or file format error in core file %s."),
2380 bfd_get_filename (core_bfd));
2382 fprintf_unfiltered (gdb_stdlog,
2383 " Reading 4-byte magic cookie "
2384 "RECORD_FULL_FILE_MAGIC (0x%s)\n",
2385 phex_nz (netorder32 (magic), 4));
2387 /* Restore the entries in recfd into record_full_arch_list_head and
2388 record_full_arch_list_tail. */
2389 record_full_arch_list_head = NULL;
2390 record_full_arch_list_tail = NULL;
2391 record_full_insn_num = 0;
2392 old_cleanups = make_cleanup (record_full_arch_list_cleanups, 0);
2393 regcache = get_current_regcache ();
2398 uint32_t regnum, len, signal, count;
2401 /* We are finished when offset reaches osec_size. */
2402 if (bfd_offset >= osec_size)
2404 bfdcore_read (core_bfd, osec, &rectype, sizeof (rectype), &bfd_offset);
2408 case record_full_reg: /* reg */
2409 /* Get register number to regnum. */
2410 bfdcore_read (core_bfd, osec, ®num,
2411 sizeof (regnum), &bfd_offset);
2412 regnum = netorder32 (regnum);
2414 rec = record_full_reg_alloc (regcache, regnum);
2417 bfdcore_read (core_bfd, osec, record_full_get_loc (rec),
2418 rec->u.reg.len, &bfd_offset);
2421 fprintf_unfiltered (gdb_stdlog,
2422 " Reading register %d (1 "
2423 "plus %lu plus %d bytes)\n",
2425 (unsigned long) sizeof (regnum),
2429 case record_full_mem: /* mem */
2431 bfdcore_read (core_bfd, osec, &len,
2432 sizeof (len), &bfd_offset);
2433 len = netorder32 (len);
2436 bfdcore_read (core_bfd, osec, &addr,
2437 sizeof (addr), &bfd_offset);
2438 addr = netorder64 (addr);
2440 rec = record_full_mem_alloc (addr, len);
2443 bfdcore_read (core_bfd, osec, record_full_get_loc (rec),
2444 rec->u.mem.len, &bfd_offset);
2447 fprintf_unfiltered (gdb_stdlog,
2448 " Reading memory %s (1 plus "
2449 "%lu plus %lu plus %d bytes)\n",
2450 paddress (get_current_arch (),
2452 (unsigned long) sizeof (addr),
2453 (unsigned long) sizeof (len),
2457 case record_full_end: /* end */
2458 rec = record_full_end_alloc ();
2459 record_full_insn_num ++;
2461 /* Get signal value. */
2462 bfdcore_read (core_bfd, osec, &signal,
2463 sizeof (signal), &bfd_offset);
2464 signal = netorder32 (signal);
2465 rec->u.end.sigval = (enum gdb_signal) signal;
2467 /* Get insn count. */
2468 bfdcore_read (core_bfd, osec, &count,
2469 sizeof (count), &bfd_offset);
2470 count = netorder32 (count);
2471 rec->u.end.insn_num = count;
2472 record_full_insn_count = count + 1;
2474 fprintf_unfiltered (gdb_stdlog,
2475 " Reading record_full_end (1 + "
2476 "%lu + %lu bytes), offset == %s\n",
2477 (unsigned long) sizeof (signal),
2478 (unsigned long) sizeof (count),
2479 paddress (get_current_arch (),
2484 error (_("Bad entry type in core file %s."),
2485 bfd_get_filename (core_bfd));
2489 /* Add rec to record arch list. */
2490 record_full_arch_list_add (rec);
2493 discard_cleanups (old_cleanups);
2495 /* Add record_full_arch_list_head to the end of record list. */
2496 record_full_first.next = record_full_arch_list_head;
2497 record_full_arch_list_head->prev = &record_full_first;
2498 record_full_arch_list_tail->next = NULL;
2499 record_full_list = &record_full_first;
2501 /* Update record_full_insn_max_num. */
2502 if (record_full_insn_num > record_full_insn_max_num)
2504 record_full_insn_max_num = record_full_insn_num;
2505 warning (_("Auto increase record/replay buffer limit to %u."),
2506 record_full_insn_max_num);
2510 printf_filtered (_("Restored records from core file %s.\n"),
2511 bfd_get_filename (core_bfd));
2513 print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1);
2516 /* bfdcore_write -- write bytes into a core file section. */
2519 bfdcore_write (bfd *obfd, asection *osec, void *buf, int len, int *offset)
2521 int ret = bfd_set_section_contents (obfd, osec, buf, *offset, len);
2526 error (_("Failed to write %d bytes to core file %s ('%s')."),
2527 len, bfd_get_filename (obfd),
2528 bfd_errmsg (bfd_get_error ()));
2531 /* Restore the execution log from a file. We use a modified elf
2532 corefile format, with an extra section for our data. */
2535 cmd_record_full_restore (char *args, int from_tty)
2537 core_file_command (args, from_tty);
2538 record_full_open (args, from_tty);
2541 /* Save the execution log to a file. We use a modified elf corefile
2542 format, with an extra section for our data. */
2545 record_full_save (struct target_ops *self, const char *recfilename)
2547 struct record_full_entry *cur_record_full_list;
2549 struct regcache *regcache;
2550 struct gdbarch *gdbarch;
2551 struct cleanup *set_cleanups;
2553 asection *osec = NULL;
2556 /* Open the save file. */
2558 fprintf_unfiltered (gdb_stdlog, "Saving execution log to core file '%s'\n",
2561 /* Open the output file. */
2562 gdb_bfd_ref_ptr obfd (create_gcore_bfd (recfilename));
2564 /* Arrange to remove the output file on failure. */
2565 gdb::unlinker unlink_file (recfilename);
2567 /* Save the current record entry to "cur_record_full_list". */
2568 cur_record_full_list = record_full_list;
2570 /* Get the values of regcache and gdbarch. */
2571 regcache = get_current_regcache ();
2572 gdbarch = get_regcache_arch (regcache);
2574 /* Disable the GDB operation record. */
2575 set_cleanups = record_full_gdb_operation_disable_set ();
2577 /* Reverse execute to the begin of record list. */
2580 /* Check for beginning and end of log. */
2581 if (record_full_list == &record_full_first)
2584 record_full_exec_insn (regcache, gdbarch, record_full_list);
2586 if (record_full_list->prev)
2587 record_full_list = record_full_list->prev;
2590 /* Compute the size needed for the extra bfd section. */
2591 save_size = 4; /* magic cookie */
2592 for (record_full_list = record_full_first.next; record_full_list;
2593 record_full_list = record_full_list->next)
2594 switch (record_full_list->type)
2596 case record_full_end:
2597 save_size += 1 + 4 + 4;
2599 case record_full_reg:
2600 save_size += 1 + 4 + record_full_list->u.reg.len;
2602 case record_full_mem:
2603 save_size += 1 + 4 + 8 + record_full_list->u.mem.len;
2607 /* Make the new bfd section. */
2608 osec = bfd_make_section_anyway_with_flags (obfd.get (), "precord",
2612 error (_("Failed to create 'precord' section for corefile %s: %s"),
2614 bfd_errmsg (bfd_get_error ()));
2615 bfd_set_section_size (obfd.get (), osec, save_size);
2616 bfd_set_section_vma (obfd.get (), osec, 0);
2617 bfd_set_section_alignment (obfd.get (), osec, 0);
2618 bfd_section_lma (obfd.get (), osec) = 0;
2620 /* Save corefile state. */
2621 write_gcore_file (obfd.get ());
2623 /* Write out the record log. */
2624 /* Write the magic code. */
2625 magic = RECORD_FULL_FILE_MAGIC;
2627 fprintf_unfiltered (gdb_stdlog,
2628 " Writing 4-byte magic cookie "
2629 "RECORD_FULL_FILE_MAGIC (0x%s)\n",
2630 phex_nz (magic, 4));
2631 bfdcore_write (obfd.get (), osec, &magic, sizeof (magic), &bfd_offset);
2633 /* Save the entries to recfd and forward execute to the end of
2635 record_full_list = &record_full_first;
2639 if (record_full_list != &record_full_first)
2642 uint32_t regnum, len, signal, count;
2645 type = record_full_list->type;
2646 bfdcore_write (obfd.get (), osec, &type, sizeof (type), &bfd_offset);
2648 switch (record_full_list->type)
2650 case record_full_reg: /* reg */
2652 fprintf_unfiltered (gdb_stdlog,
2653 " Writing register %d (1 "
2654 "plus %lu plus %d bytes)\n",
2655 record_full_list->u.reg.num,
2656 (unsigned long) sizeof (regnum),
2657 record_full_list->u.reg.len);
2660 regnum = netorder32 (record_full_list->u.reg.num);
2661 bfdcore_write (obfd.get (), osec, ®num,
2662 sizeof (regnum), &bfd_offset);
2665 bfdcore_write (obfd.get (), osec,
2666 record_full_get_loc (record_full_list),
2667 record_full_list->u.reg.len, &bfd_offset);
2670 case record_full_mem: /* mem */
2672 fprintf_unfiltered (gdb_stdlog,
2673 " Writing memory %s (1 plus "
2674 "%lu plus %lu plus %d bytes)\n",
2676 record_full_list->u.mem.addr),
2677 (unsigned long) sizeof (addr),
2678 (unsigned long) sizeof (len),
2679 record_full_list->u.mem.len);
2682 len = netorder32 (record_full_list->u.mem.len);
2683 bfdcore_write (obfd.get (), osec, &len, sizeof (len),
2686 /* Write memaddr. */
2687 addr = netorder64 (record_full_list->u.mem.addr);
2688 bfdcore_write (obfd.get (), osec, &addr,
2689 sizeof (addr), &bfd_offset);
2692 bfdcore_write (obfd.get (), osec,
2693 record_full_get_loc (record_full_list),
2694 record_full_list->u.mem.len, &bfd_offset);
2697 case record_full_end:
2699 fprintf_unfiltered (gdb_stdlog,
2700 " Writing record_full_end (1 + "
2701 "%lu + %lu bytes)\n",
2702 (unsigned long) sizeof (signal),
2703 (unsigned long) sizeof (count));
2704 /* Write signal value. */
2705 signal = netorder32 (record_full_list->u.end.sigval);
2706 bfdcore_write (obfd.get (), osec, &signal,
2707 sizeof (signal), &bfd_offset);
2709 /* Write insn count. */
2710 count = netorder32 (record_full_list->u.end.insn_num);
2711 bfdcore_write (obfd.get (), osec, &count,
2712 sizeof (count), &bfd_offset);
2717 /* Execute entry. */
2718 record_full_exec_insn (regcache, gdbarch, record_full_list);
2720 if (record_full_list->next)
2721 record_full_list = record_full_list->next;
2726 /* Reverse execute to cur_record_full_list. */
2729 /* Check for beginning and end of log. */
2730 if (record_full_list == cur_record_full_list)
2733 record_full_exec_insn (regcache, gdbarch, record_full_list);
2735 if (record_full_list->prev)
2736 record_full_list = record_full_list->prev;
2739 do_cleanups (set_cleanups);
2740 unlink_file.keep ();
2743 printf_filtered (_("Saved core file %s with execution log.\n"),
2747 /* record_full_goto_insn -- rewind the record log (forward or backward,
2748 depending on DIR) to the given entry, changing the program state
2752 record_full_goto_insn (struct record_full_entry *entry,
2753 enum exec_direction_kind dir)
2755 struct cleanup *set_cleanups = record_full_gdb_operation_disable_set ();
2756 struct regcache *regcache = get_current_regcache ();
2757 struct gdbarch *gdbarch = get_regcache_arch (regcache);
2759 /* Assume everything is valid: we will hit the entry,
2760 and we will not hit the end of the recording. */
2762 if (dir == EXEC_FORWARD)
2763 record_full_list = record_full_list->next;
2767 record_full_exec_insn (regcache, gdbarch, record_full_list);
2768 if (dir == EXEC_REVERSE)
2769 record_full_list = record_full_list->prev;
2771 record_full_list = record_full_list->next;
2772 } while (record_full_list != entry);
2773 do_cleanups (set_cleanups);
2776 /* Alias for "target record-full". */
2779 cmd_record_full_start (char *args, int from_tty)
2781 execute_command ("target record-full", from_tty);
2785 set_record_full_insn_max_num (char *args, int from_tty,
2786 struct cmd_list_element *c)
2788 if (record_full_insn_num > record_full_insn_max_num)
2790 /* Count down record_full_insn_num while releasing records from list. */
2791 while (record_full_insn_num > record_full_insn_max_num)
2793 record_full_list_release_first ();
2794 record_full_insn_num--;
2799 /* The "set record full" command. */
2802 set_record_full_command (char *args, int from_tty)
2804 printf_unfiltered (_("\"set record full\" must be followed "
2805 "by an apporpriate subcommand.\n"));
2806 help_list (set_record_full_cmdlist, "set record full ", all_commands,
2810 /* The "show record full" command. */
2813 show_record_full_command (char *args, int from_tty)
2815 cmd_show_list (show_record_full_cmdlist, from_tty, "");
2818 /* Provide a prototype to silence -Wmissing-prototypes. */
2819 extern initialize_file_ftype _initialize_record_full;
2822 _initialize_record_full (void)
2824 struct cmd_list_element *c;
2826 /* Init record_full_first. */
2827 record_full_first.prev = NULL;
2828 record_full_first.next = NULL;
2829 record_full_first.type = record_full_end;
2831 init_record_full_ops ();
2832 add_target (&record_full_ops);
2833 add_deprecated_target_alias (&record_full_ops, "record");
2834 init_record_full_core_ops ();
2835 add_target (&record_full_core_ops);
2837 add_prefix_cmd ("full", class_obscure, cmd_record_full_start,
2838 _("Start full execution recording."), &record_full_cmdlist,
2839 "record full ", 0, &record_cmdlist);
2841 c = add_cmd ("restore", class_obscure, cmd_record_full_restore,
2842 _("Restore the execution log from a file.\n\
2843 Argument is filename. File must be created with 'record save'."),
2844 &record_full_cmdlist);
2845 set_cmd_completer (c, filename_completer);
2847 /* Deprecate the old version without "full" prefix. */
2848 c = add_alias_cmd ("restore", "full restore", class_obscure, 1,
2850 set_cmd_completer (c, filename_completer);
2851 deprecate_cmd (c, "record full restore");
2853 add_prefix_cmd ("full", class_support, set_record_full_command,
2854 _("Set record options"), &set_record_full_cmdlist,
2855 "set record full ", 0, &set_record_cmdlist);
2857 add_prefix_cmd ("full", class_support, show_record_full_command,
2858 _("Show record options"), &show_record_full_cmdlist,
2859 "show record full ", 0, &show_record_cmdlist);
2861 /* Record instructions number limit command. */
2862 add_setshow_boolean_cmd ("stop-at-limit", no_class,
2863 &record_full_stop_at_limit, _("\
2864 Set whether record/replay stops when record/replay buffer becomes full."), _("\
2865 Show whether record/replay stops when record/replay buffer becomes full."),
2866 _("Default is ON.\n\
2867 When ON, if the record/replay buffer becomes full, ask user what to do.\n\
2868 When OFF, if the record/replay buffer becomes full,\n\
2869 delete the oldest recorded instruction to make room for each new one."),
2871 &set_record_full_cmdlist, &show_record_full_cmdlist);
2873 c = add_alias_cmd ("stop-at-limit", "full stop-at-limit", no_class, 1,
2874 &set_record_cmdlist);
2875 deprecate_cmd (c, "set record full stop-at-limit");
2877 c = add_alias_cmd ("stop-at-limit", "full stop-at-limit", no_class, 1,
2878 &show_record_cmdlist);
2879 deprecate_cmd (c, "show record full stop-at-limit");
2881 add_setshow_uinteger_cmd ("insn-number-max", no_class,
2882 &record_full_insn_max_num,
2883 _("Set record/replay buffer limit."),
2884 _("Show record/replay buffer limit."), _("\
2885 Set the maximum number of instructions to be stored in the\n\
2886 record/replay buffer. A value of either \"unlimited\" or zero means no\n\
2887 limit. Default is 200000."),
2888 set_record_full_insn_max_num,
2889 NULL, &set_record_full_cmdlist,
2890 &show_record_full_cmdlist);
2892 c = add_alias_cmd ("insn-number-max", "full insn-number-max", no_class, 1,
2893 &set_record_cmdlist);
2894 deprecate_cmd (c, "set record full insn-number-max");
2896 c = add_alias_cmd ("insn-number-max", "full insn-number-max", no_class, 1,
2897 &show_record_cmdlist);
2898 deprecate_cmd (c, "show record full insn-number-max");
2900 add_setshow_boolean_cmd ("memory-query", no_class,
2901 &record_full_memory_query, _("\
2902 Set whether query if PREC cannot record memory change of next instruction."),
2904 Show whether query if PREC cannot record memory change of next instruction."),
2907 When ON, query if PREC cannot record memory change of next instruction."),
2909 &set_record_full_cmdlist,
2910 &show_record_full_cmdlist);
2912 c = add_alias_cmd ("memory-query", "full memory-query", no_class, 1,
2913 &set_record_cmdlist);
2914 deprecate_cmd (c, "set record full memory-query");
2916 c = add_alias_cmd ("memory-query", "full memory-query", no_class, 1,
2917 &show_record_cmdlist);
2918 deprecate_cmd (c, "show record full memory-query");