diff options
author | Tom Tromey <tromey@redhat.com> | 2014-02-28 09:47:34 -0700 |
---|---|---|
committer | Tom Tromey <tromey@redhat.com> | 2014-03-12 13:05:58 -0600 |
commit | b3ccfe11d3b0fc84f8ccd4e4fa25b75d1dc71cfc (patch) | |
tree | bcaf99bcdc993f80db556b6851fa051a00f55fdf /gdb/target-delegates.c | |
parent | 55d9b4c146716a683d9fea769e5f4106eadb30fc (diff) | |
download | gdb-b3ccfe11d3b0fc84f8ccd4e4fa25b75d1dc71cfc.zip gdb-b3ccfe11d3b0fc84f8ccd4e4fa25b75d1dc71cfc.tar.gz gdb-b3ccfe11d3b0fc84f8ccd4e4fa25b75d1dc71cfc.tar.bz2 |
fix regressions with target-async
A patch in the target cleanup series caused a regression when using
record with target-async. Version 4 of the patch is here:
https://sourceware.org/ml/gdb-patches/2014-03/msg00159.html
The immediate problem is that record supplies to_can_async_p and
to_is_async_p methods, but does not supply a to_async method. So,
when target-async is set, record claims to support async -- but if the
underlying target does not support async, then the to_async method
call will end up in that method's default implementation, namely
tcomplain.
This worked previously because the record target used to provide a
to_async method; one that (erroneously, only at push time) checked the
other members of the target stack, and then simply dropped to_async
calls in the "does not implement async" case.
My first thought was to simply drop tcomplain as the default for
to_async. This works, but Pedro pointed out that the only reason
record has to supply to_can_async_p and to_is_async_p is that these
default to using the find_default_run_target machinery -- and these
defaults are only needed by "run" and "attach".
So, a nicer solution presents itself: change run and attach to
explicitly call into the default run target when needed; and change
to_is_async_p and to_can_async_p to default to "return 0". This makes
the target stack simpler to use and lets us remove the method
implementations from record. This is also in harmony with other plans
for the target stack; namely trying to reduce the impact of
find_default_run_target. This approach makes it clear that
find_default_is_async_p is not needed -- it is asking whether a target
that may not even be pushed is actually async, which seems like a
nonsensical question.
While an improvement, this approach proved to introduce the same bug
when using the core target. Looking a bit deeper, the issue is that
code in "attach" and "run" may need to use either the current target
stack or the default run target -- but different calls into the target
API in those functions could wind up querying different targets.
This new patch makes the target to use more explicit in "run" and
"attach". Then these commands explicitly make the needed calls
against that target. This ensures that a single target is used for
all relevant operations. This lets us remove a couple find_default_*
functions from various targets, including the dummy target. I think
this is a decent understandability improvement.
One issue I see with this patch is that the new calls in "run" and
"attach" are not very much like the rest of the target API. I think
fundamentally this is due to bad factoring in the target API, which
may need to be fixed for multi-target. Tackling that seemed ambitious
for a regression fix.
While working on this I noticed that there don't seem to be any test
cases that involve both target-async and record, so this patch changes
break-precsave.exp to add some. It also changes corefile.exp to add
some target-async tests; these pass with current trunk and with this
patch applied, but fail with the v1 patch.
This patch differs from v4 in that it moves initialization of
to_can_async_p and to_supports_non_stop into inf-child, adds some
assertions to complete_target_initialization, and adds some comments
to target.h.
Built and regtested on x86-64 Fedora 20.
2014-03-12 Tom Tromey <tromey@redhat.com>
* inf-child.c (return_zero): New function.
(inf_child_target): Set to_can_async_p, to_supports_non_stop.
* aix-thread.c (aix_thread_inferior_created): New function.
(aix_thread_attach): Remove.
(init_aix_thread_ops): Don't set to_attach.
(_initialize_aix_thread): Register inferior_created observer.
* corelow.c (init_core_ops): Don't set to_attach or
to_create_inferior.
* exec.c (init_exec_ops): Don't set to_attach or
to_create_inferior.
* infcmd.c (run_command_1): Use find_run_target. Make direct
target calls.
(attach_command): Use find_attach_target. Make direct target
calls.
* record-btrace.c (init_record_btrace_ops): Don't set
to_create_inferior.
* record-full.c (record_full_can_async_p, record_full_is_async_p):
Remove.
(init_record_full_ops, init_record_full_core_ops): Update. Don't
set to_create_inferior.
* target.c (complete_target_initialization): Add assertion.
(target_create_inferior): Remove.
(find_default_attach, find_default_create_inferior): Remove.
(find_attach_target, find_run_target): New functions.
(find_default_is_async_p, find_default_can_async_p)
(target_supports_non_stop, target_attach): Remove.
(init_dummy_target): Don't set to_create_inferior or
to_supports_non_stop.
* target.h (struct target_ops) <to_attach>: Add comment. Remove
TARGET_DEFAULT_FUNC.
<to_create_inferior>: Add comment.
<to_can_async_p, to_is_async_p, to_supports_non_stop>: Use
TARGET_DEFAULT_RETURN.
<to_can_async_p, to_supports_non_stop, to_can_run>: Add comments.
(find_attach_target, find_run_target): Declare.
(target_create_inferior): Remove.
(target_has_execution_1): Update comment.
(target_supports_non_stop): Remove.
* target-delegates.c: Rebuild.
2014-03-12 Tom Tromey <tromey@redhat.com>
* gdb.base/corefile.exp (corefile_test_run, corefile_test_attach):
New procs. Add target-async tests.
* gdb.reverse/break-precsave.exp (precsave_tests): New proc.
Add target-async tests.
Diffstat (limited to 'gdb/target-delegates.c')
-rw-r--r-- | gdb/target-delegates.c | 42 |
1 files changed, 30 insertions, 12 deletions
diff --git a/gdb/target-delegates.c b/gdb/target-delegates.c index 3ca24b7..87ce0d1 100644 --- a/gdb/target-delegates.c +++ b/gdb/target-delegates.c @@ -4,13 +4,6 @@ /* To regenerate this file, run:*/ /* make-target-delegates target.h > target-delegates.c */ static void -delegate_attach (struct target_ops *self, char *arg1, int arg2) -{ - self = self->beneath; - self->to_attach (self, arg1, arg2); -} - -static void delegate_post_attach (struct target_ops *self, int arg1) { self = self->beneath; @@ -690,12 +683,24 @@ delegate_can_async_p (struct target_ops *self) } static int +tdefault_can_async_p (struct target_ops *self) +{ + return 0; +} + +static int delegate_is_async_p (struct target_ops *self) { self = self->beneath; return self->to_is_async_p (self); } +static int +tdefault_is_async_p (struct target_ops *self) +{ + return 0; +} + static void delegate_async (struct target_ops *self, async_callback_ftype *arg1, void *arg2) { @@ -710,6 +715,19 @@ tdefault_async (struct target_ops *self, async_callback_ftype *arg1, void *arg2) } static int +delegate_supports_non_stop (struct target_ops *self) +{ + self = self->beneath; + return self->to_supports_non_stop (self); +} + +static int +tdefault_supports_non_stop (struct target_ops *self) +{ + return 0; +} + +static int delegate_find_memory_regions (struct target_ops *self, find_memory_region_ftype arg1, void *arg2) { self = self->beneath; @@ -1608,8 +1626,6 @@ delegate_decr_pc_after_break (struct target_ops *self, struct gdbarch *arg1) static void install_delegators (struct target_ops *ops) { - if (ops->to_attach == NULL) - ops->to_attach = delegate_attach; if (ops->to_post_attach == NULL) ops->to_post_attach = delegate_post_attach; if (ops->to_detach == NULL) @@ -1730,6 +1746,8 @@ install_delegators (struct target_ops *ops) ops->to_is_async_p = delegate_is_async_p; if (ops->to_async == NULL) ops->to_async = delegate_async; + if (ops->to_supports_non_stop == NULL) + ops->to_supports_non_stop = delegate_supports_non_stop; if (ops->to_find_memory_regions == NULL) ops->to_find_memory_regions = delegate_find_memory_regions; if (ops->to_make_corefile_notes == NULL) @@ -1881,7 +1899,6 @@ install_delegators (struct target_ops *ops) static void install_dummy_methods (struct target_ops *ops) { - ops->to_attach = find_default_attach; ops->to_post_attach = tdefault_post_attach; ops->to_detach = tdefault_detach; ops->to_disconnect = tdefault_disconnect; @@ -1939,9 +1956,10 @@ install_dummy_methods (struct target_ops *ops) ops->to_pid_to_exec_file = tdefault_pid_to_exec_file; ops->to_log_command = tdefault_log_command; ops->to_get_section_table = tdefault_get_section_table; - ops->to_can_async_p = find_default_can_async_p; - ops->to_is_async_p = find_default_is_async_p; + ops->to_can_async_p = tdefault_can_async_p; + ops->to_is_async_p = tdefault_is_async_p; ops->to_async = tdefault_async; + ops->to_supports_non_stop = tdefault_supports_non_stop; ops->to_find_memory_regions = dummy_find_memory_regions; ops->to_make_corefile_notes = dummy_make_corefile_notes; ops->to_get_bookmark = tdefault_get_bookmark; |