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"
39 #include "common/byte-vector.h"
43 /* This module implements "target record-full", also known as "process
44 record and replay". This target sits on top of a "normal" target
45 (a target that "has execution"), and provides a record and replay
46 functionality, including reverse debugging.
48 Target record has two modes: recording, and replaying.
50 In record mode, we intercept the to_resume and to_wait methods.
51 Whenever gdb resumes the target, we run the target in single step
52 mode, and we build up an execution log in which, for each executed
53 instruction, we record all changes in memory and register state.
54 This is invisible to the user, to whom it just looks like an
55 ordinary debugging session (except for performance degredation).
57 In replay mode, instead of actually letting the inferior run as a
58 process, we simulate its execution by playing back the recorded
59 execution log. For each instruction in the log, we simulate the
60 instruction's side effects by duplicating the changes that it would
61 have made on memory and registers. */
63 #define DEFAULT_RECORD_FULL_INSN_MAX_NUM 200000
65 #define RECORD_FULL_IS_REPLAY \
66 (record_full_list->next || execution_direction == EXEC_REVERSE)
68 #define RECORD_FULL_FILE_MAGIC netorder32(0x20091016)
70 /* These are the core structs of the process record functionality.
72 A record_full_entry is a record of the value change of a register
73 ("record_full_reg") or a part of memory ("record_full_mem"). And each
74 instruction must have a struct record_full_entry ("record_full_end")
75 that indicates that this is the last struct record_full_entry of this
78 Each struct record_full_entry is linked to "record_full_list" by "prev"
79 and "next" pointers. */
81 struct record_full_mem_entry
85 /* Set this flag if target memory for this entry
86 can no longer be accessed. */
87 int mem_entry_not_accessible;
91 gdb_byte buf[sizeof (gdb_byte *)];
95 struct record_full_reg_entry
102 gdb_byte buf[2 * sizeof (gdb_byte *)];
106 struct record_full_end_entry
108 enum gdb_signal sigval;
112 enum record_full_type
119 /* This is the data structure that makes up the execution log.
121 The execution log consists of a single linked list of entries
122 of type "struct record_full_entry". It is doubly linked so that it
123 can be traversed in either direction.
125 The start of the list is anchored by a struct called
126 "record_full_first". The pointer "record_full_list" either points
127 to the last entry that was added to the list (in record mode), or to
128 the next entry in the list that will be executed (in replay mode).
130 Each list element (struct record_full_entry), in addition to next
131 and prev pointers, consists of a union of three entry types: mem,
132 reg, and end. A field called "type" determines which entry type is
133 represented by a given list element.
135 Each instruction that is added to the execution log is represented
136 by a variable number of list elements ('entries'). The instruction
137 will have one "reg" entry for each register that is changed by
138 executing the instruction (including the PC in every case). It
139 will also have one "mem" entry for each memory change. Finally,
140 each instruction will have an "end" entry that separates it from
141 the changes associated with the next instruction. */
143 struct record_full_entry
145 struct record_full_entry *prev;
146 struct record_full_entry *next;
147 enum record_full_type type;
151 struct record_full_reg_entry reg;
153 struct record_full_mem_entry mem;
155 struct record_full_end_entry end;
159 /* If true, query if PREC cannot record memory
160 change of next instruction. */
161 int record_full_memory_query = 0;
163 struct record_full_core_buf_entry
165 struct record_full_core_buf_entry *prev;
166 struct target_section *p;
170 /* Record buf with core target. */
171 static gdb_byte *record_full_core_regbuf = NULL;
172 static struct target_section *record_full_core_start;
173 static struct target_section *record_full_core_end;
174 static struct record_full_core_buf_entry *record_full_core_buf_list = NULL;
176 /* The following variables are used for managing the linked list that
177 represents the execution log.
179 record_full_first is the anchor that holds down the beginning of
182 record_full_list serves two functions:
183 1) In record mode, it anchors the end of the list.
184 2) In replay mode, it traverses the list and points to
185 the next instruction that must be emulated.
187 record_full_arch_list_head and record_full_arch_list_tail are used
188 to manage a separate list, which is used to build up the change
189 elements of the currently executing instruction during record mode.
190 When this instruction has been completely annotated in the "arch
191 list", it will be appended to the main execution log. */
193 static struct record_full_entry record_full_first;
194 static struct record_full_entry *record_full_list = &record_full_first;
195 static struct record_full_entry *record_full_arch_list_head = NULL;
196 static struct record_full_entry *record_full_arch_list_tail = NULL;
198 /* 1 ask user. 0 auto delete the last struct record_full_entry. */
199 static int record_full_stop_at_limit = 1;
200 /* Maximum allowed number of insns in execution log. */
201 static unsigned int record_full_insn_max_num
202 = DEFAULT_RECORD_FULL_INSN_MAX_NUM;
203 /* Actual count of insns presently in execution log. */
204 static unsigned int record_full_insn_num = 0;
205 /* Count of insns logged so far (may be larger
206 than count of insns presently in execution log). */
207 static ULONGEST record_full_insn_count;
209 /* The target_ops of process record. */
210 static struct target_ops record_full_ops;
211 static struct target_ops record_full_core_ops;
213 /* See record-full.h. */
216 record_full_is_used (void)
218 struct target_ops *t;
220 t = find_record_target ();
221 return (t == &record_full_ops
222 || t == &record_full_core_ops);
226 /* Command lists for "set/show record full". */
227 static struct cmd_list_element *set_record_full_cmdlist;
228 static struct cmd_list_element *show_record_full_cmdlist;
230 /* Command list for "record full". */
231 static struct cmd_list_element *record_full_cmdlist;
233 static void record_full_goto_insn (struct record_full_entry *entry,
234 enum exec_direction_kind dir);
235 static void record_full_save (struct target_ops *self,
236 const char *recfilename);
238 /* Alloc and free functions for record_full_reg, record_full_mem, and
239 record_full_end entries. */
241 /* Alloc a record_full_reg record entry. */
243 static inline struct record_full_entry *
244 record_full_reg_alloc (struct regcache *regcache, int regnum)
246 struct record_full_entry *rec;
247 struct gdbarch *gdbarch = regcache->arch ();
249 rec = XCNEW (struct record_full_entry);
250 rec->type = record_full_reg;
251 rec->u.reg.num = regnum;
252 rec->u.reg.len = register_size (gdbarch, regnum);
253 if (rec->u.reg.len > sizeof (rec->u.reg.u.buf))
254 rec->u.reg.u.ptr = (gdb_byte *) xmalloc (rec->u.reg.len);
259 /* Free a record_full_reg record entry. */
262 record_full_reg_release (struct record_full_entry *rec)
264 gdb_assert (rec->type == record_full_reg);
265 if (rec->u.reg.len > sizeof (rec->u.reg.u.buf))
266 xfree (rec->u.reg.u.ptr);
270 /* Alloc a record_full_mem record entry. */
272 static inline struct record_full_entry *
273 record_full_mem_alloc (CORE_ADDR addr, int len)
275 struct record_full_entry *rec;
277 rec = XCNEW (struct record_full_entry);
278 rec->type = record_full_mem;
279 rec->u.mem.addr = addr;
280 rec->u.mem.len = len;
281 if (rec->u.mem.len > sizeof (rec->u.mem.u.buf))
282 rec->u.mem.u.ptr = (gdb_byte *) xmalloc (len);
287 /* Free a record_full_mem record entry. */
290 record_full_mem_release (struct record_full_entry *rec)
292 gdb_assert (rec->type == record_full_mem);
293 if (rec->u.mem.len > sizeof (rec->u.mem.u.buf))
294 xfree (rec->u.mem.u.ptr);
298 /* Alloc a record_full_end record entry. */
300 static inline struct record_full_entry *
301 record_full_end_alloc (void)
303 struct record_full_entry *rec;
305 rec = XCNEW (struct record_full_entry);
306 rec->type = record_full_end;
311 /* Free a record_full_end record entry. */
314 record_full_end_release (struct record_full_entry *rec)
319 /* Free one record entry, any type.
320 Return entry->type, in case caller wants to know. */
322 static inline enum record_full_type
323 record_full_entry_release (struct record_full_entry *rec)
325 enum record_full_type type = rec->type;
328 case record_full_reg:
329 record_full_reg_release (rec);
331 case record_full_mem:
332 record_full_mem_release (rec);
334 case record_full_end:
335 record_full_end_release (rec);
341 /* Free all record entries in list pointed to by REC. */
344 record_full_list_release (struct record_full_entry *rec)
355 record_full_entry_release (rec->next);
358 if (rec == &record_full_first)
360 record_full_insn_num = 0;
361 record_full_first.next = NULL;
364 record_full_entry_release (rec);
367 /* Free all record entries forward of the given list position. */
370 record_full_list_release_following (struct record_full_entry *rec)
372 struct record_full_entry *tmp = rec->next;
378 if (record_full_entry_release (tmp) == record_full_end)
380 record_full_insn_num--;
381 record_full_insn_count--;
387 /* Delete the first instruction from the beginning of the log, to make
388 room for adding a new instruction at the end of the log.
390 Note -- this function does not modify record_full_insn_num. */
393 record_full_list_release_first (void)
395 struct record_full_entry *tmp;
397 if (!record_full_first.next)
400 /* Loop until a record_full_end. */
403 /* Cut record_full_first.next out of the linked list. */
404 tmp = record_full_first.next;
405 record_full_first.next = tmp->next;
406 tmp->next->prev = &record_full_first;
408 /* tmp is now isolated, and can be deleted. */
409 if (record_full_entry_release (tmp) == record_full_end)
410 break; /* End loop at first record_full_end. */
412 if (!record_full_first.next)
414 gdb_assert (record_full_insn_num == 1);
415 break; /* End loop when list is empty. */
420 /* Add a struct record_full_entry to record_full_arch_list. */
423 record_full_arch_list_add (struct record_full_entry *rec)
425 if (record_debug > 1)
426 fprintf_unfiltered (gdb_stdlog,
427 "Process record: record_full_arch_list_add %s.\n",
428 host_address_to_string (rec));
430 if (record_full_arch_list_tail)
432 record_full_arch_list_tail->next = rec;
433 rec->prev = record_full_arch_list_tail;
434 record_full_arch_list_tail = rec;
438 record_full_arch_list_head = rec;
439 record_full_arch_list_tail = rec;
443 /* Return the value storage location of a record entry. */
444 static inline gdb_byte *
445 record_full_get_loc (struct record_full_entry *rec)
448 case record_full_mem:
449 if (rec->u.mem.len > sizeof (rec->u.mem.u.buf))
450 return rec->u.mem.u.ptr;
452 return rec->u.mem.u.buf;
453 case record_full_reg:
454 if (rec->u.reg.len > sizeof (rec->u.reg.u.buf))
455 return rec->u.reg.u.ptr;
457 return rec->u.reg.u.buf;
458 case record_full_end:
460 gdb_assert_not_reached ("unexpected record_full_entry type");
465 /* Record the value of a register NUM to record_full_arch_list. */
468 record_full_arch_list_add_reg (struct regcache *regcache, int regnum)
470 struct record_full_entry *rec;
472 if (record_debug > 1)
473 fprintf_unfiltered (gdb_stdlog,
474 "Process record: add register num = %d to "
478 rec = record_full_reg_alloc (regcache, regnum);
480 regcache_raw_read (regcache, regnum, record_full_get_loc (rec));
482 record_full_arch_list_add (rec);
487 /* Record the value of a region of memory whose address is ADDR and
488 length is LEN to record_full_arch_list. */
491 record_full_arch_list_add_mem (CORE_ADDR addr, int len)
493 struct record_full_entry *rec;
495 if (record_debug > 1)
496 fprintf_unfiltered (gdb_stdlog,
497 "Process record: add mem addr = %s len = %d to "
499 paddress (target_gdbarch (), addr), len);
501 if (!addr) /* FIXME: Why? Some arch must permit it... */
504 rec = record_full_mem_alloc (addr, len);
506 if (record_read_memory (target_gdbarch (), addr,
507 record_full_get_loc (rec), len))
509 record_full_mem_release (rec);
513 record_full_arch_list_add (rec);
518 /* Add a record_full_end type struct record_full_entry to
519 record_full_arch_list. */
522 record_full_arch_list_add_end (void)
524 struct record_full_entry *rec;
526 if (record_debug > 1)
527 fprintf_unfiltered (gdb_stdlog,
528 "Process record: add end to arch list.\n");
530 rec = record_full_end_alloc ();
531 rec->u.end.sigval = GDB_SIGNAL_0;
532 rec->u.end.insn_num = ++record_full_insn_count;
534 record_full_arch_list_add (rec);
540 record_full_check_insn_num (void)
542 if (record_full_insn_num == record_full_insn_max_num)
544 /* Ask user what to do. */
545 if (record_full_stop_at_limit)
547 if (!yquery (_("Do you want to auto delete previous execution "
548 "log entries when record/replay buffer becomes "
549 "full (record full stop-at-limit)?")))
550 error (_("Process record: stopped by user."));
551 record_full_stop_at_limit = 0;
557 record_full_arch_list_cleanups (void *ignore)
559 record_full_list_release (record_full_arch_list_tail);
562 /* Before inferior step (when GDB record the running message, inferior
563 only can step), GDB will call this function to record the values to
564 record_full_list. This function will call gdbarch_process_record to
565 record the running message of inferior and set them to
566 record_full_arch_list, and add it to record_full_list. */
569 record_full_message (struct regcache *regcache, enum gdb_signal signal)
572 struct gdbarch *gdbarch = regcache->arch ();
573 struct cleanup *old_cleanups
574 = make_cleanup (record_full_arch_list_cleanups, 0);
576 record_full_arch_list_head = NULL;
577 record_full_arch_list_tail = NULL;
579 /* Check record_full_insn_num. */
580 record_full_check_insn_num ();
582 /* If gdb sends a signal value to target_resume,
583 save it in the 'end' field of the previous instruction.
585 Maybe process record should record what really happened,
586 rather than what gdb pretends has happened.
588 So if Linux delivered the signal to the child process during
589 the record mode, we will record it and deliver it again in
592 If user says "ignore this signal" during the record mode, then
593 it will be ignored again during the replay mode (no matter if
594 the user says something different, like "deliver this signal"
595 during the replay mode).
597 User should understand that nothing he does during the replay
598 mode will change the behavior of the child. If he tries,
599 then that is a user error.
601 But we should still deliver the signal to gdb during the replay,
602 if we delivered it during the recording. Therefore we should
603 record the signal during record_full_wait, not
604 record_full_resume. */
605 if (record_full_list != &record_full_first) /* FIXME better way to check */
607 gdb_assert (record_full_list->type == record_full_end);
608 record_full_list->u.end.sigval = signal;
611 if (signal == GDB_SIGNAL_0
612 || !gdbarch_process_record_signal_p (gdbarch))
613 ret = gdbarch_process_record (gdbarch,
615 regcache_read_pc (regcache));
617 ret = gdbarch_process_record_signal (gdbarch,
622 error (_("Process record: inferior program stopped."));
624 error (_("Process record: failed to record execution log."));
626 discard_cleanups (old_cleanups);
628 record_full_list->next = record_full_arch_list_head;
629 record_full_arch_list_head->prev = record_full_list;
630 record_full_list = record_full_arch_list_tail;
632 if (record_full_insn_num == record_full_insn_max_num)
633 record_full_list_release_first ();
635 record_full_insn_num++;
639 record_full_message_wrapper_safe (struct regcache *regcache,
640 enum gdb_signal signal)
644 record_full_message (regcache, signal);
646 CATCH (ex, RETURN_MASK_ALL)
648 exception_print (gdb_stderr, ex);
656 /* Set to 1 if record_full_store_registers and record_full_xfer_partial
657 doesn't need record. */
659 static int record_full_gdb_operation_disable = 0;
661 scoped_restore_tmpl<int>
662 record_full_gdb_operation_disable_set (void)
664 return make_scoped_restore (&record_full_gdb_operation_disable, 1);
667 /* Flag set to TRUE for target_stopped_by_watchpoint. */
668 static enum target_stop_reason record_full_stop_reason
669 = TARGET_STOPPED_BY_NO_REASON;
671 /* Execute one instruction from the record log. Each instruction in
672 the log will be represented by an arbitrary sequence of register
673 entries and memory entries, followed by an 'end' entry. */
676 record_full_exec_insn (struct regcache *regcache,
677 struct gdbarch *gdbarch,
678 struct record_full_entry *entry)
682 case record_full_reg: /* reg */
684 gdb::byte_vector reg (entry->u.reg.len);
686 if (record_debug > 1)
687 fprintf_unfiltered (gdb_stdlog,
688 "Process record: record_full_reg %s to "
689 "inferior num = %d.\n",
690 host_address_to_string (entry),
693 regcache_cooked_read (regcache, entry->u.reg.num, reg.data ());
694 regcache_cooked_write (regcache, entry->u.reg.num,
695 record_full_get_loc (entry));
696 memcpy (record_full_get_loc (entry), reg.data (), entry->u.reg.len);
700 case record_full_mem: /* mem */
702 /* Nothing to do if the entry is flagged not_accessible. */
703 if (!entry->u.mem.mem_entry_not_accessible)
705 gdb_byte *mem = (gdb_byte *) xmalloc (entry->u.mem.len);
706 struct cleanup *cleanup = make_cleanup (xfree, mem);
708 if (record_debug > 1)
709 fprintf_unfiltered (gdb_stdlog,
710 "Process record: record_full_mem %s to "
711 "inferior addr = %s len = %d.\n",
712 host_address_to_string (entry),
713 paddress (gdbarch, entry->u.mem.addr),
716 if (record_read_memory (gdbarch,
717 entry->u.mem.addr, mem, entry->u.mem.len))
718 entry->u.mem.mem_entry_not_accessible = 1;
721 if (target_write_memory (entry->u.mem.addr,
722 record_full_get_loc (entry),
725 entry->u.mem.mem_entry_not_accessible = 1;
727 warning (_("Process record: error writing memory at "
728 "addr = %s len = %d."),
729 paddress (gdbarch, entry->u.mem.addr),
734 memcpy (record_full_get_loc (entry), mem,
737 /* We've changed memory --- check if a hardware
738 watchpoint should trap. Note that this
739 presently assumes the target beneath supports
740 continuable watchpoints. On non-continuable
741 watchpoints target, we'll want to check this
742 _before_ actually doing the memory change, and
743 not doing the change at all if the watchpoint
745 if (hardware_watchpoint_inserted_in_range
746 (regcache->aspace (),
747 entry->u.mem.addr, entry->u.mem.len))
748 record_full_stop_reason = TARGET_STOPPED_BY_WATCHPOINT;
752 do_cleanups (cleanup);
759 static void record_full_restore (void);
761 /* Asynchronous signal handle registered as event loop source for when
762 we have pending events ready to be passed to the core. */
764 static struct async_event_handler *record_full_async_inferior_event_token;
767 record_full_async_inferior_event_handler (gdb_client_data data)
769 inferior_event_handler (INF_REG_EVENT, NULL);
772 /* Open the process record target. */
775 record_full_core_open_1 (const char *name, int from_tty)
777 struct regcache *regcache = get_current_regcache ();
778 int regnum = gdbarch_num_regs (regcache->arch ());
781 /* Get record_full_core_regbuf. */
782 target_fetch_registers (regcache, -1);
783 record_full_core_regbuf = (gdb_byte *) xmalloc (MAX_REGISTER_SIZE * regnum);
784 for (i = 0; i < regnum; i ++)
785 regcache_raw_collect (regcache, i,
786 record_full_core_regbuf + MAX_REGISTER_SIZE * i);
788 /* Get record_full_core_start and record_full_core_end. */
789 if (build_section_table (core_bfd, &record_full_core_start,
790 &record_full_core_end))
792 xfree (record_full_core_regbuf);
793 record_full_core_regbuf = NULL;
794 error (_("\"%s\": Can't find sections: %s"),
795 bfd_get_filename (core_bfd), bfd_errmsg (bfd_get_error ()));
798 push_target (&record_full_core_ops);
799 record_full_restore ();
802 /* "to_open" target method for 'live' processes. */
805 record_full_open_1 (const char *name, int from_tty)
808 fprintf_unfiltered (gdb_stdlog, "Process record: record_full_open_1\n");
811 if (!target_has_execution)
812 error (_("Process record: the program is not being run."));
814 error (_("Process record target can't debug inferior in non-stop mode "
817 if (!gdbarch_process_record_p (target_gdbarch ()))
818 error (_("Process record: the current architecture doesn't support "
819 "record function."));
821 push_target (&record_full_ops);
824 static void record_full_init_record_breakpoints (void);
826 /* "to_open" target method. Open the process record target. */
829 record_full_open (const char *name, int from_tty)
832 fprintf_unfiltered (gdb_stdlog, "Process record: record_full_open\n");
837 record_full_insn_num = 0;
838 record_full_insn_count = 0;
839 record_full_list = &record_full_first;
840 record_full_list->next = NULL;
843 record_full_core_open_1 (name, from_tty);
845 record_full_open_1 (name, from_tty);
847 /* Register extra event sources in the event loop. */
848 record_full_async_inferior_event_token
849 = create_async_event_handler (record_full_async_inferior_event_handler,
852 record_full_init_record_breakpoints ();
854 observer_notify_record_changed (current_inferior (), 1, "full", NULL);
857 /* "to_close" target method. Close the process record target. */
860 record_full_close (struct target_ops *self)
862 struct record_full_core_buf_entry *entry;
865 fprintf_unfiltered (gdb_stdlog, "Process record: record_full_close\n");
867 record_full_list_release (record_full_list);
869 /* Release record_full_core_regbuf. */
870 if (record_full_core_regbuf)
872 xfree (record_full_core_regbuf);
873 record_full_core_regbuf = NULL;
876 /* Release record_full_core_buf_list. */
877 if (record_full_core_buf_list)
879 for (entry = record_full_core_buf_list->prev; entry;
882 xfree (record_full_core_buf_list);
883 record_full_core_buf_list = entry;
885 record_full_core_buf_list = NULL;
888 if (record_full_async_inferior_event_token)
889 delete_async_event_handler (&record_full_async_inferior_event_token);
892 /* "to_async" target method. */
895 record_full_async (struct target_ops *ops, int enable)
898 mark_async_event_handler (record_full_async_inferior_event_token);
900 clear_async_event_handler (record_full_async_inferior_event_token);
902 ops->beneath->to_async (ops->beneath, enable);
905 static int record_full_resume_step = 0;
907 /* True if we've been resumed, and so each record_full_wait call should
908 advance execution. If this is false, record_full_wait will return a
909 TARGET_WAITKIND_IGNORE. */
910 static int record_full_resumed = 0;
912 /* The execution direction of the last resume we got. This is
913 necessary for async mode. Vis (order is not strictly accurate):
915 1. user has the global execution direction set to forward
916 2. user does a reverse-step command
917 3. record_full_resume is called with global execution direction
918 temporarily switched to reverse
919 4. GDB's execution direction is reverted back to forward
920 5. target record notifies event loop there's an event to handle
921 6. infrun asks the target which direction was it going, and switches
922 the global execution direction accordingly (to reverse)
923 7. infrun polls an event out of the record target, and handles it
924 8. GDB goes back to the event loop, and goto #4.
926 static enum exec_direction_kind record_full_execution_dir = EXEC_FORWARD;
928 /* "to_resume" target method. Resume the process record target. */
931 record_full_resume (struct target_ops *ops, ptid_t ptid, int step,
932 enum gdb_signal signal)
934 record_full_resume_step = step;
935 record_full_resumed = 1;
936 record_full_execution_dir = execution_direction;
938 if (!RECORD_FULL_IS_REPLAY)
940 struct gdbarch *gdbarch = target_thread_architecture (ptid);
942 record_full_message (get_current_regcache (), signal);
946 /* This is not hard single step. */
947 if (!gdbarch_software_single_step_p (gdbarch))
949 /* This is a normal continue. */
954 /* This arch supports soft single step. */
955 if (thread_has_single_step_breakpoints_set (inferior_thread ()))
957 /* This is a soft single step. */
958 record_full_resume_step = 1;
961 step = !insert_single_step_breakpoints (gdbarch);
965 /* Make sure the target beneath reports all signals. */
966 target_pass_signals (0, NULL);
968 ops->beneath->to_resume (ops->beneath, ptid, step, signal);
971 /* We are about to start executing the inferior (or simulate it),
972 let's register it with the event loop. */
973 if (target_can_async_p ())
977 /* "to_commit_resume" method for process record target. */
980 record_full_commit_resume (struct target_ops *ops)
982 if (!RECORD_FULL_IS_REPLAY)
983 ops->beneath->to_commit_resume (ops->beneath);
986 static int record_full_get_sig = 0;
988 /* SIGINT signal handler, registered by "to_wait" method. */
991 record_full_sig_handler (int signo)
994 fprintf_unfiltered (gdb_stdlog, "Process record: get a signal\n");
996 /* It will break the running inferior in replay mode. */
997 record_full_resume_step = 1;
999 /* It will let record_full_wait set inferior status to get the signal
1001 record_full_get_sig = 1;
1005 record_full_wait_cleanups (void *ignore)
1007 if (execution_direction == EXEC_REVERSE)
1009 if (record_full_list->next)
1010 record_full_list = record_full_list->next;
1013 record_full_list = record_full_list->prev;
1016 /* "to_wait" target method for process record target.
1018 In record mode, the target is always run in singlestep mode
1019 (even when gdb says to continue). The to_wait method intercepts
1020 the stop events and determines which ones are to be passed on to
1021 gdb. Most stop events are just singlestep events that gdb is not
1022 to know about, so the to_wait method just records them and keeps
1025 In replay mode, this function emulates the recorded execution log,
1026 one instruction at a time (forward or backward), and determines
1030 record_full_wait_1 (struct target_ops *ops,
1031 ptid_t ptid, struct target_waitstatus *status,
1034 scoped_restore restore_operation_disable
1035 = record_full_gdb_operation_disable_set ();
1038 fprintf_unfiltered (gdb_stdlog,
1039 "Process record: record_full_wait "
1040 "record_full_resume_step = %d, "
1041 "record_full_resumed = %d, direction=%s\n",
1042 record_full_resume_step, record_full_resumed,
1043 record_full_execution_dir == EXEC_FORWARD
1044 ? "forward" : "reverse");
1046 if (!record_full_resumed)
1048 gdb_assert ((options & TARGET_WNOHANG) != 0);
1050 /* No interesting event. */
1051 status->kind = TARGET_WAITKIND_IGNORE;
1052 return minus_one_ptid;
1055 record_full_get_sig = 0;
1056 signal (SIGINT, record_full_sig_handler);
1058 record_full_stop_reason = TARGET_STOPPED_BY_NO_REASON;
1060 if (!RECORD_FULL_IS_REPLAY && ops != &record_full_core_ops)
1062 if (record_full_resume_step)
1064 /* This is a single step. */
1065 return ops->beneath->to_wait (ops->beneath, ptid, status, options);
1069 /* This is not a single step. */
1072 struct gdbarch *gdbarch = target_thread_architecture (inferior_ptid);
1076 struct thread_info *tp;
1078 ret = ops->beneath->to_wait (ops->beneath, ptid, status, options);
1079 if (status->kind == TARGET_WAITKIND_IGNORE)
1082 fprintf_unfiltered (gdb_stdlog,
1083 "Process record: record_full_wait "
1084 "target beneath not done yet\n");
1088 ALL_NON_EXITED_THREADS (tp)
1089 delete_single_step_breakpoints (tp);
1091 if (record_full_resume_step)
1094 /* Is this a SIGTRAP? */
1095 if (status->kind == TARGET_WAITKIND_STOPPED
1096 && status->value.sig == GDB_SIGNAL_TRAP)
1098 struct regcache *regcache;
1099 enum target_stop_reason *stop_reason_p
1100 = &record_full_stop_reason;
1102 /* Yes -- this is likely our single-step finishing,
1103 but check if there's any reason the core would be
1104 interested in the event. */
1106 registers_changed ();
1107 regcache = get_current_regcache ();
1108 tmp_pc = regcache_read_pc (regcache);
1109 const struct address_space *aspace = regcache->aspace ();
1111 if (target_stopped_by_watchpoint ())
1113 /* Always interested in watchpoints. */
1115 else if (record_check_stopped_by_breakpoint (aspace, tmp_pc,
1118 /* There is a breakpoint here. Let the core
1123 /* This is a single-step trap. Record the
1124 insn and issue another step.
1125 FIXME: this part can be a random SIGTRAP too.
1126 But GDB cannot handle it. */
1129 if (!record_full_message_wrapper_safe (regcache,
1132 status->kind = TARGET_WAITKIND_STOPPED;
1133 status->value.sig = GDB_SIGNAL_0;
1137 if (gdbarch_software_single_step_p (gdbarch))
1139 /* Try to insert the software single step breakpoint.
1140 If insert success, set step to 0. */
1141 set_executing (inferior_ptid, 0);
1142 reinit_frame_cache ();
1144 step = !insert_single_step_breakpoints (gdbarch);
1146 set_executing (inferior_ptid, 1);
1150 fprintf_unfiltered (gdb_stdlog,
1151 "Process record: record_full_wait "
1152 "issuing one more step in the "
1153 "target beneath\n");
1154 ops->beneath->to_resume (ops->beneath, ptid, step,
1156 ops->beneath->to_commit_resume (ops->beneath);
1161 /* The inferior is broken by a breakpoint or a signal. */
1170 struct regcache *regcache = get_current_regcache ();
1171 struct gdbarch *gdbarch = regcache->arch ();
1172 const struct address_space *aspace = regcache->aspace ();
1173 int continue_flag = 1;
1174 int first_record_full_end = 1;
1175 struct cleanup *old_cleanups
1176 = make_cleanup (record_full_wait_cleanups, 0);
1179 record_full_stop_reason = TARGET_STOPPED_BY_NO_REASON;
1180 status->kind = TARGET_WAITKIND_STOPPED;
1182 /* Check breakpoint when forward execute. */
1183 if (execution_direction == EXEC_FORWARD)
1185 tmp_pc = regcache_read_pc (regcache);
1186 if (record_check_stopped_by_breakpoint (aspace, tmp_pc,
1187 &record_full_stop_reason))
1190 fprintf_unfiltered (gdb_stdlog,
1191 "Process record: break at %s.\n",
1192 paddress (gdbarch, tmp_pc));
1197 /* If GDB is in terminal_inferior mode, it will not get the signal.
1198 And in GDB replay mode, GDB doesn't need to be in terminal_inferior
1199 mode, because inferior will not executed.
1200 Then set it to terminal_ours to make GDB get the signal. */
1201 target_terminal::ours ();
1203 /* In EXEC_FORWARD mode, record_full_list points to the tail of prev
1205 if (execution_direction == EXEC_FORWARD && record_full_list->next)
1206 record_full_list = record_full_list->next;
1208 /* Loop over the record_full_list, looking for the next place to
1212 /* Check for beginning and end of log. */
1213 if (execution_direction == EXEC_REVERSE
1214 && record_full_list == &record_full_first)
1216 /* Hit beginning of record log in reverse. */
1217 status->kind = TARGET_WAITKIND_NO_HISTORY;
1220 if (execution_direction != EXEC_REVERSE && !record_full_list->next)
1222 /* Hit end of record log going forward. */
1223 status->kind = TARGET_WAITKIND_NO_HISTORY;
1227 record_full_exec_insn (regcache, gdbarch, record_full_list);
1229 if (record_full_list->type == record_full_end)
1231 if (record_debug > 1)
1232 fprintf_unfiltered (gdb_stdlog,
1233 "Process record: record_full_end %s to "
1235 host_address_to_string (record_full_list));
1237 if (first_record_full_end && execution_direction == EXEC_REVERSE)
1239 /* When reverse excute, the first record_full_end is the
1240 part of current instruction. */
1241 first_record_full_end = 0;
1245 /* In EXEC_REVERSE mode, this is the record_full_end of prev
1247 In EXEC_FORWARD mode, this is the record_full_end of
1248 current instruction. */
1250 if (record_full_resume_step)
1252 if (record_debug > 1)
1253 fprintf_unfiltered (gdb_stdlog,
1254 "Process record: step.\n");
1258 /* check breakpoint */
1259 tmp_pc = regcache_read_pc (regcache);
1260 if (record_check_stopped_by_breakpoint (aspace, tmp_pc,
1261 &record_full_stop_reason))
1264 fprintf_unfiltered (gdb_stdlog,
1265 "Process record: break "
1267 paddress (gdbarch, tmp_pc));
1272 if (record_full_stop_reason == TARGET_STOPPED_BY_WATCHPOINT)
1275 fprintf_unfiltered (gdb_stdlog,
1276 "Process record: hit hw "
1280 /* Check target signal */
1281 if (record_full_list->u.end.sigval != GDB_SIGNAL_0)
1282 /* FIXME: better way to check */
1289 if (execution_direction == EXEC_REVERSE)
1291 if (record_full_list->prev)
1292 record_full_list = record_full_list->prev;
1296 if (record_full_list->next)
1297 record_full_list = record_full_list->next;
1301 while (continue_flag);
1304 if (record_full_get_sig)
1305 status->value.sig = GDB_SIGNAL_INT;
1306 else if (record_full_list->u.end.sigval != GDB_SIGNAL_0)
1307 /* FIXME: better way to check */
1308 status->value.sig = record_full_list->u.end.sigval;
1310 status->value.sig = GDB_SIGNAL_TRAP;
1312 discard_cleanups (old_cleanups);
1315 signal (SIGINT, handle_sigint);
1317 return inferior_ptid;
1321 record_full_wait (struct target_ops *ops,
1322 ptid_t ptid, struct target_waitstatus *status,
1327 return_ptid = record_full_wait_1 (ops, ptid, status, options);
1328 if (status->kind != TARGET_WAITKIND_IGNORE)
1330 /* We're reporting a stop. Make sure any spurious
1331 target_wait(WNOHANG) doesn't advance the target until the
1332 core wants us resumed again. */
1333 record_full_resumed = 0;
1339 record_full_stopped_by_watchpoint (struct target_ops *ops)
1341 if (RECORD_FULL_IS_REPLAY)
1342 return record_full_stop_reason == TARGET_STOPPED_BY_WATCHPOINT;
1344 return ops->beneath->to_stopped_by_watchpoint (ops->beneath);
1348 record_full_stopped_data_address (struct target_ops *ops, CORE_ADDR *addr_p)
1350 if (RECORD_FULL_IS_REPLAY)
1353 return ops->beneath->to_stopped_data_address (ops->beneath, addr_p);
1356 /* The to_stopped_by_sw_breakpoint method of target record-full. */
1359 record_full_stopped_by_sw_breakpoint (struct target_ops *ops)
1361 return record_full_stop_reason == TARGET_STOPPED_BY_SW_BREAKPOINT;
1364 /* The to_supports_stopped_by_sw_breakpoint method of target
1368 record_full_supports_stopped_by_sw_breakpoint (struct target_ops *ops)
1373 /* The to_stopped_by_hw_breakpoint method of target record-full. */
1376 record_full_stopped_by_hw_breakpoint (struct target_ops *ops)
1378 return record_full_stop_reason == TARGET_STOPPED_BY_HW_BREAKPOINT;
1381 /* The to_supports_stopped_by_sw_breakpoint method of target
1385 record_full_supports_stopped_by_hw_breakpoint (struct target_ops *ops)
1390 /* Record registers change (by user or by GDB) to list as an instruction. */
1393 record_full_registers_change (struct regcache *regcache, int regnum)
1395 /* Check record_full_insn_num. */
1396 record_full_check_insn_num ();
1398 record_full_arch_list_head = NULL;
1399 record_full_arch_list_tail = NULL;
1405 for (i = 0; i < gdbarch_num_regs (regcache->arch ()); i++)
1407 if (record_full_arch_list_add_reg (regcache, i))
1409 record_full_list_release (record_full_arch_list_tail);
1410 error (_("Process record: failed to record execution log."));
1416 if (record_full_arch_list_add_reg (regcache, regnum))
1418 record_full_list_release (record_full_arch_list_tail);
1419 error (_("Process record: failed to record execution log."));
1422 if (record_full_arch_list_add_end ())
1424 record_full_list_release (record_full_arch_list_tail);
1425 error (_("Process record: failed to record execution log."));
1427 record_full_list->next = record_full_arch_list_head;
1428 record_full_arch_list_head->prev = record_full_list;
1429 record_full_list = record_full_arch_list_tail;
1431 if (record_full_insn_num == record_full_insn_max_num)
1432 record_full_list_release_first ();
1434 record_full_insn_num++;
1437 /* "to_store_registers" method for process record target. */
1440 record_full_store_registers (struct target_ops *ops,
1441 struct regcache *regcache,
1444 if (!record_full_gdb_operation_disable)
1446 if (RECORD_FULL_IS_REPLAY)
1450 /* Let user choose if he wants to write register or not. */
1453 query (_("Because GDB is in replay mode, changing the "
1454 "value of a register will make the execution "
1455 "log unusable from this point onward. "
1456 "Change all registers?"));
1459 query (_("Because GDB is in replay mode, changing the value "
1460 "of a register will make the execution log unusable "
1461 "from this point onward. Change register %s?"),
1462 gdbarch_register_name (regcache->arch (),
1467 /* Invalidate the value of regcache that was set in function
1468 "regcache_raw_write". */
1474 i < gdbarch_num_regs (regcache->arch ());
1476 regcache_invalidate (regcache, i);
1479 regcache_invalidate (regcache, regno);
1481 error (_("Process record canceled the operation."));
1484 /* Destroy the record from here forward. */
1485 record_full_list_release_following (record_full_list);
1488 record_full_registers_change (regcache, regno);
1490 ops->beneath->to_store_registers (ops->beneath, regcache, regno);
1493 /* "to_xfer_partial" method. Behavior is conditional on
1494 RECORD_FULL_IS_REPLAY.
1495 In replay mode, we cannot write memory unles we are willing to
1496 invalidate the record/replay log from this point forward. */
1498 static enum target_xfer_status
1499 record_full_xfer_partial (struct target_ops *ops, enum target_object object,
1500 const char *annex, gdb_byte *readbuf,
1501 const gdb_byte *writebuf, ULONGEST offset,
1502 ULONGEST len, ULONGEST *xfered_len)
1504 if (!record_full_gdb_operation_disable
1505 && (object == TARGET_OBJECT_MEMORY
1506 || object == TARGET_OBJECT_RAW_MEMORY) && writebuf)
1508 if (RECORD_FULL_IS_REPLAY)
1510 /* Let user choose if he wants to write memory or not. */
1511 if (!query (_("Because GDB is in replay mode, writing to memory "
1512 "will make the execution log unusable from this "
1513 "point onward. Write memory at address %s?"),
1514 paddress (target_gdbarch (), offset)))
1515 error (_("Process record canceled the operation."));
1517 /* Destroy the record from here forward. */
1518 record_full_list_release_following (record_full_list);
1521 /* Check record_full_insn_num */
1522 record_full_check_insn_num ();
1524 /* Record registers change to list as an instruction. */
1525 record_full_arch_list_head = NULL;
1526 record_full_arch_list_tail = NULL;
1527 if (record_full_arch_list_add_mem (offset, len))
1529 record_full_list_release (record_full_arch_list_tail);
1531 fprintf_unfiltered (gdb_stdlog,
1532 "Process record: failed to record "
1534 return TARGET_XFER_E_IO;
1536 if (record_full_arch_list_add_end ())
1538 record_full_list_release (record_full_arch_list_tail);
1540 fprintf_unfiltered (gdb_stdlog,
1541 "Process record: failed to record "
1543 return TARGET_XFER_E_IO;
1545 record_full_list->next = record_full_arch_list_head;
1546 record_full_arch_list_head->prev = record_full_list;
1547 record_full_list = record_full_arch_list_tail;
1549 if (record_full_insn_num == record_full_insn_max_num)
1550 record_full_list_release_first ();
1552 record_full_insn_num++;
1555 return ops->beneath->to_xfer_partial (ops->beneath, object, annex,
1556 readbuf, writebuf, offset,
1560 /* This structure represents a breakpoint inserted while the record
1561 target is active. We use this to know when to install/remove
1562 breakpoints in/from the target beneath. For example, a breakpoint
1563 may be inserted while recording, but removed when not replaying nor
1564 recording. In that case, the breakpoint had not been inserted on
1565 the target beneath, so we should not try to remove it there. */
1567 struct record_full_breakpoint
1569 /* The address and address space the breakpoint was set at. */
1570 struct address_space *address_space;
1573 /* True when the breakpoint has been also installed in the target
1574 beneath. This will be false for breakpoints set during replay or
1576 int in_target_beneath;
1579 typedef struct record_full_breakpoint *record_full_breakpoint_p;
1580 DEF_VEC_P(record_full_breakpoint_p);
1582 /* The list of breakpoints inserted while the record target is
1584 VEC(record_full_breakpoint_p) *record_full_breakpoints = NULL;
1587 record_full_sync_record_breakpoints (struct bp_location *loc, void *data)
1589 if (loc->loc_type != bp_loc_software_breakpoint)
1594 struct record_full_breakpoint *bp = XNEW (struct record_full_breakpoint);
1596 bp->addr = loc->target_info.placed_address;
1597 bp->address_space = loc->target_info.placed_address_space;
1599 bp->in_target_beneath = 1;
1601 VEC_safe_push (record_full_breakpoint_p, record_full_breakpoints, bp);
1605 /* Sync existing breakpoints to record_full_breakpoints. */
1608 record_full_init_record_breakpoints (void)
1610 VEC_free (record_full_breakpoint_p, record_full_breakpoints);
1612 iterate_over_bp_locations (record_full_sync_record_breakpoints);
1615 /* Behavior is conditional on RECORD_FULL_IS_REPLAY. We will not actually
1616 insert or remove breakpoints in the real target when replaying, nor
1620 record_full_insert_breakpoint (struct target_ops *ops,
1621 struct gdbarch *gdbarch,
1622 struct bp_target_info *bp_tgt)
1624 struct record_full_breakpoint *bp;
1625 int in_target_beneath = 0;
1628 if (!RECORD_FULL_IS_REPLAY)
1630 /* When recording, we currently always single-step, so we don't
1631 really need to install regular breakpoints in the inferior.
1632 However, we do have to insert software single-step
1633 breakpoints, in case the target can't hardware step. To keep
1634 things simple, we always insert. */
1637 scoped_restore restore_operation_disable
1638 = record_full_gdb_operation_disable_set ();
1639 ret = ops->beneath->to_insert_breakpoint (ops->beneath, gdbarch, bp_tgt);
1644 in_target_beneath = 1;
1647 /* Use the existing entries if found in order to avoid duplication
1648 in record_full_breakpoints. */
1651 VEC_iterate (record_full_breakpoint_p,
1652 record_full_breakpoints, ix, bp);
1655 if (bp->addr == bp_tgt->placed_address
1656 && bp->address_space == bp_tgt->placed_address_space)
1658 gdb_assert (bp->in_target_beneath == in_target_beneath);
1663 bp = XNEW (struct record_full_breakpoint);
1664 bp->addr = bp_tgt->placed_address;
1665 bp->address_space = bp_tgt->placed_address_space;
1666 bp->in_target_beneath = in_target_beneath;
1667 VEC_safe_push (record_full_breakpoint_p, record_full_breakpoints, bp);
1671 /* "to_remove_breakpoint" method for process record target. */
1674 record_full_remove_breakpoint (struct target_ops *ops,
1675 struct gdbarch *gdbarch,
1676 struct bp_target_info *bp_tgt,
1677 enum remove_bp_reason reason)
1679 struct record_full_breakpoint *bp;
1683 VEC_iterate (record_full_breakpoint_p,
1684 record_full_breakpoints, ix, bp);
1687 if (bp->addr == bp_tgt->placed_address
1688 && bp->address_space == bp_tgt->placed_address_space)
1690 if (bp->in_target_beneath)
1694 scoped_restore restore_operation_disable
1695 = record_full_gdb_operation_disable_set ();
1696 ret = ops->beneath->to_remove_breakpoint (ops->beneath, gdbarch,
1702 if (reason == REMOVE_BREAKPOINT)
1704 VEC_unordered_remove (record_full_breakpoint_p,
1705 record_full_breakpoints, ix);
1711 gdb_assert_not_reached ("removing unknown breakpoint");
1714 /* "to_can_execute_reverse" method for process record target. */
1717 record_full_can_execute_reverse (struct target_ops *self)
1722 /* "to_get_bookmark" method for process record and prec over core. */
1725 record_full_get_bookmark (struct target_ops *self, const char *args,
1730 /* Return stringified form of instruction count. */
1731 if (record_full_list && record_full_list->type == record_full_end)
1732 ret = xstrdup (pulongest (record_full_list->u.end.insn_num));
1737 fprintf_unfiltered (gdb_stdlog,
1738 "record_full_get_bookmark returns %s\n", ret);
1740 fprintf_unfiltered (gdb_stdlog,
1741 "record_full_get_bookmark returns NULL\n");
1743 return (gdb_byte *) ret;
1746 /* "to_goto_bookmark" method for process record and prec over core. */
1749 record_full_goto_bookmark (struct target_ops *self,
1750 const gdb_byte *raw_bookmark, int from_tty)
1752 const char *bookmark = (const char *) raw_bookmark;
1753 struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
1756 fprintf_unfiltered (gdb_stdlog,
1757 "record_full_goto_bookmark receives %s\n", bookmark);
1759 if (bookmark[0] == '\'' || bookmark[0] == '\"')
1763 if (bookmark[strlen (bookmark) - 1] != bookmark[0])
1764 error (_("Unbalanced quotes: %s"), bookmark);
1767 copy = savestring (bookmark + 1, strlen (bookmark) - 2);
1768 make_cleanup (xfree, copy);
1772 record_goto (bookmark);
1774 do_cleanups (cleanup);
1777 static enum exec_direction_kind
1778 record_full_execution_direction (struct target_ops *self)
1780 return record_full_execution_dir;
1783 /* The to_record_method method of target record-full. */
1786 record_full_record_method (struct target_ops *self, ptid_t ptid)
1788 return RECORD_METHOD_FULL;
1792 record_full_info (struct target_ops *self)
1794 struct record_full_entry *p;
1796 if (RECORD_FULL_IS_REPLAY)
1797 printf_filtered (_("Replay mode:\n"));
1799 printf_filtered (_("Record mode:\n"));
1801 /* Find entry for first actual instruction in the log. */
1802 for (p = record_full_first.next;
1803 p != NULL && p->type != record_full_end;
1807 /* Do we have a log at all? */
1808 if (p != NULL && p->type == record_full_end)
1810 /* Display instruction number for first instruction in the log. */
1811 printf_filtered (_("Lowest recorded instruction number is %s.\n"),
1812 pulongest (p->u.end.insn_num));
1814 /* If in replay mode, display where we are in the log. */
1815 if (RECORD_FULL_IS_REPLAY)
1816 printf_filtered (_("Current instruction number is %s.\n"),
1817 pulongest (record_full_list->u.end.insn_num));
1819 /* Display instruction number for last instruction in the log. */
1820 printf_filtered (_("Highest recorded instruction number is %s.\n"),
1821 pulongest (record_full_insn_count));
1823 /* Display log count. */
1824 printf_filtered (_("Log contains %u instructions.\n"),
1825 record_full_insn_num);
1828 printf_filtered (_("No instructions have been logged.\n"));
1830 /* Display max log size. */
1831 printf_filtered (_("Max logged instructions is %u.\n"),
1832 record_full_insn_max_num);
1835 /* The "to_record_delete" target method. */
1838 record_full_delete (struct target_ops *self)
1840 record_full_list_release_following (record_full_list);
1843 /* The "to_record_is_replaying" target method. */
1846 record_full_is_replaying (struct target_ops *self, ptid_t ptid)
1848 return RECORD_FULL_IS_REPLAY;
1851 /* The "to_record_will_replay" target method. */
1854 record_full_will_replay (struct target_ops *self, ptid_t ptid, int dir)
1856 /* We can currently only record when executing forwards. Should we be able
1857 to record when executing backwards on targets that support reverse
1858 execution, this needs to be changed. */
1860 return RECORD_FULL_IS_REPLAY || dir == EXEC_REVERSE;
1863 /* Go to a specific entry. */
1866 record_full_goto_entry (struct record_full_entry *p)
1869 error (_("Target insn not found."));
1870 else if (p == record_full_list)
1871 error (_("Already at target insn."));
1872 else if (p->u.end.insn_num > record_full_list->u.end.insn_num)
1874 printf_filtered (_("Go forward to insn number %s\n"),
1875 pulongest (p->u.end.insn_num));
1876 record_full_goto_insn (p, EXEC_FORWARD);
1880 printf_filtered (_("Go backward to insn number %s\n"),
1881 pulongest (p->u.end.insn_num));
1882 record_full_goto_insn (p, EXEC_REVERSE);
1885 registers_changed ();
1886 reinit_frame_cache ();
1887 stop_pc = regcache_read_pc (get_current_regcache ());
1888 print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1);
1891 /* The "to_goto_record_begin" target method. */
1894 record_full_goto_begin (struct target_ops *self)
1896 struct record_full_entry *p = NULL;
1898 for (p = &record_full_first; p != NULL; p = p->next)
1899 if (p->type == record_full_end)
1902 record_full_goto_entry (p);
1905 /* The "to_goto_record_end" target method. */
1908 record_full_goto_end (struct target_ops *self)
1910 struct record_full_entry *p = NULL;
1912 for (p = record_full_list; p->next != NULL; p = p->next)
1914 for (; p!= NULL; p = p->prev)
1915 if (p->type == record_full_end)
1918 record_full_goto_entry (p);
1921 /* The "to_goto_record" target method. */
1924 record_full_goto (struct target_ops *self, ULONGEST target_insn)
1926 struct record_full_entry *p = NULL;
1928 for (p = &record_full_first; p != NULL; p = p->next)
1929 if (p->type == record_full_end && p->u.end.insn_num == target_insn)
1932 record_full_goto_entry (p);
1935 /* The "to_record_stop_replaying" target method. */
1938 record_full_stop_replaying (struct target_ops *self)
1940 record_full_goto_end (self);
1944 init_record_full_ops (void)
1946 record_full_ops.to_shortname = "record-full";
1947 record_full_ops.to_longname = "Process record and replay target";
1948 record_full_ops.to_doc =
1949 "Log program while executing and replay execution from log.";
1950 record_full_ops.to_open = record_full_open;
1951 record_full_ops.to_close = record_full_close;
1952 record_full_ops.to_async = record_full_async;
1953 record_full_ops.to_resume = record_full_resume;
1954 record_full_ops.to_commit_resume = record_full_commit_resume;
1955 record_full_ops.to_wait = record_full_wait;
1956 record_full_ops.to_disconnect = record_disconnect;
1957 record_full_ops.to_detach = record_detach;
1958 record_full_ops.to_mourn_inferior = record_mourn_inferior;
1959 record_full_ops.to_kill = record_kill;
1960 record_full_ops.to_store_registers = record_full_store_registers;
1961 record_full_ops.to_xfer_partial = record_full_xfer_partial;
1962 record_full_ops.to_insert_breakpoint = record_full_insert_breakpoint;
1963 record_full_ops.to_remove_breakpoint = record_full_remove_breakpoint;
1964 record_full_ops.to_stopped_by_watchpoint = record_full_stopped_by_watchpoint;
1965 record_full_ops.to_stopped_data_address = record_full_stopped_data_address;
1966 record_full_ops.to_stopped_by_sw_breakpoint
1967 = record_full_stopped_by_sw_breakpoint;
1968 record_full_ops.to_supports_stopped_by_sw_breakpoint
1969 = record_full_supports_stopped_by_sw_breakpoint;
1970 record_full_ops.to_stopped_by_hw_breakpoint
1971 = record_full_stopped_by_hw_breakpoint;
1972 record_full_ops.to_supports_stopped_by_hw_breakpoint
1973 = record_full_supports_stopped_by_hw_breakpoint;
1974 record_full_ops.to_can_execute_reverse = record_full_can_execute_reverse;
1975 record_full_ops.to_stratum = record_stratum;
1976 /* Add bookmark target methods. */
1977 record_full_ops.to_get_bookmark = record_full_get_bookmark;
1978 record_full_ops.to_goto_bookmark = record_full_goto_bookmark;
1979 record_full_ops.to_execution_direction = record_full_execution_direction;
1980 record_full_ops.to_record_method = record_full_record_method;
1981 record_full_ops.to_info_record = record_full_info;
1982 record_full_ops.to_save_record = record_full_save;
1983 record_full_ops.to_delete_record = record_full_delete;
1984 record_full_ops.to_record_is_replaying = record_full_is_replaying;
1985 record_full_ops.to_record_will_replay = record_full_will_replay;
1986 record_full_ops.to_record_stop_replaying = record_full_stop_replaying;
1987 record_full_ops.to_goto_record_begin = record_full_goto_begin;
1988 record_full_ops.to_goto_record_end = record_full_goto_end;
1989 record_full_ops.to_goto_record = record_full_goto;
1990 record_full_ops.to_magic = OPS_MAGIC;
1993 /* "to_resume" method for prec over corefile. */
1996 record_full_core_resume (struct target_ops *ops, ptid_t ptid, int step,
1997 enum gdb_signal signal)
1999 record_full_resume_step = step;
2000 record_full_resumed = 1;
2001 record_full_execution_dir = execution_direction;
2003 /* We are about to start executing the inferior (or simulate it),
2004 let's register it with the event loop. */
2005 if (target_can_async_p ())
2009 /* "to_kill" method for prec over corefile. */
2012 record_full_core_kill (struct target_ops *ops)
2015 fprintf_unfiltered (gdb_stdlog, "Process record: record_full_core_kill\n");
2017 unpush_target (&record_full_core_ops);
2020 /* "to_fetch_registers" method for prec over corefile. */
2023 record_full_core_fetch_registers (struct target_ops *ops,
2024 struct regcache *regcache,
2029 int num = gdbarch_num_regs (regcache->arch ());
2032 for (i = 0; i < num; i ++)
2033 regcache_raw_supply (regcache, i,
2034 record_full_core_regbuf + MAX_REGISTER_SIZE * i);
2037 regcache_raw_supply (regcache, regno,
2038 record_full_core_regbuf + MAX_REGISTER_SIZE * regno);
2041 /* "to_prepare_to_store" method for prec over corefile. */
2044 record_full_core_prepare_to_store (struct target_ops *self,
2045 struct regcache *regcache)
2049 /* "to_store_registers" method for prec over corefile. */
2052 record_full_core_store_registers (struct target_ops *ops,
2053 struct regcache *regcache,
2056 if (record_full_gdb_operation_disable)
2057 regcache_raw_collect (regcache, regno,
2058 record_full_core_regbuf + MAX_REGISTER_SIZE * regno);
2060 error (_("You can't do that without a process to debug."));
2063 /* "to_xfer_partial" method for prec over corefile. */
2065 static enum target_xfer_status
2066 record_full_core_xfer_partial (struct target_ops *ops,
2067 enum target_object object,
2068 const char *annex, gdb_byte *readbuf,
2069 const gdb_byte *writebuf, ULONGEST offset,
2070 ULONGEST len, ULONGEST *xfered_len)
2072 if (object == TARGET_OBJECT_MEMORY)
2074 if (record_full_gdb_operation_disable || !writebuf)
2076 struct target_section *p;
2078 for (p = record_full_core_start; p < record_full_core_end; p++)
2080 if (offset >= p->addr)
2082 struct record_full_core_buf_entry *entry;
2083 ULONGEST sec_offset;
2085 if (offset >= p->endaddr)
2088 if (offset + len > p->endaddr)
2089 len = p->endaddr - offset;
2091 sec_offset = offset - p->addr;
2093 /* Read readbuf or write writebuf p, offset, len. */
2095 if (p->the_bfd_section->flags & SEC_CONSTRUCTOR
2096 || (p->the_bfd_section->flags & SEC_HAS_CONTENTS) == 0)
2099 memset (readbuf, 0, len);
2102 return TARGET_XFER_OK;
2104 /* Get record_full_core_buf_entry. */
2105 for (entry = record_full_core_buf_list; entry;
2106 entry = entry->prev)
2113 /* Add a new entry. */
2114 entry = XNEW (struct record_full_core_buf_entry);
2116 if (!bfd_malloc_and_get_section
2117 (p->the_bfd_section->owner,
2122 return TARGET_XFER_EOF;
2124 entry->prev = record_full_core_buf_list;
2125 record_full_core_buf_list = entry;
2128 memcpy (entry->buf + sec_offset, writebuf,
2134 return ops->beneath->to_xfer_partial (ops->beneath,
2140 memcpy (readbuf, entry->buf + sec_offset,
2145 return TARGET_XFER_OK;
2149 return TARGET_XFER_E_IO;
2152 error (_("You can't do that without a process to debug."));
2155 return ops->beneath->to_xfer_partial (ops->beneath, object, annex,
2156 readbuf, writebuf, offset, len,
2160 /* "to_insert_breakpoint" method for prec over corefile. */
2163 record_full_core_insert_breakpoint (struct target_ops *ops,
2164 struct gdbarch *gdbarch,
2165 struct bp_target_info *bp_tgt)
2170 /* "to_remove_breakpoint" method for prec over corefile. */
2173 record_full_core_remove_breakpoint (struct target_ops *ops,
2174 struct gdbarch *gdbarch,
2175 struct bp_target_info *bp_tgt,
2176 enum remove_bp_reason reason)
2181 /* "to_has_execution" method for prec over corefile. */
2184 record_full_core_has_execution (struct target_ops *ops, ptid_t the_ptid)
2190 init_record_full_core_ops (void)
2192 record_full_core_ops.to_shortname = "record-core";
2193 record_full_core_ops.to_longname = "Process record and replay target";
2194 record_full_core_ops.to_doc =
2195 "Log program while executing and replay execution from log.";
2196 record_full_core_ops.to_open = record_full_open;
2197 record_full_core_ops.to_close = record_full_close;
2198 record_full_core_ops.to_async = record_full_async;
2199 record_full_core_ops.to_resume = record_full_core_resume;
2200 record_full_core_ops.to_wait = record_full_wait;
2201 record_full_core_ops.to_kill = record_full_core_kill;
2202 record_full_core_ops.to_fetch_registers = record_full_core_fetch_registers;
2203 record_full_core_ops.to_prepare_to_store = record_full_core_prepare_to_store;
2204 record_full_core_ops.to_store_registers = record_full_core_store_registers;
2205 record_full_core_ops.to_xfer_partial = record_full_core_xfer_partial;
2206 record_full_core_ops.to_insert_breakpoint
2207 = record_full_core_insert_breakpoint;
2208 record_full_core_ops.to_remove_breakpoint
2209 = record_full_core_remove_breakpoint;
2210 record_full_core_ops.to_stopped_by_watchpoint
2211 = record_full_stopped_by_watchpoint;
2212 record_full_core_ops.to_stopped_data_address
2213 = record_full_stopped_data_address;
2214 record_full_core_ops.to_stopped_by_sw_breakpoint
2215 = record_full_stopped_by_sw_breakpoint;
2216 record_full_core_ops.to_supports_stopped_by_sw_breakpoint
2217 = record_full_supports_stopped_by_sw_breakpoint;
2218 record_full_core_ops.to_stopped_by_hw_breakpoint
2219 = record_full_stopped_by_hw_breakpoint;
2220 record_full_core_ops.to_supports_stopped_by_hw_breakpoint
2221 = record_full_supports_stopped_by_hw_breakpoint;
2222 record_full_core_ops.to_can_execute_reverse
2223 = record_full_can_execute_reverse;
2224 record_full_core_ops.to_has_execution = record_full_core_has_execution;
2225 record_full_core_ops.to_stratum = record_stratum;
2226 /* Add bookmark target methods. */
2227 record_full_core_ops.to_get_bookmark = record_full_get_bookmark;
2228 record_full_core_ops.to_goto_bookmark = record_full_goto_bookmark;
2229 record_full_core_ops.to_execution_direction
2230 = record_full_execution_direction;
2231 record_full_core_ops.to_record_method = record_full_record_method;
2232 record_full_core_ops.to_info_record = record_full_info;
2233 record_full_core_ops.to_delete_record = record_full_delete;
2234 record_full_core_ops.to_record_is_replaying = record_full_is_replaying;
2235 record_full_core_ops.to_record_will_replay = record_full_will_replay;
2236 record_full_core_ops.to_goto_record_begin = record_full_goto_begin;
2237 record_full_core_ops.to_goto_record_end = record_full_goto_end;
2238 record_full_core_ops.to_goto_record = record_full_goto;
2239 record_full_core_ops.to_magic = OPS_MAGIC;
2242 /* Record log save-file format
2243 Version 1 (never released)
2246 4 bytes: magic number htonl(0x20090829).
2247 NOTE: be sure to change whenever this file format changes!
2251 1 byte: record type (record_full_end, see enum record_full_type).
2253 1 byte: record type (record_full_reg, see enum record_full_type).
2254 8 bytes: register id (network byte order).
2255 MAX_REGISTER_SIZE bytes: register value.
2257 1 byte: record type (record_full_mem, see enum record_full_type).
2258 8 bytes: memory length (network byte order).
2259 8 bytes: memory address (network byte order).
2260 n bytes: memory value (n == memory length).
2263 4 bytes: magic number netorder32(0x20091016).
2264 NOTE: be sure to change whenever this file format changes!
2268 1 byte: record type (record_full_end, see enum record_full_type).
2270 4 bytes: instruction count
2272 1 byte: record type (record_full_reg, see enum record_full_type).
2273 4 bytes: register id (network byte order).
2274 n bytes: register value (n == actual register size).
2275 (eg. 4 bytes for x86 general registers).
2277 1 byte: record type (record_full_mem, see enum record_full_type).
2278 4 bytes: memory length (network byte order).
2279 8 bytes: memory address (network byte order).
2280 n bytes: memory value (n == memory length).
2284 /* bfdcore_read -- read bytes from a core file section. */
2287 bfdcore_read (bfd *obfd, asection *osec, void *buf, int len, int *offset)
2289 int ret = bfd_get_section_contents (obfd, osec, buf, *offset, len);
2294 error (_("Failed to read %d bytes from core file %s ('%s')."),
2295 len, bfd_get_filename (obfd),
2296 bfd_errmsg (bfd_get_error ()));
2299 static inline uint64_t
2300 netorder64 (uint64_t input)
2304 store_unsigned_integer ((gdb_byte *) &ret, sizeof (ret),
2305 BFD_ENDIAN_BIG, input);
2309 static inline uint32_t
2310 netorder32 (uint32_t input)
2314 store_unsigned_integer ((gdb_byte *) &ret, sizeof (ret),
2315 BFD_ENDIAN_BIG, input);
2319 /* Restore the execution log from a core_bfd file. */
2321 record_full_restore (void)
2324 struct cleanup *old_cleanups;
2325 struct record_full_entry *rec;
2329 struct regcache *regcache;
2331 /* We restore the execution log from the open core bfd,
2333 if (core_bfd == NULL)
2336 /* "record_full_restore" can only be called when record list is empty. */
2337 gdb_assert (record_full_first.next == NULL);
2340 fprintf_unfiltered (gdb_stdlog, "Restoring recording from core file.\n");
2342 /* Now need to find our special note section. */
2343 osec = bfd_get_section_by_name (core_bfd, "null0");
2345 fprintf_unfiltered (gdb_stdlog, "Find precord section %s.\n",
2346 osec ? "succeeded" : "failed");
2349 osec_size = bfd_section_size (core_bfd, osec);
2351 fprintf_unfiltered (gdb_stdlog, "%s", bfd_section_name (core_bfd, osec));
2353 /* Check the magic code. */
2354 bfdcore_read (core_bfd, osec, &magic, sizeof (magic), &bfd_offset);
2355 if (magic != RECORD_FULL_FILE_MAGIC)
2356 error (_("Version mis-match or file format error in core file %s."),
2357 bfd_get_filename (core_bfd));
2359 fprintf_unfiltered (gdb_stdlog,
2360 " Reading 4-byte magic cookie "
2361 "RECORD_FULL_FILE_MAGIC (0x%s)\n",
2362 phex_nz (netorder32 (magic), 4));
2364 /* Restore the entries in recfd into record_full_arch_list_head and
2365 record_full_arch_list_tail. */
2366 record_full_arch_list_head = NULL;
2367 record_full_arch_list_tail = NULL;
2368 record_full_insn_num = 0;
2369 old_cleanups = make_cleanup (record_full_arch_list_cleanups, 0);
2370 regcache = get_current_regcache ();
2375 uint32_t regnum, len, signal, count;
2378 /* We are finished when offset reaches osec_size. */
2379 if (bfd_offset >= osec_size)
2381 bfdcore_read (core_bfd, osec, &rectype, sizeof (rectype), &bfd_offset);
2385 case record_full_reg: /* reg */
2386 /* Get register number to regnum. */
2387 bfdcore_read (core_bfd, osec, ®num,
2388 sizeof (regnum), &bfd_offset);
2389 regnum = netorder32 (regnum);
2391 rec = record_full_reg_alloc (regcache, regnum);
2394 bfdcore_read (core_bfd, osec, record_full_get_loc (rec),
2395 rec->u.reg.len, &bfd_offset);
2398 fprintf_unfiltered (gdb_stdlog,
2399 " Reading register %d (1 "
2400 "plus %lu plus %d bytes)\n",
2402 (unsigned long) sizeof (regnum),
2406 case record_full_mem: /* mem */
2408 bfdcore_read (core_bfd, osec, &len,
2409 sizeof (len), &bfd_offset);
2410 len = netorder32 (len);
2413 bfdcore_read (core_bfd, osec, &addr,
2414 sizeof (addr), &bfd_offset);
2415 addr = netorder64 (addr);
2417 rec = record_full_mem_alloc (addr, len);
2420 bfdcore_read (core_bfd, osec, record_full_get_loc (rec),
2421 rec->u.mem.len, &bfd_offset);
2424 fprintf_unfiltered (gdb_stdlog,
2425 " Reading memory %s (1 plus "
2426 "%lu plus %lu plus %d bytes)\n",
2427 paddress (get_current_arch (),
2429 (unsigned long) sizeof (addr),
2430 (unsigned long) sizeof (len),
2434 case record_full_end: /* end */
2435 rec = record_full_end_alloc ();
2436 record_full_insn_num ++;
2438 /* Get signal value. */
2439 bfdcore_read (core_bfd, osec, &signal,
2440 sizeof (signal), &bfd_offset);
2441 signal = netorder32 (signal);
2442 rec->u.end.sigval = (enum gdb_signal) signal;
2444 /* Get insn count. */
2445 bfdcore_read (core_bfd, osec, &count,
2446 sizeof (count), &bfd_offset);
2447 count = netorder32 (count);
2448 rec->u.end.insn_num = count;
2449 record_full_insn_count = count + 1;
2451 fprintf_unfiltered (gdb_stdlog,
2452 " Reading record_full_end (1 + "
2453 "%lu + %lu bytes), offset == %s\n",
2454 (unsigned long) sizeof (signal),
2455 (unsigned long) sizeof (count),
2456 paddress (get_current_arch (),
2461 error (_("Bad entry type in core file %s."),
2462 bfd_get_filename (core_bfd));
2466 /* Add rec to record arch list. */
2467 record_full_arch_list_add (rec);
2470 discard_cleanups (old_cleanups);
2472 /* Add record_full_arch_list_head to the end of record list. */
2473 record_full_first.next = record_full_arch_list_head;
2474 record_full_arch_list_head->prev = &record_full_first;
2475 record_full_arch_list_tail->next = NULL;
2476 record_full_list = &record_full_first;
2478 /* Update record_full_insn_max_num. */
2479 if (record_full_insn_num > record_full_insn_max_num)
2481 record_full_insn_max_num = record_full_insn_num;
2482 warning (_("Auto increase record/replay buffer limit to %u."),
2483 record_full_insn_max_num);
2487 printf_filtered (_("Restored records from core file %s.\n"),
2488 bfd_get_filename (core_bfd));
2490 print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1);
2493 /* bfdcore_write -- write bytes into a core file section. */
2496 bfdcore_write (bfd *obfd, asection *osec, void *buf, int len, int *offset)
2498 int ret = bfd_set_section_contents (obfd, osec, buf, *offset, len);
2503 error (_("Failed to write %d bytes to core file %s ('%s')."),
2504 len, bfd_get_filename (obfd),
2505 bfd_errmsg (bfd_get_error ()));
2508 /* Restore the execution log from a file. We use a modified elf
2509 corefile format, with an extra section for our data. */
2512 cmd_record_full_restore (const char *args, int from_tty)
2514 core_file_command (args, from_tty);
2515 record_full_open (args, from_tty);
2518 /* Save the execution log to a file. We use a modified elf corefile
2519 format, with an extra section for our data. */
2522 record_full_save (struct target_ops *self, const char *recfilename)
2524 struct record_full_entry *cur_record_full_list;
2526 struct regcache *regcache;
2527 struct gdbarch *gdbarch;
2529 asection *osec = NULL;
2532 /* Open the save file. */
2534 fprintf_unfiltered (gdb_stdlog, "Saving execution log to core file '%s'\n",
2537 /* Open the output file. */
2538 gdb_bfd_ref_ptr obfd (create_gcore_bfd (recfilename));
2540 /* Arrange to remove the output file on failure. */
2541 gdb::unlinker unlink_file (recfilename);
2543 /* Save the current record entry to "cur_record_full_list". */
2544 cur_record_full_list = record_full_list;
2546 /* Get the values of regcache and gdbarch. */
2547 regcache = get_current_regcache ();
2548 gdbarch = regcache->arch ();
2550 /* Disable the GDB operation record. */
2551 scoped_restore restore_operation_disable
2552 = record_full_gdb_operation_disable_set ();
2554 /* Reverse execute to the begin of record list. */
2557 /* Check for beginning and end of log. */
2558 if (record_full_list == &record_full_first)
2561 record_full_exec_insn (regcache, gdbarch, record_full_list);
2563 if (record_full_list->prev)
2564 record_full_list = record_full_list->prev;
2567 /* Compute the size needed for the extra bfd section. */
2568 save_size = 4; /* magic cookie */
2569 for (record_full_list = record_full_first.next; record_full_list;
2570 record_full_list = record_full_list->next)
2571 switch (record_full_list->type)
2573 case record_full_end:
2574 save_size += 1 + 4 + 4;
2576 case record_full_reg:
2577 save_size += 1 + 4 + record_full_list->u.reg.len;
2579 case record_full_mem:
2580 save_size += 1 + 4 + 8 + record_full_list->u.mem.len;
2584 /* Make the new bfd section. */
2585 osec = bfd_make_section_anyway_with_flags (obfd.get (), "precord",
2589 error (_("Failed to create 'precord' section for corefile %s: %s"),
2591 bfd_errmsg (bfd_get_error ()));
2592 bfd_set_section_size (obfd.get (), osec, save_size);
2593 bfd_set_section_vma (obfd.get (), osec, 0);
2594 bfd_set_section_alignment (obfd.get (), osec, 0);
2595 bfd_section_lma (obfd.get (), osec) = 0;
2597 /* Save corefile state. */
2598 write_gcore_file (obfd.get ());
2600 /* Write out the record log. */
2601 /* Write the magic code. */
2602 magic = RECORD_FULL_FILE_MAGIC;
2604 fprintf_unfiltered (gdb_stdlog,
2605 " Writing 4-byte magic cookie "
2606 "RECORD_FULL_FILE_MAGIC (0x%s)\n",
2607 phex_nz (magic, 4));
2608 bfdcore_write (obfd.get (), osec, &magic, sizeof (magic), &bfd_offset);
2610 /* Save the entries to recfd and forward execute to the end of
2612 record_full_list = &record_full_first;
2616 if (record_full_list != &record_full_first)
2619 uint32_t regnum, len, signal, count;
2622 type = record_full_list->type;
2623 bfdcore_write (obfd.get (), osec, &type, sizeof (type), &bfd_offset);
2625 switch (record_full_list->type)
2627 case record_full_reg: /* reg */
2629 fprintf_unfiltered (gdb_stdlog,
2630 " Writing register %d (1 "
2631 "plus %lu plus %d bytes)\n",
2632 record_full_list->u.reg.num,
2633 (unsigned long) sizeof (regnum),
2634 record_full_list->u.reg.len);
2637 regnum = netorder32 (record_full_list->u.reg.num);
2638 bfdcore_write (obfd.get (), osec, ®num,
2639 sizeof (regnum), &bfd_offset);
2642 bfdcore_write (obfd.get (), osec,
2643 record_full_get_loc (record_full_list),
2644 record_full_list->u.reg.len, &bfd_offset);
2647 case record_full_mem: /* mem */
2649 fprintf_unfiltered (gdb_stdlog,
2650 " Writing memory %s (1 plus "
2651 "%lu plus %lu plus %d bytes)\n",
2653 record_full_list->u.mem.addr),
2654 (unsigned long) sizeof (addr),
2655 (unsigned long) sizeof (len),
2656 record_full_list->u.mem.len);
2659 len = netorder32 (record_full_list->u.mem.len);
2660 bfdcore_write (obfd.get (), osec, &len, sizeof (len),
2663 /* Write memaddr. */
2664 addr = netorder64 (record_full_list->u.mem.addr);
2665 bfdcore_write (obfd.get (), osec, &addr,
2666 sizeof (addr), &bfd_offset);
2669 bfdcore_write (obfd.get (), osec,
2670 record_full_get_loc (record_full_list),
2671 record_full_list->u.mem.len, &bfd_offset);
2674 case record_full_end:
2676 fprintf_unfiltered (gdb_stdlog,
2677 " Writing record_full_end (1 + "
2678 "%lu + %lu bytes)\n",
2679 (unsigned long) sizeof (signal),
2680 (unsigned long) sizeof (count));
2681 /* Write signal value. */
2682 signal = netorder32 (record_full_list->u.end.sigval);
2683 bfdcore_write (obfd.get (), osec, &signal,
2684 sizeof (signal), &bfd_offset);
2686 /* Write insn count. */
2687 count = netorder32 (record_full_list->u.end.insn_num);
2688 bfdcore_write (obfd.get (), osec, &count,
2689 sizeof (count), &bfd_offset);
2694 /* Execute entry. */
2695 record_full_exec_insn (regcache, gdbarch, record_full_list);
2697 if (record_full_list->next)
2698 record_full_list = record_full_list->next;
2703 /* Reverse execute to cur_record_full_list. */
2706 /* Check for beginning and end of log. */
2707 if (record_full_list == cur_record_full_list)
2710 record_full_exec_insn (regcache, gdbarch, record_full_list);
2712 if (record_full_list->prev)
2713 record_full_list = record_full_list->prev;
2716 unlink_file.keep ();
2719 printf_filtered (_("Saved core file %s with execution log.\n"),
2723 /* record_full_goto_insn -- rewind the record log (forward or backward,
2724 depending on DIR) to the given entry, changing the program state
2728 record_full_goto_insn (struct record_full_entry *entry,
2729 enum exec_direction_kind dir)
2731 scoped_restore restore_operation_disable
2732 = record_full_gdb_operation_disable_set ();
2733 struct regcache *regcache = get_current_regcache ();
2734 struct gdbarch *gdbarch = regcache->arch ();
2736 /* Assume everything is valid: we will hit the entry,
2737 and we will not hit the end of the recording. */
2739 if (dir == EXEC_FORWARD)
2740 record_full_list = record_full_list->next;
2744 record_full_exec_insn (regcache, gdbarch, record_full_list);
2745 if (dir == EXEC_REVERSE)
2746 record_full_list = record_full_list->prev;
2748 record_full_list = record_full_list->next;
2749 } while (record_full_list != entry);
2752 /* Alias for "target record-full". */
2755 cmd_record_full_start (const char *args, int from_tty)
2757 execute_command ("target record-full", from_tty);
2761 set_record_full_insn_max_num (const char *args, int from_tty,
2762 struct cmd_list_element *c)
2764 if (record_full_insn_num > record_full_insn_max_num)
2766 /* Count down record_full_insn_num while releasing records from list. */
2767 while (record_full_insn_num > record_full_insn_max_num)
2769 record_full_list_release_first ();
2770 record_full_insn_num--;
2775 /* The "set record full" command. */
2778 set_record_full_command (const char *args, int from_tty)
2780 printf_unfiltered (_("\"set record full\" must be followed "
2781 "by an appropriate subcommand.\n"));
2782 help_list (set_record_full_cmdlist, "set record full ", all_commands,
2786 /* The "show record full" command. */
2789 show_record_full_command (const char *args, int from_tty)
2791 cmd_show_list (show_record_full_cmdlist, from_tty, "");
2795 _initialize_record_full (void)
2797 struct cmd_list_element *c;
2799 /* Init record_full_first. */
2800 record_full_first.prev = NULL;
2801 record_full_first.next = NULL;
2802 record_full_first.type = record_full_end;
2804 init_record_full_ops ();
2805 add_target (&record_full_ops);
2806 add_deprecated_target_alias (&record_full_ops, "record");
2807 init_record_full_core_ops ();
2808 add_target (&record_full_core_ops);
2810 add_prefix_cmd ("full", class_obscure, cmd_record_full_start,
2811 _("Start full execution recording."), &record_full_cmdlist,
2812 "record full ", 0, &record_cmdlist);
2814 c = add_cmd ("restore", class_obscure, cmd_record_full_restore,
2815 _("Restore the execution log from a file.\n\
2816 Argument is filename. File must be created with 'record save'."),
2817 &record_full_cmdlist);
2818 set_cmd_completer (c, filename_completer);
2820 /* Deprecate the old version without "full" prefix. */
2821 c = add_alias_cmd ("restore", "full restore", class_obscure, 1,
2823 set_cmd_completer (c, filename_completer);
2824 deprecate_cmd (c, "record full restore");
2826 add_prefix_cmd ("full", class_support, set_record_full_command,
2827 _("Set record options"), &set_record_full_cmdlist,
2828 "set record full ", 0, &set_record_cmdlist);
2830 add_prefix_cmd ("full", class_support, show_record_full_command,
2831 _("Show record options"), &show_record_full_cmdlist,
2832 "show record full ", 0, &show_record_cmdlist);
2834 /* Record instructions number limit command. */
2835 add_setshow_boolean_cmd ("stop-at-limit", no_class,
2836 &record_full_stop_at_limit, _("\
2837 Set whether record/replay stops when record/replay buffer becomes full."), _("\
2838 Show whether record/replay stops when record/replay buffer becomes full."),
2839 _("Default is ON.\n\
2840 When ON, if the record/replay buffer becomes full, ask user what to do.\n\
2841 When OFF, if the record/replay buffer becomes full,\n\
2842 delete the oldest recorded instruction to make room for each new one."),
2844 &set_record_full_cmdlist, &show_record_full_cmdlist);
2846 c = add_alias_cmd ("stop-at-limit", "full stop-at-limit", no_class, 1,
2847 &set_record_cmdlist);
2848 deprecate_cmd (c, "set record full stop-at-limit");
2850 c = add_alias_cmd ("stop-at-limit", "full stop-at-limit", no_class, 1,
2851 &show_record_cmdlist);
2852 deprecate_cmd (c, "show record full stop-at-limit");
2854 add_setshow_uinteger_cmd ("insn-number-max", no_class,
2855 &record_full_insn_max_num,
2856 _("Set record/replay buffer limit."),
2857 _("Show record/replay buffer limit."), _("\
2858 Set the maximum number of instructions to be stored in the\n\
2859 record/replay buffer. A value of either \"unlimited\" or zero means no\n\
2860 limit. Default is 200000."),
2861 set_record_full_insn_max_num,
2862 NULL, &set_record_full_cmdlist,
2863 &show_record_full_cmdlist);
2865 c = add_alias_cmd ("insn-number-max", "full insn-number-max", no_class, 1,
2866 &set_record_cmdlist);
2867 deprecate_cmd (c, "set record full insn-number-max");
2869 c = add_alias_cmd ("insn-number-max", "full insn-number-max", no_class, 1,
2870 &show_record_cmdlist);
2871 deprecate_cmd (c, "show record full insn-number-max");
2873 add_setshow_boolean_cmd ("memory-query", no_class,
2874 &record_full_memory_query, _("\
2875 Set whether query if PREC cannot record memory change of next instruction."),
2877 Show whether query if PREC cannot record memory change of next instruction."),
2880 When ON, query if PREC cannot record memory change of next instruction."),
2882 &set_record_full_cmdlist,
2883 &show_record_full_cmdlist);
2885 c = add_alias_cmd ("memory-query", "full memory-query", no_class, 1,
2886 &set_record_cmdlist);
2887 deprecate_cmd (c, "set record full memory-query");
2889 c = add_alias_cmd ("memory-query", "full memory-query", no_class, 1,
2890 &show_record_cmdlist);
2891 deprecate_cmd (c, "show record full memory-query");