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