1 /* Process record and replay target for GDB, the GNU debugger.
2 
3    Copyright (C) 2008-2024 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 "cli/cli-cmds.h"
21 #include "completer.h"
22 #include "record.h"
23 #include "observable.h"
24 #include "inferior.h"
25 #include "gdbsupport/common-utils.h"
26 #include "cli/cli-utils.h"
27 #include "disasm.h"
28 #include "interps.h"
29 #include "top.h"
30 
31 #include <ctype.h>
32 
33 /* This is the debug switch for process record.  */
34 unsigned int record_debug = 0;
35 
36 /* The number of instructions to print in "record instruction-history".  */
37 static unsigned int record_insn_history_size = 10;
38 
39 /* The variable registered as control variable in the "record
40    instruction-history" command.  Necessary for extra input
41    validation.  */
42 static unsigned int record_insn_history_size_setshow_var;
43 
44 /* The number of functions to print in "record function-call-history".  */
45 static unsigned int record_call_history_size = 10;
46 
47 /* The variable registered as control variable in the "record
48    call-history" command.  Necessary for extra input validation.  */
49 static unsigned int record_call_history_size_setshow_var;
50 
51 struct cmd_list_element *record_cmdlist = NULL;
52 static struct cmd_list_element *record_goto_cmdlist = NULL;
53 struct cmd_list_element *set_record_cmdlist = NULL;
54 struct cmd_list_element *show_record_cmdlist = NULL;
55 struct cmd_list_element *info_record_cmdlist = NULL;
56 
57 #define DEBUG(msg, args...)                                                     \
58   if (record_debug)                                                             \
59     gdb_printf (gdb_stdlog, "record: " msg "\n", ##args)
60 
61 /* See record.h.  */
62 
63 struct target_ops *
find_record_target(void)64 find_record_target (void)
65 {
66   return find_target_at (record_stratum);
67 }
68 
69 /* Check that recording is active.  Throw an error, if it isn't.  */
70 
71 static struct target_ops *
require_record_target(void)72 require_record_target (void)
73 {
74   struct target_ops *t;
75 
76   t = find_record_target ();
77   if (t == NULL)
78     error (_("No recording is currently active.\n"
79                "Use the \"record full\" or \"record btrace\" command first."));
80 
81   return t;
82 }
83 
84 /* See record.h.  */
85 
86 void
record_preopen(void)87 record_preopen (void)
88 {
89   /* Check if a record target is already running.  */
90   if (find_record_target () != NULL)
91     error (_("The process is already being recorded.  Use \"record stop\" to "
92                "stop recording first."));
93 }
94 
95 /* See record.h.  */
96 
97 void
record_start(const char * method,const char * format,int from_tty)98 record_start (const char *method, const char *format, int from_tty)
99 {
100   if (method == NULL)
101     {
102       if (format == NULL)
103           execute_command_to_string ("record", from_tty, false);
104       else
105           error (_("Invalid format."));
106     }
107   else if (strcmp (method, "full") == 0)
108     {
109       if (format == NULL)
110           execute_command_to_string ("record full", from_tty, false);
111       else
112           error (_("Invalid format."));
113     }
114   else if (strcmp (method, "btrace") == 0)
115     {
116       if (format == NULL)
117           execute_command_to_string ("record btrace", from_tty, false);
118       else if (strcmp (format, "bts") == 0)
119           execute_command_to_string ("record btrace bts", from_tty, false);
120       else if (strcmp (format, "pt") == 0)
121           execute_command_to_string ("record btrace pt", from_tty, false);
122       else
123           error (_("Invalid format."));
124     }
125   else
126     error (_("Invalid method."));
127 }
128 
129 /* See record.h.  */
130 
131 void
record_stop(int from_tty)132 record_stop (int from_tty)
133 {
134   execute_command_to_string ("record stop", from_tty, false);
135 }
136 
137 /* See record.h.  */
138 
139 int
record_read_memory(struct gdbarch * gdbarch,CORE_ADDR memaddr,gdb_byte * myaddr,ssize_t len)140 record_read_memory (struct gdbarch *gdbarch,
141                         CORE_ADDR memaddr, gdb_byte *myaddr,
142                         ssize_t len)
143 {
144   int ret = target_read_memory (memaddr, myaddr, len);
145 
146   if (ret != 0)
147     DEBUG ("error reading memory at addr %s len = %ld.\n",
148              paddress (gdbarch, memaddr), (long) len);
149 
150   return ret;
151 }
152 
153 /* Stop recording.  */
154 
155 static void
record_stop(struct target_ops * t)156 record_stop (struct target_ops *t)
157 {
158   DEBUG ("stop %s", t->shortname ());
159 
160   t->stop_recording ();
161 }
162 
163 /* Unpush the record target.  */
164 
165 static void
record_unpush(struct target_ops * t)166 record_unpush (struct target_ops *t)
167 {
168   DEBUG ("unpush %s", t->shortname ());
169 
170   current_inferior ()->unpush_target (t);
171 }
172 
173 /* See record.h.  */
174 
175 void
record_disconnect(struct target_ops * t,const char * args,int from_tty)176 record_disconnect (struct target_ops *t, const char *args, int from_tty)
177 {
178   gdb_assert (t->stratum () == record_stratum);
179 
180   DEBUG ("disconnect %s", t->shortname ());
181 
182   record_stop (t);
183   record_unpush (t);
184 
185   target_disconnect (args, from_tty);
186 }
187 
188 /* See record.h.  */
189 
190 void
record_detach(struct target_ops * t,inferior * inf,int from_tty)191 record_detach (struct target_ops *t, inferior *inf, int from_tty)
192 {
193   gdb_assert (t->stratum () == record_stratum);
194 
195   DEBUG ("detach %s", t->shortname ());
196 
197   record_stop (t);
198   record_unpush (t);
199 
200   target_detach (inf, from_tty);
201 }
202 
203 /* See record.h.  */
204 
205 void
record_mourn_inferior(struct target_ops * t)206 record_mourn_inferior (struct target_ops *t)
207 {
208   gdb_assert (t->stratum () == record_stratum);
209 
210   DEBUG ("mourn inferior %s", t->shortname ());
211 
212   /* It is safer to not stop recording.  Resources will be freed when
213      threads are discarded.  */
214   record_unpush (t);
215 
216   target_mourn_inferior (inferior_ptid);
217 }
218 
219 /* See record.h.  */
220 
221 void
record_kill(struct target_ops * t)222 record_kill (struct target_ops *t)
223 {
224   gdb_assert (t->stratum () == record_stratum);
225 
226   DEBUG ("kill %s", t->shortname ());
227 
228   /* It is safer to not stop recording.  Resources will be freed when
229      threads are discarded.  */
230   record_unpush (t);
231 
232   target_kill ();
233 }
234 
235 /* See record.h.  */
236 
237 int
record_check_stopped_by_breakpoint(const address_space * aspace,CORE_ADDR pc,enum target_stop_reason * reason)238 record_check_stopped_by_breakpoint (const address_space *aspace,
239                                             CORE_ADDR pc,
240                                             enum target_stop_reason *reason)
241 {
242   if (breakpoint_inserted_here_p (aspace, pc))
243     {
244       if (hardware_breakpoint_inserted_here_p (aspace, pc))
245           *reason = TARGET_STOPPED_BY_HW_BREAKPOINT;
246       else
247           *reason = TARGET_STOPPED_BY_SW_BREAKPOINT;
248       return 1;
249     }
250 
251   return 0;
252 }
253 
254 /* Implement "show record debug" command.  */
255 
256 static void
show_record_debug(struct ui_file * file,int from_tty,struct cmd_list_element * c,const char * value)257 show_record_debug (struct ui_file *file, int from_tty,
258                        struct cmd_list_element *c, const char *value)
259 {
260   gdb_printf (file, _("Debugging of process record target is %s.\n"),
261                 value);
262 }
263 
264 /* Alias for "target record-full".  */
265 
266 static void
cmd_record_start(const char * args,int from_tty)267 cmd_record_start (const char *args, int from_tty)
268 {
269   /* As 'record' is a prefix command then if the user types 'record blah'
270      GDB will search for the 'blah' sub-command and either run that instead
271      of calling this function, or throw an error if 'blah' doesn't exist.
272      As a result, we only get here if no args are given.  */
273   gdb_assert (args == nullptr);
274   execute_command ("target record-full", from_tty);
275 }
276 
277 /* Truncate the record log from the present point
278    of replay until the end.  */
279 
280 static void
cmd_record_delete(const char * args,int from_tty)281 cmd_record_delete (const char *args, int from_tty)
282 {
283   require_record_target ();
284 
285   if (!target_record_is_replaying (inferior_ptid))
286     {
287       gdb_printf (_("Already at end of record list.\n"));
288       return;
289     }
290 
291   if (!target_supports_delete_record ())
292     {
293       gdb_printf (_("The current record target does not support "
294                         "this operation.\n"));
295       return;
296     }
297 
298   if (!from_tty || query (_("Delete the log from this point forward "
299                                   "and begin to record the running message "
300                                   "at current PC?")))
301     target_delete_record ();
302 }
303 
304 /* Implement the "stoprecord" or "record stop" command.  */
305 
306 static void
cmd_record_stop(const char * args,int from_tty)307 cmd_record_stop (const char *args, int from_tty)
308 {
309   struct target_ops *t;
310 
311   t = require_record_target ();
312 
313   record_stop (t);
314   record_unpush (t);
315 
316   gdb_printf (_("Process record is stopped and all execution "
317                     "logs are deleted.\n"));
318 
319   interps_notify_record_changed (current_inferior (), 0, NULL, NULL);
320 }
321 
322 
323 /* The "info record" command.  */
324 
325 static void
info_record_command(const char * args,int from_tty)326 info_record_command (const char *args, int from_tty)
327 {
328   struct target_ops *t;
329 
330   t = find_record_target ();
331   if (t == NULL)
332     {
333       gdb_printf (_("No recording is currently active.\n"));
334       return;
335     }
336 
337   gdb_printf (_("Active record target: %s\n"), t->shortname ());
338   t->info_record ();
339 }
340 
341 /* The "record save" command.  */
342 
343 static void
cmd_record_save(const char * args,int from_tty)344 cmd_record_save (const char *args, int from_tty)
345 {
346   const char *recfilename;
347   char recfilename_buffer[40];
348 
349   require_record_target ();
350 
351   if (args != NULL && *args != 0)
352     recfilename = args;
353   else
354     {
355       /* Default recfile name is "gdb_record.PID".  */
356       xsnprintf (recfilename_buffer, sizeof (recfilename_buffer),
357                     "gdb_record.%d", inferior_ptid.pid ());
358       recfilename = recfilename_buffer;
359     }
360 
361   target_save_record (recfilename);
362 }
363 
364 /* See record.h.  */
365 
366 void
record_goto(const char * arg)367 record_goto (const char *arg)
368 {
369   ULONGEST insn;
370 
371   if (arg == NULL || *arg == '\0')
372     error (_("Command requires an argument (insn number to go to)."));
373 
374   insn = parse_and_eval_long (arg);
375 
376   require_record_target ();
377   target_goto_record (insn);
378 }
379 
380 /* "record goto" command.  Argument is an instruction number,
381    as given by "info record".
382 
383    Rewinds the recording (forward or backward) to the given instruction.  */
384 
385 static void
cmd_record_goto(const char * arg,int from_tty)386 cmd_record_goto (const char *arg, int from_tty)
387 {
388   record_goto (arg);
389 }
390 
391 /* The "record goto begin" command.  */
392 
393 static void
cmd_record_goto_begin(const char * arg,int from_tty)394 cmd_record_goto_begin (const char *arg, int from_tty)
395 {
396   if (arg != NULL && *arg != '\0')
397     error (_("Junk after argument: %s."), arg);
398 
399   require_record_target ();
400   target_goto_record_begin ();
401 }
402 
403 /* The "record goto end" command.  */
404 
405 static void
cmd_record_goto_end(const char * arg,int from_tty)406 cmd_record_goto_end (const char *arg, int from_tty)
407 {
408   if (arg != NULL && *arg != '\0')
409     error (_("Junk after argument: %s."), arg);
410 
411   require_record_target ();
412   target_goto_record_end ();
413 }
414 
415 /* Read an instruction number from an argument string.  */
416 
417 static ULONGEST
get_insn_number(const char ** arg)418 get_insn_number (const char **arg)
419 {
420   ULONGEST number;
421   const char *begin, *end, *pos;
422 
423   begin = *arg;
424   pos = skip_spaces (begin);
425 
426   if (!isdigit (*pos))
427     error (_("Expected positive number, got: %s."), pos);
428 
429   number = strtoulst (pos, &end, 10);
430 
431   *arg += (end - begin);
432 
433   return number;
434 }
435 
436 /* Read a context size from an argument string.  */
437 
438 static int
get_context_size(const char ** arg)439 get_context_size (const char **arg)
440 {
441   const char *pos;
442   char *end;
443 
444   pos = skip_spaces (*arg);
445 
446   if (!isdigit (*pos))
447     error (_("Expected positive number, got: %s."), pos);
448 
449   long result = strtol (pos, &end, 10);
450   *arg = end;
451   return result;
452 }
453 
454 /* Complain about junk at the end of an argument string.  */
455 
456 static void
no_chunk(const char * arg)457 no_chunk (const char *arg)
458 {
459   if (*arg != 0)
460     error (_("Junk after argument: %s."), arg);
461 }
462 
463 /* Read instruction-history modifiers from an argument string.  */
464 
465 static gdb_disassembly_flags
get_insn_history_modifiers(const char ** arg)466 get_insn_history_modifiers (const char **arg)
467 {
468   gdb_disassembly_flags modifiers;
469   const char *args;
470 
471   modifiers = 0;
472   args = *arg;
473 
474   if (args == NULL)
475     return modifiers;
476 
477   while (*args == '/')
478     {
479       ++args;
480 
481       if (*args == '\0')
482           error (_("Missing modifier."));
483 
484       for (; *args; ++args)
485           {
486             if (isspace (*args))
487               break;
488 
489             if (*args == '/')
490               continue;
491 
492             switch (*args)
493               {
494               case 'm':
495               case 's':
496                 modifiers |= DISASSEMBLY_SOURCE;
497                 modifiers |= DISASSEMBLY_FILENAME;
498                 break;
499               case 'r':
500                 modifiers |= DISASSEMBLY_RAW_INSN;
501                 break;
502               case 'b':
503                 modifiers |= DISASSEMBLY_RAW_BYTES;
504                 break;
505               case 'f':
506                 modifiers |= DISASSEMBLY_OMIT_FNAME;
507                 break;
508               case 'p':
509                 modifiers |= DISASSEMBLY_OMIT_PC;
510                 break;
511               default:
512                 error (_("Invalid modifier: %c."), *args);
513               }
514           }
515 
516       args = skip_spaces (args);
517     }
518 
519   /* Update the argument string.  */
520   *arg = args;
521 
522   return modifiers;
523 }
524 
525 /* The "set record instruction-history-size / set record
526    function-call-history-size" commands are unsigned, with UINT_MAX
527    meaning unlimited.  The target interfaces works with signed int
528    though, to indicate direction, so map "unlimited" to INT_MAX, which
529    is about the same as unlimited in practice.  If the user does have
530    a log that huge, she can fetch it in chunks across several requests,
531    but she'll likely have other problems first...  */
532 
533 static int
command_size_to_target_size(unsigned int size)534 command_size_to_target_size (unsigned int size)
535 {
536   gdb_assert (size <= INT_MAX || size == UINT_MAX);
537 
538   if (size == UINT_MAX)
539     return INT_MAX;
540   else
541     return size;
542 }
543 
544 /* The "record instruction-history" command.  */
545 
546 static void
cmd_record_insn_history(const char * arg,int from_tty)547 cmd_record_insn_history (const char *arg, int from_tty)
548 {
549   require_record_target ();
550 
551   gdb_disassembly_flags flags = get_insn_history_modifiers (&arg);
552 
553   int size = command_size_to_target_size (record_insn_history_size);
554 
555   if (arg == NULL || *arg == 0 || strcmp (arg, "+") == 0)
556     target_insn_history (size, flags);
557   else if (strcmp (arg, "-") == 0)
558     target_insn_history (-size, flags);
559   else
560     {
561       ULONGEST begin, end;
562 
563       begin = get_insn_number (&arg);
564 
565       if (*arg == ',')
566           {
567             arg = skip_spaces (++arg);
568 
569             if (*arg == '+')
570               {
571                 arg += 1;
572                 size = get_context_size (&arg);
573 
574                 no_chunk (arg);
575 
576                 target_insn_history_from (begin, size, flags);
577               }
578             else if (*arg == '-')
579               {
580                 arg += 1;
581                 size = get_context_size (&arg);
582 
583                 no_chunk (arg);
584 
585                 target_insn_history_from (begin, -size, flags);
586               }
587             else
588               {
589                 end = get_insn_number (&arg);
590 
591                 no_chunk (arg);
592 
593                 target_insn_history_range (begin, end, flags);
594               }
595           }
596       else
597           {
598             no_chunk (arg);
599 
600             target_insn_history_from (begin, size, flags);
601           }
602 
603       dont_repeat ();
604     }
605 }
606 
607 /* Read function-call-history modifiers from an argument string.  */
608 
609 static record_print_flags
get_call_history_modifiers(const char ** arg)610 get_call_history_modifiers (const char **arg)
611 {
612   record_print_flags modifiers = 0;
613   const char *args = *arg;
614 
615   if (args == NULL)
616     return modifiers;
617 
618   while (*args == '/')
619     {
620       ++args;
621 
622       if (*args == '\0')
623           error (_("Missing modifier."));
624 
625       for (; *args; ++args)
626           {
627             if (isspace (*args))
628               break;
629 
630             if (*args == '/')
631               continue;
632 
633             switch (*args)
634               {
635               case 'l':
636                 modifiers |= RECORD_PRINT_SRC_LINE;
637                 break;
638               case 'i':
639                 modifiers |= RECORD_PRINT_INSN_RANGE;
640                 break;
641               case 'c':
642                 modifiers |= RECORD_PRINT_INDENT_CALLS;
643                 break;
644               default:
645                 error (_("Invalid modifier: %c."), *args);
646               }
647           }
648 
649       args = skip_spaces (args);
650     }
651 
652   /* Update the argument string.  */
653   *arg = args;
654 
655   return modifiers;
656 }
657 
658 /* The "record function-call-history" command.  */
659 
660 static void
cmd_record_call_history(const char * arg,int from_tty)661 cmd_record_call_history (const char *arg, int from_tty)
662 {
663   require_record_target ();
664 
665   record_print_flags flags = get_call_history_modifiers (&arg);
666 
667   int size = command_size_to_target_size (record_call_history_size);
668 
669   if (arg == NULL || *arg == 0 || strcmp (arg, "+") == 0)
670     target_call_history (size, flags);
671   else if (strcmp (arg, "-") == 0)
672     target_call_history (-size, flags);
673   else
674     {
675       ULONGEST begin, end;
676 
677       begin = get_insn_number (&arg);
678 
679       if (*arg == ',')
680           {
681             arg = skip_spaces (++arg);
682 
683             if (*arg == '+')
684               {
685                 arg += 1;
686                 size = get_context_size (&arg);
687 
688                 no_chunk (arg);
689 
690                 target_call_history_from (begin, size, flags);
691               }
692             else if (*arg == '-')
693               {
694                 arg += 1;
695                 size = get_context_size (&arg);
696 
697                 no_chunk (arg);
698 
699                 target_call_history_from (begin, -size, flags);
700               }
701             else
702               {
703                 end = get_insn_number (&arg);
704 
705                 no_chunk (arg);
706 
707                 target_call_history_range (begin, end, flags);
708               }
709           }
710       else
711           {
712             no_chunk (arg);
713 
714             target_call_history_from (begin, size, flags);
715           }
716 
717       dont_repeat ();
718     }
719 }
720 
721 /* Helper for "set record instruction-history-size" and "set record
722    function-call-history-size" input validation.  COMMAND_VAR is the
723    variable registered in the command as control variable.  *SETTING
724    is the real setting the command allows changing.  */
725 
726 static void
validate_history_size(unsigned int * command_var,unsigned int * setting)727 validate_history_size (unsigned int *command_var, unsigned int *setting)
728 {
729   if (*command_var != UINT_MAX && *command_var > INT_MAX)
730     {
731       unsigned int new_value = *command_var;
732 
733       /* Restore previous value.  */
734       *command_var = *setting;
735       error (_("integer %u out of range"), new_value);
736     }
737 
738   /* Commit new value.  */
739   *setting = *command_var;
740 }
741 
742 /* Called by do_setshow_command.  We only want values in the
743    [0..INT_MAX] range, while the command's machinery accepts
744    [0..UINT_MAX].  See command_size_to_target_size.  */
745 
746 static void
set_record_insn_history_size(const char * args,int from_tty,struct cmd_list_element * c)747 set_record_insn_history_size (const char *args, int from_tty,
748                                     struct cmd_list_element *c)
749 {
750   validate_history_size (&record_insn_history_size_setshow_var,
751                                &record_insn_history_size);
752 }
753 
754 /* Called by do_setshow_command.  We only want values in the
755    [0..INT_MAX] range, while the command's machinery accepts
756    [0..UINT_MAX].  See command_size_to_target_size.  */
757 
758 static void
set_record_call_history_size(const char * args,int from_tty,struct cmd_list_element * c)759 set_record_call_history_size (const char *args, int from_tty,
760                                     struct cmd_list_element *c)
761 {
762   validate_history_size (&record_call_history_size_setshow_var,
763                                &record_call_history_size);
764 }
765 
766 void _initialize_record ();
767 void
_initialize_record()768 _initialize_record ()
769 {
770   struct cmd_list_element *c;
771 
772   add_setshow_zuinteger_cmd ("record", no_class, &record_debug,
773                                    _("Set debugging of record/replay feature."),
774                                    _("Show debugging of record/replay feature."),
775                                    _("When enabled, debugging output for "
776                                      "record/replay feature is displayed."),
777                                    NULL, show_record_debug, &setdebuglist,
778                                    &showdebuglist);
779 
780   add_setshow_uinteger_cmd ("instruction-history-size", no_class,
781                                   &record_insn_history_size_setshow_var, _("\
782 Set number of instructions to print in \"record instruction-history\"."), _("\
783 Show number of instructions to print in \"record instruction-history\"."), _("\
784 A size of \"unlimited\" means unlimited instructions.  The default is 10."),
785                                   set_record_insn_history_size, NULL,
786                                   &set_record_cmdlist, &show_record_cmdlist);
787 
788   add_setshow_uinteger_cmd ("function-call-history-size", no_class,
789                                   &record_call_history_size_setshow_var, _("\
790 Set number of function to print in \"record function-call-history\"."), _("\
791 Show number of functions to print in \"record function-call-history\"."), _("\
792 A size of \"unlimited\" means unlimited lines.  The default is 10."),
793                                   set_record_call_history_size, NULL,
794                                   &set_record_cmdlist, &show_record_cmdlist);
795 
796   cmd_list_element *record_cmd
797     = add_prefix_cmd ("record", class_obscure, cmd_record_start,
798                           _("Start recording."),
799                           &record_cmdlist, 0, &cmdlist);
800   add_com_alias ("rec", record_cmd, class_obscure, 1);
801 
802   set_show_commands setshow_record_cmds
803     = add_setshow_prefix_cmd ("record", class_support,
804                                     _("Set record options."),
805                                     _("Show record options."),
806                                     &set_record_cmdlist, &show_record_cmdlist,
807                                     &setlist, &showlist);
808 
809 
810   add_alias_cmd ("rec", setshow_record_cmds.set, class_obscure, 1, &setlist);
811   add_alias_cmd ("rec", setshow_record_cmds.show, class_obscure, 1, &showlist);
812 
813   cmd_list_element *info_record_cmd
814     = add_prefix_cmd ("record", class_support, info_record_command,
815                           _("Info record options."), &info_record_cmdlist,
816                           0, &infolist);
817   add_alias_cmd ("rec", info_record_cmd, class_obscure, 1, &infolist);
818 
819   c = add_cmd ("save", class_obscure, cmd_record_save,
820                  _("Save the execution log to a file.\n\
821 Usage: record save [FILENAME]\n\
822 Default filename is 'gdb_record.PROCESS_ID'."),
823                  &record_cmdlist);
824   set_cmd_completer (c, filename_completer);
825 
826   cmd_list_element *record_delete_cmd
827     =  add_cmd ("delete", class_obscure, cmd_record_delete,
828                     _("Delete the rest of execution log and start recording it \
829 anew."),
830               &record_cmdlist);
831   add_alias_cmd ("d", record_delete_cmd, class_obscure, 1, &record_cmdlist);
832   add_alias_cmd ("del", record_delete_cmd, class_obscure, 1, &record_cmdlist);
833 
834   cmd_list_element *record_stop_cmd
835     = add_cmd ("stop", class_obscure, cmd_record_stop,
836                  _("Stop the record/replay target."),
837                  &record_cmdlist);
838   add_alias_cmd ("s", record_stop_cmd, class_obscure, 1, &record_cmdlist);
839 
840   add_prefix_cmd ("goto", class_obscure, cmd_record_goto, _("\
841 Restore the program to its state at instruction number N.\n\
842 Argument is instruction number, as shown by 'info record'."),
843                       &record_goto_cmdlist, 1, &record_cmdlist);
844 
845   cmd_list_element *record_goto_begin_cmd
846     = add_cmd ("begin", class_obscure, cmd_record_goto_begin,
847                  _("Go to the beginning of the execution log."),
848                  &record_goto_cmdlist);
849   add_alias_cmd ("start", record_goto_begin_cmd, class_obscure, 1,
850                      &record_goto_cmdlist);
851 
852   add_cmd ("end", class_obscure, cmd_record_goto_end,
853              _("Go to the end of the execution log."),
854              &record_goto_cmdlist);
855 
856   add_cmd ("instruction-history", class_obscure, cmd_record_insn_history, _("\
857 Print disassembled instructions stored in the execution log.\n\
858 With a /m or /s modifier, source lines are included (if available).\n\
859 With a /r modifier, raw instructions in hex are included.\n\
860 With a /f modifier, function names are omitted.\n\
861 With a /p modifier, current position markers are omitted.\n\
862 With no argument, disassembles ten more instructions after the previous \
863 disassembly.\n\
864 \"record instruction-history -\" disassembles ten instructions before a \
865 previous disassembly.\n\
866 One argument specifies an instruction number as shown by 'info record', and \
867 ten instructions are disassembled after that instruction.\n\
868 Two arguments with comma between them specify starting and ending instruction \
869 numbers to disassemble.\n\
870 If the second argument is preceded by '+' or '-', it specifies the distance \
871 from the first argument.\n\
872 The number of instructions to disassemble can be defined with \"set record \
873 instruction-history-size\"."),
874              &record_cmdlist);
875 
876   add_cmd ("function-call-history", class_obscure, cmd_record_call_history, _("\
877 Prints the execution history at function granularity.\n\
878 It prints one line for each sequence of instructions that belong to the same \
879 function.\n\
880 Without modifiers, it prints the function name.\n\
881 With a /l modifier, the source file and line number range is included.\n\
882 With a /i modifier, the instruction number range is included.\n\
883 With a /c modifier, the output is indented based on the call stack depth.\n\
884 With no argument, prints ten more lines after the previous ten-line print.\n\
885 \"record function-call-history -\" prints ten lines before a previous ten-line \
886 print.\n\
887 One argument specifies a function number as shown by 'info record', and \
888 ten lines are printed after that function.\n\
889 Two arguments with comma between them specify a range of functions to print.\n\
890 If the second argument is preceded by '+' or '-', it specifies the distance \
891 from the first argument.\n\
892 The number of functions to print can be defined with \"set record \
893 function-call-history-size\"."),
894              &record_cmdlist);
895 
896   /* Sync command control variables.  */
897   record_insn_history_size_setshow_var = record_insn_history_size;
898   record_call_history_size_setshow_var = record_call_history_size;
899 }
900