Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <pedro_alves@portugalmail.pt>
To: gdb-patches@sourceware.org, Lerele <lerele@champenstudios.com>
Subject: [gdbserver/win32] (8/11) Tweak attach code to also support Windows  CE
Date: Mon, 12 Nov 2007 02:08:00 -0000	[thread overview]
Message-ID: <4737B596.30603@portugalmail.pt> (raw)

[-- Attachment #1: Type: text/plain, Size: 564 bytes --]

Hi,

Adding Windows CE attaching support, I saw that
the DebugActiveProcess call was failing with
"invalid handle".  It turns out that on Windows CE,
we can only call DebugActiveProcess if we have an open
handle to the process we're attaching to.

This patch simply reverses the order of the DebugActiveProcess,
OpenProcess calls, so that OpenProcess is done first.  As a
side effect, if OpenProcess fails, we don't need to undo the
DebugActiveProcess with DebugActiveProcessStop any more.

Tested on i686-pc-cygwin and arm-wince-mingw32ce.

Cheers,
Pedro Alves



[-- Attachment #2: win32_attach_reverse.diff --]
[-- Type: text/x-diff, Size: 2124 bytes --]

2007-11-12  Pedro Alves  <pedro_alves@portugalmail.pt>

	* win32-low.c (win32_attach): Call OpenProcess before
	DebugActiveProcess, not after.  Add last error output to error
	call.

---
 gdb/gdbserver/win32-low.c |   32 +++++++++++++++++---------------
 1 file changed, 17 insertions(+), 15 deletions(-)

Index: src/gdb/gdbserver/win32-low.c
===================================================================
--- src.orig/gdb/gdbserver/win32-low.c	2007-11-11 23:16:02.000000000 +0000
+++ src/gdb/gdbserver/win32-low.c	2007-11-11 23:16:12.000000000 +0000
@@ -754,34 +754,36 @@ win32_create_inferior (char *program, ch
 static int
 win32_attach (unsigned long pid)
 {
-  winapi_DebugActiveProcessStop DebugActiveProcessStop = NULL;
+  HANDLE h;
   winapi_DebugSetProcessKillOnExit DebugSetProcessKillOnExit = NULL;
+  DWORD err;
 #ifdef _WIN32_WCE
   HMODULE dll = GetModuleHandle (_T("COREDLL.DLL"));
 #else
   HMODULE dll = GetModuleHandle (_T("KERNEL32.DLL"));
 #endif
-  DebugActiveProcessStop = GETPROCADDRESS (dll, DebugActiveProcessStop);
   DebugSetProcessKillOnExit = GETPROCADDRESS (dll, DebugSetProcessKillOnExit);
 
-  if (DebugActiveProcess (pid))
+  h = OpenProcess (PROCESS_ALL_ACCESS, FALSE, pid);
+  if (h != NULL)
     {
-      if (DebugSetProcessKillOnExit != NULL)
- 	DebugSetProcessKillOnExit (FALSE);
+      if (DebugActiveProcess (pid))
+	{
+	  if (DebugSetProcessKillOnExit != NULL)
+	    DebugSetProcessKillOnExit (FALSE);
 
-      current_process_handle = OpenProcess (PROCESS_ALL_ACCESS, FALSE, pid);
+	  current_process_handle = h;
+	  current_process_id = pid;
+	  do_initial_child_stuff (pid);
+	  return 0;
+	}
 
-      if (current_process_handle != NULL)
- 	{
- 	  current_process_id = pid;
- 	  do_initial_child_stuff (pid);
- 	  return 0;
- 	}
-      if (DebugActiveProcessStop != NULL)
-	DebugActiveProcessStop (current_process_id);
+      CloseHandle (h);
     }
 
-  error ("Attach to process failed.");
+  err = GetLastError ();
+  error ("Attach to process failed (error %d): %s\n",
+	 (int) err, strwinerror (err));
 }
 
 /* Handle OUTPUT_DEBUG_STRING_EVENT from child process.  */



             reply	other threads:[~2007-11-12  2:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-12  2:08 Pedro Alves [this message]
2007-12-01 19:01 ` Daniel Jacobowitz
2007-12-03  3:53   ` Pedro Alves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4737B596.30603@portugalmail.pt \
    --to=pedro_alves@portugalmail.pt \
    --cc=gdb-patches@sourceware.org \
    --cc=lerele@champenstudios.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox