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