diff options
author | Tom Tromey <tromey@redhat.com> | 2013-07-12 13:00:34 -0600 |
---|---|---|
committer | Tom Tromey <tromey@redhat.com> | 2014-02-19 07:45:25 -0700 |
commit | 6b84065d0e65d86f5c38bf139ec68101ea65d802 (patch) | |
tree | 5ea660c51169821ad323fe79ab5abcae09a45dcd /gdb/record-full.c | |
parent | 1101cb7b3b05d857c8bccc848bc5664155c82730 (diff) | |
download | binutils-gdb-6b84065d0e65d86f5c38bf139ec68101ea65d802.tar.gz |
add target method delegation
This patch replaces some code in the record targets with target method
delegation.
record-full.c stores pointers to many target methods when the record
target is pushed. Then it later delegates some calls via these. This
is wrong because it violates the target stack contract. In particular
it is ok to unpush a target at any stratum, but record-full does not
keep track of this, so it could potentially call into an unpushed
target.
This patch fixes the problem by using the newly-introduced generic
approach to target delegation for the methods in question.
2014-02-19 Tom Tromey <tromey@redhat.com>
* record-full.c (record_full_beneath_to_resume_ops)
(record_full_beneath_to_resume, record_full_beneath_to_wait_ops)
(record_full_beneath_to_wait)
(record_full_beneath_to_store_registers_ops)
(record_full_beneath_to_store_registers)
(record_full_beneath_to_xfer_partial_ops)
(record_full_beneath_to_xfer_partial)
(record_full_beneath_to_insert_breakpoint_ops)
(record_full_beneath_to_insert_breakpoint)
(record_full_beneath_to_remove_breakpoint_ops)
(record_full_beneath_to_remove_breakpoint)
(record_full_beneath_to_stopped_by_watchpoint)
(record_full_beneath_to_stopped_data_address)
(record_full_beneath_to_async, tmp_to_resume_ops, tmp_to_resume)
(tmp_to_wait_ops, tmp_to_wait, tmp_to_store_registers_ops)
(tmp_to_store_registers, tmp_to_xfer_partial_ops)
(tmp_to_xfer_partial, tmp_to_instmp_to_insert_breakpoint_ops)
(tmp_to_insert_breakpoint, tmp_to_remove_breakpoint_ops)
(tmp_to_remove_breakpoint, tmp_to_stopped_by_watchpoint)
(tmp_to_stopped_data_address, tmp_to_async): Remove.
(record_full_open_1, record_full_open): Update. Use RECORD_IS_USED.
(record_full_resume, record_full_wait_1)
(record_full_stopped_by_watchpoint, record_full_stopped_data_address)
(record_full_store_registers, record_full_xfer_partial)
(record_full_insert_breakpoint, record_full_remove_breakpoint)
(record_full_async, record_full_core_xfer_partial): Use target
delegation.
* target-delegates.c: Rebuild.
* target.c (current_xfer_partial): Remove.
(update_current_target): Do not INHERIT or de_fault
to_insert_breakpoint, to_remove_breakpoint,
to_stopped_data_address, to_stopped_by_watchpoint, to_can_async_p,
to_is_async_p, to_async. Do not set to_xfer_partial field.
(default_xfer_partial): Simplify.
(current_xfer_partial): Remove.
(target_wait, target_resume): Simplify.
(find_default_can_async_p, find_default_is_async_p): Update.
(init_dummy_target): Don't set to_can_async_p, to_is_async_p,
to_xfer_partial, to_stopped_by_watchpoint,
to_stopped_data_address.
(target_store_registers): Simplify.
(forward_target_remove_breakpoint)
(forward_target_insert_breakpoint): Remove.
(target_remove_breakpoint, target_insert_breakpoint)
(debug_to_insert_breakpoint, debug_to_remove_breakpoint): Update.
* target.h (struct target_ops) <to_resume, to_wait,
to_store_registers, to_insert_breakpoint, to_remove_breakpoint,
to_stopped_by_watchpoint, to_stopped_data_address, to_can_async_p,
to_is_async_p, to_async, to_xfer_partial>: Add TARGET_DEFAULT
markup.
(forward_target_remove_breakpoint)
(forward_target_insert_breakpoint): Remove.
* record-btrace.c (record_btrace_remove_breakpoint): Delegate
directly.
(record_btrace_insert_breakpoint): Delegate directly.
Diffstat (limited to 'gdb/record-full.c')
-rw-r--r-- | gdb/record-full.c | 222 |
1 files changed, 22 insertions, 200 deletions
diff --git a/gdb/record-full.c b/gdb/record-full.c index 1d3750be612..0452dcadf5f 100644 --- a/gdb/record-full.c +++ b/gdb/record-full.c @@ -228,38 +228,6 @@ static struct cmd_list_element *show_record_full_cmdlist; /* Command list for "record full". */ static struct cmd_list_element *record_full_cmdlist; -/* The beneath function pointers. */ -static struct target_ops *record_full_beneath_to_resume_ops; -static void (*record_full_beneath_to_resume) (struct target_ops *, ptid_t, int, - enum gdb_signal); -static struct target_ops *record_full_beneath_to_wait_ops; -static ptid_t (*record_full_beneath_to_wait) (struct target_ops *, ptid_t, - struct target_waitstatus *, - int); -static struct target_ops *record_full_beneath_to_store_registers_ops; -static void (*record_full_beneath_to_store_registers) (struct target_ops *, - struct regcache *, - int regno); -static struct target_ops *record_full_beneath_to_xfer_partial_ops; -static target_xfer_partial_ftype *record_full_beneath_to_xfer_partial; -static int - (*record_full_beneath_to_insert_breakpoint) (struct target_ops *, - struct gdbarch *, - struct bp_target_info *); -static struct target_ops *record_full_beneath_to_insert_breakpoint_ops; -static int - (*record_full_beneath_to_remove_breakpoint) (struct target_ops *, - struct gdbarch *, - struct bp_target_info *); -static struct target_ops *record_full_beneath_to_remove_breakpoint_ops; -static int (*record_full_beneath_to_stopped_by_watchpoint) (struct target_ops *); -static int (*record_full_beneath_to_stopped_data_address) (struct target_ops *, - CORE_ADDR *); -static void - (*record_full_beneath_to_async) (struct target_ops *, - void (*) (enum inferior_event_type, void *), - void *); - static void record_full_goto_insn (struct record_full_entry *entry, enum exec_direction_kind dir); static void record_full_save (const char *recfilename); @@ -806,30 +774,6 @@ record_full_exec_insn (struct regcache *regcache, } } -static struct target_ops *tmp_to_resume_ops; -static void (*tmp_to_resume) (struct target_ops *, ptid_t, int, - enum gdb_signal); -static struct target_ops *tmp_to_wait_ops; -static ptid_t (*tmp_to_wait) (struct target_ops *, ptid_t, - struct target_waitstatus *, - int); -static struct target_ops *tmp_to_store_registers_ops; -static void (*tmp_to_store_registers) (struct target_ops *, - struct regcache *, - int regno); -static struct target_ops *tmp_to_xfer_partial_ops; -static target_xfer_partial_ftype *tmp_to_xfer_partial; -static int (*tmp_to_insert_breakpoint) (struct target_ops *, struct gdbarch *, - struct bp_target_info *); -static struct target_ops *tmp_to_insert_breakpoint_ops; -static int (*tmp_to_remove_breakpoint) (struct target_ops *, struct gdbarch *, - struct bp_target_info *); -static struct target_ops *tmp_to_remove_breakpoint_ops; -static int (*tmp_to_stopped_by_watchpoint) (struct target_ops *); -static int (*tmp_to_stopped_data_address) (struct target_ops *, CORE_ADDR *); -static void (*tmp_to_async) (struct target_ops *, - void (*) (enum inferior_event_type, void *), void *); - static void record_full_restore (void); /* Asynchronous signal handle registered as event loop source for when @@ -892,26 +836,6 @@ record_full_open_1 (char *name, int from_tty) error (_("Process record: the current architecture doesn't support " "record function.")); - if (!tmp_to_resume) - error (_("Could not find 'to_resume' method on the target stack.")); - if (!tmp_to_wait) - error (_("Could not find 'to_wait' method on the target stack.")); - if (!tmp_to_store_registers) - error (_("Could not find 'to_store_registers' " - "method on the target stack.")); - if (!tmp_to_insert_breakpoint) - error (_("Could not find 'to_insert_breakpoint' " - "method on the target stack.")); - if (!tmp_to_remove_breakpoint) - error (_("Could not find 'to_remove_breakpoint' " - "method on the target stack.")); - if (!tmp_to_stopped_by_watchpoint) - error (_("Could not find 'to_stopped_by_watchpoint' " - "method on the target stack.")); - if (!tmp_to_stopped_data_address) - error (_("Could not find 'to_stopped_data_address' " - "method on the target stack.")); - push_target (&record_full_ops); } @@ -929,89 +853,12 @@ record_full_open (char *name, int from_tty) record_preopen (); - /* Reset the tmp beneath pointers. */ - tmp_to_resume_ops = NULL; - tmp_to_resume = NULL; - tmp_to_wait_ops = NULL; - tmp_to_wait = NULL; - tmp_to_store_registers_ops = NULL; - tmp_to_store_registers = NULL; - tmp_to_xfer_partial_ops = NULL; - tmp_to_xfer_partial = NULL; - tmp_to_insert_breakpoint = NULL; - tmp_to_remove_breakpoint = NULL; - tmp_to_stopped_by_watchpoint = NULL; - tmp_to_stopped_data_address = NULL; - tmp_to_async = NULL; - tmp_to_insert_breakpoint_ops = NULL; - tmp_to_remove_breakpoint_ops = NULL; - - /* Set the beneath function pointers. */ - for (t = current_target.beneath; t != NULL; t = t->beneath) - { - if (!tmp_to_resume) - { - tmp_to_resume = t->to_resume; - tmp_to_resume_ops = t; - } - if (!tmp_to_wait) - { - tmp_to_wait = t->to_wait; - tmp_to_wait_ops = t; - } - if (!tmp_to_store_registers) - { - tmp_to_store_registers = t->to_store_registers; - tmp_to_store_registers_ops = t; - } - if (!tmp_to_xfer_partial) - { - tmp_to_xfer_partial = t->to_xfer_partial; - tmp_to_xfer_partial_ops = t; - } - if (!tmp_to_insert_breakpoint) - { - tmp_to_insert_breakpoint = t->to_insert_breakpoint; - tmp_to_insert_breakpoint_ops = t; - } - if (!tmp_to_remove_breakpoint) - { - tmp_to_remove_breakpoint = t->to_remove_breakpoint; - tmp_to_remove_breakpoint_ops = t; - } - if (!tmp_to_stopped_by_watchpoint) - tmp_to_stopped_by_watchpoint = t->to_stopped_by_watchpoint; - if (!tmp_to_stopped_data_address) - tmp_to_stopped_data_address = t->to_stopped_data_address; - if (!tmp_to_async) - tmp_to_async = t->to_async; - } - if (!tmp_to_xfer_partial) - error (_("Could not find 'to_xfer_partial' method on the target stack.")); - /* Reset */ record_full_insn_num = 0; record_full_insn_count = 0; record_full_list = &record_full_first; record_full_list->next = NULL; - /* Set the tmp beneath pointers to beneath pointers. */ - record_full_beneath_to_resume_ops = tmp_to_resume_ops; - record_full_beneath_to_resume = tmp_to_resume; - record_full_beneath_to_wait_ops = tmp_to_wait_ops; - record_full_beneath_to_wait = tmp_to_wait; - record_full_beneath_to_store_registers_ops = tmp_to_store_registers_ops; - record_full_beneath_to_store_registers = tmp_to_store_registers; - record_full_beneath_to_xfer_partial_ops = tmp_to_xfer_partial_ops; - record_full_beneath_to_xfer_partial = tmp_to_xfer_partial; - record_full_beneath_to_insert_breakpoint = tmp_to_insert_breakpoint; - record_full_beneath_to_insert_breakpoint_ops = tmp_to_insert_breakpoint_ops; - record_full_beneath_to_remove_breakpoint = tmp_to_remove_breakpoint; - record_full_beneath_to_remove_breakpoint_ops = tmp_to_remove_breakpoint_ops; - record_full_beneath_to_stopped_by_watchpoint = tmp_to_stopped_by_watchpoint; - record_full_beneath_to_stopped_data_address = tmp_to_stopped_data_address; - record_full_beneath_to_async = tmp_to_async; - if (core_bfd) record_full_core_open_1 (name, from_tty); else @@ -1135,8 +982,7 @@ record_full_resume (struct target_ops *ops, ptid_t ptid, int step, /* Make sure the target beneath reports all signals. */ target_pass_signals (0, NULL); - record_full_beneath_to_resume (record_full_beneath_to_resume_ops, - ptid, step, signal); + ops->beneath->to_resume (ops->beneath, ptid, step, signal); } /* We are about to start executing the inferior (or simulate it), @@ -1226,8 +1072,7 @@ record_full_wait_1 (struct target_ops *ops, if (record_full_resume_step) { /* This is a single step. */ - return record_full_beneath_to_wait (record_full_beneath_to_wait_ops, - ptid, status, options); + return ops->beneath->to_wait (ops->beneath, ptid, status, options); } else { @@ -1238,8 +1083,7 @@ record_full_wait_1 (struct target_ops *ops, while (1) { - ret = record_full_beneath_to_wait - (record_full_beneath_to_wait_ops, ptid, status, options); + ret = ops->beneath->to_wait (ops->beneath, ptid, status, options); if (status->kind == TARGET_WAITKIND_IGNORE) { if (record_debug) @@ -1323,9 +1167,8 @@ record_full_wait_1 (struct target_ops *ops, "Process record: record_full_wait " "issuing one more step in the " "target beneath\n"); - record_full_beneath_to_resume - (record_full_beneath_to_resume_ops, ptid, step, - GDB_SIGNAL_0); + ops->beneath->to_resume (ops->beneath, ptid, step, + GDB_SIGNAL_0); continue; } } @@ -1529,11 +1372,7 @@ record_full_stopped_by_watchpoint (struct target_ops *ops) if (RECORD_FULL_IS_REPLAY) return record_full_hw_watchpoint; else - { - struct target_ops *beneath = find_target_beneath (ops); - - return record_full_beneath_to_stopped_by_watchpoint (beneath); - } + return ops->beneath->to_stopped_by_watchpoint (ops->beneath); } static int @@ -1542,7 +1381,7 @@ record_full_stopped_data_address (struct target_ops *ops, CORE_ADDR *addr_p) if (RECORD_FULL_IS_REPLAY) return 0; else - return record_full_beneath_to_stopped_data_address (ops, addr_p); + return ops->beneath->to_stopped_data_address (ops->beneath, addr_p); } /* Record registers change (by user or by GDB) to list as an instruction. */ @@ -1645,8 +1484,7 @@ record_full_store_registers (struct target_ops *ops, record_full_registers_change (regcache, regno); } - record_full_beneath_to_store_registers - (record_full_beneath_to_store_registers_ops, regcache, regno); + ops->beneath->to_store_registers (ops->beneath, regcache, regno); } /* "to_xfer_partial" method. Behavior is conditional on @@ -1711,9 +1549,9 @@ record_full_xfer_partial (struct target_ops *ops, enum target_object object, record_full_insn_num++; } - return record_full_beneath_to_xfer_partial - (record_full_beneath_to_xfer_partial_ops, object, annex, - readbuf, writebuf, offset, len, xfered_len); + return ops->beneath->to_xfer_partial (ops->beneath, object, annex, + readbuf, writebuf, offset, + len, xfered_len); } /* This structure represents a breakpoint inserted while the record @@ -1794,9 +1632,7 @@ record_full_insert_breakpoint (struct target_ops *ops, int ret; old_cleanups = record_full_gdb_operation_disable_set (); - ops = record_full_beneath_to_insert_breakpoint_ops; - ret = record_full_beneath_to_insert_breakpoint (ops, gdbarch, - bp_tgt); + ret = ops->beneath->to_insert_breakpoint (ops->beneath, gdbarch, bp_tgt); do_cleanups (old_cleanups); if (ret != 0) @@ -1837,9 +1673,8 @@ record_full_remove_breakpoint (struct target_ops *ops, int ret; old_cleanups = record_full_gdb_operation_disable_set (); - ops = record_full_beneath_to_remove_breakpoint_ops; - ret = record_full_beneath_to_remove_breakpoint (ops, gdbarch, - bp_tgt); + ret = ops->beneath->to_remove_breakpoint (ops->beneath, gdbarch, + bp_tgt); do_cleanups (old_cleanups); if (ret != 0) @@ -1913,18 +1748,6 @@ record_full_goto_bookmark (gdb_byte *raw_bookmark, int from_tty) return; } -static void -record_full_async (struct target_ops *ops, - void (*callback) (enum inferior_event_type event_type, - void *context), void *context) -{ - /* If we're on top of a line target (e.g., linux-nat, remote), then - set it to async mode as well. Will be NULL if we're sitting on - top of the core target, for "record restore". */ - if (record_full_beneath_to_async != NULL) - record_full_beneath_to_async (find_target_beneath (ops), callback, context); -} - static int record_full_can_async_p (struct target_ops *ops) { @@ -2103,7 +1926,6 @@ init_record_full_ops (void) /* Add bookmark target methods. */ record_full_ops.to_get_bookmark = record_full_get_bookmark; record_full_ops.to_goto_bookmark = record_full_goto_bookmark; - record_full_ops.to_async = record_full_async; record_full_ops.to_can_async_p = record_full_can_async_p; record_full_ops.to_is_async_p = record_full_is_async_p; record_full_ops.to_execution_direction = record_full_execution_direction; @@ -2265,10 +2087,11 @@ record_full_core_xfer_partial (struct target_ops *ops, else { if (!entry) - return record_full_beneath_to_xfer_partial - (record_full_beneath_to_xfer_partial_ops, - object, annex, readbuf, writebuf, - offset, len, xfered_len); + return ops->beneath->to_xfer_partial (ops->beneath, + object, annex, + readbuf, writebuf, + offset, len, + xfered_len); memcpy (readbuf, entry->buf + sec_offset, (size_t) len); @@ -2285,9 +2108,9 @@ record_full_core_xfer_partial (struct target_ops *ops, error (_("You can't do that without a process to debug.")); } - return record_full_beneath_to_xfer_partial - (record_full_beneath_to_xfer_partial_ops, object, annex, - readbuf, writebuf, offset, len, xfered_len); + return ops->beneath->to_xfer_partial (ops->beneath, object, annex, + readbuf, writebuf, offset, len, + xfered_len); } /* "to_insert_breakpoint" method for prec over corefile. */ @@ -2349,7 +2172,6 @@ init_record_full_core_ops (void) /* Add bookmark target methods. */ record_full_core_ops.to_get_bookmark = record_full_get_bookmark; record_full_core_ops.to_goto_bookmark = record_full_goto_bookmark; - record_full_core_ops.to_async = record_full_async; record_full_core_ops.to_can_async_p = record_full_can_async_p; record_full_core_ops.to_is_async_p = record_full_is_async_p; record_full_core_ops.to_execution_direction |