This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[RFC] Kill pthread_ops_hack
- From: Vladimir Prus <vladimir at codesourcery dot com>
- To: gdb-patches at sources dot redhat dot com
- Date: Fri, 15 Aug 2008 17:15:55 +0400
- Subject: [RFC] Kill pthread_ops_hack
Whenever a target that uses ptrace is created, GDB calls inf_ptrace_target,
and then augments the result with whatever methods are necessary for the
current OS, CPU, etc. However, when inf_ptrace_target is called, the result
is stored in a global variable ptrace_ops_hack, which is then used by inf-ptrace.c
in a few places. Of course, having a variable named whatever_hack in GDB codebase
is already bad, but this design also means that we have have only one pthread-based
target active at a time, which does not seem like a good thing.
In fact, pthread_ops_hack is a consequence of current design of target stack.
When we do 'run', the linux target is not pushed yet, and find_default_create_inferior
looks for a target, and calls its to_create_inferior method. As soon as we create
inferiour, we need to push the target on stack, so that further operations will
apply to now-existing inferiour. But to_create_inferior is not passed the struct target_ops
pointer, so it does not know what to push. This patch makes to_create_inferiour
and few other methods, take struct target_ops pointer, and kills pthread_ops_hack.
I have only converted few targets -- linux and remote. Converting others will be
a mechanical task for adding a parameter to function, but before I go on with that --
anybody has objections to the general direction of this patch?
- Volodya
* target.h (struct target_ops): Make to_attach, to_detach,
to_create_inferior and to_mourn_inferior accept a pointer
to struct target_ops.
(target_attach, target_create_inferior, target_create_inferior):
Convert from macros to function. Find the right target to
invoke a method of.
(find_default_attach, find_default_create_inferior): New parameter
ops.
* corefile.c (core_file_command): Pass target to to_detach.
* corelow.c (core_detach): Add 'ops' parameter.
* fork-child.c (fork_inferior): Return the pid. Allow
init_trace_fun to be NULL.
* inf-ptrace (ptrace_ops_hack): Remove.
(inf_ptrace_him): Remove, moving all logic into....
(inf_ptrace_create_inferior): ... here. Push the target
passed as parameter.
(inf_ptrace_mourn_inferior, inf_ptrace_attach, inf_ptrace_detach):
Push/pop target passed as parameter, no ptrace_ops_hack.
(inf_ptrace_target): Don't remember result.
* inferior.h (fork_inferior): Adjust prototype.
* linux-nat.c (linux_nat_create_inferior, linux_nat_attach)
(linux_nat_detach, linux_nat_mourn_inferior): New parameter ops.
Pass it to linux_ops target.
* linux-thread-db.c (thread_db_detach, thread_db_mourn_inferior):
New parameter ops. Pass it to the target beneath.
* remote.c (remote_mourn, extended_remote_mourn, remote_detach)
(extended_remote_create_inferior): New parameter ops. Pass it
further.
* target.c (debug_to_attach, debug_to_detach)
(debug_to_mourn_inferior): New parameter ops.
(target_create_inferior): New.
(update_current_target): Do not inherit to_attach, to_detach,
to_create_inferiour, to_mourn_inferior. Do not default
to_detach and to_mourn_inferior.
(target_detach): Find the right target to use.
(target_mourn_inferior): New.
(find_default_attach, find_default_create_inferior): New parameter
ops. Pass the found target when calling its method.
(init_dummy_target): Provide fallback definition of to_detach.
(target_attach): New.
(debug_to_attach, debug_to_detach, debug_to_create_inferior)
(debug_to_mourn_inferiour): New parameter ops.
---
gdb/corefile.c | 2 +-
gdb/corelow.c | 6 +-
gdb/fork-child.c | 6 ++-
gdb/inf-ptrace.c | 42 +++++++-----------
gdb/inferior.h | 6 +-
gdb/linux-nat.c | 17 ++++---
gdb/linux-thread-db.c | 10 ++--
gdb/remote.c | 25 ++++++-----
gdb/target.c | 114 +++++++++++++++++++++++++++++++++++++-----------
gdb/target.h | 25 +++++------
10 files changed, 155 insertions(+), 98 deletions(-)
diff --git a/gdb/corefile.c b/gdb/corefile.c
index 726d9fc..5ad3998 100644
--- a/gdb/corefile.c
+++ b/gdb/corefile.c
@@ -74,7 +74,7 @@ core_file_command (char *filename, int from_tty)
error (_("GDB can't read core files on this machine."));
if (!filename)
- (t->to_detach) (filename, from_tty);
+ (t->to_detach) (t, filename, from_tty);
else
(t->to_open) (filename, from_tty);
}
diff --git a/gdb/corelow.c b/gdb/corelow.c
index 28b61e5..37d437b 100644
--- a/gdb/corelow.c
+++ b/gdb/corelow.c
@@ -75,7 +75,7 @@ static int gdb_check_format (bfd *);
static void core_open (char *, int);
-static void core_detach (char *, int);
+static void core_detach (struct target_ops *ops, char *, int);
static void core_close (int);
@@ -386,11 +386,11 @@ your %s; do ``info files''", target_longname);
}
static void
-core_detach (char *args, int from_tty)
+core_detach (struct target_ops *ops, char *args, int from_tty)
{
if (args)
error (_("Too many arguments"));
- unpush_target (&core_ops);
+ unpush_target (ops);
reinit_frame_cache ();
if (from_tty)
printf_filtered (_("No core file now.\n"));
diff --git a/gdb/fork-child.c b/gdb/fork-child.c
index 7aff110..26dc443 100644
--- a/gdb/fork-child.c
+++ b/gdb/fork-child.c
@@ -118,7 +118,7 @@ escape_bang_in_quoted_argument (const char *shell_file)
/* This function is NOT reentrant. Some of the variables have been
made static to ensure that they survive the vfork call. */
-void
+int
fork_inferior (char *exec_file_arg, char *allargs, char **env,
void (*traceme_fun) (void), void (*init_trace_fun) (int),
void (*pre_trace_fun) (void), char *shell_file_arg)
@@ -400,11 +400,13 @@ fork_inferior (char *exec_file_arg, char *allargs, char **env,
/* Now that we have a child process, make it our target, and
initialize anything target-vector-specific that needs
initializing. */
- (*init_trace_fun) (pid);
+ if (init_trace_fun)
+ (*init_trace_fun) (pid);
/* We are now in the child process of interest, having exec'd the
correct program, and are poised at the first instruction of the
new program. */
+ return pid;
}
/* Accept NTRAPS traps from the inferior. */
diff --git a/gdb/inf-ptrace.c b/gdb/inf-ptrace.c
index ee2c8fa..ae33920 100644
--- a/gdb/inf-ptrace.c
+++ b/gdb/inf-ptrace.c
@@ -34,8 +34,6 @@
#include "inf-child.h"
-/* HACK: Save the ptrace ops returned by inf_ptrace_target. */
-static struct target_ops *ptrace_ops_hack;
#ifdef PT_GET_PROCESS_STATE
@@ -100,12 +98,20 @@ inf_ptrace_me (void)
ptrace (PT_TRACE_ME, 0, (PTRACE_TYPE_ARG3)0, 0);
}
-/* Start tracing PID. */
+/* Start a new inferior Unix child process. EXEC_FILE is the file to
+ run, ALLARGS is a string containing the arguments to the program.
+ ENV is the environment vector to pass. If FROM_TTY is non-zero, be
+ chatty about it. */
static void
-inf_ptrace_him (int pid)
+inf_ptrace_create_inferior (struct target_ops *ops,
+ char *exec_file, char *allargs, char **env,
+ int from_tty)
{
- push_target (ptrace_ops_hack);
+ int pid = fork_inferior (exec_file, allargs, env, inf_ptrace_me, NULL,
+ NULL, NULL);
+
+ push_target (ops);
/* On some targets, there must be some explicit synchronization
between the parent and child processes after the debugger
@@ -124,19 +130,6 @@ inf_ptrace_him (int pid)
target_post_startup_inferior (pid_to_ptid (pid));
}
-/* Start a new inferior Unix child process. EXEC_FILE is the file to
- run, ALLARGS is a string containing the arguments to the program.
- ENV is the environment vector to pass. If FROM_TTY is non-zero, be
- chatty about it. */
-
-static void
-inf_ptrace_create_inferior (char *exec_file, char *allargs, char **env,
- int from_tty)
-{
- fork_inferior (exec_file, allargs, env, inf_ptrace_me, inf_ptrace_him,
- NULL, NULL);
-}
-
#ifdef PT_GET_PROCESS_STATE
static void
@@ -157,7 +150,7 @@ inf_ptrace_post_startup_inferior (ptid_t pid)
/* Clean up a rotting corpse of an inferior after it died. */
static void
-inf_ptrace_mourn_inferior (void)
+inf_ptrace_mourn_inferior (struct target_ops *ops)
{
int status;
@@ -167,7 +160,7 @@ inf_ptrace_mourn_inferior (void)
only report its exit status to its original parent. */
waitpid (ptid_get_pid (inferior_ptid), &status, 0);
- unpush_target (ptrace_ops_hack);
+ unpush_target (ops);
generic_mourn_inferior ();
}
@@ -175,7 +168,7 @@ inf_ptrace_mourn_inferior (void)
be chatty about it. */
static void
-inf_ptrace_attach (char *args, int from_tty)
+inf_ptrace_attach (struct target_ops *ops, char *args, int from_tty)
{
char *exec_file;
pid_t pid;
@@ -218,7 +211,7 @@ inf_ptrace_attach (char *args, int from_tty)
#endif
inferior_ptid = pid_to_ptid (pid);
- push_target (ptrace_ops_hack);
+ push_target (ops);
}
#ifdef PT_GET_PROCESS_STATE
@@ -242,7 +235,7 @@ inf_ptrace_post_attach (int pid)
specified by ARGS. If FROM_TTY is non-zero, be chatty about it. */
static void
-inf_ptrace_detach (char *args, int from_tty)
+inf_ptrace_detach (struct target_ops *ops, char *args, int from_tty)
{
pid_t pid = ptid_get_pid (inferior_ptid);
int sig = 0;
@@ -274,7 +267,7 @@ inf_ptrace_detach (char *args, int from_tty)
#endif
inferior_ptid = null_ptid;
- unpush_target (ptrace_ops_hack);
+ unpush_target (ops);
}
/* Kill the inferior. */
@@ -602,7 +595,6 @@ inf_ptrace_target (void)
t->to_stop = inf_ptrace_stop;
t->to_xfer_partial = inf_ptrace_xfer_partial;
- ptrace_ops_hack = t;
return t;
}
diff --git a/gdb/inferior.h b/gdb/inferior.h
index f53af8b..10ffb99 100644
--- a/gdb/inferior.h
+++ b/gdb/inferior.h
@@ -207,9 +207,9 @@ extern ptid_t procfs_first_available (void);
/* From fork-child.c */
-extern void fork_inferior (char *, char *, char **,
- void (*)(void),
- void (*)(int), void (*)(void), char *);
+extern int fork_inferior (char *, char *, char **,
+ void (*)(void),
+ void (*)(int), void (*)(void), char *);
extern void startup_inferior (int);
diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index b25104e..a924ed8 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -1276,7 +1276,8 @@ lin_lwp_attach_lwp (ptid_t ptid)
}
static void
-linux_nat_create_inferior (char *exec_file, char *allargs, char **env,
+linux_nat_create_inferior (struct target_ops *ops,
+ char *exec_file, char *allargs, char **env,
int from_tty)
{
int saved_async = 0;
@@ -1323,7 +1324,7 @@ linux_nat_create_inferior (char *exec_file, char *allargs, char **env,
}
#endif /* HAVE_PERSONALITY */
- linux_ops->to_create_inferior (exec_file, allargs, env, from_tty);
+ linux_ops->to_create_inferior (ops, exec_file, allargs, env, from_tty);
#ifdef HAVE_PERSONALITY
if (personality_set)
@@ -1341,14 +1342,14 @@ linux_nat_create_inferior (char *exec_file, char *allargs, char **env,
}
static void
-linux_nat_attach (char *args, int from_tty)
+linux_nat_attach (struct target_ops *ops, char *args, int from_tty)
{
struct lwp_info *lp;
int status;
/* FIXME: We should probably accept a list of process id's, and
attach all of them. */
- linux_ops->to_attach (args, from_tty);
+ linux_ops->to_attach (ops, args, from_tty);
if (!target_can_async_p ())
{
@@ -1536,7 +1537,7 @@ detach_callback (struct lwp_info *lp, void *data)
}
static void
-linux_nat_detach (char *args, int from_tty)
+linux_nat_detach (struct target_ops *ops, char *args, int from_tty)
{
int pid;
int status;
@@ -1577,7 +1578,7 @@ linux_nat_detach (char *args, int from_tty)
pid = GET_PID (inferior_ptid);
inferior_ptid = pid_to_ptid (pid);
- linux_ops->to_detach (args, from_tty);
+ linux_ops->to_detach (ops, args, from_tty);
if (target_can_async_p ())
drain_queued_events (pid);
@@ -3121,7 +3122,7 @@ linux_nat_kill (void)
}
static void
-linux_nat_mourn_inferior (void)
+linux_nat_mourn_inferior (struct target_ops *ops)
{
/* Destroy LWP info; it's no longer valid. */
init_lwp_list ();
@@ -3131,7 +3132,7 @@ linux_nat_mourn_inferior (void)
/* Normal case, no other forks available. */
if (target_can_async_p ())
linux_nat_async (NULL, 0);
- linux_ops->to_mourn_inferior ();
+ linux_ops->to_mourn_inferior (ops);
}
else
/* Multi-fork case. The current inferior_ptid has exited, but
diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c
index 650cbaa..4597e29 100644
--- a/gdb/linux-thread-db.c
+++ b/gdb/linux-thread-db.c
@@ -780,11 +780,11 @@ detach_thread (ptid_t ptid)
}
static void
-thread_db_detach (char *args, int from_tty)
+thread_db_detach (struct target_ops *ops, char *args, int from_tty)
{
disable_thread_event_reporting ();
- target_beneath->to_detach (args, from_tty);
+ target_beneath->to_detach (target_beneath, args, from_tty);
/* Should this be done by detach_command? */
target_mourn_inferior ();
@@ -927,20 +927,20 @@ thread_db_wait (ptid_t ptid, struct target_waitstatus *ourstatus)
}
static void
-thread_db_mourn_inferior (void)
+thread_db_mourn_inferior (struct target_ops *ops)
{
/* Forget about the child's process ID. We shouldn't need it
anymore. */
proc_handle.pid = 0;
- target_beneath->to_mourn_inferior ();
+ target_beneath->to_mourn_inferior (target_beneath);
/* Delete the old thread event breakpoints. Do this after mourning
the inferior, so that we don't try to uninsert them. */
remove_thread_event_breakpoints ();
/* Detach thread_db target ops. */
- unpush_target (&thread_db_ops);
+ unpush_target (ops);
using_thread_db = 0;
}
diff --git a/gdb/remote.c b/gdb/remote.c
index af3b0b8..43d1a3b 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -102,11 +102,11 @@ static void remote_close (int quitting);
static void remote_store_registers (struct regcache *regcache, int regno);
-static void remote_mourn (void);
+static void remote_mourn (struct target_ops *ops);
static void extended_remote_restart (void);
-static void extended_remote_mourn (void);
+static void extended_remote_mourn (struct target_ops *);
static void remote_mourn_1 (struct target_ops *);
@@ -130,7 +130,7 @@ static void remote_async (void (*callback) (enum inferior_event_type event_type,
static int remote_async_mask (int new_mask);
-static void remote_detach (char *args, int from_tty);
+static void remote_detach (struct target_ops *ops, char *args, int from_tty);
static void remote_interrupt (int signo);
@@ -2905,13 +2905,13 @@ remote_detach_1 (char *args, int from_tty, int extended)
}
static void
-remote_detach (char *args, int from_tty)
+remote_detach (struct target_ops *ops, char *args, int from_tty)
{
remote_detach_1 (args, from_tty, 0);
}
static void
-extended_remote_detach (char *args, int from_tty)
+extended_remote_detach (struct target_ops *ops, char *args, int from_tty)
{
remote_detach_1 (args, from_tty, 1);
}
@@ -3002,9 +3002,9 @@ extended_remote_attach_1 (struct target_ops *target, char *args, int from_tty)
}
static void
-extended_remote_attach (char *args, int from_tty)
+extended_remote_attach (struct target_ops *ops, char *args, int from_tty)
{
- extended_remote_attach_1 (&extended_remote_ops, args, from_tty);
+ extended_remote_attach_1 (ops, args, from_tty);
}
/* Convert hex digit A to a number. */
@@ -5187,9 +5187,9 @@ remote_kill (void)
}
static void
-remote_mourn (void)
+remote_mourn (struct target_ops *ops)
{
- remote_mourn_1 (&remote_ops);
+ remote_mourn_1 (ops);
}
/* Worker function for remote_mourn. */
@@ -5233,9 +5233,9 @@ extended_remote_mourn_1 (struct target_ops *target)
}
static void
-extended_remote_mourn (void)
+extended_remote_mourn (struct target_ops *ops)
{
- extended_remote_mourn_1 (&extended_remote_ops);
+ extended_remote_mourn_1 (ops);
}
static int
@@ -5347,7 +5347,8 @@ extended_remote_create_inferior_1 (char *exec_file, char *args,
}
static void
-extended_remote_create_inferior (char *exec_file, char *args,
+extended_remote_create_inferior (struct target_ops *ops,
+ char *exec_file, char *args,
char **env, int from_tty)
{
extended_remote_create_inferior_1 (exec_file, args, env, from_tty);
diff --git a/gdb/target.c b/gdb/target.c
index 050f71b..f21fa9e 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -99,9 +99,9 @@ static void debug_to_open (char *, int);
static void debug_to_close (int);
-static void debug_to_attach (char *, int);
+static void debug_to_attach (struct target_ops *ops, char *, int);
-static void debug_to_detach (char *, int);
+static void debug_to_detach (struct target_ops *ops, char *, int);
static void debug_to_resume (ptid_t, int, enum target_signal);
@@ -156,7 +156,7 @@ static void debug_to_load (char *, int);
static int debug_to_lookup_symbol (char *, CORE_ADDR *);
-static void debug_to_mourn_inferior (void);
+static void debug_to_mourn_inferior (struct target_ops *);
static int debug_to_can_run (void);
@@ -286,6 +286,24 @@ target_load (char *arg, int from_tty)
(*current_target.to_load) (arg, 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);
+ return;
+ }
+ }
+
+ internal_error (__FILE__, __LINE__,
+ "could not find a target to create inferior");
+}
+
+
static int
nomemory (CORE_ADDR memaddr, char *myaddr, int len, int write,
struct target_ops *t)
@@ -387,10 +405,10 @@ update_current_target (void)
INHERIT (to_doc, t);
INHERIT (to_open, t);
INHERIT (to_close, t);
- INHERIT (to_attach, t);
+ /* Do not inherit to_attach. */
INHERIT (to_post_attach, t);
INHERIT (to_attach_no_wait, t);
- INHERIT (to_detach, t);
+ /* Do not inherit to_detach. */
/* Do not inherit to_disconnect. */
INHERIT (to_resume, t);
INHERIT (to_wait, t);
@@ -421,7 +439,7 @@ update_current_target (void)
INHERIT (to_kill, t);
INHERIT (to_load, t);
INHERIT (to_lookup_symbol, t);
- INHERIT (to_create_inferior, t);
+ /* Do no inherit to_create_inferior. */
INHERIT (to_post_startup_inferior, t);
INHERIT (to_acknowledge_created_inferior, t);
INHERIT (to_insert_fork_catchpoint, t);
@@ -432,7 +450,7 @@ update_current_target (void)
INHERIT (to_insert_exec_catchpoint, t);
INHERIT (to_remove_exec_catchpoint, t);
INHERIT (to_has_exited, t);
- INHERIT (to_mourn_inferior, t);
+ /* Do no inherit to_mourn_inferiour. */
INHERIT (to_can_run, t);
INHERIT (to_notice_signals, t);
INHERIT (to_thread_alive, t);
@@ -486,9 +504,6 @@ update_current_target (void)
de_fault (to_post_attach,
(void (*) (int))
target_ignore);
- de_fault (to_detach,
- (void (*) (char *, int))
- target_ignore);
de_fault (to_resume,
(void (*) (ptid_t, int, enum target_signal))
noprocess);
@@ -592,9 +607,6 @@ update_current_target (void)
de_fault (to_has_exited,
(int (*) (int, int, int *))
return_zero);
- de_fault (to_mourn_inferior,
- (void (*) (void))
- noprocess);
de_fault (to_can_run,
return_zero);
de_fault (to_notice_signals,
@@ -1745,11 +1757,22 @@ target_preopen (int from_tty)
void
target_detach (char *args, int from_tty)
{
+ struct target_ops *t;
+
/* If we're in breakpoints-always-inserted mode, have to
remove them before detaching. */
remove_breakpoints ();
- (current_target.to_detach) (args, from_tty);
+ for (t = current_target.beneath; t != NULL; t = t->beneath)
+ {
+ if (t->to_detach != NULL)
+ {
+ t->to_detach (t, args, from_tty);
+ return;
+ }
+ }
+
+ internal_error (__FILE__, __LINE__, "could not find a target to detach");
}
void
@@ -1807,6 +1830,23 @@ target_follow_fork (int follow_child)
"could not find a target to follow fork");
}
+void
+target_mourn_inferior (void)
+{
+ struct target_ops *t;
+ for (t = current_target.beneath; t != NULL; t = t->beneath)
+ {
+ if (t->to_mourn_inferior != NULL)
+ {
+ t->to_mourn_inferior (t);
+ return;
+ }
+ }
+
+ internal_error (__FILE__, __LINE__,
+ "could not find a target to follow mourn inferiour");
+}
+
/* Look for a target which can describe architectural features, starting
from TARGET. If we find one, return its description. */
@@ -2052,23 +2092,24 @@ find_default_run_target (char *do_mesg)
}
void
-find_default_attach (char *args, int from_tty)
+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) (args, from_tty);
+ (t->to_attach) (t, args, from_tty);
return;
}
void
-find_default_create_inferior (char *exec_file, char *allargs, char **env,
+find_default_create_inferior (struct target_ops *ops,
+ char *exec_file, char *allargs, char **env,
int from_tty)
{
struct target_ops *t;
t = find_default_run_target ("run");
- (t->to_create_inferior) (exec_file, allargs, env, from_tty);
+ (t->to_create_inferior) (t, exec_file, allargs, env, from_tty);
return;
}
@@ -2373,6 +2414,8 @@ init_dummy_target (void)
dummy_target.to_longname = "None";
dummy_target.to_doc = "";
dummy_target.to_attach = find_default_attach;
+ dummy_target.to_detach =
+ (void (*)(struct target_ops *, char *, int))target_ignore;
dummy_target.to_create_inferior = find_default_create_inferior;
dummy_target.to_can_async_p = find_default_can_async_p;
dummy_target.to_is_async_p = find_default_is_async_p;
@@ -2408,10 +2451,28 @@ target_close (struct target_ops *targ, int quitting)
targ->to_close (quitting);
}
+void
+target_attach (char *args, int from_tty)
+{
+ struct target_ops *t;
+ for (t = current_target.beneath; t != NULL; t = t->beneath)
+ {
+ if (t->to_attach != NULL)
+ {
+ t->to_attach (t, args, from_tty);
+ return;
+ }
+ }
+
+ internal_error (__FILE__, __LINE__,
+ "could not find a target to attach");
+}
+
+
static void
-debug_to_attach (char *args, int from_tty)
+debug_to_attach (struct target_ops *ops, char *args, int from_tty)
{
- debug_target.to_attach (args, from_tty);
+ debug_target.to_attach (&debug_target, args, from_tty);
fprintf_unfiltered (gdb_stdlog, "target_attach (%s, %d)\n", args, from_tty);
}
@@ -2426,9 +2487,9 @@ debug_to_post_attach (int pid)
}
static void
-debug_to_detach (char *args, int from_tty)
+debug_to_detach (struct target_ops *ops, char *args, int from_tty)
{
- debug_target.to_detach (args, from_tty);
+ debug_target.to_detach (&debug_target, args, from_tty);
fprintf_unfiltered (gdb_stdlog, "target_detach (%s, %d)\n", args, from_tty);
}
@@ -2832,10 +2893,11 @@ debug_to_lookup_symbol (char *name, CORE_ADDR *addrp)
}
static void
-debug_to_create_inferior (char *exec_file, char *args, char **env,
+debug_to_create_inferior (struct target_ops *ops,
+ char *exec_file, char *args, char **env,
int from_tty)
{
- debug_target.to_create_inferior (exec_file, args, env, from_tty);
+ debug_target.to_create_inferior (ops, exec_file, args, env, from_tty);
fprintf_unfiltered (gdb_stdlog, "target_create_inferior (%s, %s, xxx, %d)\n",
exec_file, args, from_tty);
@@ -2939,9 +3001,9 @@ debug_to_has_exited (int pid, int wait_status, int *exit_status)
}
static void
-debug_to_mourn_inferior (void)
+debug_to_mourn_inferior (struct target_ops *ops)
{
- debug_target.to_mourn_inferior ();
+ debug_target.to_mourn_inferior (&debug_target);
fprintf_unfiltered (gdb_stdlog, "target_mourn_inferior ()\n");
}
diff --git a/gdb/target.h b/gdb/target.h
index 3a1d4b7..d12c048 100644
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -323,9 +323,9 @@ struct target_ops
to xfree everything (including the "struct target_ops"). */
void (*to_xclose) (struct target_ops *targ, int quitting);
void (*to_close) (int);
- void (*to_attach) (char *, int);
+ void (*to_attach) (struct target_ops *ops, char *, int);
void (*to_post_attach) (int);
- void (*to_detach) (char *, int);
+ void (*to_detach) (struct target_ops *ops, char *, int);
void (*to_disconnect) (struct target_ops *, char *, int);
void (*to_resume) (ptid_t, int, enum target_signal);
ptid_t (*to_wait) (ptid_t, struct target_waitstatus *);
@@ -383,7 +383,8 @@ struct target_ops
void (*to_kill) (void);
void (*to_load) (char *, int);
int (*to_lookup_symbol) (char *, CORE_ADDR *);
- void (*to_create_inferior) (char *, char *, char **, int);
+ void (*to_create_inferior) (struct target_ops *,
+ char *, char *, char **, int);
void (*to_post_startup_inferior) (ptid_t);
void (*to_acknowledge_created_inferior) (int);
void (*to_insert_fork_catchpoint) (int);
@@ -394,7 +395,7 @@ struct target_ops
void (*to_insert_exec_catchpoint) (int);
int (*to_remove_exec_catchpoint) (int);
int (*to_has_exited) (int, int, int *);
- void (*to_mourn_inferior) (void);
+ void (*to_mourn_inferior) (struct target_ops *);
int (*to_can_run) (void);
void (*to_notice_signals) (ptid_t ptid);
int (*to_thread_alive) (ptid_t ptid);
@@ -562,8 +563,7 @@ void target_close (struct target_ops *targ, int quitting);
should be ready to deliver the status of the process immediately
(without waiting) to an upcoming target_wait call. */
-#define target_attach(args, from_tty) \
- (*current_target.to_attach) (args, from_tty)
+void target_attach (char *, int);
/* Some targets don't generate traps when attaching to the inferior,
or their target_attach implementation takes care of the waiting.
@@ -807,9 +807,8 @@ extern void target_load (char *arg, int from_tty);
ENV is the environment vector to pass. Errors reported with error().
On VxWorks and various standalone systems, we ignore exec_file. */
-#define target_create_inferior(exec_file, args, env, FROM_TTY) \
- (*current_target.to_create_inferior) (exec_file, args, env, (FROM_TTY))
-
+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
@@ -879,8 +878,7 @@ int target_follow_fork (int follow_child);
/* The inferior process has died. Do what is right. */
-#define target_mourn_inferior() \
- (*current_target.to_mourn_inferior) ()
+void target_mourn_inferior (void);
/* Does target have enough data to do a run or attach command? */
@@ -1224,9 +1222,10 @@ extern void noprocess (void);
extern void target_require_runnable (void);
-extern void find_default_attach (char *, int);
+extern void find_default_attach (struct target_ops *, char *, int);
-extern void find_default_create_inferior (char *, char *, char **, int);
+extern void find_default_create_inferior (struct target_ops *,
+ char *, char *, char **, int);
extern struct target_ops *find_run_target (void);
--
1.5.3.5