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