]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/record.c
2009-10-20 Michael Snyder <msnyder@vmware.com>
[thirdparty/binutils-gdb.git] / gdb / record.c
1 /* Process record and replay target for GDB, the GNU debugger.
2
3 Copyright (C) 2008, 2009 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 "event-top.h"
25 #include "exceptions.h"
26 #include "record.h"
27
28 #include <signal.h>
29
30 /* This module implements "target record", also known as "process
31 record and replay". This target sits on top of a "normal" target
32 (a target that "has execution"), and provides a record and replay
33 functionality, including reverse debugging.
34
35 Target record has two modes: recording, and replaying.
36
37 In record mode, we intercept the to_resume and to_wait methods.
38 Whenever gdb resumes the target, we run the target in single step
39 mode, and we build up an execution log in which, for each executed
40 instruction, we record all changes in memory and register state.
41 This is invisible to the user, to whom it just looks like an
42 ordinary debugging session (except for performance degredation).
43
44 In replay mode, instead of actually letting the inferior run as a
45 process, we simulate its execution by playing back the recorded
46 execution log. For each instruction in the log, we simulate the
47 instruction's side effects by duplicating the changes that it would
48 have made on memory and registers. */
49
50 #define DEFAULT_RECORD_INSN_MAX_NUM 200000
51
52 #define RECORD_IS_REPLAY \
53 (record_list->next || execution_direction == EXEC_REVERSE)
54
55 /* These are the core structs of the process record functionality.
56
57 A record_entry is a record of the value change of a register
58 ("record_reg") or a part of memory ("record_mem"). And each
59 instruction must have a struct record_entry ("record_end") that
60 indicates that this is the last struct record_entry of this
61 instruction.
62
63 Each struct record_entry is linked to "record_list" by "prev" and
64 "next" pointers. */
65
66 struct record_mem_entry
67 {
68 CORE_ADDR addr;
69 int len;
70 /* Set this flag if target memory for this entry
71 can no longer be accessed. */
72 int mem_entry_not_accessible;
73 union
74 {
75 gdb_byte *ptr;
76 gdb_byte buf[sizeof (gdb_byte *)];
77 } u;
78 };
79
80 struct record_reg_entry
81 {
82 unsigned short num;
83 unsigned short len;
84 union
85 {
86 gdb_byte *ptr;
87 gdb_byte buf[2 * sizeof (gdb_byte *)];
88 } u;
89 };
90
91 struct record_end_entry
92 {
93 enum target_signal sigval;
94 };
95
96 enum record_type
97 {
98 record_end = 0,
99 record_reg,
100 record_mem
101 };
102
103 /* This is the data structure that makes up the execution log.
104
105 The execution log consists of a single linked list of entries
106 of type "struct record_entry". It is doubly linked so that it
107 can be traversed in either direction.
108
109 The start of the list is anchored by a struct called
110 "record_first". The pointer "record_list" either points to the
111 last entry that was added to the list (in record mode), or to the
112 next entry in the list that will be executed (in replay mode).
113
114 Each list element (struct record_entry), in addition to next and
115 prev pointers, consists of a union of three entry types: mem, reg,
116 and end. A field called "type" determines which entry type is
117 represented by a given list element.
118
119 Each instruction that is added to the execution log is represented
120 by a variable number of list elements ('entries'). The instruction
121 will have one "reg" entry for each register that is changed by
122 executing the instruction (including the PC in every case). It
123 will also have one "mem" entry for each memory change. Finally,
124 each instruction will have an "end" entry that separates it from
125 the changes associated with the next instruction. */
126
127 struct record_entry
128 {
129 struct record_entry *prev;
130 struct record_entry *next;
131 enum record_type type;
132 union
133 {
134 /* reg */
135 struct record_reg_entry reg;
136 /* mem */
137 struct record_mem_entry mem;
138 /* end */
139 struct record_end_entry end;
140 } u;
141 };
142
143 /* This is the debug switch for process record. */
144 int record_debug = 0;
145
146 /* The following variables are used for managing the linked list that
147 represents the execution log.
148
149 record_first is the anchor that holds down the beginning of the list.
150
151 record_list serves two functions:
152 1) In record mode, it anchors the end of the list.
153 2) In replay mode, it traverses the list and points to
154 the next instruction that must be emulated.
155
156 record_arch_list_head and record_arch_list_tail are used to manage
157 a separate list, which is used to build up the change elements of
158 the currently executing instruction during record mode. When this
159 instruction has been completely annotated in the "arch list", it
160 will be appended to the main execution log. */
161
162 static struct record_entry record_first;
163 static struct record_entry *record_list = &record_first;
164 static struct record_entry *record_arch_list_head = NULL;
165 static struct record_entry *record_arch_list_tail = NULL;
166
167 /* 1 ask user. 0 auto delete the last struct record_entry. */
168 static int record_stop_at_limit = 1;
169 static unsigned int record_insn_max_num = DEFAULT_RECORD_INSN_MAX_NUM;
170 static int record_insn_num = 0;
171
172 /* The target_ops of process record. */
173 static struct target_ops record_ops;
174
175 /* The beneath function pointers. */
176 static struct target_ops *record_beneath_to_resume_ops;
177 static void (*record_beneath_to_resume) (struct target_ops *, ptid_t, int,
178 enum target_signal);
179 static struct target_ops *record_beneath_to_wait_ops;
180 static ptid_t (*record_beneath_to_wait) (struct target_ops *, ptid_t,
181 struct target_waitstatus *,
182 int);
183 static struct target_ops *record_beneath_to_store_registers_ops;
184 static void (*record_beneath_to_store_registers) (struct target_ops *,
185 struct regcache *,
186 int regno);
187 static struct target_ops *record_beneath_to_xfer_partial_ops;
188 static LONGEST (*record_beneath_to_xfer_partial) (struct target_ops *ops,
189 enum target_object object,
190 const char *annex,
191 gdb_byte *readbuf,
192 const gdb_byte *writebuf,
193 ULONGEST offset,
194 LONGEST len);
195 static int (*record_beneath_to_insert_breakpoint) (struct gdbarch *,
196 struct bp_target_info *);
197 static int (*record_beneath_to_remove_breakpoint) (struct gdbarch *,
198 struct bp_target_info *);
199
200 /* Alloc and free functions for record_reg, record_mem, and record_end
201 entries. */
202
203 /* Alloc a record_reg record entry. */
204
205 static inline struct record_entry *
206 record_reg_alloc (struct regcache *regcache, int regnum)
207 {
208 struct record_entry *rec;
209 struct gdbarch *gdbarch = get_regcache_arch (regcache);
210
211 rec = (struct record_entry *) xcalloc (1, sizeof (struct record_entry));
212 rec->type = record_reg;
213 rec->u.reg.num = regnum;
214 rec->u.reg.len = register_size (gdbarch, regnum);
215 if (rec->u.reg.len > sizeof (rec->u.reg.u.buf))
216 rec->u.reg.u.ptr = (gdb_byte *) xmalloc (rec->u.reg.len);
217
218 return rec;
219 }
220
221 /* Free a record_reg record entry. */
222
223 static inline void
224 record_reg_release (struct record_entry *rec)
225 {
226 gdb_assert (rec->type == record_reg);
227 if (rec->u.reg.len > sizeof (rec->u.reg.u.buf))
228 xfree (rec->u.reg.u.ptr);
229 xfree (rec);
230 }
231
232 /* Alloc a record_mem record entry. */
233
234 static inline struct record_entry *
235 record_mem_alloc (CORE_ADDR addr, int len)
236 {
237 struct record_entry *rec;
238
239 rec = (struct record_entry *) xcalloc (1, sizeof (struct record_entry));
240 rec->type = record_mem;
241 rec->u.mem.addr = addr;
242 rec->u.mem.len = len;
243 if (rec->u.mem.len > sizeof (rec->u.mem.u.buf))
244 rec->u.mem.u.ptr = (gdb_byte *) xmalloc (len);
245
246 return rec;
247 }
248
249 /* Free a record_mem record entry. */
250
251 static inline void
252 record_mem_release (struct record_entry *rec)
253 {
254 gdb_assert (rec->type == record_mem);
255 if (rec->u.mem.len > sizeof (rec->u.mem.u.buf))
256 xfree (rec->u.mem.u.ptr);
257 xfree (rec);
258 }
259
260 /* Alloc a record_end record entry. */
261
262 static inline struct record_entry *
263 record_end_alloc (void)
264 {
265 struct record_entry *rec;
266
267 rec = (struct record_entry *) xcalloc (1, sizeof (struct record_entry));
268 rec->type = record_end;
269
270 return rec;
271 }
272
273 /* Free a record_end record entry. */
274
275 static inline void
276 record_end_release (struct record_entry *rec)
277 {
278 xfree (rec);
279 }
280
281 /* Free one record entry, any type.
282 Return entry->type, in case caller wants to know. */
283
284 static inline enum record_type
285 record_entry_release (struct record_entry *rec)
286 {
287 enum record_type type = rec->type;
288
289 switch (type) {
290 case record_reg:
291 record_reg_release (rec);
292 break;
293 case record_mem:
294 record_mem_release (rec);
295 break;
296 case record_end:
297 record_end_release (rec);
298 break;
299 }
300 return type;
301 }
302
303 /* Free all record entries in list pointed to by REC. */
304
305 static void
306 record_list_release (struct record_entry *rec)
307 {
308 if (!rec)
309 return;
310
311 while (rec->next)
312 rec = rec->next;
313
314 while (rec->prev)
315 {
316 rec = rec->prev;
317 record_entry_release (rec->next);
318 }
319
320 if (rec == &record_first)
321 {
322 record_insn_num = 0;
323 record_first.next = NULL;
324 }
325 else
326 record_entry_release (rec);
327 }
328
329 /* Free all record entries forward of the given list position. */
330
331 static void
332 record_list_release_following (struct record_entry *rec)
333 {
334 struct record_entry *tmp = rec->next;
335
336 rec->next = NULL;
337 while (tmp)
338 {
339 rec = tmp->next;
340 if (record_entry_release (tmp) == record_end)
341 record_insn_num--;
342 tmp = rec;
343 }
344 }
345
346 /* Delete the first instruction from the beginning of the log, to make
347 room for adding a new instruction at the end of the log.
348
349 Note -- this function does not modify record_insn_num. */
350
351 static void
352 record_list_release_first (void)
353 {
354 struct record_entry *tmp;
355
356 if (!record_first.next)
357 return;
358
359 /* Loop until a record_end. */
360 while (1)
361 {
362 /* Cut record_first.next out of the linked list. */
363 tmp = record_first.next;
364 record_first.next = tmp->next;
365 tmp->next->prev = &record_first;
366
367 /* tmp is now isolated, and can be deleted. */
368 if (record_entry_release (tmp) == record_end)
369 {
370 record_insn_num--;
371 break; /* End loop at first record_end. */
372 }
373
374 if (!record_first.next)
375 {
376 gdb_assert (record_insn_num == 1);
377 break; /* End loop when list is empty. */
378 }
379 }
380 }
381
382 /* Add a struct record_entry to record_arch_list. */
383
384 static void
385 record_arch_list_add (struct record_entry *rec)
386 {
387 if (record_debug > 1)
388 fprintf_unfiltered (gdb_stdlog,
389 "Process record: record_arch_list_add %s.\n",
390 host_address_to_string (rec));
391
392 if (record_arch_list_tail)
393 {
394 record_arch_list_tail->next = rec;
395 rec->prev = record_arch_list_tail;
396 record_arch_list_tail = rec;
397 }
398 else
399 {
400 record_arch_list_head = rec;
401 record_arch_list_tail = rec;
402 }
403 }
404
405 /* Return the value storage location of a record entry. */
406 static inline gdb_byte *
407 record_get_loc (struct record_entry *rec)
408 {
409 switch (rec->type) {
410 case record_mem:
411 if (rec->u.mem.len > sizeof (rec->u.mem.u.buf))
412 return rec->u.mem.u.ptr;
413 else
414 return rec->u.mem.u.buf;
415 case record_reg:
416 if (rec->u.reg.len > sizeof (rec->u.reg.u.buf))
417 return rec->u.reg.u.ptr;
418 else
419 return rec->u.reg.u.buf;
420 case record_end:
421 default:
422 gdb_assert (0);
423 return NULL;
424 }
425 }
426
427 /* Record the value of a register NUM to record_arch_list. */
428
429 int
430 record_arch_list_add_reg (struct regcache *regcache, int regnum)
431 {
432 struct record_entry *rec;
433
434 if (record_debug > 1)
435 fprintf_unfiltered (gdb_stdlog,
436 "Process record: add register num = %d to "
437 "record list.\n",
438 regnum);
439
440 rec = record_reg_alloc (regcache, regnum);
441
442 regcache_raw_read (regcache, regnum, record_get_loc (rec));
443
444 record_arch_list_add (rec);
445
446 return 0;
447 }
448
449 /* Record the value of a region of memory whose address is ADDR and
450 length is LEN to record_arch_list. */
451
452 int
453 record_arch_list_add_mem (CORE_ADDR addr, int len)
454 {
455 struct record_entry *rec;
456
457 if (record_debug > 1)
458 fprintf_unfiltered (gdb_stdlog,
459 "Process record: add mem addr = %s len = %d to "
460 "record list.\n",
461 paddress (target_gdbarch, addr), len);
462
463 if (!addr) /* FIXME: Why? Some arch must permit it... */
464 return 0;
465
466 rec = record_mem_alloc (addr, len);
467
468 if (target_read_memory (addr, record_get_loc (rec), len))
469 {
470 if (record_debug)
471 fprintf_unfiltered (gdb_stdlog,
472 "Process record: error reading memory at "
473 "addr = %s len = %d.\n",
474 paddress (target_gdbarch, addr), len);
475 record_mem_release (rec);
476 return -1;
477 }
478
479 record_arch_list_add (rec);
480
481 return 0;
482 }
483
484 /* Add a record_end type struct record_entry to record_arch_list. */
485
486 int
487 record_arch_list_add_end (void)
488 {
489 struct record_entry *rec;
490
491 if (record_debug > 1)
492 fprintf_unfiltered (gdb_stdlog,
493 "Process record: add end to arch list.\n");
494
495 rec = record_end_alloc ();
496 rec->u.end.sigval = TARGET_SIGNAL_0;
497
498 record_arch_list_add (rec);
499
500 return 0;
501 }
502
503 static void
504 record_check_insn_num (int set_terminal)
505 {
506 if (record_insn_max_num)
507 {
508 gdb_assert (record_insn_num <= record_insn_max_num);
509 if (record_insn_num == record_insn_max_num)
510 {
511 /* Ask user what to do. */
512 if (record_stop_at_limit)
513 {
514 int q;
515 if (set_terminal)
516 target_terminal_ours ();
517 q = yquery (_("Do you want to auto delete previous execution "
518 "log entries when record/replay buffer becomes "
519 "full (record stop-at-limit)?"));
520 if (set_terminal)
521 target_terminal_inferior ();
522 if (q)
523 record_stop_at_limit = 0;
524 else
525 error (_("Process record: inferior program stopped."));
526 }
527 }
528 }
529 }
530
531 /* Before inferior step (when GDB record the running message, inferior
532 only can step), GDB will call this function to record the values to
533 record_list. This function will call gdbarch_process_record to
534 record the running message of inferior and set them to
535 record_arch_list, and add it to record_list. */
536
537 static void
538 record_message_cleanups (void *ignore)
539 {
540 record_list_release (record_arch_list_tail);
541 }
542
543 struct record_message_args {
544 struct regcache *regcache;
545 enum target_signal signal;
546 };
547
548 static int
549 record_message (void *args)
550 {
551 int ret;
552 struct record_message_args *myargs = args;
553 struct gdbarch *gdbarch = get_regcache_arch (myargs->regcache);
554 struct cleanup *old_cleanups = make_cleanup (record_message_cleanups, 0);
555
556 record_arch_list_head = NULL;
557 record_arch_list_tail = NULL;
558
559 /* Check record_insn_num. */
560 record_check_insn_num (1);
561
562 /* If gdb sends a signal value to target_resume,
563 save it in the 'end' field of the previous instruction.
564
565 Maybe process record should record what really happened,
566 rather than what gdb pretends has happened.
567
568 So if Linux delivered the signal to the child process during
569 the record mode, we will record it and deliver it again in
570 the replay mode.
571
572 If user says "ignore this signal" during the record mode, then
573 it will be ignored again during the replay mode (no matter if
574 the user says something different, like "deliver this signal"
575 during the replay mode).
576
577 User should understand that nothing he does during the replay
578 mode will change the behavior of the child. If he tries,
579 then that is a user error.
580
581 But we should still deliver the signal to gdb during the replay,
582 if we delivered it during the recording. Therefore we should
583 record the signal during record_wait, not record_resume. */
584 if (record_list != &record_first) /* FIXME better way to check */
585 {
586 gdb_assert (record_list->type == record_end);
587 record_list->u.end.sigval = myargs->signal;
588 }
589
590 if (myargs->signal == TARGET_SIGNAL_0
591 || !gdbarch_process_record_signal_p (gdbarch))
592 ret = gdbarch_process_record (gdbarch,
593 myargs->regcache,
594 regcache_read_pc (myargs->regcache));
595 else
596 ret = gdbarch_process_record_signal (gdbarch,
597 myargs->regcache,
598 myargs->signal);
599
600 if (ret > 0)
601 error (_("Process record: inferior program stopped."));
602 if (ret < 0)
603 error (_("Process record: failed to record execution log."));
604
605 discard_cleanups (old_cleanups);
606
607 record_list->next = record_arch_list_head;
608 record_arch_list_head->prev = record_list;
609 record_list = record_arch_list_tail;
610
611 if (record_insn_num == record_insn_max_num && record_insn_max_num)
612 record_list_release_first ();
613 else
614 record_insn_num++;
615
616 return 1;
617 }
618
619 static int
620 do_record_message (struct regcache *regcache,
621 enum target_signal signal)
622 {
623 struct record_message_args args;
624
625 args.regcache = regcache;
626 args.signal = signal;
627 return catch_errors (record_message, &args, NULL, RETURN_MASK_ALL);
628 }
629
630 /* Set to 1 if record_store_registers and record_xfer_partial
631 doesn't need record. */
632
633 static int record_gdb_operation_disable = 0;
634
635 struct cleanup *
636 record_gdb_operation_disable_set (void)
637 {
638 struct cleanup *old_cleanups = NULL;
639
640 old_cleanups =
641 make_cleanup_restore_integer (&record_gdb_operation_disable);
642 record_gdb_operation_disable = 1;
643
644 return old_cleanups;
645 }
646
647 /* Execute one instruction from the record log. Each instruction in
648 the log will be represented by an arbitrary sequence of register
649 entries and memory entries, followed by an 'end' entry. */
650
651 static inline void
652 record_exec_insn (struct regcache *regcache, struct gdbarch *gdbarch,
653 struct record_entry *entry)
654 {
655 switch (entry->type)
656 {
657 case record_reg: /* reg */
658 {
659 gdb_byte reg[MAX_REGISTER_SIZE];
660
661 if (record_debug > 1)
662 fprintf_unfiltered (gdb_stdlog,
663 "Process record: record_reg %s to "
664 "inferior num = %d.\n",
665 host_address_to_string (entry),
666 entry->u.reg.num);
667
668 regcache_cooked_read (regcache, entry->u.reg.num, reg);
669 regcache_cooked_write (regcache, entry->u.reg.num,
670 record_get_loc (entry));
671 memcpy (record_get_loc (entry), reg, entry->u.reg.len);
672 }
673 break;
674
675 case record_mem: /* mem */
676 {
677 /* Nothing to do if the entry is flagged not_accessible. */
678 if (!entry->u.mem.mem_entry_not_accessible)
679 {
680 gdb_byte *mem = alloca (entry->u.mem.len);
681
682 if (record_debug > 1)
683 fprintf_unfiltered (gdb_stdlog,
684 "Process record: record_mem %s to "
685 "inferior addr = %s len = %d.\n",
686 host_address_to_string (entry),
687 paddress (gdbarch, entry->u.mem.addr),
688 entry->u.mem.len);
689
690 if (target_read_memory (entry->u.mem.addr, mem, entry->u.mem.len))
691 {
692 entry->u.mem.mem_entry_not_accessible = 1;
693 if (record_debug)
694 warning (_("Process record: error reading memory at "
695 "addr = %s len = %d."),
696 paddress (gdbarch, entry->u.mem.addr),
697 entry->u.mem.len);
698 }
699 else
700 {
701 if (target_write_memory (entry->u.mem.addr,
702 record_get_loc (entry),
703 entry->u.mem.len))
704 {
705 entry->u.mem.mem_entry_not_accessible = 1;
706 if (record_debug)
707 warning (_("Process record: error writing memory at "
708 "addr = %s len = %d."),
709 paddress (gdbarch, entry->u.mem.addr),
710 entry->u.mem.len);
711 }
712 else
713 memcpy (record_get_loc (entry), mem, entry->u.mem.len);
714 }
715 }
716 }
717 break;
718 }
719 }
720
721 /* "to_open" target method. Open the process record target. */
722
723 static void
724 record_open (char *name, int from_tty)
725 {
726 struct target_ops *t;
727
728 if (record_debug)
729 fprintf_unfiltered (gdb_stdlog, "Process record: record_open\n");
730
731 /* check exec */
732 if (!target_has_execution)
733 error (_("Process record: the program is not being run."));
734 if (non_stop)
735 error (_("Process record target can't debug inferior in non-stop mode "
736 "(non-stop)."));
737 if (target_async_permitted)
738 error (_("Process record target can't debug inferior in asynchronous "
739 "mode (target-async)."));
740
741 if (!gdbarch_process_record_p (target_gdbarch))
742 error (_("Process record: the current architecture doesn't support "
743 "record function."));
744
745 /* Check if record target is already running. */
746 if (current_target.to_stratum == record_stratum)
747 error (_("Process record target already running. Use \"record stop\" to "
748 "stop record target first."));
749
750 /*Reset the beneath function pointers. */
751 record_beneath_to_resume = NULL;
752 record_beneath_to_wait = NULL;
753 record_beneath_to_store_registers = NULL;
754 record_beneath_to_xfer_partial = NULL;
755 record_beneath_to_insert_breakpoint = NULL;
756 record_beneath_to_remove_breakpoint = NULL;
757
758 /* Set the beneath function pointers. */
759 for (t = current_target.beneath; t != NULL; t = t->beneath)
760 {
761 if (!record_beneath_to_resume)
762 {
763 record_beneath_to_resume = t->to_resume;
764 record_beneath_to_resume_ops = t;
765 }
766 if (!record_beneath_to_wait)
767 {
768 record_beneath_to_wait = t->to_wait;
769 record_beneath_to_wait_ops = t;
770 }
771 if (!record_beneath_to_store_registers)
772 {
773 record_beneath_to_store_registers = t->to_store_registers;
774 record_beneath_to_store_registers_ops = t;
775 }
776 if (!record_beneath_to_xfer_partial)
777 {
778 record_beneath_to_xfer_partial = t->to_xfer_partial;
779 record_beneath_to_xfer_partial_ops = t;
780 }
781 if (!record_beneath_to_insert_breakpoint)
782 record_beneath_to_insert_breakpoint = t->to_insert_breakpoint;
783 if (!record_beneath_to_remove_breakpoint)
784 record_beneath_to_remove_breakpoint = t->to_remove_breakpoint;
785 }
786 if (!record_beneath_to_resume)
787 error (_("Process record can't get to_resume."));
788 if (!record_beneath_to_wait)
789 error (_("Process record can't get to_wait."));
790 if (!record_beneath_to_store_registers)
791 error (_("Process record can't get to_store_registers."));
792 if (!record_beneath_to_xfer_partial)
793 error (_("Process record can't get to_xfer_partial."));
794 if (!record_beneath_to_insert_breakpoint)
795 error (_("Process record can't get to_insert_breakpoint."));
796 if (!record_beneath_to_remove_breakpoint)
797 error (_("Process record can't get to_remove_breakpoint."));
798
799 push_target (&record_ops);
800
801 /* Reset */
802 record_insn_num = 0;
803 record_list = &record_first;
804 record_list->next = NULL;
805 }
806
807 /* "to_close" target method. Close the process record target. */
808
809 static void
810 record_close (int quitting)
811 {
812 if (record_debug)
813 fprintf_unfiltered (gdb_stdlog, "Process record: record_close\n");
814
815 record_list_release (record_list);
816 }
817
818 static int record_resume_step = 0;
819 static int record_resume_error;
820
821 /* "to_resume" target method. Resume the process record target. */
822
823 static void
824 record_resume (struct target_ops *ops, ptid_t ptid, int step,
825 enum target_signal signal)
826 {
827 record_resume_step = step;
828
829 if (!RECORD_IS_REPLAY)
830 {
831 if (do_record_message (get_current_regcache (), signal))
832 {
833 record_resume_error = 0;
834 }
835 else
836 {
837 record_resume_error = 1;
838 return;
839 }
840 record_beneath_to_resume (record_beneath_to_resume_ops, ptid, 1,
841 signal);
842 }
843 }
844
845 static int record_get_sig = 0;
846
847 /* SIGINT signal handler, registered by "to_wait" method. */
848
849 static void
850 record_sig_handler (int signo)
851 {
852 if (record_debug)
853 fprintf_unfiltered (gdb_stdlog, "Process record: get a signal\n");
854
855 /* It will break the running inferior in replay mode. */
856 record_resume_step = 1;
857
858 /* It will let record_wait set inferior status to get the signal
859 SIGINT. */
860 record_get_sig = 1;
861 }
862
863 static void
864 record_wait_cleanups (void *ignore)
865 {
866 if (execution_direction == EXEC_REVERSE)
867 {
868 if (record_list->next)
869 record_list = record_list->next;
870 }
871 else
872 record_list = record_list->prev;
873 }
874
875 /* "to_wait" target method for process record target.
876
877 In record mode, the target is always run in singlestep mode
878 (even when gdb says to continue). The to_wait method intercepts
879 the stop events and determines which ones are to be passed on to
880 gdb. Most stop events are just singlestep events that gdb is not
881 to know about, so the to_wait method just records them and keeps
882 singlestepping.
883
884 In replay mode, this function emulates the recorded execution log,
885 one instruction at a time (forward or backward), and determines
886 where to stop. */
887
888 static ptid_t
889 record_wait (struct target_ops *ops,
890 ptid_t ptid, struct target_waitstatus *status,
891 int options)
892 {
893 struct cleanup *set_cleanups = record_gdb_operation_disable_set ();
894
895 if (record_debug)
896 fprintf_unfiltered (gdb_stdlog,
897 "Process record: record_wait "
898 "record_resume_step = %d\n",
899 record_resume_step);
900
901 if (!RECORD_IS_REPLAY)
902 {
903 if (record_resume_error)
904 {
905 /* If record_resume get error, return directly. */
906 status->kind = TARGET_WAITKIND_STOPPED;
907 status->value.sig = TARGET_SIGNAL_ABRT;
908 return inferior_ptid;
909 }
910
911 if (record_resume_step)
912 {
913 /* This is a single step. */
914 return record_beneath_to_wait (record_beneath_to_wait_ops,
915 ptid, status, options);
916 }
917 else
918 {
919 /* This is not a single step. */
920 ptid_t ret;
921 CORE_ADDR tmp_pc;
922
923 while (1)
924 {
925 ret = record_beneath_to_wait (record_beneath_to_wait_ops,
926 ptid, status, options);
927
928 /* Is this a SIGTRAP? */
929 if (status->kind == TARGET_WAITKIND_STOPPED
930 && status->value.sig == TARGET_SIGNAL_TRAP)
931 {
932 struct regcache *regcache;
933
934 /* Yes -- check if there is a breakpoint. */
935 registers_changed ();
936 regcache = get_current_regcache ();
937 tmp_pc = regcache_read_pc (regcache);
938 if (breakpoint_inserted_here_p (get_regcache_aspace (regcache),
939 tmp_pc))
940 {
941 /* There is a breakpoint. GDB will want to stop. */
942 struct gdbarch *gdbarch = get_regcache_arch (regcache);
943 CORE_ADDR decr_pc_after_break
944 = gdbarch_decr_pc_after_break (gdbarch);
945 if (decr_pc_after_break)
946 regcache_write_pc (regcache,
947 tmp_pc + decr_pc_after_break);
948 }
949 else
950 {
951 /* There is not a breakpoint, and gdb is not
952 stepping, therefore gdb will not stop.
953 Therefore we will not return to gdb.
954 Record the insn and resume. */
955 if (!do_record_message (regcache, TARGET_SIGNAL_0))
956 break;
957
958 record_beneath_to_resume (record_beneath_to_resume_ops,
959 ptid, 1,
960 TARGET_SIGNAL_0);
961 continue;
962 }
963 }
964
965 /* The inferior is broken by a breakpoint or a signal. */
966 break;
967 }
968
969 return ret;
970 }
971 }
972 else
973 {
974 struct regcache *regcache = get_current_regcache ();
975 struct gdbarch *gdbarch = get_regcache_arch (regcache);
976 int continue_flag = 1;
977 int first_record_end = 1;
978 struct cleanup *old_cleanups = make_cleanup (record_wait_cleanups, 0);
979 CORE_ADDR tmp_pc;
980
981 status->kind = TARGET_WAITKIND_STOPPED;
982
983 /* Check breakpoint when forward execute. */
984 if (execution_direction == EXEC_FORWARD)
985 {
986 tmp_pc = regcache_read_pc (regcache);
987 if (breakpoint_inserted_here_p (get_regcache_aspace (regcache),
988 tmp_pc))
989 {
990 if (record_debug)
991 fprintf_unfiltered (gdb_stdlog,
992 "Process record: break at %s.\n",
993 paddress (gdbarch, tmp_pc));
994 if (gdbarch_decr_pc_after_break (gdbarch)
995 && !record_resume_step)
996 regcache_write_pc (regcache,
997 tmp_pc +
998 gdbarch_decr_pc_after_break (gdbarch));
999 goto replay_out;
1000 }
1001 }
1002
1003 record_get_sig = 0;
1004 signal (SIGINT, record_sig_handler);
1005 /* If GDB is in terminal_inferior mode, it will not get the signal.
1006 And in GDB replay mode, GDB doesn't need to be in terminal_inferior
1007 mode, because inferior will not executed.
1008 Then set it to terminal_ours to make GDB get the signal. */
1009 target_terminal_ours ();
1010
1011 /* In EXEC_FORWARD mode, record_list points to the tail of prev
1012 instruction. */
1013 if (execution_direction == EXEC_FORWARD && record_list->next)
1014 record_list = record_list->next;
1015
1016 /* Loop over the record_list, looking for the next place to
1017 stop. */
1018 do
1019 {
1020 /* Check for beginning and end of log. */
1021 if (execution_direction == EXEC_REVERSE
1022 && record_list == &record_first)
1023 {
1024 /* Hit beginning of record log in reverse. */
1025 status->kind = TARGET_WAITKIND_NO_HISTORY;
1026 break;
1027 }
1028 if (execution_direction != EXEC_REVERSE && !record_list->next)
1029 {
1030 /* Hit end of record log going forward. */
1031 status->kind = TARGET_WAITKIND_NO_HISTORY;
1032 break;
1033 }
1034
1035 record_exec_insn (regcache, gdbarch, record_list);
1036
1037 if (record_list->type == record_end)
1038 {
1039 if (record_debug > 1)
1040 fprintf_unfiltered (gdb_stdlog,
1041 "Process record: record_end %s to "
1042 "inferior.\n",
1043 host_address_to_string (record_list));
1044
1045 if (first_record_end && execution_direction == EXEC_REVERSE)
1046 {
1047 /* When reverse excute, the first record_end is the part of
1048 current instruction. */
1049 first_record_end = 0;
1050 }
1051 else
1052 {
1053 /* In EXEC_REVERSE mode, this is the record_end of prev
1054 instruction.
1055 In EXEC_FORWARD mode, this is the record_end of current
1056 instruction. */
1057 /* step */
1058 if (record_resume_step)
1059 {
1060 if (record_debug > 1)
1061 fprintf_unfiltered (gdb_stdlog,
1062 "Process record: step.\n");
1063 continue_flag = 0;
1064 }
1065
1066 /* check breakpoint */
1067 tmp_pc = regcache_read_pc (regcache);
1068 if (breakpoint_inserted_here_p (get_regcache_aspace (regcache),
1069 tmp_pc))
1070 {
1071 if (record_debug)
1072 fprintf_unfiltered (gdb_stdlog,
1073 "Process record: break "
1074 "at %s.\n",
1075 paddress (gdbarch, tmp_pc));
1076 if (gdbarch_decr_pc_after_break (gdbarch)
1077 && execution_direction == EXEC_FORWARD
1078 && !record_resume_step)
1079 regcache_write_pc (regcache,
1080 tmp_pc +
1081 gdbarch_decr_pc_after_break (gdbarch));
1082 continue_flag = 0;
1083 }
1084 /* Check target signal */
1085 if (record_list->u.end.sigval != TARGET_SIGNAL_0)
1086 /* FIXME: better way to check */
1087 continue_flag = 0;
1088 }
1089 }
1090
1091 if (continue_flag)
1092 {
1093 if (execution_direction == EXEC_REVERSE)
1094 {
1095 if (record_list->prev)
1096 record_list = record_list->prev;
1097 }
1098 else
1099 {
1100 if (record_list->next)
1101 record_list = record_list->next;
1102 }
1103 }
1104 }
1105 while (continue_flag);
1106
1107 signal (SIGINT, handle_sigint);
1108
1109 replay_out:
1110 if (record_get_sig)
1111 status->value.sig = TARGET_SIGNAL_INT;
1112 else if (record_list->u.end.sigval != TARGET_SIGNAL_0)
1113 /* FIXME: better way to check */
1114 status->value.sig = record_list->u.end.sigval;
1115 else
1116 status->value.sig = TARGET_SIGNAL_TRAP;
1117
1118 discard_cleanups (old_cleanups);
1119 }
1120
1121 do_cleanups (set_cleanups);
1122 return inferior_ptid;
1123 }
1124
1125 /* "to_disconnect" method for process record target. */
1126
1127 static void
1128 record_disconnect (struct target_ops *target, char *args, int from_tty)
1129 {
1130 if (record_debug)
1131 fprintf_unfiltered (gdb_stdlog, "Process record: record_disconnect\n");
1132
1133 unpush_target (&record_ops);
1134 target_disconnect (args, from_tty);
1135 }
1136
1137 /* "to_detach" method for process record target. */
1138
1139 static void
1140 record_detach (struct target_ops *ops, char *args, int from_tty)
1141 {
1142 if (record_debug)
1143 fprintf_unfiltered (gdb_stdlog, "Process record: record_detach\n");
1144
1145 unpush_target (&record_ops);
1146 target_detach (args, from_tty);
1147 }
1148
1149 /* "to_mourn_inferior" method for process record target. */
1150
1151 static void
1152 record_mourn_inferior (struct target_ops *ops)
1153 {
1154 if (record_debug)
1155 fprintf_unfiltered (gdb_stdlog, "Process record: "
1156 "record_mourn_inferior\n");
1157
1158 unpush_target (&record_ops);
1159 target_mourn_inferior ();
1160 }
1161
1162 /* Close process record target before killing the inferior process. */
1163
1164 static void
1165 record_kill (struct target_ops *ops)
1166 {
1167 if (record_debug)
1168 fprintf_unfiltered (gdb_stdlog, "Process record: record_kill\n");
1169
1170 unpush_target (&record_ops);
1171 target_kill ();
1172 }
1173
1174 /* Record registers change (by user or by GDB) to list as an instruction. */
1175
1176 static void
1177 record_registers_change (struct regcache *regcache, int regnum)
1178 {
1179 /* Check record_insn_num. */
1180 record_check_insn_num (0);
1181
1182 record_arch_list_head = NULL;
1183 record_arch_list_tail = NULL;
1184
1185 if (regnum < 0)
1186 {
1187 int i;
1188 for (i = 0; i < gdbarch_num_regs (get_regcache_arch (regcache)); i++)
1189 {
1190 if (record_arch_list_add_reg (regcache, i))
1191 {
1192 record_list_release (record_arch_list_tail);
1193 error (_("Process record: failed to record execution log."));
1194 }
1195 }
1196 }
1197 else
1198 {
1199 if (record_arch_list_add_reg (regcache, regnum))
1200 {
1201 record_list_release (record_arch_list_tail);
1202 error (_("Process record: failed to record execution log."));
1203 }
1204 }
1205 if (record_arch_list_add_end ())
1206 {
1207 record_list_release (record_arch_list_tail);
1208 error (_("Process record: failed to record execution log."));
1209 }
1210 record_list->next = record_arch_list_head;
1211 record_arch_list_head->prev = record_list;
1212 record_list = record_arch_list_tail;
1213
1214 if (record_insn_num == record_insn_max_num && record_insn_max_num)
1215 record_list_release_first ();
1216 else
1217 record_insn_num++;
1218 }
1219
1220 /* "to_store_registers" method for process record target. */
1221
1222 static void
1223 record_store_registers (struct target_ops *ops, struct regcache *regcache,
1224 int regno)
1225 {
1226 if (!record_gdb_operation_disable)
1227 {
1228 if (RECORD_IS_REPLAY)
1229 {
1230 int n;
1231
1232 /* Let user choose if he wants to write register or not. */
1233 if (regno < 0)
1234 n =
1235 query (_("Because GDB is in replay mode, changing the "
1236 "value of a register will make the execution "
1237 "log unusable from this point onward. "
1238 "Change all registers?"));
1239 else
1240 n =
1241 query (_("Because GDB is in replay mode, changing the value "
1242 "of a register will make the execution log unusable "
1243 "from this point onward. Change register %s?"),
1244 gdbarch_register_name (get_regcache_arch (regcache),
1245 regno));
1246
1247 if (!n)
1248 {
1249 /* Invalidate the value of regcache that was set in function
1250 "regcache_raw_write". */
1251 if (regno < 0)
1252 {
1253 int i;
1254 for (i = 0;
1255 i < gdbarch_num_regs (get_regcache_arch (regcache));
1256 i++)
1257 regcache_invalidate (regcache, i);
1258 }
1259 else
1260 regcache_invalidate (regcache, regno);
1261
1262 error (_("Process record canceled the operation."));
1263 }
1264
1265 /* Destroy the record from here forward. */
1266 record_list_release_following (record_list);
1267 }
1268
1269 record_registers_change (regcache, regno);
1270 }
1271 record_beneath_to_store_registers (record_beneath_to_store_registers_ops,
1272 regcache, regno);
1273 }
1274
1275 /* Behavior is conditional on RECORD_IS_REPLAY.
1276 In replay mode, we cannot write memory unles we are willing to
1277 invalidate the record/replay log from this point forward. */
1278
1279 static LONGEST
1280 record_xfer_partial (struct target_ops *ops, enum target_object object,
1281 const char *annex, gdb_byte *readbuf,
1282 const gdb_byte *writebuf, ULONGEST offset, LONGEST len)
1283 {
1284 if (!record_gdb_operation_disable
1285 && (object == TARGET_OBJECT_MEMORY
1286 || object == TARGET_OBJECT_RAW_MEMORY) && writebuf)
1287 {
1288 if (RECORD_IS_REPLAY)
1289 {
1290 /* Let user choose if he wants to write memory or not. */
1291 if (!query (_("Because GDB is in replay mode, writing to memory "
1292 "will make the execution log unusable from this "
1293 "point onward. Write memory at address %s?"),
1294 paddress (target_gdbarch, offset)))
1295 error (_("Process record canceled the operation."));
1296
1297 /* Destroy the record from here forward. */
1298 record_list_release_following (record_list);
1299 }
1300
1301 /* Check record_insn_num */
1302 record_check_insn_num (0);
1303
1304 /* Record registers change to list as an instruction. */
1305 record_arch_list_head = NULL;
1306 record_arch_list_tail = NULL;
1307 if (record_arch_list_add_mem (offset, len))
1308 {
1309 record_list_release (record_arch_list_tail);
1310 if (record_debug)
1311 fprintf_unfiltered (gdb_stdlog,
1312 _("Process record: failed to record "
1313 "execution log."));
1314 return -1;
1315 }
1316 if (record_arch_list_add_end ())
1317 {
1318 record_list_release (record_arch_list_tail);
1319 if (record_debug)
1320 fprintf_unfiltered (gdb_stdlog,
1321 _("Process record: failed to record "
1322 "execution log."));
1323 return -1;
1324 }
1325 record_list->next = record_arch_list_head;
1326 record_arch_list_head->prev = record_list;
1327 record_list = record_arch_list_tail;
1328
1329 if (record_insn_num == record_insn_max_num && record_insn_max_num)
1330 record_list_release_first ();
1331 else
1332 record_insn_num++;
1333 }
1334
1335 return record_beneath_to_xfer_partial (record_beneath_to_xfer_partial_ops,
1336 object, annex, readbuf, writebuf,
1337 offset, len);
1338 }
1339
1340 /* Behavior is conditional on RECORD_IS_REPLAY.
1341 We will not actually insert or remove breakpoints when replaying,
1342 nor when recording. */
1343
1344 static int
1345 record_insert_breakpoint (struct gdbarch *gdbarch,
1346 struct bp_target_info *bp_tgt)
1347 {
1348 if (!RECORD_IS_REPLAY)
1349 {
1350 struct cleanup *old_cleanups = record_gdb_operation_disable_set ();
1351 int ret = record_beneath_to_insert_breakpoint (gdbarch, bp_tgt);
1352
1353 do_cleanups (old_cleanups);
1354
1355 return ret;
1356 }
1357
1358 return 0;
1359 }
1360
1361 /* "to_remove_breakpoint" method for process record target. */
1362
1363 static int
1364 record_remove_breakpoint (struct gdbarch *gdbarch,
1365 struct bp_target_info *bp_tgt)
1366 {
1367 if (!RECORD_IS_REPLAY)
1368 {
1369 struct cleanup *old_cleanups = record_gdb_operation_disable_set ();
1370 int ret = record_beneath_to_remove_breakpoint (gdbarch, bp_tgt);
1371
1372 do_cleanups (old_cleanups);
1373
1374 return ret;
1375 }
1376
1377 return 0;
1378 }
1379
1380 /* "to_can_execute_reverse" method for process record target. */
1381 static int
1382 record_can_execute_reverse (void)
1383 {
1384 return 1;
1385 }
1386
1387 static void
1388 init_record_ops (void)
1389 {
1390 record_ops.to_shortname = "record";
1391 record_ops.to_longname = "Process record and replay target";
1392 record_ops.to_doc =
1393 "Log program while executing and replay execution from log.";
1394 record_ops.to_open = record_open;
1395 record_ops.to_close = record_close;
1396 record_ops.to_resume = record_resume;
1397 record_ops.to_wait = record_wait;
1398 record_ops.to_disconnect = record_disconnect;
1399 record_ops.to_detach = record_detach;
1400 record_ops.to_mourn_inferior = record_mourn_inferior;
1401 record_ops.to_kill = record_kill;
1402 record_ops.to_create_inferior = find_default_create_inferior;
1403 record_ops.to_store_registers = record_store_registers;
1404 record_ops.to_xfer_partial = record_xfer_partial;
1405 record_ops.to_insert_breakpoint = record_insert_breakpoint;
1406 record_ops.to_remove_breakpoint = record_remove_breakpoint;
1407 record_ops.to_can_execute_reverse = record_can_execute_reverse;
1408 record_ops.to_stratum = record_stratum;
1409 record_ops.to_magic = OPS_MAGIC;
1410 }
1411
1412 /* Implement "show record debug" command. */
1413
1414 static void
1415 show_record_debug (struct ui_file *file, int from_tty,
1416 struct cmd_list_element *c, const char *value)
1417 {
1418 fprintf_filtered (file, _("Debugging of process record target is %s.\n"),
1419 value);
1420 }
1421
1422 /* Alias for "target record". */
1423
1424 static void
1425 cmd_record_start (char *args, int from_tty)
1426 {
1427 execute_command ("target record", from_tty);
1428 }
1429
1430 /* Truncate the record log from the present point
1431 of replay until the end. */
1432
1433 static void
1434 cmd_record_delete (char *args, int from_tty)
1435 {
1436 if (current_target.to_stratum == record_stratum)
1437 {
1438 if (RECORD_IS_REPLAY)
1439 {
1440 if (!from_tty || query (_("Delete the log from this point forward "
1441 "and begin to record the running message "
1442 "at current PC?")))
1443 record_list_release_following (record_list);
1444 }
1445 else
1446 printf_unfiltered (_("Already at end of record list.\n"));
1447
1448 }
1449 else
1450 printf_unfiltered (_("Process record is not started.\n"));
1451 }
1452
1453 /* Implement the "stoprecord" or "record stop" command. */
1454
1455 static void
1456 cmd_record_stop (char *args, int from_tty)
1457 {
1458 if (current_target.to_stratum == record_stratum)
1459 {
1460 unpush_target (&record_ops);
1461 printf_unfiltered (_("Process record is stoped and all execution "
1462 "log is deleted.\n"));
1463 }
1464 else
1465 printf_unfiltered (_("Process record is not started.\n"));
1466 }
1467
1468 /* Set upper limit of record log size. */
1469
1470 static void
1471 set_record_insn_max_num (char *args, int from_tty, struct cmd_list_element *c)
1472 {
1473 if (record_insn_num > record_insn_max_num && record_insn_max_num)
1474 {
1475 /* Count down record_insn_num while releasing records from list. */
1476 while (record_insn_num > record_insn_max_num)
1477 {
1478 record_list_release_first ();
1479 record_insn_num--;
1480 }
1481 }
1482 }
1483
1484 /* Print the current index into the record log (number of insns recorded
1485 so far). */
1486
1487 static void
1488 show_record_insn_number (char *ignore, int from_tty)
1489 {
1490 printf_unfiltered (_("Record instruction number is %d.\n"),
1491 record_insn_num);
1492 }
1493
1494 static struct cmd_list_element *record_cmdlist, *set_record_cmdlist,
1495 *show_record_cmdlist, *info_record_cmdlist;
1496
1497 static void
1498 set_record_command (char *args, int from_tty)
1499 {
1500 printf_unfiltered (_("\
1501 \"set record\" must be followed by an apporpriate subcommand.\n"));
1502 help_list (set_record_cmdlist, "set record ", all_commands, gdb_stdout);
1503 }
1504
1505 static void
1506 show_record_command (char *args, int from_tty)
1507 {
1508 cmd_show_list (show_record_cmdlist, from_tty, "");
1509 }
1510
1511 static void
1512 info_record_command (char *args, int from_tty)
1513 {
1514 cmd_show_list (info_record_cmdlist, from_tty, "");
1515 }
1516
1517 void
1518 _initialize_record (void)
1519 {
1520 /* Init record_first. */
1521 record_first.prev = NULL;
1522 record_first.next = NULL;
1523 record_first.type = record_end;
1524
1525 init_record_ops ();
1526 add_target (&record_ops);
1527
1528 add_setshow_zinteger_cmd ("record", no_class, &record_debug,
1529 _("Set debugging of record/replay feature."),
1530 _("Show debugging of record/replay feature."),
1531 _("When enabled, debugging output for "
1532 "record/replay feature is displayed."),
1533 NULL, show_record_debug, &setdebuglist,
1534 &showdebuglist);
1535
1536 add_prefix_cmd ("record", class_obscure, cmd_record_start,
1537 _("Abbreviated form of \"target record\" command."),
1538 &record_cmdlist, "record ", 0, &cmdlist);
1539 add_com_alias ("rec", "record", class_obscure, 1);
1540 add_prefix_cmd ("record", class_support, set_record_command,
1541 _("Set record options"), &set_record_cmdlist,
1542 "set record ", 0, &setlist);
1543 add_alias_cmd ("rec", "record", class_obscure, 1, &setlist);
1544 add_prefix_cmd ("record", class_support, show_record_command,
1545 _("Show record options"), &show_record_cmdlist,
1546 "show record ", 0, &showlist);
1547 add_alias_cmd ("rec", "record", class_obscure, 1, &showlist);
1548 add_prefix_cmd ("record", class_support, info_record_command,
1549 _("Info record options"), &info_record_cmdlist,
1550 "info record ", 0, &infolist);
1551 add_alias_cmd ("rec", "record", class_obscure, 1, &infolist);
1552
1553
1554 add_cmd ("delete", class_obscure, cmd_record_delete,
1555 _("Delete the rest of execution log and start recording it anew."),
1556 &record_cmdlist);
1557 add_alias_cmd ("d", "delete", class_obscure, 1, &record_cmdlist);
1558 add_alias_cmd ("del", "delete", class_obscure, 1, &record_cmdlist);
1559
1560 add_cmd ("stop", class_obscure, cmd_record_stop,
1561 _("Stop the record/replay target."),
1562 &record_cmdlist);
1563 add_alias_cmd ("s", "stop", class_obscure, 1, &record_cmdlist);
1564
1565 /* Record instructions number limit command. */
1566 add_setshow_boolean_cmd ("stop-at-limit", no_class,
1567 &record_stop_at_limit, _("\
1568 Set whether record/replay stops when record/replay buffer becomes full."), _("\
1569 Show whether record/replay stops when record/replay buffer becomes full."), _("\
1570 Default is ON.\n\
1571 When ON, if the record/replay buffer becomes full, ask user what to do.\n\
1572 When OFF, if the record/replay buffer becomes full,\n\
1573 delete the oldest recorded instruction to make room for each new one."),
1574 NULL, NULL,
1575 &set_record_cmdlist, &show_record_cmdlist);
1576 add_setshow_uinteger_cmd ("insn-number-max", no_class,
1577 &record_insn_max_num,
1578 _("Set record/replay buffer limit."),
1579 _("Show record/replay buffer limit."), _("\
1580 Set the maximum number of instructions to be stored in the\n\
1581 record/replay buffer. Zero means unlimited. Default is 200000."),
1582 set_record_insn_max_num,
1583 NULL, &set_record_cmdlist, &show_record_cmdlist);
1584 add_cmd ("insn-number", class_obscure, show_record_insn_number,
1585 _("Show the current number of instructions in the "
1586 "record/replay buffer."), &info_record_cmdlist);
1587 }