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