aboutsummaryrefslogtreecommitdiff
path: root/gdb/target.h
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2014-02-28 09:47:34 -0700
committerTom Tromey <tromey@redhat.com>2014-03-12 13:05:58 -0600
commitb3ccfe11d3b0fc84f8ccd4e4fa25b75d1dc71cfc (patch)
treebcaf99bcdc993f80db556b6851fa051a00f55fdf /gdb/target.h
parent55d9b4c146716a683d9fea769e5f4106eadb30fc (diff)
downloadgdb-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.h')
-rw-r--r--gdb/target.h64
1 files changed, 37 insertions, 27 deletions
diff --git a/gdb/target.h b/gdb/target.h
index 0d4e5ff..d7c6c3d 100644
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -401,8 +401,15 @@ struct target_ops
to xfree everything (including the "struct target_ops"). */
void (*to_xclose) (struct target_ops *targ);
void (*to_close) (struct target_ops *);
- void (*to_attach) (struct target_ops *ops, char *, int)
- TARGET_DEFAULT_FUNC (find_default_attach);
+ /* Attaches to a process on the target side. Arguments are as
+ passed to the `attach' command by the user. This routine can
+ be called when the target is not on the target-stack, if the
+ target_can_run routine returns 1; in that case, it must push
+ itself onto the stack. Upon exit, the target should be ready
+ for normal operations, and should be ready to deliver the
+ status of the process immediately (without waiting) to an
+ upcoming target_wait call. */
+ void (*to_attach) (struct target_ops *ops, char *, int);
void (*to_post_attach) (struct target_ops *, int)
TARGET_DEFAULT_IGNORE ();
void (*to_detach) (struct target_ops *ops, const char *, int)
@@ -494,6 +501,11 @@ struct target_ops
TARGET_DEFAULT_NORETURN (noprocess ());
void (*to_load) (struct target_ops *, char *, int)
TARGET_DEFAULT_NORETURN (tcomplain ());
+ /* Start an inferior process and set inferior_ptid to its pid.
+ EXEC_FILE is the file to run.
+ ALLARGS is a string containing the arguments to the program.
+ ENV is the environment vector to pass. Errors reported with error().
+ On VxWorks and various standalone systems, we ignore exec_file. */
void (*to_create_inferior) (struct target_ops *,
char *, char *, char **, int);
void (*to_post_startup_inferior) (struct target_ops *, ptid_t)
@@ -519,6 +531,9 @@ struct target_ops
TARGET_DEFAULT_RETURN (0);
void (*to_mourn_inferior) (struct target_ops *)
TARGET_DEFAULT_FUNC (default_mourn_inferior);
+ /* Note that to_can_run is special and can be invoked on an
+ unpushed target. Targets defining this method must also define
+ to_can_async_p and to_supports_non_stop. */
int (*to_can_run) (struct target_ops *)
TARGET_DEFAULT_RETURN (0);
@@ -561,14 +576,18 @@ struct target_ops
int (*to_has_execution) (struct target_ops *, ptid_t);
int to_has_thread_control; /* control thread execution */
int to_attach_no_wait;
- /* ASYNC target controls */
+ /* This method must be implemented in some situations. See the
+ comment on 'to_can_run'. */
int (*to_can_async_p) (struct target_ops *)
- TARGET_DEFAULT_FUNC (find_default_can_async_p);
+ TARGET_DEFAULT_RETURN (0);
int (*to_is_async_p) (struct target_ops *)
- TARGET_DEFAULT_FUNC (find_default_is_async_p);
+ TARGET_DEFAULT_RETURN (0);
void (*to_async) (struct target_ops *, async_callback_ftype *, void *)
TARGET_DEFAULT_NORETURN (tcomplain ());
- int (*to_supports_non_stop) (struct target_ops *);
+ /* This method must be implemented in some situations. See the
+ comment on 'to_can_run'. */
+ int (*to_supports_non_stop) (struct target_ops *)
+ TARGET_DEFAULT_RETURN (0);
/* find_memory_regions support method for gcore */
int (*to_find_memory_regions) (struct target_ops *,
find_memory_region_ftype func, void *data)
@@ -1117,15 +1136,17 @@ extern struct target_ops current_target;
void target_close (struct target_ops *targ);
-/* Attaches to a process on the target side. Arguments are as passed
- to the `attach' command by the user. This routine can be called
- when the target is not on the target-stack, if the target_can_run
- routine returns 1; in that case, it must push itself onto the stack.
- Upon exit, the target should be ready for normal operations, and
- should be ready to deliver the status of the process immediately
- (without waiting) to an upcoming target_wait call. */
+/* Find the correct target to use for "attach". If a target on the
+ current stack supports attaching, then it is returned. Otherwise,
+ the default run target is returned. */
+
+extern struct target_ops *find_attach_target (void);
-void target_attach (char *, int);
+/* Find the correct target to use for "run". If a target on the
+ current stack supports creating a new inferior, then it is
+ returned. Otherwise, the default run target is returned. */
+
+extern struct target_ops *find_run_target (void);
/* Some targets don't generate traps when attaching to the inferior,
or their target_attach implementation takes care of the waiting.
@@ -1393,15 +1414,6 @@ extern void target_kill (void);
extern void target_load (char *arg, int from_tty);
-/* Start an inferior process and set inferior_ptid to its pid.
- EXEC_FILE is the file to run.
- ALLARGS is a string containing the arguments to the program.
- ENV is the environment vector to pass. Errors reported with error().
- On VxWorks and various standalone systems, we ignore exec_file. */
-
-void target_create_inferior (char *exec_file, char *args,
- char **env, int from_tty);
-
/* Some targets (such as ttrace-based HPUX) don't allow us to request
notification of inferior events such as fork and vork immediately
after the inferior is created. (This because of how gdb gets an
@@ -1579,8 +1591,8 @@ extern int target_has_registers_1 (void);
target is currently executing; for some targets, that's the same as
whether or not the target is capable of execution, but there are
also targets which can be current while not executing. In that
- case this will become true after target_create_inferior or
- target_attach. */
+ case this will become true after to_create_inferior or
+ to_attach. */
extern int target_has_execution_1 (ptid_t);
@@ -1616,8 +1628,6 @@ extern int target_async_permitted;
/* Is the target in asynchronous execution mode? */
#define target_is_async_p() (current_target.to_is_async_p (&current_target))
-int target_supports_non_stop (void);
-
/* Put the target in async mode with the specified callback function. */
#define target_async(CALLBACK,CONTEXT) \
(current_target.to_async (&current_target, (CALLBACK), (CONTEXT)))