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
.get (),
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
1222 = current_inferior ()->aspace
.get ();
1224 if (target_stopped_by_watchpoint ())
1226 /* Always interested in watchpoints. */
1228 else if (record_check_stopped_by_breakpoint (aspace
, tmp_pc
,
1231 /* There is a breakpoint here. Let the core
1236 /* This is a single-step trap. Record the
1237 insn and issue another step.
1238 FIXME: this part can be a random SIGTRAP too.
1239 But GDB cannot handle it. */
1242 if (!record_full_message_wrapper_safe (regcache
,
1245 status
->set_stopped (GDB_SIGNAL_0
);
1249 process_stratum_target
*proc_target
1250 = current_inferior ()->process_target ();
1252 if (gdbarch_software_single_step_p (gdbarch
))
1254 /* Try to insert the software single step breakpoint.
1255 If insert success, set step to 0. */
1256 set_executing (proc_target
, inferior_ptid
, false);
1259 set_executing (proc_target
, inferior_ptid
, true);
1262 reinit_frame_cache ();
1263 step
= !insert_single_step_breakpoints (gdbarch
);
1267 gdb_printf (gdb_stdlog
,
1268 "Process record: record_full_wait "
1269 "issuing one more step in the "
1270 "target beneath\n");
1271 ops
->beneath ()->resume (ptid
, step
, GDB_SIGNAL_0
);
1272 proc_target
->commit_resumed_state
= true;
1273 proc_target
->commit_resumed ();
1274 proc_target
->commit_resumed_state
= false;
1279 /* The inferior is broken by a breakpoint or a signal. */
1288 switch_to_thread (current_inferior ()->process_target (),
1289 record_full_resume_ptid
);
1290 regcache
*regcache
= get_thread_regcache (inferior_thread ());
1291 struct gdbarch
*gdbarch
= regcache
->arch ();
1292 const address_space
*aspace
= current_inferior ()->aspace
.get ();
1293 int continue_flag
= 1;
1294 int first_record_full_end
= 1;
1300 record_full_stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
1301 status
->set_stopped (GDB_SIGNAL_0
);
1303 /* Check breakpoint when forward execute. */
1304 if (execution_direction
== EXEC_FORWARD
)
1306 tmp_pc
= regcache_read_pc (regcache
);
1307 if (record_check_stopped_by_breakpoint (aspace
, tmp_pc
,
1308 &record_full_stop_reason
))
1311 gdb_printf (gdb_stdlog
,
1312 "Process record: break at %s.\n",
1313 paddress (gdbarch
, tmp_pc
));
1318 /* If GDB is in terminal_inferior mode, it will not get the
1319 signal. And in GDB replay mode, GDB doesn't need to be
1320 in terminal_inferior mode, because inferior will not
1321 executed. Then set it to terminal_ours to make GDB get
1323 target_terminal::ours ();
1325 /* In EXEC_FORWARD mode, record_full_list points to the tail of prev
1327 if (execution_direction
== EXEC_FORWARD
&& record_full_list
->next
)
1328 record_full_list
= record_full_list
->next
;
1330 /* Loop over the record_full_list, looking for the next place to
1334 /* Check for beginning and end of log. */
1335 if (execution_direction
== EXEC_REVERSE
1336 && record_full_list
== &record_full_first
)
1338 /* Hit beginning of record log in reverse. */
1339 status
->set_no_history ();
1342 if (execution_direction
!= EXEC_REVERSE
1343 && !record_full_list
->next
)
1345 /* Hit end of record log going forward. */
1346 status
->set_no_history ();
1350 record_full_exec_insn (regcache
, gdbarch
, record_full_list
);
1352 if (record_full_list
->type
== record_full_end
)
1354 if (record_debug
> 1)
1357 "Process record: record_full_end %s to "
1359 host_address_to_string (record_full_list
));
1361 if (first_record_full_end
1362 && execution_direction
== EXEC_REVERSE
)
1364 /* When reverse execute, the first
1365 record_full_end is the part of current
1367 first_record_full_end
= 0;
1371 /* In EXEC_REVERSE mode, this is the
1372 record_full_end of prev instruction. In
1373 EXEC_FORWARD mode, this is the
1374 record_full_end of current instruction. */
1376 if (record_full_resume_step
)
1378 if (record_debug
> 1)
1379 gdb_printf (gdb_stdlog
,
1380 "Process record: step.\n");
1384 /* check breakpoint */
1385 tmp_pc
= regcache_read_pc (regcache
);
1386 if (record_check_stopped_by_breakpoint
1387 (aspace
, tmp_pc
, &record_full_stop_reason
))
1390 gdb_printf (gdb_stdlog
,
1391 "Process record: break "
1393 paddress (gdbarch
, tmp_pc
));
1398 if (record_full_stop_reason
1399 == TARGET_STOPPED_BY_WATCHPOINT
)
1402 gdb_printf (gdb_stdlog
,
1403 "Process record: hit hw "
1407 /* Check target signal */
1408 if (record_full_list
->u
.end
.sigval
!= GDB_SIGNAL_0
)
1409 /* FIXME: better way to check */
1416 if (execution_direction
== EXEC_REVERSE
)
1418 if (record_full_list
->prev
)
1419 record_full_list
= record_full_list
->prev
;
1423 if (record_full_list
->next
)
1424 record_full_list
= record_full_list
->next
;
1428 while (continue_flag
);
1431 if (status
->kind () == TARGET_WAITKIND_STOPPED
)
1433 if (record_full_get_sig
)
1434 status
->set_stopped (GDB_SIGNAL_INT
);
1435 else if (record_full_list
->u
.end
.sigval
!= GDB_SIGNAL_0
)
1436 /* FIXME: better way to check */
1437 status
->set_stopped (record_full_list
->u
.end
.sigval
);
1439 status
->set_stopped (GDB_SIGNAL_TRAP
);
1442 catch (const gdb_exception
&ex
)
1444 if (execution_direction
== EXEC_REVERSE
)
1446 if (record_full_list
->next
)
1447 record_full_list
= record_full_list
->next
;
1450 record_full_list
= record_full_list
->prev
;
1456 signal (SIGINT
, handle_sigint
);
1458 return inferior_ptid
;
1462 record_full_base_target::wait (ptid_t ptid
, struct target_waitstatus
*status
,
1463 target_wait_flags options
)
1467 clear_async_event_handler (record_full_async_inferior_event_token
);
1469 return_ptid
= record_full_wait_1 (this, ptid
, status
, options
);
1470 if (status
->kind () != TARGET_WAITKIND_IGNORE
)
1472 /* We're reporting a stop. Make sure any spurious
1473 target_wait(WNOHANG) doesn't advance the target until the
1474 core wants us resumed again. */
1475 record_full_resumed
= 0;
1481 record_full_base_target::stopped_by_watchpoint ()
1483 if (RECORD_FULL_IS_REPLAY
)
1484 return record_full_stop_reason
== TARGET_STOPPED_BY_WATCHPOINT
;
1486 return beneath ()->stopped_by_watchpoint ();
1490 record_full_base_target::stopped_data_address (CORE_ADDR
*addr_p
)
1492 if (RECORD_FULL_IS_REPLAY
)
1495 return this->beneath ()->stopped_data_address (addr_p
);
1498 /* The stopped_by_sw_breakpoint method of target record-full. */
1501 record_full_base_target::stopped_by_sw_breakpoint ()
1503 return record_full_stop_reason
== TARGET_STOPPED_BY_SW_BREAKPOINT
;
1506 /* The supports_stopped_by_sw_breakpoint method of target
1510 record_full_base_target::supports_stopped_by_sw_breakpoint ()
1515 /* The stopped_by_hw_breakpoint method of target record-full. */
1518 record_full_base_target::stopped_by_hw_breakpoint ()
1520 return record_full_stop_reason
== TARGET_STOPPED_BY_HW_BREAKPOINT
;
1523 /* The supports_stopped_by_sw_breakpoint method of target
1527 record_full_base_target::supports_stopped_by_hw_breakpoint ()
1532 /* Record registers change (by user or by GDB) to list as an instruction. */
1535 record_full_registers_change (struct regcache
*regcache
, int regnum
)
1537 /* Check record_full_insn_num. */
1538 record_full_check_insn_num ();
1540 record_full_arch_list_head
= NULL
;
1541 record_full_arch_list_tail
= NULL
;
1547 for (i
= 0; i
< gdbarch_num_regs (regcache
->arch ()); i
++)
1549 if (record_full_arch_list_add_reg (regcache
, i
))
1551 record_full_list_release (record_full_arch_list_tail
);
1552 error (_("Process record: failed to record execution log."));
1558 if (record_full_arch_list_add_reg (regcache
, regnum
))
1560 record_full_list_release (record_full_arch_list_tail
);
1561 error (_("Process record: failed to record execution log."));
1564 if (record_full_arch_list_add_end ())
1566 record_full_list_release (record_full_arch_list_tail
);
1567 error (_("Process record: failed to record execution log."));
1569 record_full_list
->next
= record_full_arch_list_head
;
1570 record_full_arch_list_head
->prev
= record_full_list
;
1571 record_full_list
= record_full_arch_list_tail
;
1573 if (record_full_insn_num
== record_full_insn_max_num
)
1574 record_full_list_release_first ();
1576 record_full_insn_num
++;
1579 /* "store_registers" method for process record target. */
1582 record_full_target::store_registers (struct regcache
*regcache
, int regno
)
1584 if (!record_full_gdb_operation_disable
)
1586 if (RECORD_FULL_IS_REPLAY
)
1590 /* Let user choose if he wants to write register or not. */
1593 query (_("Because GDB is in replay mode, changing the "
1594 "value of a register will make the execution "
1595 "log unusable from this point onward. "
1596 "Change all registers?"));
1599 query (_("Because GDB is in replay mode, changing the value "
1600 "of a register will make the execution log unusable "
1601 "from this point onward. Change register %s?"),
1602 gdbarch_register_name (regcache
->arch (),
1607 /* Invalidate the value of regcache that was set in function
1608 "regcache_raw_write". */
1614 i
< gdbarch_num_regs (regcache
->arch ());
1616 regcache
->invalidate (i
);
1619 regcache
->invalidate (regno
);
1621 error (_("Process record canceled the operation."));
1624 /* Destroy the record from here forward. */
1625 record_full_list_release_following (record_full_list
);
1628 record_full_registers_change (regcache
, regno
);
1630 this->beneath ()->store_registers (regcache
, regno
);
1633 /* "xfer_partial" method. Behavior is conditional on
1634 RECORD_FULL_IS_REPLAY.
1635 In replay mode, we cannot write memory unles we are willing to
1636 invalidate the record/replay log from this point forward. */
1638 enum target_xfer_status
1639 record_full_target::xfer_partial (enum target_object object
,
1640 const char *annex
, gdb_byte
*readbuf
,
1641 const gdb_byte
*writebuf
, ULONGEST offset
,
1642 ULONGEST len
, ULONGEST
*xfered_len
)
1644 if (!record_full_gdb_operation_disable
1645 && (object
== TARGET_OBJECT_MEMORY
1646 || object
== TARGET_OBJECT_RAW_MEMORY
) && writebuf
)
1648 if (RECORD_FULL_IS_REPLAY
)
1650 /* Let user choose if he wants to write memory or not. */
1651 if (!query (_("Because GDB is in replay mode, writing to memory "
1652 "will make the execution log unusable from this "
1653 "point onward. Write memory at address %s?"),
1654 paddress (current_inferior ()->arch (), offset
)))
1655 error (_("Process record canceled the operation."));
1657 /* Destroy the record from here forward. */
1658 record_full_list_release_following (record_full_list
);
1661 /* Check record_full_insn_num */
1662 record_full_check_insn_num ();
1664 /* Record registers change to list as an instruction. */
1665 record_full_arch_list_head
= NULL
;
1666 record_full_arch_list_tail
= NULL
;
1667 if (record_full_arch_list_add_mem (offset
, len
))
1669 record_full_list_release (record_full_arch_list_tail
);
1671 gdb_printf (gdb_stdlog
,
1672 "Process record: failed to record "
1674 return TARGET_XFER_E_IO
;
1676 if (record_full_arch_list_add_end ())
1678 record_full_list_release (record_full_arch_list_tail
);
1680 gdb_printf (gdb_stdlog
,
1681 "Process record: failed to record "
1683 return TARGET_XFER_E_IO
;
1685 record_full_list
->next
= record_full_arch_list_head
;
1686 record_full_arch_list_head
->prev
= record_full_list
;
1687 record_full_list
= record_full_arch_list_tail
;
1689 if (record_full_insn_num
== record_full_insn_max_num
)
1690 record_full_list_release_first ();
1692 record_full_insn_num
++;
1695 return this->beneath ()->xfer_partial (object
, annex
, readbuf
, writebuf
,
1696 offset
, len
, xfered_len
);
1699 /* This structure represents a breakpoint inserted while the record
1700 target is active. We use this to know when to install/remove
1701 breakpoints in/from the target beneath. For example, a breakpoint
1702 may be inserted while recording, but removed when not replaying nor
1703 recording. In that case, the breakpoint had not been inserted on
1704 the target beneath, so we should not try to remove it there. */
1706 struct record_full_breakpoint
1708 record_full_breakpoint (struct address_space
*address_space_
,
1710 bool in_target_beneath_
)
1711 : address_space (address_space_
),
1713 in_target_beneath (in_target_beneath_
)
1717 /* The address and address space the breakpoint was set at. */
1718 struct address_space
*address_space
;
1721 /* True when the breakpoint has been also installed in the target
1722 beneath. This will be false for breakpoints set during replay or
1724 bool in_target_beneath
;
1727 /* The list of breakpoints inserted while the record target is
1729 static std::vector
<record_full_breakpoint
> record_full_breakpoints
;
1731 /* Sync existing breakpoints to record_full_breakpoints. */
1734 record_full_init_record_breakpoints (void)
1736 record_full_breakpoints
.clear ();
1738 for (bp_location
*loc
: all_bp_locations ())
1740 if (loc
->loc_type
!= bp_loc_software_breakpoint
)
1744 record_full_breakpoints
.emplace_back
1745 (loc
->target_info
.placed_address_space
,
1746 loc
->target_info
.placed_address
, 1);
1750 /* Behavior is conditional on RECORD_FULL_IS_REPLAY. We will not actually
1751 insert or remove breakpoints in the real target when replaying, nor
1755 record_full_target::insert_breakpoint (struct gdbarch
*gdbarch
,
1756 struct bp_target_info
*bp_tgt
)
1758 bool in_target_beneath
= false;
1760 if (!RECORD_FULL_IS_REPLAY
)
1762 /* When recording, we currently always single-step, so we don't
1763 really need to install regular breakpoints in the inferior.
1764 However, we do have to insert software single-step
1765 breakpoints, in case the target can't hardware step. To keep
1766 things simple, we always insert. */
1768 scoped_restore restore_operation_disable
1769 = record_full_gdb_operation_disable_set ();
1771 int ret
= this->beneath ()->insert_breakpoint (gdbarch
, bp_tgt
);
1775 in_target_beneath
= true;
1778 /* Use the existing entries if found in order to avoid duplication
1779 in record_full_breakpoints. */
1781 for (const record_full_breakpoint
&bp
: record_full_breakpoints
)
1783 if (bp
.addr
== bp_tgt
->placed_address
1784 && bp
.address_space
== bp_tgt
->placed_address_space
)
1786 gdb_assert (bp
.in_target_beneath
== in_target_beneath
);
1791 record_full_breakpoints
.emplace_back (bp_tgt
->placed_address_space
,
1792 bp_tgt
->placed_address
,
1797 /* "remove_breakpoint" method for process record target. */
1800 record_full_target::remove_breakpoint (struct gdbarch
*gdbarch
,
1801 struct bp_target_info
*bp_tgt
,
1802 enum remove_bp_reason reason
)
1804 for (auto iter
= record_full_breakpoints
.begin ();
1805 iter
!= record_full_breakpoints
.end ();
1808 struct record_full_breakpoint
&bp
= *iter
;
1810 if (bp
.addr
== bp_tgt
->placed_address
1811 && bp
.address_space
== bp_tgt
->placed_address_space
)
1813 if (bp
.in_target_beneath
)
1815 scoped_restore restore_operation_disable
1816 = record_full_gdb_operation_disable_set ();
1818 int ret
= this->beneath ()->remove_breakpoint (gdbarch
, bp_tgt
,
1824 if (reason
== REMOVE_BREAKPOINT
)
1825 unordered_remove (record_full_breakpoints
, iter
);
1830 gdb_assert_not_reached ("removing unknown breakpoint");
1833 /* "can_execute_reverse" method for process record target. */
1836 record_full_base_target::can_execute_reverse ()
1841 /* "get_bookmark" method for process record and prec over core. */
1844 record_full_base_target::get_bookmark (const char *args
, int from_tty
)
1848 /* Return stringified form of instruction count. */
1849 if (record_full_list
&& record_full_list
->type
== record_full_end
)
1850 ret
= xstrdup (pulongest (record_full_list
->u
.end
.insn_num
));
1855 gdb_printf (gdb_stdlog
,
1856 "record_full_get_bookmark returns %s\n", ret
);
1858 gdb_printf (gdb_stdlog
,
1859 "record_full_get_bookmark returns NULL\n");
1861 return (gdb_byte
*) ret
;
1864 /* "goto_bookmark" method for process record and prec over core. */
1867 record_full_base_target::goto_bookmark (const gdb_byte
*raw_bookmark
,
1870 const char *bookmark
= (const char *) raw_bookmark
;
1873 gdb_printf (gdb_stdlog
,
1874 "record_full_goto_bookmark receives %s\n", bookmark
);
1876 std::string name_holder
;
1877 if (bookmark
[0] == '\'' || bookmark
[0] == '\"')
1879 if (bookmark
[strlen (bookmark
) - 1] != bookmark
[0])
1880 error (_("Unbalanced quotes: %s"), bookmark
);
1882 name_holder
= std::string (bookmark
+ 1, strlen (bookmark
) - 2);
1883 bookmark
= name_holder
.c_str ();
1886 record_goto (bookmark
);
1889 enum exec_direction_kind
1890 record_full_base_target::execution_direction ()
1892 return record_full_execution_dir
;
1895 /* The record_method method of target record-full. */
1898 record_full_base_target::record_method (ptid_t ptid
)
1900 return RECORD_METHOD_FULL
;
1904 record_full_base_target::info_record ()
1906 struct record_full_entry
*p
;
1908 if (RECORD_FULL_IS_REPLAY
)
1909 gdb_printf (_("Replay mode:\n"));
1911 gdb_printf (_("Record mode:\n"));
1913 /* Find entry for first actual instruction in the log. */
1914 for (p
= record_full_first
.next
;
1915 p
!= NULL
&& p
->type
!= record_full_end
;
1919 /* Do we have a log at all? */
1920 if (p
!= NULL
&& p
->type
== record_full_end
)
1922 /* Display instruction number for first instruction in the log. */
1923 gdb_printf (_("Lowest recorded instruction number is %s.\n"),
1924 pulongest (p
->u
.end
.insn_num
));
1926 /* If in replay mode, display where we are in the log. */
1927 if (RECORD_FULL_IS_REPLAY
)
1928 gdb_printf (_("Current instruction number is %s.\n"),
1929 pulongest (record_full_list
->u
.end
.insn_num
));
1931 /* Display instruction number for last instruction in the log. */
1932 gdb_printf (_("Highest recorded instruction number is %s.\n"),
1933 pulongest (record_full_insn_count
));
1935 /* Display log count. */
1936 gdb_printf (_("Log contains %u instructions.\n"),
1937 record_full_insn_num
);
1940 gdb_printf (_("No instructions have been logged.\n"));
1942 /* Display max log size. */
1943 gdb_printf (_("Max logged instructions is %u.\n"),
1944 record_full_insn_max_num
);
1948 record_full_base_target::supports_delete_record ()
1953 /* The "delete_record" target method. */
1956 record_full_base_target::delete_record ()
1958 record_full_list_release_following (record_full_list
);
1961 /* The "record_is_replaying" target method. */
1964 record_full_base_target::record_is_replaying (ptid_t ptid
)
1966 return RECORD_FULL_IS_REPLAY
;
1969 /* The "record_will_replay" target method. */
1972 record_full_base_target::record_will_replay (ptid_t ptid
, int dir
)
1974 /* We can currently only record when executing forwards. Should we be able
1975 to record when executing backwards on targets that support reverse
1976 execution, this needs to be changed. */
1978 return RECORD_FULL_IS_REPLAY
|| dir
== EXEC_REVERSE
;
1981 /* Go to a specific entry. */
1984 record_full_goto_entry (struct record_full_entry
*p
)
1987 error (_("Target insn not found."));
1988 else if (p
== record_full_list
)
1989 error (_("Already at target insn."));
1990 else if (p
->u
.end
.insn_num
> record_full_list
->u
.end
.insn_num
)
1992 gdb_printf (_("Go forward to insn number %s\n"),
1993 pulongest (p
->u
.end
.insn_num
));
1994 record_full_goto_insn (p
, EXEC_FORWARD
);
1998 gdb_printf (_("Go backward to insn number %s\n"),
1999 pulongest (p
->u
.end
.insn_num
));
2000 record_full_goto_insn (p
, EXEC_REVERSE
);
2003 registers_changed ();
2004 reinit_frame_cache ();
2006 thread_info
*thr
= inferior_thread ();
2007 thr
->set_stop_pc (regcache_read_pc (get_thread_regcache (thr
)));
2008 print_stack_frame (get_selected_frame (NULL
), 1, SRC_AND_LOC
, 1);
2011 /* The "goto_record_begin" target method. */
2014 record_full_base_target::goto_record_begin ()
2016 struct record_full_entry
*p
= NULL
;
2018 for (p
= &record_full_first
; p
!= NULL
; p
= p
->next
)
2019 if (p
->type
== record_full_end
)
2022 record_full_goto_entry (p
);
2025 /* The "goto_record_end" target method. */
2028 record_full_base_target::goto_record_end ()
2030 struct record_full_entry
*p
= NULL
;
2032 for (p
= record_full_list
; p
->next
!= NULL
; p
= p
->next
)
2034 for (; p
!= NULL
; p
= p
->prev
)
2035 if (p
->type
== record_full_end
)
2038 record_full_goto_entry (p
);
2041 /* The "goto_record" target method. */
2044 record_full_base_target::goto_record (ULONGEST target_insn
)
2046 struct record_full_entry
*p
= NULL
;
2048 for (p
= &record_full_first
; p
!= NULL
; p
= p
->next
)
2049 if (p
->type
== record_full_end
&& p
->u
.end
.insn_num
== target_insn
)
2052 record_full_goto_entry (p
);
2055 /* The "record_stop_replaying" target method. */
2058 record_full_base_target::record_stop_replaying ()
2063 /* "resume" method for prec over corefile. */
2066 record_full_core_target::resume (ptid_t ptid
, int step
,
2067 enum gdb_signal signal
)
2069 record_full_resume_step
= step
;
2070 record_full_resumed
= 1;
2071 record_full_execution_dir
= ::execution_direction
;
2074 /* "kill" method for prec over corefile. */
2077 record_full_core_target::kill ()
2080 gdb_printf (gdb_stdlog
, "Process record: record_full_core_kill\n");
2082 current_inferior ()->unpush_target (this);
2085 /* "fetch_registers" method for prec over corefile. */
2088 record_full_core_target::fetch_registers (struct regcache
*regcache
,
2093 int num
= gdbarch_num_regs (regcache
->arch ());
2096 for (i
= 0; i
< num
; i
++)
2097 regcache
->raw_supply (i
, *record_full_core_regbuf
);
2100 regcache
->raw_supply (regno
, *record_full_core_regbuf
);
2103 /* "prepare_to_store" method for prec over corefile. */
2106 record_full_core_target::prepare_to_store (struct regcache
*regcache
)
2110 /* "store_registers" method for prec over corefile. */
2113 record_full_core_target::store_registers (struct regcache
*regcache
,
2116 if (record_full_gdb_operation_disable
)
2117 record_full_core_regbuf
->raw_supply (regno
, *regcache
);
2119 error (_("You can't do that without a process to debug."));
2122 /* "xfer_partial" method for prec over corefile. */
2124 enum target_xfer_status
2125 record_full_core_target::xfer_partial (enum target_object object
,
2126 const char *annex
, gdb_byte
*readbuf
,
2127 const gdb_byte
*writebuf
, ULONGEST offset
,
2128 ULONGEST len
, ULONGEST
*xfered_len
)
2130 if (object
== TARGET_OBJECT_MEMORY
)
2132 if (record_full_gdb_operation_disable
|| !writebuf
)
2134 for (target_section
&p
: record_full_core_sections
)
2136 if (offset
>= p
.addr
)
2138 struct record_full_core_buf_entry
*entry
;
2139 ULONGEST sec_offset
;
2141 if (offset
>= p
.endaddr
)
2144 if (offset
+ len
> p
.endaddr
)
2145 len
= p
.endaddr
- offset
;
2147 sec_offset
= offset
- p
.addr
;
2149 /* Read readbuf or write writebuf p, offset, len. */
2151 if (p
.the_bfd_section
->flags
& SEC_CONSTRUCTOR
2152 || (p
.the_bfd_section
->flags
& SEC_HAS_CONTENTS
) == 0)
2155 memset (readbuf
, 0, len
);
2158 return TARGET_XFER_OK
;
2160 /* Get record_full_core_buf_entry. */
2161 for (entry
= record_full_core_buf_list
; entry
;
2162 entry
= entry
->prev
)
2169 /* Add a new entry. */
2170 entry
= XNEW (struct record_full_core_buf_entry
);
2172 if (!bfd_malloc_and_get_section
2173 (p
.the_bfd_section
->owner
,
2178 return TARGET_XFER_EOF
;
2180 entry
->prev
= record_full_core_buf_list
;
2181 record_full_core_buf_list
= entry
;
2184 memcpy (entry
->buf
+ sec_offset
, writebuf
,
2190 return this->beneath ()->xfer_partial (object
, annex
,
2195 memcpy (readbuf
, entry
->buf
+ sec_offset
,
2200 return TARGET_XFER_OK
;
2204 return TARGET_XFER_E_IO
;
2207 error (_("You can't do that without a process to debug."));
2210 return this->beneath ()->xfer_partial (object
, annex
,
2211 readbuf
, writebuf
, offset
, len
,
2215 /* "insert_breakpoint" method for prec over corefile. */
2218 record_full_core_target::insert_breakpoint (struct gdbarch
*gdbarch
,
2219 struct bp_target_info
*bp_tgt
)
2224 /* "remove_breakpoint" method for prec over corefile. */
2227 record_full_core_target::remove_breakpoint (struct gdbarch
*gdbarch
,
2228 struct bp_target_info
*bp_tgt
,
2229 enum remove_bp_reason reason
)
2234 /* "has_execution" method for prec over corefile. */
2237 record_full_core_target::has_execution (inferior
*inf
)
2242 /* Record log save-file format
2243 Version 1 (never released)
2246 4 bytes: magic number htonl(0x20090829).
2247 NOTE: be sure to change whenever this file format changes!
2251 1 byte: record type (record_full_end, see enum record_full_type).
2253 1 byte: record type (record_full_reg, see enum record_full_type).
2254 8 bytes: register id (network byte order).
2255 MAX_REGISTER_SIZE bytes: register value.
2257 1 byte: record type (record_full_mem, see enum record_full_type).
2258 8 bytes: memory length (network byte order).
2259 8 bytes: memory address (network byte order).
2260 n bytes: memory value (n == memory length).
2263 4 bytes: magic number netorder32(0x20091016).
2264 NOTE: be sure to change whenever this file format changes!
2268 1 byte: record type (record_full_end, see enum record_full_type).
2270 4 bytes: instruction count
2272 1 byte: record type (record_full_reg, see enum record_full_type).
2273 4 bytes: register id (network byte order).
2274 n bytes: register value (n == actual register size).
2275 (eg. 4 bytes for x86 general registers).
2277 1 byte: record type (record_full_mem, see enum record_full_type).
2278 4 bytes: memory length (network byte order).
2279 8 bytes: memory address (network byte order).
2280 n bytes: memory value (n == memory length).
2284 /* bfdcore_read -- read bytes from a core file section. */
2287 bfdcore_read (bfd
*obfd
, asection
*osec
, void *buf
, int len
, int *offset
)
2289 int ret
= bfd_get_section_contents (obfd
, osec
, buf
, *offset
, len
);
2294 error (_("Failed to read %d bytes from core file %s ('%s')."),
2295 len
, bfd_get_filename (obfd
),
2296 bfd_errmsg (bfd_get_error ()));
2299 static inline uint64_t
2300 netorder64 (uint64_t input
)
2304 store_unsigned_integer ((gdb_byte
*) &ret
, sizeof (ret
),
2305 BFD_ENDIAN_BIG
, input
);
2309 static inline uint32_t
2310 netorder32 (uint32_t input
)
2314 store_unsigned_integer ((gdb_byte
*) &ret
, sizeof (ret
),
2315 BFD_ENDIAN_BIG
, input
);
2319 /* Restore the execution log from a core_bfd file. */
2321 record_full_restore (void)
2324 struct record_full_entry
*rec
;
2329 /* We restore the execution log from the open core bfd,
2331 if (core_bfd
== NULL
)
2334 /* "record_full_restore" can only be called when record list is empty. */
2335 gdb_assert (record_full_first
.next
== NULL
);
2338 gdb_printf (gdb_stdlog
, "Restoring recording from core file.\n");
2340 /* Now need to find our special note section. */
2341 osec
= bfd_get_section_by_name (core_bfd
, "null0");
2343 gdb_printf (gdb_stdlog
, "Find precord section %s.\n",
2344 osec
? "succeeded" : "failed");
2347 osec_size
= bfd_section_size (osec
);
2349 gdb_printf (gdb_stdlog
, "%s", bfd_section_name (osec
));
2351 /* Check the magic code. */
2352 bfdcore_read (core_bfd
, osec
, &magic
, sizeof (magic
), &bfd_offset
);
2353 if (magic
!= RECORD_FULL_FILE_MAGIC
)
2354 error (_("Version mis-match or file format error in core file %s."),
2355 bfd_get_filename (core_bfd
));
2357 gdb_printf (gdb_stdlog
,
2358 " Reading 4-byte magic cookie "
2359 "RECORD_FULL_FILE_MAGIC (0x%s)\n",
2360 phex_nz (netorder32 (magic
), 4));
2362 /* Restore the entries in recfd into record_full_arch_list_head and
2363 record_full_arch_list_tail. */
2364 record_full_arch_list_head
= NULL
;
2365 record_full_arch_list_tail
= NULL
;
2366 record_full_insn_num
= 0;
2370 regcache
*regcache
= get_thread_regcache (inferior_thread ());
2375 uint32_t regnum
, len
, signal
, count
;
2378 /* We are finished when offset reaches osec_size. */
2379 if (bfd_offset
>= osec_size
)
2381 bfdcore_read (core_bfd
, osec
, &rectype
, sizeof (rectype
), &bfd_offset
);
2385 case record_full_reg
: /* reg */
2386 /* Get register number to regnum. */
2387 bfdcore_read (core_bfd
, osec
, ®num
,
2388 sizeof (regnum
), &bfd_offset
);
2389 regnum
= netorder32 (regnum
);
2391 rec
= record_full_reg_alloc (regcache
, regnum
);
2394 bfdcore_read (core_bfd
, osec
, record_full_get_loc (rec
),
2395 rec
->u
.reg
.len
, &bfd_offset
);
2398 gdb_printf (gdb_stdlog
,
2399 " Reading register %d (1 "
2400 "plus %lu plus %d bytes)\n",
2402 (unsigned long) sizeof (regnum
),
2406 case record_full_mem
: /* mem */
2408 bfdcore_read (core_bfd
, osec
, &len
,
2409 sizeof (len
), &bfd_offset
);
2410 len
= netorder32 (len
);
2413 bfdcore_read (core_bfd
, osec
, &addr
,
2414 sizeof (addr
), &bfd_offset
);
2415 addr
= netorder64 (addr
);
2417 rec
= record_full_mem_alloc (addr
, len
);
2420 bfdcore_read (core_bfd
, osec
, record_full_get_loc (rec
),
2421 rec
->u
.mem
.len
, &bfd_offset
);
2424 gdb_printf (gdb_stdlog
,
2425 " Reading memory %s (1 plus "
2426 "%lu plus %lu plus %d bytes)\n",
2427 paddress (get_current_arch (),
2429 (unsigned long) sizeof (addr
),
2430 (unsigned long) sizeof (len
),
2434 case record_full_end
: /* end */
2435 rec
= record_full_end_alloc ();
2436 record_full_insn_num
++;
2438 /* Get signal value. */
2439 bfdcore_read (core_bfd
, osec
, &signal
,
2440 sizeof (signal
), &bfd_offset
);
2441 signal
= netorder32 (signal
);
2442 rec
->u
.end
.sigval
= (enum gdb_signal
) signal
;
2444 /* Get insn count. */
2445 bfdcore_read (core_bfd
, osec
, &count
,
2446 sizeof (count
), &bfd_offset
);
2447 count
= netorder32 (count
);
2448 rec
->u
.end
.insn_num
= count
;
2449 record_full_insn_count
= count
+ 1;
2451 gdb_printf (gdb_stdlog
,
2452 " Reading record_full_end (1 + "
2453 "%lu + %lu bytes), offset == %s\n",
2454 (unsigned long) sizeof (signal
),
2455 (unsigned long) sizeof (count
),
2456 paddress (get_current_arch (),
2461 error (_("Bad entry type in core file %s."),
2462 bfd_get_filename (core_bfd
));
2466 /* Add rec to record arch list. */
2467 record_full_arch_list_add (rec
);
2470 catch (const gdb_exception
&ex
)
2472 record_full_list_release (record_full_arch_list_tail
);
2476 /* Add record_full_arch_list_head to the end of record list. */
2477 record_full_first
.next
= record_full_arch_list_head
;
2478 record_full_arch_list_head
->prev
= &record_full_first
;
2479 record_full_arch_list_tail
->next
= NULL
;
2480 record_full_list
= &record_full_first
;
2482 /* Update record_full_insn_max_num. */
2483 if (record_full_insn_num
> record_full_insn_max_num
)
2485 record_full_insn_max_num
= record_full_insn_num
;
2486 warning (_("Auto increase record/replay buffer limit to %u."),
2487 record_full_insn_max_num
);
2491 gdb_printf (_("Restored records from core file %s.\n"),
2492 bfd_get_filename (core_bfd
));
2494 print_stack_frame (get_selected_frame (NULL
), 1, SRC_AND_LOC
, 1);
2497 /* bfdcore_write -- write bytes into a core file section. */
2500 bfdcore_write (bfd
*obfd
, asection
*osec
, void *buf
, int len
, int *offset
)
2502 int ret
= bfd_set_section_contents (obfd
, osec
, buf
, *offset
, len
);
2507 error (_("Failed to write %d bytes to core file %s ('%s')."),
2508 len
, bfd_get_filename (obfd
),
2509 bfd_errmsg (bfd_get_error ()));
2512 /* Restore the execution log from a file. We use a modified elf
2513 corefile format, with an extra section for our data. */
2516 cmd_record_full_restore (const char *args
, int from_tty
)
2518 core_file_command (args
, from_tty
);
2519 record_full_open (args
, from_tty
);
2522 /* Save the execution log to a file. We use a modified elf corefile
2523 format, with an extra section for our data. */
2526 record_full_base_target::save_record (const char *recfilename
)
2528 struct record_full_entry
*cur_record_full_list
;
2530 struct gdbarch
*gdbarch
;
2532 asection
*osec
= NULL
;
2535 /* Open the save file. */
2537 gdb_printf (gdb_stdlog
, "Saving execution log to core file '%s'\n",
2540 /* Open the output file. */
2541 gdb_bfd_ref_ptr
obfd (create_gcore_bfd (recfilename
));
2543 /* Arrange to remove the output file on failure. */
2544 gdb::unlinker
unlink_file (recfilename
);
2546 /* Save the current record entry to "cur_record_full_list". */
2547 cur_record_full_list
= record_full_list
;
2549 /* Get the values of regcache and gdbarch. */
2550 regcache
*regcache
= get_thread_regcache (inferior_thread ());
2551 gdbarch
= regcache
->arch ();
2553 /* Disable the GDB operation record. */
2554 scoped_restore restore_operation_disable
2555 = record_full_gdb_operation_disable_set ();
2557 /* Reverse execute to the begin of record list. */
2560 /* Check for beginning and end of log. */
2561 if (record_full_list
== &record_full_first
)
2564 record_full_exec_insn (regcache
, gdbarch
, record_full_list
);
2566 if (record_full_list
->prev
)
2567 record_full_list
= record_full_list
->prev
;
2570 /* Compute the size needed for the extra bfd section. */
2571 save_size
= 4; /* magic cookie */
2572 for (record_full_list
= record_full_first
.next
; record_full_list
;
2573 record_full_list
= record_full_list
->next
)
2574 switch (record_full_list
->type
)
2576 case record_full_end
:
2577 save_size
+= 1 + 4 + 4;
2579 case record_full_reg
:
2580 save_size
+= 1 + 4 + record_full_list
->u
.reg
.len
;
2582 case record_full_mem
:
2583 save_size
+= 1 + 4 + 8 + record_full_list
->u
.mem
.len
;
2587 /* Make the new bfd section. */
2588 osec
= bfd_make_section_anyway_with_flags (obfd
.get (), "precord",
2592 error (_("Failed to create 'precord' section for corefile %s: %s"),
2594 bfd_errmsg (bfd_get_error ()));
2595 bfd_set_section_size (osec
, save_size
);
2596 bfd_set_section_vma (osec
, 0);
2597 bfd_set_section_alignment (osec
, 0);
2599 /* Save corefile state. */
2600 write_gcore_file (obfd
.get ());
2602 /* Write out the record log. */
2603 /* Write the magic code. */
2604 magic
= RECORD_FULL_FILE_MAGIC
;
2606 gdb_printf (gdb_stdlog
,
2607 " Writing 4-byte magic cookie "
2608 "RECORD_FULL_FILE_MAGIC (0x%s)\n",
2609 phex_nz (magic
, 4));
2610 bfdcore_write (obfd
.get (), osec
, &magic
, sizeof (magic
), &bfd_offset
);
2612 /* Save the entries to recfd and forward execute to the end of
2614 record_full_list
= &record_full_first
;
2618 if (record_full_list
!= &record_full_first
)
2621 uint32_t regnum
, len
, signal
, count
;
2624 type
= record_full_list
->type
;
2625 bfdcore_write (obfd
.get (), osec
, &type
, sizeof (type
), &bfd_offset
);
2627 switch (record_full_list
->type
)
2629 case record_full_reg
: /* reg */
2631 gdb_printf (gdb_stdlog
,
2632 " Writing register %d (1 "
2633 "plus %lu plus %d bytes)\n",
2634 record_full_list
->u
.reg
.num
,
2635 (unsigned long) sizeof (regnum
),
2636 record_full_list
->u
.reg
.len
);
2639 regnum
= netorder32 (record_full_list
->u
.reg
.num
);
2640 bfdcore_write (obfd
.get (), osec
, ®num
,
2641 sizeof (regnum
), &bfd_offset
);
2644 bfdcore_write (obfd
.get (), osec
,
2645 record_full_get_loc (record_full_list
),
2646 record_full_list
->u
.reg
.len
, &bfd_offset
);
2649 case record_full_mem
: /* mem */
2651 gdb_printf (gdb_stdlog
,
2652 " Writing memory %s (1 plus "
2653 "%lu plus %lu plus %d bytes)\n",
2655 record_full_list
->u
.mem
.addr
),
2656 (unsigned long) sizeof (addr
),
2657 (unsigned long) sizeof (len
),
2658 record_full_list
->u
.mem
.len
);
2661 len
= netorder32 (record_full_list
->u
.mem
.len
);
2662 bfdcore_write (obfd
.get (), osec
, &len
, sizeof (len
),
2665 /* Write memaddr. */
2666 addr
= netorder64 (record_full_list
->u
.mem
.addr
);
2667 bfdcore_write (obfd
.get (), osec
, &addr
,
2668 sizeof (addr
), &bfd_offset
);
2671 bfdcore_write (obfd
.get (), osec
,
2672 record_full_get_loc (record_full_list
),
2673 record_full_list
->u
.mem
.len
, &bfd_offset
);
2676 case record_full_end
:
2678 gdb_printf (gdb_stdlog
,
2679 " Writing record_full_end (1 + "
2680 "%lu + %lu bytes)\n",
2681 (unsigned long) sizeof (signal
),
2682 (unsigned long) sizeof (count
));
2683 /* Write signal value. */
2684 signal
= netorder32 (record_full_list
->u
.end
.sigval
);
2685 bfdcore_write (obfd
.get (), osec
, &signal
,
2686 sizeof (signal
), &bfd_offset
);
2688 /* Write insn count. */
2689 count
= netorder32 (record_full_list
->u
.end
.insn_num
);
2690 bfdcore_write (obfd
.get (), osec
, &count
,
2691 sizeof (count
), &bfd_offset
);
2696 /* Execute entry. */
2697 record_full_exec_insn (regcache
, gdbarch
, record_full_list
);
2699 if (record_full_list
->next
)
2700 record_full_list
= record_full_list
->next
;
2705 /* Reverse execute to cur_record_full_list. */
2708 /* Check for beginning and end of log. */
2709 if (record_full_list
== cur_record_full_list
)
2712 record_full_exec_insn (regcache
, gdbarch
, record_full_list
);
2714 if (record_full_list
->prev
)
2715 record_full_list
= record_full_list
->prev
;
2718 unlink_file
.keep ();
2721 gdb_printf (_("Saved core file %s with execution log.\n"),
2725 /* record_full_goto_insn -- rewind the record log (forward or backward,
2726 depending on DIR) to the given entry, changing the program state
2730 record_full_goto_insn (struct record_full_entry
*entry
,
2731 enum exec_direction_kind dir
)
2733 scoped_restore restore_operation_disable
2734 = record_full_gdb_operation_disable_set ();
2735 regcache
*regcache
= get_thread_regcache (inferior_thread ());
2736 struct gdbarch
*gdbarch
= regcache
->arch ();
2738 /* Assume everything is valid: we will hit the entry,
2739 and we will not hit the end of the recording. */
2741 if (dir
== EXEC_FORWARD
)
2742 record_full_list
= record_full_list
->next
;
2746 record_full_exec_insn (regcache
, gdbarch
, record_full_list
);
2747 if (dir
== EXEC_REVERSE
)
2748 record_full_list
= record_full_list
->prev
;
2750 record_full_list
= record_full_list
->next
;
2751 } while (record_full_list
!= entry
);
2754 /* Alias for "target record-full". */
2757 cmd_record_full_start (const char *args
, int from_tty
)
2759 execute_command ("target record-full", from_tty
);
2763 set_record_full_insn_max_num (const char *args
, int from_tty
,
2764 struct cmd_list_element
*c
)
2766 if (record_full_insn_num
> record_full_insn_max_num
)
2768 /* Count down record_full_insn_num while releasing records from list. */
2769 while (record_full_insn_num
> record_full_insn_max_num
)
2771 record_full_list_release_first ();
2772 record_full_insn_num
--;
2777 /* Implement the 'maintenance print record-instruction' command. */
2780 maintenance_print_record_instruction (const char *args
, int from_tty
)
2782 struct record_full_entry
*to_print
= record_full_list
;
2784 if (args
!= nullptr)
2786 int offset
= value_as_long (parse_and_eval (args
));
2789 /* Move forward OFFSET instructions. We know we found the
2790 end of an instruction when to_print->type is record_full_end. */
2791 while (to_print
->next
!= nullptr && offset
> 0)
2793 to_print
= to_print
->next
;
2794 if (to_print
->type
== record_full_end
)
2798 error (_("Not enough recorded history"));
2802 while (to_print
->prev
!= nullptr && offset
< 0)
2804 to_print
= to_print
->prev
;
2805 if (to_print
->type
== record_full_end
)
2809 error (_("Not enough recorded history"));
2812 gdb_assert (to_print
!= nullptr);
2814 gdbarch
*arch
= current_inferior ()->arch ();
2816 /* Go back to the start of the instruction. */
2817 while (to_print
->prev
!= nullptr && to_print
->prev
->type
!= record_full_end
)
2818 to_print
= to_print
->prev
;
2820 /* if we're in the first record, there are no actual instructions
2821 recorded. Warn the user and leave. */
2822 if (to_print
== &record_full_first
)
2823 error (_("Not enough recorded history"));
2825 while (to_print
->type
!= record_full_end
)
2827 switch (to_print
->type
)
2829 case record_full_reg
:
2831 type
*regtype
= gdbarch_register_type (arch
, to_print
->u
.reg
.num
);
2833 = value_from_contents (regtype
,
2834 record_full_get_loc (to_print
));
2835 gdb_printf ("Register %s changed: ",
2836 gdbarch_register_name (arch
, to_print
->u
.reg
.num
));
2837 struct value_print_options opts
;
2838 get_user_print_options (&opts
);
2840 value_print (val
, gdb_stdout
, &opts
);
2844 case record_full_mem
:
2846 gdb_byte
*b
= record_full_get_loc (to_print
);
2847 gdb_printf ("%d bytes of memory at address %s changed from:",
2848 to_print
->u
.mem
.len
,
2849 print_core_address (arch
, to_print
->u
.mem
.addr
));
2850 for (int i
= 0; i
< to_print
->u
.mem
.len
; i
++)
2851 gdb_printf (" %02x", b
[i
]);
2856 to_print
= to_print
->next
;
2860 void _initialize_record_full ();
2862 _initialize_record_full ()
2864 struct cmd_list_element
*c
;
2866 /* Init record_full_first. */
2867 record_full_first
.prev
= NULL
;
2868 record_full_first
.next
= NULL
;
2869 record_full_first
.type
= record_full_end
;
2871 add_target (record_full_target_info
, record_full_open
);
2872 add_deprecated_target_alias (record_full_target_info
, "record");
2873 add_target (record_full_core_target_info
, record_full_open
);
2875 add_prefix_cmd ("full", class_obscure
, cmd_record_full_start
,
2876 _("Start full execution recording."), &record_full_cmdlist
,
2877 0, &record_cmdlist
);
2879 cmd_list_element
*record_full_restore_cmd
2880 = add_cmd ("restore", class_obscure
, cmd_record_full_restore
,
2881 _("Restore the execution log from a file.\n\
2882 Argument is filename. File must be created with 'record save'."),
2883 &record_full_cmdlist
);
2884 set_cmd_completer (record_full_restore_cmd
, filename_completer
);
2886 /* Deprecate the old version without "full" prefix. */
2887 c
= add_alias_cmd ("restore", record_full_restore_cmd
, class_obscure
, 1,
2889 set_cmd_completer (c
, filename_completer
);
2890 deprecate_cmd (c
, "record full restore");
2892 add_setshow_prefix_cmd ("full", class_support
,
2893 _("Set record options."),
2894 _("Show record options."),
2895 &set_record_full_cmdlist
,
2896 &show_record_full_cmdlist
,
2897 &set_record_cmdlist
,
2898 &show_record_cmdlist
);
2900 /* Record instructions number limit command. */
2901 set_show_commands set_record_full_stop_at_limit_cmds
2902 = add_setshow_boolean_cmd ("stop-at-limit", no_class
,
2903 &record_full_stop_at_limit
, _("\
2904 Set whether record/replay stops when record/replay buffer becomes full."), _("\
2905 Show whether record/replay stops when record/replay buffer becomes full."),
2906 _("Default is ON.\n\
2907 When ON, if the record/replay buffer becomes full, ask user what to do.\n\
2908 When OFF, if the record/replay buffer becomes full,\n\
2909 delete the oldest recorded instruction to make room for each new one."),
2911 &set_record_full_cmdlist
,
2912 &show_record_full_cmdlist
);
2914 c
= add_alias_cmd ("stop-at-limit",
2915 set_record_full_stop_at_limit_cmds
.set
, no_class
, 1,
2916 &set_record_cmdlist
);
2917 deprecate_cmd (c
, "set record full stop-at-limit");
2919 c
= add_alias_cmd ("stop-at-limit",
2920 set_record_full_stop_at_limit_cmds
.show
, no_class
, 1,
2921 &show_record_cmdlist
);
2922 deprecate_cmd (c
, "show record full stop-at-limit");
2924 set_show_commands record_full_insn_number_max_cmds
2925 = add_setshow_uinteger_cmd ("insn-number-max", no_class
,
2926 &record_full_insn_max_num
,
2927 _("Set record/replay buffer limit."),
2928 _("Show record/replay buffer limit."), _("\
2929 Set the maximum number of instructions to be stored in the\n\
2930 record/replay buffer. A value of either \"unlimited\" or zero means no\n\
2931 limit. Default is 200000."),
2932 set_record_full_insn_max_num
,
2933 NULL
, &set_record_full_cmdlist
,
2934 &show_record_full_cmdlist
);
2936 c
= add_alias_cmd ("insn-number-max", record_full_insn_number_max_cmds
.set
,
2937 no_class
, 1, &set_record_cmdlist
);
2938 deprecate_cmd (c
, "set record full insn-number-max");
2940 c
= add_alias_cmd ("insn-number-max", record_full_insn_number_max_cmds
.show
,
2941 no_class
, 1, &show_record_cmdlist
);
2942 deprecate_cmd (c
, "show record full insn-number-max");
2944 set_show_commands record_full_memory_query_cmds
2945 = add_setshow_boolean_cmd ("memory-query", no_class
,
2946 &record_full_memory_query
, _("\
2947 Set whether query if PREC cannot record memory change of next instruction."),
2949 Show whether query if PREC cannot record memory change of next instruction."),
2952 When ON, query if PREC cannot record memory change of next instruction."),
2954 &set_record_full_cmdlist
,
2955 &show_record_full_cmdlist
);
2957 c
= add_alias_cmd ("memory-query", record_full_memory_query_cmds
.set
,
2958 no_class
, 1, &set_record_cmdlist
);
2959 deprecate_cmd (c
, "set record full memory-query");
2961 c
= add_alias_cmd ("memory-query", record_full_memory_query_cmds
.show
,
2962 no_class
, 1,&show_record_cmdlist
);
2963 deprecate_cmd (c
, "show record full memory-query");
2965 add_cmd ("record-instruction", class_maintenance
,
2966 maintenance_print_record_instruction
,
2968 Print a recorded instruction.\n\
2969 If no argument is provided, print the last instruction recorded.\n\
2970 If a negative argument is given, prints how the nth previous \
2971 instruction will be undone.\n\
2972 If a positive argument is given, prints \
2973 how the nth following instruction will be redone."), &maintenanceprintlist
);