GDB (xrefs)
Loading...
Searching...
No Matches
/tmp/gdb-13.1/gdb/record-full.c
Go to the documentation of this file.
1/* Process record and replay target for GDB, the GNU debugger.
2
3 Copyright (C) 2013-2023 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
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.
11
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.
16
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/>. */
19
20#include "defs.h"
21#include "gdbcmd.h"
22#include "regcache.h"
23#include "gdbthread.h"
24#include "inferior.h"
25#include "event-top.h"
26#include "completer.h"
27#include "arch-utils.h"
28#include "gdbcore.h"
29#include "exec.h"
30#include "record.h"
31#include "record-full.h"
32#include "elf-bfd.h"
33#include "gcore.h"
34#include "gdbsupport/event-loop.h"
35#include "inf-loop.h"
36#include "gdb_bfd.h"
37#include "observable.h"
38#include "infrun.h"
39#include "gdbsupport/gdb_unlinker.h"
40#include "gdbsupport/byte-vector.h"
41#include "async-event.h"
42
43#include <signal.h>
44
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.
49
50 Target record has two modes: recording, and replaying.
51
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).
58
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. */
64
65#define DEFAULT_RECORD_FULL_INSN_MAX_NUM 200000
66
67#define RECORD_FULL_IS_REPLAY \
68 (record_full_list->next || ::execution_direction == EXEC_REVERSE)
69
70#define RECORD_FULL_FILE_MAGIC netorder32(0x20091016)
71
72/* These are the core structs of the process record functionality.
73
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
78 instruction.
79
80 Each struct record_full_entry is linked to "record_full_list" by "prev"
81 and "next" pointers. */
82
84{
85 CORE_ADDR addr;
86 int len;
87 /* Set this flag if target memory for this entry
88 can no longer be accessed. */
90 union
91 {
92 gdb_byte *ptr;
93 gdb_byte buf[sizeof (gdb_byte *)];
94 } u;
95};
96
98{
99 unsigned short num;
100 unsigned short len;
101 union
102 {
103 gdb_byte *ptr;
104 gdb_byte buf[2 * sizeof (gdb_byte *)];
105 } u;
106};
107
109{
110 enum gdb_signal sigval;
111 ULONGEST insn_num;
112};
113
115{
120
121/* This is the data structure that makes up the execution log.
122
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.
126
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).
131
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.
136
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. */
144
146{
150 union
151 {
152 /* reg */
154 /* mem */
156 /* end */
158 } u;
159};
160
161/* If true, query if PREC cannot record memory
162 change of next instruction. */
164
166{
169 bfd_byte *buf;
170};
171
172/* Record buf with core target. */
176
177/* The following variables are used for managing the linked list that
178 represents the execution log.
179
180 record_full_first is the anchor that holds down the beginning of
181 the list.
182
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.
187
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. */
193
198
199/* true ask user. false auto delete the last struct record_full_entry. */
200static bool record_full_stop_at_limit = true;
201/* Maximum allowed number of insns in execution log. */
202static unsigned int record_full_insn_max_num
204/* Actual count of insns presently in execution log. */
205static 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). */
209
210static const char record_longname[]
211 = N_("Process record and replay target");
212static const char record_doc[]
213 = N_("Log program while executing and replay execution from log.");
214
215/* Base class implementing functionality common to both the
216 "record-full" and "record-core" targets. */
217
219{
220public:
221 const target_info &info () const override = 0;
222
223 strata stratum () const override { return record_stratum; }
224
225 void close () override;
226 void async (bool) 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;
230
231 bool stopped_by_sw_breakpoint () override;
232 bool supports_stopped_by_sw_breakpoint () override;
233
234 bool stopped_by_hw_breakpoint () override;
235 bool supports_stopped_by_hw_breakpoint () override;
236
237 bool can_execute_reverse () override;
238
239 /* Add bookmark target methods. */
240 gdb_byte *get_bookmark (const char *, int) override;
241 void goto_bookmark (const gdb_byte *, int) 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;
254};
255
256/* The "record-full" target. */
257
259 "record-full",
262};
263
265{
266public:
267 const target_info &info () const override
268 { return record_full_target_info; }
269
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;
277 const char *annex,
278 gdb_byte *readbuf,
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;
287};
288
289/* The "record-core" target. */
290
292 "record-core",
295};
296
298{
299public:
300 const target_info &info () const override
302
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;
310 const char *annex,
311 gdb_byte *readbuf,
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;
320
321 bool has_execution (inferior *inf) override;
322};
323
326
327void
329{
330 record_detach (this, inf, from_tty);
331}
332
333void
334record_full_target::disconnect (const char *args, int from_tty)
335{
336 record_disconnect (this, args, from_tty);
337}
338
339void
340record_full_core_target::disconnect (const char *args, int from_tty)
341{
342 record_disconnect (this, args, from_tty);
343}
344
345void
347{
349}
350
351void
353{
354 record_kill (this);
355}
356
357/* See record-full.h. */
358
359int
361{
362 struct target_ops *t;
363
364 t = find_record_target ();
365 return (t == &record_full_ops
366 || t == &record_full_core_ops);
367}
368
369
370/* Command lists for "set/show record full". */
373
374/* Command list for "record full". */
376
377static void record_full_goto_insn (struct record_full_entry *entry,
378 enum exec_direction_kind dir);
379
380/* Alloc and free functions for record_full_reg, record_full_mem, and
381 record_full_end entries. */
382
383/* Alloc a record_full_reg record entry. */
384
385static inline struct record_full_entry *
387{
388 struct record_full_entry *rec;
389 struct gdbarch *gdbarch = regcache->arch ();
390
391 rec = XCNEW (struct record_full_entry);
392 rec->type = record_full_reg;
393 rec->u.reg.num = 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);
397
398 return rec;
399}
400
401/* Free a record_full_reg record entry. */
402
403static inline void
405{
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);
409 xfree (rec);
410}
411
412/* Alloc a record_full_mem record entry. */
413
414static inline struct record_full_entry *
415record_full_mem_alloc (CORE_ADDR addr, int len)
416{
417 struct record_full_entry *rec;
418
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);
425
426 return rec;
427}
428
429/* Free a record_full_mem record entry. */
430
431static inline void
433{
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);
437 xfree (rec);
438}
439
440/* Alloc a record_full_end record entry. */
441
442static inline struct record_full_entry *
444{
445 struct record_full_entry *rec;
446
447 rec = XCNEW (struct record_full_entry);
448 rec->type = record_full_end;
449
450 return rec;
451}
452
453/* Free a record_full_end record entry. */
454
455static inline void
457{
458 xfree (rec);
459}
460
461/* Free one record entry, any type.
462 Return entry->type, in case caller wants to know. */
463
464static inline enum record_full_type
466{
467 enum record_full_type type = rec->type;
468
469 switch (type) {
470 case record_full_reg:
472 break;
473 case record_full_mem:
475 break;
476 case record_full_end:
478 break;
479 }
480 return type;
481}
482
483/* Free all record entries in list pointed to by REC. */
484
485static void
487{
488 if (!rec)
489 return;
490
491 while (rec->next)
492 rec = rec->next;
493
494 while (rec->prev)
495 {
496 rec = rec->prev;
498 }
499
500 if (rec == &record_full_first)
501 {
503 record_full_first.next = NULL;
504 }
505 else
507}
508
509/* Free all record entries forward of the given list position. */
510
511static void
513{
514 struct record_full_entry *tmp = rec->next;
515
516 rec->next = NULL;
517 while (tmp)
518 {
519 rec = tmp->next;
521 {
524 }
525 tmp = rec;
526 }
527}
528
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.
531
532 Note -- this function does not modify record_full_insn_num. */
533
534static void
536{
537 struct record_full_entry *tmp;
538
540 return;
541
542 /* Loop until a record_full_end. */
543 while (1)
544 {
545 /* Cut record_full_first.next out of the linked list. */
548 tmp->next->prev = &record_full_first;
549
550 /* tmp is now isolated, and can be deleted. */
552 break; /* End loop at first record_full_end. */
553
555 {
556 gdb_assert (record_full_insn_num == 1);
557 break; /* End loop when list is empty. */
558 }
559 }
560}
561
562/* Add a struct record_full_entry to record_full_arch_list. */
563
564static void
566{
567 if (record_debug > 1)
569 "Process record: record_full_arch_list_add %s.\n",
570 host_address_to_string (rec));
571
573 {
577 }
578 else
579 {
582 }
583}
584
585/* Return the value storage location of a record entry. */
586static inline gdb_byte *
588{
589 switch (rec->type) {
590 case record_full_mem:
591 if (rec->u.mem.len > sizeof (rec->u.mem.u.buf))
592 return rec->u.mem.u.ptr;
593 else
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;
598 else
599 return rec->u.reg.u.buf;
600 case record_full_end:
601 default:
602 gdb_assert_not_reached ("unexpected record_full_entry type");
603 return NULL;
604 }
605}
606
607/* Record the value of a register NUM to record_full_arch_list. */
608
609int
611{
612 struct record_full_entry *rec;
613
614 if (record_debug > 1)
616 "Process record: add register num = %d to "
617 "record list.\n",
618 regnum);
619
621
623
625
626 return 0;
627}
628
629/* Record the value of a region of memory whose address is ADDR and
630 length is LEN to record_full_arch_list. */
631
632int
633record_full_arch_list_add_mem (CORE_ADDR addr, int len)
634{
635 struct record_full_entry *rec;
636
637 if (record_debug > 1)
639 "Process record: add mem addr = %s len = %d to "
640 "record list.\n",
641 paddress (target_gdbarch (), addr), len);
642
643 if (!addr) /* FIXME: Why? Some arch must permit it... */
644 return 0;
645
646 rec = record_full_mem_alloc (addr, len);
647
649 record_full_get_loc (rec), len))
650 {
652 return -1;
653 }
654
656
657 return 0;
658}
659
660/* Add a record_full_end type struct record_full_entry to
661 record_full_arch_list. */
662
663int
665{
666 struct record_full_entry *rec;
667
668 if (record_debug > 1)
670 "Process record: add end to arch list.\n");
671
672 rec = record_full_end_alloc ();
673 rec->u.end.sigval = GDB_SIGNAL_0;
675
677
678 return 0;
679}
680
681static void
683{
685 {
686 /* Ask user what to do. */
688 {
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."));
694 }
695 }
696}
697
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. */
703
704static void
705record_full_message (struct regcache *regcache, enum gdb_signal signal)
706{
707 int ret;
708 struct gdbarch *gdbarch = regcache->arch ();
709
710 try
711 {
714
715 /* Check record_full_insn_num. */
717
718 /* If gdb sends a signal value to target_resume,
719 save it in the 'end' field of the previous instruction.
720
721 Maybe process record should record what really happened,
722 rather than what gdb pretends has happened.
723
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
726 the replay mode.
727
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).
732
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.
736
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
742 to check */
743 {
744 gdb_assert (record_full_list->type == record_full_end);
745 record_full_list->u.end.sigval = signal;
746 }
747
748 if (signal == GDB_SIGNAL_0
751 regcache,
753 else
755 regcache,
756 signal);
757
758 if (ret > 0)
759 error (_("Process record: inferior program stopped."));
760 if (ret < 0)
761 error (_("Process record: failed to record execution log."));
762 }
763 catch (const gdb_exception &ex)
764 {
766 throw;
767 }
768
772
775 else
777}
778
779static bool
781 enum gdb_signal signal)
782{
783 try
784 {
786 }
787 catch (const gdb_exception &ex)
788 {
790 return false;
791 }
792
793 return true;
794}
795
796/* Set to 1 if record_full_store_registers and record_full_xfer_partial
797 doesn't need record. */
798
800
801scoped_restore_tmpl<int>
803{
804 return make_scoped_restore (&record_full_gdb_operation_disable, 1);
805}
806
807/* Flag set to TRUE for target_stopped_by_watchpoint. */
810
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. */
814
815static inline void
817 struct gdbarch *gdbarch,
818 struct record_full_entry *entry)
819{
820 switch (entry->type)
821 {
822 case record_full_reg: /* reg */
823 {
824 gdb::byte_vector reg (entry->u.reg.len);
825
826 if (record_debug > 1)
828 "Process record: record_full_reg %s to "
829 "inferior num = %d.\n",
830 host_address_to_string (entry),
831 entry->u.reg.num);
832
833 regcache->cooked_read (entry->u.reg.num, reg.data ());
835 memcpy (record_full_get_loc (entry), reg.data (), entry->u.reg.len);
836 }
837 break;
838
839 case record_full_mem: /* mem */
840 {
841 /* Nothing to do if the entry is flagged not_accessible. */
842 if (!entry->u.mem.mem_entry_not_accessible)
843 {
844 gdb::byte_vector mem (entry->u.mem.len);
845
846 if (record_debug > 1)
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),
852 entry->u.mem.len);
853
855 entry->u.mem.addr, mem.data (),
856 entry->u.mem.len))
857 entry->u.mem.mem_entry_not_accessible = 1;
858 else
859 {
860 if (target_write_memory (entry->u.mem.addr,
861 record_full_get_loc (entry),
862 entry->u.mem.len))
863 {
864 entry->u.mem.mem_entry_not_accessible = 1;
865 if (record_debug)
866 warning (_("Process record: error writing memory at "
867 "addr = %s len = %d."),
868 paddress (gdbarch, entry->u.mem.addr),
869 entry->u.mem.len);
870 }
871 else
872 {
873 memcpy (record_full_get_loc (entry), mem.data (),
874 entry->u.mem.len);
875
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
883 traps. */
885 (regcache->aspace (),
886 entry->u.mem.addr, entry->u.mem.len))
888 }
889 }
890 }
891 }
892 break;
893 }
894}
895
896static void record_full_restore (void);
897
898/* Asynchronous signal handle registered as event loop source for when
899 we have pending events ready to be passed to the core. */
900
902
903static void
905{
907}
908
909/* Open the process record target for 'core' files. */
910
911static void
912record_full_core_open_1 (const char *name, int from_tty)
913{
916 int i;
917
918 /* Get record_full_core_regbuf. */
921
922 for (i = 0; i < regnum; i ++)
924
926
929}
930
931/* Open the process record target for 'live' processes. */
932
933static void
934record_full_open_1 (const char *name, int from_tty)
935{
936 if (record_debug)
937 gdb_printf (gdb_stdlog, "Process record: record_full_open_1\n");
938
939 /* check exec */
940 if (!target_has_execution ())
941 error (_("Process record: the program is not being run."));
942 if (non_stop)
943 error (_("Process record target can't debug inferior in non-stop mode "
944 "(non-stop)."));
945
947 error (_("Process record: the current architecture doesn't support "
948 "record function."));
949
951}
952
953static void record_full_init_record_breakpoints (void);
954
955/* Open the process record target. */
956
957static void
958record_full_open (const char *name, int from_tty)
959{
960 if (record_debug)
961 gdb_printf (gdb_stdlog, "Process record: record_full_open\n");
962
964
965 /* Reset */
969 record_full_list->next = NULL;
970
971 if (core_bfd)
972 record_full_core_open_1 (name, from_tty);
973 else
974 record_full_open_1 (name, from_tty);
975
976 /* Register extra event sources in the event loop. */
979 NULL, "record-full");
980
982
983 gdb::observers::record_changed.notify (current_inferior (), 1, "full", NULL);
984}
985
986/* "close" target method. Close the process record target. */
987
988void
990{
991 struct record_full_core_buf_entry *entry;
992
993 if (record_debug)
994 gdb_printf (gdb_stdlog, "Process record: record_full_close\n");
995
997
998 /* Release record_full_core_regbuf. */
1000 {
1003 }
1004
1005 /* Release record_full_core_buf_list. */
1007 {
1010 xfree (entry);
1011 }
1012
1015}
1016
1017/* "async" target method. */
1018
1019void
1021{
1022 if (enable)
1024 else
1026
1027 beneath ()->async (enable);
1028}
1029
1030/* The PTID and STEP arguments last passed to
1031 record_full_target::resume. */
1032static ptid_t record_full_resume_ptid = null_ptid;
1034
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. */
1038static int record_full_resumed = 0;
1039
1040/* The execution direction of the last resume we got. This is
1041 necessary for async mode. Vis (order is not strictly accurate):
1042
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.
1053*/
1055
1056/* "resume" target method. Resume the process record target. */
1057
1058void
1059record_full_target::resume (ptid_t ptid, int step, enum gdb_signal signal)
1060{
1065
1067 {
1069
1071
1072 if (!step)
1073 {
1074 /* This is not hard single step. */
1076 {
1077 /* This is a normal continue. */
1078 step = 1;
1079 }
1080 else
1081 {
1082 /* This arch supports soft single step. */
1084 {
1085 /* This is a soft single step. */
1087 }
1088 else
1090 }
1091 }
1092
1093 /* Make sure the target beneath reports all signals. */
1095
1096 this->beneath ()->resume (ptid, step, signal);
1097 }
1098}
1099
1100static int record_full_get_sig = 0;
1101
1102/* SIGINT signal handler, registered by "wait" method. */
1103
1104static void
1106{
1107 if (record_debug)
1108 gdb_printf (gdb_stdlog, "Process record: get a signal\n");
1109
1110 /* It will break the running inferior in replay mode. */
1112
1113 /* It will let record_full_wait set inferior status to get the signal
1114 SIGINT. */
1116}
1117
1118/* "wait" target method for process record target.
1119
1120 In record mode, the target is always run in singlestep mode
1121 (even when gdb says to continue). The wait method intercepts
1122 the stop events and determines which ones are to be passed on to
1123 gdb. Most stop events are just singlestep events that gdb is not
1124 to know about, so the wait method just records them and keeps
1125 singlestepping.
1126
1127 In replay mode, this function emulates the recorded execution log,
1128 one instruction at a time (forward or backward), and determines
1129 where to stop. */
1130
1131static ptid_t
1133 ptid_t ptid, struct target_waitstatus *status,
1134 target_wait_flags options)
1135{
1136 scoped_restore restore_operation_disable
1138
1139 if (record_debug)
1141 "Process record: record_full_wait "
1142 "record_full_resume_step = %d, "
1143 "record_full_resumed = %d, direction=%s\n",
1146 ? "forward" : "reverse");
1147
1149 {
1150 gdb_assert ((options & TARGET_WNOHANG) != 0);
1151
1152 /* No interesting event. */
1153 status->set_ignore ();
1154 return minus_one_ptid;
1155 }
1156
1158 signal (SIGINT, record_full_sig_handler);
1159
1161
1163 {
1165 {
1166 /* This is a single step. */
1167 return ops->beneath ()->wait (ptid, status, options);
1168 }
1169 else
1170 {
1171 /* This is not a single step. */
1172 ptid_t ret;
1173 CORE_ADDR tmp_pc;
1174 struct gdbarch *gdbarch
1176
1177 while (1)
1178 {
1179 ret = ops->beneath ()->wait (ptid, status, options);
1180 if (status->kind () == TARGET_WAITKIND_IGNORE)
1181 {
1182 if (record_debug)
1184 "Process record: record_full_wait "
1185 "target beneath not done yet\n");
1186 return ret;
1187 }
1188
1189 for (thread_info *tp : all_non_exited_threads ())
1191
1193 return ret;
1194
1195 /* Is this a SIGTRAP? */
1196 if (status->kind () == TARGET_WAITKIND_STOPPED
1197 && status->sig () == GDB_SIGNAL_TRAP)
1198 {
1199 struct regcache *regcache;
1200 enum target_stop_reason *stop_reason_p
1202
1203 /* Yes -- this is likely our single-step finishing,
1204 but check if there's any reason the core would be
1205 interested in the event. */
1206
1208 switch_to_thread (current_inferior ()->process_target (),
1209 ret);
1211 tmp_pc = regcache_read_pc (regcache);
1212 const struct address_space *aspace = regcache->aspace ();
1213
1215 {
1216 /* Always interested in watchpoints. */
1217 }
1218 else if (record_check_stopped_by_breakpoint (aspace, tmp_pc,
1219 stop_reason_p))
1220 {
1221 /* There is a breakpoint here. Let the core
1222 handle it. */
1223 }
1224 else
1225 {
1226 /* This is a single-step trap. Record the
1227 insn and issue another step.
1228 FIXME: this part can be a random SIGTRAP too.
1229 But GDB cannot handle it. */
1230 int step = 1;
1231
1233 GDB_SIGNAL_0))
1234 {
1235 status->set_stopped (GDB_SIGNAL_0);
1236 break;
1237 }
1238
1239 process_stratum_target *proc_target
1241
1243 {
1244 /* Try to insert the software single step breakpoint.
1245 If insert success, set step to 0. */
1246 set_executing (proc_target, inferior_ptid, false);
1247 SCOPE_EXIT
1248 {
1249 set_executing (proc_target, inferior_ptid, true);
1250 };
1251
1254 }
1255
1256 if (record_debug)
1258 "Process record: record_full_wait "
1259 "issuing one more step in the "
1260 "target beneath\n");
1261 ops->beneath ()->resume (ptid, step, GDB_SIGNAL_0);
1262 proc_target->commit_resumed_state = true;
1263 proc_target->commit_resumed ();
1264 proc_target->commit_resumed_state = false;
1265 continue;
1266 }
1267 }
1268
1269 /* The inferior is broken by a breakpoint or a signal. */
1270 break;
1271 }
1272
1273 return ret;
1274 }
1275 }
1276 else
1277 {
1278 switch_to_thread (current_inferior ()->process_target (),
1281 struct gdbarch *gdbarch = regcache->arch ();
1282 const struct address_space *aspace = regcache->aspace ();
1283 int continue_flag = 1;
1284 int first_record_full_end = 1;
1285
1286 try
1287 {
1288 CORE_ADDR tmp_pc;
1289
1291 status->set_stopped (GDB_SIGNAL_0);
1292
1293 /* Check breakpoint when forward execute. */
1295 {
1296 tmp_pc = regcache_read_pc (regcache);
1297 if (record_check_stopped_by_breakpoint (aspace, tmp_pc,
1299 {
1300 if (record_debug)
1302 "Process record: break at %s.\n",
1303 paddress (gdbarch, tmp_pc));
1304 goto replay_out;
1305 }
1306 }
1307
1308 /* If GDB is in terminal_inferior mode, it will not get the
1309 signal. And in GDB replay mode, GDB doesn't need to be
1310 in terminal_inferior mode, because inferior will not
1311 executed. Then set it to terminal_ours to make GDB get
1312 the signal. */
1314
1315 /* In EXEC_FORWARD mode, record_full_list points to the tail of prev
1316 instruction. */
1319
1320 /* Loop over the record_full_list, looking for the next place to
1321 stop. */
1322 do
1323 {
1324 /* Check for beginning and end of log. */
1327 {
1328 /* Hit beginning of record log in reverse. */
1329 status->set_no_history ();
1330 break;
1331 }
1334 {
1335 /* Hit end of record log going forward. */
1336 status->set_no_history ();
1337 break;
1338 }
1339
1341
1343 {
1344 if (record_debug > 1)
1346 (gdb_stdlog,
1347 "Process record: record_full_end %s to "
1348 "inferior.\n",
1349 host_address_to_string (record_full_list));
1350
1351 if (first_record_full_end
1353 {
1354 /* When reverse execute, the first
1355 record_full_end is the part of current
1356 instruction. */
1357 first_record_full_end = 0;
1358 }
1359 else
1360 {
1361 /* In EXEC_REVERSE mode, this is the
1362 record_full_end of prev instruction. In
1363 EXEC_FORWARD mode, this is the
1364 record_full_end of current instruction. */
1365 /* step */
1367 {
1368 if (record_debug > 1)
1370 "Process record: step.\n");
1371 continue_flag = 0;
1372 }
1373
1374 /* check breakpoint */
1375 tmp_pc = regcache_read_pc (regcache);
1377 (aspace, tmp_pc, &record_full_stop_reason))
1378 {
1379 if (record_debug)
1381 "Process record: break "
1382 "at %s.\n",
1383 paddress (gdbarch, tmp_pc));
1384
1385 continue_flag = 0;
1386 }
1387
1390 {
1391 if (record_debug)
1393 "Process record: hit hw "
1394 "watchpoint.\n");
1395 continue_flag = 0;
1396 }
1397 /* Check target signal */
1398 if (record_full_list->u.end.sigval != GDB_SIGNAL_0)
1399 /* FIXME: better way to check */
1400 continue_flag = 0;
1401 }
1402 }
1403
1404 if (continue_flag)
1405 {
1407 {
1410 }
1411 else
1412 {
1415 }
1416 }
1417 }
1418 while (continue_flag);
1419
1420 replay_out:
1421 if (status->kind () == TARGET_WAITKIND_STOPPED)
1422 {
1424 status->set_stopped (GDB_SIGNAL_INT);
1425 else if (record_full_list->u.end.sigval != GDB_SIGNAL_0)
1426 /* FIXME: better way to check */
1427 status->set_stopped (record_full_list->u.end.sigval);
1428 else
1429 status->set_stopped (GDB_SIGNAL_TRAP);
1430 }
1431 }
1432 catch (const gdb_exception &ex)
1433 {
1435 {
1438 }
1439 else
1441
1442 throw;
1443 }
1444 }
1445
1446 signal (SIGINT, handle_sigint);
1447
1448 return inferior_ptid;
1449}
1450
1451ptid_t
1453 target_wait_flags options)
1454{
1455 ptid_t return_ptid;
1456
1458
1459 return_ptid = record_full_wait_1 (this, ptid, status, options);
1460 if (status->kind () != TARGET_WAITKIND_IGNORE)
1461 {
1462 /* We're reporting a stop. Make sure any spurious
1463 target_wait(WNOHANG) doesn't advance the target until the
1464 core wants us resumed again. */
1466 }
1467 return return_ptid;
1468}
1469
1470bool
1472{
1475 else
1476 return beneath ()->stopped_by_watchpoint ();
1477}
1478
1479bool
1481{
1483 return false;
1484 else
1485 return this->beneath ()->stopped_data_address (addr_p);
1486}
1487
1488/* The stopped_by_sw_breakpoint method of target record-full. */
1489
1490bool
1492{
1494}
1495
1496/* The supports_stopped_by_sw_breakpoint method of target
1497 record-full. */
1498
1499bool
1501{
1502 return true;
1503}
1504
1505/* The stopped_by_hw_breakpoint method of target record-full. */
1506
1507bool
1509{
1511}
1512
1513/* The supports_stopped_by_sw_breakpoint method of target
1514 record-full. */
1515
1516bool
1518{
1519 return true;
1520}
1521
1522/* Record registers change (by user or by GDB) to list as an instruction. */
1523
1524static void
1526{
1527 /* Check record_full_insn_num. */
1529
1532
1533 if (regnum < 0)
1534 {
1535 int i;
1536
1537 for (i = 0; i < gdbarch_num_regs (regcache->arch ()); i++)
1538 {
1540 {
1542 error (_("Process record: failed to record execution log."));
1543 }
1544 }
1545 }
1546 else
1547 {
1549 {
1551 error (_("Process record: failed to record execution log."));
1552 }
1553 }
1555 {
1557 error (_("Process record: failed to record execution log."));
1558 }
1562
1565 else
1567}
1568
1569/* "store_registers" method for process record target. */
1570
1571void
1573{
1575 {
1577 {
1578 int n;
1579
1580 /* Let user choose if he wants to write register or not. */
1581 if (regno < 0)
1582 n =
1583 query (_("Because GDB is in replay mode, changing the "
1584 "value of a register will make the execution "
1585 "log unusable from this point onward. "
1586 "Change all registers?"));
1587 else
1588 n =
1589 query (_("Because GDB is in replay mode, changing the value "
1590 "of a register will make the execution log unusable "
1591 "from this point onward. Change register %s?"),
1593 regno));
1594
1595 if (!n)
1596 {
1597 /* Invalidate the value of regcache that was set in function
1598 "regcache_raw_write". */
1599 if (regno < 0)
1600 {
1601 int i;
1602
1603 for (i = 0;
1604 i < gdbarch_num_regs (regcache->arch ());
1605 i++)
1606 regcache->invalidate (i);
1607 }
1608 else
1609 regcache->invalidate (regno);
1610
1611 error (_("Process record canceled the operation."));
1612 }
1613
1614 /* Destroy the record from here forward. */
1616 }
1617
1619 }
1620 this->beneath ()->store_registers (regcache, regno);
1621}
1622
1623/* "xfer_partial" method. Behavior is conditional on
1624 RECORD_FULL_IS_REPLAY.
1625 In replay mode, we cannot write memory unles we are willing to
1626 invalidate the record/replay log from this point forward. */
1627
1630 const char *annex, gdb_byte *readbuf,
1631 const gdb_byte *writebuf, ULONGEST offset,
1632 ULONGEST len, ULONGEST *xfered_len)
1633{
1635 && (object == TARGET_OBJECT_MEMORY
1636 || object == TARGET_OBJECT_RAW_MEMORY) && writebuf)
1637 {
1639 {
1640 /* Let user choose if he wants to write memory or not. */
1641 if (!query (_("Because GDB is in replay mode, writing to memory "
1642 "will make the execution log unusable from this "
1643 "point onward. Write memory at address %s?"),
1644 paddress (target_gdbarch (), offset)))
1645 error (_("Process record canceled the operation."));
1646
1647 /* Destroy the record from here forward. */
1649 }
1650
1651 /* Check record_full_insn_num */
1653
1654 /* Record registers change to list as an instruction. */
1657 if (record_full_arch_list_add_mem (offset, len))
1658 {
1660 if (record_debug)
1662 "Process record: failed to record "
1663 "execution log.");
1664 return TARGET_XFER_E_IO;
1665 }
1667 {
1669 if (record_debug)
1671 "Process record: failed to record "
1672 "execution log.");
1673 return TARGET_XFER_E_IO;
1674 }
1678
1681 else
1683 }
1684
1685 return this->beneath ()->xfer_partial (object, annex, readbuf, writebuf,
1686 offset, len, xfered_len);
1687}
1688
1689/* This structure represents a breakpoint inserted while the record
1690 target is active. We use this to know when to install/remove
1691 breakpoints in/from the target beneath. For example, a breakpoint
1692 may be inserted while recording, but removed when not replaying nor
1693 recording. In that case, the breakpoint had not been inserted on
1694 the target beneath, so we should not try to remove it there. */
1695
1697{
1698 record_full_breakpoint (struct address_space *address_space_,
1699 CORE_ADDR addr_,
1700 bool in_target_beneath_)
1701 : address_space (address_space_),
1702 addr (addr_),
1703 in_target_beneath (in_target_beneath_)
1704 {
1705 }
1706
1707 /* The address and address space the breakpoint was set at. */
1709 CORE_ADDR addr;
1710
1711 /* True when the breakpoint has been also installed in the target
1712 beneath. This will be false for breakpoints set during replay or
1713 when recording. */
1715};
1716
1717/* The list of breakpoints inserted while the record target is
1718 active. */
1719static std::vector<record_full_breakpoint> record_full_breakpoints;
1720
1721/* Sync existing breakpoints to record_full_breakpoints. */
1722
1723static void
1725{
1726 record_full_breakpoints.clear ();
1727
1728 for (bp_location *loc : all_bp_locations ())
1729 {
1730 if (loc->loc_type != bp_loc_software_breakpoint)
1731 continue;
1732
1733 if (loc->inserted)
1734 record_full_breakpoints.emplace_back
1735 (loc->target_info.placed_address_space,
1736 loc->target_info.placed_address, 1);
1737 }
1738}
1739
1740/* Behavior is conditional on RECORD_FULL_IS_REPLAY. We will not actually
1741 insert or remove breakpoints in the real target when replaying, nor
1742 when recording. */
1743
1744int
1746 struct bp_target_info *bp_tgt)
1747{
1748 bool in_target_beneath = false;
1749
1751 {
1752 /* When recording, we currently always single-step, so we don't
1753 really need to install regular breakpoints in the inferior.
1754 However, we do have to insert software single-step
1755 breakpoints, in case the target can't hardware step. To keep
1756 things simple, we always insert. */
1757
1758 scoped_restore restore_operation_disable
1760
1761 int ret = this->beneath ()->insert_breakpoint (gdbarch, bp_tgt);
1762 if (ret != 0)
1763 return ret;
1764
1765 in_target_beneath = true;
1766 }
1767
1768 /* Use the existing entries if found in order to avoid duplication
1769 in record_full_breakpoints. */
1770
1772 {
1773 if (bp.addr == bp_tgt->placed_address
1774 && bp.address_space == bp_tgt->placed_address_space)
1775 {
1776 gdb_assert (bp.in_target_beneath == in_target_beneath);
1777 return 0;
1778 }
1779 }
1780
1781 record_full_breakpoints.emplace_back (bp_tgt->placed_address_space,
1782 bp_tgt->placed_address,
1783 in_target_beneath);
1784 return 0;
1785}
1786
1787/* "remove_breakpoint" method for process record target. */
1788
1789int
1791 struct bp_target_info *bp_tgt,
1792 enum remove_bp_reason reason)
1793{
1794 for (auto iter = record_full_breakpoints.begin ();
1795 iter != record_full_breakpoints.end ();
1796 ++iter)
1797 {
1798 struct record_full_breakpoint &bp = *iter;
1799
1800 if (bp.addr == bp_tgt->placed_address
1801 && bp.address_space == bp_tgt->placed_address_space)
1802 {
1803 if (bp.in_target_beneath)
1804 {
1805 scoped_restore restore_operation_disable
1807
1808 int ret = this->beneath ()->remove_breakpoint (gdbarch, bp_tgt,
1809 reason);
1810 if (ret != 0)
1811 return ret;
1812 }
1813
1814 if (reason == REMOVE_BREAKPOINT)
1815 unordered_remove (record_full_breakpoints, iter);
1816 return 0;
1817 }
1818 }
1819
1820 gdb_assert_not_reached ("removing unknown breakpoint");
1821}
1822
1823/* "can_execute_reverse" method for process record target. */
1824
1825bool
1827{
1828 return true;
1829}
1830
1831/* "get_bookmark" method for process record and prec over core. */
1832
1833gdb_byte *
1834record_full_base_target::get_bookmark (const char *args, int from_tty)
1835{
1836 char *ret = NULL;
1837
1838 /* Return stringified form of instruction count. */
1840 ret = xstrdup (pulongest (record_full_list->u.end.insn_num));
1841
1842 if (record_debug)
1843 {
1844 if (ret)
1846 "record_full_get_bookmark returns %s\n", ret);
1847 else
1849 "record_full_get_bookmark returns NULL\n");
1850 }
1851 return (gdb_byte *) ret;
1852}
1853
1854/* "goto_bookmark" method for process record and prec over core. */
1855
1856void
1857record_full_base_target::goto_bookmark (const gdb_byte *raw_bookmark,
1858 int from_tty)
1859{
1860 const char *bookmark = (const char *) raw_bookmark;
1861
1862 if (record_debug)
1864 "record_full_goto_bookmark receives %s\n", bookmark);
1865
1866 std::string name_holder;
1867 if (bookmark[0] == '\'' || bookmark[0] == '\"')
1868 {
1869 if (bookmark[strlen (bookmark) - 1] != bookmark[0])
1870 error (_("Unbalanced quotes: %s"), bookmark);
1871
1872 name_holder = std::string (bookmark + 1, strlen (bookmark) - 2);
1873 bookmark = name_holder.c_str ();
1874 }
1875
1877}
1878
1881{
1883}
1884
1885/* The record_method method of target record-full. */
1886
1887enum record_method
1889{
1890 return RECORD_METHOD_FULL;
1891}
1892
1893void
1895{
1896 struct record_full_entry *p;
1897
1899 gdb_printf (_("Replay mode:\n"));
1900 else
1901 gdb_printf (_("Record mode:\n"));
1902
1903 /* Find entry for first actual instruction in the log. */
1904 for (p = record_full_first.next;
1905 p != NULL && p->type != record_full_end;
1906 p = p->next)
1907 ;
1908
1909 /* Do we have a log at all? */
1910 if (p != NULL && p->type == record_full_end)
1911 {
1912 /* Display instruction number for first instruction in the log. */
1913 gdb_printf (_("Lowest recorded instruction number is %s.\n"),
1914 pulongest (p->u.end.insn_num));
1915
1916 /* If in replay mode, display where we are in the log. */
1918 gdb_printf (_("Current instruction number is %s.\n"),
1919 pulongest (record_full_list->u.end.insn_num));
1920
1921 /* Display instruction number for last instruction in the log. */
1922 gdb_printf (_("Highest recorded instruction number is %s.\n"),
1923 pulongest (record_full_insn_count));
1924
1925 /* Display log count. */
1926 gdb_printf (_("Log contains %u instructions.\n"),
1928 }
1929 else
1930 gdb_printf (_("No instructions have been logged.\n"));
1931
1932 /* Display max log size. */
1933 gdb_printf (_("Max logged instructions is %u.\n"),
1935}
1936
1937bool
1939{
1940 return true;
1941}
1942
1943/* The "delete_record" target method. */
1944
1945void
1947{
1949}
1950
1951/* The "record_is_replaying" target method. */
1952
1953bool
1955{
1956 return RECORD_FULL_IS_REPLAY;
1957}
1958
1959/* The "record_will_replay" target method. */
1960
1961bool
1963{
1964 /* We can currently only record when executing forwards. Should we be able
1965 to record when executing backwards on targets that support reverse
1966 execution, this needs to be changed. */
1967
1968 return RECORD_FULL_IS_REPLAY || dir == EXEC_REVERSE;
1969}
1970
1971/* Go to a specific entry. */
1972
1973static void
1975{
1976 if (p == NULL)
1977 error (_("Target insn not found."));
1978 else if (p == record_full_list)
1979 error (_("Already at target insn."));
1980 else if (p->u.end.insn_num > record_full_list->u.end.insn_num)
1981 {
1982 gdb_printf (_("Go forward to insn number %s\n"),
1983 pulongest (p->u.end.insn_num));
1985 }
1986 else
1987 {
1988 gdb_printf (_("Go backward to insn number %s\n"),
1989 pulongest (p->u.end.insn_num));
1991 }
1992
1997}
1998
1999/* The "goto_record_begin" target method. */
2000
2001void
2003{
2004 struct record_full_entry *p = NULL;
2005
2006 for (p = &record_full_first; p != NULL; p = p->next)
2007 if (p->type == record_full_end)
2008 break;
2009
2011}
2012
2013/* The "goto_record_end" target method. */
2014
2015void
2017{
2018 struct record_full_entry *p = NULL;
2019
2020 for (p = record_full_list; p->next != NULL; p = p->next)
2021 ;
2022 for (; p!= NULL; p = p->prev)
2023 if (p->type == record_full_end)
2024 break;
2025
2027}
2028
2029/* The "goto_record" target method. */
2030
2031void
2033{
2034 struct record_full_entry *p = NULL;
2035
2036 for (p = &record_full_first; p != NULL; p = p->next)
2037 if (p->type == record_full_end && p->u.end.insn_num == target_insn)
2038 break;
2039
2041}
2042
2043/* The "record_stop_replaying" target method. */
2044
2045void
2047{
2048 goto_record_end ();
2049}
2050
2051/* "resume" method for prec over corefile. */
2052
2053void
2054record_full_core_target::resume (ptid_t ptid, int step,
2055 enum gdb_signal signal)
2056{
2060}
2061
2062/* "kill" method for prec over corefile. */
2063
2064void
2066{
2067 if (record_debug)
2068 gdb_printf (gdb_stdlog, "Process record: record_full_core_kill\n");
2069
2071}
2072
2073/* "fetch_registers" method for prec over corefile. */
2074
2075void
2077 int regno)
2078{
2079 if (regno < 0)
2080 {
2081 int num = gdbarch_num_regs (regcache->arch ());
2082 int i;
2083
2084 for (i = 0; i < num; i ++)
2086 }
2087 else
2089}
2090
2091/* "prepare_to_store" method for prec over corefile. */
2092
2093void
2095{
2096}
2097
2098/* "store_registers" method for prec over corefile. */
2099
2100void
2102 int regno)
2103{
2106 else
2107 error (_("You can't do that without a process to debug."));
2108}
2109
2110/* "xfer_partial" method for prec over corefile. */
2111
2114 const char *annex, gdb_byte *readbuf,
2115 const gdb_byte *writebuf, ULONGEST offset,
2116 ULONGEST len, ULONGEST *xfered_len)
2117{
2118 if (object == TARGET_OBJECT_MEMORY)
2119 {
2120 if (record_full_gdb_operation_disable || !writebuf)
2121 {
2123 {
2124 if (offset >= p.addr)
2125 {
2126 struct record_full_core_buf_entry *entry;
2127 ULONGEST sec_offset;
2128
2129 if (offset >= p.endaddr)
2130 continue;
2131
2132 if (offset + len > p.endaddr)
2133 len = p.endaddr - offset;
2134
2135 sec_offset = offset - p.addr;
2136
2137 /* Read readbuf or write writebuf p, offset, len. */
2138 /* Check flags. */
2139 if (p.the_bfd_section->flags & SEC_CONSTRUCTOR
2140 || (p.the_bfd_section->flags & SEC_HAS_CONTENTS) == 0)
2141 {
2142 if (readbuf)
2143 memset (readbuf, 0, len);
2144
2145 *xfered_len = len;
2146 return TARGET_XFER_OK;
2147 }
2148 /* Get record_full_core_buf_entry. */
2149 for (entry = record_full_core_buf_list; entry;
2150 entry = entry->prev)
2151 if (entry->p == &p)
2152 break;
2153 if (writebuf)
2154 {
2155 if (!entry)
2156 {
2157 /* Add a new entry. */
2158 entry = XNEW (struct record_full_core_buf_entry);
2159 entry->p = &p;
2160 if (!bfd_malloc_and_get_section
2161 (p.the_bfd_section->owner,
2162 p.the_bfd_section,
2163 &entry->buf))
2164 {
2165 xfree (entry);
2166 return TARGET_XFER_EOF;
2167 }
2170 }
2171
2172 memcpy (entry->buf + sec_offset, writebuf,
2173 (size_t) len);
2174 }
2175 else
2176 {
2177 if (!entry)
2178 return this->beneath ()->xfer_partial (object, annex,
2179 readbuf, writebuf,
2180 offset, len,
2181 xfered_len);
2182
2183 memcpy (readbuf, entry->buf + sec_offset,
2184 (size_t) len);
2185 }
2186
2187 *xfered_len = len;
2188 return TARGET_XFER_OK;
2189 }
2190 }
2191
2192 return TARGET_XFER_E_IO;
2193 }
2194 else
2195 error (_("You can't do that without a process to debug."));
2196 }
2197
2198 return this->beneath ()->xfer_partial (object, annex,
2199 readbuf, writebuf, offset, len,
2200 xfered_len);
2201}
2202
2203/* "insert_breakpoint" method for prec over corefile. */
2204
2205int
2207 struct bp_target_info *bp_tgt)
2208{
2209 return 0;
2210}
2211
2212/* "remove_breakpoint" method for prec over corefile. */
2213
2214int
2216 struct bp_target_info *bp_tgt,
2217 enum remove_bp_reason reason)
2218{
2219 return 0;
2220}
2221
2222/* "has_execution" method for prec over corefile. */
2223
2224bool
2226{
2227 return true;
2228}
2229
2230/* Record log save-file format
2231 Version 1 (never released)
2232
2233 Header:
2234 4 bytes: magic number htonl(0x20090829).
2235 NOTE: be sure to change whenever this file format changes!
2236
2237 Records:
2238 record_full_end:
2239 1 byte: record type (record_full_end, see enum record_full_type).
2240 record_full_reg:
2241 1 byte: record type (record_full_reg, see enum record_full_type).
2242 8 bytes: register id (network byte order).
2243 MAX_REGISTER_SIZE bytes: register value.
2244 record_full_mem:
2245 1 byte: record type (record_full_mem, see enum record_full_type).
2246 8 bytes: memory length (network byte order).
2247 8 bytes: memory address (network byte order).
2248 n bytes: memory value (n == memory length).
2249
2250 Version 2
2251 4 bytes: magic number netorder32(0x20091016).
2252 NOTE: be sure to change whenever this file format changes!
2253
2254 Records:
2255 record_full_end:
2256 1 byte: record type (record_full_end, see enum record_full_type).
2257 4 bytes: signal
2258 4 bytes: instruction count
2259 record_full_reg:
2260 1 byte: record type (record_full_reg, see enum record_full_type).
2261 4 bytes: register id (network byte order).
2262 n bytes: register value (n == actual register size).
2263 (eg. 4 bytes for x86 general registers).
2264 record_full_mem:
2265 1 byte: record type (record_full_mem, see enum record_full_type).
2266 4 bytes: memory length (network byte order).
2267 8 bytes: memory address (network byte order).
2268 n bytes: memory value (n == memory length).
2269
2270*/
2271
2272/* bfdcore_read -- read bytes from a core file section. */
2273
2274static inline void
2275bfdcore_read (bfd *obfd, asection *osec, void *buf, int len, int *offset)
2276{
2277 int ret = bfd_get_section_contents (obfd, osec, buf, *offset, len);
2278
2279 if (ret)
2280 *offset += len;
2281 else
2282 error (_("Failed to read %d bytes from core file %s ('%s')."),
2283 len, bfd_get_filename (obfd),
2284 bfd_errmsg (bfd_get_error ()));
2285}
2286
2287static inline uint64_t
2288netorder64 (uint64_t input)
2289{
2290 uint64_t ret;
2291
2292 store_unsigned_integer ((gdb_byte *) &ret, sizeof (ret),
2293 BFD_ENDIAN_BIG, input);
2294 return ret;
2295}
2296
2297static inline uint32_t
2298netorder32 (uint32_t input)
2299{
2300 uint32_t ret;
2301
2302 store_unsigned_integer ((gdb_byte *) &ret, sizeof (ret),
2303 BFD_ENDIAN_BIG, input);
2304 return ret;
2305}
2306
2307/* Restore the execution log from a core_bfd file. */
2308static void
2310{
2311 uint32_t magic;
2312 struct record_full_entry *rec;
2313 asection *osec;
2314 uint32_t osec_size;
2315 int bfd_offset = 0;
2316 struct regcache *regcache;
2317
2318 /* We restore the execution log from the open core bfd,
2319 if there is one. */
2320 if (core_bfd == NULL)
2321 return;
2322
2323 /* "record_full_restore" can only be called when record list is empty. */
2324 gdb_assert (record_full_first.next == NULL);
2325
2326 if (record_debug)
2327 gdb_printf (gdb_stdlog, "Restoring recording from core file.\n");
2328
2329 /* Now need to find our special note section. */
2330 osec = bfd_get_section_by_name (core_bfd, "null0");
2331 if (record_debug)
2332 gdb_printf (gdb_stdlog, "Find precord section %s.\n",
2333 osec ? "succeeded" : "failed");
2334 if (osec == NULL)
2335 return;
2336 osec_size = bfd_section_size (osec);
2337 if (record_debug)
2338 gdb_printf (gdb_stdlog, "%s", bfd_section_name (osec));
2339
2340 /* Check the magic code. */
2341 bfdcore_read (core_bfd, osec, &magic, sizeof (magic), &bfd_offset);
2342 if (magic != RECORD_FULL_FILE_MAGIC)
2343 error (_("Version mis-match or file format error in core file %s."),
2344 bfd_get_filename (core_bfd));
2345 if (record_debug)
2347 " Reading 4-byte magic cookie "
2348 "RECORD_FULL_FILE_MAGIC (0x%s)\n",
2349 phex_nz (netorder32 (magic), 4));
2350
2351 /* Restore the entries in recfd into record_full_arch_list_head and
2352 record_full_arch_list_tail. */
2356
2357 try
2358 {
2360
2361 while (1)
2362 {
2363 uint8_t rectype;
2364 uint32_t regnum, len, signal, count;
2365 uint64_t addr;
2366
2367 /* We are finished when offset reaches osec_size. */
2368 if (bfd_offset >= osec_size)
2369 break;
2370 bfdcore_read (core_bfd, osec, &rectype, sizeof (rectype), &bfd_offset);
2371
2372 switch (rectype)
2373 {
2374 case record_full_reg: /* reg */
2375 /* Get register number to regnum. */
2376 bfdcore_read (core_bfd, osec, &regnum,
2377 sizeof (regnum), &bfd_offset);
2379
2381
2382 /* Get val. */
2384 rec->u.reg.len, &bfd_offset);
2385
2386 if (record_debug)
2388 " Reading register %d (1 "
2389 "plus %lu plus %d bytes)\n",
2390 rec->u.reg.num,
2391 (unsigned long) sizeof (regnum),
2392 rec->u.reg.len);
2393 break;
2394
2395 case record_full_mem: /* mem */
2396 /* Get len. */
2397 bfdcore_read (core_bfd, osec, &len,
2398 sizeof (len), &bfd_offset);
2399 len = netorder32 (len);
2400
2401 /* Get addr. */
2402 bfdcore_read (core_bfd, osec, &addr,
2403 sizeof (addr), &bfd_offset);
2404 addr = netorder64 (addr);
2405
2406 rec = record_full_mem_alloc (addr, len);
2407
2408 /* Get val. */
2410 rec->u.mem.len, &bfd_offset);
2411
2412 if (record_debug)
2414 " Reading memory %s (1 plus "
2415 "%lu plus %lu plus %d bytes)\n",
2417 rec->u.mem.addr),
2418 (unsigned long) sizeof (addr),
2419 (unsigned long) sizeof (len),
2420 rec->u.mem.len);
2421 break;
2422
2423 case record_full_end: /* end */
2424 rec = record_full_end_alloc ();
2426
2427 /* Get signal value. */
2428 bfdcore_read (core_bfd, osec, &signal,
2429 sizeof (signal), &bfd_offset);
2430 signal = netorder32 (signal);
2431 rec->u.end.sigval = (enum gdb_signal) signal;
2432
2433 /* Get insn count. */
2434 bfdcore_read (core_bfd, osec, &count,
2435 sizeof (count), &bfd_offset);
2436 count = netorder32 (count);
2437 rec->u.end.insn_num = count;
2438 record_full_insn_count = count + 1;
2439 if (record_debug)
2441 " Reading record_full_end (1 + "
2442 "%lu + %lu bytes), offset == %s\n",
2443 (unsigned long) sizeof (signal),
2444 (unsigned long) sizeof (count),
2446 bfd_offset));
2447 break;
2448
2449 default:
2450 error (_("Bad entry type in core file %s."),
2451 bfd_get_filename (core_bfd));
2452 break;
2453 }
2454
2455 /* Add rec to record arch list. */
2457 }
2458 }
2459 catch (const gdb_exception &ex)
2460 {
2462 throw;
2463 }
2464
2465 /* Add record_full_arch_list_head to the end of record list. */
2470
2471 /* Update record_full_insn_max_num. */
2473 {
2475 warning (_("Auto increase record/replay buffer limit to %u."),
2477 }
2478
2479 /* Succeeded. */
2480 gdb_printf (_("Restored records from core file %s.\n"),
2481 bfd_get_filename (core_bfd));
2482
2484}
2485
2486/* bfdcore_write -- write bytes into a core file section. */
2487
2488static inline void
2489bfdcore_write (bfd *obfd, asection *osec, void *buf, int len, int *offset)
2490{
2491 int ret = bfd_set_section_contents (obfd, osec, buf, *offset, len);
2492
2493 if (ret)
2494 *offset += len;
2495 else
2496 error (_("Failed to write %d bytes to core file %s ('%s')."),
2497 len, bfd_get_filename (obfd),
2498 bfd_errmsg (bfd_get_error ()));
2499}
2500
2501/* Restore the execution log from a file. We use a modified elf
2502 corefile format, with an extra section for our data. */
2503
2504static void
2505cmd_record_full_restore (const char *args, int from_tty)
2506{
2507 core_file_command (args, from_tty);
2508 record_full_open (args, from_tty);
2509}
2510
2511/* Save the execution log to a file. We use a modified elf corefile
2512 format, with an extra section for our data. */
2513
2514void
2516{
2517 struct record_full_entry *cur_record_full_list;
2518 uint32_t magic;
2519 struct regcache *regcache;
2520 struct gdbarch *gdbarch;
2521 int save_size = 0;
2522 asection *osec = NULL;
2523 int bfd_offset = 0;
2524
2525 /* Open the save file. */
2526 if (record_debug)
2527 gdb_printf (gdb_stdlog, "Saving execution log to core file '%s'\n",
2528 recfilename);
2529
2530 /* Open the output file. */
2531 gdb_bfd_ref_ptr obfd (create_gcore_bfd (recfilename));
2532
2533 /* Arrange to remove the output file on failure. */
2534 gdb::unlinker unlink_file (recfilename);
2535
2536 /* Save the current record entry to "cur_record_full_list". */
2537 cur_record_full_list = record_full_list;
2538
2539 /* Get the values of regcache and gdbarch. */
2541 gdbarch = regcache->arch ();
2542
2543 /* Disable the GDB operation record. */
2544 scoped_restore restore_operation_disable
2546
2547 /* Reverse execute to the begin of record list. */
2548 while (1)
2549 {
2550 /* Check for beginning and end of log. */
2552 break;
2553
2555
2558 }
2559
2560 /* Compute the size needed for the extra bfd section. */
2561 save_size = 4; /* magic cookie */
2564 switch (record_full_list->type)
2565 {
2566 case record_full_end:
2567 save_size += 1 + 4 + 4;
2568 break;
2569 case record_full_reg:
2570 save_size += 1 + 4 + record_full_list->u.reg.len;
2571 break;
2572 case record_full_mem:
2573 save_size += 1 + 4 + 8 + record_full_list->u.mem.len;
2574 break;
2575 }
2576
2577 /* Make the new bfd section. */
2578 osec = bfd_make_section_anyway_with_flags (obfd.get (), "precord",
2579 SEC_HAS_CONTENTS
2580 | SEC_READONLY);
2581 if (osec == NULL)
2582 error (_("Failed to create 'precord' section for corefile %s: %s"),
2583 recfilename,
2584 bfd_errmsg (bfd_get_error ()));
2585 bfd_set_section_size (osec, save_size);
2586 bfd_set_section_vma (osec, 0);
2587 bfd_set_section_alignment (osec, 0);
2588
2589 /* Save corefile state. */
2590 write_gcore_file (obfd.get ());
2591
2592 /* Write out the record log. */
2593 /* Write the magic code. */
2594 magic = RECORD_FULL_FILE_MAGIC;
2595 if (record_debug)
2597 " Writing 4-byte magic cookie "
2598 "RECORD_FULL_FILE_MAGIC (0x%s)\n",
2599 phex_nz (magic, 4));
2600 bfdcore_write (obfd.get (), osec, &magic, sizeof (magic), &bfd_offset);
2601
2602 /* Save the entries to recfd and forward execute to the end of
2603 record list. */
2605 while (1)
2606 {
2607 /* Save entry. */
2609 {
2610 uint8_t type;
2611 uint32_t regnum, len, signal, count;
2612 uint64_t addr;
2613
2615 bfdcore_write (obfd.get (), osec, &type, sizeof (type), &bfd_offset);
2616
2617 switch (record_full_list->type)
2618 {
2619 case record_full_reg: /* reg */
2620 if (record_debug)
2622 " Writing register %d (1 "
2623 "plus %lu plus %d bytes)\n",
2625 (unsigned long) sizeof (regnum),
2627
2628 /* Write regnum. */
2630 bfdcore_write (obfd.get (), osec, &regnum,
2631 sizeof (regnum), &bfd_offset);
2632
2633 /* Write regval. */
2634 bfdcore_write (obfd.get (), osec,
2636 record_full_list->u.reg.len, &bfd_offset);
2637 break;
2638
2639 case record_full_mem: /* mem */
2640 if (record_debug)
2642 " Writing memory %s (1 plus "
2643 "%lu plus %lu plus %d bytes)\n",
2646 (unsigned long) sizeof (addr),
2647 (unsigned long) sizeof (len),
2649
2650 /* Write memlen. */
2652 bfdcore_write (obfd.get (), osec, &len, sizeof (len),
2653 &bfd_offset);
2654
2655 /* Write memaddr. */
2657 bfdcore_write (obfd.get (), osec, &addr,
2658 sizeof (addr), &bfd_offset);
2659
2660 /* Write memval. */
2661 bfdcore_write (obfd.get (), osec,
2663 record_full_list->u.mem.len, &bfd_offset);
2664 break;
2665
2666 case record_full_end:
2667 if (record_debug)
2669 " Writing record_full_end (1 + "
2670 "%lu + %lu bytes)\n",
2671 (unsigned long) sizeof (signal),
2672 (unsigned long) sizeof (count));
2673 /* Write signal value. */
2675 bfdcore_write (obfd.get (), osec, &signal,
2676 sizeof (signal), &bfd_offset);
2677
2678 /* Write insn count. */
2680 bfdcore_write (obfd.get (), osec, &count,
2681 sizeof (count), &bfd_offset);
2682 break;
2683 }
2684 }
2685
2686 /* Execute entry. */
2688
2691 else
2692 break;
2693 }
2694
2695 /* Reverse execute to cur_record_full_list. */
2696 while (1)
2697 {
2698 /* Check for beginning and end of log. */
2699 if (record_full_list == cur_record_full_list)
2700 break;
2701
2703
2706 }
2707
2708 unlink_file.keep ();
2709
2710 /* Succeeded. */
2711 gdb_printf (_("Saved core file %s with execution log.\n"),
2712 recfilename);
2713}
2714
2715/* record_full_goto_insn -- rewind the record log (forward or backward,
2716 depending on DIR) to the given entry, changing the program state
2717 correspondingly. */
2718
2719static void
2721 enum exec_direction_kind dir)
2722{
2723 scoped_restore restore_operation_disable
2726 struct gdbarch *gdbarch = regcache->arch ();
2727
2728 /* Assume everything is valid: we will hit the entry,
2729 and we will not hit the end of the recording. */
2730
2731 if (dir == EXEC_FORWARD)
2733
2734 do
2735 {
2737 if (dir == EXEC_REVERSE)
2739 else
2741 } while (record_full_list != entry);
2742}
2743
2744/* Alias for "target record-full". */
2745
2746static void
2747cmd_record_full_start (const char *args, int from_tty)
2748{
2749 execute_command ("target record-full", from_tty);
2750}
2751
2752static void
2753set_record_full_insn_max_num (const char *args, int from_tty,
2754 struct cmd_list_element *c)
2755{
2757 {
2758 /* Count down record_full_insn_num while releasing records from list. */
2760 {
2763 }
2764 }
2765}
2766
2768void
2770{
2771 struct cmd_list_element *c;
2772
2773 /* Init record_full_first. */
2774 record_full_first.prev = NULL;
2775 record_full_first.next = NULL;
2777
2781
2783 _("Start full execution recording."), &record_full_cmdlist,
2784 0, &record_cmdlist);
2785
2786 cmd_list_element *record_full_restore_cmd
2788 _("Restore the execution log from a file.\n\
2789Argument is filename. File must be created with 'record save'."),
2791 set_cmd_completer (record_full_restore_cmd, filename_completer);
2792
2793 /* Deprecate the old version without "full" prefix. */
2794 c = add_alias_cmd ("restore", record_full_restore_cmd, class_obscure, 1,
2797 deprecate_cmd (c, "record full restore");
2798
2800 _("Set record options."),
2801 _("Show record options."),
2806
2807 /* Record instructions number limit command. */
2808 set_show_commands set_record_full_stop_at_limit_cmds
2809 = add_setshow_boolean_cmd ("stop-at-limit", no_class,
2811Set whether record/replay stops when record/replay buffer becomes full."), _("\
2812Show whether record/replay stops when record/replay buffer becomes full."),
2813 _("Default is ON.\n\
2814When ON, if the record/replay buffer becomes full, ask user what to do.\n\
2815When OFF, if the record/replay buffer becomes full,\n\
2816delete the oldest recorded instruction to make room for each new one."),
2817 NULL, NULL,
2820
2821 c = add_alias_cmd ("stop-at-limit",
2822 set_record_full_stop_at_limit_cmds.set, no_class, 1,
2824 deprecate_cmd (c, "set record full stop-at-limit");
2825
2826 c = add_alias_cmd ("stop-at-limit",
2827 set_record_full_stop_at_limit_cmds.show, no_class, 1,
2829 deprecate_cmd (c, "show record full stop-at-limit");
2830
2831 set_show_commands record_full_insn_number_max_cmds
2832 = add_setshow_uinteger_cmd ("insn-number-max", no_class,
2834 _("Set record/replay buffer limit."),
2835 _("Show record/replay buffer limit."), _("\
2836Set the maximum number of instructions to be stored in the\n\
2837record/replay buffer. A value of either \"unlimited\" or zero means no\n\
2838limit. Default is 200000."),
2842
2843 c = add_alias_cmd ("insn-number-max", record_full_insn_number_max_cmds.set,
2845 deprecate_cmd (c, "set record full insn-number-max");
2846
2847 c = add_alias_cmd ("insn-number-max", record_full_insn_number_max_cmds.show,
2849 deprecate_cmd (c, "show record full insn-number-max");
2850
2851 set_show_commands record_full_memory_query_cmds
2852 = add_setshow_boolean_cmd ("memory-query", no_class,
2854Set whether query if PREC cannot record memory change of next instruction."),
2855 _("\
2856Show whether query if PREC cannot record memory change of next instruction."),
2857 _("\
2858Default is OFF.\n\
2859When ON, query if PREC cannot record memory change of next instruction."),
2860 NULL, NULL,
2863
2864 c = add_alias_cmd ("memory-query", record_full_memory_query_cmds.set,
2866 deprecate_cmd (c, "set record full memory-query");
2867
2868 c = add_alias_cmd ("memory-query", record_full_memory_query_cmds.show,
2870 deprecate_cmd (c, "show record full memory-query");
2871}
int regnum
Definition: aarch64-tdep.c:68
const char *const name
Definition: aarch64-tdep.c:67
void * xmalloc(YYSIZE_T)
void xfree(void *)
struct gdbarch * get_current_arch(void)
Definition: arch-utils.c:846
struct gdbarch * target_gdbarch(void)
Definition: arch-utils.c:1453
void mark_async_event_handler(async_event_handler *async_handler_ptr)
Definition: async-event.c:294
async_event_handler * create_async_event_handler(async_event_handler_func *proc, gdb_client_data client_data, const char *name)
Definition: async-event.c:269
void clear_async_event_handler(async_event_handler *async_handler_ptr)
Definition: async-event.c:306
void delete_async_event_handler(async_event_handler **async_handler_ptr)
Definition: async-event.c:348
const std::vector< bp_location * > & all_bp_locations()
Definition: breakpoint.c:657
int hardware_watchpoint_inserted_in_range(const address_space *aspace, CORE_ADDR addr, ULONGEST len)
Definition: breakpoint.c:4345
int insert_single_step_breakpoints(struct gdbarch *gdbarch)
Definition: breakpoint.c:13642
remove_bp_reason
Definition: breakpoint.h:64
@ REMOVE_BREAKPOINT
Definition: breakpoint.h:67
@ bp_loc_software_breakpoint
Definition: breakpoint.h:316
int unpush_target(struct target_ops *t)
Definition: inferior.c:98
void push_target(struct target_ops *t)
Definition: inferior.h:376
struct process_stratum_target * process_target()
Definition: inferior.h:419
enum register_status raw_read(int regnum, gdb_byte *buf)
Definition: regcache.c:605
enum register_status cooked_read(int regnum, gdb_byte *buf)
Definition: regcache.c:692
void info_record() override
Definition: record-full.c:1894
bool can_execute_reverse() override
Definition: record-full.c:1826
void goto_bookmark(const gdb_byte *, int) override
Definition: record-full.c:1857
ptid_t wait(ptid_t, struct target_waitstatus *, target_wait_flags) override
Definition: record-full.c:1452
enum record_method record_method(ptid_t ptid) override
Definition: record-full.c:1888
void goto_record_begin() override
Definition: record-full.c:2002
void goto_record_end() override
Definition: record-full.c:2016
bool supports_stopped_by_hw_breakpoint() override
Definition: record-full.c:1517
bool supports_delete_record() override
Definition: record-full.c:1938
bool stopped_by_sw_breakpoint() override
Definition: record-full.c:1491
void goto_record(ULONGEST insn) override
Definition: record-full.c:2032
gdb_byte * get_bookmark(const char *, int) override
Definition: record-full.c:1834
enum exec_direction_kind execution_direction() override
Definition: record-full.c:1880
bool supports_stopped_by_sw_breakpoint() override
Definition: record-full.c:1500
void close() override
Definition: record-full.c:989
bool stopped_by_watchpoint() override
Definition: record-full.c:1471
void delete_record() override
Definition: record-full.c:1946
strata stratum() const override
Definition: record-full.c:223
bool stopped_data_address(CORE_ADDR *) override
Definition: record-full.c:1480
void save_record(const char *filename) override
Definition: record-full.c:2515
void async(bool) override
Definition: record-full.c:1020
bool record_will_replay(ptid_t ptid, int dir) override
Definition: record-full.c:1962
bool stopped_by_hw_breakpoint() override
Definition: record-full.c:1508
void record_stop_replaying() override
Definition: record-full.c:2046
bool record_is_replaying(ptid_t ptid) override
Definition: record-full.c:1954
const target_info & info() const override=0
enum target_xfer_status xfer_partial(enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len) override
Definition: record-full.c:2113
void resume(ptid_t, int, enum gdb_signal) override
Definition: record-full.c:2054
void store_registers(struct regcache *, int) override
Definition: record-full.c:2101
void fetch_registers(struct regcache *regcache, int regno) override
Definition: record-full.c:2076
void prepare_to_store(struct regcache *regcache) override
Definition: record-full.c:2094
int remove_breakpoint(struct gdbarch *, struct bp_target_info *, enum remove_bp_reason) override
Definition: record-full.c:2215
void kill() override
Definition: record-full.c:2065
const target_info & info() const override
Definition: record-full.c:300
int insert_breakpoint(struct gdbarch *, struct bp_target_info *) override
Definition: record-full.c:2206
bool has_execution(inferior *inf) override
Definition: record-full.c:2225
void disconnect(const char *, int) override
Definition: record-full.c:340
void disconnect(const char *, int) override
Definition: record-full.c:334
void mourn_inferior() override
Definition: record-full.c:346
int remove_breakpoint(struct gdbarch *, struct bp_target_info *, enum remove_bp_reason) override
Definition: record-full.c:1790
void kill() override
Definition: record-full.c:352
void store_registers(struct regcache *, int) override
Definition: record-full.c:1572
void detach(inferior *, int) override
Definition: record-full.c:328
int insert_breakpoint(struct gdbarch *, struct bp_target_info *) override
Definition: record-full.c:1745
enum target_xfer_status xfer_partial(enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len) override
Definition: record-full.c:1629
void resume(ptid_t, int, enum gdb_signal) override
Definition: record-full.c:1059
const target_info & info() const override
Definition: record-full.c:267
gdbarch * arch() const
Definition: regcache.c:230
void invalidate(int regnum)
Definition: regcache.c:311
void raw_supply(int regnum, const void *buf) override
Definition: regcache.c:1053
void cooked_write(int regnum, const gdb_byte *buf)
Definition: regcache.c:861
const address_space * aspace() const
Definition: regcache.h:342
static void ours()
Definition: target.c:1065
void set_stop_pc(CORE_ADDR stop_pc)
Definition: gdbthread.h:369
set_show_commands add_setshow_uinteger_cmd(const char *name, enum command_class theclass, unsigned int *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
Definition: cli-decode.c:1053
struct cmd_list_element * add_alias_cmd(const char *name, cmd_list_element *target, enum command_class theclass, int abbrev_flag, struct cmd_list_element **list)
Definition: cli-decode.c:294
struct cmd_list_element * add_cmd(const char *name, enum command_class theclass, const char *doc, struct cmd_list_element **list)
Definition: cli-decode.c:233
void set_cmd_completer(struct cmd_list_element *cmd, completer_ftype *completer)
Definition: cli-decode.c:117
struct cmd_list_element * deprecate_cmd(struct cmd_list_element *cmd, const char *replacement)
Definition: cli-decode.c:280
set_show_commands add_setshow_prefix_cmd(const char *name, command_class theclass, const char *set_doc, const char *show_doc, cmd_list_element **set_subcommands_list, cmd_list_element **show_subcommands_list, cmd_list_element **set_list, cmd_list_element **show_list)
Definition: cli-decode.c:428
struct cmd_list_element * add_prefix_cmd(const char *name, enum command_class theclass, cmd_simple_func_ftype *fun, const char *doc, struct cmd_list_element **subcommands, int allow_unknown, struct cmd_list_element **list)
Definition: cli-decode.c:357
set_show_commands add_setshow_boolean_cmd(const char *name, enum command_class theclass, bool *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
Definition: cli-decode.c:739
@ class_obscure
Definition: command.h:64
@ class_support
Definition: command.h:58
@ no_class
Definition: command.h:53
void filename_completer(struct cmd_list_element *ignore, completion_tracker &tracker, const char *text, const char *word)
Definition: completer.c:204
void core_file_command(const char *filename, int from_tty)
Definition: corelow.c:406
static void store_unsigned_integer(gdb_byte *addr, int len, enum bfd_endian byte_order, ULONGEST val)
Definition: defs.h:561
void handle_sigint(int sig)
Definition: event-top.c:1152
void exception_print(struct ui_file *file, const struct gdb_exception &e)
Definition: exceptions.c:105
target_section_table build_section_table(struct bfd *some_bfd)
Definition: exec.c:563
void reinit_frame_cache(void)
Definition: frame.c:2006
frame_info_ptr get_selected_frame(const char *message)
Definition: frame.c:1813
@ SRC_AND_LOC
Definition: frame.h:594
void print_stack_frame(frame_info_ptr, int print_level, enum print_what print_what, int set_current_sal)
Definition: stack.c:356
gdb_bfd_ref_ptr create_gcore_bfd(const char *filename)
Definition: gcore.c:55
void write_gcore_file(bfd *obfd)
Definition: gcore.c:115
gdb::ref_ptr< struct bfd, gdb_bfd_ref_policy > gdb_bfd_ref_ptr
Definition: gdb_bfd.h:78
const char * gdbarch_register_name(struct gdbarch *gdbarch, int regnr)
Definition: gdbarch.c:2142
int gdbarch_process_record_signal(struct gdbarch *gdbarch, struct regcache *regcache, enum gdb_signal signal)
Definition: gdbarch.c:4279
int gdbarch_num_regs(struct gdbarch *gdbarch)
Definition: gdbarch.c:1899
bfd * obfd
Definition: gdbarch-gen.h:894
int gdbarch_process_record(struct gdbarch *gdbarch, struct regcache *regcache, CORE_ADDR addr)
Definition: gdbarch.c:4255
bool gdbarch_process_record_signal_p(struct gdbarch *gdbarch)
Definition: gdbarch.c:4272
bool gdbarch_software_single_step_p(struct gdbarch *gdbarch)
Definition: gdbarch.c:3223
bool gdbarch_process_record_p(struct gdbarch *gdbarch)
Definition: gdbarch.c:4248
void execute_command(const char *, int)
Definition: top.c:574
#define core_bfd
Definition: gdbcore.h:130
all_non_exited_threads_range all_non_exited_threads(process_stratum_target *proc_target=nullptr, ptid_t filter_ptid=minus_one_ptid)
Definition: gdbthread.h:743
void set_executing(process_stratum_target *targ, ptid_t ptid, bool executing)
Definition: thread.c:880
struct thread_info * inferior_thread(void)
Definition: thread.c:83
void switch_to_thread(struct thread_info *thr)
Definition: thread.c:1335
int thread_has_single_step_breakpoints_set(struct thread_info *tp)
Definition: thread.c:140
void delete_single_step_breakpoints(struct thread_info *tp)
Definition: thread.c:118
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t int status
Definition: gnu-nat.c:1791
void inferior_event_handler(enum inferior_event_type event_type)
Definition: inf-loop.c:36
ptid_t inferior_ptid
Definition: infcmd.c:91
struct inferior * current_inferior(void)
Definition: inferior.c:54
enum exec_direction_kind execution_direction
Definition: infrun.c:9451
bool non_stop
Definition: infrun.c:203
exec_direction_kind
Definition: infrun.h:112
@ EXEC_REVERSE
Definition: infrun.h:114
@ EXEC_FORWARD
Definition: infrun.h:113
observable< struct inferior *, int, const char *, const char * > record_changed
static void record_full_restore(void)
Definition: record-full.c:2309
static struct record_full_entry * record_full_end_alloc(void)
Definition: record-full.c:443
static unsigned int record_full_insn_num
Definition: record-full.c:205
#define DEFAULT_RECORD_FULL_INSN_MAX_NUM
Definition: record-full.c:65
static void record_full_end_release(struct record_full_entry *rec)
Definition: record-full.c:456
static enum exec_direction_kind record_full_execution_dir
Definition: record-full.c:1054
record_full_type
Definition: record-full.c:115
@ record_full_end
Definition: record-full.c:116
@ record_full_reg
Definition: record-full.c:117
@ record_full_mem
Definition: record-full.c:118
static struct record_full_entry * record_full_list
Definition: record-full.c:195
static void record_full_registers_change(struct regcache *regcache, int regnum)
Definition: record-full.c:1525
static void record_full_goto_entry(struct record_full_entry *p)
Definition: record-full.c:1974
static const char record_doc[]
Definition: record-full.c:213
static struct record_full_entry * record_full_arch_list_tail
Definition: record-full.c:197
static ptid_t record_full_resume_ptid
Definition: record-full.c:1032
static void record_full_sig_handler(int signo)
Definition: record-full.c:1105
static void cmd_record_full_start(const char *args, int from_tty)
Definition: record-full.c:2747
static void record_full_goto_insn(struct record_full_entry *entry, enum exec_direction_kind dir)
Definition: record-full.c:2720
static unsigned int record_full_insn_max_num
Definition: record-full.c:203
#define RECORD_FULL_IS_REPLAY
Definition: record-full.c:67
static int record_full_resume_step
Definition: record-full.c:1033
static struct cmd_list_element * set_record_full_cmdlist
Definition: record-full.c:371
static enum target_stop_reason record_full_stop_reason
Definition: record-full.c:809
static void record_full_exec_insn(struct regcache *regcache, struct gdbarch *gdbarch, struct record_full_entry *entry)
Definition: record-full.c:816
bool record_full_memory_query
Definition: record-full.c:163
static struct cmd_list_element * show_record_full_cmdlist
Definition: record-full.c:372
static void record_full_check_insn_num(void)
Definition: record-full.c:682
static const target_info record_full_target_info
Definition: record-full.c:258
static void record_full_message(struct regcache *regcache, enum gdb_signal signal)
Definition: record-full.c:705
static struct cmd_list_element * record_full_cmdlist
Definition: record-full.c:375
static void record_full_list_release_following(struct record_full_entry *rec)
Definition: record-full.c:512
int record_full_arch_list_add_reg(struct regcache *regcache, int regnum)
Definition: record-full.c:610
static uint64_t netorder64(uint64_t input)
Definition: record-full.c:2288
static struct async_event_handler * record_full_async_inferior_event_token
Definition: record-full.c:901
static record_full_core_target record_full_core_ops
Definition: record-full.c:325
#define RECORD_FULL_FILE_MAGIC
Definition: record-full.c:70
static void set_record_full_insn_max_num(const char *args, int from_tty, struct cmd_list_element *c)
Definition: record-full.c:2753
static struct record_full_entry record_full_first
Definition: record-full.c:194
int record_full_arch_list_add_mem(CORE_ADDR addr, int len)
Definition: record-full.c:633
static struct record_full_entry * record_full_arch_list_head
Definition: record-full.c:196
int record_full_arch_list_add_end(void)
Definition: record-full.c:664
static struct record_full_entry * record_full_mem_alloc(CORE_ADDR addr, int len)
Definition: record-full.c:415
static uint32_t netorder32(uint32_t input)
Definition: record-full.c:2298
static void bfdcore_write(bfd *obfd, asection *osec, void *buf, int len, int *offset)
Definition: record-full.c:2489
static void record_full_list_release(struct record_full_entry *rec)
Definition: record-full.c:486
static void record_full_mem_release(struct record_full_entry *rec)
Definition: record-full.c:432
static record_full_target record_full_ops
Definition: record-full.c:324
static int record_full_gdb_operation_disable
Definition: record-full.c:799
static void record_full_arch_list_add(struct record_full_entry *rec)
Definition: record-full.c:565
static void record_full_list_release_first(void)
Definition: record-full.c:535
static void record_full_open_1(const char *name, int from_tty)
Definition: record-full.c:934
void _initialize_record_full()
Definition: record-full.c:2769
static bool record_full_message_wrapper_safe(struct regcache *regcache, enum gdb_signal signal)
Definition: record-full.c:780
static int record_full_get_sig
Definition: record-full.c:1100
static bool record_full_stop_at_limit
Definition: record-full.c:200
int record_full_is_used(void)
Definition: record-full.c:360
static ULONGEST record_full_insn_count
Definition: record-full.c:208
static void record_full_reg_release(struct record_full_entry *rec)
Definition: record-full.c:404
static detached_regcache * record_full_core_regbuf
Definition: record-full.c:173
static ptid_t record_full_wait_1(struct target_ops *ops, ptid_t ptid, struct target_waitstatus *status, target_wait_flags options)
Definition: record-full.c:1132
static void record_full_core_open_1(const char *name, int from_tty)
Definition: record-full.c:912
static struct record_full_core_buf_entry * record_full_core_buf_list
Definition: record-full.c:175
static struct record_full_entry * record_full_reg_alloc(struct regcache *regcache, int regnum)
Definition: record-full.c:386
static target_section_table record_full_core_sections
Definition: record-full.c:174
static std::vector< record_full_breakpoint > record_full_breakpoints
Definition: record-full.c:1719
static void record_full_init_record_breakpoints(void)
Definition: record-full.c:1724
static gdb_byte * record_full_get_loc(struct record_full_entry *rec)
Definition: record-full.c:587
static enum record_full_type record_full_entry_release(struct record_full_entry *rec)
Definition: record-full.c:465
static void bfdcore_read(bfd *obfd, asection *osec, void *buf, int len, int *offset)
Definition: record-full.c:2275
static void cmd_record_full_restore(const char *args, int from_tty)
Definition: record-full.c:2505
static const target_info record_full_core_target_info
Definition: record-full.c:291
static const char record_longname[]
Definition: record-full.c:211
static void record_full_open(const char *name, int from_tty)
Definition: record-full.c:958
static int record_full_resumed
Definition: record-full.c:1038
static void record_full_async_inferior_event_handler(gdb_client_data data)
Definition: record-full.c:904
scoped_restore_tmpl< int > record_full_gdb_operation_disable_set(void)
Definition: record-full.c:802
void record_detach(struct target_ops *t, inferior *inf, int from_tty)
Definition: record.c:190
unsigned int record_debug
Definition: record.c:33
struct cmd_list_element * set_record_cmdlist
Definition: record.c:52
void record_goto(const char *arg)
Definition: record.c:362
int record_read_memory(struct gdbarch *gdbarch, CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
Definition: record.c:139
struct cmd_list_element * show_record_cmdlist
Definition: record.c:53
void record_disconnect(struct target_ops *t, const char *args, int from_tty)
Definition: record.c:175
struct cmd_list_element * record_cmdlist
Definition: record.c:50
struct target_ops * find_record_target(void)
Definition: record.c:63
void record_preopen(void)
Definition: record.c:86
void record_mourn_inferior(struct target_ops *t)
Definition: record.c:205
void record_kill(struct target_ops *t)
Definition: record.c:221
int record_check_stopped_by_breakpoint(const address_space *aspace, CORE_ADDR pc, enum target_stop_reason *reason)
Definition: record.c:237
record_method
Definition: record.h:44
@ RECORD_METHOD_FULL
Definition: record.h:49
CORE_ADDR regcache_read_pc(struct regcache *regcache)
Definition: regcache.c:1324
int register_size(struct gdbarch *gdbarch, int regnum)
Definition: regcache.c:170
struct regcache * get_current_regcache(void)
Definition: regcache.c:426
void registers_changed(void)
Definition: regcache.c:577
#define enable()
Definition: ser-go32.c:239
CORE_ADDR placed_address
Definition: breakpoint.h:266
struct address_space * placed_address_space
Definition: breakpoint.h:259
Definition: gnu-nat.c:154
struct address_space * address_space
Definition: record-full.c:1708
record_full_breakpoint(struct address_space *address_space_, CORE_ADDR addr_, bool in_target_beneath_)
Definition: record-full.c:1698
Definition: record-full.c:166
struct target_section * p
Definition: record-full.c:168
bfd_byte * buf
Definition: record-full.c:169
struct record_full_core_buf_entry * prev
Definition: record-full.c:167
Definition: record-full.c:109
ULONGEST insn_num
Definition: record-full.c:111
enum gdb_signal sigval
Definition: record-full.c:110
Definition: record-full.c:146
struct record_full_mem_entry mem
Definition: record-full.c:155
struct record_full_end_entry end
Definition: record-full.c:157
enum record_full_type type
Definition: record-full.c:149
struct record_full_entry * next
Definition: record-full.c:148
union record_full_entry::@154 u
struct record_full_entry * prev
Definition: record-full.c:147
struct record_full_reg_entry reg
Definition: record-full.c:153
Definition: record-full.c:84
CORE_ADDR addr
Definition: record-full.c:85
gdb_byte * ptr
Definition: record-full.c:92
int len
Definition: record-full.c:86
gdb_byte buf[sizeof(gdb_byte *)]
Definition: record-full.c:93
int mem_entry_not_accessible
Definition: record-full.c:89
union record_full_mem_entry::@152 u
Definition: record-full.c:98
gdb_byte buf[2 *sizeof(gdb_byte *)]
Definition: record-full.c:104
union record_full_reg_entry::@153 u
unsigned short num
Definition: record-full.c:99
gdb_byte * ptr
Definition: record-full.c:103
unsigned short len
Definition: record-full.c:100
cmd_list_element * set
Definition: command.h:406
cmd_list_element * show
Definition: command.h:406
virtual ptid_t wait(ptid_t, struct target_waitstatus *, target_wait_flags options) TARGET_DEFAULT_FUNC(default_target_wait)
virtual int remove_breakpoint(struct gdbarch *, struct bp_target_info *, enum remove_bp_reason) TARGET_DEFAULT_NORETURN(noprocess())
virtual bool stopped_by_watchpoint() TARGET_DEFAULT_RETURN(false)
target_ops * beneath() const
Definition: target.c:3020
virtual bool stopped_data_address(CORE_ADDR *) TARGET_DEFAULT_RETURN(false)
virtual void commit_resumed() TARGET_DEFAULT_IGNORE()
virtual void store_registers(struct regcache *, int) TARGET_DEFAULT_NORETURN(noprocess())
virtual enum target_xfer_status xfer_partial(enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len) TARGET_DEFAULT_RETURN(TARGET_XFER_E_IO)
virtual void async(bool) TARGET_DEFAULT_NORETURN(tcomplain())
virtual void resume(ptid_t, int TARGET_DEBUG_PRINTER(target_debug_print_step), enum gdb_signal) TARGET_DEFAULT_NORETURN(noprocess())
virtual int insert_breakpoint(struct gdbarch *, struct bp_target_info *) TARGET_DEFAULT_NORETURN(noprocess())
Definition: gdbtypes.h:922
std::vector< target_section > target_section_table
void target_fetch_registers(struct regcache *regcache, int regno)
Definition: target.c:3921
void target_pass_signals(gdb::array_view< const unsigned char > pass_signals)
Definition: target.c:2677
gdbarch * target_thread_architecture(ptid_t ptid)
Definition: target.c:435
void add_deprecated_target_alias(const target_info &tinfo, const char *alias)
Definition: target.c:891
int target_write_memory(CORE_ADDR memaddr, const gdb_byte *myaddr, ssize_t len)
Definition: target.c:1847
bool target_has_execution(inferior *inf)
Definition: target.c:202
void add_target(const target_info &t, target_open_ftype *func, completer_ftype *completer)
Definition: target.c:863
bool target_stopped_by_watchpoint()
Definition: target.c:471
@ INF_REG_EVENT
Definition: target.h:129
target_xfer_status
Definition: target.h:214
@ TARGET_XFER_E_IO
Definition: target.h:227
@ TARGET_XFER_EOF
Definition: target.h:219
@ TARGET_XFER_OK
Definition: target.h:216
target_object
Definition: target.h:138
@ TARGET_OBJECT_RAW_MEMORY
Definition: target.h:146
@ TARGET_OBJECT_MEMORY
Definition: target.h:142
strata
Definition: target.h:89
@ record_stratum
Definition: target.h:94
int query(const char *ctlstr,...)
Definition: utils.c:1010
const char * paddress(struct gdbarch *gdbarch, CORE_ADDR addr)
Definition: utils.c:3114
int yquery(const char *ctlstr,...)
Definition: utils.c:993
void gdb_printf(struct ui_file *stream, const char *format,...)
Definition: utils.c:1865
#define gdb_stderr
Definition: utils.h:193
#define gdb_stdlog
Definition: utils.h:196
@ TARGET_WNOHANG
Definition: wait.h:32
@ TARGET_WAITKIND_STOPPED
Definition: waitstatus.h:36
@ TARGET_WAITKIND_IGNORE
Definition: waitstatus.h:89
target_stop_reason
Definition: waitstatus.h:428
@ TARGET_STOPPED_BY_SW_BREAKPOINT
Definition: waitstatus.h:434
@ TARGET_STOPPED_BY_WATCHPOINT
Definition: waitstatus.h:440
@ TARGET_STOPPED_BY_HW_BREAKPOINT
Definition: waitstatus.h:437
@ TARGET_STOPPED_BY_NO_REASON
Definition: waitstatus.h:431