Introduce and use gdb::unlinker
[deliverable/binutils-gdb.git] / gdb / record-full.c
1 /* Process record and replay target for GDB, the GNU debugger.
2
3 Copyright (C) 2013-2017 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 "completer.h"
26 #include "arch-utils.h"
27 #include "gdbcore.h"
28 #include "exec.h"
29 #include "record.h"
30 #include "record-full.h"
31 #include "elf-bfd.h"
32 #include "gcore.h"
33 #include "event-loop.h"
34 #include "inf-loop.h"
35 #include "gdb_bfd.h"
36 #include "observer.h"
37 #include "infrun.h"
38 #include "common/gdb_unlinker.h"
39
40 #include <signal.h>
41
42 /* This module implements "target record-full", also known as "process
43 record and replay". This target sits on top of a "normal" target
44 (a target that "has execution"), and provides a record and replay
45 functionality, including reverse debugging.
46
47 Target record has two modes: recording, and replaying.
48
49 In record mode, we intercept the to_resume and to_wait methods.
50 Whenever gdb resumes the target, we run the target in single step
51 mode, and we build up an execution log in which, for each executed
52 instruction, we record all changes in memory and register state.
53 This is invisible to the user, to whom it just looks like an
54 ordinary debugging session (except for performance degredation).
55
56 In replay mode, instead of actually letting the inferior run as a
57 process, we simulate its execution by playing back the recorded
58 execution log. For each instruction in the log, we simulate the
59 instruction's side effects by duplicating the changes that it would
60 have made on memory and registers. */
61
62 #define DEFAULT_RECORD_FULL_INSN_MAX_NUM 200000
63
64 #define RECORD_FULL_IS_REPLAY \
65 (record_full_list->next || execution_direction == EXEC_REVERSE)
66
67 #define RECORD_FULL_FILE_MAGIC netorder32(0x20091016)
68
69 /* These are the core structs of the process record functionality.
70
71 A record_full_entry is a record of the value change of a register
72 ("record_full_reg") or a part of memory ("record_full_mem"). And each
73 instruction must have a struct record_full_entry ("record_full_end")
74 that indicates that this is the last struct record_full_entry of this
75 instruction.
76
77 Each struct record_full_entry is linked to "record_full_list" by "prev"
78 and "next" pointers. */
79
80 struct record_full_mem_entry
81 {
82 CORE_ADDR addr;
83 int len;
84 /* Set this flag if target memory for this entry
85 can no longer be accessed. */
86 int mem_entry_not_accessible;
87 union
88 {
89 gdb_byte *ptr;
90 gdb_byte buf[sizeof (gdb_byte *)];
91 } u;
92 };
93
94 struct record_full_reg_entry
95 {
96 unsigned short num;
97 unsigned short len;
98 union
99 {
100 gdb_byte *ptr;
101 gdb_byte buf[2 * sizeof (gdb_byte *)];
102 } u;
103 };
104
105 struct record_full_end_entry
106 {
107 enum gdb_signal sigval;
108 ULONGEST insn_num;
109 };
110
111 enum record_full_type
112 {
113 record_full_end = 0,
114 record_full_reg,
115 record_full_mem
116 };
117
118 /* This is the data structure that makes up the execution log.
119
120 The execution log consists of a single linked list of entries
121 of type "struct record_full_entry". It is doubly linked so that it
122 can be traversed in either direction.
123
124 The start of the list is anchored by a struct called
125 "record_full_first". The pointer "record_full_list" either points
126 to the last entry that was added to the list (in record mode), or to
127 the next entry in the list that will be executed (in replay mode).
128
129 Each list element (struct record_full_entry), in addition to next
130 and prev pointers, consists of a union of three entry types: mem,
131 reg, and end. A field called "type" determines which entry type is
132 represented by a given list element.
133
134 Each instruction that is added to the execution log is represented
135 by a variable number of list elements ('entries'). The instruction
136 will have one "reg" entry for each register that is changed by
137 executing the instruction (including the PC in every case). It
138 will also have one "mem" entry for each memory change. Finally,
139 each instruction will have an "end" entry that separates it from
140 the changes associated with the next instruction. */
141
142 struct record_full_entry
143 {
144 struct record_full_entry *prev;
145 struct record_full_entry *next;
146 enum record_full_type type;
147 union
148 {
149 /* reg */
150 struct record_full_reg_entry reg;
151 /* mem */
152 struct record_full_mem_entry mem;
153 /* end */
154 struct record_full_end_entry end;
155 } u;
156 };
157
158 /* If true, query if PREC cannot record memory
159 change of next instruction. */
160 int record_full_memory_query = 0;
161
162 struct record_full_core_buf_entry
163 {
164 struct record_full_core_buf_entry *prev;
165 struct target_section *p;
166 bfd_byte *buf;
167 };
168
169 /* Record buf with core target. */
170 static gdb_byte *record_full_core_regbuf = NULL;
171 static struct target_section *record_full_core_start;
172 static struct target_section *record_full_core_end;
173 static struct record_full_core_buf_entry *record_full_core_buf_list = NULL;
174
175 /* The following variables are used for managing the linked list that
176 represents the execution log.
177
178 record_full_first is the anchor that holds down the beginning of
179 the list.
180
181 record_full_list serves two functions:
182 1) In record mode, it anchors the end of the list.
183 2) In replay mode, it traverses the list and points to
184 the next instruction that must be emulated.
185
186 record_full_arch_list_head and record_full_arch_list_tail are used
187 to manage a separate list, which is used to build up the change
188 elements of the currently executing instruction during record mode.
189 When this instruction has been completely annotated in the "arch
190 list", it will be appended to the main execution log. */
191
192 static struct record_full_entry record_full_first;
193 static struct record_full_entry *record_full_list = &record_full_first;
194 static struct record_full_entry *record_full_arch_list_head = NULL;
195 static struct record_full_entry *record_full_arch_list_tail = NULL;
196
197 /* 1 ask user. 0 auto delete the last struct record_full_entry. */
198 static int record_full_stop_at_limit = 1;
199 /* Maximum allowed number of insns in execution log. */
200 static unsigned int record_full_insn_max_num
201 = DEFAULT_RECORD_FULL_INSN_MAX_NUM;
202 /* Actual count of insns presently in execution log. */
203 static unsigned int record_full_insn_num = 0;
204 /* Count of insns logged so far (may be larger
205 than count of insns presently in execution log). */
206 static ULONGEST record_full_insn_count;
207
208 /* The target_ops of process record. */
209 static struct target_ops record_full_ops;
210 static struct target_ops record_full_core_ops;
211
212 /* See record-full.h. */
213
214 int
215 record_full_is_used (void)
216 {
217 struct target_ops *t;
218
219 t = find_record_target ();
220 return (t == &record_full_ops
221 || t == &record_full_core_ops);
222 }
223
224
225 /* Command lists for "set/show record full". */
226 static struct cmd_list_element *set_record_full_cmdlist;
227 static struct cmd_list_element *show_record_full_cmdlist;
228
229 /* Command list for "record full". */
230 static struct cmd_list_element *record_full_cmdlist;
231
232 static void record_full_goto_insn (struct record_full_entry *entry,
233 enum exec_direction_kind dir);
234 static void record_full_save (struct target_ops *self,
235 const char *recfilename);
236
237 /* Alloc and free functions for record_full_reg, record_full_mem, and
238 record_full_end entries. */
239
240 /* Alloc a record_full_reg record entry. */
241
242 static inline struct record_full_entry *
243 record_full_reg_alloc (struct regcache *regcache, int regnum)
244 {
245 struct record_full_entry *rec;
246 struct gdbarch *gdbarch = get_regcache_arch (regcache);
247
248 rec = XCNEW (struct record_full_entry);
249 rec->type = record_full_reg;
250 rec->u.reg.num = regnum;
251 rec->u.reg.len = register_size (gdbarch, regnum);
252 if (rec->u.reg.len > sizeof (rec->u.reg.u.buf))
253 rec->u.reg.u.ptr = (gdb_byte *) xmalloc (rec->u.reg.len);
254
255 return rec;
256 }
257
258 /* Free a record_full_reg record entry. */
259
260 static inline void
261 record_full_reg_release (struct record_full_entry *rec)
262 {
263 gdb_assert (rec->type == record_full_reg);
264 if (rec->u.reg.len > sizeof (rec->u.reg.u.buf))
265 xfree (rec->u.reg.u.ptr);
266 xfree (rec);
267 }
268
269 /* Alloc a record_full_mem record entry. */
270
271 static inline struct record_full_entry *
272 record_full_mem_alloc (CORE_ADDR addr, int len)
273 {
274 struct record_full_entry *rec;
275
276 rec = XCNEW (struct record_full_entry);
277 rec->type = record_full_mem;
278 rec->u.mem.addr = addr;
279 rec->u.mem.len = len;
280 if (rec->u.mem.len > sizeof (rec->u.mem.u.buf))
281 rec->u.mem.u.ptr = (gdb_byte *) xmalloc (len);
282
283 return rec;
284 }
285
286 /* Free a record_full_mem record entry. */
287
288 static inline void
289 record_full_mem_release (struct record_full_entry *rec)
290 {
291 gdb_assert (rec->type == record_full_mem);
292 if (rec->u.mem.len > sizeof (rec->u.mem.u.buf))
293 xfree (rec->u.mem.u.ptr);
294 xfree (rec);
295 }
296
297 /* Alloc a record_full_end record entry. */
298
299 static inline struct record_full_entry *
300 record_full_end_alloc (void)
301 {
302 struct record_full_entry *rec;
303
304 rec = XCNEW (struct record_full_entry);
305 rec->type = record_full_end;
306
307 return rec;
308 }
309
310 /* Free a record_full_end record entry. */
311
312 static inline void
313 record_full_end_release (struct record_full_entry *rec)
314 {
315 xfree (rec);
316 }
317
318 /* Free one record entry, any type.
319 Return entry->type, in case caller wants to know. */
320
321 static inline enum record_full_type
322 record_full_entry_release (struct record_full_entry *rec)
323 {
324 enum record_full_type type = rec->type;
325
326 switch (type) {
327 case record_full_reg:
328 record_full_reg_release (rec);
329 break;
330 case record_full_mem:
331 record_full_mem_release (rec);
332 break;
333 case record_full_end:
334 record_full_end_release (rec);
335 break;
336 }
337 return type;
338 }
339
340 /* Free all record entries in list pointed to by REC. */
341
342 static void
343 record_full_list_release (struct record_full_entry *rec)
344 {
345 if (!rec)
346 return;
347
348 while (rec->next)
349 rec = rec->next;
350
351 while (rec->prev)
352 {
353 rec = rec->prev;
354 record_full_entry_release (rec->next);
355 }
356
357 if (rec == &record_full_first)
358 {
359 record_full_insn_num = 0;
360 record_full_first.next = NULL;
361 }
362 else
363 record_full_entry_release (rec);
364 }
365
366 /* Free all record entries forward of the given list position. */
367
368 static void
369 record_full_list_release_following (struct record_full_entry *rec)
370 {
371 struct record_full_entry *tmp = rec->next;
372
373 rec->next = NULL;
374 while (tmp)
375 {
376 rec = tmp->next;
377 if (record_full_entry_release (tmp) == record_full_end)
378 {
379 record_full_insn_num--;
380 record_full_insn_count--;
381 }
382 tmp = rec;
383 }
384 }
385
386 /* Delete the first instruction from the beginning of the log, to make
387 room for adding a new instruction at the end of the log.
388
389 Note -- this function does not modify record_full_insn_num. */
390
391 static void
392 record_full_list_release_first (void)
393 {
394 struct record_full_entry *tmp;
395
396 if (!record_full_first.next)
397 return;
398
399 /* Loop until a record_full_end. */
400 while (1)
401 {
402 /* Cut record_full_first.next out of the linked list. */
403 tmp = record_full_first.next;
404 record_full_first.next = tmp->next;
405 tmp->next->prev = &record_full_first;
406
407 /* tmp is now isolated, and can be deleted. */
408 if (record_full_entry_release (tmp) == record_full_end)
409 break; /* End loop at first record_full_end. */
410
411 if (!record_full_first.next)
412 {
413 gdb_assert (record_full_insn_num == 1);
414 break; /* End loop when list is empty. */
415 }
416 }
417 }
418
419 /* Add a struct record_full_entry to record_full_arch_list. */
420
421 static void
422 record_full_arch_list_add (struct record_full_entry *rec)
423 {
424 if (record_debug > 1)
425 fprintf_unfiltered (gdb_stdlog,
426 "Process record: record_full_arch_list_add %s.\n",
427 host_address_to_string (rec));
428
429 if (record_full_arch_list_tail)
430 {
431 record_full_arch_list_tail->next = rec;
432 rec->prev = record_full_arch_list_tail;
433 record_full_arch_list_tail = rec;
434 }
435 else
436 {
437 record_full_arch_list_head = rec;
438 record_full_arch_list_tail = rec;
439 }
440 }
441
442 /* Return the value storage location of a record entry. */
443 static inline gdb_byte *
444 record_full_get_loc (struct record_full_entry *rec)
445 {
446 switch (rec->type) {
447 case record_full_mem:
448 if (rec->u.mem.len > sizeof (rec->u.mem.u.buf))
449 return rec->u.mem.u.ptr;
450 else
451 return rec->u.mem.u.buf;
452 case record_full_reg:
453 if (rec->u.reg.len > sizeof (rec->u.reg.u.buf))
454 return rec->u.reg.u.ptr;
455 else
456 return rec->u.reg.u.buf;
457 case record_full_end:
458 default:
459 gdb_assert_not_reached ("unexpected record_full_entry type");
460 return NULL;
461 }
462 }
463
464 /* Record the value of a register NUM to record_full_arch_list. */
465
466 int
467 record_full_arch_list_add_reg (struct regcache *regcache, int regnum)
468 {
469 struct record_full_entry *rec;
470
471 if (record_debug > 1)
472 fprintf_unfiltered (gdb_stdlog,
473 "Process record: add register num = %d to "
474 "record list.\n",
475 regnum);
476
477 rec = record_full_reg_alloc (regcache, regnum);
478
479 regcache_raw_read (regcache, regnum, record_full_get_loc (rec));
480
481 record_full_arch_list_add (rec);
482
483 return 0;
484 }
485
486 /* Record the value of a region of memory whose address is ADDR and
487 length is LEN to record_full_arch_list. */
488
489 int
490 record_full_arch_list_add_mem (CORE_ADDR addr, int len)
491 {
492 struct record_full_entry *rec;
493
494 if (record_debug > 1)
495 fprintf_unfiltered (gdb_stdlog,
496 "Process record: add mem addr = %s len = %d to "
497 "record list.\n",
498 paddress (target_gdbarch (), addr), len);
499
500 if (!addr) /* FIXME: Why? Some arch must permit it... */
501 return 0;
502
503 rec = record_full_mem_alloc (addr, len);
504
505 if (record_read_memory (target_gdbarch (), addr,
506 record_full_get_loc (rec), len))
507 {
508 record_full_mem_release (rec);
509 return -1;
510 }
511
512 record_full_arch_list_add (rec);
513
514 return 0;
515 }
516
517 /* Add a record_full_end type struct record_full_entry to
518 record_full_arch_list. */
519
520 int
521 record_full_arch_list_add_end (void)
522 {
523 struct record_full_entry *rec;
524
525 if (record_debug > 1)
526 fprintf_unfiltered (gdb_stdlog,
527 "Process record: add end to arch list.\n");
528
529 rec = record_full_end_alloc ();
530 rec->u.end.sigval = GDB_SIGNAL_0;
531 rec->u.end.insn_num = ++record_full_insn_count;
532
533 record_full_arch_list_add (rec);
534
535 return 0;
536 }
537
538 static void
539 record_full_check_insn_num (void)
540 {
541 if (record_full_insn_num == record_full_insn_max_num)
542 {
543 /* Ask user what to do. */
544 if (record_full_stop_at_limit)
545 {
546 if (!yquery (_("Do you want to auto delete previous execution "
547 "log entries when record/replay buffer becomes "
548 "full (record full stop-at-limit)?")))
549 error (_("Process record: stopped by user."));
550 record_full_stop_at_limit = 0;
551 }
552 }
553 }
554
555 static void
556 record_full_arch_list_cleanups (void *ignore)
557 {
558 record_full_list_release (record_full_arch_list_tail);
559 }
560
561 /* Before inferior step (when GDB record the running message, inferior
562 only can step), GDB will call this function to record the values to
563 record_full_list. This function will call gdbarch_process_record to
564 record the running message of inferior and set them to
565 record_full_arch_list, and add it to record_full_list. */
566
567 static int
568 record_full_message (struct regcache *regcache, enum gdb_signal signal)
569 {
570 int ret;
571 struct gdbarch *gdbarch = get_regcache_arch (regcache);
572 struct cleanup *old_cleanups
573 = make_cleanup (record_full_arch_list_cleanups, 0);
574
575 record_full_arch_list_head = NULL;
576 record_full_arch_list_tail = NULL;
577
578 /* Check record_full_insn_num. */
579 record_full_check_insn_num ();
580
581 /* If gdb sends a signal value to target_resume,
582 save it in the 'end' field of the previous instruction.
583
584 Maybe process record should record what really happened,
585 rather than what gdb pretends has happened.
586
587 So if Linux delivered the signal to the child process during
588 the record mode, we will record it and deliver it again in
589 the replay mode.
590
591 If user says "ignore this signal" during the record mode, then
592 it will be ignored again during the replay mode (no matter if
593 the user says something different, like "deliver this signal"
594 during the replay mode).
595
596 User should understand that nothing he does during the replay
597 mode will change the behavior of the child. If he tries,
598 then that is a user error.
599
600 But we should still deliver the signal to gdb during the replay,
601 if we delivered it during the recording. Therefore we should
602 record the signal during record_full_wait, not
603 record_full_resume. */
604 if (record_full_list != &record_full_first) /* FIXME better way to check */
605 {
606 gdb_assert (record_full_list->type == record_full_end);
607 record_full_list->u.end.sigval = signal;
608 }
609
610 if (signal == GDB_SIGNAL_0
611 || !gdbarch_process_record_signal_p (gdbarch))
612 ret = gdbarch_process_record (gdbarch,
613 regcache,
614 regcache_read_pc (regcache));
615 else
616 ret = gdbarch_process_record_signal (gdbarch,
617 regcache,
618 signal);
619
620 if (ret > 0)
621 error (_("Process record: inferior program stopped."));
622 if (ret < 0)
623 error (_("Process record: failed to record execution log."));
624
625 discard_cleanups (old_cleanups);
626
627 record_full_list->next = record_full_arch_list_head;
628 record_full_arch_list_head->prev = record_full_list;
629 record_full_list = record_full_arch_list_tail;
630
631 if (record_full_insn_num == record_full_insn_max_num)
632 record_full_list_release_first ();
633 else
634 record_full_insn_num++;
635
636 return 1;
637 }
638
639 struct record_full_message_args {
640 struct regcache *regcache;
641 enum gdb_signal signal;
642 };
643
644 static int
645 record_full_message_wrapper (void *args)
646 {
647 struct record_full_message_args *record_full_args
648 = (struct record_full_message_args *) args;
649
650 return record_full_message (record_full_args->regcache,
651 record_full_args->signal);
652 }
653
654 static int
655 record_full_message_wrapper_safe (struct regcache *regcache,
656 enum gdb_signal signal)
657 {
658 struct record_full_message_args args;
659
660 args.regcache = regcache;
661 args.signal = signal;
662
663 return catch_errors (record_full_message_wrapper, &args, "",
664 RETURN_MASK_ALL);
665 }
666
667 /* Set to 1 if record_full_store_registers and record_full_xfer_partial
668 doesn't need record. */
669
670 static int record_full_gdb_operation_disable = 0;
671
672 struct cleanup *
673 record_full_gdb_operation_disable_set (void)
674 {
675 struct cleanup *old_cleanups = NULL;
676
677 old_cleanups =
678 make_cleanup_restore_integer (&record_full_gdb_operation_disable);
679 record_full_gdb_operation_disable = 1;
680
681 return old_cleanups;
682 }
683
684 /* Flag set to TRUE for target_stopped_by_watchpoint. */
685 static enum target_stop_reason record_full_stop_reason
686 = TARGET_STOPPED_BY_NO_REASON;
687
688 /* Execute one instruction from the record log. Each instruction in
689 the log will be represented by an arbitrary sequence of register
690 entries and memory entries, followed by an 'end' entry. */
691
692 static inline void
693 record_full_exec_insn (struct regcache *regcache,
694 struct gdbarch *gdbarch,
695 struct record_full_entry *entry)
696 {
697 switch (entry->type)
698 {
699 case record_full_reg: /* reg */
700 {
701 gdb_byte reg[MAX_REGISTER_SIZE];
702
703 if (record_debug > 1)
704 fprintf_unfiltered (gdb_stdlog,
705 "Process record: record_full_reg %s to "
706 "inferior num = %d.\n",
707 host_address_to_string (entry),
708 entry->u.reg.num);
709
710 regcache_cooked_read (regcache, entry->u.reg.num, reg);
711 regcache_cooked_write (regcache, entry->u.reg.num,
712 record_full_get_loc (entry));
713 memcpy (record_full_get_loc (entry), reg, entry->u.reg.len);
714 }
715 break;
716
717 case record_full_mem: /* mem */
718 {
719 /* Nothing to do if the entry is flagged not_accessible. */
720 if (!entry->u.mem.mem_entry_not_accessible)
721 {
722 gdb_byte *mem = (gdb_byte *) xmalloc (entry->u.mem.len);
723 struct cleanup *cleanup = make_cleanup (xfree, mem);
724
725 if (record_debug > 1)
726 fprintf_unfiltered (gdb_stdlog,
727 "Process record: record_full_mem %s to "
728 "inferior addr = %s len = %d.\n",
729 host_address_to_string (entry),
730 paddress (gdbarch, entry->u.mem.addr),
731 entry->u.mem.len);
732
733 if (record_read_memory (gdbarch,
734 entry->u.mem.addr, mem, entry->u.mem.len))
735 entry->u.mem.mem_entry_not_accessible = 1;
736 else
737 {
738 if (target_write_memory (entry->u.mem.addr,
739 record_full_get_loc (entry),
740 entry->u.mem.len))
741 {
742 entry->u.mem.mem_entry_not_accessible = 1;
743 if (record_debug)
744 warning (_("Process record: error writing memory at "
745 "addr = %s len = %d."),
746 paddress (gdbarch, entry->u.mem.addr),
747 entry->u.mem.len);
748 }
749 else
750 {
751 memcpy (record_full_get_loc (entry), mem,
752 entry->u.mem.len);
753
754 /* We've changed memory --- check if a hardware
755 watchpoint should trap. Note that this
756 presently assumes the target beneath supports
757 continuable watchpoints. On non-continuable
758 watchpoints target, we'll want to check this
759 _before_ actually doing the memory change, and
760 not doing the change at all if the watchpoint
761 traps. */
762 if (hardware_watchpoint_inserted_in_range
763 (get_regcache_aspace (regcache),
764 entry->u.mem.addr, entry->u.mem.len))
765 record_full_stop_reason = TARGET_STOPPED_BY_WATCHPOINT;
766 }
767 }
768
769 do_cleanups (cleanup);
770 }
771 }
772 break;
773 }
774 }
775
776 static void record_full_restore (void);
777
778 /* Asynchronous signal handle registered as event loop source for when
779 we have pending events ready to be passed to the core. */
780
781 static struct async_event_handler *record_full_async_inferior_event_token;
782
783 static void
784 record_full_async_inferior_event_handler (gdb_client_data data)
785 {
786 inferior_event_handler (INF_REG_EVENT, NULL);
787 }
788
789 /* Open the process record target. */
790
791 static void
792 record_full_core_open_1 (const char *name, int from_tty)
793 {
794 struct regcache *regcache = get_current_regcache ();
795 int regnum = gdbarch_num_regs (get_regcache_arch (regcache));
796 int i;
797
798 /* Get record_full_core_regbuf. */
799 target_fetch_registers (regcache, -1);
800 record_full_core_regbuf = (gdb_byte *) xmalloc (MAX_REGISTER_SIZE * regnum);
801 for (i = 0; i < regnum; i ++)
802 regcache_raw_collect (regcache, i,
803 record_full_core_regbuf + MAX_REGISTER_SIZE * i);
804
805 /* Get record_full_core_start and record_full_core_end. */
806 if (build_section_table (core_bfd, &record_full_core_start,
807 &record_full_core_end))
808 {
809 xfree (record_full_core_regbuf);
810 record_full_core_regbuf = NULL;
811 error (_("\"%s\": Can't find sections: %s"),
812 bfd_get_filename (core_bfd), bfd_errmsg (bfd_get_error ()));
813 }
814
815 push_target (&record_full_core_ops);
816 record_full_restore ();
817 }
818
819 /* "to_open" target method for 'live' processes. */
820
821 static void
822 record_full_open_1 (const char *name, int from_tty)
823 {
824 if (record_debug)
825 fprintf_unfiltered (gdb_stdlog, "Process record: record_full_open_1\n");
826
827 /* check exec */
828 if (!target_has_execution)
829 error (_("Process record: the program is not being run."));
830 if (non_stop)
831 error (_("Process record target can't debug inferior in non-stop mode "
832 "(non-stop)."));
833
834 if (!gdbarch_process_record_p (target_gdbarch ()))
835 error (_("Process record: the current architecture doesn't support "
836 "record function."));
837
838 push_target (&record_full_ops);
839 }
840
841 static void record_full_init_record_breakpoints (void);
842
843 /* "to_open" target method. Open the process record target. */
844
845 static void
846 record_full_open (const char *name, int from_tty)
847 {
848 struct target_ops *t;
849
850 if (record_debug)
851 fprintf_unfiltered (gdb_stdlog, "Process record: record_full_open\n");
852
853 record_preopen ();
854
855 /* Reset */
856 record_full_insn_num = 0;
857 record_full_insn_count = 0;
858 record_full_list = &record_full_first;
859 record_full_list->next = NULL;
860
861 if (core_bfd)
862 record_full_core_open_1 (name, from_tty);
863 else
864 record_full_open_1 (name, from_tty);
865
866 /* Register extra event sources in the event loop. */
867 record_full_async_inferior_event_token
868 = create_async_event_handler (record_full_async_inferior_event_handler,
869 NULL);
870
871 record_full_init_record_breakpoints ();
872
873 observer_notify_record_changed (current_inferior (), 1, "full", NULL);
874 }
875
876 /* "to_close" target method. Close the process record target. */
877
878 static void
879 record_full_close (struct target_ops *self)
880 {
881 struct record_full_core_buf_entry *entry;
882
883 if (record_debug)
884 fprintf_unfiltered (gdb_stdlog, "Process record: record_full_close\n");
885
886 record_full_list_release (record_full_list);
887
888 /* Release record_full_core_regbuf. */
889 if (record_full_core_regbuf)
890 {
891 xfree (record_full_core_regbuf);
892 record_full_core_regbuf = NULL;
893 }
894
895 /* Release record_full_core_buf_list. */
896 if (record_full_core_buf_list)
897 {
898 for (entry = record_full_core_buf_list->prev; entry;
899 entry = entry->prev)
900 {
901 xfree (record_full_core_buf_list);
902 record_full_core_buf_list = entry;
903 }
904 record_full_core_buf_list = NULL;
905 }
906
907 if (record_full_async_inferior_event_token)
908 delete_async_event_handler (&record_full_async_inferior_event_token);
909 }
910
911 /* "to_async" target method. */
912
913 static void
914 record_full_async (struct target_ops *ops, int enable)
915 {
916 if (enable)
917 mark_async_event_handler (record_full_async_inferior_event_token);
918 else
919 clear_async_event_handler (record_full_async_inferior_event_token);
920
921 ops->beneath->to_async (ops->beneath, enable);
922 }
923
924 static int record_full_resume_step = 0;
925
926 /* True if we've been resumed, and so each record_full_wait call should
927 advance execution. If this is false, record_full_wait will return a
928 TARGET_WAITKIND_IGNORE. */
929 static int record_full_resumed = 0;
930
931 /* The execution direction of the last resume we got. This is
932 necessary for async mode. Vis (order is not strictly accurate):
933
934 1. user has the global execution direction set to forward
935 2. user does a reverse-step command
936 3. record_full_resume is called with global execution direction
937 temporarily switched to reverse
938 4. GDB's execution direction is reverted back to forward
939 5. target record notifies event loop there's an event to handle
940 6. infrun asks the target which direction was it going, and switches
941 the global execution direction accordingly (to reverse)
942 7. infrun polls an event out of the record target, and handles it
943 8. GDB goes back to the event loop, and goto #4.
944 */
945 static enum exec_direction_kind record_full_execution_dir = EXEC_FORWARD;
946
947 /* "to_resume" target method. Resume the process record target. */
948
949 static void
950 record_full_resume (struct target_ops *ops, ptid_t ptid, int step,
951 enum gdb_signal signal)
952 {
953 record_full_resume_step = step;
954 record_full_resumed = 1;
955 record_full_execution_dir = execution_direction;
956
957 if (!RECORD_FULL_IS_REPLAY)
958 {
959 struct gdbarch *gdbarch = target_thread_architecture (ptid);
960
961 record_full_message (get_current_regcache (), signal);
962
963 if (!step)
964 {
965 /* This is not hard single step. */
966 if (!gdbarch_software_single_step_p (gdbarch))
967 {
968 /* This is a normal continue. */
969 step = 1;
970 }
971 else
972 {
973 /* This arch supports soft single step. */
974 if (thread_has_single_step_breakpoints_set (inferior_thread ()))
975 {
976 /* This is a soft single step. */
977 record_full_resume_step = 1;
978 }
979 else
980 step = !insert_single_step_breakpoints (gdbarch);
981 }
982 }
983
984 /* Make sure the target beneath reports all signals. */
985 target_pass_signals (0, NULL);
986
987 ops->beneath->to_resume (ops->beneath, ptid, step, signal);
988 }
989
990 /* We are about to start executing the inferior (or simulate it),
991 let's register it with the event loop. */
992 if (target_can_async_p ())
993 target_async (1);
994 }
995
996 /* "to_commit_resume" method for process record target. */
997
998 static void
999 record_full_commit_resume (struct target_ops *ops)
1000 {
1001 if (!RECORD_FULL_IS_REPLAY)
1002 ops->beneath->to_commit_resume (ops->beneath);
1003 }
1004
1005 static int record_full_get_sig = 0;
1006
1007 /* SIGINT signal handler, registered by "to_wait" method. */
1008
1009 static void
1010 record_full_sig_handler (int signo)
1011 {
1012 if (record_debug)
1013 fprintf_unfiltered (gdb_stdlog, "Process record: get a signal\n");
1014
1015 /* It will break the running inferior in replay mode. */
1016 record_full_resume_step = 1;
1017
1018 /* It will let record_full_wait set inferior status to get the signal
1019 SIGINT. */
1020 record_full_get_sig = 1;
1021 }
1022
1023 static void
1024 record_full_wait_cleanups (void *ignore)
1025 {
1026 if (execution_direction == EXEC_REVERSE)
1027 {
1028 if (record_full_list->next)
1029 record_full_list = record_full_list->next;
1030 }
1031 else
1032 record_full_list = record_full_list->prev;
1033 }
1034
1035 /* "to_wait" target method for process record target.
1036
1037 In record mode, the target is always run in singlestep mode
1038 (even when gdb says to continue). The to_wait method intercepts
1039 the stop events and determines which ones are to be passed on to
1040 gdb. Most stop events are just singlestep events that gdb is not
1041 to know about, so the to_wait method just records them and keeps
1042 singlestepping.
1043
1044 In replay mode, this function emulates the recorded execution log,
1045 one instruction at a time (forward or backward), and determines
1046 where to stop. */
1047
1048 static ptid_t
1049 record_full_wait_1 (struct target_ops *ops,
1050 ptid_t ptid, struct target_waitstatus *status,
1051 int options)
1052 {
1053 struct cleanup *set_cleanups = record_full_gdb_operation_disable_set ();
1054
1055 if (record_debug)
1056 fprintf_unfiltered (gdb_stdlog,
1057 "Process record: record_full_wait "
1058 "record_full_resume_step = %d, "
1059 "record_full_resumed = %d, direction=%s\n",
1060 record_full_resume_step, record_full_resumed,
1061 record_full_execution_dir == EXEC_FORWARD
1062 ? "forward" : "reverse");
1063
1064 if (!record_full_resumed)
1065 {
1066 gdb_assert ((options & TARGET_WNOHANG) != 0);
1067
1068 /* No interesting event. */
1069 status->kind = TARGET_WAITKIND_IGNORE;
1070 return minus_one_ptid;
1071 }
1072
1073 record_full_get_sig = 0;
1074 signal (SIGINT, record_full_sig_handler);
1075
1076 record_full_stop_reason = TARGET_STOPPED_BY_NO_REASON;
1077
1078 if (!RECORD_FULL_IS_REPLAY && ops != &record_full_core_ops)
1079 {
1080 if (record_full_resume_step)
1081 {
1082 /* This is a single step. */
1083 return ops->beneath->to_wait (ops->beneath, ptid, status, options);
1084 }
1085 else
1086 {
1087 /* This is not a single step. */
1088 ptid_t ret;
1089 CORE_ADDR tmp_pc;
1090 struct gdbarch *gdbarch = target_thread_architecture (inferior_ptid);
1091
1092 while (1)
1093 {
1094 struct thread_info *tp;
1095
1096 ret = ops->beneath->to_wait (ops->beneath, ptid, status, options);
1097 if (status->kind == TARGET_WAITKIND_IGNORE)
1098 {
1099 if (record_debug)
1100 fprintf_unfiltered (gdb_stdlog,
1101 "Process record: record_full_wait "
1102 "target beneath not done yet\n");
1103 return ret;
1104 }
1105
1106 ALL_NON_EXITED_THREADS (tp)
1107 delete_single_step_breakpoints (tp);
1108
1109 if (record_full_resume_step)
1110 return ret;
1111
1112 /* Is this a SIGTRAP? */
1113 if (status->kind == TARGET_WAITKIND_STOPPED
1114 && status->value.sig == GDB_SIGNAL_TRAP)
1115 {
1116 struct regcache *regcache;
1117 struct address_space *aspace;
1118 enum target_stop_reason *stop_reason_p
1119 = &record_full_stop_reason;
1120
1121 /* Yes -- this is likely our single-step finishing,
1122 but check if there's any reason the core would be
1123 interested in the event. */
1124
1125 registers_changed ();
1126 regcache = get_current_regcache ();
1127 tmp_pc = regcache_read_pc (regcache);
1128 aspace = get_regcache_aspace (regcache);
1129
1130 if (target_stopped_by_watchpoint ())
1131 {
1132 /* Always interested in watchpoints. */
1133 }
1134 else if (record_check_stopped_by_breakpoint (aspace, tmp_pc,
1135 stop_reason_p))
1136 {
1137 /* There is a breakpoint here. Let the core
1138 handle it. */
1139 }
1140 else
1141 {
1142 /* This is a single-step trap. Record the
1143 insn and issue another step.
1144 FIXME: this part can be a random SIGTRAP too.
1145 But GDB cannot handle it. */
1146 int step = 1;
1147
1148 if (!record_full_message_wrapper_safe (regcache,
1149 GDB_SIGNAL_0))
1150 {
1151 status->kind = TARGET_WAITKIND_STOPPED;
1152 status->value.sig = GDB_SIGNAL_0;
1153 break;
1154 }
1155
1156 if (gdbarch_software_single_step_p (gdbarch))
1157 {
1158 /* Try to insert the software single step breakpoint.
1159 If insert success, set step to 0. */
1160 set_executing (inferior_ptid, 0);
1161 reinit_frame_cache ();
1162
1163 step = !insert_single_step_breakpoints (gdbarch);
1164
1165 set_executing (inferior_ptid, 1);
1166 }
1167
1168 if (record_debug)
1169 fprintf_unfiltered (gdb_stdlog,
1170 "Process record: record_full_wait "
1171 "issuing one more step in the "
1172 "target beneath\n");
1173 ops->beneath->to_resume (ops->beneath, ptid, step,
1174 GDB_SIGNAL_0);
1175 ops->beneath->to_commit_resume (ops->beneath);
1176 continue;
1177 }
1178 }
1179
1180 /* The inferior is broken by a breakpoint or a signal. */
1181 break;
1182 }
1183
1184 return ret;
1185 }
1186 }
1187 else
1188 {
1189 struct regcache *regcache = get_current_regcache ();
1190 struct gdbarch *gdbarch = get_regcache_arch (regcache);
1191 struct address_space *aspace = get_regcache_aspace (regcache);
1192 int continue_flag = 1;
1193 int first_record_full_end = 1;
1194 struct cleanup *old_cleanups
1195 = make_cleanup (record_full_wait_cleanups, 0);
1196 CORE_ADDR tmp_pc;
1197
1198 record_full_stop_reason = TARGET_STOPPED_BY_NO_REASON;
1199 status->kind = TARGET_WAITKIND_STOPPED;
1200
1201 /* Check breakpoint when forward execute. */
1202 if (execution_direction == EXEC_FORWARD)
1203 {
1204 tmp_pc = regcache_read_pc (regcache);
1205 if (record_check_stopped_by_breakpoint (aspace, tmp_pc,
1206 &record_full_stop_reason))
1207 {
1208 if (record_debug)
1209 fprintf_unfiltered (gdb_stdlog,
1210 "Process record: break at %s.\n",
1211 paddress (gdbarch, tmp_pc));
1212 goto replay_out;
1213 }
1214 }
1215
1216 /* If GDB is in terminal_inferior mode, it will not get the signal.
1217 And in GDB replay mode, GDB doesn't need to be in terminal_inferior
1218 mode, because inferior will not executed.
1219 Then set it to terminal_ours to make GDB get the signal. */
1220 target_terminal_ours ();
1221
1222 /* In EXEC_FORWARD mode, record_full_list points to the tail of prev
1223 instruction. */
1224 if (execution_direction == EXEC_FORWARD && record_full_list->next)
1225 record_full_list = record_full_list->next;
1226
1227 /* Loop over the record_full_list, looking for the next place to
1228 stop. */
1229 do
1230 {
1231 /* Check for beginning and end of log. */
1232 if (execution_direction == EXEC_REVERSE
1233 && record_full_list == &record_full_first)
1234 {
1235 /* Hit beginning of record log in reverse. */
1236 status->kind = TARGET_WAITKIND_NO_HISTORY;
1237 break;
1238 }
1239 if (execution_direction != EXEC_REVERSE && !record_full_list->next)
1240 {
1241 /* Hit end of record log going forward. */
1242 status->kind = TARGET_WAITKIND_NO_HISTORY;
1243 break;
1244 }
1245
1246 record_full_exec_insn (regcache, gdbarch, record_full_list);
1247
1248 if (record_full_list->type == record_full_end)
1249 {
1250 if (record_debug > 1)
1251 fprintf_unfiltered (gdb_stdlog,
1252 "Process record: record_full_end %s to "
1253 "inferior.\n",
1254 host_address_to_string (record_full_list));
1255
1256 if (first_record_full_end && execution_direction == EXEC_REVERSE)
1257 {
1258 /* When reverse excute, the first record_full_end is the
1259 part of current instruction. */
1260 first_record_full_end = 0;
1261 }
1262 else
1263 {
1264 /* In EXEC_REVERSE mode, this is the record_full_end of prev
1265 instruction.
1266 In EXEC_FORWARD mode, this is the record_full_end of
1267 current instruction. */
1268 /* step */
1269 if (record_full_resume_step)
1270 {
1271 if (record_debug > 1)
1272 fprintf_unfiltered (gdb_stdlog,
1273 "Process record: step.\n");
1274 continue_flag = 0;
1275 }
1276
1277 /* check breakpoint */
1278 tmp_pc = regcache_read_pc (regcache);
1279 if (record_check_stopped_by_breakpoint (aspace, tmp_pc,
1280 &record_full_stop_reason))
1281 {
1282 if (record_debug)
1283 fprintf_unfiltered (gdb_stdlog,
1284 "Process record: break "
1285 "at %s.\n",
1286 paddress (gdbarch, tmp_pc));
1287
1288 continue_flag = 0;
1289 }
1290
1291 if (record_full_stop_reason == TARGET_STOPPED_BY_WATCHPOINT)
1292 {
1293 if (record_debug)
1294 fprintf_unfiltered (gdb_stdlog,
1295 "Process record: hit hw "
1296 "watchpoint.\n");
1297 continue_flag = 0;
1298 }
1299 /* Check target signal */
1300 if (record_full_list->u.end.sigval != GDB_SIGNAL_0)
1301 /* FIXME: better way to check */
1302 continue_flag = 0;
1303 }
1304 }
1305
1306 if (continue_flag)
1307 {
1308 if (execution_direction == EXEC_REVERSE)
1309 {
1310 if (record_full_list->prev)
1311 record_full_list = record_full_list->prev;
1312 }
1313 else
1314 {
1315 if (record_full_list->next)
1316 record_full_list = record_full_list->next;
1317 }
1318 }
1319 }
1320 while (continue_flag);
1321
1322 replay_out:
1323 if (record_full_get_sig)
1324 status->value.sig = GDB_SIGNAL_INT;
1325 else if (record_full_list->u.end.sigval != GDB_SIGNAL_0)
1326 /* FIXME: better way to check */
1327 status->value.sig = record_full_list->u.end.sigval;
1328 else
1329 status->value.sig = GDB_SIGNAL_TRAP;
1330
1331 discard_cleanups (old_cleanups);
1332 }
1333
1334 signal (SIGINT, handle_sigint);
1335
1336 do_cleanups (set_cleanups);
1337 return inferior_ptid;
1338 }
1339
1340 static ptid_t
1341 record_full_wait (struct target_ops *ops,
1342 ptid_t ptid, struct target_waitstatus *status,
1343 int options)
1344 {
1345 ptid_t return_ptid;
1346
1347 return_ptid = record_full_wait_1 (ops, ptid, status, options);
1348 if (status->kind != TARGET_WAITKIND_IGNORE)
1349 {
1350 /* We're reporting a stop. Make sure any spurious
1351 target_wait(WNOHANG) doesn't advance the target until the
1352 core wants us resumed again. */
1353 record_full_resumed = 0;
1354 }
1355 return return_ptid;
1356 }
1357
1358 static int
1359 record_full_stopped_by_watchpoint (struct target_ops *ops)
1360 {
1361 if (RECORD_FULL_IS_REPLAY)
1362 return record_full_stop_reason == TARGET_STOPPED_BY_WATCHPOINT;
1363 else
1364 return ops->beneath->to_stopped_by_watchpoint (ops->beneath);
1365 }
1366
1367 static int
1368 record_full_stopped_data_address (struct target_ops *ops, CORE_ADDR *addr_p)
1369 {
1370 if (RECORD_FULL_IS_REPLAY)
1371 return 0;
1372 else
1373 return ops->beneath->to_stopped_data_address (ops->beneath, addr_p);
1374 }
1375
1376 /* The to_stopped_by_sw_breakpoint method of target record-full. */
1377
1378 static int
1379 record_full_stopped_by_sw_breakpoint (struct target_ops *ops)
1380 {
1381 return record_full_stop_reason == TARGET_STOPPED_BY_SW_BREAKPOINT;
1382 }
1383
1384 /* The to_supports_stopped_by_sw_breakpoint method of target
1385 record-full. */
1386
1387 static int
1388 record_full_supports_stopped_by_sw_breakpoint (struct target_ops *ops)
1389 {
1390 return 1;
1391 }
1392
1393 /* The to_stopped_by_hw_breakpoint method of target record-full. */
1394
1395 static int
1396 record_full_stopped_by_hw_breakpoint (struct target_ops *ops)
1397 {
1398 return record_full_stop_reason == TARGET_STOPPED_BY_HW_BREAKPOINT;
1399 }
1400
1401 /* The to_supports_stopped_by_sw_breakpoint method of target
1402 record-full. */
1403
1404 static int
1405 record_full_supports_stopped_by_hw_breakpoint (struct target_ops *ops)
1406 {
1407 return 1;
1408 }
1409
1410 /* Record registers change (by user or by GDB) to list as an instruction. */
1411
1412 static void
1413 record_full_registers_change (struct regcache *regcache, int regnum)
1414 {
1415 /* Check record_full_insn_num. */
1416 record_full_check_insn_num ();
1417
1418 record_full_arch_list_head = NULL;
1419 record_full_arch_list_tail = NULL;
1420
1421 if (regnum < 0)
1422 {
1423 int i;
1424
1425 for (i = 0; i < gdbarch_num_regs (get_regcache_arch (regcache)); i++)
1426 {
1427 if (record_full_arch_list_add_reg (regcache, i))
1428 {
1429 record_full_list_release (record_full_arch_list_tail);
1430 error (_("Process record: failed to record execution log."));
1431 }
1432 }
1433 }
1434 else
1435 {
1436 if (record_full_arch_list_add_reg (regcache, regnum))
1437 {
1438 record_full_list_release (record_full_arch_list_tail);
1439 error (_("Process record: failed to record execution log."));
1440 }
1441 }
1442 if (record_full_arch_list_add_end ())
1443 {
1444 record_full_list_release (record_full_arch_list_tail);
1445 error (_("Process record: failed to record execution log."));
1446 }
1447 record_full_list->next = record_full_arch_list_head;
1448 record_full_arch_list_head->prev = record_full_list;
1449 record_full_list = record_full_arch_list_tail;
1450
1451 if (record_full_insn_num == record_full_insn_max_num)
1452 record_full_list_release_first ();
1453 else
1454 record_full_insn_num++;
1455 }
1456
1457 /* "to_store_registers" method for process record target. */
1458
1459 static void
1460 record_full_store_registers (struct target_ops *ops,
1461 struct regcache *regcache,
1462 int regno)
1463 {
1464 if (!record_full_gdb_operation_disable)
1465 {
1466 if (RECORD_FULL_IS_REPLAY)
1467 {
1468 int n;
1469
1470 /* Let user choose if he wants to write register or not. */
1471 if (regno < 0)
1472 n =
1473 query (_("Because GDB is in replay mode, changing the "
1474 "value of a register will make the execution "
1475 "log unusable from this point onward. "
1476 "Change all registers?"));
1477 else
1478 n =
1479 query (_("Because GDB is in replay mode, changing the value "
1480 "of a register will make the execution log unusable "
1481 "from this point onward. Change register %s?"),
1482 gdbarch_register_name (get_regcache_arch (regcache),
1483 regno));
1484
1485 if (!n)
1486 {
1487 /* Invalidate the value of regcache that was set in function
1488 "regcache_raw_write". */
1489 if (regno < 0)
1490 {
1491 int i;
1492
1493 for (i = 0;
1494 i < gdbarch_num_regs (get_regcache_arch (regcache));
1495 i++)
1496 regcache_invalidate (regcache, i);
1497 }
1498 else
1499 regcache_invalidate (regcache, regno);
1500
1501 error (_("Process record canceled the operation."));
1502 }
1503
1504 /* Destroy the record from here forward. */
1505 record_full_list_release_following (record_full_list);
1506 }
1507
1508 record_full_registers_change (regcache, regno);
1509 }
1510 ops->beneath->to_store_registers (ops->beneath, regcache, regno);
1511 }
1512
1513 /* "to_xfer_partial" method. Behavior is conditional on
1514 RECORD_FULL_IS_REPLAY.
1515 In replay mode, we cannot write memory unles we are willing to
1516 invalidate the record/replay log from this point forward. */
1517
1518 static enum target_xfer_status
1519 record_full_xfer_partial (struct target_ops *ops, enum target_object object,
1520 const char *annex, gdb_byte *readbuf,
1521 const gdb_byte *writebuf, ULONGEST offset,
1522 ULONGEST len, ULONGEST *xfered_len)
1523 {
1524 if (!record_full_gdb_operation_disable
1525 && (object == TARGET_OBJECT_MEMORY
1526 || object == TARGET_OBJECT_RAW_MEMORY) && writebuf)
1527 {
1528 if (RECORD_FULL_IS_REPLAY)
1529 {
1530 /* Let user choose if he wants to write memory or not. */
1531 if (!query (_("Because GDB is in replay mode, writing to memory "
1532 "will make the execution log unusable from this "
1533 "point onward. Write memory at address %s?"),
1534 paddress (target_gdbarch (), offset)))
1535 error (_("Process record canceled the operation."));
1536
1537 /* Destroy the record from here forward. */
1538 record_full_list_release_following (record_full_list);
1539 }
1540
1541 /* Check record_full_insn_num */
1542 record_full_check_insn_num ();
1543
1544 /* Record registers change to list as an instruction. */
1545 record_full_arch_list_head = NULL;
1546 record_full_arch_list_tail = NULL;
1547 if (record_full_arch_list_add_mem (offset, len))
1548 {
1549 record_full_list_release (record_full_arch_list_tail);
1550 if (record_debug)
1551 fprintf_unfiltered (gdb_stdlog,
1552 "Process record: failed to record "
1553 "execution log.");
1554 return TARGET_XFER_E_IO;
1555 }
1556 if (record_full_arch_list_add_end ())
1557 {
1558 record_full_list_release (record_full_arch_list_tail);
1559 if (record_debug)
1560 fprintf_unfiltered (gdb_stdlog,
1561 "Process record: failed to record "
1562 "execution log.");
1563 return TARGET_XFER_E_IO;
1564 }
1565 record_full_list->next = record_full_arch_list_head;
1566 record_full_arch_list_head->prev = record_full_list;
1567 record_full_list = record_full_arch_list_tail;
1568
1569 if (record_full_insn_num == record_full_insn_max_num)
1570 record_full_list_release_first ();
1571 else
1572 record_full_insn_num++;
1573 }
1574
1575 return ops->beneath->to_xfer_partial (ops->beneath, object, annex,
1576 readbuf, writebuf, offset,
1577 len, xfered_len);
1578 }
1579
1580 /* This structure represents a breakpoint inserted while the record
1581 target is active. We use this to know when to install/remove
1582 breakpoints in/from the target beneath. For example, a breakpoint
1583 may be inserted while recording, but removed when not replaying nor
1584 recording. In that case, the breakpoint had not been inserted on
1585 the target beneath, so we should not try to remove it there. */
1586
1587 struct record_full_breakpoint
1588 {
1589 /* The address and address space the breakpoint was set at. */
1590 struct address_space *address_space;
1591 CORE_ADDR addr;
1592
1593 /* True when the breakpoint has been also installed in the target
1594 beneath. This will be false for breakpoints set during replay or
1595 when recording. */
1596 int in_target_beneath;
1597 };
1598
1599 typedef struct record_full_breakpoint *record_full_breakpoint_p;
1600 DEF_VEC_P(record_full_breakpoint_p);
1601
1602 /* The list of breakpoints inserted while the record target is
1603 active. */
1604 VEC(record_full_breakpoint_p) *record_full_breakpoints = NULL;
1605
1606 static void
1607 record_full_sync_record_breakpoints (struct bp_location *loc, void *data)
1608 {
1609 if (loc->loc_type != bp_loc_software_breakpoint)
1610 return;
1611
1612 if (loc->inserted)
1613 {
1614 struct record_full_breakpoint *bp = XNEW (struct record_full_breakpoint);
1615
1616 bp->addr = loc->target_info.placed_address;
1617 bp->address_space = loc->target_info.placed_address_space;
1618
1619 bp->in_target_beneath = 1;
1620
1621 VEC_safe_push (record_full_breakpoint_p, record_full_breakpoints, bp);
1622 }
1623 }
1624
1625 /* Sync existing breakpoints to record_full_breakpoints. */
1626
1627 static void
1628 record_full_init_record_breakpoints (void)
1629 {
1630 VEC_free (record_full_breakpoint_p, record_full_breakpoints);
1631
1632 iterate_over_bp_locations (record_full_sync_record_breakpoints);
1633 }
1634
1635 /* Behavior is conditional on RECORD_FULL_IS_REPLAY. We will not actually
1636 insert or remove breakpoints in the real target when replaying, nor
1637 when recording. */
1638
1639 static int
1640 record_full_insert_breakpoint (struct target_ops *ops,
1641 struct gdbarch *gdbarch,
1642 struct bp_target_info *bp_tgt)
1643 {
1644 struct record_full_breakpoint *bp;
1645 int in_target_beneath = 0;
1646 int ix;
1647
1648 if (!RECORD_FULL_IS_REPLAY)
1649 {
1650 /* When recording, we currently always single-step, so we don't
1651 really need to install regular breakpoints in the inferior.
1652 However, we do have to insert software single-step
1653 breakpoints, in case the target can't hardware step. To keep
1654 things simple, we always insert. */
1655 struct cleanup *old_cleanups;
1656 int ret;
1657
1658 old_cleanups = record_full_gdb_operation_disable_set ();
1659 ret = ops->beneath->to_insert_breakpoint (ops->beneath, gdbarch, bp_tgt);
1660 do_cleanups (old_cleanups);
1661
1662 if (ret != 0)
1663 return ret;
1664
1665 in_target_beneath = 1;
1666 }
1667
1668 /* Use the existing entries if found in order to avoid duplication
1669 in record_full_breakpoints. */
1670
1671 for (ix = 0;
1672 VEC_iterate (record_full_breakpoint_p,
1673 record_full_breakpoints, ix, bp);
1674 ++ix)
1675 {
1676 if (bp->addr == bp_tgt->placed_address
1677 && bp->address_space == bp_tgt->placed_address_space)
1678 {
1679 gdb_assert (bp->in_target_beneath == in_target_beneath);
1680 return 0;
1681 }
1682 }
1683
1684 bp = XNEW (struct record_full_breakpoint);
1685 bp->addr = bp_tgt->placed_address;
1686 bp->address_space = bp_tgt->placed_address_space;
1687 bp->in_target_beneath = in_target_beneath;
1688 VEC_safe_push (record_full_breakpoint_p, record_full_breakpoints, bp);
1689 return 0;
1690 }
1691
1692 /* "to_remove_breakpoint" method for process record target. */
1693
1694 static int
1695 record_full_remove_breakpoint (struct target_ops *ops,
1696 struct gdbarch *gdbarch,
1697 struct bp_target_info *bp_tgt,
1698 enum remove_bp_reason reason)
1699 {
1700 struct record_full_breakpoint *bp;
1701 int ix;
1702
1703 for (ix = 0;
1704 VEC_iterate (record_full_breakpoint_p,
1705 record_full_breakpoints, ix, bp);
1706 ++ix)
1707 {
1708 if (bp->addr == bp_tgt->placed_address
1709 && bp->address_space == bp_tgt->placed_address_space)
1710 {
1711 if (bp->in_target_beneath)
1712 {
1713 struct cleanup *old_cleanups;
1714 int ret;
1715
1716 old_cleanups = record_full_gdb_operation_disable_set ();
1717 ret = ops->beneath->to_remove_breakpoint (ops->beneath, gdbarch,
1718 bp_tgt, reason);
1719 do_cleanups (old_cleanups);
1720
1721 if (ret != 0)
1722 return ret;
1723 }
1724
1725 if (reason == REMOVE_BREAKPOINT)
1726 {
1727 VEC_unordered_remove (record_full_breakpoint_p,
1728 record_full_breakpoints, ix);
1729 }
1730 return 0;
1731 }
1732 }
1733
1734 gdb_assert_not_reached ("removing unknown breakpoint");
1735 }
1736
1737 /* "to_can_execute_reverse" method for process record target. */
1738
1739 static int
1740 record_full_can_execute_reverse (struct target_ops *self)
1741 {
1742 return 1;
1743 }
1744
1745 /* "to_get_bookmark" method for process record and prec over core. */
1746
1747 static gdb_byte *
1748 record_full_get_bookmark (struct target_ops *self, const char *args,
1749 int from_tty)
1750 {
1751 char *ret = NULL;
1752
1753 /* Return stringified form of instruction count. */
1754 if (record_full_list && record_full_list->type == record_full_end)
1755 ret = xstrdup (pulongest (record_full_list->u.end.insn_num));
1756
1757 if (record_debug)
1758 {
1759 if (ret)
1760 fprintf_unfiltered (gdb_stdlog,
1761 "record_full_get_bookmark returns %s\n", ret);
1762 else
1763 fprintf_unfiltered (gdb_stdlog,
1764 "record_full_get_bookmark returns NULL\n");
1765 }
1766 return (gdb_byte *) ret;
1767 }
1768
1769 /* "to_goto_bookmark" method for process record and prec over core. */
1770
1771 static void
1772 record_full_goto_bookmark (struct target_ops *self,
1773 const gdb_byte *raw_bookmark, int from_tty)
1774 {
1775 const char *bookmark = (const char *) raw_bookmark;
1776 struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
1777
1778 if (record_debug)
1779 fprintf_unfiltered (gdb_stdlog,
1780 "record_full_goto_bookmark receives %s\n", bookmark);
1781
1782 if (bookmark[0] == '\'' || bookmark[0] == '\"')
1783 {
1784 char *copy;
1785
1786 if (bookmark[strlen (bookmark) - 1] != bookmark[0])
1787 error (_("Unbalanced quotes: %s"), bookmark);
1788
1789
1790 copy = savestring (bookmark + 1, strlen (bookmark) - 2);
1791 make_cleanup (xfree, copy);
1792 bookmark = copy;
1793 }
1794
1795 record_goto (bookmark);
1796
1797 do_cleanups (cleanup);
1798 }
1799
1800 static enum exec_direction_kind
1801 record_full_execution_direction (struct target_ops *self)
1802 {
1803 return record_full_execution_dir;
1804 }
1805
1806 static void
1807 record_full_info (struct target_ops *self)
1808 {
1809 struct record_full_entry *p;
1810
1811 if (RECORD_FULL_IS_REPLAY)
1812 printf_filtered (_("Replay mode:\n"));
1813 else
1814 printf_filtered (_("Record mode:\n"));
1815
1816 /* Find entry for first actual instruction in the log. */
1817 for (p = record_full_first.next;
1818 p != NULL && p->type != record_full_end;
1819 p = p->next)
1820 ;
1821
1822 /* Do we have a log at all? */
1823 if (p != NULL && p->type == record_full_end)
1824 {
1825 /* Display instruction number for first instruction in the log. */
1826 printf_filtered (_("Lowest recorded instruction number is %s.\n"),
1827 pulongest (p->u.end.insn_num));
1828
1829 /* If in replay mode, display where we are in the log. */
1830 if (RECORD_FULL_IS_REPLAY)
1831 printf_filtered (_("Current instruction number is %s.\n"),
1832 pulongest (record_full_list->u.end.insn_num));
1833
1834 /* Display instruction number for last instruction in the log. */
1835 printf_filtered (_("Highest recorded instruction number is %s.\n"),
1836 pulongest (record_full_insn_count));
1837
1838 /* Display log count. */
1839 printf_filtered (_("Log contains %u instructions.\n"),
1840 record_full_insn_num);
1841 }
1842 else
1843 printf_filtered (_("No instructions have been logged.\n"));
1844
1845 /* Display max log size. */
1846 printf_filtered (_("Max logged instructions is %u.\n"),
1847 record_full_insn_max_num);
1848 }
1849
1850 /* The "to_record_delete" target method. */
1851
1852 static void
1853 record_full_delete (struct target_ops *self)
1854 {
1855 record_full_list_release_following (record_full_list);
1856 }
1857
1858 /* The "to_record_is_replaying" target method. */
1859
1860 static int
1861 record_full_is_replaying (struct target_ops *self, ptid_t ptid)
1862 {
1863 return RECORD_FULL_IS_REPLAY;
1864 }
1865
1866 /* The "to_record_will_replay" target method. */
1867
1868 static int
1869 record_full_will_replay (struct target_ops *self, ptid_t ptid, int dir)
1870 {
1871 /* We can currently only record when executing forwards. Should we be able
1872 to record when executing backwards on targets that support reverse
1873 execution, this needs to be changed. */
1874
1875 return RECORD_FULL_IS_REPLAY || dir == EXEC_REVERSE;
1876 }
1877
1878 /* Go to a specific entry. */
1879
1880 static void
1881 record_full_goto_entry (struct record_full_entry *p)
1882 {
1883 if (p == NULL)
1884 error (_("Target insn not found."));
1885 else if (p == record_full_list)
1886 error (_("Already at target insn."));
1887 else if (p->u.end.insn_num > record_full_list->u.end.insn_num)
1888 {
1889 printf_filtered (_("Go forward to insn number %s\n"),
1890 pulongest (p->u.end.insn_num));
1891 record_full_goto_insn (p, EXEC_FORWARD);
1892 }
1893 else
1894 {
1895 printf_filtered (_("Go backward to insn number %s\n"),
1896 pulongest (p->u.end.insn_num));
1897 record_full_goto_insn (p, EXEC_REVERSE);
1898 }
1899
1900 registers_changed ();
1901 reinit_frame_cache ();
1902 stop_pc = regcache_read_pc (get_current_regcache ());
1903 print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1);
1904 }
1905
1906 /* The "to_goto_record_begin" target method. */
1907
1908 static void
1909 record_full_goto_begin (struct target_ops *self)
1910 {
1911 struct record_full_entry *p = NULL;
1912
1913 for (p = &record_full_first; p != NULL; p = p->next)
1914 if (p->type == record_full_end)
1915 break;
1916
1917 record_full_goto_entry (p);
1918 }
1919
1920 /* The "to_goto_record_end" target method. */
1921
1922 static void
1923 record_full_goto_end (struct target_ops *self)
1924 {
1925 struct record_full_entry *p = NULL;
1926
1927 for (p = record_full_list; p->next != NULL; p = p->next)
1928 ;
1929 for (; p!= NULL; p = p->prev)
1930 if (p->type == record_full_end)
1931 break;
1932
1933 record_full_goto_entry (p);
1934 }
1935
1936 /* The "to_goto_record" target method. */
1937
1938 static void
1939 record_full_goto (struct target_ops *self, ULONGEST target_insn)
1940 {
1941 struct record_full_entry *p = NULL;
1942
1943 for (p = &record_full_first; p != NULL; p = p->next)
1944 if (p->type == record_full_end && p->u.end.insn_num == target_insn)
1945 break;
1946
1947 record_full_goto_entry (p);
1948 }
1949
1950 /* The "to_record_stop_replaying" target method. */
1951
1952 static void
1953 record_full_stop_replaying (struct target_ops *self)
1954 {
1955 record_full_goto_end (self);
1956 }
1957
1958 static void
1959 init_record_full_ops (void)
1960 {
1961 record_full_ops.to_shortname = "record-full";
1962 record_full_ops.to_longname = "Process record and replay target";
1963 record_full_ops.to_doc =
1964 "Log program while executing and replay execution from log.";
1965 record_full_ops.to_open = record_full_open;
1966 record_full_ops.to_close = record_full_close;
1967 record_full_ops.to_async = record_full_async;
1968 record_full_ops.to_resume = record_full_resume;
1969 record_full_ops.to_commit_resume = record_full_commit_resume;
1970 record_full_ops.to_wait = record_full_wait;
1971 record_full_ops.to_disconnect = record_disconnect;
1972 record_full_ops.to_detach = record_detach;
1973 record_full_ops.to_mourn_inferior = record_mourn_inferior;
1974 record_full_ops.to_kill = record_kill;
1975 record_full_ops.to_store_registers = record_full_store_registers;
1976 record_full_ops.to_xfer_partial = record_full_xfer_partial;
1977 record_full_ops.to_insert_breakpoint = record_full_insert_breakpoint;
1978 record_full_ops.to_remove_breakpoint = record_full_remove_breakpoint;
1979 record_full_ops.to_stopped_by_watchpoint = record_full_stopped_by_watchpoint;
1980 record_full_ops.to_stopped_data_address = record_full_stopped_data_address;
1981 record_full_ops.to_stopped_by_sw_breakpoint
1982 = record_full_stopped_by_sw_breakpoint;
1983 record_full_ops.to_supports_stopped_by_sw_breakpoint
1984 = record_full_supports_stopped_by_sw_breakpoint;
1985 record_full_ops.to_stopped_by_hw_breakpoint
1986 = record_full_stopped_by_hw_breakpoint;
1987 record_full_ops.to_supports_stopped_by_hw_breakpoint
1988 = record_full_supports_stopped_by_hw_breakpoint;
1989 record_full_ops.to_can_execute_reverse = record_full_can_execute_reverse;
1990 record_full_ops.to_stratum = record_stratum;
1991 /* Add bookmark target methods. */
1992 record_full_ops.to_get_bookmark = record_full_get_bookmark;
1993 record_full_ops.to_goto_bookmark = record_full_goto_bookmark;
1994 record_full_ops.to_execution_direction = record_full_execution_direction;
1995 record_full_ops.to_info_record = record_full_info;
1996 record_full_ops.to_save_record = record_full_save;
1997 record_full_ops.to_delete_record = record_full_delete;
1998 record_full_ops.to_record_is_replaying = record_full_is_replaying;
1999 record_full_ops.to_record_will_replay = record_full_will_replay;
2000 record_full_ops.to_record_stop_replaying = record_full_stop_replaying;
2001 record_full_ops.to_goto_record_begin = record_full_goto_begin;
2002 record_full_ops.to_goto_record_end = record_full_goto_end;
2003 record_full_ops.to_goto_record = record_full_goto;
2004 record_full_ops.to_magic = OPS_MAGIC;
2005 }
2006
2007 /* "to_resume" method for prec over corefile. */
2008
2009 static void
2010 record_full_core_resume (struct target_ops *ops, ptid_t ptid, int step,
2011 enum gdb_signal signal)
2012 {
2013 record_full_resume_step = step;
2014 record_full_resumed = 1;
2015 record_full_execution_dir = execution_direction;
2016
2017 /* We are about to start executing the inferior (or simulate it),
2018 let's register it with the event loop. */
2019 if (target_can_async_p ())
2020 target_async (1);
2021 }
2022
2023 /* "to_kill" method for prec over corefile. */
2024
2025 static void
2026 record_full_core_kill (struct target_ops *ops)
2027 {
2028 if (record_debug)
2029 fprintf_unfiltered (gdb_stdlog, "Process record: record_full_core_kill\n");
2030
2031 unpush_target (&record_full_core_ops);
2032 }
2033
2034 /* "to_fetch_registers" method for prec over corefile. */
2035
2036 static void
2037 record_full_core_fetch_registers (struct target_ops *ops,
2038 struct regcache *regcache,
2039 int regno)
2040 {
2041 if (regno < 0)
2042 {
2043 int num = gdbarch_num_regs (get_regcache_arch (regcache));
2044 int i;
2045
2046 for (i = 0; i < num; i ++)
2047 regcache_raw_supply (regcache, i,
2048 record_full_core_regbuf + MAX_REGISTER_SIZE * i);
2049 }
2050 else
2051 regcache_raw_supply (regcache, regno,
2052 record_full_core_regbuf + MAX_REGISTER_SIZE * regno);
2053 }
2054
2055 /* "to_prepare_to_store" method for prec over corefile. */
2056
2057 static void
2058 record_full_core_prepare_to_store (struct target_ops *self,
2059 struct regcache *regcache)
2060 {
2061 }
2062
2063 /* "to_store_registers" method for prec over corefile. */
2064
2065 static void
2066 record_full_core_store_registers (struct target_ops *ops,
2067 struct regcache *regcache,
2068 int regno)
2069 {
2070 if (record_full_gdb_operation_disable)
2071 regcache_raw_collect (regcache, regno,
2072 record_full_core_regbuf + MAX_REGISTER_SIZE * regno);
2073 else
2074 error (_("You can't do that without a process to debug."));
2075 }
2076
2077 /* "to_xfer_partial" method for prec over corefile. */
2078
2079 static enum target_xfer_status
2080 record_full_core_xfer_partial (struct target_ops *ops,
2081 enum target_object object,
2082 const char *annex, gdb_byte *readbuf,
2083 const gdb_byte *writebuf, ULONGEST offset,
2084 ULONGEST len, ULONGEST *xfered_len)
2085 {
2086 if (object == TARGET_OBJECT_MEMORY)
2087 {
2088 if (record_full_gdb_operation_disable || !writebuf)
2089 {
2090 struct target_section *p;
2091
2092 for (p = record_full_core_start; p < record_full_core_end; p++)
2093 {
2094 if (offset >= p->addr)
2095 {
2096 struct record_full_core_buf_entry *entry;
2097 ULONGEST sec_offset;
2098
2099 if (offset >= p->endaddr)
2100 continue;
2101
2102 if (offset + len > p->endaddr)
2103 len = p->endaddr - offset;
2104
2105 sec_offset = offset - p->addr;
2106
2107 /* Read readbuf or write writebuf p, offset, len. */
2108 /* Check flags. */
2109 if (p->the_bfd_section->flags & SEC_CONSTRUCTOR
2110 || (p->the_bfd_section->flags & SEC_HAS_CONTENTS) == 0)
2111 {
2112 if (readbuf)
2113 memset (readbuf, 0, len);
2114
2115 *xfered_len = len;
2116 return TARGET_XFER_OK;
2117 }
2118 /* Get record_full_core_buf_entry. */
2119 for (entry = record_full_core_buf_list; entry;
2120 entry = entry->prev)
2121 if (entry->p == p)
2122 break;
2123 if (writebuf)
2124 {
2125 if (!entry)
2126 {
2127 /* Add a new entry. */
2128 entry = XNEW (struct record_full_core_buf_entry);
2129 entry->p = p;
2130 if (!bfd_malloc_and_get_section
2131 (p->the_bfd_section->owner,
2132 p->the_bfd_section,
2133 &entry->buf))
2134 {
2135 xfree (entry);
2136 return TARGET_XFER_EOF;
2137 }
2138 entry->prev = record_full_core_buf_list;
2139 record_full_core_buf_list = entry;
2140 }
2141
2142 memcpy (entry->buf + sec_offset, writebuf,
2143 (size_t) len);
2144 }
2145 else
2146 {
2147 if (!entry)
2148 return ops->beneath->to_xfer_partial (ops->beneath,
2149 object, annex,
2150 readbuf, writebuf,
2151 offset, len,
2152 xfered_len);
2153
2154 memcpy (readbuf, entry->buf + sec_offset,
2155 (size_t) len);
2156 }
2157
2158 *xfered_len = len;
2159 return TARGET_XFER_OK;
2160 }
2161 }
2162
2163 return TARGET_XFER_E_IO;
2164 }
2165 else
2166 error (_("You can't do that without a process to debug."));
2167 }
2168
2169 return ops->beneath->to_xfer_partial (ops->beneath, object, annex,
2170 readbuf, writebuf, offset, len,
2171 xfered_len);
2172 }
2173
2174 /* "to_insert_breakpoint" method for prec over corefile. */
2175
2176 static int
2177 record_full_core_insert_breakpoint (struct target_ops *ops,
2178 struct gdbarch *gdbarch,
2179 struct bp_target_info *bp_tgt)
2180 {
2181 return 0;
2182 }
2183
2184 /* "to_remove_breakpoint" method for prec over corefile. */
2185
2186 static int
2187 record_full_core_remove_breakpoint (struct target_ops *ops,
2188 struct gdbarch *gdbarch,
2189 struct bp_target_info *bp_tgt,
2190 enum remove_bp_reason reason)
2191 {
2192 return 0;
2193 }
2194
2195 /* "to_has_execution" method for prec over corefile. */
2196
2197 static int
2198 record_full_core_has_execution (struct target_ops *ops, ptid_t the_ptid)
2199 {
2200 return 1;
2201 }
2202
2203 static void
2204 init_record_full_core_ops (void)
2205 {
2206 record_full_core_ops.to_shortname = "record-core";
2207 record_full_core_ops.to_longname = "Process record and replay target";
2208 record_full_core_ops.to_doc =
2209 "Log program while executing and replay execution from log.";
2210 record_full_core_ops.to_open = record_full_open;
2211 record_full_core_ops.to_close = record_full_close;
2212 record_full_core_ops.to_async = record_full_async;
2213 record_full_core_ops.to_resume = record_full_core_resume;
2214 record_full_core_ops.to_wait = record_full_wait;
2215 record_full_core_ops.to_kill = record_full_core_kill;
2216 record_full_core_ops.to_fetch_registers = record_full_core_fetch_registers;
2217 record_full_core_ops.to_prepare_to_store = record_full_core_prepare_to_store;
2218 record_full_core_ops.to_store_registers = record_full_core_store_registers;
2219 record_full_core_ops.to_xfer_partial = record_full_core_xfer_partial;
2220 record_full_core_ops.to_insert_breakpoint
2221 = record_full_core_insert_breakpoint;
2222 record_full_core_ops.to_remove_breakpoint
2223 = record_full_core_remove_breakpoint;
2224 record_full_core_ops.to_stopped_by_watchpoint
2225 = record_full_stopped_by_watchpoint;
2226 record_full_core_ops.to_stopped_data_address
2227 = record_full_stopped_data_address;
2228 record_full_core_ops.to_stopped_by_sw_breakpoint
2229 = record_full_stopped_by_sw_breakpoint;
2230 record_full_core_ops.to_supports_stopped_by_sw_breakpoint
2231 = record_full_supports_stopped_by_sw_breakpoint;
2232 record_full_core_ops.to_stopped_by_hw_breakpoint
2233 = record_full_stopped_by_hw_breakpoint;
2234 record_full_core_ops.to_supports_stopped_by_hw_breakpoint
2235 = record_full_supports_stopped_by_hw_breakpoint;
2236 record_full_core_ops.to_can_execute_reverse
2237 = record_full_can_execute_reverse;
2238 record_full_core_ops.to_has_execution = record_full_core_has_execution;
2239 record_full_core_ops.to_stratum = record_stratum;
2240 /* Add bookmark target methods. */
2241 record_full_core_ops.to_get_bookmark = record_full_get_bookmark;
2242 record_full_core_ops.to_goto_bookmark = record_full_goto_bookmark;
2243 record_full_core_ops.to_execution_direction
2244 = record_full_execution_direction;
2245 record_full_core_ops.to_info_record = record_full_info;
2246 record_full_core_ops.to_delete_record = record_full_delete;
2247 record_full_core_ops.to_record_is_replaying = record_full_is_replaying;
2248 record_full_core_ops.to_record_will_replay = record_full_will_replay;
2249 record_full_core_ops.to_goto_record_begin = record_full_goto_begin;
2250 record_full_core_ops.to_goto_record_end = record_full_goto_end;
2251 record_full_core_ops.to_goto_record = record_full_goto;
2252 record_full_core_ops.to_magic = OPS_MAGIC;
2253 }
2254
2255 /* Record log save-file format
2256 Version 1 (never released)
2257
2258 Header:
2259 4 bytes: magic number htonl(0x20090829).
2260 NOTE: be sure to change whenever this file format changes!
2261
2262 Records:
2263 record_full_end:
2264 1 byte: record type (record_full_end, see enum record_full_type).
2265 record_full_reg:
2266 1 byte: record type (record_full_reg, see enum record_full_type).
2267 8 bytes: register id (network byte order).
2268 MAX_REGISTER_SIZE bytes: register value.
2269 record_full_mem:
2270 1 byte: record type (record_full_mem, see enum record_full_type).
2271 8 bytes: memory length (network byte order).
2272 8 bytes: memory address (network byte order).
2273 n bytes: memory value (n == memory length).
2274
2275 Version 2
2276 4 bytes: magic number netorder32(0x20091016).
2277 NOTE: be sure to change whenever this file format changes!
2278
2279 Records:
2280 record_full_end:
2281 1 byte: record type (record_full_end, see enum record_full_type).
2282 4 bytes: signal
2283 4 bytes: instruction count
2284 record_full_reg:
2285 1 byte: record type (record_full_reg, see enum record_full_type).
2286 4 bytes: register id (network byte order).
2287 n bytes: register value (n == actual register size).
2288 (eg. 4 bytes for x86 general registers).
2289 record_full_mem:
2290 1 byte: record type (record_full_mem, see enum record_full_type).
2291 4 bytes: memory length (network byte order).
2292 8 bytes: memory address (network byte order).
2293 n bytes: memory value (n == memory length).
2294
2295 */
2296
2297 /* bfdcore_read -- read bytes from a core file section. */
2298
2299 static inline void
2300 bfdcore_read (bfd *obfd, asection *osec, void *buf, int len, int *offset)
2301 {
2302 int ret = bfd_get_section_contents (obfd, osec, buf, *offset, len);
2303
2304 if (ret)
2305 *offset += len;
2306 else
2307 error (_("Failed to read %d bytes from core file %s ('%s')."),
2308 len, bfd_get_filename (obfd),
2309 bfd_errmsg (bfd_get_error ()));
2310 }
2311
2312 static inline uint64_t
2313 netorder64 (uint64_t input)
2314 {
2315 uint64_t ret;
2316
2317 store_unsigned_integer ((gdb_byte *) &ret, sizeof (ret),
2318 BFD_ENDIAN_BIG, input);
2319 return ret;
2320 }
2321
2322 static inline uint32_t
2323 netorder32 (uint32_t input)
2324 {
2325 uint32_t ret;
2326
2327 store_unsigned_integer ((gdb_byte *) &ret, sizeof (ret),
2328 BFD_ENDIAN_BIG, input);
2329 return ret;
2330 }
2331
2332 static inline uint16_t
2333 netorder16 (uint16_t input)
2334 {
2335 uint16_t ret;
2336
2337 store_unsigned_integer ((gdb_byte *) &ret, sizeof (ret),
2338 BFD_ENDIAN_BIG, input);
2339 return ret;
2340 }
2341
2342 /* Restore the execution log from a core_bfd file. */
2343 static void
2344 record_full_restore (void)
2345 {
2346 uint32_t magic;
2347 struct cleanup *old_cleanups;
2348 struct record_full_entry *rec;
2349 asection *osec;
2350 uint32_t osec_size;
2351 int bfd_offset = 0;
2352 struct regcache *regcache;
2353
2354 /* We restore the execution log from the open core bfd,
2355 if there is one. */
2356 if (core_bfd == NULL)
2357 return;
2358
2359 /* "record_full_restore" can only be called when record list is empty. */
2360 gdb_assert (record_full_first.next == NULL);
2361
2362 if (record_debug)
2363 fprintf_unfiltered (gdb_stdlog, "Restoring recording from core file.\n");
2364
2365 /* Now need to find our special note section. */
2366 osec = bfd_get_section_by_name (core_bfd, "null0");
2367 if (record_debug)
2368 fprintf_unfiltered (gdb_stdlog, "Find precord section %s.\n",
2369 osec ? "succeeded" : "failed");
2370 if (osec == NULL)
2371 return;
2372 osec_size = bfd_section_size (core_bfd, osec);
2373 if (record_debug)
2374 fprintf_unfiltered (gdb_stdlog, "%s", bfd_section_name (core_bfd, osec));
2375
2376 /* Check the magic code. */
2377 bfdcore_read (core_bfd, osec, &magic, sizeof (magic), &bfd_offset);
2378 if (magic != RECORD_FULL_FILE_MAGIC)
2379 error (_("Version mis-match or file format error in core file %s."),
2380 bfd_get_filename (core_bfd));
2381 if (record_debug)
2382 fprintf_unfiltered (gdb_stdlog,
2383 " Reading 4-byte magic cookie "
2384 "RECORD_FULL_FILE_MAGIC (0x%s)\n",
2385 phex_nz (netorder32 (magic), 4));
2386
2387 /* Restore the entries in recfd into record_full_arch_list_head and
2388 record_full_arch_list_tail. */
2389 record_full_arch_list_head = NULL;
2390 record_full_arch_list_tail = NULL;
2391 record_full_insn_num = 0;
2392 old_cleanups = make_cleanup (record_full_arch_list_cleanups, 0);
2393 regcache = get_current_regcache ();
2394
2395 while (1)
2396 {
2397 uint8_t rectype;
2398 uint32_t regnum, len, signal, count;
2399 uint64_t addr;
2400
2401 /* We are finished when offset reaches osec_size. */
2402 if (bfd_offset >= osec_size)
2403 break;
2404 bfdcore_read (core_bfd, osec, &rectype, sizeof (rectype), &bfd_offset);
2405
2406 switch (rectype)
2407 {
2408 case record_full_reg: /* reg */
2409 /* Get register number to regnum. */
2410 bfdcore_read (core_bfd, osec, &regnum,
2411 sizeof (regnum), &bfd_offset);
2412 regnum = netorder32 (regnum);
2413
2414 rec = record_full_reg_alloc (regcache, regnum);
2415
2416 /* Get val. */
2417 bfdcore_read (core_bfd, osec, record_full_get_loc (rec),
2418 rec->u.reg.len, &bfd_offset);
2419
2420 if (record_debug)
2421 fprintf_unfiltered (gdb_stdlog,
2422 " Reading register %d (1 "
2423 "plus %lu plus %d bytes)\n",
2424 rec->u.reg.num,
2425 (unsigned long) sizeof (regnum),
2426 rec->u.reg.len);
2427 break;
2428
2429 case record_full_mem: /* mem */
2430 /* Get len. */
2431 bfdcore_read (core_bfd, osec, &len,
2432 sizeof (len), &bfd_offset);
2433 len = netorder32 (len);
2434
2435 /* Get addr. */
2436 bfdcore_read (core_bfd, osec, &addr,
2437 sizeof (addr), &bfd_offset);
2438 addr = netorder64 (addr);
2439
2440 rec = record_full_mem_alloc (addr, len);
2441
2442 /* Get val. */
2443 bfdcore_read (core_bfd, osec, record_full_get_loc (rec),
2444 rec->u.mem.len, &bfd_offset);
2445
2446 if (record_debug)
2447 fprintf_unfiltered (gdb_stdlog,
2448 " Reading memory %s (1 plus "
2449 "%lu plus %lu plus %d bytes)\n",
2450 paddress (get_current_arch (),
2451 rec->u.mem.addr),
2452 (unsigned long) sizeof (addr),
2453 (unsigned long) sizeof (len),
2454 rec->u.mem.len);
2455 break;
2456
2457 case record_full_end: /* end */
2458 rec = record_full_end_alloc ();
2459 record_full_insn_num ++;
2460
2461 /* Get signal value. */
2462 bfdcore_read (core_bfd, osec, &signal,
2463 sizeof (signal), &bfd_offset);
2464 signal = netorder32 (signal);
2465 rec->u.end.sigval = (enum gdb_signal) signal;
2466
2467 /* Get insn count. */
2468 bfdcore_read (core_bfd, osec, &count,
2469 sizeof (count), &bfd_offset);
2470 count = netorder32 (count);
2471 rec->u.end.insn_num = count;
2472 record_full_insn_count = count + 1;
2473 if (record_debug)
2474 fprintf_unfiltered (gdb_stdlog,
2475 " Reading record_full_end (1 + "
2476 "%lu + %lu bytes), offset == %s\n",
2477 (unsigned long) sizeof (signal),
2478 (unsigned long) sizeof (count),
2479 paddress (get_current_arch (),
2480 bfd_offset));
2481 break;
2482
2483 default:
2484 error (_("Bad entry type in core file %s."),
2485 bfd_get_filename (core_bfd));
2486 break;
2487 }
2488
2489 /* Add rec to record arch list. */
2490 record_full_arch_list_add (rec);
2491 }
2492
2493 discard_cleanups (old_cleanups);
2494
2495 /* Add record_full_arch_list_head to the end of record list. */
2496 record_full_first.next = record_full_arch_list_head;
2497 record_full_arch_list_head->prev = &record_full_first;
2498 record_full_arch_list_tail->next = NULL;
2499 record_full_list = &record_full_first;
2500
2501 /* Update record_full_insn_max_num. */
2502 if (record_full_insn_num > record_full_insn_max_num)
2503 {
2504 record_full_insn_max_num = record_full_insn_num;
2505 warning (_("Auto increase record/replay buffer limit to %u."),
2506 record_full_insn_max_num);
2507 }
2508
2509 /* Succeeded. */
2510 printf_filtered (_("Restored records from core file %s.\n"),
2511 bfd_get_filename (core_bfd));
2512
2513 print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1);
2514 }
2515
2516 /* bfdcore_write -- write bytes into a core file section. */
2517
2518 static inline void
2519 bfdcore_write (bfd *obfd, asection *osec, void *buf, int len, int *offset)
2520 {
2521 int ret = bfd_set_section_contents (obfd, osec, buf, *offset, len);
2522
2523 if (ret)
2524 *offset += len;
2525 else
2526 error (_("Failed to write %d bytes to core file %s ('%s')."),
2527 len, bfd_get_filename (obfd),
2528 bfd_errmsg (bfd_get_error ()));
2529 }
2530
2531 /* Restore the execution log from a file. We use a modified elf
2532 corefile format, with an extra section for our data. */
2533
2534 static void
2535 cmd_record_full_restore (char *args, int from_tty)
2536 {
2537 core_file_command (args, from_tty);
2538 record_full_open (args, from_tty);
2539 }
2540
2541 /* Save the execution log to a file. We use a modified elf corefile
2542 format, with an extra section for our data. */
2543
2544 static void
2545 record_full_save (struct target_ops *self, const char *recfilename)
2546 {
2547 struct record_full_entry *cur_record_full_list;
2548 uint32_t magic;
2549 struct regcache *regcache;
2550 struct gdbarch *gdbarch;
2551 struct cleanup *set_cleanups;
2552 int save_size = 0;
2553 asection *osec = NULL;
2554 int bfd_offset = 0;
2555
2556 /* Open the save file. */
2557 if (record_debug)
2558 fprintf_unfiltered (gdb_stdlog, "Saving execution log to core file '%s'\n",
2559 recfilename);
2560
2561 /* Open the output file. */
2562 gdb_bfd_ref_ptr obfd (create_gcore_bfd (recfilename));
2563
2564 /* Arrange to remove the output file on failure. */
2565 gdb::unlinker unlink_file (recfilename);
2566
2567 /* Save the current record entry to "cur_record_full_list". */
2568 cur_record_full_list = record_full_list;
2569
2570 /* Get the values of regcache and gdbarch. */
2571 regcache = get_current_regcache ();
2572 gdbarch = get_regcache_arch (regcache);
2573
2574 /* Disable the GDB operation record. */
2575 set_cleanups = record_full_gdb_operation_disable_set ();
2576
2577 /* Reverse execute to the begin of record list. */
2578 while (1)
2579 {
2580 /* Check for beginning and end of log. */
2581 if (record_full_list == &record_full_first)
2582 break;
2583
2584 record_full_exec_insn (regcache, gdbarch, record_full_list);
2585
2586 if (record_full_list->prev)
2587 record_full_list = record_full_list->prev;
2588 }
2589
2590 /* Compute the size needed for the extra bfd section. */
2591 save_size = 4; /* magic cookie */
2592 for (record_full_list = record_full_first.next; record_full_list;
2593 record_full_list = record_full_list->next)
2594 switch (record_full_list->type)
2595 {
2596 case record_full_end:
2597 save_size += 1 + 4 + 4;
2598 break;
2599 case record_full_reg:
2600 save_size += 1 + 4 + record_full_list->u.reg.len;
2601 break;
2602 case record_full_mem:
2603 save_size += 1 + 4 + 8 + record_full_list->u.mem.len;
2604 break;
2605 }
2606
2607 /* Make the new bfd section. */
2608 osec = bfd_make_section_anyway_with_flags (obfd.get (), "precord",
2609 SEC_HAS_CONTENTS
2610 | SEC_READONLY);
2611 if (osec == NULL)
2612 error (_("Failed to create 'precord' section for corefile %s: %s"),
2613 recfilename,
2614 bfd_errmsg (bfd_get_error ()));
2615 bfd_set_section_size (obfd.get (), osec, save_size);
2616 bfd_set_section_vma (obfd.get (), osec, 0);
2617 bfd_set_section_alignment (obfd.get (), osec, 0);
2618 bfd_section_lma (obfd.get (), osec) = 0;
2619
2620 /* Save corefile state. */
2621 write_gcore_file (obfd.get ());
2622
2623 /* Write out the record log. */
2624 /* Write the magic code. */
2625 magic = RECORD_FULL_FILE_MAGIC;
2626 if (record_debug)
2627 fprintf_unfiltered (gdb_stdlog,
2628 " Writing 4-byte magic cookie "
2629 "RECORD_FULL_FILE_MAGIC (0x%s)\n",
2630 phex_nz (magic, 4));
2631 bfdcore_write (obfd.get (), osec, &magic, sizeof (magic), &bfd_offset);
2632
2633 /* Save the entries to recfd and forward execute to the end of
2634 record list. */
2635 record_full_list = &record_full_first;
2636 while (1)
2637 {
2638 /* Save entry. */
2639 if (record_full_list != &record_full_first)
2640 {
2641 uint8_t type;
2642 uint32_t regnum, len, signal, count;
2643 uint64_t addr;
2644
2645 type = record_full_list->type;
2646 bfdcore_write (obfd.get (), osec, &type, sizeof (type), &bfd_offset);
2647
2648 switch (record_full_list->type)
2649 {
2650 case record_full_reg: /* reg */
2651 if (record_debug)
2652 fprintf_unfiltered (gdb_stdlog,
2653 " Writing register %d (1 "
2654 "plus %lu plus %d bytes)\n",
2655 record_full_list->u.reg.num,
2656 (unsigned long) sizeof (regnum),
2657 record_full_list->u.reg.len);
2658
2659 /* Write regnum. */
2660 regnum = netorder32 (record_full_list->u.reg.num);
2661 bfdcore_write (obfd.get (), osec, &regnum,
2662 sizeof (regnum), &bfd_offset);
2663
2664 /* Write regval. */
2665 bfdcore_write (obfd.get (), osec,
2666 record_full_get_loc (record_full_list),
2667 record_full_list->u.reg.len, &bfd_offset);
2668 break;
2669
2670 case record_full_mem: /* mem */
2671 if (record_debug)
2672 fprintf_unfiltered (gdb_stdlog,
2673 " Writing memory %s (1 plus "
2674 "%lu plus %lu plus %d bytes)\n",
2675 paddress (gdbarch,
2676 record_full_list->u.mem.addr),
2677 (unsigned long) sizeof (addr),
2678 (unsigned long) sizeof (len),
2679 record_full_list->u.mem.len);
2680
2681 /* Write memlen. */
2682 len = netorder32 (record_full_list->u.mem.len);
2683 bfdcore_write (obfd.get (), osec, &len, sizeof (len),
2684 &bfd_offset);
2685
2686 /* Write memaddr. */
2687 addr = netorder64 (record_full_list->u.mem.addr);
2688 bfdcore_write (obfd.get (), osec, &addr,
2689 sizeof (addr), &bfd_offset);
2690
2691 /* Write memval. */
2692 bfdcore_write (obfd.get (), osec,
2693 record_full_get_loc (record_full_list),
2694 record_full_list->u.mem.len, &bfd_offset);
2695 break;
2696
2697 case record_full_end:
2698 if (record_debug)
2699 fprintf_unfiltered (gdb_stdlog,
2700 " Writing record_full_end (1 + "
2701 "%lu + %lu bytes)\n",
2702 (unsigned long) sizeof (signal),
2703 (unsigned long) sizeof (count));
2704 /* Write signal value. */
2705 signal = netorder32 (record_full_list->u.end.sigval);
2706 bfdcore_write (obfd.get (), osec, &signal,
2707 sizeof (signal), &bfd_offset);
2708
2709 /* Write insn count. */
2710 count = netorder32 (record_full_list->u.end.insn_num);
2711 bfdcore_write (obfd.get (), osec, &count,
2712 sizeof (count), &bfd_offset);
2713 break;
2714 }
2715 }
2716
2717 /* Execute entry. */
2718 record_full_exec_insn (regcache, gdbarch, record_full_list);
2719
2720 if (record_full_list->next)
2721 record_full_list = record_full_list->next;
2722 else
2723 break;
2724 }
2725
2726 /* Reverse execute to cur_record_full_list. */
2727 while (1)
2728 {
2729 /* Check for beginning and end of log. */
2730 if (record_full_list == cur_record_full_list)
2731 break;
2732
2733 record_full_exec_insn (regcache, gdbarch, record_full_list);
2734
2735 if (record_full_list->prev)
2736 record_full_list = record_full_list->prev;
2737 }
2738
2739 do_cleanups (set_cleanups);
2740 unlink_file.keep ();
2741
2742 /* Succeeded. */
2743 printf_filtered (_("Saved core file %s with execution log.\n"),
2744 recfilename);
2745 }
2746
2747 /* record_full_goto_insn -- rewind the record log (forward or backward,
2748 depending on DIR) to the given entry, changing the program state
2749 correspondingly. */
2750
2751 static void
2752 record_full_goto_insn (struct record_full_entry *entry,
2753 enum exec_direction_kind dir)
2754 {
2755 struct cleanup *set_cleanups = record_full_gdb_operation_disable_set ();
2756 struct regcache *regcache = get_current_regcache ();
2757 struct gdbarch *gdbarch = get_regcache_arch (regcache);
2758
2759 /* Assume everything is valid: we will hit the entry,
2760 and we will not hit the end of the recording. */
2761
2762 if (dir == EXEC_FORWARD)
2763 record_full_list = record_full_list->next;
2764
2765 do
2766 {
2767 record_full_exec_insn (regcache, gdbarch, record_full_list);
2768 if (dir == EXEC_REVERSE)
2769 record_full_list = record_full_list->prev;
2770 else
2771 record_full_list = record_full_list->next;
2772 } while (record_full_list != entry);
2773 do_cleanups (set_cleanups);
2774 }
2775
2776 /* Alias for "target record-full". */
2777
2778 static void
2779 cmd_record_full_start (char *args, int from_tty)
2780 {
2781 execute_command ("target record-full", from_tty);
2782 }
2783
2784 static void
2785 set_record_full_insn_max_num (char *args, int from_tty,
2786 struct cmd_list_element *c)
2787 {
2788 if (record_full_insn_num > record_full_insn_max_num)
2789 {
2790 /* Count down record_full_insn_num while releasing records from list. */
2791 while (record_full_insn_num > record_full_insn_max_num)
2792 {
2793 record_full_list_release_first ();
2794 record_full_insn_num--;
2795 }
2796 }
2797 }
2798
2799 /* The "set record full" command. */
2800
2801 static void
2802 set_record_full_command (char *args, int from_tty)
2803 {
2804 printf_unfiltered (_("\"set record full\" must be followed "
2805 "by an apporpriate subcommand.\n"));
2806 help_list (set_record_full_cmdlist, "set record full ", all_commands,
2807 gdb_stdout);
2808 }
2809
2810 /* The "show record full" command. */
2811
2812 static void
2813 show_record_full_command (char *args, int from_tty)
2814 {
2815 cmd_show_list (show_record_full_cmdlist, from_tty, "");
2816 }
2817
2818 /* Provide a prototype to silence -Wmissing-prototypes. */
2819 extern initialize_file_ftype _initialize_record_full;
2820
2821 void
2822 _initialize_record_full (void)
2823 {
2824 struct cmd_list_element *c;
2825
2826 /* Init record_full_first. */
2827 record_full_first.prev = NULL;
2828 record_full_first.next = NULL;
2829 record_full_first.type = record_full_end;
2830
2831 init_record_full_ops ();
2832 add_target (&record_full_ops);
2833 add_deprecated_target_alias (&record_full_ops, "record");
2834 init_record_full_core_ops ();
2835 add_target (&record_full_core_ops);
2836
2837 add_prefix_cmd ("full", class_obscure, cmd_record_full_start,
2838 _("Start full execution recording."), &record_full_cmdlist,
2839 "record full ", 0, &record_cmdlist);
2840
2841 c = add_cmd ("restore", class_obscure, cmd_record_full_restore,
2842 _("Restore the execution log from a file.\n\
2843 Argument is filename. File must be created with 'record save'."),
2844 &record_full_cmdlist);
2845 set_cmd_completer (c, filename_completer);
2846
2847 /* Deprecate the old version without "full" prefix. */
2848 c = add_alias_cmd ("restore", "full restore", class_obscure, 1,
2849 &record_cmdlist);
2850 set_cmd_completer (c, filename_completer);
2851 deprecate_cmd (c, "record full restore");
2852
2853 add_prefix_cmd ("full", class_support, set_record_full_command,
2854 _("Set record options"), &set_record_full_cmdlist,
2855 "set record full ", 0, &set_record_cmdlist);
2856
2857 add_prefix_cmd ("full", class_support, show_record_full_command,
2858 _("Show record options"), &show_record_full_cmdlist,
2859 "show record full ", 0, &show_record_cmdlist);
2860
2861 /* Record instructions number limit command. */
2862 add_setshow_boolean_cmd ("stop-at-limit", no_class,
2863 &record_full_stop_at_limit, _("\
2864 Set whether record/replay stops when record/replay buffer becomes full."), _("\
2865 Show whether record/replay stops when record/replay buffer becomes full."),
2866 _("Default is ON.\n\
2867 When ON, if the record/replay buffer becomes full, ask user what to do.\n\
2868 When OFF, if the record/replay buffer becomes full,\n\
2869 delete the oldest recorded instruction to make room for each new one."),
2870 NULL, NULL,
2871 &set_record_full_cmdlist, &show_record_full_cmdlist);
2872
2873 c = add_alias_cmd ("stop-at-limit", "full stop-at-limit", no_class, 1,
2874 &set_record_cmdlist);
2875 deprecate_cmd (c, "set record full stop-at-limit");
2876
2877 c = add_alias_cmd ("stop-at-limit", "full stop-at-limit", no_class, 1,
2878 &show_record_cmdlist);
2879 deprecate_cmd (c, "show record full stop-at-limit");
2880
2881 add_setshow_uinteger_cmd ("insn-number-max", no_class,
2882 &record_full_insn_max_num,
2883 _("Set record/replay buffer limit."),
2884 _("Show record/replay buffer limit."), _("\
2885 Set the maximum number of instructions to be stored in the\n\
2886 record/replay buffer. A value of either \"unlimited\" or zero means no\n\
2887 limit. Default is 200000."),
2888 set_record_full_insn_max_num,
2889 NULL, &set_record_full_cmdlist,
2890 &show_record_full_cmdlist);
2891
2892 c = add_alias_cmd ("insn-number-max", "full insn-number-max", no_class, 1,
2893 &set_record_cmdlist);
2894 deprecate_cmd (c, "set record full insn-number-max");
2895
2896 c = add_alias_cmd ("insn-number-max", "full insn-number-max", no_class, 1,
2897 &show_record_cmdlist);
2898 deprecate_cmd (c, "show record full insn-number-max");
2899
2900 add_setshow_boolean_cmd ("memory-query", no_class,
2901 &record_full_memory_query, _("\
2902 Set whether query if PREC cannot record memory change of next instruction."),
2903 _("\
2904 Show whether query if PREC cannot record memory change of next instruction."),
2905 _("\
2906 Default is OFF.\n\
2907 When ON, query if PREC cannot record memory change of next instruction."),
2908 NULL, NULL,
2909 &set_record_full_cmdlist,
2910 &show_record_full_cmdlist);
2911
2912 c = add_alias_cmd ("memory-query", "full memory-query", no_class, 1,
2913 &set_record_cmdlist);
2914 deprecate_cmd (c, "set record full memory-query");
2915
2916 c = add_alias_cmd ("memory-query", "full memory-query", no_class, 1,
2917 &show_record_cmdlist);
2918 deprecate_cmd (c, "show record full memory-query");
2919 }
This page took 0.09971 seconds and 4 git commands to generate.