This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFC] How to get target_ops from to_kill method?


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
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,
 
 
 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)
 
 
 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));
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]