* [RFC] How to get target_ops from to_kill method?
@ 2009-03-16 16:42 Joel Brobecker
2009-03-16 17:02 ` Pedro Alves
0 siblings, 1 reply; 12+ messages in thread
From: Joel Brobecker @ 2009-03-16 16:42 UTC (permalink / raw)
To: gdb-patches; +Cc: Tristan Gingold
[-- Attachment #1: Type: text/plain, Size: 1406 bytes --]
Hello,
As I was hinting in one of my earlier emails, there is a nasty error
in darwin-nat.c, in the fact that we set the darwin_ops->to_kill method
to a procedure that has the wrong profile: darwin_kill_inferior takes
a target_ops * as its parameter, whereas the to_kill method is supposed
to take none!
Attached is a patch that fixes the issue, at least for now. But as you
can see, darwin_kill_inferior makes calls to a few routines that are
also used as methods in darwin's target_ops, and thus must take
a target_ops as their first parameter. As a minimal change, what
my first patch does is simply use the current_target global and passes
it to darwin_wait and darwin_resume. But this isn't very satisfactory,
I don't want to increase the use of a global if I can help it.
As it turns out, all the routines being used by darwin_kill_inferior
don't use the target_ops. So what my second patch did was extract out
each of these routines inside another identical function, but without
the target_ops parameter. What this does, basically, is defined the
target_ops methods as wrappers to the real routines. This is what my
second patch does.
However, I'm really wondering whether it would make sense to have
*all* the methods take the target_ops as the first parameter. We've
been slowly adding this parameter as we need them, but really, why
not be consistent across the board?
Thoughts?
--
Joel
[-- Attachment #2: darwin-kill.diff --]
[-- Type: text/x-diff, Size: 1344 bytes --]
Index: darwin-nat.c
===================================================================
RCS file: /cvs/src/src/gdb/darwin-nat.c,v
retrieving revision 1.5
diff -u -p -r1.5 darwin-nat.c
--- darwin-nat.c 12 Mar 2009 22:29:30 -0000 1.5
+++ darwin-nat.c 16 Mar 2009 15:53:40 -0000
@@ -90,7 +90,7 @@ static void darwin_mourn_inferior (struc
static int darwin_lookup_task (char *args, task_t * ptask, int *ppid);
-static void darwin_kill_inferior (struct target_ops *ops);
+static void darwin_kill_inferior (void);
static void darwin_ptrace_me (void);
@@ -367,7 +367,7 @@ darwin_resume (struct target_ops *ops,
{
int nsignal = target_signal_to_host (signal);
res = PTRACE (PT_THUPDATE, pid,
- (void *)exc_msg.thread_port, nsignal);
+ (void *)exc_msg.thread_port, nsignal);
if (res < 0)
printf_unfiltered (_("ptrace THUP: res=%d\n"), res);
}
@@ -693,13 +693,16 @@ darwin_stop_inferior (struct target_ops
}
static void
-darwin_kill_inferior (struct target_ops *ops)
+darwin_kill_inferior (void)
{
struct target_waitstatus wstatus;
ptid_t ptid;
kern_return_t kret;
int status;
int res;
+ /* FIXME: brobecker/2009-03-16: Is there a better way to get
+ to the current target ops? */
+ struct target_ops *ops = ¤t_target;
gdb_assert (darwin_inf != NULL);
[-- Attachment #3: darwin-kill2.diff --]
[-- Type: text/x-diff, Size: 3338 bytes --]
Index: darwin-nat.c
===================================================================
RCS file: /cvs/src/src/gdb/darwin-nat.c,v
retrieving revision 1.6
diff -u -p -r1.6 darwin-nat.c
--- darwin-nat.c 16 Mar 2009 15:57:08 -0000 1.6
+++ darwin-nat.c 16 Mar 2009 16:22:01 -0000
@@ -90,8 +90,6 @@ static void darwin_mourn_inferior (struc
static int darwin_lookup_task (char *args, task_t * ptask, int *ppid);
-static void darwin_kill_inferior (struct target_ops *ops);
-
static void darwin_ptrace_me (void);
static void darwin_ptrace_him (int pid);
@@ -337,8 +335,7 @@ darwin_stop (ptid_t t)
}
static void
-darwin_resume (struct target_ops *ops,
- ptid_t ptid, int step, enum target_signal signal)
+darwin_resume_1 (ptid_t ptid, int step, enum target_signal signal)
{
struct target_waitstatus status;
int pid;
@@ -406,6 +403,13 @@ darwin_resume (struct target_ops *ops,
}
}
+static void
+darwin_resume (struct target_ops *ops,
+ ptid_t ptid, int step, enum target_signal signal)
+{
+ darwin_resume_1 (ptid, step, signal);
+}
+
kern_return_t
catch_exception_raise_state
(mach_port_t port,
@@ -475,8 +479,7 @@ catch_exception_raise (mach_port_t port,
}
static ptid_t
-darwin_wait (struct target_ops *ops,
- ptid_t ptid, struct target_waitstatus *status)
+darwin_wait_1 (ptid_t ptid, struct target_waitstatus *status)
{
kern_return_t kret;
mach_msg_header_t *hdr = &msgin.hdr;
@@ -613,6 +616,13 @@ darwin_wait (struct target_ops *ops,
}
}
+static ptid_t
+darwin_wait (struct target_ops *ops,
+ ptid_t ptid, struct target_waitstatus *status)
+{
+ return darwin_wait_1 (ptid, status);
+}
+
static void
darwin_mourn_inferior (struct target_ops *ops)
{
@@ -668,7 +678,7 @@ darwin_mourn_inferior (struct target_ops
}
static void
-darwin_stop_inferior (struct target_ops *ops, darwin_inferior *inf)
+darwin_stop_inferior_1 (darwin_inferior *inf)
{
struct target_waitstatus wstatus;
ptid_t ptid;
@@ -688,12 +698,18 @@ darwin_stop_inferior (struct target_ops
if (res != 0)
warning (_("cannot kill: %s\n"), strerror (errno));
- ptid = darwin_wait (ops, inferior_ptid, &wstatus);
+ ptid = darwin_wait_1 (inferior_ptid, &wstatus);
gdb_assert (wstatus.kind = TARGET_WAITKIND_STOPPED);
}
static void
-darwin_kill_inferior (struct target_ops *ops)
+darwin_stop_inferior (struct target_ops *ops, darwin_inferior *inf)
+{
+ darwin_stop_inferior_1 (inf);
+}
+
+static void
+darwin_kill_inferior (void)
{
struct target_waitstatus wstatus;
ptid_t ptid;
@@ -706,7 +722,7 @@ darwin_kill_inferior (struct target_ops
if (ptid_equal (inferior_ptid, null_ptid))
return;
- darwin_stop_inferior (ops, darwin_inf);
+ darwin_stop_inferior_1 (darwin_inf);
res = PTRACE (PT_KILL, darwin_inf->pid, 0, 0);
gdb_assert (res == 0);
@@ -714,13 +730,13 @@ darwin_kill_inferior (struct target_ops
if (msg_state == GOT_MESSAGE)
{
exc_msg.ex_type = 0;
- darwin_resume (ops, inferior_ptid, 0, 0);
+ darwin_resume_1 (inferior_ptid, 0, 0);
}
kret = task_resume (darwin_inf->task);
MACH_CHECK_ERROR (kret);
- ptid = darwin_wait (ops, inferior_ptid, &wstatus);
+ ptid = darwin_wait_1 (inferior_ptid, &wstatus);
/* This double wait seems required... */
res = waitpid (darwin_inf->pid, &status, 0);
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [RFC] How to get target_ops from to_kill method? 2009-03-16 16:42 [RFC] How to get target_ops from to_kill method? Joel Brobecker @ 2009-03-16 17:02 ` Pedro Alves 2009-03-16 17:24 ` Joel Brobecker 0 siblings, 1 reply; 12+ messages in thread From: Pedro Alves @ 2009-03-16 17:02 UTC (permalink / raw) To: gdb-patches; +Cc: Joel Brobecker, Tristan Gingold On Monday 16 March 2009 16:22:47, Joel Brobecker wrote: > As I was hinting in one of my earlier emails, there is a nasty error > in darwin-nat.c, in the fact that we set the darwin_ops->to_kill method > to a procedure that has the wrong profile: darwin_kill_inferior takes > a target_ops * as its parameter, whereas the to_kill method is supposed > to take none! Thank you very much for handling these breakages. > As it turns out, all the routines being used by darwin_kill_inferior > don't use the target_ops. So what my second patch did was extract out > each of these routines inside another identical function, but without > the target_ops parameter. What this does, basically, is defined the > target_ops methods as wrappers to the real routines. This is what my > second patch does. I much prefer this version over the other. It's incremental, and doesn't add any hack or reference to the current_target global. > > However, I'm really wondering whether it would make sense to have > *all* the methods take the target_ops as the first parameter. We've > been slowly adding this parameter as we need them, but really, why > not be consistent across the board? Mostly, because it's a bunch of work that affects most native targets. I tried hard to avoid missing any conversion in the last set of changes, but, it ended up I broke a lot of stuff... But, yeah, there's a lot of inconsistency here. -- Pedro Alves ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFC] How to get target_ops from to_kill method? 2009-03-16 17:02 ` Pedro Alves @ 2009-03-16 17:24 ` Joel Brobecker 2009-03-16 17:24 ` Pedro Alves 0 siblings, 1 reply; 12+ messages in thread From: Joel Brobecker @ 2009-03-16 17:24 UTC (permalink / raw) To: Pedro Alves; +Cc: gdb-patches, Tristan Gingold > Thank you very much for handling these breakages. No problem, I know how easily they can happen. [about having a target_ops argument for all methods] > Mostly, because it's a bunch of work that affects most native > targets. I tried hard to avoid missing any conversion in > the last set of changes, but, it ended up I broke a lot > of stuff... But, yeah, there's a lot of inconsistency > here. Yeah, fixing them all would be a lot of work, indeed. How about we decide that, from now on, all new methods should have a target_ops parameter as their first argument? Do you think that it would be a good thing? We can fix the others as needed... > I much prefer this version over the other. It's incremental, and > doesn't add any hack or reference to the current_target global. Me too. I haven't checked it in, yet, because it would become unecessary if we added the target_ops parameter to the to_kill method, which I can take care of.... What do you think? -- Joel ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFC] How to get target_ops from to_kill method? 2009-03-16 17:24 ` Joel Brobecker @ 2009-03-16 17:24 ` Pedro Alves 2009-03-16 19:07 ` Joel Brobecker 0 siblings, 1 reply; 12+ messages in thread From: Pedro Alves @ 2009-03-16 17:24 UTC (permalink / raw) To: Joel Brobecker; +Cc: gdb-patches, Tristan Gingold On Monday 16 March 2009 17:16:13, Joel Brobecker wrote: > > Yeah, fixing them all would be a lot of work, indeed. How about > we decide that, from now on, all new methods should have a target_ops > parameter as their first argument? Do you think that it would be > a good thing? We can fix the others as needed... I can't see it a bad thing, so I'm on for it. > > I much prefer this version over the other. It's incremental, and > > doesn't add any hack or reference to the current_target global. > > Me too. I haven't checked it in, yet, because it would become > unecessary if we added the target_ops parameter to the to_kill > method, which I can take care of.... What do you think? If you're willing to, it sounds very good to me. :-) -- Pedro Alves ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFC] How to get target_ops from to_kill method? 2009-03-16 17:24 ` Pedro Alves @ 2009-03-16 19:07 ` Joel Brobecker 2009-03-16 22:22 ` Joel Brobecker 0 siblings, 1 reply; 12+ messages in thread From: Joel Brobecker @ 2009-03-16 19:07 UTC (permalink / raw) To: Pedro Alves; +Cc: gdb-patches, Tristan Gingold > > Yeah, fixing them all would be a lot of work, indeed. How about > > we decide that, from now on, all new methods should have a target_ops > > parameter as their first argument? Do you think that it would be > > a good thing? We can fix the others as needed... > > I can't see it a bad thing, so I'm on for it. Excellent. So, unless I hear any objection, I'll add a comment at the beginning of the target_ops structure that details this new requirement. > > > I much prefer this version over the other. It's incremental, and > > > doesn't add any hack or reference to the current_target global. > > > > Me too. I haven't checked it in, yet, because it would become > > unecessary if we added the target_ops parameter to the to_kill > > method, which I can take care of.... What do you think? > > If you're willing to, it sounds very good to me. :-) Hey, you're not the only one who's allowed to break other's builds, you know? ;-) I'll take care of that asap. (I have to switch to something else for the rest of the afternoon) -- Joel ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFC] How to get target_ops from to_kill method? 2009-03-16 19:07 ` Joel Brobecker @ 2009-03-16 22:22 ` Joel Brobecker 2009-03-17 0:05 ` Pedro Alves 0 siblings, 1 reply; 12+ messages in thread From: Joel Brobecker @ 2009-03-16 22:22 UTC (permalink / raw) To: Pedro Alves; +Cc: gdb-patches, Tristan Gingold [-- Attachment #1: Type: text/plain, Size: 742 bytes --] Hi Pedro, Our Windows machine was so slow building GDB today that it gave me extra time to work on this (between various build failures :-(). So here's a patch. Do you think that the implementation for "target_kill" is good? That was my first implementation until I realized that the to_kill field is inherited. So perhaps I can simplify the implementation by calling the to_kill field from the target layer that's at the top of the current target stack? Other than that, I think I got all implementations, and I recompiled all the files that I could recompile on my x86_64-linux machine. I also built GDB with --enable-targets=all, even if I don't think it help test that much more since most impacted files are "native" units. -- Joel [-- Attachment #2: to_kill.diff --] [-- Type: text/x-diff, Size: 11253 bytes --] commit cb91440f06e701569775fd8b7c6fe396524f0e80 Author: Joel Brobecker <brobecker@adacore.com> Date: Mon Mar 16 16:00:31 2009 -0400 Add a target_ops parameter to the to_kill method in struct target_ops. * target.h (struct target_ops): Add a "target_ops *" parameter to method to_kill. (target_kill): Remove macro. Add declaration. * target.c (debug_to_kill): Add ops parameter. Update call to debug_target.to_kill. (target_kill): New function. (update_current_target): Update the call to de_fault for field "to_kill". * gnu-nat.c, go32-nat.c, hpux-thread.c, inf-ptrace.c, inf-ttrace.c, linux-nat.c, monitor.c, nto-procfs.c, procfs.c, remote-m32r-sdi.c, remote-mips.c, remote-sim.c, remote.c, windows-nat.c: Update accordingly. diff --git a/gdb/gnu-nat.c b/gdb/gnu-nat.c index a43a47d..20b5958 100644 --- a/gdb/gnu-nat.c +++ b/gdb/gnu-nat.c @@ -2030,7 +2030,7 @@ gnu_resume (struct target_ops *ops, \f static void -gnu_kill_inferior (void) +gnu_kill_inferior (struct target_ops *ops) { struct proc *task = gnu_current_inf->task; if (task) diff --git a/gdb/go32-nat.c b/gdb/go32-nat.c index a5a889c..fc45f3f 100644 --- a/gdb/go32-nat.c +++ b/gdb/go32-nat.c @@ -184,7 +184,7 @@ static int go32_xfer_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len, struct target_ops *target); static void go32_files_info (struct target_ops *target); static void go32_stop (ptid_t); -static void go32_kill_inferior (void); +static void go32_kill_inferior (struct target_ops *ops); static void go32_create_inferior (struct target_ops *ops, char *exec_file, char *args, char **env, int from_tty); static void go32_mourn_inferior (struct target_ops *ops); @@ -580,7 +580,7 @@ go32_stop (ptid_t ptid) } static void -go32_kill_inferior (void) +go32_kill_inferior (struct target_ops *ops) { redir_cmdline_delete (&child_cmd); resume_signal = -1; @@ -607,7 +607,7 @@ go32_create_inferior (char *exec_file, char *args, char **env, int from_tty) if (prog_has_started) { go32_stop (inferior_ptid); - go32_kill_inferior (); + go32_kill_inferior (ops); } resume_signal = -1; resume_is_step = 0; @@ -690,7 +690,7 @@ go32_mourn_inferior (struct target_ops *ops) at all times, but it doesn't, probably under an assumption that the OS cleans up when the debuggee exits. */ i386_cleanup_dregs (); - go32_kill_inferior (); + go32_kill_inferior (ops); generic_mourn_inferior (); } diff --git a/gdb/hpux-thread.c b/gdb/hpux-thread.c index f0acfcf..ab5eb93 100644 --- a/gdb/hpux-thread.c +++ b/gdb/hpux-thread.c @@ -426,9 +426,9 @@ hpux_thread_files_info (struct target_ops *ignore) } static void -hpux_thread_kill_inferior (void) +hpux_thread_kill_inferior (struct target_ops *ops) { - deprecated_child_ops.to_kill (); + deprecated_child_ops.to_kill (ops); } static void diff --git a/gdb/inf-ptrace.c b/gdb/inf-ptrace.c index f40b6b7..f088ffd 100644 --- a/gdb/inf-ptrace.c +++ b/gdb/inf-ptrace.c @@ -320,7 +320,7 @@ inf_ptrace_detach (struct target_ops *ops, char *args, int from_tty) /* Kill the inferior. */ static void -inf_ptrace_kill (void) +inf_ptrace_kill (struct target_ops *ops) { pid_t pid = ptid_get_pid (inferior_ptid); int status; diff --git a/gdb/inf-ttrace.c b/gdb/inf-ttrace.c index 965282a..3014c2c 100644 --- a/gdb/inf-ttrace.c +++ b/gdb/inf-ttrace.c @@ -814,7 +814,7 @@ inf_ttrace_detach (struct target_ops *ops, char *args, int from_tty) } static void -inf_ttrace_kill (void) +inf_ttrace_kill (struct target_ops *ops) { pid_t pid = ptid_get_pid (inferior_ptid); diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c index 12b786e..cc5d3e7 100644 --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -3167,7 +3167,7 @@ kill_wait_callback (struct lwp_info *lp, void *data) } static void -linux_nat_kill (void) +linux_nat_kill (struct target_ops *ops) { struct target_waitstatus last; ptid_t last_ptid; diff --git a/gdb/monitor.c b/gdb/monitor.c index 5557998..60db1dc 100644 --- a/gdb/monitor.c +++ b/gdb/monitor.c @@ -1991,7 +1991,7 @@ monitor_xfer_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len, int write, } static void -monitor_kill (void) +monitor_kill (struct target_ops *ops) { return; /* ignore attempts to kill target system */ } diff --git a/gdb/nto-procfs.c b/gdb/nto-procfs.c index 75102f1..b46c64d 100644 --- a/gdb/nto-procfs.c +++ b/gdb/nto-procfs.c @@ -1120,7 +1120,7 @@ procfs_stop (ptid_t ptid) } static void -procfs_kill_inferior (void) +procfs_kill_inferior (struct target_ops *ops) { target_mourn_inferior (); } diff --git a/gdb/procfs.c b/gdb/procfs.c index c4b6b55..adb44f4 100644 --- a/gdb/procfs.c +++ b/gdb/procfs.c @@ -123,7 +123,7 @@ static void procfs_fetch_registers (struct target_ops *, static void procfs_store_registers (struct target_ops *, struct regcache *, int); static void procfs_notice_signals (ptid_t); -static void procfs_kill_inferior (void); +static void procfs_kill_inferior (struct target_ops *ops); static void procfs_mourn_inferior (struct target_ops *ops); static void procfs_create_inferior (struct target_ops *, char *, char *, char **, int); @@ -4764,7 +4764,7 @@ unconditionally_kill_inferior (procinfo *pi) */ static void -procfs_kill_inferior (void) +procfs_kill_inferior (struct target_ops *ops) { if (!ptid_equal (inferior_ptid, null_ptid)) /* ? */ { diff --git a/gdb/remote-m32r-sdi.c b/gdb/remote-m32r-sdi.c index baf9c61..c7f908e 100644 --- a/gdb/remote-m32r-sdi.c +++ b/gdb/remote-m32r-sdi.c @@ -1112,7 +1112,7 @@ m32r_xfer_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len, } static void -m32r_kill (void) +m32r_kill (struct target_ops *ops) { if (remote_debug) fprintf_unfiltered (gdb_stdlog, "m32r_kill()\n"); diff --git a/gdb/remote-mips.c b/gdb/remote-mips.c index 66e8328..a442c66 100644 --- a/gdb/remote-mips.c +++ b/gdb/remote-mips.c @@ -2129,7 +2129,7 @@ mips_files_info (struct target_ops *ignore) right port, we could interrupt the process with a break signal. */ static void -mips_kill (void) +mips_kill (struct target_ops *ops) { if (!mips_wait_flag) return; diff --git a/gdb/remote-sim.c b/gdb/remote-sim.c index bb67b88..4eae65a 100644 --- a/gdb/remote-sim.c +++ b/gdb/remote-sim.c @@ -72,7 +72,7 @@ static void gdb_os_evprintf_filtered (host_callback *, const char *, va_list); static void gdb_os_error (host_callback *, const char *, ...) ATTR_NORETURN; -static void gdbsim_kill (void); +static void gdbsim_kill (struct target_ops *); static void gdbsim_load (char *prog, int fromtty); @@ -378,7 +378,7 @@ gdbsim_store_register (struct target_ops *ops, and releasing other resources acquired by the simulated program. */ static void -gdbsim_kill (void) +gdbsim_kill (struct target_ops *ops) { if (remote_debug) printf_filtered ("gdbsim_kill\n"); @@ -451,7 +451,7 @@ gdbsim_create_inferior (struct target_ops *target, char *exec_file, char *args, args); if (ptid_equal (inferior_ptid, remote_sim_ptid)) - gdbsim_kill (); + gdbsim_kill (target); remove_breakpoints (); init_wait_for_inferior (); diff --git a/gdb/remote.c b/gdb/remote.c index 0c27307..e3a7170 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -111,7 +111,7 @@ static void remote_send (char **buf, long *sizeof_buf_p); static int readchar (int timeout); -static void remote_kill (void); +static void remote_kill (struct target_ops *ops); static int tohex (int nib); @@ -6528,7 +6528,7 @@ getpkt_or_notif_sane (char **buf, long *sizeof_buf, int forever) \f static void -remote_kill (void) +remote_kill (struct target_ops *ops) { /* Use catch_errors so the user can quit from gdb even when we aren't on speaking terms with the remote system. */ @@ -6560,7 +6560,7 @@ remote_vkill (int pid, struct remote_state *rs) } static void -extended_remote_kill (void) +extended_remote_kill (struct target_ops *ops) { int res; int pid = ptid_get_pid (inferior_ptid); diff --git a/gdb/target.c b/gdb/target.c index b89d551..27139a9 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -136,7 +136,7 @@ static void debug_to_terminal_ours (void); static void debug_to_terminal_info (char *, int); -static void debug_to_kill (void); +static void debug_to_kill (struct target_ops *); static void debug_to_load (char *, int); @@ -257,6 +257,24 @@ target_ignore (void) } void +target_kill (void) +{ + struct target_ops *t; + + for (t = current_target.beneath; t != NULL; t = t->beneath) + if (t->to_kill != NULL) + { + if (targetdebug) + fprintf_unfiltered (gdb_stdlog, "target_kill ()\n"); + + t->to_kill (t); + return; + } + + noprocess (); +} + +void target_load (char *arg, int from_tty) { dcache_invalidate (target_dcache); @@ -557,7 +575,7 @@ update_current_target (void) de_fault (to_terminal_info, default_terminal_info); de_fault (to_kill, - (void (*) (void)) + (void (*) (struct target_ops *)) noprocess); de_fault (to_load, (void (*) (char *, int)) @@ -3025,9 +3043,9 @@ debug_to_terminal_info (char *arg, int from_tty) } static void -debug_to_kill (void) +debug_to_kill (struct target_ops *ops) { - debug_target.to_kill (); + debug_target.to_kill (ops); fprintf_unfiltered (gdb_stdlog, "target_kill ()\n"); } diff --git a/gdb/target.h b/gdb/target.h index 7f4cd8f..e7f087b 100644 --- a/gdb/target.h +++ b/gdb/target.h @@ -378,7 +378,7 @@ struct target_ops void (*to_terminal_ours) (void); void (*to_terminal_save_ours) (void); void (*to_terminal_info) (char *, int); - void (*to_kill) (void); + void (*to_kill) (struct target_ops *); void (*to_load) (char *, int); int (*to_lookup_symbol) (char *, CORE_ADDR *); void (*to_create_inferior) (struct target_ops *, @@ -790,8 +790,7 @@ extern void print_section_info (struct target_ops *, bfd *); /* Kill the inferior process. Make it go away. */ -#define target_kill() \ - (*current_target.to_kill) () +extern void target_kill (void); /* Load an executable file into the target process. This is expected to not only bring new code into the target process, but also to diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index 33ff1a0..2ab1709 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -114,7 +114,7 @@ static int debug_registers_used; static void windows_stop (ptid_t); static int windows_thread_alive (struct target_ops *, ptid_t); -static void windows_kill_inferior (void); +static void windows_kill_inferior (struct target_ops *); static enum target_signal last_sig = TARGET_SIGNAL_0; /* Set if a signal was received from the debugged process */ @@ -1493,7 +1493,7 @@ windows_wait (struct target_ops *ops, detach = deprecated_ui_loop_hook (0); if (detach) - windows_kill_inferior (); + windows_kill_inferior (ops); } } } @@ -2014,7 +2014,7 @@ windows_xfer_memory (CORE_ADDR memaddr, gdb_byte *our, int len, } static void -windows_kill_inferior (void) +windows_kill_inferior (struct target_ops *ops) { CHECK (TerminateProcess (current_process_handle, 0)); ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFC] How to get target_ops from to_kill method? 2009-03-16 22:22 ` Joel Brobecker @ 2009-03-17 0:05 ` Pedro Alves 2009-03-17 18:05 ` Joel Brobecker 0 siblings, 1 reply; 12+ messages in thread From: Pedro Alves @ 2009-03-17 0:05 UTC (permalink / raw) To: Joel Brobecker; +Cc: gdb-patches, Tristan Gingold On Monday 16 March 2009 22:11:03, Joel Brobecker wrote: > Do you think that the implementation for "target_kill" is good? > That was my first implementation until I realized that the to_kill > field is inherited. So perhaps I can simplify the implementation by > calling the to_kill field from the target layer that's at the top > of the current target stack? The implementation of the function itself is good. What happens is that we're switching from having the stack "hardcoded" at push time, to have it traversed on demand, so, this method doesn't need to be inherited and shouldn't be defaulted anymore. You can also delete debug_to_kill, it becomes unreacheable code, since you start the lookup at current_target.beneath, and you now handle the debug outputting in the new target_kill function. At some point, I'd like to implement some of the ideas at: http://sourceware.org/ml/gdb-patches/2009-02/msg00156.html The most important/annoying part is to convert the targets and the method interfaces, due to the need to touch "native" files. > Other than that, I think I got all implementations, and I recompiled > all the files that I could recompile on my x86_64-linux machine. > I also built GDB with --enable-targets=all, even if I don't think > it help test that much more since most impacted files are "native" > units. Yeah, that's the problem with these conversions. :-) > static void > -hpux_thread_kill_inferior (void) > +hpux_thread_kill_inferior (struct target_ops *ops) > { > - deprecated_child_ops.to_kill (); > + deprecated_child_ops.to_kill (ops); Doesn't matter much for a deprecated_child_ops target user, but, this should be: deprecated_child_ops.to_kill (&deprecated_child_ops); ... so the next target in the chain can again do find_target_beneath (ops)->to_kill (find_target_beneath (ops)), and so on. -- Pedro Alves ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFC] How to get target_ops from to_kill method? 2009-03-17 0:05 ` Pedro Alves @ 2009-03-17 18:05 ` Joel Brobecker 2009-03-17 18:28 ` Pedro Alves 0 siblings, 1 reply; 12+ messages in thread From: Joel Brobecker @ 2009-03-17 18:05 UTC (permalink / raw) To: Pedro Alves; +Cc: gdb-patches, Tristan Gingold [-- Attachment #1: Type: text/plain, Size: 1557 bytes --] > At some point, I'd like to implement some of the ideas at: > > http://sourceware.org/ml/gdb-patches/2009-02/msg00156.html Yep, they make good sense. > The most important/annoying part is to convert the targets and the > method interfaces, due to the need to touch "native" files. I know what you mean, now :) > Doesn't matter much for a deprecated_child_ops target user, > but, this should be: > > deprecated_child_ops.to_kill (&deprecated_child_ops); > > ... so the next target in the chain can again do > find_target_beneath (ops)->to_kill (find_target_beneath (ops)), > and so on. Humpf, yes, right. That was pretty mindless of me... Here is what I propose to check in. Do you think I should remove the INHERIT for the to_kill method as well? 2009-03-17 Joel Brobecker <brobecker@adacore.com> Add a target_ops parameter to the to_kill method in struct target_ops. * target.h (struct target_ops): Add a "target_ops *" parameter to method to_kill. (target_kill): Remove macro. Add declaration. * target.c (debug_to_kill): Delete, no longer necessary. (target_kill): New function. (update_current_target): Update the call to de_fault for field "to_kill". (setup_target_debug): Do not set current_target.to_kill. * gnu-nat.c, go32-nat.c, hpux-thread.c, inf-ptrace.c, inf-ttrace.c, linux-nat.c, monitor.c, nto-procfs.c, procfs.c, remote-m32r-sdi.c, remote-mips.c, remote-sim.c, remote.c, windows-nat.c: Update accordingly. -- Joel [-- Attachment #2: to_kill.diff --] [-- Type: text/x-diff, Size: 11282 bytes --] diff --git a/gdb/gnu-nat.c b/gdb/gnu-nat.c index a43a47d..20b5958 100644 --- a/gdb/gnu-nat.c +++ b/gdb/gnu-nat.c @@ -2030,7 +2030,7 @@ gnu_resume (struct target_ops *ops, \f static void -gnu_kill_inferior (void) +gnu_kill_inferior (struct target_ops *ops) { struct proc *task = gnu_current_inf->task; if (task) diff --git a/gdb/go32-nat.c b/gdb/go32-nat.c index ce8b6dc..e1f793e 100644 --- a/gdb/go32-nat.c +++ b/gdb/go32-nat.c @@ -184,7 +184,7 @@ static int go32_xfer_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len, struct target_ops *target); static void go32_files_info (struct target_ops *target); static void go32_stop (ptid_t); -static void go32_kill_inferior (void); +static void go32_kill_inferior (struct target_ops *ops); static void go32_create_inferior (struct target_ops *ops, char *exec_file, char *args, char **env, int from_tty); static void go32_mourn_inferior (struct target_ops *ops); @@ -580,7 +580,7 @@ go32_stop (ptid_t ptid) } static void -go32_kill_inferior (void) +go32_kill_inferior (struct target_ops *ops) { redir_cmdline_delete (&child_cmd); resume_signal = -1; @@ -608,7 +608,7 @@ go32_create_inferior (struct target_ops *ops, char *exec_file, if (prog_has_started) { go32_stop (inferior_ptid); - go32_kill_inferior (); + go32_kill_inferior (ops); } resume_signal = -1; resume_is_step = 0; @@ -691,7 +691,7 @@ go32_mourn_inferior (struct target_ops *ops) at all times, but it doesn't, probably under an assumption that the OS cleans up when the debuggee exits. */ i386_cleanup_dregs (); - go32_kill_inferior (); + go32_kill_inferior (ops); generic_mourn_inferior (); } diff --git a/gdb/hpux-thread.c b/gdb/hpux-thread.c index f0acfcf..bdc547d 100644 --- a/gdb/hpux-thread.c +++ b/gdb/hpux-thread.c @@ -426,9 +426,9 @@ hpux_thread_files_info (struct target_ops *ignore) } static void -hpux_thread_kill_inferior (void) +hpux_thread_kill_inferior (struct target_ops *ops) { - deprecated_child_ops.to_kill (); + deprecated_child_ops.to_kill (&deprecated_child_ops); } static void diff --git a/gdb/inf-ptrace.c b/gdb/inf-ptrace.c index f40b6b7..f088ffd 100644 --- a/gdb/inf-ptrace.c +++ b/gdb/inf-ptrace.c @@ -320,7 +320,7 @@ inf_ptrace_detach (struct target_ops *ops, char *args, int from_tty) /* Kill the inferior. */ static void -inf_ptrace_kill (void) +inf_ptrace_kill (struct target_ops *ops) { pid_t pid = ptid_get_pid (inferior_ptid); int status; diff --git a/gdb/inf-ttrace.c b/gdb/inf-ttrace.c index 965282a..3014c2c 100644 --- a/gdb/inf-ttrace.c +++ b/gdb/inf-ttrace.c @@ -814,7 +814,7 @@ inf_ttrace_detach (struct target_ops *ops, char *args, int from_tty) } static void -inf_ttrace_kill (void) +inf_ttrace_kill (struct target_ops *ops) { pid_t pid = ptid_get_pid (inferior_ptid); diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c index 12b786e..cc5d3e7 100644 --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -3167,7 +3167,7 @@ kill_wait_callback (struct lwp_info *lp, void *data) } static void -linux_nat_kill (void) +linux_nat_kill (struct target_ops *ops) { struct target_waitstatus last; ptid_t last_ptid; diff --git a/gdb/monitor.c b/gdb/monitor.c index 5557998..60db1dc 100644 --- a/gdb/monitor.c +++ b/gdb/monitor.c @@ -1991,7 +1991,7 @@ monitor_xfer_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len, int write, } static void -monitor_kill (void) +monitor_kill (struct target_ops *ops) { return; /* ignore attempts to kill target system */ } diff --git a/gdb/nto-procfs.c b/gdb/nto-procfs.c index 75102f1..b46c64d 100644 --- a/gdb/nto-procfs.c +++ b/gdb/nto-procfs.c @@ -1120,7 +1120,7 @@ procfs_stop (ptid_t ptid) } static void -procfs_kill_inferior (void) +procfs_kill_inferior (struct target_ops *ops) { target_mourn_inferior (); } diff --git a/gdb/procfs.c b/gdb/procfs.c index c4b6b55..adb44f4 100644 --- a/gdb/procfs.c +++ b/gdb/procfs.c @@ -123,7 +123,7 @@ static void procfs_fetch_registers (struct target_ops *, static void procfs_store_registers (struct target_ops *, struct regcache *, int); static void procfs_notice_signals (ptid_t); -static void procfs_kill_inferior (void); +static void procfs_kill_inferior (struct target_ops *ops); static void procfs_mourn_inferior (struct target_ops *ops); static void procfs_create_inferior (struct target_ops *, char *, char *, char **, int); @@ -4764,7 +4764,7 @@ unconditionally_kill_inferior (procinfo *pi) */ static void -procfs_kill_inferior (void) +procfs_kill_inferior (struct target_ops *ops) { if (!ptid_equal (inferior_ptid, null_ptid)) /* ? */ { diff --git a/gdb/remote-m32r-sdi.c b/gdb/remote-m32r-sdi.c index baf9c61..c7f908e 100644 --- a/gdb/remote-m32r-sdi.c +++ b/gdb/remote-m32r-sdi.c @@ -1112,7 +1112,7 @@ m32r_xfer_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len, } static void -m32r_kill (void) +m32r_kill (struct target_ops *ops) { if (remote_debug) fprintf_unfiltered (gdb_stdlog, "m32r_kill()\n"); diff --git a/gdb/remote-mips.c b/gdb/remote-mips.c index 9b514b1..b35bb62 100644 --- a/gdb/remote-mips.c +++ b/gdb/remote-mips.c @@ -2129,7 +2129,7 @@ mips_files_info (struct target_ops *ignore) right port, we could interrupt the process with a break signal. */ static void -mips_kill (void) +mips_kill (struct target_ops *ops) { if (!mips_wait_flag) return; @@ -3276,7 +3276,6 @@ mips_load (char *file, int from_tty) to a different value than GDB thinks it has. The following ensures that the write_pc() WILL update the PC value: */ struct regcache *regcache = get_current_regcache (); - regcache_invalidate (regcache, gdbarch_pc_regnum (get_regcache_arch (regcache))); } diff --git a/gdb/remote-sim.c b/gdb/remote-sim.c index bb67b88..4eae65a 100644 --- a/gdb/remote-sim.c +++ b/gdb/remote-sim.c @@ -72,7 +72,7 @@ static void gdb_os_evprintf_filtered (host_callback *, const char *, va_list); static void gdb_os_error (host_callback *, const char *, ...) ATTR_NORETURN; -static void gdbsim_kill (void); +static void gdbsim_kill (struct target_ops *); static void gdbsim_load (char *prog, int fromtty); @@ -378,7 +378,7 @@ gdbsim_store_register (struct target_ops *ops, and releasing other resources acquired by the simulated program. */ static void -gdbsim_kill (void) +gdbsim_kill (struct target_ops *ops) { if (remote_debug) printf_filtered ("gdbsim_kill\n"); @@ -451,7 +451,7 @@ gdbsim_create_inferior (struct target_ops *target, char *exec_file, char *args, args); if (ptid_equal (inferior_ptid, remote_sim_ptid)) - gdbsim_kill (); + gdbsim_kill (target); remove_breakpoints (); init_wait_for_inferior (); diff --git a/gdb/remote.c b/gdb/remote.c index 0c27307..e3a7170 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -111,7 +111,7 @@ static void remote_send (char **buf, long *sizeof_buf_p); static int readchar (int timeout); -static void remote_kill (void); +static void remote_kill (struct target_ops *ops); static int tohex (int nib); @@ -6528,7 +6528,7 @@ getpkt_or_notif_sane (char **buf, long *sizeof_buf, int forever) \f static void -remote_kill (void) +remote_kill (struct target_ops *ops) { /* Use catch_errors so the user can quit from gdb even when we aren't on speaking terms with the remote system. */ @@ -6560,7 +6560,7 @@ remote_vkill (int pid, struct remote_state *rs) } static void -extended_remote_kill (void) +extended_remote_kill (struct target_ops *ops) { int res; int pid = ptid_get_pid (inferior_ptid); diff --git a/gdb/target.c b/gdb/target.c index b89d551..e90b6d7 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -136,8 +136,6 @@ static void debug_to_terminal_ours (void); static void debug_to_terminal_info (char *, int); -static void debug_to_kill (void); - static void debug_to_load (char *, int); static int debug_to_lookup_symbol (char *, CORE_ADDR *); @@ -257,6 +255,24 @@ target_ignore (void) } void +target_kill (void) +{ + struct target_ops *t; + + for (t = current_target.beneath; t != NULL; t = t->beneath) + if (t->to_kill != NULL) + { + if (targetdebug) + fprintf_unfiltered (gdb_stdlog, "target_kill ()\n"); + + t->to_kill (t); + return; + } + + noprocess (); +} + +void target_load (char *arg, int from_tty) { dcache_invalidate (target_dcache); @@ -557,7 +573,7 @@ update_current_target (void) de_fault (to_terminal_info, default_terminal_info); de_fault (to_kill, - (void (*) (void)) + (void (*) (struct target_ops *)) noprocess); de_fault (to_load, (void (*) (char *, int)) @@ -3025,14 +3041,6 @@ debug_to_terminal_info (char *arg, int from_tty) } static void -debug_to_kill (void) -{ - debug_target.to_kill (); - - fprintf_unfiltered (gdb_stdlog, "target_kill ()\n"); -} - -static void debug_to_load (char *args, int from_tty) { debug_target.to_load (args, from_tty); @@ -3227,7 +3235,6 @@ setup_target_debug (void) current_target.to_terminal_ours = debug_to_terminal_ours; current_target.to_terminal_save_ours = debug_to_terminal_save_ours; current_target.to_terminal_info = debug_to_terminal_info; - current_target.to_kill = debug_to_kill; current_target.to_load = debug_to_load; current_target.to_lookup_symbol = debug_to_lookup_symbol; current_target.to_post_startup_inferior = debug_to_post_startup_inferior; diff --git a/gdb/target.h b/gdb/target.h index 7f4cd8f..e7f087b 100644 --- a/gdb/target.h +++ b/gdb/target.h @@ -378,7 +378,7 @@ struct target_ops void (*to_terminal_ours) (void); void (*to_terminal_save_ours) (void); void (*to_terminal_info) (char *, int); - void (*to_kill) (void); + void (*to_kill) (struct target_ops *); void (*to_load) (char *, int); int (*to_lookup_symbol) (char *, CORE_ADDR *); void (*to_create_inferior) (struct target_ops *, @@ -790,8 +790,7 @@ extern void print_section_info (struct target_ops *, bfd *); /* Kill the inferior process. Make it go away. */ -#define target_kill() \ - (*current_target.to_kill) () +extern void target_kill (void); /* Load an executable file into the target process. This is expected to not only bring new code into the target process, but also to diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index 33ff1a0..2ab1709 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -114,7 +114,7 @@ static int debug_registers_used; static void windows_stop (ptid_t); static int windows_thread_alive (struct target_ops *, ptid_t); -static void windows_kill_inferior (void); +static void windows_kill_inferior (struct target_ops *); static enum target_signal last_sig = TARGET_SIGNAL_0; /* Set if a signal was received from the debugged process */ @@ -1493,7 +1493,7 @@ windows_wait (struct target_ops *ops, detach = deprecated_ui_loop_hook (0); if (detach) - windows_kill_inferior (); + windows_kill_inferior (ops); } } } @@ -2014,7 +2014,7 @@ windows_xfer_memory (CORE_ADDR memaddr, gdb_byte *our, int len, } static void -windows_kill_inferior (void) +windows_kill_inferior (struct target_ops *ops) { CHECK (TerminateProcess (current_process_handle, 0)); ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFC] How to get target_ops from to_kill method? 2009-03-17 18:05 ` Joel Brobecker @ 2009-03-17 18:28 ` Pedro Alves 2009-03-17 19:11 ` Joel Brobecker 0 siblings, 1 reply; 12+ messages in thread From: Pedro Alves @ 2009-03-17 18:28 UTC (permalink / raw) To: Joel Brobecker; +Cc: gdb-patches, Tristan Gingold On Tuesday 17 March 2009 17:46:25, Joel Brobecker wrote: > Here is what I propose to check in. Do you think I should remove > the INHERIT for the to_kill method as well? > Yes. You're not accessing the inherited or de_faulted current_target.to_kill anymore. You always go through the non-inherited current_target.beneath->to_kill, so, you can remove the INHERIT, and the de_fault for to_kill. -- Pedro Alves ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFC] How to get target_ops from to_kill method? 2009-03-17 18:28 ` Pedro Alves @ 2009-03-17 19:11 ` Joel Brobecker 2009-03-17 19:13 ` Pedro Alves 0 siblings, 1 reply; 12+ messages in thread From: Joel Brobecker @ 2009-03-17 19:11 UTC (permalink / raw) To: Pedro Alves; +Cc: gdb-patches, Tristan Gingold [-- Attachment #1: Type: text/plain, Size: 1185 bytes --] > Yes. You're not accessing the inherited or de_faulted > current_target.to_kill anymore. You always go through the non-inherited > current_target.beneath->to_kill, so, you can remove the INHERIT, and the > de_fault for to_kill. Cool! I really like your ideas about the target vector. I think it really is going to simplify the handling for that target stack a lot. New patch: Add a target_ops parameter to the to_kill method in struct target_ops. * target.h (struct target_ops): Add a "target_ops *" parameter to method to_kill. (target_kill): Remove macro. Add declaration. * target.c (debug_to_kill): Delete, no longer necessary. (target_kill): New function. (update_current_target): Stop inheriting the to_kill method. Do not de_fault it to no_process either. (setup_target_debug): Do not set current_target.to_kill. * gnu-nat.c, go32-nat.c, hpux-thread.c, inf-ptrace.c, inf-ttrace.c, linux-nat.c, monitor.c, nto-procfs.c, procfs.c, remote-m32r-sdi.c, remote-mips.c, remote-sim.c, remote.c, windows-nat.c: Update accordingly. Tested on x86_64-linux again... -- Joel [-- Attachment #2: to_kill.diff --] [-- Type: text/x-diff, Size: 11633 bytes --] diff --git a/gdb/gnu-nat.c b/gdb/gnu-nat.c index a43a47d..20b5958 100644 --- a/gdb/gnu-nat.c +++ b/gdb/gnu-nat.c @@ -2030,7 +2030,7 @@ gnu_resume (struct target_ops *ops, \f static void -gnu_kill_inferior (void) +gnu_kill_inferior (struct target_ops *ops) { struct proc *task = gnu_current_inf->task; if (task) diff --git a/gdb/go32-nat.c b/gdb/go32-nat.c index ce8b6dc..e1f793e 100644 --- a/gdb/go32-nat.c +++ b/gdb/go32-nat.c @@ -184,7 +184,7 @@ static int go32_xfer_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len, struct target_ops *target); static void go32_files_info (struct target_ops *target); static void go32_stop (ptid_t); -static void go32_kill_inferior (void); +static void go32_kill_inferior (struct target_ops *ops); static void go32_create_inferior (struct target_ops *ops, char *exec_file, char *args, char **env, int from_tty); static void go32_mourn_inferior (struct target_ops *ops); @@ -580,7 +580,7 @@ go32_stop (ptid_t ptid) } static void -go32_kill_inferior (void) +go32_kill_inferior (struct target_ops *ops) { redir_cmdline_delete (&child_cmd); resume_signal = -1; @@ -608,7 +608,7 @@ go32_create_inferior (struct target_ops *ops, char *exec_file, if (prog_has_started) { go32_stop (inferior_ptid); - go32_kill_inferior (); + go32_kill_inferior (ops); } resume_signal = -1; resume_is_step = 0; @@ -691,7 +691,7 @@ go32_mourn_inferior (struct target_ops *ops) at all times, but it doesn't, probably under an assumption that the OS cleans up when the debuggee exits. */ i386_cleanup_dregs (); - go32_kill_inferior (); + go32_kill_inferior (ops); generic_mourn_inferior (); } diff --git a/gdb/hpux-thread.c b/gdb/hpux-thread.c index f0acfcf..bdc547d 100644 --- a/gdb/hpux-thread.c +++ b/gdb/hpux-thread.c @@ -426,9 +426,9 @@ hpux_thread_files_info (struct target_ops *ignore) } static void -hpux_thread_kill_inferior (void) +hpux_thread_kill_inferior (struct target_ops *ops) { - deprecated_child_ops.to_kill (); + deprecated_child_ops.to_kill (&deprecated_child_ops); } static void diff --git a/gdb/inf-ptrace.c b/gdb/inf-ptrace.c index f40b6b7..f088ffd 100644 --- a/gdb/inf-ptrace.c +++ b/gdb/inf-ptrace.c @@ -320,7 +320,7 @@ inf_ptrace_detach (struct target_ops *ops, char *args, int from_tty) /* Kill the inferior. */ static void -inf_ptrace_kill (void) +inf_ptrace_kill (struct target_ops *ops) { pid_t pid = ptid_get_pid (inferior_ptid); int status; diff --git a/gdb/inf-ttrace.c b/gdb/inf-ttrace.c index 965282a..3014c2c 100644 --- a/gdb/inf-ttrace.c +++ b/gdb/inf-ttrace.c @@ -814,7 +814,7 @@ inf_ttrace_detach (struct target_ops *ops, char *args, int from_tty) } static void -inf_ttrace_kill (void) +inf_ttrace_kill (struct target_ops *ops) { pid_t pid = ptid_get_pid (inferior_ptid); diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c index 12b786e..cc5d3e7 100644 --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -3167,7 +3167,7 @@ kill_wait_callback (struct lwp_info *lp, void *data) } static void -linux_nat_kill (void) +linux_nat_kill (struct target_ops *ops) { struct target_waitstatus last; ptid_t last_ptid; diff --git a/gdb/monitor.c b/gdb/monitor.c index 5557998..60db1dc 100644 --- a/gdb/monitor.c +++ b/gdb/monitor.c @@ -1991,7 +1991,7 @@ monitor_xfer_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len, int write, } static void -monitor_kill (void) +monitor_kill (struct target_ops *ops) { return; /* ignore attempts to kill target system */ } diff --git a/gdb/nto-procfs.c b/gdb/nto-procfs.c index 75102f1..b46c64d 100644 --- a/gdb/nto-procfs.c +++ b/gdb/nto-procfs.c @@ -1120,7 +1120,7 @@ procfs_stop (ptid_t ptid) } static void -procfs_kill_inferior (void) +procfs_kill_inferior (struct target_ops *ops) { target_mourn_inferior (); } diff --git a/gdb/procfs.c b/gdb/procfs.c index c4b6b55..adb44f4 100644 --- a/gdb/procfs.c +++ b/gdb/procfs.c @@ -123,7 +123,7 @@ static void procfs_fetch_registers (struct target_ops *, static void procfs_store_registers (struct target_ops *, struct regcache *, int); static void procfs_notice_signals (ptid_t); -static void procfs_kill_inferior (void); +static void procfs_kill_inferior (struct target_ops *ops); static void procfs_mourn_inferior (struct target_ops *ops); static void procfs_create_inferior (struct target_ops *, char *, char *, char **, int); @@ -4764,7 +4764,7 @@ unconditionally_kill_inferior (procinfo *pi) */ static void -procfs_kill_inferior (void) +procfs_kill_inferior (struct target_ops *ops) { if (!ptid_equal (inferior_ptid, null_ptid)) /* ? */ { diff --git a/gdb/remote-m32r-sdi.c b/gdb/remote-m32r-sdi.c index baf9c61..c7f908e 100644 --- a/gdb/remote-m32r-sdi.c +++ b/gdb/remote-m32r-sdi.c @@ -1112,7 +1112,7 @@ m32r_xfer_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len, } static void -m32r_kill (void) +m32r_kill (struct target_ops *ops) { if (remote_debug) fprintf_unfiltered (gdb_stdlog, "m32r_kill()\n"); diff --git a/gdb/remote-mips.c b/gdb/remote-mips.c index 9b514b1..b35bb62 100644 --- a/gdb/remote-mips.c +++ b/gdb/remote-mips.c @@ -2129,7 +2129,7 @@ mips_files_info (struct target_ops *ignore) right port, we could interrupt the process with a break signal. */ static void -mips_kill (void) +mips_kill (struct target_ops *ops) { if (!mips_wait_flag) return; @@ -3276,7 +3276,6 @@ mips_load (char *file, int from_tty) to a different value than GDB thinks it has. The following ensures that the write_pc() WILL update the PC value: */ struct regcache *regcache = get_current_regcache (); - regcache_invalidate (regcache, gdbarch_pc_regnum (get_regcache_arch (regcache))); } diff --git a/gdb/remote-sim.c b/gdb/remote-sim.c index bb67b88..4eae65a 100644 --- a/gdb/remote-sim.c +++ b/gdb/remote-sim.c @@ -72,7 +72,7 @@ static void gdb_os_evprintf_filtered (host_callback *, const char *, va_list); static void gdb_os_error (host_callback *, const char *, ...) ATTR_NORETURN; -static void gdbsim_kill (void); +static void gdbsim_kill (struct target_ops *); static void gdbsim_load (char *prog, int fromtty); @@ -378,7 +378,7 @@ gdbsim_store_register (struct target_ops *ops, and releasing other resources acquired by the simulated program. */ static void -gdbsim_kill (void) +gdbsim_kill (struct target_ops *ops) { if (remote_debug) printf_filtered ("gdbsim_kill\n"); @@ -451,7 +451,7 @@ gdbsim_create_inferior (struct target_ops *target, char *exec_file, char *args, args); if (ptid_equal (inferior_ptid, remote_sim_ptid)) - gdbsim_kill (); + gdbsim_kill (target); remove_breakpoints (); init_wait_for_inferior (); diff --git a/gdb/remote.c b/gdb/remote.c index 0c27307..e3a7170 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -111,7 +111,7 @@ static void remote_send (char **buf, long *sizeof_buf_p); static int readchar (int timeout); -static void remote_kill (void); +static void remote_kill (struct target_ops *ops); static int tohex (int nib); @@ -6528,7 +6528,7 @@ getpkt_or_notif_sane (char **buf, long *sizeof_buf, int forever) \f static void -remote_kill (void) +remote_kill (struct target_ops *ops) { /* Use catch_errors so the user can quit from gdb even when we aren't on speaking terms with the remote system. */ @@ -6560,7 +6560,7 @@ remote_vkill (int pid, struct remote_state *rs) } static void -extended_remote_kill (void) +extended_remote_kill (struct target_ops *ops) { int res; int pid = ptid_get_pid (inferior_ptid); diff --git a/gdb/target.c b/gdb/target.c index b89d551..86cdb71 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -136,8 +136,6 @@ static void debug_to_terminal_ours (void); static void debug_to_terminal_info (char *, int); -static void debug_to_kill (void); - static void debug_to_load (char *, int); static int debug_to_lookup_symbol (char *, CORE_ADDR *); @@ -257,6 +255,24 @@ target_ignore (void) } void +target_kill (void) +{ + struct target_ops *t; + + for (t = current_target.beneath; t != NULL; t = t->beneath) + if (t->to_kill != NULL) + { + if (targetdebug) + fprintf_unfiltered (gdb_stdlog, "target_kill ()\n"); + + t->to_kill (t); + return; + } + + noprocess (); +} + +void target_load (char *arg, int from_tty) { dcache_invalidate (target_dcache); @@ -430,7 +446,7 @@ update_current_target (void) INHERIT (to_terminal_ours, t); INHERIT (to_terminal_save_ours, t); INHERIT (to_terminal_info, t); - INHERIT (to_kill, t); + /* Do not inherit to_kill. */ INHERIT (to_load, t); INHERIT (to_lookup_symbol, t); /* Do no inherit to_create_inferior. */ @@ -556,9 +572,6 @@ update_current_target (void) target_ignore); de_fault (to_terminal_info, default_terminal_info); - de_fault (to_kill, - (void (*) (void)) - noprocess); de_fault (to_load, (void (*) (char *, int)) tcomplain); @@ -3025,14 +3038,6 @@ debug_to_terminal_info (char *arg, int from_tty) } static void -debug_to_kill (void) -{ - debug_target.to_kill (); - - fprintf_unfiltered (gdb_stdlog, "target_kill ()\n"); -} - -static void debug_to_load (char *args, int from_tty) { debug_target.to_load (args, from_tty); @@ -3227,7 +3232,6 @@ setup_target_debug (void) current_target.to_terminal_ours = debug_to_terminal_ours; current_target.to_terminal_save_ours = debug_to_terminal_save_ours; current_target.to_terminal_info = debug_to_terminal_info; - current_target.to_kill = debug_to_kill; current_target.to_load = debug_to_load; current_target.to_lookup_symbol = debug_to_lookup_symbol; current_target.to_post_startup_inferior = debug_to_post_startup_inferior; diff --git a/gdb/target.h b/gdb/target.h index 7f4cd8f..e7f087b 100644 --- a/gdb/target.h +++ b/gdb/target.h @@ -378,7 +378,7 @@ struct target_ops void (*to_terminal_ours) (void); void (*to_terminal_save_ours) (void); void (*to_terminal_info) (char *, int); - void (*to_kill) (void); + void (*to_kill) (struct target_ops *); void (*to_load) (char *, int); int (*to_lookup_symbol) (char *, CORE_ADDR *); void (*to_create_inferior) (struct target_ops *, @@ -790,8 +790,7 @@ extern void print_section_info (struct target_ops *, bfd *); /* Kill the inferior process. Make it go away. */ -#define target_kill() \ - (*current_target.to_kill) () +extern void target_kill (void); /* Load an executable file into the target process. This is expected to not only bring new code into the target process, but also to diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index 33ff1a0..2ab1709 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -114,7 +114,7 @@ static int debug_registers_used; static void windows_stop (ptid_t); static int windows_thread_alive (struct target_ops *, ptid_t); -static void windows_kill_inferior (void); +static void windows_kill_inferior (struct target_ops *); static enum target_signal last_sig = TARGET_SIGNAL_0; /* Set if a signal was received from the debugged process */ @@ -1493,7 +1493,7 @@ windows_wait (struct target_ops *ops, detach = deprecated_ui_loop_hook (0); if (detach) - windows_kill_inferior (); + windows_kill_inferior (ops); } } } @@ -2014,7 +2014,7 @@ windows_xfer_memory (CORE_ADDR memaddr, gdb_byte *our, int len, } static void -windows_kill_inferior (void) +windows_kill_inferior (struct target_ops *ops) { CHECK (TerminateProcess (current_process_handle, 0)); ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFC] How to get target_ops from to_kill method? 2009-03-17 19:11 ` Joel Brobecker @ 2009-03-17 19:13 ` Pedro Alves 2009-03-17 19:31 ` Joel Brobecker 0 siblings, 1 reply; 12+ messages in thread From: Pedro Alves @ 2009-03-17 19:13 UTC (permalink / raw) To: Joel Brobecker; +Cc: gdb-patches, Tristan Gingold On Tuesday 17 March 2009 19:06:45, Joel Brobecker wrote: > New patch: > > Add a target_ops parameter to the to_kill method in struct target_ops. > > * target.h (struct target_ops): Add a "target_ops *" parameter to > method to_kill. > (target_kill): Remove macro. Add declaration. > * target.c (debug_to_kill): Delete, no longer necessary. > (target_kill): New function. > (update_current_target): Stop inheriting the to_kill method. > Do not de_fault it to no_process either. > (setup_target_debug): Do not set current_target.to_kill. > * gnu-nat.c, go32-nat.c, hpux-thread.c, inf-ptrace.c, inf-ttrace.c, > linux-nat.c, monitor.c, nto-procfs.c, procfs.c, remote-m32r-sdi.c, > remote-mips.c, remote-sim.c, remote.c, windows-nat.c: Update > accordingly. > > Tested on x86_64-linux again... > This looks great. Please go ahead and commit it. Thanks! -- Pedro Alves ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RFC] How to get target_ops from to_kill method? 2009-03-17 19:13 ` Pedro Alves @ 2009-03-17 19:31 ` Joel Brobecker 0 siblings, 0 replies; 12+ messages in thread From: Joel Brobecker @ 2009-03-17 19:31 UTC (permalink / raw) To: Pedro Alves; +Cc: gdb-patches, Tristan Gingold > > * target.h (struct target_ops): Add a "target_ops *" parameter to > > method to_kill. > > (target_kill): Remove macro. Add declaration. > > * target.c (debug_to_kill): Delete, no longer necessary. > > (target_kill): New function. > > (update_current_target): Stop inheriting the to_kill method. > > Do not de_fault it to no_process either. > > (setup_target_debug): Do not set current_target.to_kill. > > * gnu-nat.c, go32-nat.c, hpux-thread.c, inf-ptrace.c, inf-ttrace.c, > > linux-nat.c, monitor.c, nto-procfs.c, procfs.c, remote-m32r-sdi.c, > > remote-mips.c, remote-sim.c, remote.c, windows-nat.c: Update > > accordingly. > > > > Tested on x86_64-linux again... > > This looks great. Please go ahead and commit it. Thanks! Yoohoo! Thanks a lot for your help, Pedro. Much appreciated. -- Joel ^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2009-03-17 19:28 UTC | newest] Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2009-03-16 16:42 [RFC] How to get target_ops from to_kill method? Joel Brobecker 2009-03-16 17:02 ` Pedro Alves 2009-03-16 17:24 ` Joel Brobecker 2009-03-16 17:24 ` Pedro Alves 2009-03-16 19:07 ` Joel Brobecker 2009-03-16 22:22 ` Joel Brobecker 2009-03-17 0:05 ` Pedro Alves 2009-03-17 18:05 ` Joel Brobecker 2009-03-17 18:28 ` Pedro Alves 2009-03-17 19:11 ` Joel Brobecker 2009-03-17 19:13 ` Pedro Alves 2009-03-17 19:31 ` Joel Brobecker
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox