1 /* Process record and replay target for GDB, the GNU debugger.
3 Copyright (C) 2013-2018 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"
25 #include "event-top.h"
26 #include "completer.h"
27 #include "arch-utils.h"
31 #include "record-full.h"
34 #include "event-loop.h"
37 #include "observable.h"
39 #include "common/gdb_unlinker.h"
40 #include "common/byte-vector.h"
44 /* This module implements "target record-full", also known as "process
45 record and replay". This target sits on top of a "normal" target
46 (a target that "has execution"), and provides a record and replay
47 functionality, including reverse debugging.
49 Target record has two modes: recording, and replaying.
51 In record mode, we intercept the resume and wait methods.
52 Whenever gdb resumes the target, we run the target in single step
53 mode, and we build up an execution log in which, for each executed
54 instruction, we record all changes in memory and register state.
55 This is invisible to the user, to whom it just looks like an
56 ordinary debugging session (except for performance degredation).
58 In replay mode, instead of actually letting the inferior run as a
59 process, we simulate its execution by playing back the recorded
60 execution log. For each instruction in the log, we simulate the
61 instruction's side effects by duplicating the changes that it would
62 have made on memory and registers. */
64 #define DEFAULT_RECORD_FULL_INSN_MAX_NUM 200000
66 #define RECORD_FULL_IS_REPLAY \
67 (record_full_list->next || ::execution_direction == EXEC_REVERSE)
69 #define RECORD_FULL_FILE_MAGIC netorder32(0x20091016)
71 /* These are the core structs of the process record functionality.
73 A record_full_entry is a record of the value change of a register
74 ("record_full_reg") or a part of memory ("record_full_mem"). And each
75 instruction must have a struct record_full_entry ("record_full_end")
76 that indicates that this is the last struct record_full_entry of this
79 Each struct record_full_entry is linked to "record_full_list" by "prev"
80 and "next" pointers. */
82 struct record_full_mem_entry
86 /* Set this flag if target memory for this entry
87 can no longer be accessed. */
88 int mem_entry_not_accessible
;
92 gdb_byte buf
[sizeof (gdb_byte
*)];
96 struct record_full_reg_entry
103 gdb_byte buf
[2 * sizeof (gdb_byte
*)];
107 struct record_full_end_entry
109 enum gdb_signal sigval
;
113 enum record_full_type
120 /* This is the data structure that makes up the execution log.
122 The execution log consists of a single linked list of entries
123 of type "struct record_full_entry". It is doubly linked so that it
124 can be traversed in either direction.
126 The start of the list is anchored by a struct called
127 "record_full_first". The pointer "record_full_list" either points
128 to the last entry that was added to the list (in record mode), or to
129 the next entry in the list that will be executed (in replay mode).
131 Each list element (struct record_full_entry), in addition to next
132 and prev pointers, consists of a union of three entry types: mem,
133 reg, and end. A field called "type" determines which entry type is
134 represented by a given list element.
136 Each instruction that is added to the execution log is represented
137 by a variable number of list elements ('entries'). The instruction
138 will have one "reg" entry for each register that is changed by
139 executing the instruction (including the PC in every case). It
140 will also have one "mem" entry for each memory change. Finally,
141 each instruction will have an "end" entry that separates it from
142 the changes associated with the next instruction. */
144 struct record_full_entry
146 struct record_full_entry
*prev
;
147 struct record_full_entry
*next
;
148 enum record_full_type type
;
152 struct record_full_reg_entry reg
;
154 struct record_full_mem_entry mem
;
156 struct record_full_end_entry end
;
160 /* If true, query if PREC cannot record memory
161 change of next instruction. */
162 int record_full_memory_query
= 0;
164 struct record_full_core_buf_entry
166 struct record_full_core_buf_entry
*prev
;
167 struct target_section
*p
;
171 /* Record buf with core target. */
172 static detached_regcache
*record_full_core_regbuf
= NULL
;
173 static struct target_section
*record_full_core_start
;
174 static struct target_section
*record_full_core_end
;
175 static struct record_full_core_buf_entry
*record_full_core_buf_list
= NULL
;
177 /* The following variables are used for managing the linked list that
178 represents the execution log.
180 record_full_first is the anchor that holds down the beginning of
183 record_full_list serves two functions:
184 1) In record mode, it anchors the end of the list.
185 2) In replay mode, it traverses the list and points to
186 the next instruction that must be emulated.
188 record_full_arch_list_head and record_full_arch_list_tail are used
189 to manage a separate list, which is used to build up the change
190 elements of the currently executing instruction during record mode.
191 When this instruction has been completely annotated in the "arch
192 list", it will be appended to the main execution log. */
194 static struct record_full_entry record_full_first
;
195 static struct record_full_entry
*record_full_list
= &record_full_first
;
196 static struct record_full_entry
*record_full_arch_list_head
= NULL
;
197 static struct record_full_entry
*record_full_arch_list_tail
= NULL
;
199 /* 1 ask user. 0 auto delete the last struct record_full_entry. */
200 static int record_full_stop_at_limit
= 1;
201 /* Maximum allowed number of insns in execution log. */
202 static unsigned int record_full_insn_max_num
203 = DEFAULT_RECORD_FULL_INSN_MAX_NUM
;
204 /* Actual count of insns presently in execution log. */
205 static unsigned int record_full_insn_num
= 0;
206 /* Count of insns logged so far (may be larger
207 than count of insns presently in execution log). */
208 static ULONGEST record_full_insn_count
;
210 static const char record_longname
[]
211 = N_("Process record and replay target");
212 static const char record_doc
[]
213 = N_("Log program while executing and replay execution from log.");
215 /* Base class implementing functionality common to both the
216 "record-full" and "record-core" targets. */
218 class record_full_base_target
: public target_ops
221 record_full_base_target ()
222 { to_stratum
= record_stratum
; }
224 const target_info
&info () const override
= 0;
226 void close () override
;
227 void async (int) override
;
228 ptid_t
wait (ptid_t
, struct target_waitstatus
*, int) override
;
229 bool stopped_by_watchpoint () override
;
230 bool stopped_data_address (CORE_ADDR
*) override
;
232 bool stopped_by_sw_breakpoint () override
;
233 bool supports_stopped_by_sw_breakpoint () override
;
235 bool stopped_by_hw_breakpoint () override
;
236 bool supports_stopped_by_hw_breakpoint () override
;
238 bool can_execute_reverse () override
;
240 /* Add bookmark target methods. */
241 gdb_byte
*get_bookmark (const char *, int) override
;
242 void goto_bookmark (const gdb_byte
*, int) override
;
243 enum exec_direction_kind
execution_direction () override
;
244 enum record_method
record_method (ptid_t ptid
) override
;
245 void info_record () override
;
246 void save_record (const char *filename
) override
;
247 bool supports_delete_record () override
;
248 void delete_record () override
;
249 bool record_is_replaying (ptid_t ptid
) override
;
250 bool record_will_replay (ptid_t ptid
, int dir
) override
;
251 void record_stop_replaying () override
;
252 void goto_record_begin () override
;
253 void goto_record_end () override
;
254 void goto_record (ULONGEST insn
) override
;
257 /* The "record-full" target. */
259 static const target_info record_full_target_info
= {
265 class record_full_target final
: public record_full_base_target
268 const target_info
&info () const override
269 { return record_full_target_info
; }
271 void commit_resume () override
;
272 void resume (ptid_t
, int, enum gdb_signal
) override
;
273 void disconnect (const char *, int) override
;
274 void detach (inferior
*, int) override
;
275 void mourn_inferior () override
;
276 void kill () override
;
277 void store_registers (struct regcache
*, int) override
;
278 enum target_xfer_status
xfer_partial (enum target_object object
,
281 const gdb_byte
*writebuf
,
282 ULONGEST offset
, ULONGEST len
,
283 ULONGEST
*xfered_len
) override
;
284 int insert_breakpoint (struct gdbarch
*,
285 struct bp_target_info
*) override
;
286 int remove_breakpoint (struct gdbarch
*,
287 struct bp_target_info
*,
288 enum remove_bp_reason
) override
;
291 /* The "record-core" target. */
293 static const target_info record_full_core_target_info
= {
299 class record_full_core_target final
: public record_full_base_target
302 const target_info
&info () const override
303 { return record_full_core_target_info
; }
305 void resume (ptid_t
, int, enum gdb_signal
) override
;
306 void disconnect (const char *, int) override
;
307 void kill () override
;
308 void fetch_registers (struct regcache
*regcache
, int regno
) override
;
309 void prepare_to_store (struct regcache
*regcache
) override
;
310 void store_registers (struct regcache
*, int) override
;
311 enum target_xfer_status
xfer_partial (enum target_object object
,
314 const gdb_byte
*writebuf
,
315 ULONGEST offset
, ULONGEST len
,
316 ULONGEST
*xfered_len
) override
;
317 int insert_breakpoint (struct gdbarch
*,
318 struct bp_target_info
*) override
;
319 int remove_breakpoint (struct gdbarch
*,
320 struct bp_target_info
*,
321 enum remove_bp_reason
) override
;
323 bool has_execution (ptid_t
) override
;
326 static record_full_target record_full_ops
;
327 static record_full_core_target record_full_core_ops
;
330 record_full_target::detach (inferior
*inf
, int from_tty
)
332 record_detach (this, inf
, from_tty
);
336 record_full_target::disconnect (const char *args
, int from_tty
)
338 record_disconnect (this, args
, from_tty
);
342 record_full_core_target::disconnect (const char *args
, int from_tty
)
344 record_disconnect (this, args
, from_tty
);
348 record_full_target::mourn_inferior ()
350 record_mourn_inferior (this);
354 record_full_target::kill ()
359 /* See record-full.h. */
362 record_full_is_used (void)
364 struct target_ops
*t
;
366 t
= find_record_target ();
367 return (t
== &record_full_ops
368 || t
== &record_full_core_ops
);
372 /* Command lists for "set/show record full". */
373 static struct cmd_list_element
*set_record_full_cmdlist
;
374 static struct cmd_list_element
*show_record_full_cmdlist
;
376 /* Command list for "record full". */
377 static struct cmd_list_element
*record_full_cmdlist
;
379 static void record_full_goto_insn (struct record_full_entry
*entry
,
380 enum exec_direction_kind dir
);
382 /* Alloc and free functions for record_full_reg, record_full_mem, and
383 record_full_end entries. */
385 /* Alloc a record_full_reg record entry. */
387 static inline struct record_full_entry
*
388 record_full_reg_alloc (struct regcache
*regcache
, int regnum
)
390 struct record_full_entry
*rec
;
391 struct gdbarch
*gdbarch
= regcache
->arch ();
393 rec
= XCNEW (struct record_full_entry
);
394 rec
->type
= record_full_reg
;
395 rec
->u
.reg
.num
= regnum
;
396 rec
->u
.reg
.len
= register_size (gdbarch
, regnum
);
397 if (rec
->u
.reg
.len
> sizeof (rec
->u
.reg
.u
.buf
))
398 rec
->u
.reg
.u
.ptr
= (gdb_byte
*) xmalloc (rec
->u
.reg
.len
);
403 /* Free a record_full_reg record entry. */
406 record_full_reg_release (struct record_full_entry
*rec
)
408 gdb_assert (rec
->type
== record_full_reg
);
409 if (rec
->u
.reg
.len
> sizeof (rec
->u
.reg
.u
.buf
))
410 xfree (rec
->u
.reg
.u
.ptr
);
414 /* Alloc a record_full_mem record entry. */
416 static inline struct record_full_entry
*
417 record_full_mem_alloc (CORE_ADDR addr
, int len
)
419 struct record_full_entry
*rec
;
421 rec
= XCNEW (struct record_full_entry
);
422 rec
->type
= record_full_mem
;
423 rec
->u
.mem
.addr
= addr
;
424 rec
->u
.mem
.len
= len
;
425 if (rec
->u
.mem
.len
> sizeof (rec
->u
.mem
.u
.buf
))
426 rec
->u
.mem
.u
.ptr
= (gdb_byte
*) xmalloc (len
);
431 /* Free a record_full_mem record entry. */
434 record_full_mem_release (struct record_full_entry
*rec
)
436 gdb_assert (rec
->type
== record_full_mem
);
437 if (rec
->u
.mem
.len
> sizeof (rec
->u
.mem
.u
.buf
))
438 xfree (rec
->u
.mem
.u
.ptr
);
442 /* Alloc a record_full_end record entry. */
444 static inline struct record_full_entry
*
445 record_full_end_alloc (void)
447 struct record_full_entry
*rec
;
449 rec
= XCNEW (struct record_full_entry
);
450 rec
->type
= record_full_end
;
455 /* Free a record_full_end record entry. */
458 record_full_end_release (struct record_full_entry
*rec
)
463 /* Free one record entry, any type.
464 Return entry->type, in case caller wants to know. */
466 static inline enum record_full_type
467 record_full_entry_release (struct record_full_entry
*rec
)
469 enum record_full_type type
= rec
->type
;
472 case record_full_reg
:
473 record_full_reg_release (rec
);
475 case record_full_mem
:
476 record_full_mem_release (rec
);
478 case record_full_end
:
479 record_full_end_release (rec
);
485 /* Free all record entries in list pointed to by REC. */
488 record_full_list_release (struct record_full_entry
*rec
)
499 record_full_entry_release (rec
->next
);
502 if (rec
== &record_full_first
)
504 record_full_insn_num
= 0;
505 record_full_first
.next
= NULL
;
508 record_full_entry_release (rec
);
511 /* Free all record entries forward of the given list position. */
514 record_full_list_release_following (struct record_full_entry
*rec
)
516 struct record_full_entry
*tmp
= rec
->next
;
522 if (record_full_entry_release (tmp
) == record_full_end
)
524 record_full_insn_num
--;
525 record_full_insn_count
--;
531 /* Delete the first instruction from the beginning of the log, to make
532 room for adding a new instruction at the end of the log.
534 Note -- this function does not modify record_full_insn_num. */
537 record_full_list_release_first (void)
539 struct record_full_entry
*tmp
;
541 if (!record_full_first
.next
)
544 /* Loop until a record_full_end. */
547 /* Cut record_full_first.next out of the linked list. */
548 tmp
= record_full_first
.next
;
549 record_full_first
.next
= tmp
->next
;
550 tmp
->next
->prev
= &record_full_first
;
552 /* tmp is now isolated, and can be deleted. */
553 if (record_full_entry_release (tmp
) == record_full_end
)
554 break; /* End loop at first record_full_end. */
556 if (!record_full_first
.next
)
558 gdb_assert (record_full_insn_num
== 1);
559 break; /* End loop when list is empty. */
564 /* Add a struct record_full_entry to record_full_arch_list. */
567 record_full_arch_list_add (struct record_full_entry
*rec
)
569 if (record_debug
> 1)
570 fprintf_unfiltered (gdb_stdlog
,
571 "Process record: record_full_arch_list_add %s.\n",
572 host_address_to_string (rec
));
574 if (record_full_arch_list_tail
)
576 record_full_arch_list_tail
->next
= rec
;
577 rec
->prev
= record_full_arch_list_tail
;
578 record_full_arch_list_tail
= rec
;
582 record_full_arch_list_head
= rec
;
583 record_full_arch_list_tail
= rec
;
587 /* Return the value storage location of a record entry. */
588 static inline gdb_byte
*
589 record_full_get_loc (struct record_full_entry
*rec
)
592 case record_full_mem
:
593 if (rec
->u
.mem
.len
> sizeof (rec
->u
.mem
.u
.buf
))
594 return rec
->u
.mem
.u
.ptr
;
596 return rec
->u
.mem
.u
.buf
;
597 case record_full_reg
:
598 if (rec
->u
.reg
.len
> sizeof (rec
->u
.reg
.u
.buf
))
599 return rec
->u
.reg
.u
.ptr
;
601 return rec
->u
.reg
.u
.buf
;
602 case record_full_end
:
604 gdb_assert_not_reached ("unexpected record_full_entry type");
609 /* Record the value of a register NUM to record_full_arch_list. */
612 record_full_arch_list_add_reg (struct regcache
*regcache
, int regnum
)
614 struct record_full_entry
*rec
;
616 if (record_debug
> 1)
617 fprintf_unfiltered (gdb_stdlog
,
618 "Process record: add register num = %d to "
622 rec
= record_full_reg_alloc (regcache
, regnum
);
624 regcache
->raw_read (regnum
, record_full_get_loc (rec
));
626 record_full_arch_list_add (rec
);
631 /* Record the value of a region of memory whose address is ADDR and
632 length is LEN to record_full_arch_list. */
635 record_full_arch_list_add_mem (CORE_ADDR addr
, int len
)
637 struct record_full_entry
*rec
;
639 if (record_debug
> 1)
640 fprintf_unfiltered (gdb_stdlog
,
641 "Process record: add mem addr = %s len = %d to "
643 paddress (target_gdbarch (), addr
), len
);
645 if (!addr
) /* FIXME: Why? Some arch must permit it... */
648 rec
= record_full_mem_alloc (addr
, len
);
650 if (record_read_memory (target_gdbarch (), addr
,
651 record_full_get_loc (rec
), len
))
653 record_full_mem_release (rec
);
657 record_full_arch_list_add (rec
);
662 /* Add a record_full_end type struct record_full_entry to
663 record_full_arch_list. */
666 record_full_arch_list_add_end (void)
668 struct record_full_entry
*rec
;
670 if (record_debug
> 1)
671 fprintf_unfiltered (gdb_stdlog
,
672 "Process record: add end to arch list.\n");
674 rec
= record_full_end_alloc ();
675 rec
->u
.end
.sigval
= GDB_SIGNAL_0
;
676 rec
->u
.end
.insn_num
= ++record_full_insn_count
;
678 record_full_arch_list_add (rec
);
684 record_full_check_insn_num (void)
686 if (record_full_insn_num
== record_full_insn_max_num
)
688 /* Ask user what to do. */
689 if (record_full_stop_at_limit
)
691 if (!yquery (_("Do you want to auto delete previous execution "
692 "log entries when record/replay buffer becomes "
693 "full (record full stop-at-limit)?")))
694 error (_("Process record: stopped by user."));
695 record_full_stop_at_limit
= 0;
700 /* Before inferior step (when GDB record the running message, inferior
701 only can step), GDB will call this function to record the values to
702 record_full_list. This function will call gdbarch_process_record to
703 record the running message of inferior and set them to
704 record_full_arch_list, and add it to record_full_list. */
707 record_full_message (struct regcache
*regcache
, enum gdb_signal signal
)
710 struct gdbarch
*gdbarch
= regcache
->arch ();
714 record_full_arch_list_head
= NULL
;
715 record_full_arch_list_tail
= NULL
;
717 /* Check record_full_insn_num. */
718 record_full_check_insn_num ();
720 /* If gdb sends a signal value to target_resume,
721 save it in the 'end' field of the previous instruction.
723 Maybe process record should record what really happened,
724 rather than what gdb pretends has happened.
726 So if Linux delivered the signal to the child process during
727 the record mode, we will record it and deliver it again in
730 If user says "ignore this signal" during the record mode, then
731 it will be ignored again during the replay mode (no matter if
732 the user says something different, like "deliver this signal"
733 during the replay mode).
735 User should understand that nothing he does during the replay
736 mode will change the behavior of the child. If he tries,
737 then that is a user error.
739 But we should still deliver the signal to gdb during the replay,
740 if we delivered it during the recording. Therefore we should
741 record the signal during record_full_wait, not
742 record_full_resume. */
743 if (record_full_list
!= &record_full_first
) /* FIXME better way
746 gdb_assert (record_full_list
->type
== record_full_end
);
747 record_full_list
->u
.end
.sigval
= signal
;
750 if (signal
== GDB_SIGNAL_0
751 || !gdbarch_process_record_signal_p (gdbarch
))
752 ret
= gdbarch_process_record (gdbarch
,
754 regcache_read_pc (regcache
));
756 ret
= gdbarch_process_record_signal (gdbarch
,
761 error (_("Process record: inferior program stopped."));
763 error (_("Process record: failed to record execution log."));
765 CATCH (ex
, RETURN_MASK_ALL
)
767 record_full_list_release (record_full_arch_list_tail
);
768 throw_exception (ex
);
772 record_full_list
->next
= record_full_arch_list_head
;
773 record_full_arch_list_head
->prev
= record_full_list
;
774 record_full_list
= record_full_arch_list_tail
;
776 if (record_full_insn_num
== record_full_insn_max_num
)
777 record_full_list_release_first ();
779 record_full_insn_num
++;
783 record_full_message_wrapper_safe (struct regcache
*regcache
,
784 enum gdb_signal signal
)
788 record_full_message (regcache
, signal
);
790 CATCH (ex
, RETURN_MASK_ALL
)
792 exception_print (gdb_stderr
, ex
);
800 /* Set to 1 if record_full_store_registers and record_full_xfer_partial
801 doesn't need record. */
803 static int record_full_gdb_operation_disable
= 0;
805 scoped_restore_tmpl
<int>
806 record_full_gdb_operation_disable_set (void)
808 return make_scoped_restore (&record_full_gdb_operation_disable
, 1);
811 /* Flag set to TRUE for target_stopped_by_watchpoint. */
812 static enum target_stop_reason record_full_stop_reason
813 = TARGET_STOPPED_BY_NO_REASON
;
815 /* Execute one instruction from the record log. Each instruction in
816 the log will be represented by an arbitrary sequence of register
817 entries and memory entries, followed by an 'end' entry. */
820 record_full_exec_insn (struct regcache
*regcache
,
821 struct gdbarch
*gdbarch
,
822 struct record_full_entry
*entry
)
826 case record_full_reg
: /* reg */
828 gdb::byte_vector
reg (entry
->u
.reg
.len
);
830 if (record_debug
> 1)
831 fprintf_unfiltered (gdb_stdlog
,
832 "Process record: record_full_reg %s to "
833 "inferior num = %d.\n",
834 host_address_to_string (entry
),
837 regcache
->cooked_read (entry
->u
.reg
.num
, reg
.data ());
838 regcache
->cooked_write (entry
->u
.reg
.num
, record_full_get_loc (entry
));
839 memcpy (record_full_get_loc (entry
), reg
.data (), entry
->u
.reg
.len
);
843 case record_full_mem
: /* mem */
845 /* Nothing to do if the entry is flagged not_accessible. */
846 if (!entry
->u
.mem
.mem_entry_not_accessible
)
848 gdb::byte_vector
mem (entry
->u
.mem
.len
);
850 if (record_debug
> 1)
851 fprintf_unfiltered (gdb_stdlog
,
852 "Process record: record_full_mem %s to "
853 "inferior addr = %s len = %d.\n",
854 host_address_to_string (entry
),
855 paddress (gdbarch
, entry
->u
.mem
.addr
),
858 if (record_read_memory (gdbarch
,
859 entry
->u
.mem
.addr
, mem
.data (),
861 entry
->u
.mem
.mem_entry_not_accessible
= 1;
864 if (target_write_memory (entry
->u
.mem
.addr
,
865 record_full_get_loc (entry
),
868 entry
->u
.mem
.mem_entry_not_accessible
= 1;
870 warning (_("Process record: error writing memory at "
871 "addr = %s len = %d."),
872 paddress (gdbarch
, entry
->u
.mem
.addr
),
877 memcpy (record_full_get_loc (entry
), mem
.data (),
880 /* We've changed memory --- check if a hardware
881 watchpoint should trap. Note that this
882 presently assumes the target beneath supports
883 continuable watchpoints. On non-continuable
884 watchpoints target, we'll want to check this
885 _before_ actually doing the memory change, and
886 not doing the change at all if the watchpoint
888 if (hardware_watchpoint_inserted_in_range
889 (regcache
->aspace (),
890 entry
->u
.mem
.addr
, entry
->u
.mem
.len
))
891 record_full_stop_reason
= TARGET_STOPPED_BY_WATCHPOINT
;
900 static void record_full_restore (void);
902 /* Asynchronous signal handle registered as event loop source for when
903 we have pending events ready to be passed to the core. */
905 static struct async_event_handler
*record_full_async_inferior_event_token
;
908 record_full_async_inferior_event_handler (gdb_client_data data
)
910 inferior_event_handler (INF_REG_EVENT
, NULL
);
913 /* Open the process record target for 'core' files. */
916 record_full_core_open_1 (const char *name
, int from_tty
)
918 struct regcache
*regcache
= get_current_regcache ();
919 int regnum
= gdbarch_num_regs (regcache
->arch ());
922 /* Get record_full_core_regbuf. */
923 target_fetch_registers (regcache
, -1);
924 record_full_core_regbuf
= new detached_regcache (regcache
->arch (), false);
926 for (i
= 0; i
< regnum
; i
++)
927 record_full_core_regbuf
->raw_supply (i
, *regcache
);
929 /* Get record_full_core_start and record_full_core_end. */
930 if (build_section_table (core_bfd
, &record_full_core_start
,
931 &record_full_core_end
))
933 delete record_full_core_regbuf
;
934 record_full_core_regbuf
= NULL
;
935 error (_("\"%s\": Can't find sections: %s"),
936 bfd_get_filename (core_bfd
), bfd_errmsg (bfd_get_error ()));
939 push_target (&record_full_core_ops
);
940 record_full_restore ();
943 /* Open the process record target for 'live' processes. */
946 record_full_open_1 (const char *name
, int from_tty
)
949 fprintf_unfiltered (gdb_stdlog
, "Process record: record_full_open_1\n");
952 if (!target_has_execution
)
953 error (_("Process record: the program is not being run."));
955 error (_("Process record target can't debug inferior in non-stop mode "
958 if (!gdbarch_process_record_p (target_gdbarch ()))
959 error (_("Process record: the current architecture doesn't support "
960 "record function."));
962 push_target (&record_full_ops
);
965 static void record_full_init_record_breakpoints (void);
967 /* Open the process record target. */
970 record_full_open (const char *name
, int from_tty
)
973 fprintf_unfiltered (gdb_stdlog
, "Process record: record_full_open\n");
978 record_full_insn_num
= 0;
979 record_full_insn_count
= 0;
980 record_full_list
= &record_full_first
;
981 record_full_list
->next
= NULL
;
984 record_full_core_open_1 (name
, from_tty
);
986 record_full_open_1 (name
, from_tty
);
988 /* Register extra event sources in the event loop. */
989 record_full_async_inferior_event_token
990 = create_async_event_handler (record_full_async_inferior_event_handler
,
993 record_full_init_record_breakpoints ();
995 gdb::observers::record_changed
.notify (current_inferior (), 1, "full", NULL
);
998 /* "close" target method. Close the process record target. */
1001 record_full_base_target::close ()
1003 struct record_full_core_buf_entry
*entry
;
1006 fprintf_unfiltered (gdb_stdlog
, "Process record: record_full_close\n");
1008 record_full_list_release (record_full_list
);
1010 /* Release record_full_core_regbuf. */
1011 if (record_full_core_regbuf
)
1013 delete record_full_core_regbuf
;
1014 record_full_core_regbuf
= NULL
;
1017 /* Release record_full_core_buf_list. */
1018 if (record_full_core_buf_list
)
1020 for (entry
= record_full_core_buf_list
->prev
; entry
;
1021 entry
= entry
->prev
)
1023 xfree (record_full_core_buf_list
);
1024 record_full_core_buf_list
= entry
;
1026 record_full_core_buf_list
= NULL
;
1029 if (record_full_async_inferior_event_token
)
1030 delete_async_event_handler (&record_full_async_inferior_event_token
);
1033 /* "async" target method. */
1036 record_full_base_target::async (int enable
)
1039 mark_async_event_handler (record_full_async_inferior_event_token
);
1041 clear_async_event_handler (record_full_async_inferior_event_token
);
1043 beneath ()->async (enable
);
1046 static int record_full_resume_step
= 0;
1048 /* True if we've been resumed, and so each record_full_wait call should
1049 advance execution. If this is false, record_full_wait will return a
1050 TARGET_WAITKIND_IGNORE. */
1051 static int record_full_resumed
= 0;
1053 /* The execution direction of the last resume we got. This is
1054 necessary for async mode. Vis (order is not strictly accurate):
1056 1. user has the global execution direction set to forward
1057 2. user does a reverse-step command
1058 3. record_full_resume is called with global execution direction
1059 temporarily switched to reverse
1060 4. GDB's execution direction is reverted back to forward
1061 5. target record notifies event loop there's an event to handle
1062 6. infrun asks the target which direction was it going, and switches
1063 the global execution direction accordingly (to reverse)
1064 7. infrun polls an event out of the record target, and handles it
1065 8. GDB goes back to the event loop, and goto #4.
1067 static enum exec_direction_kind record_full_execution_dir
= EXEC_FORWARD
;
1069 /* "resume" target method. Resume the process record target. */
1072 record_full_target::resume (ptid_t ptid
, int step
, enum gdb_signal signal
)
1074 record_full_resume_step
= step
;
1075 record_full_resumed
= 1;
1076 record_full_execution_dir
= ::execution_direction
;
1078 if (!RECORD_FULL_IS_REPLAY
)
1080 struct gdbarch
*gdbarch
= target_thread_architecture (ptid
);
1082 record_full_message (get_current_regcache (), signal
);
1086 /* This is not hard single step. */
1087 if (!gdbarch_software_single_step_p (gdbarch
))
1089 /* This is a normal continue. */
1094 /* This arch supports soft single step. */
1095 if (thread_has_single_step_breakpoints_set (inferior_thread ()))
1097 /* This is a soft single step. */
1098 record_full_resume_step
= 1;
1101 step
= !insert_single_step_breakpoints (gdbarch
);
1105 /* Make sure the target beneath reports all signals. */
1106 target_pass_signals (0, NULL
);
1108 this->beneath ()->resume (ptid
, step
, signal
);
1111 /* We are about to start executing the inferior (or simulate it),
1112 let's register it with the event loop. */
1113 if (target_can_async_p ())
1117 /* "commit_resume" method for process record target. */
1120 record_full_target::commit_resume ()
1122 if (!RECORD_FULL_IS_REPLAY
)
1123 beneath ()->commit_resume ();
1126 static int record_full_get_sig
= 0;
1128 /* SIGINT signal handler, registered by "wait" method. */
1131 record_full_sig_handler (int signo
)
1134 fprintf_unfiltered (gdb_stdlog
, "Process record: get a signal\n");
1136 /* It will break the running inferior in replay mode. */
1137 record_full_resume_step
= 1;
1139 /* It will let record_full_wait set inferior status to get the signal
1141 record_full_get_sig
= 1;
1144 /* "wait" target method for process record target.
1146 In record mode, the target is always run in singlestep mode
1147 (even when gdb says to continue). The wait method intercepts
1148 the stop events and determines which ones are to be passed on to
1149 gdb. Most stop events are just singlestep events that gdb is not
1150 to know about, so the wait method just records them and keeps
1153 In replay mode, this function emulates the recorded execution log,
1154 one instruction at a time (forward or backward), and determines
1158 record_full_wait_1 (struct target_ops
*ops
,
1159 ptid_t ptid
, struct target_waitstatus
*status
,
1162 scoped_restore restore_operation_disable
1163 = record_full_gdb_operation_disable_set ();
1166 fprintf_unfiltered (gdb_stdlog
,
1167 "Process record: record_full_wait "
1168 "record_full_resume_step = %d, "
1169 "record_full_resumed = %d, direction=%s\n",
1170 record_full_resume_step
, record_full_resumed
,
1171 record_full_execution_dir
== EXEC_FORWARD
1172 ? "forward" : "reverse");
1174 if (!record_full_resumed
)
1176 gdb_assert ((options
& TARGET_WNOHANG
) != 0);
1178 /* No interesting event. */
1179 status
->kind
= TARGET_WAITKIND_IGNORE
;
1180 return minus_one_ptid
;
1183 record_full_get_sig
= 0;
1184 signal (SIGINT
, record_full_sig_handler
);
1186 record_full_stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
1188 if (!RECORD_FULL_IS_REPLAY
&& ops
!= &record_full_core_ops
)
1190 if (record_full_resume_step
)
1192 /* This is a single step. */
1193 return ops
->beneath ()->wait (ptid
, status
, options
);
1197 /* This is not a single step. */
1200 struct gdbarch
*gdbarch
= target_thread_architecture (inferior_ptid
);
1204 ret
= ops
->beneath ()->wait (ptid
, status
, options
);
1205 if (status
->kind
== TARGET_WAITKIND_IGNORE
)
1208 fprintf_unfiltered (gdb_stdlog
,
1209 "Process record: record_full_wait "
1210 "target beneath not done yet\n");
1214 for (thread_info
*tp
: all_non_exited_threads ())
1215 delete_single_step_breakpoints (tp
);
1217 if (record_full_resume_step
)
1220 /* Is this a SIGTRAP? */
1221 if (status
->kind
== TARGET_WAITKIND_STOPPED
1222 && status
->value
.sig
== GDB_SIGNAL_TRAP
)
1224 struct regcache
*regcache
;
1225 enum target_stop_reason
*stop_reason_p
1226 = &record_full_stop_reason
;
1228 /* Yes -- this is likely our single-step finishing,
1229 but check if there's any reason the core would be
1230 interested in the event. */
1232 registers_changed ();
1233 regcache
= get_current_regcache ();
1234 tmp_pc
= regcache_read_pc (regcache
);
1235 const struct address_space
*aspace
= regcache
->aspace ();
1237 if (target_stopped_by_watchpoint ())
1239 /* Always interested in watchpoints. */
1241 else if (record_check_stopped_by_breakpoint (aspace
, tmp_pc
,
1244 /* There is a breakpoint here. Let the core
1249 /* This is a single-step trap. Record the
1250 insn and issue another step.
1251 FIXME: this part can be a random SIGTRAP too.
1252 But GDB cannot handle it. */
1255 if (!record_full_message_wrapper_safe (regcache
,
1258 status
->kind
= TARGET_WAITKIND_STOPPED
;
1259 status
->value
.sig
= GDB_SIGNAL_0
;
1263 if (gdbarch_software_single_step_p (gdbarch
))
1265 /* Try to insert the software single step breakpoint.
1266 If insert success, set step to 0. */
1267 set_executing (inferior_ptid
, 0);
1268 reinit_frame_cache ();
1270 step
= !insert_single_step_breakpoints (gdbarch
);
1272 set_executing (inferior_ptid
, 1);
1276 fprintf_unfiltered (gdb_stdlog
,
1277 "Process record: record_full_wait "
1278 "issuing one more step in the "
1279 "target beneath\n");
1280 ops
->beneath ()->resume (ptid
, step
, GDB_SIGNAL_0
);
1281 ops
->beneath ()->commit_resume ();
1286 /* The inferior is broken by a breakpoint or a signal. */
1295 struct regcache
*regcache
= get_current_regcache ();
1296 struct gdbarch
*gdbarch
= regcache
->arch ();
1297 const struct address_space
*aspace
= regcache
->aspace ();
1298 int continue_flag
= 1;
1299 int first_record_full_end
= 1;
1305 record_full_stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
1306 status
->kind
= TARGET_WAITKIND_STOPPED
;
1308 /* Check breakpoint when forward execute. */
1309 if (execution_direction
== EXEC_FORWARD
)
1311 tmp_pc
= regcache_read_pc (regcache
);
1312 if (record_check_stopped_by_breakpoint (aspace
, tmp_pc
,
1313 &record_full_stop_reason
))
1316 fprintf_unfiltered (gdb_stdlog
,
1317 "Process record: break at %s.\n",
1318 paddress (gdbarch
, tmp_pc
));
1323 /* If GDB is in terminal_inferior mode, it will not get the
1324 signal. And in GDB replay mode, GDB doesn't need to be
1325 in terminal_inferior mode, because inferior will not
1326 executed. Then set it to terminal_ours to make GDB get
1328 target_terminal::ours ();
1330 /* In EXEC_FORWARD mode, record_full_list points to the tail of prev
1332 if (execution_direction
== EXEC_FORWARD
&& record_full_list
->next
)
1333 record_full_list
= record_full_list
->next
;
1335 /* Loop over the record_full_list, looking for the next place to
1339 /* Check for beginning and end of log. */
1340 if (execution_direction
== EXEC_REVERSE
1341 && record_full_list
== &record_full_first
)
1343 /* Hit beginning of record log in reverse. */
1344 status
->kind
= TARGET_WAITKIND_NO_HISTORY
;
1347 if (execution_direction
!= EXEC_REVERSE
1348 && !record_full_list
->next
)
1350 /* Hit end of record log going forward. */
1351 status
->kind
= TARGET_WAITKIND_NO_HISTORY
;
1355 record_full_exec_insn (regcache
, gdbarch
, record_full_list
);
1357 if (record_full_list
->type
== record_full_end
)
1359 if (record_debug
> 1)
1362 "Process record: record_full_end %s to "
1364 host_address_to_string (record_full_list
));
1366 if (first_record_full_end
1367 && execution_direction
== EXEC_REVERSE
)
1369 /* When reverse excute, the first
1370 record_full_end is the part of current
1372 first_record_full_end
= 0;
1376 /* In EXEC_REVERSE mode, this is the
1377 record_full_end of prev instruction. In
1378 EXEC_FORWARD mode, this is the
1379 record_full_end of current instruction. */
1381 if (record_full_resume_step
)
1383 if (record_debug
> 1)
1384 fprintf_unfiltered (gdb_stdlog
,
1385 "Process record: step.\n");
1389 /* check breakpoint */
1390 tmp_pc
= regcache_read_pc (regcache
);
1391 if (record_check_stopped_by_breakpoint
1392 (aspace
, tmp_pc
, &record_full_stop_reason
))
1395 fprintf_unfiltered (gdb_stdlog
,
1396 "Process record: break "
1398 paddress (gdbarch
, tmp_pc
));
1403 if (record_full_stop_reason
1404 == TARGET_STOPPED_BY_WATCHPOINT
)
1407 fprintf_unfiltered (gdb_stdlog
,
1408 "Process record: hit hw "
1412 /* Check target signal */
1413 if (record_full_list
->u
.end
.sigval
!= GDB_SIGNAL_0
)
1414 /* FIXME: better way to check */
1421 if (execution_direction
== EXEC_REVERSE
)
1423 if (record_full_list
->prev
)
1424 record_full_list
= record_full_list
->prev
;
1428 if (record_full_list
->next
)
1429 record_full_list
= record_full_list
->next
;
1433 while (continue_flag
);
1436 if (record_full_get_sig
)
1437 status
->value
.sig
= GDB_SIGNAL_INT
;
1438 else if (record_full_list
->u
.end
.sigval
!= GDB_SIGNAL_0
)
1439 /* FIXME: better way to check */
1440 status
->value
.sig
= record_full_list
->u
.end
.sigval
;
1442 status
->value
.sig
= GDB_SIGNAL_TRAP
;
1444 CATCH (ex
, RETURN_MASK_ALL
)
1446 if (execution_direction
== EXEC_REVERSE
)
1448 if (record_full_list
->next
)
1449 record_full_list
= record_full_list
->next
;
1452 record_full_list
= record_full_list
->prev
;
1454 throw_exception (ex
);
1459 signal (SIGINT
, handle_sigint
);
1461 return inferior_ptid
;
1465 record_full_base_target::wait (ptid_t ptid
, struct target_waitstatus
*status
,
1470 return_ptid
= record_full_wait_1 (this, ptid
, status
, options
);
1471 if (status
->kind
!= TARGET_WAITKIND_IGNORE
)
1473 /* We're reporting a stop. Make sure any spurious
1474 target_wait(WNOHANG) doesn't advance the target until the
1475 core wants us resumed again. */
1476 record_full_resumed
= 0;
1482 record_full_base_target::stopped_by_watchpoint ()
1484 if (RECORD_FULL_IS_REPLAY
)
1485 return record_full_stop_reason
== TARGET_STOPPED_BY_WATCHPOINT
;
1487 return beneath ()->stopped_by_watchpoint ();
1491 record_full_base_target::stopped_data_address (CORE_ADDR
*addr_p
)
1493 if (RECORD_FULL_IS_REPLAY
)
1496 return this->beneath ()->stopped_data_address (addr_p
);
1499 /* The stopped_by_sw_breakpoint method of target record-full. */
1502 record_full_base_target::stopped_by_sw_breakpoint ()
1504 return record_full_stop_reason
== TARGET_STOPPED_BY_SW_BREAKPOINT
;
1507 /* The supports_stopped_by_sw_breakpoint method of target
1511 record_full_base_target::supports_stopped_by_sw_breakpoint ()
1516 /* The stopped_by_hw_breakpoint method of target record-full. */
1519 record_full_base_target::stopped_by_hw_breakpoint ()
1521 return record_full_stop_reason
== TARGET_STOPPED_BY_HW_BREAKPOINT
;
1524 /* The supports_stopped_by_sw_breakpoint method of target
1528 record_full_base_target::supports_stopped_by_hw_breakpoint ()
1533 /* Record registers change (by user or by GDB) to list as an instruction. */
1536 record_full_registers_change (struct regcache
*regcache
, int regnum
)
1538 /* Check record_full_insn_num. */
1539 record_full_check_insn_num ();
1541 record_full_arch_list_head
= NULL
;
1542 record_full_arch_list_tail
= NULL
;
1548 for (i
= 0; i
< gdbarch_num_regs (regcache
->arch ()); i
++)
1550 if (record_full_arch_list_add_reg (regcache
, i
))
1552 record_full_list_release (record_full_arch_list_tail
);
1553 error (_("Process record: failed to record execution log."));
1559 if (record_full_arch_list_add_reg (regcache
, regnum
))
1561 record_full_list_release (record_full_arch_list_tail
);
1562 error (_("Process record: failed to record execution log."));
1565 if (record_full_arch_list_add_end ())
1567 record_full_list_release (record_full_arch_list_tail
);
1568 error (_("Process record: failed to record execution log."));
1570 record_full_list
->next
= record_full_arch_list_head
;
1571 record_full_arch_list_head
->prev
= record_full_list
;
1572 record_full_list
= record_full_arch_list_tail
;
1574 if (record_full_insn_num
== record_full_insn_max_num
)
1575 record_full_list_release_first ();
1577 record_full_insn_num
++;
1580 /* "store_registers" method for process record target. */
1583 record_full_target::store_registers (struct regcache
*regcache
, int regno
)
1585 if (!record_full_gdb_operation_disable
)
1587 if (RECORD_FULL_IS_REPLAY
)
1591 /* Let user choose if he wants to write register or not. */
1594 query (_("Because GDB is in replay mode, changing the "
1595 "value of a register will make the execution "
1596 "log unusable from this point onward. "
1597 "Change all registers?"));
1600 query (_("Because GDB is in replay mode, changing the value "
1601 "of a register will make the execution log unusable "
1602 "from this point onward. Change register %s?"),
1603 gdbarch_register_name (regcache
->arch (),
1608 /* Invalidate the value of regcache that was set in function
1609 "regcache_raw_write". */
1615 i
< gdbarch_num_regs (regcache
->arch ());
1617 regcache
->invalidate (i
);
1620 regcache
->invalidate (regno
);
1622 error (_("Process record canceled the operation."));
1625 /* Destroy the record from here forward. */
1626 record_full_list_release_following (record_full_list
);
1629 record_full_registers_change (regcache
, regno
);
1631 this->beneath ()->store_registers (regcache
, regno
);
1634 /* "xfer_partial" method. Behavior is conditional on
1635 RECORD_FULL_IS_REPLAY.
1636 In replay mode, we cannot write memory unles we are willing to
1637 invalidate the record/replay log from this point forward. */
1639 enum target_xfer_status
1640 record_full_target::xfer_partial (enum target_object object
,
1641 const char *annex
, gdb_byte
*readbuf
,
1642 const gdb_byte
*writebuf
, ULONGEST offset
,
1643 ULONGEST len
, ULONGEST
*xfered_len
)
1645 if (!record_full_gdb_operation_disable
1646 && (object
== TARGET_OBJECT_MEMORY
1647 || object
== TARGET_OBJECT_RAW_MEMORY
) && writebuf
)
1649 if (RECORD_FULL_IS_REPLAY
)
1651 /* Let user choose if he wants to write memory or not. */
1652 if (!query (_("Because GDB is in replay mode, writing to memory "
1653 "will make the execution log unusable from this "
1654 "point onward. Write memory at address %s?"),
1655 paddress (target_gdbarch (), offset
)))
1656 error (_("Process record canceled the operation."));
1658 /* Destroy the record from here forward. */
1659 record_full_list_release_following (record_full_list
);
1662 /* Check record_full_insn_num */
1663 record_full_check_insn_num ();
1665 /* Record registers change to list as an instruction. */
1666 record_full_arch_list_head
= NULL
;
1667 record_full_arch_list_tail
= NULL
;
1668 if (record_full_arch_list_add_mem (offset
, len
))
1670 record_full_list_release (record_full_arch_list_tail
);
1672 fprintf_unfiltered (gdb_stdlog
,
1673 "Process record: failed to record "
1675 return TARGET_XFER_E_IO
;
1677 if (record_full_arch_list_add_end ())
1679 record_full_list_release (record_full_arch_list_tail
);
1681 fprintf_unfiltered (gdb_stdlog
,
1682 "Process record: failed to record "
1684 return TARGET_XFER_E_IO
;
1686 record_full_list
->next
= record_full_arch_list_head
;
1687 record_full_arch_list_head
->prev
= record_full_list
;
1688 record_full_list
= record_full_arch_list_tail
;
1690 if (record_full_insn_num
== record_full_insn_max_num
)
1691 record_full_list_release_first ();
1693 record_full_insn_num
++;
1696 return this->beneath ()->xfer_partial (object
, annex
, readbuf
, writebuf
,
1697 offset
, len
, xfered_len
);
1700 /* This structure represents a breakpoint inserted while the record
1701 target is active. We use this to know when to install/remove
1702 breakpoints in/from the target beneath. For example, a breakpoint
1703 may be inserted while recording, but removed when not replaying nor
1704 recording. In that case, the breakpoint had not been inserted on
1705 the target beneath, so we should not try to remove it there. */
1707 struct record_full_breakpoint
1709 record_full_breakpoint (struct address_space
*address_space_
,
1711 bool in_target_beneath_
)
1712 : address_space (address_space_
),
1714 in_target_beneath (in_target_beneath_
)
1718 /* The address and address space the breakpoint was set at. */
1719 struct address_space
*address_space
;
1722 /* True when the breakpoint has been also installed in the target
1723 beneath. This will be false for breakpoints set during replay or
1725 bool in_target_beneath
;
1728 /* The list of breakpoints inserted while the record target is
1730 static std::vector
<record_full_breakpoint
> record_full_breakpoints
;
1733 record_full_sync_record_breakpoints (struct bp_location
*loc
, void *data
)
1735 if (loc
->loc_type
!= bp_loc_software_breakpoint
)
1740 record_full_breakpoints
.emplace_back
1741 (loc
->target_info
.placed_address_space
,
1742 loc
->target_info
.placed_address
,
1747 /* Sync existing breakpoints to record_full_breakpoints. */
1750 record_full_init_record_breakpoints (void)
1752 record_full_breakpoints
.clear ();
1754 iterate_over_bp_locations (record_full_sync_record_breakpoints
);
1757 /* Behavior is conditional on RECORD_FULL_IS_REPLAY. We will not actually
1758 insert or remove breakpoints in the real target when replaying, nor
1762 record_full_target::insert_breakpoint (struct gdbarch
*gdbarch
,
1763 struct bp_target_info
*bp_tgt
)
1765 bool in_target_beneath
= false;
1767 if (!RECORD_FULL_IS_REPLAY
)
1769 /* When recording, we currently always single-step, so we don't
1770 really need to install regular breakpoints in the inferior.
1771 However, we do have to insert software single-step
1772 breakpoints, in case the target can't hardware step. To keep
1773 things simple, we always insert. */
1775 scoped_restore restore_operation_disable
1776 = record_full_gdb_operation_disable_set ();
1778 int ret
= this->beneath ()->insert_breakpoint (gdbarch
, bp_tgt
);
1782 in_target_beneath
= true;
1785 /* Use the existing entries if found in order to avoid duplication
1786 in record_full_breakpoints. */
1788 for (const record_full_breakpoint
&bp
: record_full_breakpoints
)
1790 if (bp
.addr
== bp_tgt
->placed_address
1791 && bp
.address_space
== bp_tgt
->placed_address_space
)
1793 gdb_assert (bp
.in_target_beneath
== in_target_beneath
);
1798 record_full_breakpoints
.emplace_back (bp_tgt
->placed_address_space
,
1799 bp_tgt
->placed_address
,
1804 /* "remove_breakpoint" method for process record target. */
1807 record_full_target::remove_breakpoint (struct gdbarch
*gdbarch
,
1808 struct bp_target_info
*bp_tgt
,
1809 enum remove_bp_reason reason
)
1811 for (auto iter
= record_full_breakpoints
.begin ();
1812 iter
!= record_full_breakpoints
.end ();
1815 struct record_full_breakpoint
&bp
= *iter
;
1817 if (bp
.addr
== bp_tgt
->placed_address
1818 && bp
.address_space
== bp_tgt
->placed_address_space
)
1820 if (bp
.in_target_beneath
)
1822 scoped_restore restore_operation_disable
1823 = record_full_gdb_operation_disable_set ();
1825 int ret
= this->beneath ()->remove_breakpoint (gdbarch
, bp_tgt
,
1831 if (reason
== REMOVE_BREAKPOINT
)
1832 unordered_remove (record_full_breakpoints
, iter
);
1837 gdb_assert_not_reached ("removing unknown breakpoint");
1840 /* "can_execute_reverse" method for process record target. */
1843 record_full_base_target::can_execute_reverse ()
1848 /* "get_bookmark" method for process record and prec over core. */
1851 record_full_base_target::get_bookmark (const char *args
, int from_tty
)
1855 /* Return stringified form of instruction count. */
1856 if (record_full_list
&& record_full_list
->type
== record_full_end
)
1857 ret
= xstrdup (pulongest (record_full_list
->u
.end
.insn_num
));
1862 fprintf_unfiltered (gdb_stdlog
,
1863 "record_full_get_bookmark returns %s\n", ret
);
1865 fprintf_unfiltered (gdb_stdlog
,
1866 "record_full_get_bookmark returns NULL\n");
1868 return (gdb_byte
*) ret
;
1871 /* "goto_bookmark" method for process record and prec over core. */
1874 record_full_base_target::goto_bookmark (const gdb_byte
*raw_bookmark
,
1877 const char *bookmark
= (const char *) raw_bookmark
;
1880 fprintf_unfiltered (gdb_stdlog
,
1881 "record_full_goto_bookmark receives %s\n", bookmark
);
1883 std::string name_holder
;
1884 if (bookmark
[0] == '\'' || bookmark
[0] == '\"')
1886 if (bookmark
[strlen (bookmark
) - 1] != bookmark
[0])
1887 error (_("Unbalanced quotes: %s"), bookmark
);
1889 name_holder
= std::string (bookmark
+ 1, strlen (bookmark
) - 2);
1890 bookmark
= name_holder
.c_str ();
1893 record_goto (bookmark
);
1896 enum exec_direction_kind
1897 record_full_base_target::execution_direction ()
1899 return record_full_execution_dir
;
1902 /* The record_method method of target record-full. */
1905 record_full_base_target::record_method (ptid_t ptid
)
1907 return RECORD_METHOD_FULL
;
1911 record_full_base_target::info_record ()
1913 struct record_full_entry
*p
;
1915 if (RECORD_FULL_IS_REPLAY
)
1916 printf_filtered (_("Replay mode:\n"));
1918 printf_filtered (_("Record mode:\n"));
1920 /* Find entry for first actual instruction in the log. */
1921 for (p
= record_full_first
.next
;
1922 p
!= NULL
&& p
->type
!= record_full_end
;
1926 /* Do we have a log at all? */
1927 if (p
!= NULL
&& p
->type
== record_full_end
)
1929 /* Display instruction number for first instruction in the log. */
1930 printf_filtered (_("Lowest recorded instruction number is %s.\n"),
1931 pulongest (p
->u
.end
.insn_num
));
1933 /* If in replay mode, display where we are in the log. */
1934 if (RECORD_FULL_IS_REPLAY
)
1935 printf_filtered (_("Current instruction number is %s.\n"),
1936 pulongest (record_full_list
->u
.end
.insn_num
));
1938 /* Display instruction number for last instruction in the log. */
1939 printf_filtered (_("Highest recorded instruction number is %s.\n"),
1940 pulongest (record_full_insn_count
));
1942 /* Display log count. */
1943 printf_filtered (_("Log contains %u instructions.\n"),
1944 record_full_insn_num
);
1947 printf_filtered (_("No instructions have been logged.\n"));
1949 /* Display max log size. */
1950 printf_filtered (_("Max logged instructions is %u.\n"),
1951 record_full_insn_max_num
);
1955 record_full_base_target::supports_delete_record ()
1960 /* The "delete_record" target method. */
1963 record_full_base_target::delete_record ()
1965 record_full_list_release_following (record_full_list
);
1968 /* The "record_is_replaying" target method. */
1971 record_full_base_target::record_is_replaying (ptid_t ptid
)
1973 return RECORD_FULL_IS_REPLAY
;
1976 /* The "record_will_replay" target method. */
1979 record_full_base_target::record_will_replay (ptid_t ptid
, int dir
)
1981 /* We can currently only record when executing forwards. Should we be able
1982 to record when executing backwards on targets that support reverse
1983 execution, this needs to be changed. */
1985 return RECORD_FULL_IS_REPLAY
|| dir
== EXEC_REVERSE
;
1988 /* Go to a specific entry. */
1991 record_full_goto_entry (struct record_full_entry
*p
)
1994 error (_("Target insn not found."));
1995 else if (p
== record_full_list
)
1996 error (_("Already at target insn."));
1997 else if (p
->u
.end
.insn_num
> record_full_list
->u
.end
.insn_num
)
1999 printf_filtered (_("Go forward to insn number %s\n"),
2000 pulongest (p
->u
.end
.insn_num
));
2001 record_full_goto_insn (p
, EXEC_FORWARD
);
2005 printf_filtered (_("Go backward to insn number %s\n"),
2006 pulongest (p
->u
.end
.insn_num
));
2007 record_full_goto_insn (p
, EXEC_REVERSE
);
2010 registers_changed ();
2011 reinit_frame_cache ();
2012 inferior_thread ()->suspend
.stop_pc
2013 = regcache_read_pc (get_current_regcache ());
2014 print_stack_frame (get_selected_frame (NULL
), 1, SRC_AND_LOC
, 1);
2017 /* The "goto_record_begin" target method. */
2020 record_full_base_target::goto_record_begin ()
2022 struct record_full_entry
*p
= NULL
;
2024 for (p
= &record_full_first
; p
!= NULL
; p
= p
->next
)
2025 if (p
->type
== record_full_end
)
2028 record_full_goto_entry (p
);
2031 /* The "goto_record_end" target method. */
2034 record_full_base_target::goto_record_end ()
2036 struct record_full_entry
*p
= NULL
;
2038 for (p
= record_full_list
; p
->next
!= NULL
; p
= p
->next
)
2040 for (; p
!= NULL
; p
= p
->prev
)
2041 if (p
->type
== record_full_end
)
2044 record_full_goto_entry (p
);
2047 /* The "goto_record" target method. */
2050 record_full_base_target::goto_record (ULONGEST target_insn
)
2052 struct record_full_entry
*p
= NULL
;
2054 for (p
= &record_full_first
; p
!= NULL
; p
= p
->next
)
2055 if (p
->type
== record_full_end
&& p
->u
.end
.insn_num
== target_insn
)
2058 record_full_goto_entry (p
);
2061 /* The "record_stop_replaying" target method. */
2064 record_full_base_target::record_stop_replaying ()
2069 /* "resume" method for prec over corefile. */
2072 record_full_core_target::resume (ptid_t ptid
, int step
,
2073 enum gdb_signal signal
)
2075 record_full_resume_step
= step
;
2076 record_full_resumed
= 1;
2077 record_full_execution_dir
= ::execution_direction
;
2079 /* We are about to start executing the inferior (or simulate it),
2080 let's register it with the event loop. */
2081 if (target_can_async_p ())
2085 /* "kill" method for prec over corefile. */
2088 record_full_core_target::kill ()
2091 fprintf_unfiltered (gdb_stdlog
, "Process record: record_full_core_kill\n");
2093 unpush_target (this);
2096 /* "fetch_registers" method for prec over corefile. */
2099 record_full_core_target::fetch_registers (struct regcache
*regcache
,
2104 int num
= gdbarch_num_regs (regcache
->arch ());
2107 for (i
= 0; i
< num
; i
++)
2108 regcache
->raw_supply (i
, *record_full_core_regbuf
);
2111 regcache
->raw_supply (regno
, *record_full_core_regbuf
);
2114 /* "prepare_to_store" method for prec over corefile. */
2117 record_full_core_target::prepare_to_store (struct regcache
*regcache
)
2121 /* "store_registers" method for prec over corefile. */
2124 record_full_core_target::store_registers (struct regcache
*regcache
,
2127 if (record_full_gdb_operation_disable
)
2128 record_full_core_regbuf
->raw_supply (regno
, *regcache
);
2130 error (_("You can't do that without a process to debug."));
2133 /* "xfer_partial" method for prec over corefile. */
2135 enum target_xfer_status
2136 record_full_core_target::xfer_partial (enum target_object object
,
2137 const char *annex
, gdb_byte
*readbuf
,
2138 const gdb_byte
*writebuf
, ULONGEST offset
,
2139 ULONGEST len
, ULONGEST
*xfered_len
)
2141 if (object
== TARGET_OBJECT_MEMORY
)
2143 if (record_full_gdb_operation_disable
|| !writebuf
)
2145 struct target_section
*p
;
2147 for (p
= record_full_core_start
; p
< record_full_core_end
; p
++)
2149 if (offset
>= p
->addr
)
2151 struct record_full_core_buf_entry
*entry
;
2152 ULONGEST sec_offset
;
2154 if (offset
>= p
->endaddr
)
2157 if (offset
+ len
> p
->endaddr
)
2158 len
= p
->endaddr
- offset
;
2160 sec_offset
= offset
- p
->addr
;
2162 /* Read readbuf or write writebuf p, offset, len. */
2164 if (p
->the_bfd_section
->flags
& SEC_CONSTRUCTOR
2165 || (p
->the_bfd_section
->flags
& SEC_HAS_CONTENTS
) == 0)
2168 memset (readbuf
, 0, len
);
2171 return TARGET_XFER_OK
;
2173 /* Get record_full_core_buf_entry. */
2174 for (entry
= record_full_core_buf_list
; entry
;
2175 entry
= entry
->prev
)
2182 /* Add a new entry. */
2183 entry
= XNEW (struct record_full_core_buf_entry
);
2185 if (!bfd_malloc_and_get_section
2186 (p
->the_bfd_section
->owner
,
2191 return TARGET_XFER_EOF
;
2193 entry
->prev
= record_full_core_buf_list
;
2194 record_full_core_buf_list
= entry
;
2197 memcpy (entry
->buf
+ sec_offset
, writebuf
,
2203 return this->beneath ()->xfer_partial (object
, annex
,
2208 memcpy (readbuf
, entry
->buf
+ sec_offset
,
2213 return TARGET_XFER_OK
;
2217 return TARGET_XFER_E_IO
;
2220 error (_("You can't do that without a process to debug."));
2223 return this->beneath ()->xfer_partial (object
, annex
,
2224 readbuf
, writebuf
, offset
, len
,
2228 /* "insert_breakpoint" method for prec over corefile. */
2231 record_full_core_target::insert_breakpoint (struct gdbarch
*gdbarch
,
2232 struct bp_target_info
*bp_tgt
)
2237 /* "remove_breakpoint" method for prec over corefile. */
2240 record_full_core_target::remove_breakpoint (struct gdbarch
*gdbarch
,
2241 struct bp_target_info
*bp_tgt
,
2242 enum remove_bp_reason reason
)
2247 /* "has_execution" method for prec over corefile. */
2250 record_full_core_target::has_execution (ptid_t the_ptid
)
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 /* Restore the execution log from a core_bfd file. */
2334 record_full_restore (void)
2337 struct record_full_entry
*rec
;
2341 struct regcache
*regcache
;
2343 /* We restore the execution log from the open core bfd,
2345 if (core_bfd
== NULL
)
2348 /* "record_full_restore" can only be called when record list is empty. */
2349 gdb_assert (record_full_first
.next
== NULL
);
2352 fprintf_unfiltered (gdb_stdlog
, "Restoring recording from core file.\n");
2354 /* Now need to find our special note section. */
2355 osec
= bfd_get_section_by_name (core_bfd
, "null0");
2357 fprintf_unfiltered (gdb_stdlog
, "Find precord section %s.\n",
2358 osec
? "succeeded" : "failed");
2361 osec_size
= bfd_section_size (core_bfd
, osec
);
2363 fprintf_unfiltered (gdb_stdlog
, "%s", bfd_section_name (core_bfd
, osec
));
2365 /* Check the magic code. */
2366 bfdcore_read (core_bfd
, osec
, &magic
, sizeof (magic
), &bfd_offset
);
2367 if (magic
!= RECORD_FULL_FILE_MAGIC
)
2368 error (_("Version mis-match or file format error in core file %s."),
2369 bfd_get_filename (core_bfd
));
2371 fprintf_unfiltered (gdb_stdlog
,
2372 " Reading 4-byte magic cookie "
2373 "RECORD_FULL_FILE_MAGIC (0x%s)\n",
2374 phex_nz (netorder32 (magic
), 4));
2376 /* Restore the entries in recfd into record_full_arch_list_head and
2377 record_full_arch_list_tail. */
2378 record_full_arch_list_head
= NULL
;
2379 record_full_arch_list_tail
= NULL
;
2380 record_full_insn_num
= 0;
2384 regcache
= get_current_regcache ();
2389 uint32_t regnum
, len
, signal
, count
;
2392 /* We are finished when offset reaches osec_size. */
2393 if (bfd_offset
>= osec_size
)
2395 bfdcore_read (core_bfd
, osec
, &rectype
, sizeof (rectype
), &bfd_offset
);
2399 case record_full_reg
: /* reg */
2400 /* Get register number to regnum. */
2401 bfdcore_read (core_bfd
, osec
, ®num
,
2402 sizeof (regnum
), &bfd_offset
);
2403 regnum
= netorder32 (regnum
);
2405 rec
= record_full_reg_alloc (regcache
, regnum
);
2408 bfdcore_read (core_bfd
, osec
, record_full_get_loc (rec
),
2409 rec
->u
.reg
.len
, &bfd_offset
);
2412 fprintf_unfiltered (gdb_stdlog
,
2413 " Reading register %d (1 "
2414 "plus %lu plus %d bytes)\n",
2416 (unsigned long) sizeof (regnum
),
2420 case record_full_mem
: /* mem */
2422 bfdcore_read (core_bfd
, osec
, &len
,
2423 sizeof (len
), &bfd_offset
);
2424 len
= netorder32 (len
);
2427 bfdcore_read (core_bfd
, osec
, &addr
,
2428 sizeof (addr
), &bfd_offset
);
2429 addr
= netorder64 (addr
);
2431 rec
= record_full_mem_alloc (addr
, len
);
2434 bfdcore_read (core_bfd
, osec
, record_full_get_loc (rec
),
2435 rec
->u
.mem
.len
, &bfd_offset
);
2438 fprintf_unfiltered (gdb_stdlog
,
2439 " Reading memory %s (1 plus "
2440 "%lu plus %lu plus %d bytes)\n",
2441 paddress (get_current_arch (),
2443 (unsigned long) sizeof (addr
),
2444 (unsigned long) sizeof (len
),
2448 case record_full_end
: /* end */
2449 rec
= record_full_end_alloc ();
2450 record_full_insn_num
++;
2452 /* Get signal value. */
2453 bfdcore_read (core_bfd
, osec
, &signal
,
2454 sizeof (signal
), &bfd_offset
);
2455 signal
= netorder32 (signal
);
2456 rec
->u
.end
.sigval
= (enum gdb_signal
) signal
;
2458 /* Get insn count. */
2459 bfdcore_read (core_bfd
, osec
, &count
,
2460 sizeof (count
), &bfd_offset
);
2461 count
= netorder32 (count
);
2462 rec
->u
.end
.insn_num
= count
;
2463 record_full_insn_count
= count
+ 1;
2465 fprintf_unfiltered (gdb_stdlog
,
2466 " Reading record_full_end (1 + "
2467 "%lu + %lu bytes), offset == %s\n",
2468 (unsigned long) sizeof (signal
),
2469 (unsigned long) sizeof (count
),
2470 paddress (get_current_arch (),
2475 error (_("Bad entry type in core file %s."),
2476 bfd_get_filename (core_bfd
));
2480 /* Add rec to record arch list. */
2481 record_full_arch_list_add (rec
);
2484 CATCH (ex
, RETURN_MASK_ALL
)
2486 record_full_list_release (record_full_arch_list_tail
);
2487 throw_exception (ex
);
2491 /* Add record_full_arch_list_head to the end of record list. */
2492 record_full_first
.next
= record_full_arch_list_head
;
2493 record_full_arch_list_head
->prev
= &record_full_first
;
2494 record_full_arch_list_tail
->next
= NULL
;
2495 record_full_list
= &record_full_first
;
2497 /* Update record_full_insn_max_num. */
2498 if (record_full_insn_num
> record_full_insn_max_num
)
2500 record_full_insn_max_num
= record_full_insn_num
;
2501 warning (_("Auto increase record/replay buffer limit to %u."),
2502 record_full_insn_max_num
);
2506 printf_filtered (_("Restored records from core file %s.\n"),
2507 bfd_get_filename (core_bfd
));
2509 print_stack_frame (get_selected_frame (NULL
), 1, SRC_AND_LOC
, 1);
2512 /* bfdcore_write -- write bytes into a core file section. */
2515 bfdcore_write (bfd
*obfd
, asection
*osec
, void *buf
, int len
, int *offset
)
2517 int ret
= bfd_set_section_contents (obfd
, osec
, buf
, *offset
, len
);
2522 error (_("Failed to write %d bytes to core file %s ('%s')."),
2523 len
, bfd_get_filename (obfd
),
2524 bfd_errmsg (bfd_get_error ()));
2527 /* Restore the execution log from a file. We use a modified elf
2528 corefile format, with an extra section for our data. */
2531 cmd_record_full_restore (const char *args
, int from_tty
)
2533 core_file_command (args
, from_tty
);
2534 record_full_open (args
, from_tty
);
2537 /* Save the execution log to a file. We use a modified elf corefile
2538 format, with an extra section for our data. */
2541 record_full_base_target::save_record (const char *recfilename
)
2543 struct record_full_entry
*cur_record_full_list
;
2545 struct regcache
*regcache
;
2546 struct gdbarch
*gdbarch
;
2548 asection
*osec
= NULL
;
2551 /* Open the save file. */
2553 fprintf_unfiltered (gdb_stdlog
, "Saving execution log to core file '%s'\n",
2556 /* Open the output file. */
2557 gdb_bfd_ref_ptr
obfd (create_gcore_bfd (recfilename
));
2559 /* Arrange to remove the output file on failure. */
2560 gdb::unlinker
unlink_file (recfilename
);
2562 /* Save the current record entry to "cur_record_full_list". */
2563 cur_record_full_list
= record_full_list
;
2565 /* Get the values of regcache and gdbarch. */
2566 regcache
= get_current_regcache ();
2567 gdbarch
= regcache
->arch ();
2569 /* Disable the GDB operation record. */
2570 scoped_restore restore_operation_disable
2571 = record_full_gdb_operation_disable_set ();
2573 /* Reverse execute to the begin of record list. */
2576 /* Check for beginning and end of log. */
2577 if (record_full_list
== &record_full_first
)
2580 record_full_exec_insn (regcache
, gdbarch
, record_full_list
);
2582 if (record_full_list
->prev
)
2583 record_full_list
= record_full_list
->prev
;
2586 /* Compute the size needed for the extra bfd section. */
2587 save_size
= 4; /* magic cookie */
2588 for (record_full_list
= record_full_first
.next
; record_full_list
;
2589 record_full_list
= record_full_list
->next
)
2590 switch (record_full_list
->type
)
2592 case record_full_end
:
2593 save_size
+= 1 + 4 + 4;
2595 case record_full_reg
:
2596 save_size
+= 1 + 4 + record_full_list
->u
.reg
.len
;
2598 case record_full_mem
:
2599 save_size
+= 1 + 4 + 8 + record_full_list
->u
.mem
.len
;
2603 /* Make the new bfd section. */
2604 osec
= bfd_make_section_anyway_with_flags (obfd
.get (), "precord",
2608 error (_("Failed to create 'precord' section for corefile %s: %s"),
2610 bfd_errmsg (bfd_get_error ()));
2611 bfd_set_section_size (obfd
.get (), osec
, save_size
);
2612 bfd_set_section_vma (obfd
.get (), osec
, 0);
2613 bfd_set_section_alignment (obfd
.get (), osec
, 0);
2614 bfd_section_lma (obfd
.get (), osec
) = 0;
2616 /* Save corefile state. */
2617 write_gcore_file (obfd
.get ());
2619 /* Write out the record log. */
2620 /* Write the magic code. */
2621 magic
= RECORD_FULL_FILE_MAGIC
;
2623 fprintf_unfiltered (gdb_stdlog
,
2624 " Writing 4-byte magic cookie "
2625 "RECORD_FULL_FILE_MAGIC (0x%s)\n",
2626 phex_nz (magic
, 4));
2627 bfdcore_write (obfd
.get (), osec
, &magic
, sizeof (magic
), &bfd_offset
);
2629 /* Save the entries to recfd and forward execute to the end of
2631 record_full_list
= &record_full_first
;
2635 if (record_full_list
!= &record_full_first
)
2638 uint32_t regnum
, len
, signal
, count
;
2641 type
= record_full_list
->type
;
2642 bfdcore_write (obfd
.get (), osec
, &type
, sizeof (type
), &bfd_offset
);
2644 switch (record_full_list
->type
)
2646 case record_full_reg
: /* reg */
2648 fprintf_unfiltered (gdb_stdlog
,
2649 " Writing register %d (1 "
2650 "plus %lu plus %d bytes)\n",
2651 record_full_list
->u
.reg
.num
,
2652 (unsigned long) sizeof (regnum
),
2653 record_full_list
->u
.reg
.len
);
2656 regnum
= netorder32 (record_full_list
->u
.reg
.num
);
2657 bfdcore_write (obfd
.get (), osec
, ®num
,
2658 sizeof (regnum
), &bfd_offset
);
2661 bfdcore_write (obfd
.get (), osec
,
2662 record_full_get_loc (record_full_list
),
2663 record_full_list
->u
.reg
.len
, &bfd_offset
);
2666 case record_full_mem
: /* mem */
2668 fprintf_unfiltered (gdb_stdlog
,
2669 " Writing memory %s (1 plus "
2670 "%lu plus %lu plus %d bytes)\n",
2672 record_full_list
->u
.mem
.addr
),
2673 (unsigned long) sizeof (addr
),
2674 (unsigned long) sizeof (len
),
2675 record_full_list
->u
.mem
.len
);
2678 len
= netorder32 (record_full_list
->u
.mem
.len
);
2679 bfdcore_write (obfd
.get (), osec
, &len
, sizeof (len
),
2682 /* Write memaddr. */
2683 addr
= netorder64 (record_full_list
->u
.mem
.addr
);
2684 bfdcore_write (obfd
.get (), osec
, &addr
,
2685 sizeof (addr
), &bfd_offset
);
2688 bfdcore_write (obfd
.get (), osec
,
2689 record_full_get_loc (record_full_list
),
2690 record_full_list
->u
.mem
.len
, &bfd_offset
);
2693 case record_full_end
:
2695 fprintf_unfiltered (gdb_stdlog
,
2696 " Writing record_full_end (1 + "
2697 "%lu + %lu bytes)\n",
2698 (unsigned long) sizeof (signal
),
2699 (unsigned long) sizeof (count
));
2700 /* Write signal value. */
2701 signal
= netorder32 (record_full_list
->u
.end
.sigval
);
2702 bfdcore_write (obfd
.get (), osec
, &signal
,
2703 sizeof (signal
), &bfd_offset
);
2705 /* Write insn count. */
2706 count
= netorder32 (record_full_list
->u
.end
.insn_num
);
2707 bfdcore_write (obfd
.get (), osec
, &count
,
2708 sizeof (count
), &bfd_offset
);
2713 /* Execute entry. */
2714 record_full_exec_insn (regcache
, gdbarch
, record_full_list
);
2716 if (record_full_list
->next
)
2717 record_full_list
= record_full_list
->next
;
2722 /* Reverse execute to cur_record_full_list. */
2725 /* Check for beginning and end of log. */
2726 if (record_full_list
== cur_record_full_list
)
2729 record_full_exec_insn (regcache
, gdbarch
, record_full_list
);
2731 if (record_full_list
->prev
)
2732 record_full_list
= record_full_list
->prev
;
2735 unlink_file
.keep ();
2738 printf_filtered (_("Saved core file %s with execution log.\n"),
2742 /* record_full_goto_insn -- rewind the record log (forward or backward,
2743 depending on DIR) to the given entry, changing the program state
2747 record_full_goto_insn (struct record_full_entry
*entry
,
2748 enum exec_direction_kind dir
)
2750 scoped_restore restore_operation_disable
2751 = record_full_gdb_operation_disable_set ();
2752 struct regcache
*regcache
= get_current_regcache ();
2753 struct gdbarch
*gdbarch
= regcache
->arch ();
2755 /* Assume everything is valid: we will hit the entry,
2756 and we will not hit the end of the recording. */
2758 if (dir
== EXEC_FORWARD
)
2759 record_full_list
= record_full_list
->next
;
2763 record_full_exec_insn (regcache
, gdbarch
, record_full_list
);
2764 if (dir
== EXEC_REVERSE
)
2765 record_full_list
= record_full_list
->prev
;
2767 record_full_list
= record_full_list
->next
;
2768 } while (record_full_list
!= entry
);
2771 /* Alias for "target record-full". */
2774 cmd_record_full_start (const char *args
, int from_tty
)
2776 execute_command ("target record-full", from_tty
);
2780 set_record_full_insn_max_num (const char *args
, int from_tty
,
2781 struct cmd_list_element
*c
)
2783 if (record_full_insn_num
> record_full_insn_max_num
)
2785 /* Count down record_full_insn_num while releasing records from list. */
2786 while (record_full_insn_num
> record_full_insn_max_num
)
2788 record_full_list_release_first ();
2789 record_full_insn_num
--;
2794 /* The "set record full" command. */
2797 set_record_full_command (const char *args
, int from_tty
)
2799 printf_unfiltered (_("\"set record full\" must be followed "
2800 "by an appropriate subcommand.\n"));
2801 help_list (set_record_full_cmdlist
, "set record full ", all_commands
,
2805 /* The "show record full" command. */
2808 show_record_full_command (const char *args
, int from_tty
)
2810 cmd_show_list (show_record_full_cmdlist
, from_tty
, "");
2814 _initialize_record_full (void)
2816 struct cmd_list_element
*c
;
2818 /* Init record_full_first. */
2819 record_full_first
.prev
= NULL
;
2820 record_full_first
.next
= NULL
;
2821 record_full_first
.type
= record_full_end
;
2823 add_target (record_full_target_info
, record_full_open
);
2824 add_deprecated_target_alias (record_full_target_info
, "record");
2825 add_target (record_full_core_target_info
, record_full_open
);
2827 add_prefix_cmd ("full", class_obscure
, cmd_record_full_start
,
2828 _("Start full execution recording."), &record_full_cmdlist
,
2829 "record full ", 0, &record_cmdlist
);
2831 c
= add_cmd ("restore", class_obscure
, cmd_record_full_restore
,
2832 _("Restore the execution log from a file.\n\
2833 Argument is filename. File must be created with 'record save'."),
2834 &record_full_cmdlist
);
2835 set_cmd_completer (c
, filename_completer
);
2837 /* Deprecate the old version without "full" prefix. */
2838 c
= add_alias_cmd ("restore", "full restore", class_obscure
, 1,
2840 set_cmd_completer (c
, filename_completer
);
2841 deprecate_cmd (c
, "record full restore");
2843 add_prefix_cmd ("full", class_support
, set_record_full_command
,
2844 _("Set record options"), &set_record_full_cmdlist
,
2845 "set record full ", 0, &set_record_cmdlist
);
2847 add_prefix_cmd ("full", class_support
, show_record_full_command
,
2848 _("Show record options"), &show_record_full_cmdlist
,
2849 "show record full ", 0, &show_record_cmdlist
);
2851 /* Record instructions number limit command. */
2852 add_setshow_boolean_cmd ("stop-at-limit", no_class
,
2853 &record_full_stop_at_limit
, _("\
2854 Set whether record/replay stops when record/replay buffer becomes full."), _("\
2855 Show whether record/replay stops when record/replay buffer becomes full."),
2856 _("Default is ON.\n\
2857 When ON, if the record/replay buffer becomes full, ask user what to do.\n\
2858 When OFF, if the record/replay buffer becomes full,\n\
2859 delete the oldest recorded instruction to make room for each new one."),
2861 &set_record_full_cmdlist
, &show_record_full_cmdlist
);
2863 c
= add_alias_cmd ("stop-at-limit", "full stop-at-limit", no_class
, 1,
2864 &set_record_cmdlist
);
2865 deprecate_cmd (c
, "set record full stop-at-limit");
2867 c
= add_alias_cmd ("stop-at-limit", "full stop-at-limit", no_class
, 1,
2868 &show_record_cmdlist
);
2869 deprecate_cmd (c
, "show record full stop-at-limit");
2871 add_setshow_uinteger_cmd ("insn-number-max", no_class
,
2872 &record_full_insn_max_num
,
2873 _("Set record/replay buffer limit."),
2874 _("Show record/replay buffer limit."), _("\
2875 Set the maximum number of instructions to be stored in the\n\
2876 record/replay buffer. A value of either \"unlimited\" or zero means no\n\
2877 limit. Default is 200000."),
2878 set_record_full_insn_max_num
,
2879 NULL
, &set_record_full_cmdlist
,
2880 &show_record_full_cmdlist
);
2882 c
= add_alias_cmd ("insn-number-max", "full insn-number-max", no_class
, 1,
2883 &set_record_cmdlist
);
2884 deprecate_cmd (c
, "set record full insn-number-max");
2886 c
= add_alias_cmd ("insn-number-max", "full insn-number-max", no_class
, 1,
2887 &show_record_cmdlist
);
2888 deprecate_cmd (c
, "show record full insn-number-max");
2890 add_setshow_boolean_cmd ("memory-query", no_class
,
2891 &record_full_memory_query
, _("\
2892 Set whether query if PREC cannot record memory change of next instruction."),
2894 Show whether query if PREC cannot record memory change of next instruction."),
2897 When ON, query if PREC cannot record memory change of next instruction."),
2899 &set_record_full_cmdlist
,
2900 &show_record_full_cmdlist
);
2902 c
= add_alias_cmd ("memory-query", "full memory-query", no_class
, 1,
2903 &set_record_cmdlist
);
2904 deprecate_cmd (c
, "set record full memory-query");
2906 c
= add_alias_cmd ("memory-query", "full memory-query", no_class
, 1,
2907 &show_record_cmdlist
);
2908 deprecate_cmd (c
, "show record full memory-query");