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