1 /* Process record and replay target for GDB, the GNU debugger.
3 Copyright (C) 2013-2022 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"
45 /* This module implements "target record-full", also known as "process
46 record and replay". This target sits on top of a "normal" target
47 (a target that "has execution"), and provides a record and replay
48 functionality, including reverse debugging.
50 Target record has two modes: recording, and replaying.
52 In record mode, we intercept the resume and wait methods.
53 Whenever gdb resumes the target, we run the target in single step
54 mode, and we build up an execution log in which, for each executed
55 instruction, we record all changes in memory and register state.
56 This is invisible to the user, to whom it just looks like an
57 ordinary debugging session (except for performance degradation).
59 In replay mode, instead of actually letting the inferior run as a
60 process, we simulate its execution by playing back the recorded
61 execution log. For each instruction in the log, we simulate the
62 instruction's side effects by duplicating the changes that it would
63 have made on memory and registers. */
65 #define DEFAULT_RECORD_FULL_INSN_MAX_NUM 200000
67 #define RECORD_FULL_IS_REPLAY \
68 (record_full_list->next || ::execution_direction == EXEC_REVERSE)
70 #define RECORD_FULL_FILE_MAGIC netorder32(0x20091016)
72 /* These are the core structs of the process record functionality.
74 A record_full_entry is a record of the value change of a register
75 ("record_full_reg") or a part of memory ("record_full_mem"). And each
76 instruction must have a struct record_full_entry ("record_full_end")
77 that indicates that this is the last struct record_full_entry of this
80 Each struct record_full_entry is linked to "record_full_list" by "prev"
81 and "next" pointers. */
83 struct record_full_mem_entry
87 /* Set this flag if target memory for this entry
88 can no longer be accessed. */
89 int mem_entry_not_accessible
;
93 gdb_byte buf
[sizeof (gdb_byte
*)];
97 struct record_full_reg_entry
104 gdb_byte buf
[2 * sizeof (gdb_byte
*)];
108 struct record_full_end_entry
110 enum gdb_signal sigval
;
114 enum record_full_type
121 /* This is the data structure that makes up the execution log.
123 The execution log consists of a single linked list of entries
124 of type "struct record_full_entry". It is doubly linked so that it
125 can be traversed in either direction.
127 The start of the list is anchored by a struct called
128 "record_full_first". The pointer "record_full_list" either points
129 to the last entry that was added to the list (in record mode), or to
130 the next entry in the list that will be executed (in replay mode).
132 Each list element (struct record_full_entry), in addition to next
133 and prev pointers, consists of a union of three entry types: mem,
134 reg, and end. A field called "type" determines which entry type is
135 represented by a given list element.
137 Each instruction that is added to the execution log is represented
138 by a variable number of list elements ('entries'). The instruction
139 will have one "reg" entry for each register that is changed by
140 executing the instruction (including the PC in every case). It
141 will also have one "mem" entry for each memory change. Finally,
142 each instruction will have an "end" entry that separates it from
143 the changes associated with the next instruction. */
145 struct record_full_entry
147 struct record_full_entry
*prev
;
148 struct record_full_entry
*next
;
149 enum record_full_type type
;
153 struct record_full_reg_entry reg
;
155 struct record_full_mem_entry mem
;
157 struct record_full_end_entry end
;
161 /* If true, query if PREC cannot record memory
162 change of next instruction. */
163 bool record_full_memory_query
= false;
165 struct record_full_core_buf_entry
167 struct record_full_core_buf_entry
*prev
;
168 struct target_section
*p
;
172 /* Record buf with core target. */
173 static detached_regcache
*record_full_core_regbuf
= NULL
;
174 static target_section_table record_full_core_sections
;
175 static struct record_full_core_buf_entry
*record_full_core_buf_list
= NULL
;
177 /* The following variables are used for managing the linked list that
178 represents the execution log.
180 record_full_first is the anchor that holds down the beginning of
183 record_full_list serves two functions:
184 1) In record mode, it anchors the end of the list.
185 2) In replay mode, it traverses the list and points to
186 the next instruction that must be emulated.
188 record_full_arch_list_head and record_full_arch_list_tail are used
189 to manage a separate list, which is used to build up the change
190 elements of the currently executing instruction during record mode.
191 When this instruction has been completely annotated in the "arch
192 list", it will be appended to the main execution log. */
194 static struct record_full_entry record_full_first
;
195 static struct record_full_entry
*record_full_list
= &record_full_first
;
196 static struct record_full_entry
*record_full_arch_list_head
= NULL
;
197 static struct record_full_entry
*record_full_arch_list_tail
= NULL
;
199 /* true ask user. false auto delete the last struct record_full_entry. */
200 static bool record_full_stop_at_limit
= true;
201 /* Maximum allowed number of insns in execution log. */
202 static unsigned int record_full_insn_max_num
203 = DEFAULT_RECORD_FULL_INSN_MAX_NUM
;
204 /* Actual count of insns presently in execution log. */
205 static unsigned int record_full_insn_num
= 0;
206 /* Count of insns logged so far (may be larger
207 than count of insns presently in execution log). */
208 static ULONGEST record_full_insn_count
;
210 static const char record_longname
[]
211 = N_("Process record and replay target");
212 static const char record_doc
[]
213 = N_("Log program while executing and replay execution from log.");
215 /* Base class implementing functionality common to both the
216 "record-full" and "record-core" targets. */
218 class record_full_base_target
: public target_ops
221 const target_info
&info () const override
= 0;
223 strata
stratum () const override
{ return record_stratum
; }
225 void close () override
;
226 void async (int) override
;
227 ptid_t
wait (ptid_t
, struct target_waitstatus
*, target_wait_flags
) override
;
228 bool stopped_by_watchpoint () override
;
229 bool stopped_data_address (CORE_ADDR
*) override
;
231 bool stopped_by_sw_breakpoint () override
;
232 bool supports_stopped_by_sw_breakpoint () override
;
234 bool stopped_by_hw_breakpoint () override
;
235 bool supports_stopped_by_hw_breakpoint () override
;
237 bool can_execute_reverse () override
;
239 /* Add bookmark target methods. */
240 gdb_byte
*get_bookmark (const char *, int) override
;
241 void goto_bookmark (const gdb_byte
*, int) override
;
242 enum exec_direction_kind
execution_direction () override
;
243 enum record_method
record_method (ptid_t ptid
) override
;
244 void info_record () override
;
245 void save_record (const char *filename
) override
;
246 bool supports_delete_record () override
;
247 void delete_record () override
;
248 bool record_is_replaying (ptid_t ptid
) override
;
249 bool record_will_replay (ptid_t ptid
, int dir
) override
;
250 void record_stop_replaying () override
;
251 void goto_record_begin () override
;
252 void goto_record_end () override
;
253 void goto_record (ULONGEST insn
) override
;
256 /* The "record-full" target. */
258 static const target_info record_full_target_info
= {
264 class record_full_target final
: public record_full_base_target
267 const target_info
&info () const override
268 { return record_full_target_info
; }
270 void resume (ptid_t
, int, enum gdb_signal
) override
;
271 void disconnect (const char *, int) override
;
272 void detach (inferior
*, int) override
;
273 void mourn_inferior () override
;
274 void kill () override
;
275 void store_registers (struct regcache
*, int) override
;
276 enum target_xfer_status
xfer_partial (enum target_object object
,
279 const gdb_byte
*writebuf
,
280 ULONGEST offset
, ULONGEST len
,
281 ULONGEST
*xfered_len
) override
;
282 int insert_breakpoint (struct gdbarch
*,
283 struct bp_target_info
*) override
;
284 int remove_breakpoint (struct gdbarch
*,
285 struct bp_target_info
*,
286 enum remove_bp_reason
) override
;
289 /* The "record-core" target. */
291 static const target_info record_full_core_target_info
= {
297 class record_full_core_target final
: public record_full_base_target
300 const target_info
&info () const override
301 { return record_full_core_target_info
; }
303 void resume (ptid_t
, int, enum gdb_signal
) override
;
304 void disconnect (const char *, int) override
;
305 void kill () override
;
306 void fetch_registers (struct regcache
*regcache
, int regno
) override
;
307 void prepare_to_store (struct regcache
*regcache
) override
;
308 void store_registers (struct regcache
*, int) override
;
309 enum target_xfer_status
xfer_partial (enum target_object object
,
312 const gdb_byte
*writebuf
,
313 ULONGEST offset
, ULONGEST len
,
314 ULONGEST
*xfered_len
) override
;
315 int insert_breakpoint (struct gdbarch
*,
316 struct bp_target_info
*) override
;
317 int remove_breakpoint (struct gdbarch
*,
318 struct bp_target_info
*,
319 enum remove_bp_reason
) override
;
321 bool has_execution (inferior
*inf
) override
;
324 static record_full_target record_full_ops
;
325 static record_full_core_target record_full_core_ops
;
328 record_full_target::detach (inferior
*inf
, int from_tty
)
330 record_detach (this, inf
, from_tty
);
334 record_full_target::disconnect (const char *args
, int from_tty
)
336 record_disconnect (this, args
, from_tty
);
340 record_full_core_target::disconnect (const char *args
, int from_tty
)
342 record_disconnect (this, args
, from_tty
);
346 record_full_target::mourn_inferior ()
348 record_mourn_inferior (this);
352 record_full_target::kill ()
357 /* See record-full.h. */
360 record_full_is_used (void)
362 struct target_ops
*t
;
364 t
= find_record_target ();
365 return (t
== &record_full_ops
366 || t
== &record_full_core_ops
);
370 /* Command lists for "set/show record full". */
371 static struct cmd_list_element
*set_record_full_cmdlist
;
372 static struct cmd_list_element
*show_record_full_cmdlist
;
374 /* Command list for "record full". */
375 static struct cmd_list_element
*record_full_cmdlist
;
377 static void record_full_goto_insn (struct record_full_entry
*entry
,
378 enum exec_direction_kind dir
);
380 /* Alloc and free functions for record_full_reg, record_full_mem, and
381 record_full_end entries. */
383 /* Alloc a record_full_reg record entry. */
385 static inline struct record_full_entry
*
386 record_full_reg_alloc (struct regcache
*regcache
, int regnum
)
388 struct record_full_entry
*rec
;
389 struct gdbarch
*gdbarch
= regcache
->arch ();
391 rec
= XCNEW (struct record_full_entry
);
392 rec
->type
= record_full_reg
;
393 rec
->u
.reg
.num
= regnum
;
394 rec
->u
.reg
.len
= register_size (gdbarch
, regnum
);
395 if (rec
->u
.reg
.len
> sizeof (rec
->u
.reg
.u
.buf
))
396 rec
->u
.reg
.u
.ptr
= (gdb_byte
*) xmalloc (rec
->u
.reg
.len
);
401 /* Free a record_full_reg record entry. */
404 record_full_reg_release (struct record_full_entry
*rec
)
406 gdb_assert (rec
->type
== record_full_reg
);
407 if (rec
->u
.reg
.len
> sizeof (rec
->u
.reg
.u
.buf
))
408 xfree (rec
->u
.reg
.u
.ptr
);
412 /* Alloc a record_full_mem record entry. */
414 static inline struct record_full_entry
*
415 record_full_mem_alloc (CORE_ADDR addr
, int len
)
417 struct record_full_entry
*rec
;
419 rec
= XCNEW (struct record_full_entry
);
420 rec
->type
= record_full_mem
;
421 rec
->u
.mem
.addr
= addr
;
422 rec
->u
.mem
.len
= len
;
423 if (rec
->u
.mem
.len
> sizeof (rec
->u
.mem
.u
.buf
))
424 rec
->u
.mem
.u
.ptr
= (gdb_byte
*) xmalloc (len
);
429 /* Free a record_full_mem record entry. */
432 record_full_mem_release (struct record_full_entry
*rec
)
434 gdb_assert (rec
->type
== record_full_mem
);
435 if (rec
->u
.mem
.len
> sizeof (rec
->u
.mem
.u
.buf
))
436 xfree (rec
->u
.mem
.u
.ptr
);
440 /* Alloc a record_full_end record entry. */
442 static inline struct record_full_entry
*
443 record_full_end_alloc (void)
445 struct record_full_entry
*rec
;
447 rec
= XCNEW (struct record_full_entry
);
448 rec
->type
= record_full_end
;
453 /* Free a record_full_end record entry. */
456 record_full_end_release (struct record_full_entry
*rec
)
461 /* Free one record entry, any type.
462 Return entry->type, in case caller wants to know. */
464 static inline enum record_full_type
465 record_full_entry_release (struct record_full_entry
*rec
)
467 enum record_full_type type
= rec
->type
;
470 case record_full_reg
:
471 record_full_reg_release (rec
);
473 case record_full_mem
:
474 record_full_mem_release (rec
);
476 case record_full_end
:
477 record_full_end_release (rec
);
483 /* Free all record entries in list pointed to by REC. */
486 record_full_list_release (struct record_full_entry
*rec
)
497 record_full_entry_release (rec
->next
);
500 if (rec
== &record_full_first
)
502 record_full_insn_num
= 0;
503 record_full_first
.next
= NULL
;
506 record_full_entry_release (rec
);
509 /* Free all record entries forward of the given list position. */
512 record_full_list_release_following (struct record_full_entry
*rec
)
514 struct record_full_entry
*tmp
= rec
->next
;
520 if (record_full_entry_release (tmp
) == record_full_end
)
522 record_full_insn_num
--;
523 record_full_insn_count
--;
529 /* Delete the first instruction from the beginning of the log, to make
530 room for adding a new instruction at the end of the log.
532 Note -- this function does not modify record_full_insn_num. */
535 record_full_list_release_first (void)
537 struct record_full_entry
*tmp
;
539 if (!record_full_first
.next
)
542 /* Loop until a record_full_end. */
545 /* Cut record_full_first.next out of the linked list. */
546 tmp
= record_full_first
.next
;
547 record_full_first
.next
= tmp
->next
;
548 tmp
->next
->prev
= &record_full_first
;
550 /* tmp is now isolated, and can be deleted. */
551 if (record_full_entry_release (tmp
) == record_full_end
)
552 break; /* End loop at first record_full_end. */
554 if (!record_full_first
.next
)
556 gdb_assert (record_full_insn_num
== 1);
557 break; /* End loop when list is empty. */
562 /* Add a struct record_full_entry to record_full_arch_list. */
565 record_full_arch_list_add (struct record_full_entry
*rec
)
567 if (record_debug
> 1)
568 fprintf_unfiltered (gdb_stdlog
,
569 "Process record: record_full_arch_list_add %s.\n",
570 host_address_to_string (rec
));
572 if (record_full_arch_list_tail
)
574 record_full_arch_list_tail
->next
= rec
;
575 rec
->prev
= record_full_arch_list_tail
;
576 record_full_arch_list_tail
= rec
;
580 record_full_arch_list_head
= rec
;
581 record_full_arch_list_tail
= rec
;
585 /* Return the value storage location of a record entry. */
586 static inline gdb_byte
*
587 record_full_get_loc (struct record_full_entry
*rec
)
590 case record_full_mem
:
591 if (rec
->u
.mem
.len
> sizeof (rec
->u
.mem
.u
.buf
))
592 return rec
->u
.mem
.u
.ptr
;
594 return rec
->u
.mem
.u
.buf
;
595 case record_full_reg
:
596 if (rec
->u
.reg
.len
> sizeof (rec
->u
.reg
.u
.buf
))
597 return rec
->u
.reg
.u
.ptr
;
599 return rec
->u
.reg
.u
.buf
;
600 case record_full_end
:
602 gdb_assert_not_reached ("unexpected record_full_entry type");
607 /* Record the value of a register NUM to record_full_arch_list. */
610 record_full_arch_list_add_reg (struct regcache
*regcache
, int regnum
)
612 struct record_full_entry
*rec
;
614 if (record_debug
> 1)
615 fprintf_unfiltered (gdb_stdlog
,
616 "Process record: add register num = %d to "
620 rec
= record_full_reg_alloc (regcache
, regnum
);
622 regcache
->raw_read (regnum
, record_full_get_loc (rec
));
624 record_full_arch_list_add (rec
);
629 /* Record the value of a region of memory whose address is ADDR and
630 length is LEN to record_full_arch_list. */
633 record_full_arch_list_add_mem (CORE_ADDR addr
, int len
)
635 struct record_full_entry
*rec
;
637 if (record_debug
> 1)
638 fprintf_unfiltered (gdb_stdlog
,
639 "Process record: add mem addr = %s len = %d to "
641 paddress (target_gdbarch (), addr
), len
);
643 if (!addr
) /* FIXME: Why? Some arch must permit it... */
646 rec
= record_full_mem_alloc (addr
, len
);
648 if (record_read_memory (target_gdbarch (), addr
,
649 record_full_get_loc (rec
), len
))
651 record_full_mem_release (rec
);
655 record_full_arch_list_add (rec
);
660 /* Add a record_full_end type struct record_full_entry to
661 record_full_arch_list. */
664 record_full_arch_list_add_end (void)
666 struct record_full_entry
*rec
;
668 if (record_debug
> 1)
669 fprintf_unfiltered (gdb_stdlog
,
670 "Process record: add end to arch list.\n");
672 rec
= record_full_end_alloc ();
673 rec
->u
.end
.sigval
= GDB_SIGNAL_0
;
674 rec
->u
.end
.insn_num
= ++record_full_insn_count
;
676 record_full_arch_list_add (rec
);
682 record_full_check_insn_num (void)
684 if (record_full_insn_num
== record_full_insn_max_num
)
686 /* Ask user what to do. */
687 if (record_full_stop_at_limit
)
689 if (!yquery (_("Do you want to auto delete previous execution "
690 "log entries when record/replay buffer becomes "
691 "full (record full stop-at-limit)?")))
692 error (_("Process record: stopped by user."));
693 record_full_stop_at_limit
= 0;
698 /* Before inferior step (when GDB record the running message, inferior
699 only can step), GDB will call this function to record the values to
700 record_full_list. This function will call gdbarch_process_record to
701 record the running message of inferior and set them to
702 record_full_arch_list, and add it to record_full_list. */
705 record_full_message (struct regcache
*regcache
, enum gdb_signal signal
)
708 struct gdbarch
*gdbarch
= regcache
->arch ();
712 record_full_arch_list_head
= NULL
;
713 record_full_arch_list_tail
= NULL
;
715 /* Check record_full_insn_num. */
716 record_full_check_insn_num ();
718 /* If gdb sends a signal value to target_resume,
719 save it in the 'end' field of the previous instruction.
721 Maybe process record should record what really happened,
722 rather than what gdb pretends has happened.
724 So if Linux delivered the signal to the child process during
725 the record mode, we will record it and deliver it again in
728 If user says "ignore this signal" during the record mode, then
729 it will be ignored again during the replay mode (no matter if
730 the user says something different, like "deliver this signal"
731 during the replay mode).
733 User should understand that nothing he does during the replay
734 mode will change the behavior of the child. If he tries,
735 then that is a user error.
737 But we should still deliver the signal to gdb during the replay,
738 if we delivered it during the recording. Therefore we should
739 record the signal during record_full_wait, not
740 record_full_resume. */
741 if (record_full_list
!= &record_full_first
) /* FIXME better way
744 gdb_assert (record_full_list
->type
== record_full_end
);
745 record_full_list
->u
.end
.sigval
= signal
;
748 if (signal
== GDB_SIGNAL_0
749 || !gdbarch_process_record_signal_p (gdbarch
))
750 ret
= gdbarch_process_record (gdbarch
,
752 regcache_read_pc (regcache
));
754 ret
= gdbarch_process_record_signal (gdbarch
,
759 error (_("Process record: inferior program stopped."));
761 error (_("Process record: failed to record execution log."));
763 catch (const gdb_exception
&ex
)
765 record_full_list_release (record_full_arch_list_tail
);
769 record_full_list
->next
= record_full_arch_list_head
;
770 record_full_arch_list_head
->prev
= record_full_list
;
771 record_full_list
= record_full_arch_list_tail
;
773 if (record_full_insn_num
== record_full_insn_max_num
)
774 record_full_list_release_first ();
776 record_full_insn_num
++;
780 record_full_message_wrapper_safe (struct regcache
*regcache
,
781 enum gdb_signal signal
)
785 record_full_message (regcache
, signal
);
787 catch (const gdb_exception
&ex
)
789 exception_print (gdb_stderr
, ex
);
796 /* Set to 1 if record_full_store_registers and record_full_xfer_partial
797 doesn't need record. */
799 static int record_full_gdb_operation_disable
= 0;
801 scoped_restore_tmpl
<int>
802 record_full_gdb_operation_disable_set (void)
804 return make_scoped_restore (&record_full_gdb_operation_disable
, 1);
807 /* Flag set to TRUE for target_stopped_by_watchpoint. */
808 static enum target_stop_reason record_full_stop_reason
809 = TARGET_STOPPED_BY_NO_REASON
;
811 /* Execute one instruction from the record log. Each instruction in
812 the log will be represented by an arbitrary sequence of register
813 entries and memory entries, followed by an 'end' entry. */
816 record_full_exec_insn (struct regcache
*regcache
,
817 struct gdbarch
*gdbarch
,
818 struct record_full_entry
*entry
)
822 case record_full_reg
: /* reg */
824 gdb::byte_vector
reg (entry
->u
.reg
.len
);
826 if (record_debug
> 1)
827 fprintf_unfiltered (gdb_stdlog
,
828 "Process record: record_full_reg %s to "
829 "inferior num = %d.\n",
830 host_address_to_string (entry
),
833 regcache
->cooked_read (entry
->u
.reg
.num
, reg
.data ());
834 regcache
->cooked_write (entry
->u
.reg
.num
, record_full_get_loc (entry
));
835 memcpy (record_full_get_loc (entry
), reg
.data (), entry
->u
.reg
.len
);
839 case record_full_mem
: /* mem */
841 /* Nothing to do if the entry is flagged not_accessible. */
842 if (!entry
->u
.mem
.mem_entry_not_accessible
)
844 gdb::byte_vector
mem (entry
->u
.mem
.len
);
846 if (record_debug
> 1)
847 fprintf_unfiltered (gdb_stdlog
,
848 "Process record: record_full_mem %s to "
849 "inferior addr = %s len = %d.\n",
850 host_address_to_string (entry
),
851 paddress (gdbarch
, entry
->u
.mem
.addr
),
854 if (record_read_memory (gdbarch
,
855 entry
->u
.mem
.addr
, mem
.data (),
857 entry
->u
.mem
.mem_entry_not_accessible
= 1;
860 if (target_write_memory (entry
->u
.mem
.addr
,
861 record_full_get_loc (entry
),
864 entry
->u
.mem
.mem_entry_not_accessible
= 1;
866 warning (_("Process record: error writing memory at "
867 "addr = %s len = %d."),
868 paddress (gdbarch
, entry
->u
.mem
.addr
),
873 memcpy (record_full_get_loc (entry
), mem
.data (),
876 /* We've changed memory --- check if a hardware
877 watchpoint should trap. Note that this
878 presently assumes the target beneath supports
879 continuable watchpoints. On non-continuable
880 watchpoints target, we'll want to check this
881 _before_ actually doing the memory change, and
882 not doing the change at all if the watchpoint
884 if (hardware_watchpoint_inserted_in_range
885 (regcache
->aspace (),
886 entry
->u
.mem
.addr
, entry
->u
.mem
.len
))
887 record_full_stop_reason
= TARGET_STOPPED_BY_WATCHPOINT
;
896 static void record_full_restore (void);
898 /* Asynchronous signal handle registered as event loop source for when
899 we have pending events ready to be passed to the core. */
901 static struct async_event_handler
*record_full_async_inferior_event_token
;
904 record_full_async_inferior_event_handler (gdb_client_data data
)
906 inferior_event_handler (INF_REG_EVENT
);
909 /* Open the process record target for 'core' files. */
912 record_full_core_open_1 (const char *name
, int from_tty
)
914 struct regcache
*regcache
= get_current_regcache ();
915 int regnum
= gdbarch_num_regs (regcache
->arch ());
918 /* Get record_full_core_regbuf. */
919 target_fetch_registers (regcache
, -1);
920 record_full_core_regbuf
= new detached_regcache (regcache
->arch (), false);
922 for (i
= 0; i
< regnum
; i
++)
923 record_full_core_regbuf
->raw_supply (i
, *regcache
);
925 record_full_core_sections
= build_section_table (core_bfd
);
927 current_inferior ()->push_target (&record_full_core_ops
);
928 record_full_restore ();
931 /* Open the process record target for 'live' processes. */
934 record_full_open_1 (const char *name
, int from_tty
)
937 fprintf_unfiltered (gdb_stdlog
, "Process record: record_full_open_1\n");
940 if (!target_has_execution ())
941 error (_("Process record: the program is not being run."));
943 error (_("Process record target can't debug inferior in non-stop mode "
946 if (!gdbarch_process_record_p (target_gdbarch ()))
947 error (_("Process record: the current architecture doesn't support "
948 "record function."));
950 current_inferior ()->push_target (&record_full_ops
);
953 static void record_full_init_record_breakpoints (void);
955 /* Open the process record target. */
958 record_full_open (const char *name
, int from_tty
)
961 fprintf_unfiltered (gdb_stdlog
, "Process record: record_full_open\n");
966 record_full_insn_num
= 0;
967 record_full_insn_count
= 0;
968 record_full_list
= &record_full_first
;
969 record_full_list
->next
= NULL
;
972 record_full_core_open_1 (name
, from_tty
);
974 record_full_open_1 (name
, from_tty
);
976 /* Register extra event sources in the event loop. */
977 record_full_async_inferior_event_token
978 = create_async_event_handler (record_full_async_inferior_event_handler
,
979 NULL
, "record-full");
981 record_full_init_record_breakpoints ();
983 gdb::observers::record_changed
.notify (current_inferior (), 1, "full", NULL
);
986 /* "close" target method. Close the process record target. */
989 record_full_base_target::close ()
991 struct record_full_core_buf_entry
*entry
;
994 fprintf_unfiltered (gdb_stdlog
, "Process record: record_full_close\n");
996 record_full_list_release (record_full_list
);
998 /* Release record_full_core_regbuf. */
999 if (record_full_core_regbuf
)
1001 delete record_full_core_regbuf
;
1002 record_full_core_regbuf
= NULL
;
1005 /* Release record_full_core_buf_list. */
1006 while (record_full_core_buf_list
)
1008 entry
= record_full_core_buf_list
;
1009 record_full_core_buf_list
= record_full_core_buf_list
->prev
;
1013 if (record_full_async_inferior_event_token
)
1014 delete_async_event_handler (&record_full_async_inferior_event_token
);
1017 /* "async" target method. */
1020 record_full_base_target::async (int enable
)
1023 mark_async_event_handler (record_full_async_inferior_event_token
);
1025 clear_async_event_handler (record_full_async_inferior_event_token
);
1027 beneath ()->async (enable
);
1030 /* The PTID and STEP arguments last passed to
1031 record_full_target::resume. */
1032 static ptid_t record_full_resume_ptid
= null_ptid
;
1033 static int record_full_resume_step
= 0;
1035 /* True if we've been resumed, and so each record_full_wait call should
1036 advance execution. If this is false, record_full_wait will return a
1037 TARGET_WAITKIND_IGNORE. */
1038 static int record_full_resumed
= 0;
1040 /* The execution direction of the last resume we got. This is
1041 necessary for async mode. Vis (order is not strictly accurate):
1043 1. user has the global execution direction set to forward
1044 2. user does a reverse-step command
1045 3. record_full_resume is called with global execution direction
1046 temporarily switched to reverse
1047 4. GDB's execution direction is reverted back to forward
1048 5. target record notifies event loop there's an event to handle
1049 6. infrun asks the target which direction was it going, and switches
1050 the global execution direction accordingly (to reverse)
1051 7. infrun polls an event out of the record target, and handles it
1052 8. GDB goes back to the event loop, and goto #4.
1054 static enum exec_direction_kind record_full_execution_dir
= EXEC_FORWARD
;
1056 /* "resume" target method. Resume the process record target. */
1059 record_full_target::resume (ptid_t ptid
, int step
, enum gdb_signal signal
)
1061 record_full_resume_ptid
= inferior_ptid
;
1062 record_full_resume_step
= step
;
1063 record_full_resumed
= 1;
1064 record_full_execution_dir
= ::execution_direction
;
1066 if (!RECORD_FULL_IS_REPLAY
)
1068 struct gdbarch
*gdbarch
= target_thread_architecture (ptid
);
1070 record_full_message (get_current_regcache (), signal
);
1074 /* This is not hard single step. */
1075 if (!gdbarch_software_single_step_p (gdbarch
))
1077 /* This is a normal continue. */
1082 /* This arch supports soft single step. */
1083 if (thread_has_single_step_breakpoints_set (inferior_thread ()))
1085 /* This is a soft single step. */
1086 record_full_resume_step
= 1;
1089 step
= !insert_single_step_breakpoints (gdbarch
);
1093 /* Make sure the target beneath reports all signals. */
1094 target_pass_signals ({});
1096 this->beneath ()->resume (ptid
, step
, signal
);
1099 /* We are about to start executing the inferior (or simulate it),
1100 let's register it with the event loop. */
1101 if (target_can_async_p ())
1105 static int record_full_get_sig
= 0;
1107 /* SIGINT signal handler, registered by "wait" method. */
1110 record_full_sig_handler (int signo
)
1113 fprintf_unfiltered (gdb_stdlog
, "Process record: get a signal\n");
1115 /* It will break the running inferior in replay mode. */
1116 record_full_resume_step
= 1;
1118 /* It will let record_full_wait set inferior status to get the signal
1120 record_full_get_sig
= 1;
1123 /* "wait" target method for process record target.
1125 In record mode, the target is always run in singlestep mode
1126 (even when gdb says to continue). The wait method intercepts
1127 the stop events and determines which ones are to be passed on to
1128 gdb. Most stop events are just singlestep events that gdb is not
1129 to know about, so the wait method just records them and keeps
1132 In replay mode, this function emulates the recorded execution log,
1133 one instruction at a time (forward or backward), and determines
1137 record_full_wait_1 (struct target_ops
*ops
,
1138 ptid_t ptid
, struct target_waitstatus
*status
,
1139 target_wait_flags options
)
1141 scoped_restore restore_operation_disable
1142 = record_full_gdb_operation_disable_set ();
1145 fprintf_unfiltered (gdb_stdlog
,
1146 "Process record: record_full_wait "
1147 "record_full_resume_step = %d, "
1148 "record_full_resumed = %d, direction=%s\n",
1149 record_full_resume_step
, record_full_resumed
,
1150 record_full_execution_dir
== EXEC_FORWARD
1151 ? "forward" : "reverse");
1153 if (!record_full_resumed
)
1155 gdb_assert ((options
& TARGET_WNOHANG
) != 0);
1157 /* No interesting event. */
1158 status
->set_ignore ();
1159 return minus_one_ptid
;
1162 record_full_get_sig
= 0;
1163 signal (SIGINT
, record_full_sig_handler
);
1165 record_full_stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
1167 if (!RECORD_FULL_IS_REPLAY
&& ops
!= &record_full_core_ops
)
1169 if (record_full_resume_step
)
1171 /* This is a single step. */
1172 return ops
->beneath ()->wait (ptid
, status
, options
);
1176 /* This is not a single step. */
1179 struct gdbarch
*gdbarch
1180 = target_thread_architecture (record_full_resume_ptid
);
1184 ret
= ops
->beneath ()->wait (ptid
, status
, options
);
1185 if (status
->kind () == TARGET_WAITKIND_IGNORE
)
1188 fprintf_unfiltered (gdb_stdlog
,
1189 "Process record: record_full_wait "
1190 "target beneath not done yet\n");
1194 for (thread_info
*tp
: all_non_exited_threads ())
1195 delete_single_step_breakpoints (tp
);
1197 if (record_full_resume_step
)
1200 /* Is this a SIGTRAP? */
1201 if (status
->kind () == TARGET_WAITKIND_STOPPED
1202 && status
->sig () == GDB_SIGNAL_TRAP
)
1204 struct regcache
*regcache
;
1205 enum target_stop_reason
*stop_reason_p
1206 = &record_full_stop_reason
;
1208 /* Yes -- this is likely our single-step finishing,
1209 but check if there's any reason the core would be
1210 interested in the event. */
1212 registers_changed ();
1213 switch_to_thread (current_inferior ()->process_target (),
1215 regcache
= get_current_regcache ();
1216 tmp_pc
= regcache_read_pc (regcache
);
1217 const struct address_space
*aspace
= regcache
->aspace ();
1219 if (target_stopped_by_watchpoint ())
1221 /* Always interested in watchpoints. */
1223 else if (record_check_stopped_by_breakpoint (aspace
, tmp_pc
,
1226 /* There is a breakpoint here. Let the core
1231 /* This is a single-step trap. Record the
1232 insn and issue another step.
1233 FIXME: this part can be a random SIGTRAP too.
1234 But GDB cannot handle it. */
1237 if (!record_full_message_wrapper_safe (regcache
,
1240 status
->set_stopped (GDB_SIGNAL_0
);
1244 process_stratum_target
*proc_target
1245 = current_inferior ()->process_target ();
1247 if (gdbarch_software_single_step_p (gdbarch
))
1249 /* Try to insert the software single step breakpoint.
1250 If insert success, set step to 0. */
1251 set_executing (proc_target
, inferior_ptid
, false);
1254 set_executing (proc_target
, inferior_ptid
, true);
1257 reinit_frame_cache ();
1258 step
= !insert_single_step_breakpoints (gdbarch
);
1262 fprintf_unfiltered (gdb_stdlog
,
1263 "Process record: record_full_wait "
1264 "issuing one more step in the "
1265 "target beneath\n");
1266 ops
->beneath ()->resume (ptid
, step
, GDB_SIGNAL_0
);
1267 proc_target
->commit_resumed_state
= true;
1268 proc_target
->commit_resumed ();
1269 proc_target
->commit_resumed_state
= false;
1274 /* The inferior is broken by a breakpoint or a signal. */
1283 switch_to_thread (current_inferior ()->process_target (),
1284 record_full_resume_ptid
);
1285 struct regcache
*regcache
= get_current_regcache ();
1286 struct gdbarch
*gdbarch
= regcache
->arch ();
1287 const struct address_space
*aspace
= regcache
->aspace ();
1288 int continue_flag
= 1;
1289 int first_record_full_end
= 1;
1295 record_full_stop_reason
= TARGET_STOPPED_BY_NO_REASON
;
1296 status
->set_stopped (GDB_SIGNAL_0
);
1298 /* Check breakpoint when forward execute. */
1299 if (execution_direction
== EXEC_FORWARD
)
1301 tmp_pc
= regcache_read_pc (regcache
);
1302 if (record_check_stopped_by_breakpoint (aspace
, tmp_pc
,
1303 &record_full_stop_reason
))
1306 fprintf_unfiltered (gdb_stdlog
,
1307 "Process record: break at %s.\n",
1308 paddress (gdbarch
, tmp_pc
));
1313 /* If GDB is in terminal_inferior mode, it will not get the
1314 signal. And in GDB replay mode, GDB doesn't need to be
1315 in terminal_inferior mode, because inferior will not
1316 executed. Then set it to terminal_ours to make GDB get
1318 target_terminal::ours ();
1320 /* In EXEC_FORWARD mode, record_full_list points to the tail of prev
1322 if (execution_direction
== EXEC_FORWARD
&& record_full_list
->next
)
1323 record_full_list
= record_full_list
->next
;
1325 /* Loop over the record_full_list, looking for the next place to
1329 /* Check for beginning and end of log. */
1330 if (execution_direction
== EXEC_REVERSE
1331 && record_full_list
== &record_full_first
)
1333 /* Hit beginning of record log in reverse. */
1334 status
->set_no_history ();
1337 if (execution_direction
!= EXEC_REVERSE
1338 && !record_full_list
->next
)
1340 /* Hit end of record log going forward. */
1341 status
->set_no_history ();
1345 record_full_exec_insn (regcache
, gdbarch
, record_full_list
);
1347 if (record_full_list
->type
== record_full_end
)
1349 if (record_debug
> 1)
1352 "Process record: record_full_end %s to "
1354 host_address_to_string (record_full_list
));
1356 if (first_record_full_end
1357 && execution_direction
== EXEC_REVERSE
)
1359 /* When reverse execute, the first
1360 record_full_end is the part of current
1362 first_record_full_end
= 0;
1366 /* In EXEC_REVERSE mode, this is the
1367 record_full_end of prev instruction. In
1368 EXEC_FORWARD mode, this is the
1369 record_full_end of current instruction. */
1371 if (record_full_resume_step
)
1373 if (record_debug
> 1)
1374 fprintf_unfiltered (gdb_stdlog
,
1375 "Process record: step.\n");
1379 /* check breakpoint */
1380 tmp_pc
= regcache_read_pc (regcache
);
1381 if (record_check_stopped_by_breakpoint
1382 (aspace
, tmp_pc
, &record_full_stop_reason
))
1385 fprintf_unfiltered (gdb_stdlog
,
1386 "Process record: break "
1388 paddress (gdbarch
, tmp_pc
));
1393 if (record_full_stop_reason
1394 == TARGET_STOPPED_BY_WATCHPOINT
)
1397 fprintf_unfiltered (gdb_stdlog
,
1398 "Process record: hit hw "
1402 /* Check target signal */
1403 if (record_full_list
->u
.end
.sigval
!= GDB_SIGNAL_0
)
1404 /* FIXME: better way to check */
1411 if (execution_direction
== EXEC_REVERSE
)
1413 if (record_full_list
->prev
)
1414 record_full_list
= record_full_list
->prev
;
1418 if (record_full_list
->next
)
1419 record_full_list
= record_full_list
->next
;
1423 while (continue_flag
);
1426 if (status
->kind () == TARGET_WAITKIND_STOPPED
)
1428 if (record_full_get_sig
)
1429 status
->set_stopped (GDB_SIGNAL_INT
);
1430 else if (record_full_list
->u
.end
.sigval
!= GDB_SIGNAL_0
)
1431 /* FIXME: better way to check */
1432 status
->set_stopped (record_full_list
->u
.end
.sigval
);
1434 status
->set_stopped (GDB_SIGNAL_TRAP
);
1437 catch (const gdb_exception
&ex
)
1439 if (execution_direction
== EXEC_REVERSE
)
1441 if (record_full_list
->next
)
1442 record_full_list
= record_full_list
->next
;
1445 record_full_list
= record_full_list
->prev
;
1451 signal (SIGINT
, handle_sigint
);
1453 return inferior_ptid
;
1457 record_full_base_target::wait (ptid_t ptid
, struct target_waitstatus
*status
,
1458 target_wait_flags options
)
1462 clear_async_event_handler (record_full_async_inferior_event_token
);
1464 return_ptid
= record_full_wait_1 (this, ptid
, status
, options
);
1465 if (status
->kind () != TARGET_WAITKIND_IGNORE
)
1467 /* We're reporting a stop. Make sure any spurious
1468 target_wait(WNOHANG) doesn't advance the target until the
1469 core wants us resumed again. */
1470 record_full_resumed
= 0;
1476 record_full_base_target::stopped_by_watchpoint ()
1478 if (RECORD_FULL_IS_REPLAY
)
1479 return record_full_stop_reason
== TARGET_STOPPED_BY_WATCHPOINT
;
1481 return beneath ()->stopped_by_watchpoint ();
1485 record_full_base_target::stopped_data_address (CORE_ADDR
*addr_p
)
1487 if (RECORD_FULL_IS_REPLAY
)
1490 return this->beneath ()->stopped_data_address (addr_p
);
1493 /* The stopped_by_sw_breakpoint method of target record-full. */
1496 record_full_base_target::stopped_by_sw_breakpoint ()
1498 return record_full_stop_reason
== TARGET_STOPPED_BY_SW_BREAKPOINT
;
1501 /* The supports_stopped_by_sw_breakpoint method of target
1505 record_full_base_target::supports_stopped_by_sw_breakpoint ()
1510 /* The stopped_by_hw_breakpoint method of target record-full. */
1513 record_full_base_target::stopped_by_hw_breakpoint ()
1515 return record_full_stop_reason
== TARGET_STOPPED_BY_HW_BREAKPOINT
;
1518 /* The supports_stopped_by_sw_breakpoint method of target
1522 record_full_base_target::supports_stopped_by_hw_breakpoint ()
1527 /* Record registers change (by user or by GDB) to list as an instruction. */
1530 record_full_registers_change (struct regcache
*regcache
, int regnum
)
1532 /* Check record_full_insn_num. */
1533 record_full_check_insn_num ();
1535 record_full_arch_list_head
= NULL
;
1536 record_full_arch_list_tail
= NULL
;
1542 for (i
= 0; i
< gdbarch_num_regs (regcache
->arch ()); i
++)
1544 if (record_full_arch_list_add_reg (regcache
, i
))
1546 record_full_list_release (record_full_arch_list_tail
);
1547 error (_("Process record: failed to record execution log."));
1553 if (record_full_arch_list_add_reg (regcache
, regnum
))
1555 record_full_list_release (record_full_arch_list_tail
);
1556 error (_("Process record: failed to record execution log."));
1559 if (record_full_arch_list_add_end ())
1561 record_full_list_release (record_full_arch_list_tail
);
1562 error (_("Process record: failed to record execution log."));
1564 record_full_list
->next
= record_full_arch_list_head
;
1565 record_full_arch_list_head
->prev
= record_full_list
;
1566 record_full_list
= record_full_arch_list_tail
;
1568 if (record_full_insn_num
== record_full_insn_max_num
)
1569 record_full_list_release_first ();
1571 record_full_insn_num
++;
1574 /* "store_registers" method for process record target. */
1577 record_full_target::store_registers (struct regcache
*regcache
, int regno
)
1579 if (!record_full_gdb_operation_disable
)
1581 if (RECORD_FULL_IS_REPLAY
)
1585 /* Let user choose if he wants to write register or not. */
1588 query (_("Because GDB is in replay mode, changing the "
1589 "value of a register will make the execution "
1590 "log unusable from this point onward. "
1591 "Change all registers?"));
1594 query (_("Because GDB is in replay mode, changing the value "
1595 "of a register will make the execution log unusable "
1596 "from this point onward. Change register %s?"),
1597 gdbarch_register_name (regcache
->arch (),
1602 /* Invalidate the value of regcache that was set in function
1603 "regcache_raw_write". */
1609 i
< gdbarch_num_regs (regcache
->arch ());
1611 regcache
->invalidate (i
);
1614 regcache
->invalidate (regno
);
1616 error (_("Process record canceled the operation."));
1619 /* Destroy the record from here forward. */
1620 record_full_list_release_following (record_full_list
);
1623 record_full_registers_change (regcache
, regno
);
1625 this->beneath ()->store_registers (regcache
, regno
);
1628 /* "xfer_partial" method. Behavior is conditional on
1629 RECORD_FULL_IS_REPLAY.
1630 In replay mode, we cannot write memory unles we are willing to
1631 invalidate the record/replay log from this point forward. */
1633 enum target_xfer_status
1634 record_full_target::xfer_partial (enum target_object object
,
1635 const char *annex
, gdb_byte
*readbuf
,
1636 const gdb_byte
*writebuf
, ULONGEST offset
,
1637 ULONGEST len
, ULONGEST
*xfered_len
)
1639 if (!record_full_gdb_operation_disable
1640 && (object
== TARGET_OBJECT_MEMORY
1641 || object
== TARGET_OBJECT_RAW_MEMORY
) && writebuf
)
1643 if (RECORD_FULL_IS_REPLAY
)
1645 /* Let user choose if he wants to write memory or not. */
1646 if (!query (_("Because GDB is in replay mode, writing to memory "
1647 "will make the execution log unusable from this "
1648 "point onward. Write memory at address %s?"),
1649 paddress (target_gdbarch (), offset
)))
1650 error (_("Process record canceled the operation."));
1652 /* Destroy the record from here forward. */
1653 record_full_list_release_following (record_full_list
);
1656 /* Check record_full_insn_num */
1657 record_full_check_insn_num ();
1659 /* Record registers change to list as an instruction. */
1660 record_full_arch_list_head
= NULL
;
1661 record_full_arch_list_tail
= NULL
;
1662 if (record_full_arch_list_add_mem (offset
, len
))
1664 record_full_list_release (record_full_arch_list_tail
);
1666 fprintf_unfiltered (gdb_stdlog
,
1667 "Process record: failed to record "
1669 return TARGET_XFER_E_IO
;
1671 if (record_full_arch_list_add_end ())
1673 record_full_list_release (record_full_arch_list_tail
);
1675 fprintf_unfiltered (gdb_stdlog
,
1676 "Process record: failed to record "
1678 return TARGET_XFER_E_IO
;
1680 record_full_list
->next
= record_full_arch_list_head
;
1681 record_full_arch_list_head
->prev
= record_full_list
;
1682 record_full_list
= record_full_arch_list_tail
;
1684 if (record_full_insn_num
== record_full_insn_max_num
)
1685 record_full_list_release_first ();
1687 record_full_insn_num
++;
1690 return this->beneath ()->xfer_partial (object
, annex
, readbuf
, writebuf
,
1691 offset
, len
, xfered_len
);
1694 /* This structure represents a breakpoint inserted while the record
1695 target is active. We use this to know when to install/remove
1696 breakpoints in/from the target beneath. For example, a breakpoint
1697 may be inserted while recording, but removed when not replaying nor
1698 recording. In that case, the breakpoint had not been inserted on
1699 the target beneath, so we should not try to remove it there. */
1701 struct record_full_breakpoint
1703 record_full_breakpoint (struct address_space
*address_space_
,
1705 bool in_target_beneath_
)
1706 : address_space (address_space_
),
1708 in_target_beneath (in_target_beneath_
)
1712 /* The address and address space the breakpoint was set at. */
1713 struct address_space
*address_space
;
1716 /* True when the breakpoint has been also installed in the target
1717 beneath. This will be false for breakpoints set during replay or
1719 bool in_target_beneath
;
1722 /* The list of breakpoints inserted while the record target is
1724 static std::vector
<record_full_breakpoint
> record_full_breakpoints
;
1726 /* Sync existing breakpoints to record_full_breakpoints. */
1729 record_full_init_record_breakpoints (void)
1731 record_full_breakpoints
.clear ();
1733 for (bp_location
*loc
: all_bp_locations ())
1735 if (loc
->loc_type
!= bp_loc_software_breakpoint
)
1739 record_full_breakpoints
.emplace_back
1740 (loc
->target_info
.placed_address_space
,
1741 loc
->target_info
.placed_address
, 1);
1745 /* Behavior is conditional on RECORD_FULL_IS_REPLAY. We will not actually
1746 insert or remove breakpoints in the real target when replaying, nor
1750 record_full_target::insert_breakpoint (struct gdbarch
*gdbarch
,
1751 struct bp_target_info
*bp_tgt
)
1753 bool in_target_beneath
= false;
1755 if (!RECORD_FULL_IS_REPLAY
)
1757 /* When recording, we currently always single-step, so we don't
1758 really need to install regular breakpoints in the inferior.
1759 However, we do have to insert software single-step
1760 breakpoints, in case the target can't hardware step. To keep
1761 things simple, we always insert. */
1763 scoped_restore restore_operation_disable
1764 = record_full_gdb_operation_disable_set ();
1766 int ret
= this->beneath ()->insert_breakpoint (gdbarch
, bp_tgt
);
1770 in_target_beneath
= true;
1773 /* Use the existing entries if found in order to avoid duplication
1774 in record_full_breakpoints. */
1776 for (const record_full_breakpoint
&bp
: record_full_breakpoints
)
1778 if (bp
.addr
== bp_tgt
->placed_address
1779 && bp
.address_space
== bp_tgt
->placed_address_space
)
1781 gdb_assert (bp
.in_target_beneath
== in_target_beneath
);
1786 record_full_breakpoints
.emplace_back (bp_tgt
->placed_address_space
,
1787 bp_tgt
->placed_address
,
1792 /* "remove_breakpoint" method for process record target. */
1795 record_full_target::remove_breakpoint (struct gdbarch
*gdbarch
,
1796 struct bp_target_info
*bp_tgt
,
1797 enum remove_bp_reason reason
)
1799 for (auto iter
= record_full_breakpoints
.begin ();
1800 iter
!= record_full_breakpoints
.end ();
1803 struct record_full_breakpoint
&bp
= *iter
;
1805 if (bp
.addr
== bp_tgt
->placed_address
1806 && bp
.address_space
== bp_tgt
->placed_address_space
)
1808 if (bp
.in_target_beneath
)
1810 scoped_restore restore_operation_disable
1811 = record_full_gdb_operation_disable_set ();
1813 int ret
= this->beneath ()->remove_breakpoint (gdbarch
, bp_tgt
,
1819 if (reason
== REMOVE_BREAKPOINT
)
1820 unordered_remove (record_full_breakpoints
, iter
);
1825 gdb_assert_not_reached ("removing unknown breakpoint");
1828 /* "can_execute_reverse" method for process record target. */
1831 record_full_base_target::can_execute_reverse ()
1836 /* "get_bookmark" method for process record and prec over core. */
1839 record_full_base_target::get_bookmark (const char *args
, int from_tty
)
1843 /* Return stringified form of instruction count. */
1844 if (record_full_list
&& record_full_list
->type
== record_full_end
)
1845 ret
= xstrdup (pulongest (record_full_list
->u
.end
.insn_num
));
1850 fprintf_unfiltered (gdb_stdlog
,
1851 "record_full_get_bookmark returns %s\n", ret
);
1853 fprintf_unfiltered (gdb_stdlog
,
1854 "record_full_get_bookmark returns NULL\n");
1856 return (gdb_byte
*) ret
;
1859 /* "goto_bookmark" method for process record and prec over core. */
1862 record_full_base_target::goto_bookmark (const gdb_byte
*raw_bookmark
,
1865 const char *bookmark
= (const char *) raw_bookmark
;
1868 fprintf_unfiltered (gdb_stdlog
,
1869 "record_full_goto_bookmark receives %s\n", bookmark
);
1871 std::string name_holder
;
1872 if (bookmark
[0] == '\'' || bookmark
[0] == '\"')
1874 if (bookmark
[strlen (bookmark
) - 1] != bookmark
[0])
1875 error (_("Unbalanced quotes: %s"), bookmark
);
1877 name_holder
= std::string (bookmark
+ 1, strlen (bookmark
) - 2);
1878 bookmark
= name_holder
.c_str ();
1881 record_goto (bookmark
);
1884 enum exec_direction_kind
1885 record_full_base_target::execution_direction ()
1887 return record_full_execution_dir
;
1890 /* The record_method method of target record-full. */
1893 record_full_base_target::record_method (ptid_t ptid
)
1895 return RECORD_METHOD_FULL
;
1899 record_full_base_target::info_record ()
1901 struct record_full_entry
*p
;
1903 if (RECORD_FULL_IS_REPLAY
)
1904 printf_filtered (_("Replay mode:\n"));
1906 printf_filtered (_("Record mode:\n"));
1908 /* Find entry for first actual instruction in the log. */
1909 for (p
= record_full_first
.next
;
1910 p
!= NULL
&& p
->type
!= record_full_end
;
1914 /* Do we have a log at all? */
1915 if (p
!= NULL
&& p
->type
== record_full_end
)
1917 /* Display instruction number for first instruction in the log. */
1918 printf_filtered (_("Lowest recorded instruction number is %s.\n"),
1919 pulongest (p
->u
.end
.insn_num
));
1921 /* If in replay mode, display where we are in the log. */
1922 if (RECORD_FULL_IS_REPLAY
)
1923 printf_filtered (_("Current instruction number is %s.\n"),
1924 pulongest (record_full_list
->u
.end
.insn_num
));
1926 /* Display instruction number for last instruction in the log. */
1927 printf_filtered (_("Highest recorded instruction number is %s.\n"),
1928 pulongest (record_full_insn_count
));
1930 /* Display log count. */
1931 printf_filtered (_("Log contains %u instructions.\n"),
1932 record_full_insn_num
);
1935 printf_filtered (_("No instructions have been logged.\n"));
1937 /* Display max log size. */
1938 printf_filtered (_("Max logged instructions is %u.\n"),
1939 record_full_insn_max_num
);
1943 record_full_base_target::supports_delete_record ()
1948 /* The "delete_record" target method. */
1951 record_full_base_target::delete_record ()
1953 record_full_list_release_following (record_full_list
);
1956 /* The "record_is_replaying" target method. */
1959 record_full_base_target::record_is_replaying (ptid_t ptid
)
1961 return RECORD_FULL_IS_REPLAY
;
1964 /* The "record_will_replay" target method. */
1967 record_full_base_target::record_will_replay (ptid_t ptid
, int dir
)
1969 /* We can currently only record when executing forwards. Should we be able
1970 to record when executing backwards on targets that support reverse
1971 execution, this needs to be changed. */
1973 return RECORD_FULL_IS_REPLAY
|| dir
== EXEC_REVERSE
;
1976 /* Go to a specific entry. */
1979 record_full_goto_entry (struct record_full_entry
*p
)
1982 error (_("Target insn not found."));
1983 else if (p
== record_full_list
)
1984 error (_("Already at target insn."));
1985 else if (p
->u
.end
.insn_num
> record_full_list
->u
.end
.insn_num
)
1987 printf_filtered (_("Go forward to insn number %s\n"),
1988 pulongest (p
->u
.end
.insn_num
));
1989 record_full_goto_insn (p
, EXEC_FORWARD
);
1993 printf_filtered (_("Go backward to insn number %s\n"),
1994 pulongest (p
->u
.end
.insn_num
));
1995 record_full_goto_insn (p
, EXEC_REVERSE
);
1998 registers_changed ();
1999 reinit_frame_cache ();
2000 inferior_thread ()->set_stop_pc (regcache_read_pc (get_current_regcache ()));
2001 print_stack_frame (get_selected_frame (NULL
), 1, SRC_AND_LOC
, 1);
2004 /* The "goto_record_begin" target method. */
2007 record_full_base_target::goto_record_begin ()
2009 struct record_full_entry
*p
= NULL
;
2011 for (p
= &record_full_first
; p
!= NULL
; p
= p
->next
)
2012 if (p
->type
== record_full_end
)
2015 record_full_goto_entry (p
);
2018 /* The "goto_record_end" target method. */
2021 record_full_base_target::goto_record_end ()
2023 struct record_full_entry
*p
= NULL
;
2025 for (p
= record_full_list
; p
->next
!= NULL
; p
= p
->next
)
2027 for (; p
!= NULL
; p
= p
->prev
)
2028 if (p
->type
== record_full_end
)
2031 record_full_goto_entry (p
);
2034 /* The "goto_record" target method. */
2037 record_full_base_target::goto_record (ULONGEST target_insn
)
2039 struct record_full_entry
*p
= NULL
;
2041 for (p
= &record_full_first
; p
!= NULL
; p
= p
->next
)
2042 if (p
->type
== record_full_end
&& p
->u
.end
.insn_num
== target_insn
)
2045 record_full_goto_entry (p
);
2048 /* The "record_stop_replaying" target method. */
2051 record_full_base_target::record_stop_replaying ()
2056 /* "resume" method for prec over corefile. */
2059 record_full_core_target::resume (ptid_t ptid
, int step
,
2060 enum gdb_signal signal
)
2062 record_full_resume_step
= step
;
2063 record_full_resumed
= 1;
2064 record_full_execution_dir
= ::execution_direction
;
2066 /* We are about to start executing the inferior (or simulate it),
2067 let's register it with the event loop. */
2068 if (target_can_async_p ())
2072 /* "kill" method for prec over corefile. */
2075 record_full_core_target::kill ()
2078 fprintf_unfiltered (gdb_stdlog
, "Process record: record_full_core_kill\n");
2080 current_inferior ()->unpush_target (this);
2083 /* "fetch_registers" method for prec over corefile. */
2086 record_full_core_target::fetch_registers (struct regcache
*regcache
,
2091 int num
= gdbarch_num_regs (regcache
->arch ());
2094 for (i
= 0; i
< num
; i
++)
2095 regcache
->raw_supply (i
, *record_full_core_regbuf
);
2098 regcache
->raw_supply (regno
, *record_full_core_regbuf
);
2101 /* "prepare_to_store" method for prec over corefile. */
2104 record_full_core_target::prepare_to_store (struct regcache
*regcache
)
2108 /* "store_registers" method for prec over corefile. */
2111 record_full_core_target::store_registers (struct regcache
*regcache
,
2114 if (record_full_gdb_operation_disable
)
2115 record_full_core_regbuf
->raw_supply (regno
, *regcache
);
2117 error (_("You can't do that without a process to debug."));
2120 /* "xfer_partial" method for prec over corefile. */
2122 enum target_xfer_status
2123 record_full_core_target::xfer_partial (enum target_object object
,
2124 const char *annex
, gdb_byte
*readbuf
,
2125 const gdb_byte
*writebuf
, ULONGEST offset
,
2126 ULONGEST len
, ULONGEST
*xfered_len
)
2128 if (object
== TARGET_OBJECT_MEMORY
)
2130 if (record_full_gdb_operation_disable
|| !writebuf
)
2132 for (target_section
&p
: record_full_core_sections
)
2134 if (offset
>= p
.addr
)
2136 struct record_full_core_buf_entry
*entry
;
2137 ULONGEST sec_offset
;
2139 if (offset
>= p
.endaddr
)
2142 if (offset
+ len
> p
.endaddr
)
2143 len
= p
.endaddr
- offset
;
2145 sec_offset
= offset
- p
.addr
;
2147 /* Read readbuf or write writebuf p, offset, len. */
2149 if (p
.the_bfd_section
->flags
& SEC_CONSTRUCTOR
2150 || (p
.the_bfd_section
->flags
& SEC_HAS_CONTENTS
) == 0)
2153 memset (readbuf
, 0, len
);
2156 return TARGET_XFER_OK
;
2158 /* Get record_full_core_buf_entry. */
2159 for (entry
= record_full_core_buf_list
; entry
;
2160 entry
= entry
->prev
)
2167 /* Add a new entry. */
2168 entry
= XNEW (struct record_full_core_buf_entry
);
2170 if (!bfd_malloc_and_get_section
2171 (p
.the_bfd_section
->owner
,
2176 return TARGET_XFER_EOF
;
2178 entry
->prev
= record_full_core_buf_list
;
2179 record_full_core_buf_list
= entry
;
2182 memcpy (entry
->buf
+ sec_offset
, writebuf
,
2188 return this->beneath ()->xfer_partial (object
, annex
,
2193 memcpy (readbuf
, entry
->buf
+ sec_offset
,
2198 return TARGET_XFER_OK
;
2202 return TARGET_XFER_E_IO
;
2205 error (_("You can't do that without a process to debug."));
2208 return this->beneath ()->xfer_partial (object
, annex
,
2209 readbuf
, writebuf
, offset
, len
,
2213 /* "insert_breakpoint" method for prec over corefile. */
2216 record_full_core_target::insert_breakpoint (struct gdbarch
*gdbarch
,
2217 struct bp_target_info
*bp_tgt
)
2222 /* "remove_breakpoint" method for prec over corefile. */
2225 record_full_core_target::remove_breakpoint (struct gdbarch
*gdbarch
,
2226 struct bp_target_info
*bp_tgt
,
2227 enum remove_bp_reason reason
)
2232 /* "has_execution" method for prec over corefile. */
2235 record_full_core_target::has_execution (inferior
*inf
)
2240 /* Record log save-file format
2241 Version 1 (never released)
2244 4 bytes: magic number htonl(0x20090829).
2245 NOTE: be sure to change whenever this file format changes!
2249 1 byte: record type (record_full_end, see enum record_full_type).
2251 1 byte: record type (record_full_reg, see enum record_full_type).
2252 8 bytes: register id (network byte order).
2253 MAX_REGISTER_SIZE bytes: register value.
2255 1 byte: record type (record_full_mem, see enum record_full_type).
2256 8 bytes: memory length (network byte order).
2257 8 bytes: memory address (network byte order).
2258 n bytes: memory value (n == memory length).
2261 4 bytes: magic number netorder32(0x20091016).
2262 NOTE: be sure to change whenever this file format changes!
2266 1 byte: record type (record_full_end, see enum record_full_type).
2268 4 bytes: instruction count
2270 1 byte: record type (record_full_reg, see enum record_full_type).
2271 4 bytes: register id (network byte order).
2272 n bytes: register value (n == actual register size).
2273 (eg. 4 bytes for x86 general registers).
2275 1 byte: record type (record_full_mem, see enum record_full_type).
2276 4 bytes: memory length (network byte order).
2277 8 bytes: memory address (network byte order).
2278 n bytes: memory value (n == memory length).
2282 /* bfdcore_read -- read bytes from a core file section. */
2285 bfdcore_read (bfd
*obfd
, asection
*osec
, void *buf
, int len
, int *offset
)
2287 int ret
= bfd_get_section_contents (obfd
, osec
, buf
, *offset
, len
);
2292 error (_("Failed to read %d bytes from core file %s ('%s')."),
2293 len
, bfd_get_filename (obfd
),
2294 bfd_errmsg (bfd_get_error ()));
2297 static inline uint64_t
2298 netorder64 (uint64_t input
)
2302 store_unsigned_integer ((gdb_byte
*) &ret
, sizeof (ret
),
2303 BFD_ENDIAN_BIG
, input
);
2307 static inline uint32_t
2308 netorder32 (uint32_t input
)
2312 store_unsigned_integer ((gdb_byte
*) &ret
, sizeof (ret
),
2313 BFD_ENDIAN_BIG
, input
);
2317 /* Restore the execution log from a core_bfd file. */
2319 record_full_restore (void)
2322 struct record_full_entry
*rec
;
2326 struct regcache
*regcache
;
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 fprintf_unfiltered (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 fprintf_unfiltered (gdb_stdlog
, "Find precord section %s.\n",
2343 osec
? "succeeded" : "failed");
2346 osec_size
= bfd_section_size (osec
);
2348 fprintf_unfiltered (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 fprintf_unfiltered (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
= get_current_regcache ();
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 fprintf_unfiltered (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 fprintf_unfiltered (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 fprintf_unfiltered (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 printf_filtered (_("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 regcache
*regcache
;
2530 struct gdbarch
*gdbarch
;
2532 asection
*osec
= NULL
;
2535 /* Open the save file. */
2537 fprintf_unfiltered (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
= get_current_regcache ();
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 fprintf_unfiltered (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 fprintf_unfiltered (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 fprintf_unfiltered (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 fprintf_unfiltered (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 printf_filtered (_("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 struct regcache
*regcache
= get_current_regcache ();
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 void _initialize_record_full ();
2779 _initialize_record_full ()
2781 struct cmd_list_element
*c
;
2783 /* Init record_full_first. */
2784 record_full_first
.prev
= NULL
;
2785 record_full_first
.next
= NULL
;
2786 record_full_first
.type
= record_full_end
;
2788 add_target (record_full_target_info
, record_full_open
);
2789 add_deprecated_target_alias (record_full_target_info
, "record");
2790 add_target (record_full_core_target_info
, record_full_open
);
2792 add_prefix_cmd ("full", class_obscure
, cmd_record_full_start
,
2793 _("Start full execution recording."), &record_full_cmdlist
,
2794 0, &record_cmdlist
);
2796 cmd_list_element
*record_full_restore_cmd
2797 = add_cmd ("restore", class_obscure
, cmd_record_full_restore
,
2798 _("Restore the execution log from a file.\n\
2799 Argument is filename. File must be created with 'record save'."),
2800 &record_full_cmdlist
);
2801 set_cmd_completer (record_full_restore_cmd
, filename_completer
);
2803 /* Deprecate the old version without "full" prefix. */
2804 c
= add_alias_cmd ("restore", record_full_restore_cmd
, class_obscure
, 1,
2806 set_cmd_completer (c
, filename_completer
);
2807 deprecate_cmd (c
, "record full restore");
2809 add_setshow_prefix_cmd ("full", class_support
,
2810 _("Set record options."),
2811 _("Show record options."),
2812 &set_record_full_cmdlist
,
2813 &show_record_full_cmdlist
,
2814 &set_record_cmdlist
,
2815 &show_record_cmdlist
);
2817 /* Record instructions number limit command. */
2818 set_show_commands set_record_full_stop_at_limit_cmds
2819 = add_setshow_boolean_cmd ("stop-at-limit", no_class
,
2820 &record_full_stop_at_limit
, _("\
2821 Set whether record/replay stops when record/replay buffer becomes full."), _("\
2822 Show whether record/replay stops when record/replay buffer becomes full."),
2823 _("Default is ON.\n\
2824 When ON, if the record/replay buffer becomes full, ask user what to do.\n\
2825 When OFF, if the record/replay buffer becomes full,\n\
2826 delete the oldest recorded instruction to make room for each new one."),
2828 &set_record_full_cmdlist
,
2829 &show_record_full_cmdlist
);
2831 c
= add_alias_cmd ("stop-at-limit",
2832 set_record_full_stop_at_limit_cmds
.set
, no_class
, 1,
2833 &set_record_cmdlist
);
2834 deprecate_cmd (c
, "set record full stop-at-limit");
2836 c
= add_alias_cmd ("stop-at-limit",
2837 set_record_full_stop_at_limit_cmds
.show
, no_class
, 1,
2838 &show_record_cmdlist
);
2839 deprecate_cmd (c
, "show record full stop-at-limit");
2841 set_show_commands record_full_insn_number_max_cmds
2842 = add_setshow_uinteger_cmd ("insn-number-max", no_class
,
2843 &record_full_insn_max_num
,
2844 _("Set record/replay buffer limit."),
2845 _("Show record/replay buffer limit."), _("\
2846 Set the maximum number of instructions to be stored in the\n\
2847 record/replay buffer. A value of either \"unlimited\" or zero means no\n\
2848 limit. Default is 200000."),
2849 set_record_full_insn_max_num
,
2850 NULL
, &set_record_full_cmdlist
,
2851 &show_record_full_cmdlist
);
2853 c
= add_alias_cmd ("insn-number-max", record_full_insn_number_max_cmds
.set
,
2854 no_class
, 1, &set_record_cmdlist
);
2855 deprecate_cmd (c
, "set record full insn-number-max");
2857 c
= add_alias_cmd ("insn-number-max", record_full_insn_number_max_cmds
.show
,
2858 no_class
, 1, &show_record_cmdlist
);
2859 deprecate_cmd (c
, "show record full insn-number-max");
2861 set_show_commands record_full_memory_query_cmds
2862 = add_setshow_boolean_cmd ("memory-query", no_class
,
2863 &record_full_memory_query
, _("\
2864 Set whether query if PREC cannot record memory change of next instruction."),
2866 Show whether query if PREC cannot record memory change of next instruction."),
2869 When ON, query if PREC cannot record memory change of next instruction."),
2871 &set_record_full_cmdlist
,
2872 &show_record_full_cmdlist
);
2874 c
= add_alias_cmd ("memory-query", record_full_memory_query_cmds
.set
,
2875 no_class
, 1, &set_record_cmdlist
);
2876 deprecate_cmd (c
, "set record full memory-query");
2878 c
= add_alias_cmd ("memory-query", record_full_memory_query_cmds
.show
,
2879 no_class
, 1,&show_record_cmdlist
);
2880 deprecate_cmd (c
, "show record full memory-query");