1 /* Process record and replay target for GDB, the GNU debugger.
3 Copyright (C) 2013-2023 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 "gdbsupport/event-loop.h"
37 #include "observable.h"
39 #include "gdbsupport/gdb_unlinker.h"
40 #include "gdbsupport/byte-vector.h"
41 #include "async-event.h"
47 /* This module implements "target record-full", also known as "process
48 record and replay". This target sits on top of a "normal" target
49 (a target that "has execution"), and provides a record and replay
50 functionality, including reverse debugging.
52 Target record has two modes: recording, and replaying.
54 In record mode, we intercept the resume and wait methods.
55 Whenever gdb resumes the target, we run the target in single step
56 mode, and we build up an execution log in which, for each executed
57 instruction, we record all changes in memory and register state.
58 This is invisible to the user, to whom it just looks like an
59 ordinary debugging session (except for performance degradation).
61 In replay mode, instead of actually letting the inferior run as a
62 process, we simulate its execution by playing back the recorded
63 execution log. For each instruction in the log, we simulate the
64 instruction's side effects by duplicating the changes that it would
65 have made on memory and registers. */
67 #define DEFAULT_RECORD_FULL_INSN_MAX_NUM 200000
69 #define RECORD_FULL_IS_REPLAY \
70 (record_full_list->next || ::execution_direction == EXEC_REVERSE)
72 #define RECORD_FULL_FILE_MAGIC netorder32(0x20091016)
74 /* These are the core structs of the process record functionality.
76 A record_full_entry is a record of the value change of a register
77 ("record_full_reg") or a part of memory ("record_full_mem"). And each
78 instruction must have a struct record_full_entry ("record_full_end")
79 that indicates that this is the last struct record_full_entry of this
82 Each struct record_full_entry is linked to "record_full_list" by "prev"
83 and "next" pointers. */
85 struct record_full_mem_entry
89 /* Set this flag if target memory for this entry
90 can no longer be accessed. */
91 int mem_entry_not_accessible
;
95 gdb_byte buf
[sizeof (gdb_byte
*)];
99 struct record_full_reg_entry
106 gdb_byte buf
[2 * sizeof (gdb_byte
*)];
110 struct record_full_end_entry
112 enum gdb_signal sigval
;
116 enum record_full_type
123 /* This is the data structure that makes up the execution log.
125 The execution log consists of a single linked list of entries
126 of type "struct record_full_entry". It is doubly linked so that it
127 can be traversed in either direction.
129 The start of the list is anchored by a struct called
130 "record_full_first". The pointer "record_full_list" either points
131 to the last entry that was added to the list (in record mode), or to
132 the next entry in the list that will be executed (in replay mode).
134 Each list element (struct record_full_entry), in addition to next
135 and prev pointers, consists of a union of three entry types: mem,
136 reg, and end. A field called "type" determines which entry type is
137 represented by a given list element.
139 Each instruction that is added to the execution log is represented
140 by a variable number of list elements ('entries'). The instruction
141 will have one "reg" entry for each register that is changed by
142 executing the instruction (including the PC in every case). It
143 will also have one "mem" entry for each memory change. Finally,
144 each instruction will have an "end" entry that separates it from
145 the changes associated with the next instruction. */
147 struct record_full_entry
149 struct record_full_entry
*prev
;
150 struct record_full_entry
*next
;
151 enum record_full_type type
;
155 struct record_full_reg_entry reg
;
157 struct record_full_mem_entry mem
;
159 struct record_full_end_entry end
;
163 /* If true, query if PREC cannot record memory
164 change of next instruction. */
165 bool record_full_memory_query
= false;
167 struct record_full_core_buf_entry
169 struct record_full_core_buf_entry
*prev
;
170 struct target_section
*p
;
174 /* Record buf with core target. */
175 static detached_regcache
*record_full_core_regbuf
= NULL
;
176 static std::vector
<target_section
> record_full_core_sections
;
177 static struct record_full_core_buf_entry
*record_full_core_buf_list
= NULL
;
179 /* The following variables are used for managing the linked list that
180 represents the execution log.
182 record_full_first is the anchor that holds down the beginning of
185 record_full_list serves two functions:
186 1) In record mode, it anchors the end of the list.
187 2) In replay mode, it traverses the list and points to
188 the next instruction that must be emulated.
190 record_full_arch_list_head and record_full_arch_list_tail are used
191 to manage a separate list, which is used to build up the change
192 elements of the currently executing instruction during record mode.
193 When this instruction has been completely annotated in the "arch
194 list", it will be appended to the main execution log. */
196 static struct record_full_entry record_full_first
;
197 static struct record_full_entry
*record_full_list
= &record_full_first
;
198 static struct record_full_entry
*record_full_arch_list_head
= NULL
;
199 static struct record_full_entry
*record_full_arch_list_tail
= NULL
;
201 /* true ask user. false auto delete the last struct record_full_entry. */
202 static bool record_full_stop_at_limit
= true;
203 /* Maximum allowed number of insns in execution log. */
204 static unsigned int record_full_insn_max_num
205 = DEFAULT_RECORD_FULL_INSN_MAX_NUM
;
206 /* Actual count of insns presently in execution log. */
207 static unsigned int record_full_insn_num
= 0;
208 /* Count of insns logged so far (may be larger
209 than count of insns presently in execution log). */
210 static ULONGEST record_full_insn_count
;
212 static const char record_longname
[]
213 = N_("Process record and replay target");
214 static const char record_doc
[]
215 = N_("Log program while executing and replay execution from log.");
217 /* Base class implementing functionality common to both the
218 "record-full" and "record-core" targets. */
220 class record_full_base_target
: public target_ops
223 const target_info
&info () const override
= 0;
225 strata
stratum () const override
{ return record_stratum
; }
227 void close () override
;
228 void async (bool) override
;
229 ptid_t
wait (ptid_t
, struct target_waitstatus
*, target_wait_flags
) override
;
230 bool stopped_by_watchpoint () override
;
231 bool stopped_data_address (CORE_ADDR
*) override
;
233 bool stopped_by_sw_breakpoint () override
;
234 bool supports_stopped_by_sw_breakpoint () override
;
236 bool stopped_by_hw_breakpoint () override
;
237 bool supports_stopped_by_hw_breakpoint () override
;
239 bool can_execute_reverse () override
;
241 /* Add bookmark target methods. */
242 gdb_byte
*get_bookmark (const char *, int) override
;
243 void goto_bookmark (const gdb_byte
*, int) override
;
244 enum exec_direction_kind
execution_direction () override
;
245 enum record_method
record_method (ptid_t ptid
) override
;
246 void info_record () override
;
247 void save_record (const char *filename
) override
;
248 bool supports_delete_record () override
;
249 void delete_record () override
;
250 bool record_is_replaying (ptid_t ptid
) override
;
251 bool record_will_replay (ptid_t ptid
, int dir
) override
;
252 void record_stop_replaying () override
;
253 void goto_record_begin () override
;
254 void goto_record_end () override
;
255 void goto_record (ULONGEST insn
) override
;
258 /* The "record-full" target. */
260 static const target_info record_full_target_info
= {
266 class record_full_target final
: public record_full_base_target
269 const target_info
&info () const override
270 { return record_full_target_info
; }
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 (inferior
*inf
) 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 gdb_printf (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 gdb_printf (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 gdb_printf (gdb_stdlog
,
641 "Process record: add mem addr = %s len = %d to "
643 paddress (current_inferior ()->arch (), 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 (current_inferior ()->arch (), 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 gdb_printf (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 (const gdb_exception
&ex
)
767 record_full_list_release (record_full_arch_list_tail
);
771 record_full_list
->next
= record_full_arch_list_head
;
772 record_full_arch_list_head
->prev
= record_full_list
;
773 record_full_list
= record_full_arch_list_tail
;
775 if (record_full_insn_num
== record_full_insn_max_num
)
776 record_full_list_release_first ();
778 record_full_insn_num
++;
782 record_full_message_wrapper_safe (struct regcache
*regcache
,
783 enum gdb_signal signal
)
787 record_full_message (regcache
, signal
);
789 catch (const gdb_exception_error
&ex
)
791 exception_print (gdb_stderr
, ex
);
798 /* Set to 1 if record_full_store_registers and record_full_xfer_partial
799 doesn't need record. */
801 static int record_full_gdb_operation_disable
= 0;
803 scoped_restore_tmpl
<int>
804 record_full_gdb_operation_disable_set (void)
806 return make_scoped_restore (&record_full_gdb_operation_disable
, 1);
809 /* Flag set to TRUE for target_stopped_by_watchpoint. */
810 static enum target_stop_reason record_full_stop_reason
811 = TARGET_STOPPED_BY_NO_REASON
;
813 /* Execute one instruction from the record log. Each instruction in
814 the log will be represented by an arbitrary sequence of register
815 entries and memory entries, followed by an 'end' entry. */
818 record_full_exec_insn (struct regcache
*regcache
,
819 struct gdbarch
*gdbarch
,
820 struct record_full_entry
*entry
)
824 case record_full_reg
: /* reg */
826 gdb::byte_vector
reg (entry
->u
.reg
.len
);
828 if (record_debug
> 1)
829 gdb_printf (gdb_stdlog
,
830 "Process record: record_full_reg %s to "
831 "inferior num = %d.\n",
832 host_address_to_string (entry
),
835 regcache
->cooked_read (entry
->u
.reg
.num
, reg
.data ());
836 regcache
->cooked_write (entry
->u
.reg
.num
, record_full_get_loc (entry
));
837 memcpy (record_full_get_loc (entry
), reg
.data (), entry
->u
.reg
.len
);
841 case record_full_mem
: /* mem */
843 /* Nothing to do if the entry is flagged not_accessible. */
844 if (!entry
->u
.mem
.mem_entry_not_accessible
)
846 gdb::byte_vector
mem (entry
->u
.mem
.len
);
848 if (record_debug
> 1)
849 gdb_printf (gdb_stdlog
,
850 "Process record: record_full_mem %s to "
851 "inferior addr = %s len = %d.\n",
852 host_address_to_string (entry
),
853 paddress (gdbarch
, entry
->u
.mem
.addr
),
856 if (record_read_memory (gdbarch
,
857 entry
->u
.mem
.addr
, mem
.data (),
859 entry
->u
.mem
.mem_entry_not_accessible
= 1;
862 if (target_write_memory (entry
->u
.mem
.addr
,
863 record_full_get_loc (entry
),
866 entry
->u
.mem
.mem_entry_not_accessible
= 1;
868 warning (_("Process record: error writing memory at "
869 "addr = %s len = %d."),
870 paddress (gdbarch
, entry
->u
.mem
.addr
),
875 memcpy (record_full_get_loc (entry
), mem
.data (),
878 /* We've changed memory --- check if a hardware
879 watchpoint should trap. Note that this
880 presently assumes the target beneath supports
881 continuable watchpoints. On non-continuable
882 watchpoints target, we'll want to check this
883 _before_ actually doing the memory change, and
884 not doing the change at all if the watchpoint
886 if (hardware_watchpoint_inserted_in_range
887 (current_inferior ()->aspace
,
888 entry
->u
.mem
.addr
, entry
->u
.mem
.len
))
889 record_full_stop_reason
= TARGET_STOPPED_BY_WATCHPOINT
;
898 static void record_full_restore (void);
900 /* Asynchronous signal handle registered as event loop source for when
901 we have pending events ready to be passed to the core. */
903 static struct async_event_handler
*record_full_async_inferior_event_token
;
906 record_full_async_inferior_event_handler (gdb_client_data data
)
908 inferior_event_handler (INF_REG_EVENT
);
911 /* Open the process record target for 'core' files. */
914 record_full_core_open_1 (const char *name
, int from_tty
)
916 regcache
*regcache
= get_thread_regcache (inferior_thread ());
917 int regnum
= gdbarch_num_regs (regcache
->arch ());
920 /* Get record_full_core_regbuf. */
921 target_fetch_registers (regcache
, -1);
922 record_full_core_regbuf
= new detached_regcache (regcache
->arch (), false);
924 for (i
= 0; i
< regnum
; i
++)
925 record_full_core_regbuf
->raw_supply (i
, *regcache
);
927 record_full_core_sections
= build_section_table (core_bfd
);
929 current_inferior ()->push_target (&record_full_core_ops
);
930 record_full_restore ();
933 /* Open the process record target for 'live' processes. */
936 record_full_open_1 (const char *name
, int from_tty
)
939 gdb_printf (gdb_stdlog
, "Process record: record_full_open_1\n");
942 if (!target_has_execution ())
943 error (_("Process record: the program is not being run."));
945 error (_("Process record target can't debug inferior in non-stop mode "
948 if (!gdbarch_process_record_p (current_inferior ()->arch ()))
949 error (_("Process record: the current architecture doesn't support "
950 "record function."));
952 current_inferior ()->push_target (&record_full_ops
);
955 static void record_full_init_record_breakpoints (void);
957 /* Open the process record target. */
960 record_full_open (const char *name
, int from_tty
)
963 gdb_printf (gdb_stdlog
, "Process record: record_full_open\n");
968 record_full_insn_num
= 0;
969 record_full_insn_count
= 0;
970 record_full_list
= &record_full_first
;
971 record_full_list
->next
= NULL
;
974 record_full_core_open_1 (name
, from_tty
);
976 record_full_open_1 (name
, from_tty
);
978 /* Register extra event sources in the event loop. */
979 record_full_async_inferior_event_token
980 = create_async_event_handler (record_full_async_inferior_event_handler
,
981 NULL
, "record-full");
983 record_full_init_record_breakpoints ();
985 interps_notify_record_changed (current_inferior (), 1, "full", NULL
);
988 /* "close" target method. Close the process record target. */
991 record_full_base_target::close ()
993 struct record_full_core_buf_entry
*entry
;
996 gdb_printf (gdb_stdlog
, "Process record: record_full_close\n");
998 record_full_list_release (record_full_list
);
1000 /* Release record_full_core_regbuf. */
1001 if (record_full_core_regbuf
)
1003 delete record_full_core_regbuf
;
1004 record_full_core_regbuf
= NULL
;
1007 /* Release record_full_core_buf_list. */
1008 while (record_full_core_buf_list
)
1010 entry
= record_full_core_buf_list
;
1011 record_full_core_buf_list
= record_full_core_buf_list
->prev
;
1015 if (record_full_async_inferior_event_token
)
1016 delete_async_event_handler (&record_full_async_inferior_event_token
);
1019 /* "async" target method. */
1022 record_full_base_target::async (bool enable
)
1025 mark_async_event_handler (record_full_async_inferior_event_token
);
1027 clear_async_event_handler (record_full_async_inferior_event_token
);
1029 beneath ()->async (enable
);
1032 /* The PTID and STEP arguments last passed to
1033 record_full_target::resume. */
1034 static ptid_t record_full_resume_ptid
= null_ptid
;
1035 static int record_full_resume_step
= 0;
1037 /* True if we've been resumed, and so each record_full_wait call should
1038 advance execution. If this is false, record_full_wait will return a
1039 TARGET_WAITKIND_IGNORE. */
1040 static int record_full_resumed
= 0;
1042 /* The execution direction of the last resume we got. This is
1043 necessary for async mode. Vis (order is not strictly accurate):
1045 1. user has the global execution direction set to forward
1046 2. user does a reverse-step command
1047 3. record_full_resume is called with global execution direction
1048 temporarily switched to reverse
1049 4. GDB's execution direction is reverted back to forward
1050 5. target record notifies event loop there's an event to handle
1051 6. infrun asks the target which direction was it going, and switches
1052 the global execution direction accordingly (to reverse)
1053 7. infrun polls an event out of the record target, and handles it
1054 8. GDB goes back to the event loop, and goto #4.
1056 static enum exec_direction_kind record_full_execution_dir
= EXEC_FORWARD
;
1058 /* "resume" target method. Resume the process record target. */
1061 record_full_target::resume (ptid_t ptid
, int step
, enum gdb_signal signal
)
1063 record_full_resume_ptid
= inferior_ptid
;
1064 record_full_resume_step
= step
;
1065 record_full_resumed
= 1;
1066 record_full_execution_dir
= ::execution_direction
;
1068 if (!RECORD_FULL_IS_REPLAY
)
1070 struct gdbarch
*gdbarch
= target_thread_architecture (ptid
);
1072 record_full_message (get_thread_regcache (inferior_thread ()), signal
);
1076 /* This is not hard single step. */
1077 if (!gdbarch_software_single_step_p (gdbarch
))
1079 /* This is a normal continue. */
1084 /* This arch supports soft single step. */
1085 if (thread_has_single_step_breakpoints_set (inferior_thread ()))
1087 /* This is a soft single step. */
1088 record_full_resume_step
= 1;
1091 step
= !insert_single_step_breakpoints (gdbarch
);
1095 /* Make sure the target beneath reports all signals. */
1096 target_pass_signals ({});
1098 /* Disable range-stepping, forcing the process target to report stops for
1099 all executed instructions, so we can record them all. */
1100 process_stratum_target
*proc_target
1101 = current_inferior ()->process_target ();
1102 for (thread_info
*thread
: all_non_exited_threads (proc_target
, ptid
))
1103 thread
->control
.may_range_step
= 0;
1105 this->beneath ()->resume (ptid
, step
, signal
);
1109 static int record_full_get_sig
= 0;
1111 /* SIGINT signal handler, registered by "wait" method. */
1114 record_full_sig_handler (int signo
)
1117 gdb_printf (gdb_stdlog
, "Process record: get a signal\n");
1119 /* It will break the running inferior in replay mode. */
1120 record_full_resume_step
= 1;
1122 /* It will let record_full_wait set inferior status to get the signal
1124 record_full_get_sig
= 1;
1127 /* "wait" target method for process record target.
1129 In record mode, the target is always run in singlestep mode
1130 (even when gdb says to continue). The wait method intercepts
1131 the stop events and determines which ones are to be passed on to
1132 gdb. Most stop events are just singlestep events that gdb is not
1133 to know about, so the wait method just records them and keeps
1136 In replay mode, this function emulates the recorded execution log,
1137 one instruction at a time (forward or backward), and determines
1141 record_full_wait_1 (struct target_ops
*ops
,
1142 ptid_t ptid
, struct target_waitstatus
*status
,
1143 target_wait_flags options
)
1145 scoped_restore restore_operation_disable
1146 = record_full_gdb_operation_disable_set ();
1149 gdb_printf (gdb_stdlog
,
1150 "Process record: record_full_wait "
1151 "record_full_resume_step = %d, "
1152 "record_full_resumed = %d, direction=%s\n",
1153 record_full_resume_step
, record_full_resumed
,
1154 record_full_execution_dir
== EXEC_FORWARD
1155 ? "forward" : "reverse");
1157 if (!record_full_resumed
)
1159 gdb_assert ((options
& TARGET_WNOHANG
) != 0);
1161 /* No interesting event. */
1162 status
->set_ignore ();
1163 return minus_one_ptid
;
1166 record_full_get_sig
= 0;
1167 signal (SIGINT
, record_full_sig_handler
);
1169 record_full_stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
1171 if (!RECORD_FULL_IS_REPLAY
&& ops
!= &record_full_core_ops
)
1173 if (record_full_resume_step
)
1175 /* This is a single step. */
1176 return ops
->beneath ()->wait (ptid
, status
, options
);
1180 /* This is not a single step. */
1183 struct gdbarch
*gdbarch
1184 = target_thread_architecture (record_full_resume_ptid
);
1188 ret
= ops
->beneath ()->wait (ptid
, status
, options
);
1189 if (status
->kind () == TARGET_WAITKIND_IGNORE
)
1192 gdb_printf (gdb_stdlog
,
1193 "Process record: record_full_wait "
1194 "target beneath not done yet\n");
1198 for (thread_info
*tp
: all_non_exited_threads ())
1199 delete_single_step_breakpoints (tp
);
1201 if (record_full_resume_step
)
1204 /* Is this a SIGTRAP? */
1205 if (status
->kind () == TARGET_WAITKIND_STOPPED
1206 && status
->sig () == GDB_SIGNAL_TRAP
)
1208 struct regcache
*regcache
;
1209 enum target_stop_reason
*stop_reason_p
1210 = &record_full_stop_reason
;
1212 /* Yes -- this is likely our single-step finishing,
1213 but check if there's any reason the core would be
1214 interested in the event. */
1216 registers_changed ();
1217 switch_to_thread (current_inferior ()->process_target (),
1219 regcache
= get_thread_regcache (inferior_thread ());
1220 tmp_pc
= regcache_read_pc (regcache
);
1221 const address_space
*aspace
= current_inferior ()->aspace
;
1223 if (target_stopped_by_watchpoint ())
1225 /* Always interested in watchpoints. */
1227 else if (record_check_stopped_by_breakpoint (aspace
, tmp_pc
,
1230 /* There is a breakpoint here. Let the core
1235 /* This is a single-step trap. Record the
1236 insn and issue another step.
1237 FIXME: this part can be a random SIGTRAP too.
1238 But GDB cannot handle it. */
1241 if (!record_full_message_wrapper_safe (regcache
,
1244 status
->set_stopped (GDB_SIGNAL_0
);
1248 process_stratum_target
*proc_target
1249 = current_inferior ()->process_target ();
1251 if (gdbarch_software_single_step_p (gdbarch
))
1253 /* Try to insert the software single step breakpoint.
1254 If insert success, set step to 0. */
1255 set_executing (proc_target
, inferior_ptid
, false);
1258 set_executing (proc_target
, inferior_ptid
, true);
1261 reinit_frame_cache ();
1262 step
= !insert_single_step_breakpoints (gdbarch
);
1266 gdb_printf (gdb_stdlog
,
1267 "Process record: record_full_wait "
1268 "issuing one more step in the "
1269 "target beneath\n");
1270 ops
->beneath ()->resume (ptid
, step
, GDB_SIGNAL_0
);
1271 proc_target
->commit_resumed_state
= true;
1272 proc_target
->commit_resumed ();
1273 proc_target
->commit_resumed_state
= false;
1278 /* The inferior is broken by a breakpoint or a signal. */
1287 switch_to_thread (current_inferior ()->process_target (),
1288 record_full_resume_ptid
);
1289 regcache
*regcache
= get_thread_regcache (inferior_thread ());
1290 struct gdbarch
*gdbarch
= regcache
->arch ();
1291 const address_space
*aspace
= current_inferior ()->aspace
;
1292 int continue_flag
= 1;
1293 int first_record_full_end
= 1;
1299 record_full_stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
1300 status
->set_stopped (GDB_SIGNAL_0
);
1302 /* Check breakpoint when forward execute. */
1303 if (execution_direction
== EXEC_FORWARD
)
1305 tmp_pc
= regcache_read_pc (regcache
);
1306 if (record_check_stopped_by_breakpoint (aspace
, tmp_pc
,
1307 &record_full_stop_reason
))
1310 gdb_printf (gdb_stdlog
,
1311 "Process record: break at %s.\n",
1312 paddress (gdbarch
, tmp_pc
));
1317 /* If GDB is in terminal_inferior mode, it will not get the
1318 signal. And in GDB replay mode, GDB doesn't need to be
1319 in terminal_inferior mode, because inferior will not
1320 executed. Then set it to terminal_ours to make GDB get
1322 target_terminal::ours ();
1324 /* In EXEC_FORWARD mode, record_full_list points to the tail of prev
1326 if (execution_direction
== EXEC_FORWARD
&& record_full_list
->next
)
1327 record_full_list
= record_full_list
->next
;
1329 /* Loop over the record_full_list, looking for the next place to
1333 /* Check for beginning and end of log. */
1334 if (execution_direction
== EXEC_REVERSE
1335 && record_full_list
== &record_full_first
)
1337 /* Hit beginning of record log in reverse. */
1338 status
->set_no_history ();
1341 if (execution_direction
!= EXEC_REVERSE
1342 && !record_full_list
->next
)
1344 /* Hit end of record log going forward. */
1345 status
->set_no_history ();
1349 record_full_exec_insn (regcache
, gdbarch
, record_full_list
);
1351 if (record_full_list
->type
== record_full_end
)
1353 if (record_debug
> 1)
1356 "Process record: record_full_end %s to "
1358 host_address_to_string (record_full_list
));
1360 if (first_record_full_end
1361 && execution_direction
== EXEC_REVERSE
)
1363 /* When reverse execute, the first
1364 record_full_end is the part of current
1366 first_record_full_end
= 0;
1370 /* In EXEC_REVERSE mode, this is the
1371 record_full_end of prev instruction. In
1372 EXEC_FORWARD mode, this is the
1373 record_full_end of current instruction. */
1375 if (record_full_resume_step
)
1377 if (record_debug
> 1)
1378 gdb_printf (gdb_stdlog
,
1379 "Process record: step.\n");
1383 /* check breakpoint */
1384 tmp_pc
= regcache_read_pc (regcache
);
1385 if (record_check_stopped_by_breakpoint
1386 (aspace
, tmp_pc
, &record_full_stop_reason
))
1389 gdb_printf (gdb_stdlog
,
1390 "Process record: break "
1392 paddress (gdbarch
, tmp_pc
));
1397 if (record_full_stop_reason
1398 == TARGET_STOPPED_BY_WATCHPOINT
)
1401 gdb_printf (gdb_stdlog
,
1402 "Process record: hit hw "
1406 /* Check target signal */
1407 if (record_full_list
->u
.end
.sigval
!= GDB_SIGNAL_0
)
1408 /* FIXME: better way to check */
1415 if (execution_direction
== EXEC_REVERSE
)
1417 if (record_full_list
->prev
)
1418 record_full_list
= record_full_list
->prev
;
1422 if (record_full_list
->next
)
1423 record_full_list
= record_full_list
->next
;
1427 while (continue_flag
);
1430 if (status
->kind () == TARGET_WAITKIND_STOPPED
)
1432 if (record_full_get_sig
)
1433 status
->set_stopped (GDB_SIGNAL_INT
);
1434 else if (record_full_list
->u
.end
.sigval
!= GDB_SIGNAL_0
)
1435 /* FIXME: better way to check */
1436 status
->set_stopped (record_full_list
->u
.end
.sigval
);
1438 status
->set_stopped (GDB_SIGNAL_TRAP
);
1441 catch (const gdb_exception
&ex
)
1443 if (execution_direction
== EXEC_REVERSE
)
1445 if (record_full_list
->next
)
1446 record_full_list
= record_full_list
->next
;
1449 record_full_list
= record_full_list
->prev
;
1455 signal (SIGINT
, handle_sigint
);
1457 return inferior_ptid
;
1461 record_full_base_target::wait (ptid_t ptid
, struct target_waitstatus
*status
,
1462 target_wait_flags options
)
1466 clear_async_event_handler (record_full_async_inferior_event_token
);
1468 return_ptid
= record_full_wait_1 (this, ptid
, status
, options
);
1469 if (status
->kind () != TARGET_WAITKIND_IGNORE
)
1471 /* We're reporting a stop. Make sure any spurious
1472 target_wait(WNOHANG) doesn't advance the target until the
1473 core wants us resumed again. */
1474 record_full_resumed
= 0;
1480 record_full_base_target::stopped_by_watchpoint ()
1482 if (RECORD_FULL_IS_REPLAY
)
1483 return record_full_stop_reason
== TARGET_STOPPED_BY_WATCHPOINT
;
1485 return beneath ()->stopped_by_watchpoint ();
1489 record_full_base_target::stopped_data_address (CORE_ADDR
*addr_p
)
1491 if (RECORD_FULL_IS_REPLAY
)
1494 return this->beneath ()->stopped_data_address (addr_p
);
1497 /* The stopped_by_sw_breakpoint method of target record-full. */
1500 record_full_base_target::stopped_by_sw_breakpoint ()
1502 return record_full_stop_reason
== TARGET_STOPPED_BY_SW_BREAKPOINT
;
1505 /* The supports_stopped_by_sw_breakpoint method of target
1509 record_full_base_target::supports_stopped_by_sw_breakpoint ()
1514 /* The stopped_by_hw_breakpoint method of target record-full. */
1517 record_full_base_target::stopped_by_hw_breakpoint ()
1519 return record_full_stop_reason
== TARGET_STOPPED_BY_HW_BREAKPOINT
;
1522 /* The supports_stopped_by_sw_breakpoint method of target
1526 record_full_base_target::supports_stopped_by_hw_breakpoint ()
1531 /* Record registers change (by user or by GDB) to list as an instruction. */
1534 record_full_registers_change (struct regcache
*regcache
, int regnum
)
1536 /* Check record_full_insn_num. */
1537 record_full_check_insn_num ();
1539 record_full_arch_list_head
= NULL
;
1540 record_full_arch_list_tail
= NULL
;
1546 for (i
= 0; i
< gdbarch_num_regs (regcache
->arch ()); i
++)
1548 if (record_full_arch_list_add_reg (regcache
, i
))
1550 record_full_list_release (record_full_arch_list_tail
);
1551 error (_("Process record: failed to record execution log."));
1557 if (record_full_arch_list_add_reg (regcache
, regnum
))
1559 record_full_list_release (record_full_arch_list_tail
);
1560 error (_("Process record: failed to record execution log."));
1563 if (record_full_arch_list_add_end ())
1565 record_full_list_release (record_full_arch_list_tail
);
1566 error (_("Process record: failed to record execution log."));
1568 record_full_list
->next
= record_full_arch_list_head
;
1569 record_full_arch_list_head
->prev
= record_full_list
;
1570 record_full_list
= record_full_arch_list_tail
;
1572 if (record_full_insn_num
== record_full_insn_max_num
)
1573 record_full_list_release_first ();
1575 record_full_insn_num
++;
1578 /* "store_registers" method for process record target. */
1581 record_full_target::store_registers (struct regcache
*regcache
, int regno
)
1583 if (!record_full_gdb_operation_disable
)
1585 if (RECORD_FULL_IS_REPLAY
)
1589 /* Let user choose if he wants to write register or not. */
1592 query (_("Because GDB is in replay mode, changing the "
1593 "value of a register will make the execution "
1594 "log unusable from this point onward. "
1595 "Change all registers?"));
1598 query (_("Because GDB is in replay mode, changing the value "
1599 "of a register will make the execution log unusable "
1600 "from this point onward. Change register %s?"),
1601 gdbarch_register_name (regcache
->arch (),
1606 /* Invalidate the value of regcache that was set in function
1607 "regcache_raw_write". */
1613 i
< gdbarch_num_regs (regcache
->arch ());
1615 regcache
->invalidate (i
);
1618 regcache
->invalidate (regno
);
1620 error (_("Process record canceled the operation."));
1623 /* Destroy the record from here forward. */
1624 record_full_list_release_following (record_full_list
);
1627 record_full_registers_change (regcache
, regno
);
1629 this->beneath ()->store_registers (regcache
, regno
);
1632 /* "xfer_partial" method. Behavior is conditional on
1633 RECORD_FULL_IS_REPLAY.
1634 In replay mode, we cannot write memory unles we are willing to
1635 invalidate the record/replay log from this point forward. */
1637 enum target_xfer_status
1638 record_full_target::xfer_partial (enum target_object object
,
1639 const char *annex
, gdb_byte
*readbuf
,
1640 const gdb_byte
*writebuf
, ULONGEST offset
,
1641 ULONGEST len
, ULONGEST
*xfered_len
)
1643 if (!record_full_gdb_operation_disable
1644 && (object
== TARGET_OBJECT_MEMORY
1645 || object
== TARGET_OBJECT_RAW_MEMORY
) && writebuf
)
1647 if (RECORD_FULL_IS_REPLAY
)
1649 /* Let user choose if he wants to write memory or not. */
1650 if (!query (_("Because GDB is in replay mode, writing to memory "
1651 "will make the execution log unusable from this "
1652 "point onward. Write memory at address %s?"),
1653 paddress (current_inferior ()->arch (), offset
)))
1654 error (_("Process record canceled the operation."));
1656 /* Destroy the record from here forward. */
1657 record_full_list_release_following (record_full_list
);
1660 /* Check record_full_insn_num */
1661 record_full_check_insn_num ();
1663 /* Record registers change to list as an instruction. */
1664 record_full_arch_list_head
= NULL
;
1665 record_full_arch_list_tail
= NULL
;
1666 if (record_full_arch_list_add_mem (offset
, len
))
1668 record_full_list_release (record_full_arch_list_tail
);
1670 gdb_printf (gdb_stdlog
,
1671 "Process record: failed to record "
1673 return TARGET_XFER_E_IO
;
1675 if (record_full_arch_list_add_end ())
1677 record_full_list_release (record_full_arch_list_tail
);
1679 gdb_printf (gdb_stdlog
,
1680 "Process record: failed to record "
1682 return TARGET_XFER_E_IO
;
1684 record_full_list
->next
= record_full_arch_list_head
;
1685 record_full_arch_list_head
->prev
= record_full_list
;
1686 record_full_list
= record_full_arch_list_tail
;
1688 if (record_full_insn_num
== record_full_insn_max_num
)
1689 record_full_list_release_first ();
1691 record_full_insn_num
++;
1694 return this->beneath ()->xfer_partial (object
, annex
, readbuf
, writebuf
,
1695 offset
, len
, xfered_len
);
1698 /* This structure represents a breakpoint inserted while the record
1699 target is active. We use this to know when to install/remove
1700 breakpoints in/from the target beneath. For example, a breakpoint
1701 may be inserted while recording, but removed when not replaying nor
1702 recording. In that case, the breakpoint had not been inserted on
1703 the target beneath, so we should not try to remove it there. */
1705 struct record_full_breakpoint
1707 record_full_breakpoint (struct address_space
*address_space_
,
1709 bool in_target_beneath_
)
1710 : address_space (address_space_
),
1712 in_target_beneath (in_target_beneath_
)
1716 /* The address and address space the breakpoint was set at. */
1717 struct address_space
*address_space
;
1720 /* True when the breakpoint has been also installed in the target
1721 beneath. This will be false for breakpoints set during replay or
1723 bool in_target_beneath
;
1726 /* The list of breakpoints inserted while the record target is
1728 static std::vector
<record_full_breakpoint
> record_full_breakpoints
;
1730 /* Sync existing breakpoints to record_full_breakpoints. */
1733 record_full_init_record_breakpoints (void)
1735 record_full_breakpoints
.clear ();
1737 for (bp_location
*loc
: all_bp_locations ())
1739 if (loc
->loc_type
!= bp_loc_software_breakpoint
)
1743 record_full_breakpoints
.emplace_back
1744 (loc
->target_info
.placed_address_space
,
1745 loc
->target_info
.placed_address
, 1);
1749 /* Behavior is conditional on RECORD_FULL_IS_REPLAY. We will not actually
1750 insert or remove breakpoints in the real target when replaying, nor
1754 record_full_target::insert_breakpoint (struct gdbarch
*gdbarch
,
1755 struct bp_target_info
*bp_tgt
)
1757 bool in_target_beneath
= false;
1759 if (!RECORD_FULL_IS_REPLAY
)
1761 /* When recording, we currently always single-step, so we don't
1762 really need to install regular breakpoints in the inferior.
1763 However, we do have to insert software single-step
1764 breakpoints, in case the target can't hardware step. To keep
1765 things simple, we always insert. */
1767 scoped_restore restore_operation_disable
1768 = record_full_gdb_operation_disable_set ();
1770 int ret
= this->beneath ()->insert_breakpoint (gdbarch
, bp_tgt
);
1774 in_target_beneath
= true;
1777 /* Use the existing entries if found in order to avoid duplication
1778 in record_full_breakpoints. */
1780 for (const record_full_breakpoint
&bp
: record_full_breakpoints
)
1782 if (bp
.addr
== bp_tgt
->placed_address
1783 && bp
.address_space
== bp_tgt
->placed_address_space
)
1785 gdb_assert (bp
.in_target_beneath
== in_target_beneath
);
1790 record_full_breakpoints
.emplace_back (bp_tgt
->placed_address_space
,
1791 bp_tgt
->placed_address
,
1796 /* "remove_breakpoint" method for process record target. */
1799 record_full_target::remove_breakpoint (struct gdbarch
*gdbarch
,
1800 struct bp_target_info
*bp_tgt
,
1801 enum remove_bp_reason reason
)
1803 for (auto iter
= record_full_breakpoints
.begin ();
1804 iter
!= record_full_breakpoints
.end ();
1807 struct record_full_breakpoint
&bp
= *iter
;
1809 if (bp
.addr
== bp_tgt
->placed_address
1810 && bp
.address_space
== bp_tgt
->placed_address_space
)
1812 if (bp
.in_target_beneath
)
1814 scoped_restore restore_operation_disable
1815 = record_full_gdb_operation_disable_set ();
1817 int ret
= this->beneath ()->remove_breakpoint (gdbarch
, bp_tgt
,
1823 if (reason
== REMOVE_BREAKPOINT
)
1824 unordered_remove (record_full_breakpoints
, iter
);
1829 gdb_assert_not_reached ("removing unknown breakpoint");
1832 /* "can_execute_reverse" method for process record target. */
1835 record_full_base_target::can_execute_reverse ()
1840 /* "get_bookmark" method for process record and prec over core. */
1843 record_full_base_target::get_bookmark (const char *args
, int from_tty
)
1847 /* Return stringified form of instruction count. */
1848 if (record_full_list
&& record_full_list
->type
== record_full_end
)
1849 ret
= xstrdup (pulongest (record_full_list
->u
.end
.insn_num
));
1854 gdb_printf (gdb_stdlog
,
1855 "record_full_get_bookmark returns %s\n", ret
);
1857 gdb_printf (gdb_stdlog
,
1858 "record_full_get_bookmark returns NULL\n");
1860 return (gdb_byte
*) ret
;
1863 /* "goto_bookmark" method for process record and prec over core. */
1866 record_full_base_target::goto_bookmark (const gdb_byte
*raw_bookmark
,
1869 const char *bookmark
= (const char *) raw_bookmark
;
1872 gdb_printf (gdb_stdlog
,
1873 "record_full_goto_bookmark receives %s\n", bookmark
);
1875 std::string name_holder
;
1876 if (bookmark
[0] == '\'' || bookmark
[0] == '\"')
1878 if (bookmark
[strlen (bookmark
) - 1] != bookmark
[0])
1879 error (_("Unbalanced quotes: %s"), bookmark
);
1881 name_holder
= std::string (bookmark
+ 1, strlen (bookmark
) - 2);
1882 bookmark
= name_holder
.c_str ();
1885 record_goto (bookmark
);
1888 enum exec_direction_kind
1889 record_full_base_target::execution_direction ()
1891 return record_full_execution_dir
;
1894 /* The record_method method of target record-full. */
1897 record_full_base_target::record_method (ptid_t ptid
)
1899 return RECORD_METHOD_FULL
;
1903 record_full_base_target::info_record ()
1905 struct record_full_entry
*p
;
1907 if (RECORD_FULL_IS_REPLAY
)
1908 gdb_printf (_("Replay mode:\n"));
1910 gdb_printf (_("Record mode:\n"));
1912 /* Find entry for first actual instruction in the log. */
1913 for (p
= record_full_first
.next
;
1914 p
!= NULL
&& p
->type
!= record_full_end
;
1918 /* Do we have a log at all? */
1919 if (p
!= NULL
&& p
->type
== record_full_end
)
1921 /* Display instruction number for first instruction in the log. */
1922 gdb_printf (_("Lowest recorded instruction number is %s.\n"),
1923 pulongest (p
->u
.end
.insn_num
));
1925 /* If in replay mode, display where we are in the log. */
1926 if (RECORD_FULL_IS_REPLAY
)
1927 gdb_printf (_("Current instruction number is %s.\n"),
1928 pulongest (record_full_list
->u
.end
.insn_num
));
1930 /* Display instruction number for last instruction in the log. */
1931 gdb_printf (_("Highest recorded instruction number is %s.\n"),
1932 pulongest (record_full_insn_count
));
1934 /* Display log count. */
1935 gdb_printf (_("Log contains %u instructions.\n"),
1936 record_full_insn_num
);
1939 gdb_printf (_("No instructions have been logged.\n"));
1941 /* Display max log size. */
1942 gdb_printf (_("Max logged instructions is %u.\n"),
1943 record_full_insn_max_num
);
1947 record_full_base_target::supports_delete_record ()
1952 /* The "delete_record" target method. */
1955 record_full_base_target::delete_record ()
1957 record_full_list_release_following (record_full_list
);
1960 /* The "record_is_replaying" target method. */
1963 record_full_base_target::record_is_replaying (ptid_t ptid
)
1965 return RECORD_FULL_IS_REPLAY
;
1968 /* The "record_will_replay" target method. */
1971 record_full_base_target::record_will_replay (ptid_t ptid
, int dir
)
1973 /* We can currently only record when executing forwards. Should we be able
1974 to record when executing backwards on targets that support reverse
1975 execution, this needs to be changed. */
1977 return RECORD_FULL_IS_REPLAY
|| dir
== EXEC_REVERSE
;
1980 /* Go to a specific entry. */
1983 record_full_goto_entry (struct record_full_entry
*p
)
1986 error (_("Target insn not found."));
1987 else if (p
== record_full_list
)
1988 error (_("Already at target insn."));
1989 else if (p
->u
.end
.insn_num
> record_full_list
->u
.end
.insn_num
)
1991 gdb_printf (_("Go forward to insn number %s\n"),
1992 pulongest (p
->u
.end
.insn_num
));
1993 record_full_goto_insn (p
, EXEC_FORWARD
);
1997 gdb_printf (_("Go backward to insn number %s\n"),
1998 pulongest (p
->u
.end
.insn_num
));
1999 record_full_goto_insn (p
, EXEC_REVERSE
);
2002 registers_changed ();
2003 reinit_frame_cache ();
2005 thread_info
*thr
= inferior_thread ();
2006 thr
->set_stop_pc (regcache_read_pc (get_thread_regcache (thr
)));
2007 print_stack_frame (get_selected_frame (NULL
), 1, SRC_AND_LOC
, 1);
2010 /* The "goto_record_begin" target method. */
2013 record_full_base_target::goto_record_begin ()
2015 struct record_full_entry
*p
= NULL
;
2017 for (p
= &record_full_first
; p
!= NULL
; p
= p
->next
)
2018 if (p
->type
== record_full_end
)
2021 record_full_goto_entry (p
);
2024 /* The "goto_record_end" target method. */
2027 record_full_base_target::goto_record_end ()
2029 struct record_full_entry
*p
= NULL
;
2031 for (p
= record_full_list
; p
->next
!= NULL
; p
= p
->next
)
2033 for (; p
!= NULL
; p
= p
->prev
)
2034 if (p
->type
== record_full_end
)
2037 record_full_goto_entry (p
);
2040 /* The "goto_record" target method. */
2043 record_full_base_target::goto_record (ULONGEST target_insn
)
2045 struct record_full_entry
*p
= NULL
;
2047 for (p
= &record_full_first
; p
!= NULL
; p
= p
->next
)
2048 if (p
->type
== record_full_end
&& p
->u
.end
.insn_num
== target_insn
)
2051 record_full_goto_entry (p
);
2054 /* The "record_stop_replaying" target method. */
2057 record_full_base_target::record_stop_replaying ()
2062 /* "resume" method for prec over corefile. */
2065 record_full_core_target::resume (ptid_t ptid
, int step
,
2066 enum gdb_signal signal
)
2068 record_full_resume_step
= step
;
2069 record_full_resumed
= 1;
2070 record_full_execution_dir
= ::execution_direction
;
2073 /* "kill" method for prec over corefile. */
2076 record_full_core_target::kill ()
2079 gdb_printf (gdb_stdlog
, "Process record: record_full_core_kill\n");
2081 current_inferior ()->unpush_target (this);
2084 /* "fetch_registers" method for prec over corefile. */
2087 record_full_core_target::fetch_registers (struct regcache
*regcache
,
2092 int num
= gdbarch_num_regs (regcache
->arch ());
2095 for (i
= 0; i
< num
; i
++)
2096 regcache
->raw_supply (i
, *record_full_core_regbuf
);
2099 regcache
->raw_supply (regno
, *record_full_core_regbuf
);
2102 /* "prepare_to_store" method for prec over corefile. */
2105 record_full_core_target::prepare_to_store (struct regcache
*regcache
)
2109 /* "store_registers" method for prec over corefile. */
2112 record_full_core_target::store_registers (struct regcache
*regcache
,
2115 if (record_full_gdb_operation_disable
)
2116 record_full_core_regbuf
->raw_supply (regno
, *regcache
);
2118 error (_("You can't do that without a process to debug."));
2121 /* "xfer_partial" method for prec over corefile. */
2123 enum target_xfer_status
2124 record_full_core_target::xfer_partial (enum target_object object
,
2125 const char *annex
, gdb_byte
*readbuf
,
2126 const gdb_byte
*writebuf
, ULONGEST offset
,
2127 ULONGEST len
, ULONGEST
*xfered_len
)
2129 if (object
== TARGET_OBJECT_MEMORY
)
2131 if (record_full_gdb_operation_disable
|| !writebuf
)
2133 for (target_section
&p
: record_full_core_sections
)
2135 if (offset
>= p
.addr
)
2137 struct record_full_core_buf_entry
*entry
;
2138 ULONGEST sec_offset
;
2140 if (offset
>= p
.endaddr
)
2143 if (offset
+ len
> p
.endaddr
)
2144 len
= p
.endaddr
- offset
;
2146 sec_offset
= offset
- p
.addr
;
2148 /* Read readbuf or write writebuf p, offset, len. */
2150 if (p
.the_bfd_section
->flags
& SEC_CONSTRUCTOR
2151 || (p
.the_bfd_section
->flags
& SEC_HAS_CONTENTS
) == 0)
2154 memset (readbuf
, 0, len
);
2157 return TARGET_XFER_OK
;
2159 /* Get record_full_core_buf_entry. */
2160 for (entry
= record_full_core_buf_list
; entry
;
2161 entry
= entry
->prev
)
2168 /* Add a new entry. */
2169 entry
= XNEW (struct record_full_core_buf_entry
);
2171 if (!bfd_malloc_and_get_section
2172 (p
.the_bfd_section
->owner
,
2177 return TARGET_XFER_EOF
;
2179 entry
->prev
= record_full_core_buf_list
;
2180 record_full_core_buf_list
= entry
;
2183 memcpy (entry
->buf
+ sec_offset
, writebuf
,
2189 return this->beneath ()->xfer_partial (object
, annex
,
2194 memcpy (readbuf
, entry
->buf
+ sec_offset
,
2199 return TARGET_XFER_OK
;
2203 return TARGET_XFER_E_IO
;
2206 error (_("You can't do that without a process to debug."));
2209 return this->beneath ()->xfer_partial (object
, annex
,
2210 readbuf
, writebuf
, offset
, len
,
2214 /* "insert_breakpoint" method for prec over corefile. */
2217 record_full_core_target::insert_breakpoint (struct gdbarch
*gdbarch
,
2218 struct bp_target_info
*bp_tgt
)
2223 /* "remove_breakpoint" method for prec over corefile. */
2226 record_full_core_target::remove_breakpoint (struct gdbarch
*gdbarch
,
2227 struct bp_target_info
*bp_tgt
,
2228 enum remove_bp_reason reason
)
2233 /* "has_execution" method for prec over corefile. */
2236 record_full_core_target::has_execution (inferior
*inf
)
2241 /* Record log save-file format
2242 Version 1 (never released)
2245 4 bytes: magic number htonl(0x20090829).
2246 NOTE: be sure to change whenever this file format changes!
2250 1 byte: record type (record_full_end, see enum record_full_type).
2252 1 byte: record type (record_full_reg, see enum record_full_type).
2253 8 bytes: register id (network byte order).
2254 MAX_REGISTER_SIZE bytes: register value.
2256 1 byte: record type (record_full_mem, see enum record_full_type).
2257 8 bytes: memory length (network byte order).
2258 8 bytes: memory address (network byte order).
2259 n bytes: memory value (n == memory length).
2262 4 bytes: magic number netorder32(0x20091016).
2263 NOTE: be sure to change whenever this file format changes!
2267 1 byte: record type (record_full_end, see enum record_full_type).
2269 4 bytes: instruction count
2271 1 byte: record type (record_full_reg, see enum record_full_type).
2272 4 bytes: register id (network byte order).
2273 n bytes: register value (n == actual register size).
2274 (eg. 4 bytes for x86 general registers).
2276 1 byte: record type (record_full_mem, see enum record_full_type).
2277 4 bytes: memory length (network byte order).
2278 8 bytes: memory address (network byte order).
2279 n bytes: memory value (n == memory length).
2283 /* bfdcore_read -- read bytes from a core file section. */
2286 bfdcore_read (bfd
*obfd
, asection
*osec
, void *buf
, int len
, int *offset
)
2288 int ret
= bfd_get_section_contents (obfd
, osec
, buf
, *offset
, len
);
2293 error (_("Failed to read %d bytes from core file %s ('%s')."),
2294 len
, bfd_get_filename (obfd
),
2295 bfd_errmsg (bfd_get_error ()));
2298 static inline uint64_t
2299 netorder64 (uint64_t input
)
2303 store_unsigned_integer ((gdb_byte
*) &ret
, sizeof (ret
),
2304 BFD_ENDIAN_BIG
, input
);
2308 static inline uint32_t
2309 netorder32 (uint32_t input
)
2313 store_unsigned_integer ((gdb_byte
*) &ret
, sizeof (ret
),
2314 BFD_ENDIAN_BIG
, input
);
2318 /* Restore the execution log from a core_bfd file. */
2320 record_full_restore (void)
2323 struct record_full_entry
*rec
;
2328 /* We restore the execution log from the open core bfd,
2330 if (core_bfd
== NULL
)
2333 /* "record_full_restore" can only be called when record list is empty. */
2334 gdb_assert (record_full_first
.next
== NULL
);
2337 gdb_printf (gdb_stdlog
, "Restoring recording from core file.\n");
2339 /* Now need to find our special note section. */
2340 osec
= bfd_get_section_by_name (core_bfd
, "null0");
2342 gdb_printf (gdb_stdlog
, "Find precord section %s.\n",
2343 osec
? "succeeded" : "failed");
2346 osec_size
= bfd_section_size (osec
);
2348 gdb_printf (gdb_stdlog
, "%s", bfd_section_name (osec
));
2350 /* Check the magic code. */
2351 bfdcore_read (core_bfd
, osec
, &magic
, sizeof (magic
), &bfd_offset
);
2352 if (magic
!= RECORD_FULL_FILE_MAGIC
)
2353 error (_("Version mis-match or file format error in core file %s."),
2354 bfd_get_filename (core_bfd
));
2356 gdb_printf (gdb_stdlog
,
2357 " Reading 4-byte magic cookie "
2358 "RECORD_FULL_FILE_MAGIC (0x%s)\n",
2359 phex_nz (netorder32 (magic
), 4));
2361 /* Restore the entries in recfd into record_full_arch_list_head and
2362 record_full_arch_list_tail. */
2363 record_full_arch_list_head
= NULL
;
2364 record_full_arch_list_tail
= NULL
;
2365 record_full_insn_num
= 0;
2369 regcache
*regcache
= get_thread_regcache (inferior_thread ());
2374 uint32_t regnum
, len
, signal
, count
;
2377 /* We are finished when offset reaches osec_size. */
2378 if (bfd_offset
>= osec_size
)
2380 bfdcore_read (core_bfd
, osec
, &rectype
, sizeof (rectype
), &bfd_offset
);
2384 case record_full_reg
: /* reg */
2385 /* Get register number to regnum. */
2386 bfdcore_read (core_bfd
, osec
, ®num
,
2387 sizeof (regnum
), &bfd_offset
);
2388 regnum
= netorder32 (regnum
);
2390 rec
= record_full_reg_alloc (regcache
, regnum
);
2393 bfdcore_read (core_bfd
, osec
, record_full_get_loc (rec
),
2394 rec
->u
.reg
.len
, &bfd_offset
);
2397 gdb_printf (gdb_stdlog
,
2398 " Reading register %d (1 "
2399 "plus %lu plus %d bytes)\n",
2401 (unsigned long) sizeof (regnum
),
2405 case record_full_mem
: /* mem */
2407 bfdcore_read (core_bfd
, osec
, &len
,
2408 sizeof (len
), &bfd_offset
);
2409 len
= netorder32 (len
);
2412 bfdcore_read (core_bfd
, osec
, &addr
,
2413 sizeof (addr
), &bfd_offset
);
2414 addr
= netorder64 (addr
);
2416 rec
= record_full_mem_alloc (addr
, len
);
2419 bfdcore_read (core_bfd
, osec
, record_full_get_loc (rec
),
2420 rec
->u
.mem
.len
, &bfd_offset
);
2423 gdb_printf (gdb_stdlog
,
2424 " Reading memory %s (1 plus "
2425 "%lu plus %lu plus %d bytes)\n",
2426 paddress (get_current_arch (),
2428 (unsigned long) sizeof (addr
),
2429 (unsigned long) sizeof (len
),
2433 case record_full_end
: /* end */
2434 rec
= record_full_end_alloc ();
2435 record_full_insn_num
++;
2437 /* Get signal value. */
2438 bfdcore_read (core_bfd
, osec
, &signal
,
2439 sizeof (signal
), &bfd_offset
);
2440 signal
= netorder32 (signal
);
2441 rec
->u
.end
.sigval
= (enum gdb_signal
) signal
;
2443 /* Get insn count. */
2444 bfdcore_read (core_bfd
, osec
, &count
,
2445 sizeof (count
), &bfd_offset
);
2446 count
= netorder32 (count
);
2447 rec
->u
.end
.insn_num
= count
;
2448 record_full_insn_count
= count
+ 1;
2450 gdb_printf (gdb_stdlog
,
2451 " Reading record_full_end (1 + "
2452 "%lu + %lu bytes), offset == %s\n",
2453 (unsigned long) sizeof (signal
),
2454 (unsigned long) sizeof (count
),
2455 paddress (get_current_arch (),
2460 error (_("Bad entry type in core file %s."),
2461 bfd_get_filename (core_bfd
));
2465 /* Add rec to record arch list. */
2466 record_full_arch_list_add (rec
);
2469 catch (const gdb_exception
&ex
)
2471 record_full_list_release (record_full_arch_list_tail
);
2475 /* Add record_full_arch_list_head to the end of record list. */
2476 record_full_first
.next
= record_full_arch_list_head
;
2477 record_full_arch_list_head
->prev
= &record_full_first
;
2478 record_full_arch_list_tail
->next
= NULL
;
2479 record_full_list
= &record_full_first
;
2481 /* Update record_full_insn_max_num. */
2482 if (record_full_insn_num
> record_full_insn_max_num
)
2484 record_full_insn_max_num
= record_full_insn_num
;
2485 warning (_("Auto increase record/replay buffer limit to %u."),
2486 record_full_insn_max_num
);
2490 gdb_printf (_("Restored records from core file %s.\n"),
2491 bfd_get_filename (core_bfd
));
2493 print_stack_frame (get_selected_frame (NULL
), 1, SRC_AND_LOC
, 1);
2496 /* bfdcore_write -- write bytes into a core file section. */
2499 bfdcore_write (bfd
*obfd
, asection
*osec
, void *buf
, int len
, int *offset
)
2501 int ret
= bfd_set_section_contents (obfd
, osec
, buf
, *offset
, len
);
2506 error (_("Failed to write %d bytes to core file %s ('%s')."),
2507 len
, bfd_get_filename (obfd
),
2508 bfd_errmsg (bfd_get_error ()));
2511 /* Restore the execution log from a file. We use a modified elf
2512 corefile format, with an extra section for our data. */
2515 cmd_record_full_restore (const char *args
, int from_tty
)
2517 core_file_command (args
, from_tty
);
2518 record_full_open (args
, from_tty
);
2521 /* Save the execution log to a file. We use a modified elf corefile
2522 format, with an extra section for our data. */
2525 record_full_base_target::save_record (const char *recfilename
)
2527 struct record_full_entry
*cur_record_full_list
;
2529 struct gdbarch
*gdbarch
;
2531 asection
*osec
= NULL
;
2534 /* Open the save file. */
2536 gdb_printf (gdb_stdlog
, "Saving execution log to core file '%s'\n",
2539 /* Open the output file. */
2540 gdb_bfd_ref_ptr
obfd (create_gcore_bfd (recfilename
));
2542 /* Arrange to remove the output file on failure. */
2543 gdb::unlinker
unlink_file (recfilename
);
2545 /* Save the current record entry to "cur_record_full_list". */
2546 cur_record_full_list
= record_full_list
;
2548 /* Get the values of regcache and gdbarch. */
2549 regcache
*regcache
= get_thread_regcache (inferior_thread ());
2550 gdbarch
= regcache
->arch ();
2552 /* Disable the GDB operation record. */
2553 scoped_restore restore_operation_disable
2554 = record_full_gdb_operation_disable_set ();
2556 /* Reverse execute to the begin of record list. */
2559 /* Check for beginning and end of log. */
2560 if (record_full_list
== &record_full_first
)
2563 record_full_exec_insn (regcache
, gdbarch
, record_full_list
);
2565 if (record_full_list
->prev
)
2566 record_full_list
= record_full_list
->prev
;
2569 /* Compute the size needed for the extra bfd section. */
2570 save_size
= 4; /* magic cookie */
2571 for (record_full_list
= record_full_first
.next
; record_full_list
;
2572 record_full_list
= record_full_list
->next
)
2573 switch (record_full_list
->type
)
2575 case record_full_end
:
2576 save_size
+= 1 + 4 + 4;
2578 case record_full_reg
:
2579 save_size
+= 1 + 4 + record_full_list
->u
.reg
.len
;
2581 case record_full_mem
:
2582 save_size
+= 1 + 4 + 8 + record_full_list
->u
.mem
.len
;
2586 /* Make the new bfd section. */
2587 osec
= bfd_make_section_anyway_with_flags (obfd
.get (), "precord",
2591 error (_("Failed to create 'precord' section for corefile %s: %s"),
2593 bfd_errmsg (bfd_get_error ()));
2594 bfd_set_section_size (osec
, save_size
);
2595 bfd_set_section_vma (osec
, 0);
2596 bfd_set_section_alignment (osec
, 0);
2598 /* Save corefile state. */
2599 write_gcore_file (obfd
.get ());
2601 /* Write out the record log. */
2602 /* Write the magic code. */
2603 magic
= RECORD_FULL_FILE_MAGIC
;
2605 gdb_printf (gdb_stdlog
,
2606 " Writing 4-byte magic cookie "
2607 "RECORD_FULL_FILE_MAGIC (0x%s)\n",
2608 phex_nz (magic
, 4));
2609 bfdcore_write (obfd
.get (), osec
, &magic
, sizeof (magic
), &bfd_offset
);
2611 /* Save the entries to recfd and forward execute to the end of
2613 record_full_list
= &record_full_first
;
2617 if (record_full_list
!= &record_full_first
)
2620 uint32_t regnum
, len
, signal
, count
;
2623 type
= record_full_list
->type
;
2624 bfdcore_write (obfd
.get (), osec
, &type
, sizeof (type
), &bfd_offset
);
2626 switch (record_full_list
->type
)
2628 case record_full_reg
: /* reg */
2630 gdb_printf (gdb_stdlog
,
2631 " Writing register %d (1 "
2632 "plus %lu plus %d bytes)\n",
2633 record_full_list
->u
.reg
.num
,
2634 (unsigned long) sizeof (regnum
),
2635 record_full_list
->u
.reg
.len
);
2638 regnum
= netorder32 (record_full_list
->u
.reg
.num
);
2639 bfdcore_write (obfd
.get (), osec
, ®num
,
2640 sizeof (regnum
), &bfd_offset
);
2643 bfdcore_write (obfd
.get (), osec
,
2644 record_full_get_loc (record_full_list
),
2645 record_full_list
->u
.reg
.len
, &bfd_offset
);
2648 case record_full_mem
: /* mem */
2650 gdb_printf (gdb_stdlog
,
2651 " Writing memory %s (1 plus "
2652 "%lu plus %lu plus %d bytes)\n",
2654 record_full_list
->u
.mem
.addr
),
2655 (unsigned long) sizeof (addr
),
2656 (unsigned long) sizeof (len
),
2657 record_full_list
->u
.mem
.len
);
2660 len
= netorder32 (record_full_list
->u
.mem
.len
);
2661 bfdcore_write (obfd
.get (), osec
, &len
, sizeof (len
),
2664 /* Write memaddr. */
2665 addr
= netorder64 (record_full_list
->u
.mem
.addr
);
2666 bfdcore_write (obfd
.get (), osec
, &addr
,
2667 sizeof (addr
), &bfd_offset
);
2670 bfdcore_write (obfd
.get (), osec
,
2671 record_full_get_loc (record_full_list
),
2672 record_full_list
->u
.mem
.len
, &bfd_offset
);
2675 case record_full_end
:
2677 gdb_printf (gdb_stdlog
,
2678 " Writing record_full_end (1 + "
2679 "%lu + %lu bytes)\n",
2680 (unsigned long) sizeof (signal
),
2681 (unsigned long) sizeof (count
));
2682 /* Write signal value. */
2683 signal
= netorder32 (record_full_list
->u
.end
.sigval
);
2684 bfdcore_write (obfd
.get (), osec
, &signal
,
2685 sizeof (signal
), &bfd_offset
);
2687 /* Write insn count. */
2688 count
= netorder32 (record_full_list
->u
.end
.insn_num
);
2689 bfdcore_write (obfd
.get (), osec
, &count
,
2690 sizeof (count
), &bfd_offset
);
2695 /* Execute entry. */
2696 record_full_exec_insn (regcache
, gdbarch
, record_full_list
);
2698 if (record_full_list
->next
)
2699 record_full_list
= record_full_list
->next
;
2704 /* Reverse execute to cur_record_full_list. */
2707 /* Check for beginning and end of log. */
2708 if (record_full_list
== cur_record_full_list
)
2711 record_full_exec_insn (regcache
, gdbarch
, record_full_list
);
2713 if (record_full_list
->prev
)
2714 record_full_list
= record_full_list
->prev
;
2717 unlink_file
.keep ();
2720 gdb_printf (_("Saved core file %s with execution log.\n"),
2724 /* record_full_goto_insn -- rewind the record log (forward or backward,
2725 depending on DIR) to the given entry, changing the program state
2729 record_full_goto_insn (struct record_full_entry
*entry
,
2730 enum exec_direction_kind dir
)
2732 scoped_restore restore_operation_disable
2733 = record_full_gdb_operation_disable_set ();
2734 regcache
*regcache
= get_thread_regcache (inferior_thread ());
2735 struct gdbarch
*gdbarch
= regcache
->arch ();
2737 /* Assume everything is valid: we will hit the entry,
2738 and we will not hit the end of the recording. */
2740 if (dir
== EXEC_FORWARD
)
2741 record_full_list
= record_full_list
->next
;
2745 record_full_exec_insn (regcache
, gdbarch
, record_full_list
);
2746 if (dir
== EXEC_REVERSE
)
2747 record_full_list
= record_full_list
->prev
;
2749 record_full_list
= record_full_list
->next
;
2750 } while (record_full_list
!= entry
);
2753 /* Alias for "target record-full". */
2756 cmd_record_full_start (const char *args
, int from_tty
)
2758 execute_command ("target record-full", from_tty
);
2762 set_record_full_insn_max_num (const char *args
, int from_tty
,
2763 struct cmd_list_element
*c
)
2765 if (record_full_insn_num
> record_full_insn_max_num
)
2767 /* Count down record_full_insn_num while releasing records from list. */
2768 while (record_full_insn_num
> record_full_insn_max_num
)
2770 record_full_list_release_first ();
2771 record_full_insn_num
--;
2776 /* Implement the 'maintenance print record-instruction' command. */
2779 maintenance_print_record_instruction (const char *args
, int from_tty
)
2781 struct record_full_entry
*to_print
= record_full_list
;
2783 if (args
!= nullptr)
2785 int offset
= value_as_long (parse_and_eval (args
));
2788 /* Move forward OFFSET instructions. We know we found the
2789 end of an instruction when to_print->type is record_full_end. */
2790 while (to_print
->next
!= nullptr && offset
> 0)
2792 to_print
= to_print
->next
;
2793 if (to_print
->type
== record_full_end
)
2797 error (_("Not enough recorded history"));
2801 while (to_print
->prev
!= nullptr && offset
< 0)
2803 to_print
= to_print
->prev
;
2804 if (to_print
->type
== record_full_end
)
2808 error (_("Not enough recorded history"));
2811 gdb_assert (to_print
!= nullptr);
2813 gdbarch
*arch
= current_inferior ()->arch ();
2815 /* Go back to the start of the instruction. */
2816 while (to_print
->prev
!= nullptr && to_print
->prev
->type
!= record_full_end
)
2817 to_print
= to_print
->prev
;
2819 /* if we're in the first record, there are no actual instructions
2820 recorded. Warn the user and leave. */
2821 if (to_print
== &record_full_first
)
2822 error (_("Not enough recorded history"));
2824 while (to_print
->type
!= record_full_end
)
2826 switch (to_print
->type
)
2828 case record_full_reg
:
2830 type
*regtype
= gdbarch_register_type (arch
, to_print
->u
.reg
.num
);
2832 = value_from_contents (regtype
,
2833 record_full_get_loc (to_print
));
2834 gdb_printf ("Register %s changed: ",
2835 gdbarch_register_name (arch
, to_print
->u
.reg
.num
));
2836 struct value_print_options opts
;
2837 get_user_print_options (&opts
);
2839 value_print (val
, gdb_stdout
, &opts
);
2843 case record_full_mem
:
2845 gdb_byte
*b
= record_full_get_loc (to_print
);
2846 gdb_printf ("%d bytes of memory at address %s changed from:",
2847 to_print
->u
.mem
.len
,
2848 print_core_address (arch
, to_print
->u
.mem
.addr
));
2849 for (int i
= 0; i
< to_print
->u
.mem
.len
; i
++)
2850 gdb_printf (" %02x", b
[i
]);
2855 to_print
= to_print
->next
;
2859 void _initialize_record_full ();
2861 _initialize_record_full ()
2863 struct cmd_list_element
*c
;
2865 /* Init record_full_first. */
2866 record_full_first
.prev
= NULL
;
2867 record_full_first
.next
= NULL
;
2868 record_full_first
.type
= record_full_end
;
2870 add_target (record_full_target_info
, record_full_open
);
2871 add_deprecated_target_alias (record_full_target_info
, "record");
2872 add_target (record_full_core_target_info
, record_full_open
);
2874 add_prefix_cmd ("full", class_obscure
, cmd_record_full_start
,
2875 _("Start full execution recording."), &record_full_cmdlist
,
2876 0, &record_cmdlist
);
2878 cmd_list_element
*record_full_restore_cmd
2879 = add_cmd ("restore", class_obscure
, cmd_record_full_restore
,
2880 _("Restore the execution log from a file.\n\
2881 Argument is filename. File must be created with 'record save'."),
2882 &record_full_cmdlist
);
2883 set_cmd_completer (record_full_restore_cmd
, filename_completer
);
2885 /* Deprecate the old version without "full" prefix. */
2886 c
= add_alias_cmd ("restore", record_full_restore_cmd
, class_obscure
, 1,
2888 set_cmd_completer (c
, filename_completer
);
2889 deprecate_cmd (c
, "record full restore");
2891 add_setshow_prefix_cmd ("full", class_support
,
2892 _("Set record options."),
2893 _("Show record options."),
2894 &set_record_full_cmdlist
,
2895 &show_record_full_cmdlist
,
2896 &set_record_cmdlist
,
2897 &show_record_cmdlist
);
2899 /* Record instructions number limit command. */
2900 set_show_commands set_record_full_stop_at_limit_cmds
2901 = add_setshow_boolean_cmd ("stop-at-limit", no_class
,
2902 &record_full_stop_at_limit
, _("\
2903 Set whether record/replay stops when record/replay buffer becomes full."), _("\
2904 Show whether record/replay stops when record/replay buffer becomes full."),
2905 _("Default is ON.\n\
2906 When ON, if the record/replay buffer becomes full, ask user what to do.\n\
2907 When OFF, if the record/replay buffer becomes full,\n\
2908 delete the oldest recorded instruction to make room for each new one."),
2910 &set_record_full_cmdlist
,
2911 &show_record_full_cmdlist
);
2913 c
= add_alias_cmd ("stop-at-limit",
2914 set_record_full_stop_at_limit_cmds
.set
, no_class
, 1,
2915 &set_record_cmdlist
);
2916 deprecate_cmd (c
, "set record full stop-at-limit");
2918 c
= add_alias_cmd ("stop-at-limit",
2919 set_record_full_stop_at_limit_cmds
.show
, no_class
, 1,
2920 &show_record_cmdlist
);
2921 deprecate_cmd (c
, "show record full stop-at-limit");
2923 set_show_commands record_full_insn_number_max_cmds
2924 = add_setshow_uinteger_cmd ("insn-number-max", no_class
,
2925 &record_full_insn_max_num
,
2926 _("Set record/replay buffer limit."),
2927 _("Show record/replay buffer limit."), _("\
2928 Set the maximum number of instructions to be stored in the\n\
2929 record/replay buffer. A value of either \"unlimited\" or zero means no\n\
2930 limit. Default is 200000."),
2931 set_record_full_insn_max_num
,
2932 NULL
, &set_record_full_cmdlist
,
2933 &show_record_full_cmdlist
);
2935 c
= add_alias_cmd ("insn-number-max", record_full_insn_number_max_cmds
.set
,
2936 no_class
, 1, &set_record_cmdlist
);
2937 deprecate_cmd (c
, "set record full insn-number-max");
2939 c
= add_alias_cmd ("insn-number-max", record_full_insn_number_max_cmds
.show
,
2940 no_class
, 1, &show_record_cmdlist
);
2941 deprecate_cmd (c
, "show record full insn-number-max");
2943 set_show_commands record_full_memory_query_cmds
2944 = add_setshow_boolean_cmd ("memory-query", no_class
,
2945 &record_full_memory_query
, _("\
2946 Set whether query if PREC cannot record memory change of next instruction."),
2948 Show whether query if PREC cannot record memory change of next instruction."),
2951 When ON, query if PREC cannot record memory change of next instruction."),
2953 &set_record_full_cmdlist
,
2954 &show_record_full_cmdlist
);
2956 c
= add_alias_cmd ("memory-query", record_full_memory_query_cmds
.set
,
2957 no_class
, 1, &set_record_cmdlist
);
2958 deprecate_cmd (c
, "set record full memory-query");
2960 c
= add_alias_cmd ("memory-query", record_full_memory_query_cmds
.show
,
2961 no_class
, 1,&show_record_cmdlist
);
2962 deprecate_cmd (c
, "show record full memory-query");
2964 add_cmd ("record-instruction", class_maintenance
,
2965 maintenance_print_record_instruction
,
2967 Print a recorded instruction.\n\
2968 If no argument is provided, print the last instruction recorded.\n\
2969 If a negative argument is given, prints how the nth previous \
2970 instruction will be undone.\n\
2971 If a positive argument is given, prints \
2972 how the nth following instruction will be redone."), &maintenanceprintlist
);