]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/record-full.c
Make "set/show dcache line-size" and "set/show dcache size" zinteger commands instead...
[thirdparty/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
460014f5 1024record_full_close (void)
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
d02ed0bb 1526static int
88d1aa9d 1527record_full_stopped_data_address (struct target_ops *ops, CORE_ADDR *addr_p)
d02ed0bb 1528{
88d1aa9d 1529 if (RECORD_FULL_IS_REPLAY)
d02ed0bb
MM
1530 return 0;
1531 else
88d1aa9d 1532 return record_full_beneath_to_stopped_data_address (ops, addr_p);
d02ed0bb
MM
1533}
1534
1535/* Record registers change (by user or by GDB) to list as an instruction. */
1536
1537static void
88d1aa9d 1538record_full_registers_change (struct regcache *regcache, int regnum)
d02ed0bb 1539{
88d1aa9d
MM
1540 /* Check record_full_insn_num. */
1541 record_full_check_insn_num (0);
d02ed0bb 1542
88d1aa9d
MM
1543 record_full_arch_list_head = NULL;
1544 record_full_arch_list_tail = NULL;
d02ed0bb
MM
1545
1546 if (regnum < 0)
1547 {
1548 int i;
1549
1550 for (i = 0; i < gdbarch_num_regs (get_regcache_arch (regcache)); i++)
1551 {
25ea693b 1552 if (record_full_arch_list_add_reg (regcache, i))
d02ed0bb 1553 {
88d1aa9d 1554 record_full_list_release (record_full_arch_list_tail);
d02ed0bb
MM
1555 error (_("Process record: failed to record execution log."));
1556 }
1557 }
1558 }
1559 else
1560 {
25ea693b 1561 if (record_full_arch_list_add_reg (regcache, regnum))
d02ed0bb 1562 {
88d1aa9d 1563 record_full_list_release (record_full_arch_list_tail);
d02ed0bb
MM
1564 error (_("Process record: failed to record execution log."));
1565 }
1566 }
25ea693b 1567 if (record_full_arch_list_add_end ())
d02ed0bb 1568 {
88d1aa9d 1569 record_full_list_release (record_full_arch_list_tail);
d02ed0bb
MM
1570 error (_("Process record: failed to record execution log."));
1571 }
88d1aa9d
MM
1572 record_full_list->next = record_full_arch_list_head;
1573 record_full_arch_list_head->prev = record_full_list;
1574 record_full_list = record_full_arch_list_tail;
d02ed0bb 1575
88d1aa9d
MM
1576 if (record_full_insn_num == record_full_insn_max_num
1577 && record_full_insn_max_num)
1578 record_full_list_release_first ();
d02ed0bb 1579 else
88d1aa9d 1580 record_full_insn_num++;
d02ed0bb
MM
1581}
1582
1583/* "to_store_registers" method for process record target. */
1584
1585static void
88d1aa9d
MM
1586record_full_store_registers (struct target_ops *ops,
1587 struct regcache *regcache,
1588 int regno)
d02ed0bb 1589{
88d1aa9d 1590 if (!record_full_gdb_operation_disable)
d02ed0bb 1591 {
88d1aa9d 1592 if (RECORD_FULL_IS_REPLAY)
d02ed0bb
MM
1593 {
1594 int n;
1595
1596 /* Let user choose if he wants to write register or not. */
1597 if (regno < 0)
1598 n =
1599 query (_("Because GDB is in replay mode, changing the "
1600 "value of a register will make the execution "
1601 "log unusable from this point onward. "
1602 "Change all registers?"));
1603 else
1604 n =
1605 query (_("Because GDB is in replay mode, changing the value "
1606 "of a register will make the execution log unusable "
1607 "from this point onward. Change register %s?"),
1608 gdbarch_register_name (get_regcache_arch (regcache),
1609 regno));
1610
1611 if (!n)
1612 {
1613 /* Invalidate the value of regcache that was set in function
1614 "regcache_raw_write". */
1615 if (regno < 0)
1616 {
1617 int i;
1618
1619 for (i = 0;
1620 i < gdbarch_num_regs (get_regcache_arch (regcache));
1621 i++)
1622 regcache_invalidate (regcache, i);
1623 }
1624 else
1625 regcache_invalidate (regcache, regno);
1626
1627 error (_("Process record canceled the operation."));
1628 }
1629
1630 /* Destroy the record from here forward. */
88d1aa9d 1631 record_full_list_release_following (record_full_list);
d02ed0bb
MM
1632 }
1633
88d1aa9d 1634 record_full_registers_change (regcache, regno);
d02ed0bb 1635 }
88d1aa9d
MM
1636 record_full_beneath_to_store_registers
1637 (record_full_beneath_to_store_registers_ops, regcache, regno);
d02ed0bb
MM
1638}
1639
88d1aa9d
MM
1640/* "to_xfer_partial" method. Behavior is conditional on
1641 RECORD_FULL_IS_REPLAY.
d02ed0bb
MM
1642 In replay mode, we cannot write memory unles we are willing to
1643 invalidate the record/replay log from this point forward. */
1644
1645static LONGEST
88d1aa9d
MM
1646record_full_xfer_partial (struct target_ops *ops, enum target_object object,
1647 const char *annex, gdb_byte *readbuf,
1648 const gdb_byte *writebuf, ULONGEST offset,
1649 LONGEST len)
d02ed0bb 1650{
88d1aa9d 1651 if (!record_full_gdb_operation_disable
d02ed0bb
MM
1652 && (object == TARGET_OBJECT_MEMORY
1653 || object == TARGET_OBJECT_RAW_MEMORY) && writebuf)
1654 {
88d1aa9d 1655 if (RECORD_FULL_IS_REPLAY)
d02ed0bb
MM
1656 {
1657 /* Let user choose if he wants to write memory or not. */
1658 if (!query (_("Because GDB is in replay mode, writing to memory "
1659 "will make the execution log unusable from this "
1660 "point onward. Write memory at address %s?"),
1661 paddress (target_gdbarch (), offset)))
1662 error (_("Process record canceled the operation."));
1663
1664 /* Destroy the record from here forward. */
88d1aa9d 1665 record_full_list_release_following (record_full_list);
d02ed0bb
MM
1666 }
1667
88d1aa9d
MM
1668 /* Check record_full_insn_num */
1669 record_full_check_insn_num (0);
d02ed0bb
MM
1670
1671 /* Record registers change to list as an instruction. */
88d1aa9d
MM
1672 record_full_arch_list_head = NULL;
1673 record_full_arch_list_tail = NULL;
25ea693b 1674 if (record_full_arch_list_add_mem (offset, len))
d02ed0bb 1675 {
88d1aa9d 1676 record_full_list_release (record_full_arch_list_tail);
d02ed0bb
MM
1677 if (record_debug)
1678 fprintf_unfiltered (gdb_stdlog,
1679 "Process record: failed to record "
1680 "execution log.");
1681 return -1;
1682 }
25ea693b 1683 if (record_full_arch_list_add_end ())
d02ed0bb 1684 {
88d1aa9d 1685 record_full_list_release (record_full_arch_list_tail);
d02ed0bb
MM
1686 if (record_debug)
1687 fprintf_unfiltered (gdb_stdlog,
1688 "Process record: failed to record "
1689 "execution log.");
1690 return -1;
1691 }
88d1aa9d
MM
1692 record_full_list->next = record_full_arch_list_head;
1693 record_full_arch_list_head->prev = record_full_list;
1694 record_full_list = record_full_arch_list_tail;
d02ed0bb 1695
88d1aa9d
MM
1696 if (record_full_insn_num == record_full_insn_max_num
1697 && record_full_insn_max_num)
1698 record_full_list_release_first ();
d02ed0bb 1699 else
88d1aa9d 1700 record_full_insn_num++;
d02ed0bb
MM
1701 }
1702
88d1aa9d
MM
1703 return record_full_beneath_to_xfer_partial
1704 (record_full_beneath_to_xfer_partial_ops, object, annex,
1705 readbuf, writebuf, offset, len);
d02ed0bb
MM
1706}
1707
1708/* This structure represents a breakpoint inserted while the record
1709 target is active. We use this to know when to install/remove
1710 breakpoints in/from the target beneath. For example, a breakpoint
1711 may be inserted while recording, but removed when not replaying nor
1712 recording. In that case, the breakpoint had not been inserted on
1713 the target beneath, so we should not try to remove it there. */
1714
88d1aa9d 1715struct record_full_breakpoint
d02ed0bb
MM
1716{
1717 /* The address and address space the breakpoint was set at. */
1718 struct address_space *address_space;
1719 CORE_ADDR addr;
1720
1721 /* True when the breakpoint has been also installed in the target
1722 beneath. This will be false for breakpoints set during replay or
1723 when recording. */
1724 int in_target_beneath;
1725};
1726
88d1aa9d
MM
1727typedef struct record_full_breakpoint *record_full_breakpoint_p;
1728DEF_VEC_P(record_full_breakpoint_p);
d02ed0bb
MM
1729
1730/* The list of breakpoints inserted while the record target is
1731 active. */
88d1aa9d 1732VEC(record_full_breakpoint_p) *record_full_breakpoints = NULL;
d02ed0bb
MM
1733
1734static void
88d1aa9d 1735record_full_sync_record_breakpoints (struct bp_location *loc, void *data)
d02ed0bb
MM
1736{
1737 if (loc->loc_type != bp_loc_software_breakpoint)
1738 return;
1739
1740 if (loc->inserted)
1741 {
88d1aa9d 1742 struct record_full_breakpoint *bp = XNEW (struct record_full_breakpoint);
d02ed0bb
MM
1743
1744 bp->addr = loc->target_info.placed_address;
1745 bp->address_space = loc->target_info.placed_address_space;
1746
1747 bp->in_target_beneath = 1;
1748
88d1aa9d 1749 VEC_safe_push (record_full_breakpoint_p, record_full_breakpoints, bp);
d02ed0bb
MM
1750 }
1751}
1752
88d1aa9d 1753/* Sync existing breakpoints to record_full_breakpoints. */
d02ed0bb
MM
1754
1755static void
88d1aa9d 1756record_full_init_record_breakpoints (void)
d02ed0bb 1757{
88d1aa9d 1758 VEC_free (record_full_breakpoint_p, record_full_breakpoints);
d02ed0bb 1759
88d1aa9d 1760 iterate_over_bp_locations (record_full_sync_record_breakpoints);
d02ed0bb
MM
1761}
1762
88d1aa9d 1763/* Behavior is conditional on RECORD_FULL_IS_REPLAY. We will not actually
d02ed0bb
MM
1764 insert or remove breakpoints in the real target when replaying, nor
1765 when recording. */
1766
1767static int
88d1aa9d
MM
1768record_full_insert_breakpoint (struct gdbarch *gdbarch,
1769 struct bp_target_info *bp_tgt)
d02ed0bb 1770{
88d1aa9d 1771 struct record_full_breakpoint *bp;
d02ed0bb
MM
1772 int in_target_beneath = 0;
1773
88d1aa9d 1774 if (!RECORD_FULL_IS_REPLAY)
d02ed0bb
MM
1775 {
1776 /* When recording, we currently always single-step, so we don't
1777 really need to install regular breakpoints in the inferior.
1778 However, we do have to insert software single-step
1779 breakpoints, in case the target can't hardware step. To keep
1780 things single, we always insert. */
1781 struct cleanup *old_cleanups;
1782 int ret;
1783
25ea693b 1784 old_cleanups = record_full_gdb_operation_disable_set ();
88d1aa9d 1785 ret = record_full_beneath_to_insert_breakpoint (gdbarch, bp_tgt);
d02ed0bb
MM
1786 do_cleanups (old_cleanups);
1787
1788 if (ret != 0)
1789 return ret;
1790
1791 in_target_beneath = 1;
1792 }
1793
88d1aa9d 1794 bp = XNEW (struct record_full_breakpoint);
d02ed0bb
MM
1795 bp->addr = bp_tgt->placed_address;
1796 bp->address_space = bp_tgt->placed_address_space;
1797 bp->in_target_beneath = in_target_beneath;
88d1aa9d 1798 VEC_safe_push (record_full_breakpoint_p, record_full_breakpoints, bp);
d02ed0bb
MM
1799 return 0;
1800}
1801
1802/* "to_remove_breakpoint" method for process record target. */
1803
1804static int
88d1aa9d
MM
1805record_full_remove_breakpoint (struct gdbarch *gdbarch,
1806 struct bp_target_info *bp_tgt)
d02ed0bb 1807{
88d1aa9d 1808 struct record_full_breakpoint *bp;
d02ed0bb
MM
1809 int ix;
1810
1811 for (ix = 0;
88d1aa9d
MM
1812 VEC_iterate (record_full_breakpoint_p,
1813 record_full_breakpoints, ix, bp);
d02ed0bb
MM
1814 ++ix)
1815 {
1816 if (bp->addr == bp_tgt->placed_address
1817 && bp->address_space == bp_tgt->placed_address_space)
1818 {
1819 if (bp->in_target_beneath)
1820 {
1821 struct cleanup *old_cleanups;
1822 int ret;
1823
25ea693b 1824 old_cleanups = record_full_gdb_operation_disable_set ();
88d1aa9d 1825 ret = record_full_beneath_to_remove_breakpoint (gdbarch, bp_tgt);
d02ed0bb
MM
1826 do_cleanups (old_cleanups);
1827
1828 if (ret != 0)
1829 return ret;
1830 }
1831
88d1aa9d
MM
1832 VEC_unordered_remove (record_full_breakpoint_p,
1833 record_full_breakpoints, ix);
d02ed0bb
MM
1834 return 0;
1835 }
1836 }
1837
1838 gdb_assert_not_reached ("removing unknown breakpoint");
1839}
1840
1841/* "to_can_execute_reverse" method for process record target. */
1842
1843static int
88d1aa9d 1844record_full_can_execute_reverse (void)
d02ed0bb
MM
1845{
1846 return 1;
1847}
1848
1849/* "to_get_bookmark" method for process record and prec over core. */
1850
1851static gdb_byte *
88d1aa9d 1852record_full_get_bookmark (char *args, int from_tty)
d02ed0bb
MM
1853{
1854 gdb_byte *ret = NULL;
1855
1856 /* Return stringified form of instruction count. */
88d1aa9d
MM
1857 if (record_full_list && record_full_list->type == record_full_end)
1858 ret = xstrdup (pulongest (record_full_list->u.end.insn_num));
d02ed0bb
MM
1859
1860 if (record_debug)
1861 {
1862 if (ret)
1863 fprintf_unfiltered (gdb_stdlog,
88d1aa9d 1864 "record_full_get_bookmark returns %s\n", ret);
d02ed0bb
MM
1865 else
1866 fprintf_unfiltered (gdb_stdlog,
88d1aa9d 1867 "record_full_get_bookmark returns NULL\n");
d02ed0bb
MM
1868 }
1869 return ret;
1870}
1871
1872/* "to_goto_bookmark" method for process record and prec over core. */
1873
1874static void
88d1aa9d 1875record_full_goto_bookmark (gdb_byte *bookmark, int from_tty)
d02ed0bb
MM
1876{
1877 if (record_debug)
1878 fprintf_unfiltered (gdb_stdlog,
88d1aa9d 1879 "record_full_goto_bookmark receives %s\n", bookmark);
d02ed0bb
MM
1880
1881 if (bookmark[0] == '\'' || bookmark[0] == '\"')
1882 {
1883 if (bookmark[strlen (bookmark) - 1] != bookmark[0])
1884 error (_("Unbalanced quotes: %s"), bookmark);
1885
1886 /* Strip trailing quote. */
1887 bookmark[strlen (bookmark) - 1] = '\0';
1888 /* Strip leading quote. */
1889 bookmark++;
88d1aa9d 1890 /* Pass along to cmd_record_full_goto. */
d02ed0bb
MM
1891 }
1892
1893 cmd_record_goto ((char *) bookmark, from_tty);
1894 return;
1895}
1896
1897static void
88d1aa9d
MM
1898record_full_async (void (*callback) (enum inferior_event_type event_type,
1899 void *context), void *context)
d02ed0bb
MM
1900{
1901 /* If we're on top of a line target (e.g., linux-nat, remote), then
1902 set it to async mode as well. Will be NULL if we're sitting on
1903 top of the core target, for "record restore". */
88d1aa9d
MM
1904 if (record_full_beneath_to_async != NULL)
1905 record_full_beneath_to_async (callback, context);
d02ed0bb
MM
1906}
1907
1908static int
88d1aa9d 1909record_full_can_async_p (void)
d02ed0bb
MM
1910{
1911 /* We only enable async when the user specifically asks for it. */
1912 return target_async_permitted;
1913}
1914
1915static int
88d1aa9d 1916record_full_is_async_p (void)
d02ed0bb
MM
1917{
1918 /* We only enable async when the user specifically asks for it. */
1919 return target_async_permitted;
1920}
1921
1922static enum exec_direction_kind
88d1aa9d 1923record_full_execution_direction (void)
d02ed0bb 1924{
88d1aa9d 1925 return record_full_execution_dir;
d02ed0bb
MM
1926}
1927
1928static void
88d1aa9d 1929record_full_info (void)
d02ed0bb 1930{
88d1aa9d 1931 struct record_full_entry *p;
d02ed0bb 1932
88d1aa9d 1933 if (RECORD_FULL_IS_REPLAY)
d02ed0bb
MM
1934 printf_filtered (_("Replay mode:\n"));
1935 else
1936 printf_filtered (_("Record mode:\n"));
1937
1938 /* Find entry for first actual instruction in the log. */
88d1aa9d
MM
1939 for (p = record_full_first.next;
1940 p != NULL && p->type != record_full_end;
d02ed0bb
MM
1941 p = p->next)
1942 ;
1943
1944 /* Do we have a log at all? */
88d1aa9d 1945 if (p != NULL && p->type == record_full_end)
d02ed0bb
MM
1946 {
1947 /* Display instruction number for first instruction in the log. */
1948 printf_filtered (_("Lowest recorded instruction number is %s.\n"),
1949 pulongest (p->u.end.insn_num));
1950
1951 /* If in replay mode, display where we are in the log. */
88d1aa9d 1952 if (RECORD_FULL_IS_REPLAY)
d02ed0bb 1953 printf_filtered (_("Current instruction number is %s.\n"),
88d1aa9d 1954 pulongest (record_full_list->u.end.insn_num));
d02ed0bb
MM
1955
1956 /* Display instruction number for last instruction in the log. */
1957 printf_filtered (_("Highest recorded instruction number is %s.\n"),
88d1aa9d 1958 pulongest (record_full_insn_count));
d02ed0bb
MM
1959
1960 /* Display log count. */
1961 printf_filtered (_("Log contains %d instructions.\n"),
88d1aa9d 1962 record_full_insn_num);
d02ed0bb
MM
1963 }
1964 else
1965 printf_filtered (_("No instructions have been logged.\n"));
1966
1967 /* Display max log size. */
1968 printf_filtered (_("Max logged instructions is %d.\n"),
88d1aa9d 1969 record_full_insn_max_num);
d02ed0bb
MM
1970}
1971
1972/* The "to_record_delete" target method. */
1973
1974static void
88d1aa9d 1975record_full_delete (void)
d02ed0bb 1976{
88d1aa9d 1977 record_full_list_release_following (record_full_list);
d02ed0bb
MM
1978}
1979
1980/* The "to_record_is_replaying" target method. */
1981
1982static int
88d1aa9d 1983record_full_is_replaying (void)
d02ed0bb 1984{
88d1aa9d 1985 return RECORD_FULL_IS_REPLAY;
d02ed0bb
MM
1986}
1987
1988/* Go to a specific entry. */
1989
1990static void
88d1aa9d 1991record_full_goto_entry (struct record_full_entry *p)
d02ed0bb
MM
1992{
1993 if (p == NULL)
1994 error (_("Target insn not found."));
88d1aa9d 1995 else if (p == record_full_list)
d02ed0bb 1996 error (_("Already at target insn."));
88d1aa9d 1997 else if (p->u.end.insn_num > record_full_list->u.end.insn_num)
d02ed0bb
MM
1998 {
1999 printf_filtered (_("Go forward to insn number %s\n"),
2000 pulongest (p->u.end.insn_num));
88d1aa9d 2001 record_full_goto_insn (p, EXEC_FORWARD);
d02ed0bb
MM
2002 }
2003 else
2004 {
2005 printf_filtered (_("Go backward to insn number %s\n"),
2006 pulongest (p->u.end.insn_num));
88d1aa9d 2007 record_full_goto_insn (p, EXEC_REVERSE);
d02ed0bb
MM
2008 }
2009
2010 registers_changed ();
2011 reinit_frame_cache ();
2012 print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC);
2013}
2014
2015/* The "to_goto_record_begin" target method. */
2016
2017static void
88d1aa9d 2018record_full_goto_begin (void)
d02ed0bb 2019{
88d1aa9d 2020 struct record_full_entry *p = NULL;
d02ed0bb 2021
88d1aa9d
MM
2022 for (p = &record_full_first; p != NULL; p = p->next)
2023 if (p->type == record_full_end)
d02ed0bb
MM
2024 break;
2025
88d1aa9d 2026 record_full_goto_entry (p);
d02ed0bb
MM
2027}
2028
2029/* The "to_goto_record_end" target method. */
2030
2031static void
88d1aa9d 2032record_full_goto_end (void)
d02ed0bb 2033{
88d1aa9d 2034 struct record_full_entry *p = NULL;
d02ed0bb 2035
88d1aa9d 2036 for (p = record_full_list; p->next != NULL; p = p->next)
d02ed0bb
MM
2037 ;
2038 for (; p!= NULL; p = p->prev)
88d1aa9d 2039 if (p->type == record_full_end)
d02ed0bb
MM
2040 break;
2041
88d1aa9d 2042 record_full_goto_entry (p);
d02ed0bb
MM
2043}
2044
2045/* The "to_goto_record" target method. */
2046
2047static void
88d1aa9d 2048record_full_goto (ULONGEST target_insn)
d02ed0bb 2049{
88d1aa9d 2050 struct record_full_entry *p = NULL;
d02ed0bb 2051
88d1aa9d
MM
2052 for (p = &record_full_first; p != NULL; p = p->next)
2053 if (p->type == record_full_end && p->u.end.insn_num == target_insn)
d02ed0bb
MM
2054 break;
2055
88d1aa9d 2056 record_full_goto_entry (p);
d02ed0bb
MM
2057}
2058
2059static void
88d1aa9d 2060init_record_full_ops (void)
d02ed0bb 2061{
88d1aa9d
MM
2062 record_full_ops.to_shortname = "record-full";
2063 record_full_ops.to_longname = "Process record and replay target";
2064 record_full_ops.to_doc =
d02ed0bb 2065 "Log program while executing and replay execution from log.";
88d1aa9d
MM
2066 record_full_ops.to_open = record_full_open;
2067 record_full_ops.to_close = record_full_close;
2068 record_full_ops.to_resume = record_full_resume;
2069 record_full_ops.to_wait = record_full_wait;
7c1687a9
MM
2070 record_full_ops.to_disconnect = record_disconnect;
2071 record_full_ops.to_detach = record_detach;
2072 record_full_ops.to_mourn_inferior = record_mourn_inferior;
2073 record_full_ops.to_kill = record_kill;
88d1aa9d
MM
2074 record_full_ops.to_create_inferior = find_default_create_inferior;
2075 record_full_ops.to_store_registers = record_full_store_registers;
2076 record_full_ops.to_xfer_partial = record_full_xfer_partial;
2077 record_full_ops.to_insert_breakpoint = record_full_insert_breakpoint;
2078 record_full_ops.to_remove_breakpoint = record_full_remove_breakpoint;
2079 record_full_ops.to_stopped_by_watchpoint = record_full_stopped_by_watchpoint;
2080 record_full_ops.to_stopped_data_address = record_full_stopped_data_address;
2081 record_full_ops.to_can_execute_reverse = record_full_can_execute_reverse;
2082 record_full_ops.to_stratum = record_stratum;
d02ed0bb 2083 /* Add bookmark target methods. */
88d1aa9d
MM
2084 record_full_ops.to_get_bookmark = record_full_get_bookmark;
2085 record_full_ops.to_goto_bookmark = record_full_goto_bookmark;
2086 record_full_ops.to_async = record_full_async;
2087 record_full_ops.to_can_async_p = record_full_can_async_p;
2088 record_full_ops.to_is_async_p = record_full_is_async_p;
2089 record_full_ops.to_execution_direction = record_full_execution_direction;
2090 record_full_ops.to_info_record = record_full_info;
2091 record_full_ops.to_save_record = record_full_save;
2092 record_full_ops.to_delete_record = record_full_delete;
2093 record_full_ops.to_record_is_replaying = record_full_is_replaying;
2094 record_full_ops.to_goto_record_begin = record_full_goto_begin;
2095 record_full_ops.to_goto_record_end = record_full_goto_end;
2096 record_full_ops.to_goto_record = record_full_goto;
2097 record_full_ops.to_magic = OPS_MAGIC;
d02ed0bb
MM
2098}
2099
2100/* "to_resume" method for prec over corefile. */
2101
2102static void
88d1aa9d
MM
2103record_full_core_resume (struct target_ops *ops, ptid_t ptid, int step,
2104 enum gdb_signal signal)
d02ed0bb 2105{
88d1aa9d
MM
2106 record_full_resume_step = step;
2107 record_full_resumed = 1;
2108 record_full_execution_dir = execution_direction;
d02ed0bb
MM
2109
2110 /* We are about to start executing the inferior (or simulate it),
2111 let's register it with the event loop. */
2112 if (target_can_async_p ())
2113 {
2114 target_async (inferior_event_handler, 0);
2115
2116 /* Notify the event loop there's an event to wait for. */
88d1aa9d 2117 mark_async_event_handler (record_full_async_inferior_event_token);
d02ed0bb
MM
2118 }
2119}
2120
2121/* "to_kill" method for prec over corefile. */
2122
2123static void
88d1aa9d 2124record_full_core_kill (struct target_ops *ops)
d02ed0bb
MM
2125{
2126 if (record_debug)
88d1aa9d 2127 fprintf_unfiltered (gdb_stdlog, "Process record: record_full_core_kill\n");
d02ed0bb 2128
88d1aa9d 2129 unpush_target (&record_full_core_ops);
d02ed0bb
MM
2130}
2131
2132/* "to_fetch_registers" method for prec over corefile. */
2133
2134static void
88d1aa9d
MM
2135record_full_core_fetch_registers (struct target_ops *ops,
2136 struct regcache *regcache,
2137 int regno)
d02ed0bb
MM
2138{
2139 if (regno < 0)
2140 {
2141 int num = gdbarch_num_regs (get_regcache_arch (regcache));
2142 int i;
2143
2144 for (i = 0; i < num; i ++)
2145 regcache_raw_supply (regcache, i,
88d1aa9d 2146 record_full_core_regbuf + MAX_REGISTER_SIZE * i);
d02ed0bb
MM
2147 }
2148 else
2149 regcache_raw_supply (regcache, regno,
88d1aa9d 2150 record_full_core_regbuf + MAX_REGISTER_SIZE * regno);
d02ed0bb
MM
2151}
2152
2153/* "to_prepare_to_store" method for prec over corefile. */
2154
2155static void
88d1aa9d 2156record_full_core_prepare_to_store (struct regcache *regcache)
d02ed0bb
MM
2157{
2158}
2159
2160/* "to_store_registers" method for prec over corefile. */
2161
2162static void
88d1aa9d 2163record_full_core_store_registers (struct target_ops *ops,
d02ed0bb
MM
2164 struct regcache *regcache,
2165 int regno)
2166{
88d1aa9d 2167 if (record_full_gdb_operation_disable)
d02ed0bb 2168 regcache_raw_collect (regcache, regno,
88d1aa9d 2169 record_full_core_regbuf + MAX_REGISTER_SIZE * regno);
d02ed0bb
MM
2170 else
2171 error (_("You can't do that without a process to debug."));
2172}
2173
2174/* "to_xfer_partial" method for prec over corefile. */
2175
2176static LONGEST
88d1aa9d
MM
2177record_full_core_xfer_partial (struct target_ops *ops,
2178 enum target_object object,
2179 const char *annex, gdb_byte *readbuf,
2180 const gdb_byte *writebuf, ULONGEST offset,
2181 LONGEST len)
d02ed0bb
MM
2182{
2183 if (object == TARGET_OBJECT_MEMORY)
2184 {
88d1aa9d 2185 if (record_full_gdb_operation_disable || !writebuf)
d02ed0bb
MM
2186 {
2187 struct target_section *p;
2188
88d1aa9d 2189 for (p = record_full_core_start; p < record_full_core_end; p++)
d02ed0bb
MM
2190 {
2191 if (offset >= p->addr)
2192 {
88d1aa9d 2193 struct record_full_core_buf_entry *entry;
d02ed0bb
MM
2194 ULONGEST sec_offset;
2195
2196 if (offset >= p->endaddr)
2197 continue;
2198
2199 if (offset + len > p->endaddr)
2200 len = p->endaddr - offset;
2201
2202 sec_offset = offset - p->addr;
2203
2204 /* Read readbuf or write writebuf p, offset, len. */
2205 /* Check flags. */
2206 if (p->the_bfd_section->flags & SEC_CONSTRUCTOR
2207 || (p->the_bfd_section->flags & SEC_HAS_CONTENTS) == 0)
2208 {
2209 if (readbuf)
2210 memset (readbuf, 0, len);
2211 return len;
2212 }
88d1aa9d
MM
2213 /* Get record_full_core_buf_entry. */
2214 for (entry = record_full_core_buf_list; entry;
d02ed0bb
MM
2215 entry = entry->prev)
2216 if (entry->p == p)
2217 break;
2218 if (writebuf)
2219 {
2220 if (!entry)
2221 {
2222 /* Add a new entry. */
88d1aa9d
MM
2223 entry = (struct record_full_core_buf_entry *)
2224 xmalloc
2225 (sizeof (struct record_full_core_buf_entry));
d02ed0bb
MM
2226 entry->p = p;
2227 if (!bfd_malloc_and_get_section (p->bfd,
2228 p->the_bfd_section,
2229 &entry->buf))
2230 {
2231 xfree (entry);
2232 return 0;
2233 }
88d1aa9d
MM
2234 entry->prev = record_full_core_buf_list;
2235 record_full_core_buf_list = entry;
d02ed0bb
MM
2236 }
2237
2238 memcpy (entry->buf + sec_offset, writebuf,
2239 (size_t) len);
2240 }
2241 else
2242 {
2243 if (!entry)
88d1aa9d
MM
2244 return record_full_beneath_to_xfer_partial
2245 (record_full_beneath_to_xfer_partial_ops,
d02ed0bb
MM
2246 object, annex, readbuf, writebuf,
2247 offset, len);
2248
2249 memcpy (readbuf, entry->buf + sec_offset,
2250 (size_t) len);
2251 }
2252
2253 return len;
2254 }
2255 }
2256
2257 return -1;
2258 }
2259 else
2260 error (_("You can't do that without a process to debug."));
2261 }
2262
88d1aa9d
MM
2263 return record_full_beneath_to_xfer_partial
2264 (record_full_beneath_to_xfer_partial_ops, object, annex,
2265 readbuf, writebuf, offset, len);
d02ed0bb
MM
2266}
2267
2268/* "to_insert_breakpoint" method for prec over corefile. */
2269
2270static int
88d1aa9d
MM
2271record_full_core_insert_breakpoint (struct gdbarch *gdbarch,
2272 struct bp_target_info *bp_tgt)
d02ed0bb
MM
2273{
2274 return 0;
2275}
2276
2277/* "to_remove_breakpoint" method for prec over corefile. */
2278
2279static int
88d1aa9d
MM
2280record_full_core_remove_breakpoint (struct gdbarch *gdbarch,
2281 struct bp_target_info *bp_tgt)
d02ed0bb
MM
2282{
2283 return 0;
2284}
2285
2286/* "to_has_execution" method for prec over corefile. */
2287
2288static int
88d1aa9d 2289record_full_core_has_execution (struct target_ops *ops, ptid_t the_ptid)
d02ed0bb
MM
2290{
2291 return 1;
2292}
2293
2294static void
88d1aa9d 2295init_record_full_core_ops (void)
d02ed0bb 2296{
88d1aa9d
MM
2297 record_full_core_ops.to_shortname = "record-core";
2298 record_full_core_ops.to_longname = "Process record and replay target";
2299 record_full_core_ops.to_doc =
d02ed0bb 2300 "Log program while executing and replay execution from log.";
88d1aa9d
MM
2301 record_full_core_ops.to_open = record_full_open;
2302 record_full_core_ops.to_close = record_full_close;
2303 record_full_core_ops.to_resume = record_full_core_resume;
2304 record_full_core_ops.to_wait = record_full_wait;
2305 record_full_core_ops.to_kill = record_full_core_kill;
2306 record_full_core_ops.to_fetch_registers = record_full_core_fetch_registers;
2307 record_full_core_ops.to_prepare_to_store = record_full_core_prepare_to_store;
2308 record_full_core_ops.to_store_registers = record_full_core_store_registers;
2309 record_full_core_ops.to_xfer_partial = record_full_core_xfer_partial;
2310 record_full_core_ops.to_insert_breakpoint
2311 = record_full_core_insert_breakpoint;
2312 record_full_core_ops.to_remove_breakpoint
2313 = record_full_core_remove_breakpoint;
2314 record_full_core_ops.to_stopped_by_watchpoint
2315 = record_full_stopped_by_watchpoint;
2316 record_full_core_ops.to_stopped_data_address
2317 = record_full_stopped_data_address;
2318 record_full_core_ops.to_can_execute_reverse
2319 = record_full_can_execute_reverse;
2320 record_full_core_ops.to_has_execution = record_full_core_has_execution;
2321 record_full_core_ops.to_stratum = record_stratum;
d02ed0bb 2322 /* Add bookmark target methods. */
88d1aa9d
MM
2323 record_full_core_ops.to_get_bookmark = record_full_get_bookmark;
2324 record_full_core_ops.to_goto_bookmark = record_full_goto_bookmark;
2325 record_full_core_ops.to_async = record_full_async;
2326 record_full_core_ops.to_can_async_p = record_full_can_async_p;
2327 record_full_core_ops.to_is_async_p = record_full_is_async_p;
2328 record_full_core_ops.to_execution_direction
2329 = record_full_execution_direction;
2330 record_full_core_ops.to_info_record = record_full_info;
2331 record_full_core_ops.to_delete_record = record_full_delete;
2332 record_full_core_ops.to_record_is_replaying = record_full_is_replaying;
2333 record_full_core_ops.to_goto_record_begin = record_full_goto_begin;
2334 record_full_core_ops.to_goto_record_end = record_full_goto_end;
2335 record_full_core_ops.to_goto_record = record_full_goto;
2336 record_full_core_ops.to_magic = OPS_MAGIC;
d02ed0bb
MM
2337}
2338
2339/* Record log save-file format
2340 Version 1 (never released)
2341
2342 Header:
2343 4 bytes: magic number htonl(0x20090829).
2344 NOTE: be sure to change whenever this file format changes!
2345
2346 Records:
88d1aa9d
MM
2347 record_full_end:
2348 1 byte: record type (record_full_end, see enum record_full_type).
2349 record_full_reg:
2350 1 byte: record type (record_full_reg, see enum record_full_type).
d02ed0bb
MM
2351 8 bytes: register id (network byte order).
2352 MAX_REGISTER_SIZE bytes: register value.
88d1aa9d
MM
2353 record_full_mem:
2354 1 byte: record type (record_full_mem, see enum record_full_type).
d02ed0bb
MM
2355 8 bytes: memory length (network byte order).
2356 8 bytes: memory address (network byte order).
2357 n bytes: memory value (n == memory length).
2358
2359 Version 2
2360 4 bytes: magic number netorder32(0x20091016).
2361 NOTE: be sure to change whenever this file format changes!
2362
2363 Records:
88d1aa9d
MM
2364 record_full_end:
2365 1 byte: record type (record_full_end, see enum record_full_type).
d02ed0bb
MM
2366 4 bytes: signal
2367 4 bytes: instruction count
88d1aa9d
MM
2368 record_full_reg:
2369 1 byte: record type (record_full_reg, see enum record_full_type).
d02ed0bb
MM
2370 4 bytes: register id (network byte order).
2371 n bytes: register value (n == actual register size).
2372 (eg. 4 bytes for x86 general registers).
88d1aa9d
MM
2373 record_full_mem:
2374 1 byte: record type (record_full_mem, see enum record_full_type).
d02ed0bb
MM
2375 4 bytes: memory length (network byte order).
2376 8 bytes: memory address (network byte order).
2377 n bytes: memory value (n == memory length).
2378
2379*/
2380
2381/* bfdcore_read -- read bytes from a core file section. */
2382
2383static inline void
2384bfdcore_read (bfd *obfd, asection *osec, void *buf, int len, int *offset)
2385{
2386 int ret = bfd_get_section_contents (obfd, osec, buf, *offset, len);
2387
2388 if (ret)
2389 *offset += len;
2390 else
2391 error (_("Failed to read %d bytes from core file %s ('%s')."),
2392 len, bfd_get_filename (obfd),
2393 bfd_errmsg (bfd_get_error ()));
2394}
2395
2396static inline uint64_t
2397netorder64 (uint64_t input)
2398{
2399 uint64_t ret;
2400
2401 store_unsigned_integer ((gdb_byte *) &ret, sizeof (ret),
2402 BFD_ENDIAN_BIG, input);
2403 return ret;
2404}
2405
2406static inline uint32_t
2407netorder32 (uint32_t input)
2408{
2409 uint32_t ret;
2410
2411 store_unsigned_integer ((gdb_byte *) &ret, sizeof (ret),
2412 BFD_ENDIAN_BIG, input);
2413 return ret;
2414}
2415
2416static inline uint16_t
2417netorder16 (uint16_t input)
2418{
2419 uint16_t ret;
2420
2421 store_unsigned_integer ((gdb_byte *) &ret, sizeof (ret),
2422 BFD_ENDIAN_BIG, input);
2423 return ret;
2424}
2425
2426/* Restore the execution log from a core_bfd file. */
2427static void
88d1aa9d 2428record_full_restore (void)
d02ed0bb
MM
2429{
2430 uint32_t magic;
2431 struct cleanup *old_cleanups;
88d1aa9d 2432 struct record_full_entry *rec;
d02ed0bb
MM
2433 asection *osec;
2434 uint32_t osec_size;
2435 int bfd_offset = 0;
2436 struct regcache *regcache;
2437
2438 /* We restore the execution log from the open core bfd,
2439 if there is one. */
2440 if (core_bfd == NULL)
2441 return;
2442
88d1aa9d
MM
2443 /* "record_full_restore" can only be called when record list is empty. */
2444 gdb_assert (record_full_first.next == NULL);
d02ed0bb
MM
2445
2446 if (record_debug)
2447 fprintf_unfiltered (gdb_stdlog, "Restoring recording from core file.\n");
2448
2449 /* Now need to find our special note section. */
2450 osec = bfd_get_section_by_name (core_bfd, "null0");
2451 if (record_debug)
2452 fprintf_unfiltered (gdb_stdlog, "Find precord section %s.\n",
2453 osec ? "succeeded" : "failed");
2454 if (osec == NULL)
2455 return;
2456 osec_size = bfd_section_size (core_bfd, osec);
2457 if (record_debug)
2458 fprintf_unfiltered (gdb_stdlog, "%s", bfd_section_name (core_bfd, osec));
2459
2460 /* Check the magic code. */
2461 bfdcore_read (core_bfd, osec, &magic, sizeof (magic), &bfd_offset);
88d1aa9d 2462 if (magic != RECORD_FULL_FILE_MAGIC)
d02ed0bb
MM
2463 error (_("Version mis-match or file format error in core file %s."),
2464 bfd_get_filename (core_bfd));
2465 if (record_debug)
2466 fprintf_unfiltered (gdb_stdlog,
2467 " Reading 4-byte magic cookie "
88d1aa9d 2468 "RECORD_FULL_FILE_MAGIC (0x%s)\n",
d02ed0bb
MM
2469 phex_nz (netorder32 (magic), 4));
2470
88d1aa9d
MM
2471 /* Restore the entries in recfd into record_full_arch_list_head and
2472 record_full_arch_list_tail. */
2473 record_full_arch_list_head = NULL;
2474 record_full_arch_list_tail = NULL;
2475 record_full_insn_num = 0;
2476 old_cleanups = make_cleanup (record_full_arch_list_cleanups, 0);
d02ed0bb
MM
2477 regcache = get_current_regcache ();
2478
2479 while (1)
2480 {
2481 uint8_t rectype;
2482 uint32_t regnum, len, signal, count;
2483 uint64_t addr;
2484
2485 /* We are finished when offset reaches osec_size. */
2486 if (bfd_offset >= osec_size)
2487 break;
2488 bfdcore_read (core_bfd, osec, &rectype, sizeof (rectype), &bfd_offset);
2489
2490 switch (rectype)
2491 {
88d1aa9d 2492 case record_full_reg: /* reg */
d02ed0bb
MM
2493 /* Get register number to regnum. */
2494 bfdcore_read (core_bfd, osec, &regnum,
2495 sizeof (regnum), &bfd_offset);
2496 regnum = netorder32 (regnum);
2497
88d1aa9d 2498 rec = record_full_reg_alloc (regcache, regnum);
d02ed0bb
MM
2499
2500 /* Get val. */
88d1aa9d 2501 bfdcore_read (core_bfd, osec, record_full_get_loc (rec),
d02ed0bb
MM
2502 rec->u.reg.len, &bfd_offset);
2503
2504 if (record_debug)
2505 fprintf_unfiltered (gdb_stdlog,
2506 " Reading register %d (1 "
2507 "plus %lu plus %d bytes)\n",
2508 rec->u.reg.num,
2509 (unsigned long) sizeof (regnum),
2510 rec->u.reg.len);
2511 break;
2512
88d1aa9d 2513 case record_full_mem: /* mem */
d02ed0bb
MM
2514 /* Get len. */
2515 bfdcore_read (core_bfd, osec, &len,
2516 sizeof (len), &bfd_offset);
2517 len = netorder32 (len);
2518
2519 /* Get addr. */
2520 bfdcore_read (core_bfd, osec, &addr,
2521 sizeof (addr), &bfd_offset);
2522 addr = netorder64 (addr);
2523
88d1aa9d 2524 rec = record_full_mem_alloc (addr, len);
d02ed0bb
MM
2525
2526 /* Get val. */
88d1aa9d 2527 bfdcore_read (core_bfd, osec, record_full_get_loc (rec),
d02ed0bb
MM
2528 rec->u.mem.len, &bfd_offset);
2529
2530 if (record_debug)
2531 fprintf_unfiltered (gdb_stdlog,
2532 " Reading memory %s (1 plus "
2533 "%lu plus %lu plus %d bytes)\n",
2534 paddress (get_current_arch (),
2535 rec->u.mem.addr),
2536 (unsigned long) sizeof (addr),
2537 (unsigned long) sizeof (len),
2538 rec->u.mem.len);
2539 break;
2540
88d1aa9d
MM
2541 case record_full_end: /* end */
2542 rec = record_full_end_alloc ();
2543 record_full_insn_num ++;
d02ed0bb
MM
2544
2545 /* Get signal value. */
2546 bfdcore_read (core_bfd, osec, &signal,
2547 sizeof (signal), &bfd_offset);
2548 signal = netorder32 (signal);
2549 rec->u.end.sigval = signal;
2550
2551 /* Get insn count. */
2552 bfdcore_read (core_bfd, osec, &count,
2553 sizeof (count), &bfd_offset);
2554 count = netorder32 (count);
2555 rec->u.end.insn_num = count;
88d1aa9d 2556 record_full_insn_count = count + 1;
d02ed0bb
MM
2557 if (record_debug)
2558 fprintf_unfiltered (gdb_stdlog,
88d1aa9d 2559 " Reading record_full_end (1 + "
d02ed0bb
MM
2560 "%lu + %lu bytes), offset == %s\n",
2561 (unsigned long) sizeof (signal),
2562 (unsigned long) sizeof (count),
2563 paddress (get_current_arch (),
2564 bfd_offset));
2565 break;
2566
2567 default:
2568 error (_("Bad entry type in core file %s."),
2569 bfd_get_filename (core_bfd));
2570 break;
2571 }
2572
2573 /* Add rec to record arch list. */
88d1aa9d 2574 record_full_arch_list_add (rec);
d02ed0bb
MM
2575 }
2576
2577 discard_cleanups (old_cleanups);
2578
88d1aa9d
MM
2579 /* Add record_full_arch_list_head to the end of record list. */
2580 record_full_first.next = record_full_arch_list_head;
2581 record_full_arch_list_head->prev = &record_full_first;
2582 record_full_arch_list_tail->next = NULL;
2583 record_full_list = &record_full_first;
d02ed0bb 2584
88d1aa9d
MM
2585 /* Update record_full_insn_max_num. */
2586 if (record_full_insn_num > record_full_insn_max_num)
d02ed0bb 2587 {
88d1aa9d 2588 record_full_insn_max_num = record_full_insn_num;
d02ed0bb 2589 warning (_("Auto increase record/replay buffer limit to %d."),
88d1aa9d 2590 record_full_insn_max_num);
d02ed0bb
MM
2591 }
2592
2593 /* Succeeded. */
2594 printf_filtered (_("Restored records from core file %s.\n"),
2595 bfd_get_filename (core_bfd));
2596
2597 print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC);
2598}
2599
2600/* bfdcore_write -- write bytes into a core file section. */
2601
2602static inline void
2603bfdcore_write (bfd *obfd, asection *osec, void *buf, int len, int *offset)
2604{
2605 int ret = bfd_set_section_contents (obfd, osec, buf, *offset, len);
2606
2607 if (ret)
2608 *offset += len;
2609 else
2610 error (_("Failed to write %d bytes to core file %s ('%s')."),
2611 len, bfd_get_filename (obfd),
2612 bfd_errmsg (bfd_get_error ()));
2613}
2614
2615/* Restore the execution log from a file. We use a modified elf
2616 corefile format, with an extra section for our data. */
2617
2618static void
88d1aa9d 2619cmd_record_full_restore (char *args, int from_tty)
d02ed0bb
MM
2620{
2621 core_file_command (args, from_tty);
88d1aa9d 2622 record_full_open (args, from_tty);
d02ed0bb
MM
2623}
2624
2625static void
88d1aa9d 2626record_full_save_cleanups (void *data)
d02ed0bb
MM
2627{
2628 bfd *obfd = data;
2629 char *pathname = xstrdup (bfd_get_filename (obfd));
2630
2631 gdb_bfd_unref (obfd);
2632 unlink (pathname);
2633 xfree (pathname);
2634}
2635
2636/* Save the execution log to a file. We use a modified elf corefile
2637 format, with an extra section for our data. */
2638
2639static void
88d1aa9d 2640record_full_save (char *recfilename)
d02ed0bb 2641{
88d1aa9d 2642 struct record_full_entry *cur_record_full_list;
d02ed0bb
MM
2643 uint32_t magic;
2644 struct regcache *regcache;
2645 struct gdbarch *gdbarch;
2646 struct cleanup *old_cleanups;
2647 struct cleanup *set_cleanups;
2648 bfd *obfd;
2649 int save_size = 0;
2650 asection *osec = NULL;
2651 int bfd_offset = 0;
2652
2653 /* Open the save file. */
2654 if (record_debug)
2655 fprintf_unfiltered (gdb_stdlog, "Saving execution log to core file '%s'\n",
2656 recfilename);
2657
2658 /* Open the output file. */
2659 obfd = create_gcore_bfd (recfilename);
88d1aa9d 2660 old_cleanups = make_cleanup (record_full_save_cleanups, obfd);
d02ed0bb 2661
88d1aa9d
MM
2662 /* Save the current record entry to "cur_record_full_list". */
2663 cur_record_full_list = record_full_list;
d02ed0bb
MM
2664
2665 /* Get the values of regcache and gdbarch. */
2666 regcache = get_current_regcache ();
2667 gdbarch = get_regcache_arch (regcache);
2668
2669 /* Disable the GDB operation record. */
25ea693b 2670 set_cleanups = record_full_gdb_operation_disable_set ();
d02ed0bb
MM
2671
2672 /* Reverse execute to the begin of record list. */
2673 while (1)
2674 {
2675 /* Check for beginning and end of log. */
88d1aa9d 2676 if (record_full_list == &record_full_first)
d02ed0bb
MM
2677 break;
2678
88d1aa9d 2679 record_full_exec_insn (regcache, gdbarch, record_full_list);
d02ed0bb 2680
88d1aa9d
MM
2681 if (record_full_list->prev)
2682 record_full_list = record_full_list->prev;
d02ed0bb
MM
2683 }
2684
2685 /* Compute the size needed for the extra bfd section. */
2686 save_size = 4; /* magic cookie */
88d1aa9d
MM
2687 for (record_full_list = record_full_first.next; record_full_list;
2688 record_full_list = record_full_list->next)
2689 switch (record_full_list->type)
d02ed0bb 2690 {
88d1aa9d 2691 case record_full_end:
d02ed0bb
MM
2692 save_size += 1 + 4 + 4;
2693 break;
88d1aa9d
MM
2694 case record_full_reg:
2695 save_size += 1 + 4 + record_full_list->u.reg.len;
d02ed0bb 2696 break;
88d1aa9d
MM
2697 case record_full_mem:
2698 save_size += 1 + 4 + 8 + record_full_list->u.mem.len;
d02ed0bb
MM
2699 break;
2700 }
2701
2702 /* Make the new bfd section. */
2703 osec = bfd_make_section_anyway_with_flags (obfd, "precord",
2704 SEC_HAS_CONTENTS
2705 | SEC_READONLY);
2706 if (osec == NULL)
2707 error (_("Failed to create 'precord' section for corefile %s: %s"),
2708 recfilename,
2709 bfd_errmsg (bfd_get_error ()));
2710 bfd_set_section_size (obfd, osec, save_size);
2711 bfd_set_section_vma (obfd, osec, 0);
2712 bfd_set_section_alignment (obfd, osec, 0);
2713 bfd_section_lma (obfd, osec) = 0;
2714
2715 /* Save corefile state. */
2716 write_gcore_file (obfd);
2717
2718 /* Write out the record log. */
2719 /* Write the magic code. */
88d1aa9d 2720 magic = RECORD_FULL_FILE_MAGIC;
d02ed0bb
MM
2721 if (record_debug)
2722 fprintf_unfiltered (gdb_stdlog,
2723 " Writing 4-byte magic cookie "
88d1aa9d 2724 "RECORD_FULL_FILE_MAGIC (0x%s)\n",
d02ed0bb
MM
2725 phex_nz (magic, 4));
2726 bfdcore_write (obfd, osec, &magic, sizeof (magic), &bfd_offset);
2727
2728 /* Save the entries to recfd and forward execute to the end of
2729 record list. */
88d1aa9d 2730 record_full_list = &record_full_first;
d02ed0bb
MM
2731 while (1)
2732 {
2733 /* Save entry. */
88d1aa9d 2734 if (record_full_list != &record_full_first)
d02ed0bb
MM
2735 {
2736 uint8_t type;
2737 uint32_t regnum, len, signal, count;
2738 uint64_t addr;
2739
88d1aa9d 2740 type = record_full_list->type;
d02ed0bb
MM
2741 bfdcore_write (obfd, osec, &type, sizeof (type), &bfd_offset);
2742
88d1aa9d 2743 switch (record_full_list->type)
d02ed0bb 2744 {
88d1aa9d 2745 case record_full_reg: /* reg */
d02ed0bb
MM
2746 if (record_debug)
2747 fprintf_unfiltered (gdb_stdlog,
2748 " Writing register %d (1 "
2749 "plus %lu plus %d bytes)\n",
88d1aa9d 2750 record_full_list->u.reg.num,
d02ed0bb 2751 (unsigned long) sizeof (regnum),
88d1aa9d 2752 record_full_list->u.reg.len);
d02ed0bb
MM
2753
2754 /* Write regnum. */
88d1aa9d 2755 regnum = netorder32 (record_full_list->u.reg.num);
d02ed0bb
MM
2756 bfdcore_write (obfd, osec, &regnum,
2757 sizeof (regnum), &bfd_offset);
2758
2759 /* Write regval. */
88d1aa9d
MM
2760 bfdcore_write (obfd, osec,
2761 record_full_get_loc (record_full_list),
2762 record_full_list->u.reg.len, &bfd_offset);
d02ed0bb
MM
2763 break;
2764
88d1aa9d 2765 case record_full_mem: /* mem */
d02ed0bb
MM
2766 if (record_debug)
2767 fprintf_unfiltered (gdb_stdlog,
2768 " Writing memory %s (1 plus "
2769 "%lu plus %lu plus %d bytes)\n",
2770 paddress (gdbarch,
88d1aa9d 2771 record_full_list->u.mem.addr),
d02ed0bb
MM
2772 (unsigned long) sizeof (addr),
2773 (unsigned long) sizeof (len),
88d1aa9d 2774 record_full_list->u.mem.len);
d02ed0bb
MM
2775
2776 /* Write memlen. */
88d1aa9d 2777 len = netorder32 (record_full_list->u.mem.len);
d02ed0bb
MM
2778 bfdcore_write (obfd, osec, &len, sizeof (len), &bfd_offset);
2779
2780 /* Write memaddr. */
88d1aa9d 2781 addr = netorder64 (record_full_list->u.mem.addr);
d02ed0bb
MM
2782 bfdcore_write (obfd, osec, &addr,
2783 sizeof (addr), &bfd_offset);
2784
2785 /* Write memval. */
88d1aa9d
MM
2786 bfdcore_write (obfd, osec,
2787 record_full_get_loc (record_full_list),
2788 record_full_list->u.mem.len, &bfd_offset);
d02ed0bb
MM
2789 break;
2790
88d1aa9d 2791 case record_full_end:
d02ed0bb
MM
2792 if (record_debug)
2793 fprintf_unfiltered (gdb_stdlog,
88d1aa9d 2794 " Writing record_full_end (1 + "
d02ed0bb
MM
2795 "%lu + %lu bytes)\n",
2796 (unsigned long) sizeof (signal),
2797 (unsigned long) sizeof (count));
2798 /* Write signal value. */
88d1aa9d 2799 signal = netorder32 (record_full_list->u.end.sigval);
d02ed0bb
MM
2800 bfdcore_write (obfd, osec, &signal,
2801 sizeof (signal), &bfd_offset);
2802
2803 /* Write insn count. */
88d1aa9d 2804 count = netorder32 (record_full_list->u.end.insn_num);
d02ed0bb
MM
2805 bfdcore_write (obfd, osec, &count,
2806 sizeof (count), &bfd_offset);
2807 break;
2808 }
2809 }
2810
2811 /* Execute entry. */
88d1aa9d 2812 record_full_exec_insn (regcache, gdbarch, record_full_list);
d02ed0bb 2813
88d1aa9d
MM
2814 if (record_full_list->next)
2815 record_full_list = record_full_list->next;
d02ed0bb
MM
2816 else
2817 break;
2818 }
2819
88d1aa9d 2820 /* Reverse execute to cur_record_full_list. */
d02ed0bb
MM
2821 while (1)
2822 {
2823 /* Check for beginning and end of log. */
88d1aa9d 2824 if (record_full_list == cur_record_full_list)
d02ed0bb
MM
2825 break;
2826
88d1aa9d 2827 record_full_exec_insn (regcache, gdbarch, record_full_list);
d02ed0bb 2828
88d1aa9d
MM
2829 if (record_full_list->prev)
2830 record_full_list = record_full_list->prev;
d02ed0bb
MM
2831 }
2832
2833 do_cleanups (set_cleanups);
2834 gdb_bfd_unref (obfd);
2835 discard_cleanups (old_cleanups);
2836
2837 /* Succeeded. */
2838 printf_filtered (_("Saved core file %s with execution log.\n"),
2839 recfilename);
2840}
2841
88d1aa9d 2842/* record_full_goto_insn -- rewind the record log (forward or backward,
d02ed0bb
MM
2843 depending on DIR) to the given entry, changing the program state
2844 correspondingly. */
2845
2846static void
88d1aa9d
MM
2847record_full_goto_insn (struct record_full_entry *entry,
2848 enum exec_direction_kind dir)
d02ed0bb 2849{
25ea693b 2850 struct cleanup *set_cleanups = record_full_gdb_operation_disable_set ();
d02ed0bb
MM
2851 struct regcache *regcache = get_current_regcache ();
2852 struct gdbarch *gdbarch = get_regcache_arch (regcache);
2853
2854 /* Assume everything is valid: we will hit the entry,
2855 and we will not hit the end of the recording. */
2856
2857 if (dir == EXEC_FORWARD)
88d1aa9d 2858 record_full_list = record_full_list->next;
d02ed0bb
MM
2859
2860 do
2861 {
88d1aa9d 2862 record_full_exec_insn (regcache, gdbarch, record_full_list);
d02ed0bb 2863 if (dir == EXEC_REVERSE)
88d1aa9d 2864 record_full_list = record_full_list->prev;
d02ed0bb 2865 else
88d1aa9d
MM
2866 record_full_list = record_full_list->next;
2867 } while (record_full_list != entry);
d02ed0bb
MM
2868 do_cleanups (set_cleanups);
2869}
2870
2871/* Alias for "target record-full". */
2872
2873static void
88d1aa9d 2874cmd_record_full_start (char *args, int from_tty)
d02ed0bb
MM
2875{
2876 execute_command ("target record-full", from_tty);
2877}
2878
2879static void
88d1aa9d
MM
2880set_record_full_insn_max_num (char *args, int from_tty,
2881 struct cmd_list_element *c)
d02ed0bb 2882{
88d1aa9d
MM
2883 if (record_full_insn_num > record_full_insn_max_num
2884 && record_full_insn_max_num)
d02ed0bb 2885 {
88d1aa9d
MM
2886 /* Count down record_full_insn_num while releasing records from list. */
2887 while (record_full_insn_num > record_full_insn_max_num)
d02ed0bb 2888 {
88d1aa9d
MM
2889 record_full_list_release_first ();
2890 record_full_insn_num--;
d02ed0bb
MM
2891 }
2892 }
2893}
2894
2895/* The "set record full" command. */
2896
2897static void
2898set_record_full_command (char *args, int from_tty)
2899{
2900 printf_unfiltered (_("\"set record full\" must be followed "
2901 "by an apporpriate subcommand.\n"));
2902 help_list (set_record_full_cmdlist, "set record full ", all_commands,
2903 gdb_stdout);
2904}
2905
2906/* The "show record full" command. */
2907
2908static void
2909show_record_full_command (char *args, int from_tty)
2910{
2911 cmd_show_list (show_record_full_cmdlist, from_tty, "");
2912}
2913
2914/* Provide a prototype to silence -Wmissing-prototypes. */
2915extern initialize_file_ftype _initialize_record_full;
2916
2917void
2918_initialize_record_full (void)
2919{
2920 struct cmd_list_element *c;
2921
88d1aa9d
MM
2922 /* Init record_full_first. */
2923 record_full_first.prev = NULL;
2924 record_full_first.next = NULL;
2925 record_full_first.type = record_full_end;
d02ed0bb 2926
88d1aa9d
MM
2927 init_record_full_ops ();
2928 add_target (&record_full_ops);
2929 add_deprecated_target_alias (&record_full_ops, "record");
2930 init_record_full_core_ops ();
2931 add_target (&record_full_core_ops);
d02ed0bb 2932
88d1aa9d 2933 add_prefix_cmd ("full", class_obscure, cmd_record_full_start,
d02ed0bb
MM
2934 _("Start full execution recording."), &record_full_cmdlist,
2935 "record full ", 0, &record_cmdlist);
2936
88d1aa9d 2937 c = add_cmd ("restore", class_obscure, cmd_record_full_restore,
d02ed0bb
MM
2938 _("Restore the execution log from a file.\n\
2939Argument is filename. File must be created with 'record save'."),
2940 &record_full_cmdlist);
2941 set_cmd_completer (c, filename_completer);
2942
2943 /* Deprecate the old version without "full" prefix. */
2944 c = add_alias_cmd ("restore", "full restore", class_obscure, 1,
2945 &record_cmdlist);
2946 set_cmd_completer (c, filename_completer);
2947 deprecate_cmd (c, "record full restore");
2948
2949 add_prefix_cmd ("full", class_support, set_record_full_command,
2950 _("Set record options"), &set_record_full_cmdlist,
2951 "set record full ", 0, &set_record_cmdlist);
2952
2953 add_prefix_cmd ("full", class_support, show_record_full_command,
2954 _("Show record options"), &show_record_full_cmdlist,
2955 "show record full ", 0, &show_record_cmdlist);
2956
2957 /* Record instructions number limit command. */
2958 add_setshow_boolean_cmd ("stop-at-limit", no_class,
88d1aa9d 2959 &record_full_stop_at_limit, _("\
d02ed0bb
MM
2960Set whether record/replay stops when record/replay buffer becomes full."), _("\
2961Show whether record/replay stops when record/replay buffer becomes full."),
2962 _("Default is ON.\n\
2963When ON, if the record/replay buffer becomes full, ask user what to do.\n\
2964When OFF, if the record/replay buffer becomes full,\n\
2965delete the oldest recorded instruction to make room for each new one."),
2966 NULL, NULL,
2967 &set_record_full_cmdlist, &show_record_full_cmdlist);
2968
2969 c = add_alias_cmd ("stop-at-limit", "full stop-at-limit", no_class, 1,
2970 &set_record_cmdlist);
2971 deprecate_cmd (c, "set record full stop-at-limit");
2972
2973 c = add_alias_cmd ("stop-at-limit", "full stop-at-limit", no_class, 1,
2974 &show_record_cmdlist);
2975 deprecate_cmd (c, "show record full stop-at-limit");
2976
88d1aa9d
MM
2977 add_setshow_uinteger_cmd ("insn-number-max", no_class,
2978 &record_full_insn_max_num,
d02ed0bb
MM
2979 _("Set record/replay buffer limit."),
2980 _("Show record/replay buffer limit."), _("\
2981Set the maximum number of instructions to be stored in the\n\
2982record/replay buffer. Zero means unlimited. Default is 200000."),
88d1aa9d 2983 set_record_full_insn_max_num,
d02ed0bb
MM
2984 NULL, &set_record_full_cmdlist,
2985 &show_record_full_cmdlist);
2986
2987 c = add_alias_cmd ("insn-number-max", "full insn-number-max", no_class, 1,
2988 &set_record_cmdlist);
2989 deprecate_cmd (c, "set record full insn-number-max");
2990
2991 c = add_alias_cmd ("insn-number-max", "full insn-number-max", no_class, 1,
2992 &show_record_cmdlist);
2993 deprecate_cmd (c, "show record full insn-number-max");
2994
88d1aa9d 2995 add_setshow_boolean_cmd ("memory-query", no_class,
25ea693b 2996 &record_full_memory_query, _("\
d02ed0bb
MM
2997Set whether query if PREC cannot record memory change of next instruction."),
2998 _("\
2999Show whether query if PREC cannot record memory change of next instruction."),
3000 _("\
3001Default is OFF.\n\
3002When ON, query if PREC cannot record memory change of next instruction."),
3003 NULL, NULL,
88d1aa9d
MM
3004 &set_record_full_cmdlist,
3005 &show_record_full_cmdlist);
d02ed0bb
MM
3006
3007 c = add_alias_cmd ("memory-query", "full memory-query", no_class, 1,
3008 &set_record_cmdlist);
3009 deprecate_cmd (c, "set record full memory-query");
3010
3011 c = add_alias_cmd ("memory-query", "full memory-query", no_class, 1,
3012 &show_record_cmdlist);
3013 deprecate_cmd (c, "show record full memory-query");
3014}