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] -DUNICODE support.


Hi all,

I noticed that building gdbserver -DUNICODE is broken.

One reason is that when I done the WinCE port of gdbserver, I
missed the fact that there is no GetProcAddressW on desktop
Windows - There is only an ANSI GetProcAddress, without
the A suffix.  On WinCE GetProcAddress is Wide.  Another reason is
that we are using the CreateProcess macro, which maps to
CreateProcessW when UNICODE is defined.  Since the string parameters
we hold by the time we get to the CreateProcess call are all char*,
we might as well force use CreateProcessA always.  Tested by
building gdbserver on i686-pc-cygwin, i686-pc-mingw with and
without -DUNICODE, and on arm-mingw32ce, which is always UNICODE.
And by confirming that the GetProcAddress calls return
valid pointers on MinGW with -DUNICODE.

OK?

Cheers,
Pedro Alves

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

	* win32-low.c (GETPROCADDRESS): Define.
	(winapi_DebugActiveProcessStop): Add WINAPI.  typedef as pointer.
	(winapi_DebugSetProcessKillOnExit): Likewise.
	(win32_create_inferior): Force usage of ansi CreateProcessA.
	(win32_attach): Use GETPROCADDRESS.
	(win32_detach): Likewise.

---
 gdb/gdbserver/win32-low.c |   56 ++++++++++++++++++++++++----------------------
 1 file changed, 30 insertions(+), 26 deletions(-)

Index: src/gdb/gdbserver/win32-low.c
===================================================================
--- src.orig/gdb/gdbserver/win32-low.c	2007-05-07 03:21:08.000000000 +0100
+++ src/gdb/gdbserver/win32-low.c	2007-05-07 03:53:42.000000000 +0100
@@ -55,6 +55,15 @@
 #define COUNTOF(STR) (sizeof (STR) / sizeof ((STR)[0]))
 #endif
 
+#define GETPROCADDRESS(DLL, PROC) GETPROCADDRESS_ (DLL, PROC)
+#ifdef _WIN32_WCE
+# define GETPROCADDRESS_(DLL, PROC) \
+  ((winapi_ ## PROC) GetProcAddress (DLL, TEXT (#PROC)))
+#else
+# define GETPROCADDRESS_(DLL, PROC) \
+  ((winapi_ ## PROC) GetProcAddress (DLL, #PROC))
+#endif
+
 int using_threads = 1;
 
 /* Globals.  */
@@ -70,8 +79,8 @@ static int debug_registers_used = 0;
 
 #define NUM_REGS (the_low_target.num_regs)
 
-typedef BOOL winapi_DebugActiveProcessStop (DWORD dwProcessId);
-typedef BOOL winapi_DebugSetProcessKillOnExit (BOOL KillOnExit);
+typedef BOOL WINAPI (*winapi_DebugActiveProcessStop) (DWORD dwProcessId);
+typedef BOOL WINAPI (*winapi_DebugSetProcessKillOnExit) (BOOL KillOnExit);
 
 #ifndef CONTEXT_EXTENDED_REGISTERS
 #define CONTEXT_EXTENDED_REGISTERS 0
@@ -462,7 +471,7 @@ win32_create_inferior (char *program, ch
   int argc;
   PROCESS_INFORMATION pi;
 #ifndef __MINGW32CE__
-  STARTUPINFO si = { sizeof (STARTUPINFO) };
+  STARTUPINFOA si = { sizeof (STARTUPINFOA) };
   char *winenv = NULL;
 #else
   wchar_t *wargs, *wprogram;
@@ -523,16 +532,16 @@ win32_create_inferior (char *program, ch
                         NULL,     /* start info, not supported */
                         &pi);     /* proc info */
 #else
-  ret = CreateProcess (program, /* image name */
-		       args,	/* command line */
-		       NULL,	/* security */
-		       NULL,	/* thread */
-		       TRUE,	/* inherit handles */
-		       flags,	/* start flags */
-		       winenv,  /* environment */
-		       NULL,	/* current directory */
-		       &si,     /* start info */
-		       &pi);    /* proc info */
+  ret = CreateProcessA (program,  /* image name */
+			args,     /* command line */
+			NULL,     /* security */
+			NULL,     /* thread */
+			TRUE,     /* inherit handles */
+			flags,    /* start flags */
+			winenv,   /* environment */
+			NULL,     /* current directory */
+			&si,      /* start info */
+			&pi);     /* proc info */
 #endif
 
 #ifndef USE_WIN32API
@@ -573,18 +582,15 @@ static int
 win32_attach (unsigned long pid)
 {
   int res = 0;
-  winapi_DebugActiveProcessStop *DebugActiveProcessStop = NULL;
-
-  winapi_DebugSetProcessKillOnExit *DebugSetProcessKillOnExit = NULL;
+  winapi_DebugActiveProcessStop DebugActiveProcessStop = NULL;
+  winapi_DebugSetProcessKillOnExit DebugSetProcessKillOnExit = NULL;
 #ifdef _WIN32_WCE
   HMODULE dll = GetModuleHandle (_T("COREDLL.DLL"));
 #else
   HMODULE dll = GetModuleHandle (_T("KERNEL32.DLL"));
 #endif
-  DebugActiveProcessStop = (winapi_DebugActiveProcessStop *)
-    GetProcAddress (dll, _T("DebugActiveProcessStop"));
-  DebugSetProcessKillOnExit = (winapi_DebugSetProcessKillOnExit *)
-    GetProcAddress (dll, _T("DebugSetProcessKillOnExit"));
+  DebugActiveProcessStop = GETPROCADDRESS (dll, DebugActiveProcessStop);
+  DebugSetProcessKillOnExit = GETPROCADDRESS (dll, DebugSetProcessKillOnExit);
 
   res = DebugActiveProcess (pid) ? 1 : 0;
 
@@ -686,17 +692,15 @@ win32_kill (void)
 static void
 win32_detach (void)
 {
-  winapi_DebugActiveProcessStop *DebugActiveProcessStop = NULL;
-  winapi_DebugSetProcessKillOnExit *DebugSetProcessKillOnExit = NULL;
+  winapi_DebugActiveProcessStop DebugActiveProcessStop = NULL;
+  winapi_DebugSetProcessKillOnExit DebugSetProcessKillOnExit = NULL;
 #ifdef _WIN32_WCE
   HMODULE dll = GetModuleHandle (_T("COREDLL.DLL"));
 #else
   HMODULE dll = GetModuleHandle (_T("KERNEL32.DLL"));
 #endif
-  DebugActiveProcessStop = (winapi_DebugActiveProcessStop *)
-    GetProcAddress (dll, _T("DebugActiveProcessStop"));
-  DebugSetProcessKillOnExit = (winapi_DebugSetProcessKillOnExit *)
-    GetProcAddress (dll, _T("DebugSetProcessKillOnExit"));
+  DebugActiveProcessStop = GETPROCADDRESS (dll, DebugActiveProcessStop);
+  DebugSetProcessKillOnExit = GETPROCADDRESS (dll, DebugSetProcessKillOnExit);
 
   if (DebugSetProcessKillOnExit != NULL)
     DebugSetProcessKillOnExit (FALSE);


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