1 /* Process record and replay target for GDB, the GNU debugger.
3 Copyright (C) 2008-2013 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/>. */
22 #include "completer.h"
26 #include "common/common-utils.h"
28 /* This is the debug switch for process record. */
29 unsigned int record_debug
= 0;
31 struct cmd_list_element
*record_cmdlist
= NULL
;
32 struct cmd_list_element
*set_record_cmdlist
= NULL
;
33 struct cmd_list_element
*show_record_cmdlist
= NULL
;
34 struct cmd_list_element
*info_record_cmdlist
= NULL
;
36 /* Find the record target in the target stack. */
38 static struct target_ops
*
39 find_record_target (void)
43 for (t
= current_target
.beneath
; t
!= NULL
; t
= t
->beneath
)
44 if (t
->to_stratum
== record_stratum
)
50 /* Check that recording is active. Throw an error, if it isn't. */
52 static struct target_ops
*
53 require_record_target (void)
57 t
= find_record_target ();
59 error (_("No record target is currently active.\n"
60 "Use one of the \"target record-<tab><tab>\" commands first."));
68 record_read_memory (struct gdbarch
*gdbarch
,
69 CORE_ADDR memaddr
, gdb_byte
*myaddr
,
72 int ret
= target_read_memory (memaddr
, myaddr
, len
);
74 if (ret
&& record_debug
)
75 printf_unfiltered (_("Process record: error reading memory "
76 "at addr %s len = %ld.\n"),
77 paddress (gdbarch
, memaddr
), (long) len
);
81 /* Implement "show record debug" command. */
84 show_record_debug (struct ui_file
*file
, int from_tty
,
85 struct cmd_list_element
*c
, const char *value
)
87 fprintf_filtered (file
, _("Debugging of process record target is %s.\n"),
91 /* Alias for "target record". */
94 cmd_record_start (char *args
, int from_tty
)
96 execute_command ("target record-full", from_tty
);
99 /* Truncate the record log from the present point
100 of replay until the end. */
103 cmd_record_delete (char *args
, int from_tty
)
105 require_record_target ();
107 if (!target_record_is_replaying ())
109 printf_unfiltered (_("Already at end of record list.\n"));
113 if (!target_supports_delete_record ())
115 printf_unfiltered (_("The current record target does not support "
116 "this operation.\n"));
120 if (!from_tty
|| query (_("Delete the log from this point forward "
121 "and begin to record the running message "
123 target_delete_record ();
126 /* Implement the "stoprecord" or "record stop" command. */
129 cmd_record_stop (char *args
, int from_tty
)
131 struct target_ops
*t
;
133 t
= require_record_target ();
136 printf_unfiltered (_("Process record is stopped and all execution "
137 "logs are deleted.\n"));
139 observer_notify_record_changed (current_inferior (), 0);
142 /* The "set record" command. */
145 set_record_command (char *args
, int from_tty
)
147 printf_unfiltered (_("\"set record\" must be followed "
148 "by an apporpriate subcommand.\n"));
149 help_list (set_record_cmdlist
, "set record ", all_commands
, gdb_stdout
);
152 /* The "show record" command. */
155 show_record_command (char *args
, int from_tty
)
157 cmd_show_list (show_record_cmdlist
, from_tty
, "");
160 /* The "info record" command. */
163 info_record_command (char *args
, int from_tty
)
165 struct target_ops
*t
;
167 t
= find_record_target ();
170 printf_filtered (_("No record target is currently active.\n"));
174 printf_filtered (_("Active record target: %s\n"), t
->to_shortname
);
175 if (t
->to_info_record
!= NULL
)
176 t
->to_info_record ();
179 /* The "record save" command. */
182 cmd_record_save (char *args
, int from_tty
)
184 char *recfilename
, recfilename_buffer
[40];
186 require_record_target ();
188 if (args
!= NULL
&& *args
!= 0)
192 /* Default recfile name is "gdb_record.PID". */
193 xsnprintf (recfilename_buffer
, sizeof (recfilename_buffer
),
194 "gdb_record.%d", PIDGET (inferior_ptid
));
195 recfilename
= recfilename_buffer
;
198 target_save_record (recfilename
);
201 /* "record goto" command. Argument is an instruction number,
202 as given by "info record".
204 Rewinds the recording (forward or backward) to the given instruction. */
207 cmd_record_goto (char *arg
, int from_tty
)
209 require_record_target ();
211 if (arg
== NULL
|| *arg
== '\0')
212 error (_("Command requires an argument (insn number to go to)."));
214 if (strncmp (arg
, "start", strlen ("start")) == 0
215 || strncmp (arg
, "begin", strlen ("begin")) == 0)
216 target_goto_record_begin ();
217 else if (strncmp (arg
, "end", strlen ("end")) == 0)
218 target_goto_record_end ();
223 insn
= parse_and_eval_long (arg
);
224 target_goto_record (insn
);
228 /* Provide a prototype to silence -Wmissing-prototypes. */
229 extern initialize_file_ftype _initialize_record
;
232 _initialize_record (void)
234 struct cmd_list_element
*c
;
236 add_setshow_zuinteger_cmd ("record", no_class
, &record_debug
,
237 _("Set debugging of record/replay feature."),
238 _("Show debugging of record/replay feature."),
239 _("When enabled, debugging output for "
240 "record/replay feature is displayed."),
241 NULL
, show_record_debug
, &setdebuglist
,
244 c
= add_prefix_cmd ("record", class_obscure
, cmd_record_start
,
245 _("Start recording."),
246 &record_cmdlist
, "record ", 0, &cmdlist
);
247 set_cmd_completer (c
, filename_completer
);
249 add_com_alias ("rec", "record", class_obscure
, 1);
250 add_prefix_cmd ("record", class_support
, set_record_command
,
251 _("Set record options"), &set_record_cmdlist
,
252 "set record ", 0, &setlist
);
253 add_alias_cmd ("rec", "record", class_obscure
, 1, &setlist
);
254 add_prefix_cmd ("record", class_support
, show_record_command
,
255 _("Show record options"), &show_record_cmdlist
,
256 "show record ", 0, &showlist
);
257 add_alias_cmd ("rec", "record", class_obscure
, 1, &showlist
);
258 add_prefix_cmd ("record", class_support
, info_record_command
,
259 _("Info record options"), &info_record_cmdlist
,
260 "info record ", 0, &infolist
);
261 add_alias_cmd ("rec", "record", class_obscure
, 1, &infolist
);
263 c
= add_cmd ("save", class_obscure
, cmd_record_save
,
264 _("Save the execution log to a file.\n\
265 Argument is optional filename.\n\
266 Default filename is 'gdb_record.<process_id>'."),
268 set_cmd_completer (c
, filename_completer
);
270 add_cmd ("delete", class_obscure
, cmd_record_delete
,
271 _("Delete the rest of execution log and start recording it anew."),
273 add_alias_cmd ("d", "delete", class_obscure
, 1, &record_cmdlist
);
274 add_alias_cmd ("del", "delete", class_obscure
, 1, &record_cmdlist
);
276 add_cmd ("stop", class_obscure
, cmd_record_stop
,
277 _("Stop the record/replay target."),
279 add_alias_cmd ("s", "stop", class_obscure
, 1, &record_cmdlist
);
281 add_cmd ("goto", class_obscure
, cmd_record_goto
, _("\
282 Restore the program to its state at instruction number N.\n\
283 Argument is instruction number, as shown by 'info record'."),