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.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.c')
-rw-r--r-- | gdb/target.c | 129 |
1 files changed, 32 insertions, 97 deletions
diff --git a/gdb/target.c b/gdb/target.c index f7868c0..0d22297 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -95,10 +95,6 @@ static char *dummy_make_corefile_notes (struct target_ops *self, static char *default_pid_to_str (struct target_ops *ops, ptid_t ptid); -static int find_default_can_async_p (struct target_ops *ignore); - -static int find_default_is_async_p (struct target_ops *ignore); - static enum exec_direction_kind default_execution_direction (struct target_ops *self); @@ -387,6 +383,12 @@ complete_target_initialization (struct target_ops *t) if (t->to_has_execution == NULL) t->to_has_execution = return_zero_has_execution; + /* These methods can be called on an unpushed target and so require + a default implementation if the target might plausibly be the + default run target. */ + gdb_assert (t->to_can_run == NULL || (t->to_can_async_p != NULL + && t->to_supports_non_stop != NULL)); + install_delegators (t); } @@ -473,29 +475,6 @@ target_load (char *arg, int from_tty) } void -target_create_inferior (char *exec_file, char *args, - char **env, int from_tty) -{ - struct target_ops *t; - - for (t = current_target.beneath; t != NULL; t = t->beneath) - { - if (t->to_create_inferior != NULL) - { - t->to_create_inferior (t, exec_file, args, env, from_tty); - if (targetdebug) - fprintf_unfiltered (gdb_stdlog, - "target_create_inferior (%s, %s, xxx, %d)\n", - exec_file, args, from_tty); - return; - } - } - - internal_error (__FILE__, __LINE__, - _("could not find a target to create inferior")); -} - -void target_terminal_inferior (void) { /* A background resume (``run&'') should leave GDB in control of the @@ -2632,79 +2611,46 @@ find_default_run_target (char *do_mesg) return runable; } -void -find_default_attach (struct target_ops *ops, char *args, int from_tty) -{ - struct target_ops *t; - - t = find_default_run_target ("attach"); - (t->to_attach) (t, args, from_tty); - return; -} +/* See target.h. */ -void -find_default_create_inferior (struct target_ops *ops, - char *exec_file, char *allargs, char **env, - int from_tty) +struct target_ops * +find_attach_target (void) { struct target_ops *t; - t = find_default_run_target ("run"); - (t->to_create_inferior) (t, exec_file, allargs, env, from_tty); - return; -} + /* If a target on the current stack can attach, use it. */ + for (t = current_target.beneath; t != NULL; t = t->beneath) + { + if (t->to_attach != NULL) + break; + } -static int -find_default_can_async_p (struct target_ops *ignore) -{ - struct target_ops *t; + /* Otherwise, use the default run target for attaching. */ + if (t == NULL) + t = find_default_run_target ("attach"); - /* This may be called before the target is pushed on the stack; - look for the default process stratum. If there's none, gdb isn't - configured with a native debugger, and target remote isn't - connected yet. */ - t = find_default_run_target (NULL); - if (t && t->to_can_async_p != delegate_can_async_p) - return (t->to_can_async_p) (t); - return 0; + return t; } -static int -find_default_is_async_p (struct target_ops *ignore) -{ - struct target_ops *t; - - /* This may be called before the target is pushed on the stack; - look for the default process stratum. If there's none, gdb isn't - configured with a native debugger, and target remote isn't - connected yet. */ - t = find_default_run_target (NULL); - if (t && t->to_is_async_p != delegate_is_async_p) - return (t->to_is_async_p) (t); - return 0; -} +/* See target.h. */ -static int -find_default_supports_non_stop (struct target_ops *self) +struct target_ops * +find_run_target (void) { struct target_ops *t; - t = find_default_run_target (NULL); - if (t && t->to_supports_non_stop) - return (t->to_supports_non_stop) (t); - return 0; -} - -int -target_supports_non_stop (void) -{ - struct target_ops *t; + /* If a target on the current stack can attach, use it. */ + for (t = current_target.beneath; t != NULL; t = t->beneath) + { + if (t->to_create_inferior != NULL) + break; + } - for (t = ¤t_target; t != NULL; t = t->beneath) - if (t->to_supports_non_stop) - return t->to_supports_non_stop (t); + /* Otherwise, use the default run target. */ + if (t == NULL) + t = find_default_run_target ("run"); - return 0; + return t; } /* Implement the "info proc" command. */ @@ -3256,8 +3202,6 @@ init_dummy_target (void) dummy_target.to_shortname = "None"; dummy_target.to_longname = "None"; dummy_target.to_doc = ""; - dummy_target.to_create_inferior = find_default_create_inferior; - dummy_target.to_supports_non_stop = find_default_supports_non_stop; dummy_target.to_supports_disable_randomization = find_default_supports_disable_randomization; dummy_target.to_stratum = dummy_stratum; @@ -3293,15 +3237,6 @@ target_close (struct target_ops *targ) fprintf_unfiltered (gdb_stdlog, "target_close ()\n"); } -void -target_attach (char *args, int from_tty) -{ - current_target.to_attach (¤t_target, args, from_tty); - if (targetdebug) - fprintf_unfiltered (gdb_stdlog, "target_attach (%s, %d)\n", - args, from_tty); -} - int target_thread_alive (ptid_t ptid) { |