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]

[gdbserver/win32] Fix attach.


Hi all,

A few months ago, Leo Zayas noticed that gdbserver/win32 attach
functionality was broken because we where returning the wrong values.

This patch fixes it, and documents target_ops::attach
return value interface.

Cheers,
Pedro Alves


2007-05-08  Pedro Alves  <pedro_alves@portugalmail.pt>

	* win32-low.c (win32-attach): Fix return value.
	* target.h (target_ops): Describe ATTACH return values.

---
 gdb/gdbserver/target.h    |    5 ++++-
 gdb/gdbserver/win32-low.c |   29 ++++++++++++-----------------
 2 files changed, 16 insertions(+), 18 deletions(-)

Index: src/gdb/gdbserver/win32-low.c
===================================================================
--- src.orig/gdb/gdbserver/win32-low.c	2007-05-07 04:15:54.000000000 +0100
+++ src/gdb/gdbserver/win32-low.c	2007-05-08 01:52:40.000000000 +0100
@@ -580,7 +580,6 @@ win32_create_inferior (char *program, ch
 static int
 win32_attach (unsigned long pid)
 {
-  int res = 0;
   winapi_DebugActiveProcessStop DebugActiveProcessStop = NULL;
   winapi_DebugSetProcessKillOnExit DebugSetProcessKillOnExit = NULL;
 #ifdef _WIN32_WCE
@@ -591,28 +590,24 @@ win32_attach (unsigned long pid)
   DebugActiveProcessStop = GETPROCADDRESS (dll, DebugActiveProcessStop);
   DebugSetProcessKillOnExit = GETPROCADDRESS (dll, DebugSetProcessKillOnExit);
 
-  res = DebugActiveProcess (pid) ? 1 : 0;
-
-  if (!res)
-    error ("Attach to process failed.");
-
-  if (DebugSetProcessKillOnExit != NULL)
-    DebugSetProcessKillOnExit (FALSE);
+  if (DebugActiveProcess (pid))
+    {
+      if (DebugSetProcessKillOnExit != NULL)
+ 	DebugSetProcessKillOnExit (FALSE);
 
-  current_process_id = pid;
-  current_process_handle = OpenProcess (PROCESS_ALL_ACCESS, FALSE, pid);
+      current_process_handle = OpenProcess (PROCESS_ALL_ACCESS, FALSE, pid);
 
-  if (current_process_handle == NULL)
-    {
-      res = 0;
+      if (current_process_handle != NULL)
+ 	{
+ 	  current_process_id = pid;
+ 	  do_initial_child_stuff (pid);
+ 	  return 0;
+ 	}
       if (DebugActiveProcessStop != NULL)
 	DebugActiveProcessStop (current_process_id);
     }
 
-  if (res)
-    do_initial_child_stuff (pid);
-
-  return res;
+  error ("Attach to process failed.");
 }
 
 /* Handle OUTPUT_DEBUG_STRING_EVENT from child process.  */
Index: src/gdb/gdbserver/target.h
===================================================================
--- src.orig/gdb/gdbserver/target.h	2007-05-08 01:52:40.000000000 +0100
+++ src/gdb/gdbserver/target.h	2007-05-08 01:56:06.000000000 +0100
@@ -58,7 +58,10 @@ struct target_ops
   /* Attach to a running process.
 
      PID is the process ID to attach to, specified by the user
-     or a higher layer.  */
+     or a higher layer.
+
+     Returns -1 if attaching is unsupported, 0 on success, and calls
+     error() otherwise.  */
 
   int (*attach) (unsigned long pid);
 


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