-int record_debug = 0;
-
-/* If true, query if PREC cannot record memory
- change of next instruction. */
-int record_memory_query = 0;
-
-struct record_core_buf_entry
-{
- struct record_core_buf_entry *prev;
- struct target_section *p;
- bfd_byte *buf;
-};
-
-/* Record buf with core target. */
-static gdb_byte *record_core_regbuf = NULL;
-static struct target_section *record_core_start;
-static struct target_section *record_core_end;
-static struct record_core_buf_entry *record_core_buf_list = NULL;
-
-/* The following variables are used for managing the linked list that
- represents the execution log.
-
- record_first is the anchor that holds down the beginning of the list.
-
- record_list serves two functions:
- 1) In record mode, it anchors the end of the list.
- 2) In replay mode, it traverses the list and points to
- the next instruction that must be emulated.
-
- record_arch_list_head and record_arch_list_tail are used to manage
- a separate list, which is used to build up the change elements of
- the currently executing instruction during record mode. When this
- instruction has been completely annotated in the "arch list", it
- will be appended to the main execution log. */
-
-static struct record_entry record_first;
-static struct record_entry *record_list = &record_first;
-static struct record_entry *record_arch_list_head = NULL;
-static struct record_entry *record_arch_list_tail = NULL;
-
-/* 1 ask user. 0 auto delete the last struct record_entry. */
-static int record_stop_at_limit = 1;
-/* Maximum allowed number of insns in execution log. */
-static unsigned int record_insn_max_num = DEFAULT_RECORD_INSN_MAX_NUM;
-/* Actual count of insns presently in execution log. */
-static int record_insn_num = 0;
-/* Count of insns logged so far (may be larger
- than count of insns presently in execution log). */
-static ULONGEST record_insn_count;
-
-/* The target_ops of process record. */
-static struct target_ops record_ops;
-static struct target_ops record_core_ops;
-
-/* The beneath function pointers. */
-static struct target_ops *record_beneath_to_resume_ops;
-static void (*record_beneath_to_resume) (struct target_ops *, ptid_t, int,
- enum target_signal);
-static struct target_ops *record_beneath_to_wait_ops;
-static ptid_t (*record_beneath_to_wait) (struct target_ops *, ptid_t,
- struct target_waitstatus *,
- int);
-static struct target_ops *record_beneath_to_store_registers_ops;
-static void (*record_beneath_to_store_registers) (struct target_ops *,
- struct regcache *,
- int regno);
-static struct target_ops *record_beneath_to_xfer_partial_ops;
-static LONGEST (*record_beneath_to_xfer_partial) (struct target_ops *ops,
- enum target_object object,
- const char *annex,
- gdb_byte *readbuf,
- const gdb_byte *writebuf,
- ULONGEST offset,
- LONGEST len);
-static int (*record_beneath_to_insert_breakpoint) (struct gdbarch *,
- struct bp_target_info *);
-static int (*record_beneath_to_remove_breakpoint) (struct gdbarch *,
- struct bp_target_info *);
-static int (*record_beneath_to_stopped_by_watchpoint) (void);
-static int (*record_beneath_to_stopped_data_address) (struct target_ops *,
- CORE_ADDR *);
-
-/* Alloc and free functions for record_reg, record_mem, and record_end
- entries. */
-
-/* Alloc a record_reg record entry. */
-
-static inline struct record_entry *
-record_reg_alloc (struct regcache *regcache, int regnum)
-{
- struct record_entry *rec;
- struct gdbarch *gdbarch = get_regcache_arch (regcache);
-
- rec = (struct record_entry *) xcalloc (1, sizeof (struct record_entry));
- rec->type = record_reg;
- rec->u.reg.num = regnum;
- rec->u.reg.len = register_size (gdbarch, regnum);
- if (rec->u.reg.len > sizeof (rec->u.reg.u.buf))
- rec->u.reg.u.ptr = (gdb_byte *) xmalloc (rec->u.reg.len);
-
- return rec;
-}
-
-/* Free a record_reg record entry. */
-
-static inline void
-record_reg_release (struct record_entry *rec)
-{
- gdb_assert (rec->type == record_reg);
- if (rec->u.reg.len > sizeof (rec->u.reg.u.buf))
- xfree (rec->u.reg.u.ptr);
- xfree (rec);
-}
-
-/* Alloc a record_mem record entry. */
-
-static inline struct record_entry *
-record_mem_alloc (CORE_ADDR addr, int len)
-{
- struct record_entry *rec;
-
- rec = (struct record_entry *) xcalloc (1, sizeof (struct record_entry));
- rec->type = record_mem;
- rec->u.mem.addr = addr;
- rec->u.mem.len = len;
- if (rec->u.mem.len > sizeof (rec->u.mem.u.buf))
- rec->u.mem.u.ptr = (gdb_byte *) xmalloc (len);
-
- return rec;
-}
-
-/* Free a record_mem record entry. */
-
-static inline void
-record_mem_release (struct record_entry *rec)
-{
- gdb_assert (rec->type == record_mem);
- if (rec->u.mem.len > sizeof (rec->u.mem.u.buf))
- xfree (rec->u.mem.u.ptr);
- xfree (rec);
-}
-
-/* Alloc a record_end record entry. */
-
-static inline struct record_entry *
-record_end_alloc (void)
-{
- struct record_entry *rec;
-
- rec = (struct record_entry *) xcalloc (1, sizeof (struct record_entry));
- rec->type = record_end;
-
- return rec;
-}
-
-/* Free a record_end record entry. */
-
-static inline void
-record_end_release (struct record_entry *rec)
-{
- xfree (rec);
-}
-
-/* Free one record entry, any type.
- Return entry->type, in case caller wants to know. */
-
-static inline enum record_type
-record_entry_release (struct record_entry *rec)
-{
- enum record_type type = rec->type;
-
- switch (type) {
- case record_reg:
- record_reg_release (rec);
- break;
- case record_mem:
- record_mem_release (rec);
- break;
- case record_end:
- record_end_release (rec);
- break;
- }
- return type;
-}
-
-/* Free all record entries in list pointed to by REC. */
-
-static void
-record_list_release (struct record_entry *rec)
-{
- if (!rec)
- return;
-
- while (rec->next)
- rec = rec->next;
-
- while (rec->prev)
- {
- rec = rec->prev;
- record_entry_release (rec->next);
- }
-
- if (rec == &record_first)
- {
- record_insn_num = 0;
- record_first.next = NULL;
- }
- else
- record_entry_release (rec);
-}
-
-/* Free all record entries forward of the given list position. */
-
-static void
-record_list_release_following (struct record_entry *rec)
-{
- struct record_entry *tmp = rec->next;
-
- rec->next = NULL;
- while (tmp)
- {
- rec = tmp->next;
- if (record_entry_release (tmp) == record_end)
- {
- record_insn_num--;
- record_insn_count--;
- }
- tmp = rec;
- }
-}
-
-/* Delete the first instruction from the beginning of the log, to make
- room for adding a new instruction at the end of the log.
-
- Note -- this function does not modify record_insn_num. */
-
-static void
-record_list_release_first (void)
-{
- struct record_entry *tmp;
-
- if (!record_first.next)
- return;
-
- /* Loop until a record_end. */
- while (1)
- {
- /* Cut record_first.next out of the linked list. */
- tmp = record_first.next;
- record_first.next = tmp->next;
- tmp->next->prev = &record_first;
-
- /* tmp is now isolated, and can be deleted. */
- if (record_entry_release (tmp) == record_end)
- break; /* End loop at first record_end. */
-
- if (!record_first.next)
- {
- gdb_assert (record_insn_num == 1);
- break; /* End loop when list is empty. */
- }
- }
-}
-
-/* Add a struct record_entry to record_arch_list. */
-
-static void
-record_arch_list_add (struct record_entry *rec)
-{
- if (record_debug > 1)
- fprintf_unfiltered (gdb_stdlog,
- "Process record: record_arch_list_add %s.\n",
- host_address_to_string (rec));
-
- if (record_arch_list_tail)
- {
- record_arch_list_tail->next = rec;
- rec->prev = record_arch_list_tail;
- record_arch_list_tail = rec;
- }
- else
- {
- record_arch_list_head = rec;
- record_arch_list_tail = rec;
- }
-}
-
-/* Return the value storage location of a record entry. */
-static inline gdb_byte *
-record_get_loc (struct record_entry *rec)
-{
- switch (rec->type) {
- case record_mem:
- if (rec->u.mem.len > sizeof (rec->u.mem.u.buf))
- return rec->u.mem.u.ptr;
- else
- return rec->u.mem.u.buf;
- case record_reg:
- if (rec->u.reg.len > sizeof (rec->u.reg.u.buf))
- return rec->u.reg.u.ptr;
- else
- return rec->u.reg.u.buf;
- case record_end:
- default:
- gdb_assert_not_reached ("unexpected record_entry type");
- return NULL;
- }
-}
-
-/* Record the value of a register NUM to record_arch_list. */
-
-int
-record_arch_list_add_reg (struct regcache *regcache, int regnum)
-{
- struct record_entry *rec;
-
- if (record_debug > 1)
- fprintf_unfiltered (gdb_stdlog,
- "Process record: add register num = %d to "
- "record list.\n",
- regnum);
-
- rec = record_reg_alloc (regcache, regnum);
-
- regcache_raw_read (regcache, regnum, record_get_loc (rec));
-
- record_arch_list_add (rec);
-
- return 0;
-}
-
-/* Record the value of a region of memory whose address is ADDR and
- length is LEN to record_arch_list. */
-
-int
-record_arch_list_add_mem (CORE_ADDR addr, int len)
-{
- struct record_entry *rec;
-
- if (record_debug > 1)
- fprintf_unfiltered (gdb_stdlog,
- "Process record: add mem addr = %s len = %d to "
- "record list.\n",
- paddress (target_gdbarch, addr), len);
-
- if (!addr) /* FIXME: Why? Some arch must permit it... */
- return 0;
-
- rec = record_mem_alloc (addr, len);
-
- if (target_read_memory (addr, record_get_loc (rec), len))
- {
- if (record_debug)
- fprintf_unfiltered (gdb_stdlog,
- "Process record: error reading memory at "
- "addr = %s len = %d.\n",
- paddress (target_gdbarch, addr), len);
- record_mem_release (rec);
- return -1;
- }
-
- record_arch_list_add (rec);
-
- return 0;
-}
-
-/* Add a record_end type struct record_entry to record_arch_list. */
-
-int
-record_arch_list_add_end (void)
-{
- struct record_entry *rec;
-
- if (record_debug > 1)
- fprintf_unfiltered (gdb_stdlog,
- "Process record: add end to arch list.\n");
-
- rec = record_end_alloc ();
- rec->u.end.sigval = TARGET_SIGNAL_0;
- rec->u.end.insn_num = ++record_insn_count;
-
- record_arch_list_add (rec);
-
- return 0;
-}
-
-static void
-record_check_insn_num (int set_terminal)
-{
- if (record_insn_max_num)
- {
- gdb_assert (record_insn_num <= record_insn_max_num);
- if (record_insn_num == record_insn_max_num)
- {
- /* Ask user what to do. */
- if (record_stop_at_limit)
- {
- int q;
-
- if (set_terminal)
- target_terminal_ours ();
- q = yquery (_("Do you want to auto delete previous execution "
- "log entries when record/replay buffer becomes "
- "full (record stop-at-limit)?"));
- if (set_terminal)
- target_terminal_inferior ();
- if (q)
- record_stop_at_limit = 0;
- else
- error (_("Process record: stopped by user."));
- }
- }
- }
-}