* [RFC] Reenable compilation with cygwin 1.5 versions
@ 2010-03-03 16:54 Pierre Muller
2010-03-03 17:14 ` Corinna Vinschen
2010-03-03 20:30 ` Christopher Faylor
0 siblings, 2 replies; 10+ messages in thread
From: Pierre Muller @ 2010-03-03 16:54 UTC (permalink / raw)
To: gdb-patches
I would like to get some comments
on the following patch.
After Corinna Vinschen patch
http://sourceware.org/ml/gdb-patches/2010-02/msg00677.html
GDB cannot be compiled with Cygwin 1.5... versions,
As 1.7 does not support Win9x and WinMe,
I would like to keep both support for
cygwin 1.5 and 1.7.
I started by using
cvs diff -r 1.203 --ifdef=__USE_OLD_CYGWIN_API_ windows-nat.c
and using the idea of Christopher idea in
http://sourceware.org/ml/gdb-patches/2010-03/msg00012.html
but I had to rework quite some time to get
to something that at least compiles for
mingw32, cygwin 1.5 and cygwin 1.7.
I did not really carefully check my patch yet,
but I would like to get some feedback now ..
I defined two macros:
__USE_OLD_CYGWIN_API_
and
__USE_NEW_CYGWIN_API_
but I realize that these kind of names are not
very nice and if someone could suggest better names,
it would be probably better ...
Concerning the remote-fileio.c patch,
I am not sure, but Corinna Vinschen seemed to
suggest that the use of PATH_MAX+1 was
an error anyway, so maybe PATH_MAX is OK
for both old and new cygwin versions.
Pierre Muller
Pascal language support maintainer for GDB
ChangeLog entry (not complete)
2010-03-03 Pierre Muller <muller@ics.u-strasbg.fr>
* remote-fileio.c:
__USE_OLD_CYGWIN_API_: new macro.
(remote_fileio_func_rename): Allow compilation with old
Cygwin API.
* windows-nat.c:
__USE_OLD_CYGWIN_API_, __USE_NEW_CYGWIN_API_: new macros.
Adapt code to allow compilation with old Cygwin API.
(get_module_name): Allow compilation with old Cygwin API.
(windows_make_so): Idem.
(get_image_name): Idem.
(windows_detach): Idem.
(windows_pid_to_exec_file): Idem.
(windows_create_inferior): Idem.
(_initialize_windows_nat): Idem.
(bad_GetModuleFileNameExW): Only define if __USE_NEW_CYGWIN_API_ is
defined.
(_initialize_loadable): Idem.
Index: remote-fileio.c
===================================================================
RCS file: /cvs/src/src/gdb/remote-fileio.c,v
retrieving revision 1.34
diff -u -p -r1.34 remote-fileio.c
--- remote-fileio.c 1 Mar 2010 09:09:24 -0000 1.34
+++ remote-fileio.c 3 Mar 2010 16:11:15 -0000
@@ -35,6 +35,11 @@
#include <sys/time.h>
#ifdef __CYGWIN__
#include <sys/cygwin.h> /* For
cygwin_conv_to_full_posix_path. */
+#include <cygwin/version.h>
+#if
CYGWIN_VERSION_DLL_MAKE_COMBINED(CYGWIN_VERSION_API_MAJOR,CYGWIN_VERSION_API
_MINOR) < 181
+#define __USE_OLD_CYGWIN_API_
+#endif
+
#endif
#include <signal.h>
@@ -1021,14 +1026,24 @@ remote_fileio_func_rename (char *buf)
errno = EISDIR;
else
{
+#ifndef __USE_OLD_CYGWIN_API_
char oldfullpath[PATH_MAX];
char newfullpath[PATH_MAX];
+#else /* __USE_OLD_CYGWIN_API_ */
+ char oldfullpath[PATH_MAX + 1];
+ char newfullpath[PATH_MAX + 1];
+#endif /* __USE_OLD_CYGWIN_API_ */
int len;
+#ifndef __USE_OLD_CYGWIN_API_
cygwin_conv_path (CCP_WIN_A_TO_POSIX, oldpath,
oldfullpath,
PATH_MAX);
cygwin_conv_path (CCP_WIN_A_TO_POSIX, newpath,
newfullpath,
PATH_MAX);
+#else /* __USE_OLD_CYGWIN_API_ */
+ cygwin_conv_to_full_posix_path (oldpath, oldfullpath);
+ cygwin_conv_to_full_posix_path (newpath, newfullpath);
+#endif /* __USE_OLD_CYGWIN_API_ */
len = strlen (oldfullpath);
if (newfullpath[len] == '/'
&& !strncmp (oldfullpath, newfullpath, len))
Index: windows-nat.c
===================================================================
RCS file: /cvs/src/src/gdb/windows-nat.c,v
retrieving revision 1.204
diff -u -p -r1.204 windows-nat.c
--- windows-nat.c 1 Mar 2010 09:09:24 -0000 1.204
+++ windows-nat.c 3 Mar 2010 16:11:15 -0000
@@ -41,6 +41,12 @@
#include <psapi.h>
#ifdef __CYGWIN__
#include <sys/cygwin.h>
+#include <cygwin/version.h>
+#if
CYGWIN_VERSION_DLL_MAKE_COMBINED(CYGWIN_VERSION_API_MAJOR,CYGWIN_VERSION_API
_MINOR) < 181
+#define __USE_OLD_CYGWIN_API_
+#else
+#define __USE_NEW_CYGWIN_API_
+#endif
#endif
#include <signal.h>
@@ -71,11 +77,11 @@
#define DebugBreakProcess dyn_DebugBreakProcess
#define DebugSetProcessKillOnExit dyn_DebugSetProcessKillOnExit
#define EnumProcessModules dyn_EnumProcessModules
-#ifndef __CYGWIN__
+#ifndef __USE_NEW_CYGWIN_API_
#define GetModuleFileNameExA dyn_GetModuleFileNameExA
-#else
+#else /* __USE_NEW_CYGWIN_API_ */
#define GetModuleFileNameExW dyn_GetModuleFileNameExW
-#endif
+#endif /* __USE_NEW_CYGWIN_API_ */
#define GetModuleInformation dyn_GetModuleInformation
#define LookupPrivilegeValueA dyn_LookupPrivilegeValueA
#define OpenProcessToken dyn_OpenProcessToken
@@ -87,13 +93,13 @@ static BOOL WINAPI (*DebugBreakProcess)
static BOOL WINAPI (*DebugSetProcessKillOnExit) (BOOL);
static BOOL WINAPI (*EnumProcessModules) (HANDLE, HMODULE *, DWORD,
LPDWORD);
-#ifndef __CYGWIN__
+#ifndef __USE_NEW_CYGWIN_API_
static DWORD WINAPI (*GetModuleFileNameExA) (HANDLE, HMODULE, LPSTR,
DWORD);
-#else
+#else /* __USE_NEW_CYGWIN_API_ */
static DWORD WINAPI (*GetModuleFileNameExW) (HANDLE, HMODULE, LPWSTR,
DWORD);
-#endif
+#endif /* __USE_NEW_CYGWIN_API_ */
static BOOL WINAPI (*GetModuleInformation) (HANDLE, HMODULE, LPMODULEINFO,
DWORD);
static BOOL WINAPI (*LookupPrivilegeValueA)(LPCSTR, LPCSTR, PLUID);
@@ -492,10 +498,17 @@ get_module_name (LPVOID base_address, ch
HMODULE *DllHandle = dh_buf; /* Set to temporary storage for initial
query */
DWORD cbNeeded;
#ifdef __CYGWIN__
+#ifdef __USE_NEW_CYGWIN_API_
wchar_t pathbuf[PATH_MAX]; /* Temporary storage prior to converting to
posix form. PATH_MAX is always enough
as long as SO_NAME_MAX_PATH_SIZE is
defined
as 512. */
+#else /* not __USE_NOT_CYGWIN_API_ */
+ char pathbuf[PATH_MAX + 1]; /* Temporary storage prior to converting to
+ posix form */
+#endif /* not __USE_NEW_CYGWIN_API_ */
+#else
+ char *pathbuf = dll_name_ret; /* Just copy directly to passed-in
arg */
#endif
cbNeeded = 0;
@@ -524,7 +537,7 @@ get_module_name (LPVOID base_address, ch
if (!base_address || mi.lpBaseOfDll == base_address)
{
/* Try to find the name of the given module */
-#ifdef __CYGWIN__
+#ifdef __USE_NEW_CYGWIN_API_
/* Cygwin prefers that the path be in /x/y/z format */
len = GetModuleFileNameExW (current_process_handle,
DllHandle[i], pathbuf, PATH_MAX);
@@ -533,12 +546,16 @@ get_module_name (LPVOID base_address, ch
if (cygwin_conv_path (CCP_WIN_W_TO_POSIX, pathbuf, dll_name_ret,
PATH_MAX) < 0)
error (_("Error converting dll name to POSIX: %d."), errno);
-#else
+#else /* not __USE_NEW_CYGWIN_API_ */
len = GetModuleFileNameExA (current_process_handle,
- DllHandle[i], dll_name_ret, MAX_PATH);
+ DllHandle[i], pathbuf, MAX_PATH);
+#endif /* not __USE_NEW_CYGWIN_API_ */
if (len == 0)
error (_("Error getting dll name: %u."), (unsigned) GetLastError
());
-#endif
+#ifdef __USE_OLD_CYGWIN_API_
+ /* Cygwin prefers that the path be in /x/y/z format */
+ cygwin_conv_to_full_posix_path (pathbuf, dll_name_ret);
+#endif /* __USE_OLD_CYGWIN_API_ */
return 1; /* success */
}
}
@@ -629,7 +646,7 @@ windows_make_so (const char *name, LPVOI
{
struct so_list *so;
char *p;
-#ifndef __CYGWIN__
+#ifndef __USE_NEW_CYGWIN_API_
char buf[MAX_PATH + 1];
char cwd[MAX_PATH + 1];
WIN32_FIND_DATA w32_fd;
@@ -651,12 +668,13 @@ windows_make_so (const char *name, LPVOI
SetCurrentDirectory (cwd);
}
}
+
if (strcasecmp (buf, "ntdll.dll") == 0)
{
GetSystemDirectory (buf, sizeof (buf));
strcat (buf, "\\ntdll.dll");
}
-#else
+#else /* __USE_NEW_CYGWIN_API_ */
wchar_t buf[PATH_MAX];
buf[0] = L'\0';
@@ -668,7 +686,7 @@ windows_make_so (const char *name, LPVOI
wcscat (buf, L"\\ntdll.dll");
}
}
-#endif
+#endif /* __USE_NEW_CYGWIN_API_ */
so = XZALLOC (struct so_list);
so->lm_info = (struct lm_info *) xmalloc (sizeof (struct lm_info));
so->lm_info->load_addr = load_addr;
@@ -676,6 +694,7 @@ windows_make_so (const char *name, LPVOI
#ifndef __CYGWIN__
strcpy (so->so_name, buf);
#else
+#ifdef __USE_NEW_CYGWIN_API_
if (buf[0])
cygwin_conv_path (CCP_WIN_W_TO_POSIX, buf, so->so_name,
SO_NAME_MAX_PATH_SIZE);
@@ -690,6 +709,9 @@ windows_make_so (const char *name, LPVOI
else
error (_("dll path too long"));
}
+#else /* __USE_OLD_CYGWIN_API_ */
+ cygwin_conv_to_posix_path (buf, so->so_name);
+#endif /* __USE_OLD_CYGWIN_API_ */
/* Record cygwin1.dll .text start/end. */
p = strchr (so->so_name, '\0') - (sizeof ("/cygwin1.dll") - 1);
if (p >= so->so_name && strcasecmp (p, "/cygwin1.dll") == 0)
@@ -728,7 +750,7 @@ windows_make_so (const char *name, LPVOI
static char *
get_image_name (HANDLE h, void *address, int unicode)
{
-#ifdef __CYGWIN__
+#ifdef __USE_NEW_CYGWIN_API_
static char buf[PATH_MAX];
#else
static char buf[(2 * MAX_PATH) + 1];
@@ -763,12 +785,12 @@ get_image_name (HANDLE h, void *address,
WCHAR *unicode_address = (WCHAR *) alloca (len * sizeof (WCHAR));
ReadProcessMemory (h, address_ptr, unicode_address, len * sizeof
(WCHAR),
&done);
-#ifdef __CYGWIN__
+#ifdef __USE_NEW_CYGWIN_API_
wcstombs (buf, unicode_address, PATH_MAX);
#else
WideCharToMultiByte (CP_ACP, 0, unicode_address, len, buf, sizeof
buf,
0, 0);
-#endif
+#endif /* __USE_NEW_CYGWIN_API_ */
}
return buf;
@@ -780,7 +802,7 @@ static int
handle_load_dll (void *dummy)
{
LOAD_DLL_DEBUG_INFO *event = ¤t_event.u.LoadDll;
-#ifdef __CYGWIN__
+#ifdef __USE_NEW_CYGWIN_API_
char dll_buf[PATH_MAX];
#else
char dll_buf[MAX_PATH + 1];
@@ -1825,9 +1847,13 @@ windows_detach (struct target_ops *ops,
static char *
windows_pid_to_exec_file (int pid)
{
-#ifdef __CYGWIN__
+#ifdef __USE_NEW_CYGWIN_API_
static char path[PATH_MAX];
+#else /* not __USE_NEW_CYGWIN_API_ */
+ static char path[MAX_PATH + 1];
+#endif /* not __USE_NEW_CYGWIN_API_ */
+#ifdef __CYGWIN__
/* Try to find exe name as symlink target of /proc/<pid>/exe */
int nchars;
char procexe[sizeof ("/proc/4294967295/exe")];
@@ -1838,8 +1864,6 @@ windows_pid_to_exec_file (int pid)
path[nchars] = '\0'; /* Got it */
return path;
}
-#else
- static char path[MAX_PATH + 1];
#endif
/* If we get here then either Cygwin is hosed, this isn't a Cygwin
version
@@ -1877,23 +1901,28 @@ static void
windows_create_inferior (struct target_ops *ops, char *exec_file,
char *allargs, char **in_env, int from_tty)
{
-#ifdef __CYGWIN__
+#ifdef __USE_NEW_CYGWIN_API_
STARTUPINFOW si;
wchar_t real_path[PATH_MAX];
wchar_t shell[PATH_MAX]; /* Path to shell */
- const char *sh;
wchar_t *toexec;
wchar_t *cygallargs;
wchar_t *args;
size_t len;
- int tty;
- int ostdin, ostdout, ostderr;
-#else
- STARTUPINFOA si;
- char real_path[PATH_MAX];
+#else /* not __USE_NEW_CYGWIN_API_ */
+ STARTUPINFO si;
+ char real_path[MAXPATHLEN];
char shell[MAX_PATH + 1]; /* Path to shell */
char *toexec;
char *args;
+#endif /* __USE_OLD_CYGWIN_API_ */
+ const char *sh;
+#ifdef __USE_NEW_CYGWIN_API_
+#endif /* __USE_NEW_CYGWIN_API_ */
+#ifdef __CYGWIN__
+ int tty;
+ int ostdin, ostdout, ostderr;
+#else
HANDLE tty;
#endif
PROCESS_INFORMATION pi;
@@ -1917,35 +1946,60 @@ windows_create_inferior (struct target_o
if (!useshell)
{
flags |= DEBUG_ONLY_THIS_PROCESS;
+#ifdef __USE_NEW_CYGWIN_API_
if (cygwin_conv_path (CCP_POSIX_TO_WIN_W, exec_file, real_path,
PATH_MAX * sizeof (wchar_t)) < 0)
error (_("Error starting executable: %d"), errno);
+#else /* not __USE_NEW_CYGWIN_API_ */
+ cygwin_conv_to_win32_path (exec_file, real_path);
+#endif /* not __USE_NEW_CYGWIN_API_ */
toexec = real_path;
+#ifdef __USE_NEW_CYGWIN_API_
len = mbstowcs (NULL, allargs, 0) + 1;
if (len == (size_t) -1)
error (_("Error starting executable: %d"), errno);
cygallargs = (wchar_t *) alloca (len * sizeof (wchar_t));
mbstowcs (cygallargs, allargs, len);
+#endif /* __USE_NEW_CYGWIN_API_ */
}
else
{
+#ifdef __USE_OLD_CYGWIN_API_
+ char *newallargs;
+#endif /* __USE_OLD_CYGWIN_API_ */
sh = getenv ("SHELL");
if (!sh)
sh = "/bin/sh";
+#ifdef __USE_NEW_CYGWIN_API_
if (cygwin_conv_path (CCP_POSIX_TO_WIN_W, sh, shell, PATH_MAX) < 0)
error (_("Error starting executable via shell: %d"), errno);
len = sizeof (L" -c 'exec '") + mbstowcs (NULL, exec_file, 0)
+ mbstowcs (NULL, allargs, 0) + 2;
cygallargs = (wchar_t *) alloca (len * sizeof (wchar_t));
swprintf (cygallargs, len, L" -c 'exec %s %s'", exec_file, allargs);
+#else /* not __USE_NEW_CYGWIN_API_ */
+ cygwin_conv_to_win32_path (sh, shell);
+ newallargs = alloca (sizeof (" -c 'exec '") + strlen (exec_file)
+ + strlen (allargs) + 2);
+ sprintf (newallargs, " -c 'exec %s %s'", exec_file, allargs);
+ allargs = newallargs;
+#endif /* not __USE_NEW_CYGWIN_API_ */
toexec = shell;
flags |= DEBUG_PROCESS;
}
+#ifdef __USE_NEW_CYGWIN_API_
args = (wchar_t *) alloca ((wcslen (toexec) + wcslen (cygallargs) + 2)
* sizeof (wchar_t));
wcscpy (args, toexec);
wcscat (args, L" ");
wcscat (args, cygallargs);
+#else /* not __USE_NEW_CYGWIN_API_ */
+ args = alloca (strlen (toexec) + strlen (allargs) + 2);
+ strcpy (args, toexec);
+ strcat (args, " ");
+ strcat (args, allargs);
+#endif /* not __USE_NEW_CYGWIN_API_ */
+
/* Prepare the environment vars for CreateProcess. */
cygwin_internal (CW_SYNC_WINENV);
@@ -1969,7 +2023,7 @@ windows_create_inferior (struct target_o
dup2 (tty, 2);
}
}
-
+#ifdef __USE_NEW_CYGWIN_API_
windows_init_thread_list ();
ret = CreateProcessW (0,
args, /* command line */
@@ -1981,25 +2035,16 @@ windows_create_inferior (struct target_o
NULL, /* current directory */
&si,
&pi);
- if (tty >= 0)
- {
- close (tty);
- dup2 (ostdin, 0);
- dup2 (ostdout, 1);
- dup2 (ostderr, 2);
- close (ostdin);
- close (ostdout);
- close (ostderr);
- }
-#else
+#endif /* __USE_NEW_CYGWIN_API_ */
+#else /* not __CYGWIN__ */
+ toexec = exec_file;
+ flags |= DEBUG_ONLY_THIS_PROCESS;
+
args = alloca (strlen (toexec) + strlen (allargs) + 2);
strcpy (args, toexec);
strcat (args, " ");
strcat (args, allargs);
- toexec = exec_file;
- flags |= DEBUG_ONLY_THIS_PROCESS;
-
if (!inferior_io_terminal)
tty = INVALID_HANDLE_VALUE;
else
@@ -2021,6 +2066,8 @@ windows_create_inferior (struct target_o
si.dwFlags |= STARTF_USESTDHANDLES;
}
}
+#endif /* not __CYGWIN__ */
+#ifndef __USE_NEW_CYGWIN_API_
windows_init_thread_list ();
ret = CreateProcessA (0,
@@ -2033,6 +2080,19 @@ windows_create_inferior (struct target_o
NULL, /* current directory */
&si,
&pi);
+#endif /* not _USE_NEW__CYGWIN__API_ */
+#ifdef __CYGWIN__
+ if (tty >= 0)
+ {
+ close (tty);
+ dup2 (ostdin, 0);
+ dup2 (ostdout, 1);
+ dup2 (ostderr, 2);
+ close (ostdin);
+ close (ostdout);
+ close (ostderr);
+ }
+#else
if (tty != INVALID_HANDLE_VALUE)
CloseHandle (tty);
#endif
@@ -2299,10 +2359,9 @@ _initialize_windows_nat (void)
init_windows_ops ();
-#ifdef __CYGWIN__
+#ifdef __USE_NEW_CYGWIN_API_
cygwin_internal (CW_SET_DOS_FILE_WARNING, 0);
#endif
-
c = add_com ("dll-symbols", class_files, dll_symbol_command,
_("Load dll library symbols from FILE."));
set_cmd_completer (c, filename_completer);
@@ -2485,7 +2544,7 @@ bad_EnumProcessModules (HANDLE w, HMODUL
{
return FALSE;
}
-#ifndef __CYGWIN__
+#ifndef __USE_NEW_CYGWIN_API_
static DWORD WINAPI
bad_GetModuleFileNameExA (HANDLE w, HMODULE x, LPSTR y, DWORD z)
{
@@ -2547,17 +2606,17 @@ _initialize_loadable (void)
GetProcAddress (hm, "EnumProcessModules");
dyn_GetModuleInformation = (void *)
GetProcAddress (hm, "GetModuleInformation");
-#ifndef __CYGWIN__
+#ifndef __USE_NEW_CYGWIN_API_
dyn_GetModuleFileNameExA = (void *)
GetProcAddress (hm, "GetModuleFileNameExA");
#else
dyn_GetModuleFileNameExW = (void *)
GetProcAddress (hm, "GetModuleFileNameExW");
-#endif
+#endif /* __USE_NEW_CYGWIN_API_ */
}
if (!dyn_EnumProcessModules || !dyn_GetModuleInformation
-#ifndef __CYGWIN__
+#ifndef __USE_NEW_CYGWIN_API_
|| !dyn_GetModuleFileNameExA
#else
|| !dyn_GetModuleFileNameExW
@@ -2568,7 +2627,7 @@ _initialize_loadable (void)
wasn't found in psapi.dll. */
dyn_EnumProcessModules = bad_EnumProcessModules;
dyn_GetModuleInformation = bad_GetModuleInformation;
-#ifndef __CYGWIN__
+#ifndef __USE_NEW_CYGWIN_API_
dyn_GetModuleFileNameExA = bad_GetModuleFileNameExA;
#else
dyn_GetModuleFileNameExW = bad_GetModuleFileNameExW;
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [RFC] Reenable compilation with cygwin 1.5 versions 2010-03-03 16:54 [RFC] Reenable compilation with cygwin 1.5 versions Pierre Muller @ 2010-03-03 17:14 ` Corinna Vinschen 2010-03-03 20:30 ` Christopher Faylor 1 sibling, 0 replies; 10+ messages in thread From: Corinna Vinschen @ 2010-03-03 17:14 UTC (permalink / raw) To: gdb-patches On Mar 3 17:54, Pierre Muller wrote: > Concerning the remote-fileio.c patch, > I am not sure, but Corinna Vinschen seemed to > suggest that the use of PATH_MAX+1 was > an error anyway, so maybe PATH_MAX is OK > for both old and new cygwin versions. The "+ 1" is not required because PATH_MAX is defined as the path length including the trailing NUL, see http://www.opengroup.org/onlinepubs/9699919799/basedefs/limits.h.html On the old Cygwin versions PATH_MAX == MAX_PATH, which is also defined including the trailing NUL, see http://msdn.microsoft.com/en-us/library/aa365247%28VS.85%29.aspx#maxpath Corinna -- Corinna Vinschen Cygwin Project Co-Leader Red Hat ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [RFC] Reenable compilation with cygwin 1.5 versions 2010-03-03 16:54 [RFC] Reenable compilation with cygwin 1.5 versions Pierre Muller 2010-03-03 17:14 ` Corinna Vinschen @ 2010-03-03 20:30 ` Christopher Faylor 2010-03-04 15:32 ` [RFC-v2] " Pierre Muller 1 sibling, 1 reply; 10+ messages in thread From: Christopher Faylor @ 2010-03-03 20:30 UTC (permalink / raw) To: gdb-patches, Pierre Muller On Wed, Mar 03, 2010 at 05:54:43PM +0100, Pierre Muller wrote: >Index: remote-fileio.c >=================================================================== >RCS file: /cvs/src/src/gdb/remote-fileio.c,v >retrieving revision 1.34 >diff -u -p -r1.34 remote-fileio.c >--- remote-fileio.c 1 Mar 2010 09:09:24 -0000 1.34 >+++ remote-fileio.c 3 Mar 2010 16:11:15 -0000 >@@ -35,6 +35,11 @@ > #include <sys/time.h> > #ifdef __CYGWIN__ > #include <sys/cygwin.h> /* For >cygwin_conv_to_full_posix_path. */ >+#include <cygwin/version.h> >+#if >CYGWIN_VERSION_DLL_MAKE_COMBINED(CYGWIN_VERSION_API_MAJOR,CYGWIN_VERSION_API >_MINOR) < 181 >+#define __USE_OLD_CYGWIN_API_ >+#endif >+ > #endif > #include <signal.h> > >@@ -1021,14 +1026,24 @@ remote_fileio_func_rename (char *buf) > errno = EISDIR; > else > { >+#ifndef __USE_OLD_CYGWIN_API_ > char oldfullpath[PATH_MAX]; > char newfullpath[PATH_MAX]; >+#else /* __USE_OLD_CYGWIN_API_ */ >+ char oldfullpath[PATH_MAX + 1]; >+ char newfullpath[PATH_MAX + 1]; >+#endif /* __USE_OLD_CYGWIN_API_ */ > int len; > >+#ifndef __USE_OLD_CYGWIN_API_ > cygwin_conv_path (CCP_WIN_A_TO_POSIX, oldpath, >oldfullpath, > PATH_MAX); > cygwin_conv_path (CCP_WIN_A_TO_POSIX, newpath, >newfullpath, > PATH_MAX); >+#else /* __USE_OLD_CYGWIN_API_ */ >+ cygwin_conv_to_full_posix_path (oldpath, oldfullpath); >+ cygwin_conv_to_full_posix_path (newpath, newfullpath); >+#endif /* __USE_OLD_CYGWIN_API_ */ > len = strlen (oldfullpath); > if (newfullpath[len] == '/' > && !strncmp (oldfullpath, newfullpath, len)) I think it would be cleaner to define a cygwin_conv_path at the top of the file based on cygwin_conv_to_full_posix_path. Then no __USE_OLD_CYGWIN_API_ would be necessary (given the understanding that the PATH_MAX changes aren't needed). >Index: windows-nat.c >=================================================================== >RCS file: /cvs/src/src/gdb/windows-nat.c,v >retrieving revision 1.204 >diff -u -p -r1.204 windows-nat.c >--- windows-nat.c 1 Mar 2010 09:09:24 -0000 1.204 >+++ windows-nat.c 3 Mar 2010 16:11:15 -0000 >@@ -41,6 +41,12 @@ > #include <psapi.h> > #ifdef __CYGWIN__ > #include <sys/cygwin.h> >+#include <cygwin/version.h> >+#if >CYGWIN_VERSION_DLL_MAKE_COMBINED(CYGWIN_VERSION_API_MAJOR,CYGWIN_VERSION_API >_MINOR) < 181 >+#define __USE_OLD_CYGWIN_API_ >+#else >+#define __USE_NEW_CYGWIN_API_ >+#endif > #endif > #include <signal.h> > >@@ -71,11 +77,11 @@ > #define DebugBreakProcess dyn_DebugBreakProcess > #define DebugSetProcessKillOnExit dyn_DebugSetProcessKillOnExit > #define EnumProcessModules dyn_EnumProcessModules >-#ifndef __CYGWIN__ >+#ifndef __USE_NEW_CYGWIN_API_ > #define GetModuleFileNameExA dyn_GetModuleFileNameExA >-#else >+#else /* __USE_NEW_CYGWIN_API_ */ > #define GetModuleFileNameExW dyn_GetModuleFileNameExW >-#endif >+#endif /* __USE_NEW_CYGWIN_API_ */ > #define GetModuleInformation dyn_GetModuleInformation > #define LookupPrivilegeValueA dyn_LookupPrivilegeValueA > #define OpenProcessToken dyn_OpenProcessToken >@@ -87,13 +93,13 @@ static BOOL WINAPI (*DebugBreakProcess) > static BOOL WINAPI (*DebugSetProcessKillOnExit) (BOOL); > static BOOL WINAPI (*EnumProcessModules) (HANDLE, HMODULE *, DWORD, > LPDWORD); >-#ifndef __CYGWIN__ >+#ifndef __USE_NEW_CYGWIN_API_ > static DWORD WINAPI (*GetModuleFileNameExA) (HANDLE, HMODULE, LPSTR, > DWORD); >-#else >+#else /* __USE_NEW_CYGWIN_API_ */ > static DWORD WINAPI (*GetModuleFileNameExW) (HANDLE, HMODULE, LPWSTR, > DWORD); >-#endif >+#endif /* __USE_NEW_CYGWIN_API_ */ > static BOOL WINAPI (*GetModuleInformation) (HANDLE, HMODULE, LPMODULEINFO, > DWORD); > static BOOL WINAPI (*LookupPrivilegeValueA)(LPCSTR, LPCSTR, PLUID); Here also, it seems like just defining and using a GetModulesFileNameEx, etc. and deciding whether to do "A" or "W" in a macro would be much cleaner. You probably still need to make decisions about using wide characters but the test should be on something like "USE_WIDE_CHARS" rather than "__USE_NEW_CYGWIN_API" since, the use of wide characters doesn't really have anything to do with the new Cygwin API. cgf ^ permalink raw reply [flat|nested] 10+ messages in thread
* [RFC-v2] Reenable compilation with cygwin 1.5 versions 2010-03-03 20:30 ` Christopher Faylor @ 2010-03-04 15:32 ` Pierre Muller 2010-03-04 16:38 ` Christopher Faylor 0 siblings, 1 reply; 10+ messages in thread From: Pierre Muller @ 2010-03-04 15:32 UTC (permalink / raw) To: gdb-patches This new version of the patch that tries to separate what is directly use of UNICODE versions of Windows API from what is Cygwin API specific code. Following Christopher's suggestion, the patch for remote-fileio.c defines a static cygwin_conv_path function, with the minimum need to the restricted usage made inside that file. __USE_OLD_CYGWIN_API_ macro could be renamed something like __PROVIDE_LOCAL_CYGWIN_CONV_PATH_... This patch can now be considered as independent of the windows-nat.c patch. Concerning windows-nat.c, I changed most of Corinna's modifications into #ifdef __USE_UNICODE_API_ This allows to use Unicode functions also for mingw32, by compiling with -D__USE_UNICODE_API_ option. A small number of code adaptation was necessary to get this to work also, but it was easier to check that the separation between Unicode function and cygwin API versions was made correctly this way. The Cygwin versions must be compiled according to the API >=181 condition. Anyhow, all systems supported by the new cygwin do have Unicode versions of their functions, so that it does not restrict their usage... Older cygwin's cannot compile using Unicode function because that would require to isolate the cygwin_conv_path issues, which seemed not interesting to me. Further suggestions? Comments? Pierre 2010-03-04 Pierre Muller <muller@ics.u-strasbg.fr> * remote-fileio.c: (__USE_OLD_CYGWIN_API_): New macro, set for older cygwin API that does not have cygwin_conv_path. (cygwin_conv_path): New static function emulating new cygwin API. * windows-nat.c: __USE_UNICODE_API_: new macro. Macro set by default for Cygwin API version >= 181. (get_module_name): Handle macro __USE_UNICODE_API_. (windows_make_so): Idem. (get_image_name): Idem. (windows_detach): Idem. (windows_pid_to_exec_file): Idem. (windows_create_inferior): Idem. (_initialize_windows_nat): Idem. (bad_GetModuleFileNameExW): Only define if __USE_UNICODE_API_ is defined. (_initialize_loadable): Idem. Index: remote-fileio.c =================================================================== RCS file: /cvs/src/src/gdb/remote-fileio.c,v retrieving revision 1.34 diff -u -p -r1.34 remote-fileio.c --- remote-fileio.c 1 Mar 2010 09:09:24 -0000 1.34 +++ remote-fileio.c 4 Mar 2010 15:06:28 -0000 @@ -35,9 +35,45 @@ #include <sys/time.h> #ifdef __CYGWIN__ #include <sys/cygwin.h> /* For cygwin_conv_to_full_posix_path. */ +#include <cygwin/version.h> +#if CYGWIN_VERSION_DLL_MAKE_COMBINED(CYGWIN_VERSION_API_MAJOR,CYGWIN_VERSION_API _MINOR) < 181 +#define __USE_OLD_CYGWIN_API_ +#endif + #endif #include <signal.h> +#ifdef __USE_OLD_CYGWIN_API_ +/* Possible 'what' values in calls to cygwin_conv_path/cygwin_create_path. */ +enum +{ + CCP_POSIX_TO_WIN_A = 0, /* from is char*, to is char* */ + CCP_POSIX_TO_WIN_W, /* from is char*, to is wchar_t* */ + CCP_WIN_A_TO_POSIX, /* from is char*, to is char* */ + CCP_WIN_W_TO_POSIX, /* from is wchar_t*, to is char* */ + + /* Or these values to the above as needed. */ + CCP_ABSOLUTE = 0, /* Request absolute path (default). */ + CCP_RELATIVE = 0x100 /* Request to keep path relative. */ +}; +typedef unsigned int cygwin_conv_path_t; + +static ssize_t +cygwin_conv_path (cygwin_conv_path_t what, const void *from, + void *to, size_t size) +{ + if (size < PATH_MAX) + internal_error (__FILE__,__LINE__, + "string buffer too short in cygwin_conv_path"); + + if (what == CCP_WIN_A_TO_POSIX) + return cygwin_conv_to_full_posix_path (from, to); + else + internal_error (__FILE__,__LINE__,"Error in cygwin_conv_path"); +} +#endif /* __USE_OLD_CYGWIN_API_ */ + + static struct { int *fd_map; int fd_map_size; Index: windows-nat.c =================================================================== RCS file: /cvs/src/src/gdb/windows-nat.c,v retrieving revision 1.204 diff -u -p -r1.204 windows-nat.c --- windows-nat.c 1 Mar 2010 09:09:24 -0000 1.204 +++ windows-nat.c 4 Mar 2010 15:06:28 -0000 @@ -41,6 +41,10 @@ #include <psapi.h> #ifdef __CYGWIN__ #include <sys/cygwin.h> +#include <cygwin/version.h> +#if CYGWIN_VERSION_DLL_MAKE_COMBINED(CYGWIN_VERSION_API_MAJOR,CYGWIN_VERSION_API _MINOR) >= 181 +#define __USE_UNICODE_API_ +#endif #endif #include <signal.h> @@ -71,11 +75,11 @@ #define DebugBreakProcess dyn_DebugBreakProcess #define DebugSetProcessKillOnExit dyn_DebugSetProcessKillOnExit #define EnumProcessModules dyn_EnumProcessModules -#ifndef __CYGWIN__ +#ifndef __USE_UNICODE_API_ #define GetModuleFileNameExA dyn_GetModuleFileNameExA -#else +#else /* __USE_UNICODE_API_ */ #define GetModuleFileNameExW dyn_GetModuleFileNameExW -#endif +#endif /* __USE_UNICODE_API_ */ #define GetModuleInformation dyn_GetModuleInformation #define LookupPrivilegeValueA dyn_LookupPrivilegeValueA #define OpenProcessToken dyn_OpenProcessToken @@ -87,13 +91,13 @@ static BOOL WINAPI (*DebugBreakProcess) static BOOL WINAPI (*DebugSetProcessKillOnExit) (BOOL); static BOOL WINAPI (*EnumProcessModules) (HANDLE, HMODULE *, DWORD, LPDWORD); -#ifndef __CYGWIN__ +#ifndef __USE_UNICODE_API_ static DWORD WINAPI (*GetModuleFileNameExA) (HANDLE, HMODULE, LPSTR, DWORD); -#else +#else /* __USE_UNICODE_API_ */ static DWORD WINAPI (*GetModuleFileNameExW) (HANDLE, HMODULE, LPWSTR, DWORD); -#endif +#endif /* __USE_UNICODE_API_ */ static BOOL WINAPI (*GetModuleInformation) (HANDLE, HMODULE, LPMODULEINFO, DWORD); static BOOL WINAPI (*LookupPrivilegeValueA)(LPCSTR, LPCSTR, PLUID); @@ -491,12 +495,19 @@ get_module_name (LPVOID base_address, ch HMODULE dh_buf[1]; HMODULE *DllHandle = dh_buf; /* Set to temporary storage for initial query */ DWORD cbNeeded; -#ifdef __CYGWIN__ +#ifdef __USE_UNICODE_API_ wchar_t pathbuf[PATH_MAX]; /* Temporary storage prior to converting to posix form. PATH_MAX is always enough as long as SO_NAME_MAX_PATH_SIZE is defined as 512. */ +#else /* not __USE_NOT_CYGWIN_API_ */ +#ifdef __CYGWIN__ + char pathbuf[PATH_MAX]; /* Temporary storage prior to converting to + posix form */ +#else + char *pathbuf = dll_name_ret; /* Just copy directly to passed-in arg */ #endif +#endif /* not __USE_UNICODE_API_ */ cbNeeded = 0; /* Find size of buffer needed to handle list of modules loaded in inferior */ @@ -524,21 +535,31 @@ get_module_name (LPVOID base_address, ch if (!base_address || mi.lpBaseOfDll == base_address) { /* Try to find the name of the given module */ -#ifdef __CYGWIN__ +#ifdef __USE_UNICODE_API_ /* Cygwin prefers that the path be in /x/y/z format */ len = GetModuleFileNameExW (current_process_handle, DllHandle[i], pathbuf, PATH_MAX); +#else /* not __USE_UNICODE_API_ */ + len = GetModuleFileNameExA (current_process_handle, + DllHandle[i], pathbuf, MAX_PATH); +#endif /* not __USE_iUNICODE_API_ */ if (len == 0) error (_("Error getting dll name: %lu."), GetLastError ()); +#ifdef __CYGWIN__ +#ifdef __USE_UNICODE_API_ if (cygwin_conv_path (CCP_WIN_W_TO_POSIX, pathbuf, dll_name_ret, PATH_MAX) < 0) error (_("Error converting dll name to POSIX: %d."), errno); -#else - len = GetModuleFileNameExA (current_process_handle, - DllHandle[i], dll_name_ret, MAX_PATH); - if (len == 0) - error (_("Error getting dll name: %u."), (unsigned) GetLastError ()); -#endif +#else /* not __USE_UNICODE_API_ */ + /* Cygwin prefers that the path be in /x/y/z format */ + cygwin_conv_to_full_posix_path (pathbuf, dll_name_ret); +#endif /* __USE_UNICODE_API_ */ +#else /* not __CYGWIN__ */ +#ifdef __USE_UNICODE_API_ + wcscpy (pathbuf, (wchar_t *)dll_name_ret); +#endif /* __USE_UNICODE_API_ */ + +#endif /* __CYGWIN__ */ return 1; /* success */ } } @@ -629,7 +650,7 @@ windows_make_so (const char *name, LPVOI { struct so_list *so; char *p; -#ifndef __CYGWIN__ +#ifndef __USE_UNICODE_API_ char buf[MAX_PATH + 1]; char cwd[MAX_PATH + 1]; WIN32_FIND_DATA w32_fd; @@ -651,13 +672,17 @@ windows_make_so (const char *name, LPVOI SetCurrentDirectory (cwd); } } + if (strcasecmp (buf, "ntdll.dll") == 0) { GetSystemDirectory (buf, sizeof (buf)); strcat (buf, "\\ntdll.dll"); } -#else +#else /* __USE_UNICODE_API_ */ wchar_t buf[PATH_MAX]; +#ifndef __CYGWIN__ + char bufa [PATH_MAX]; +#endif /* not __CYGWIN__ */ buf[0] = L'\0'; if (access (name, F_OK) != 0) @@ -668,14 +693,26 @@ windows_make_so (const char *name, LPVOI wcscat (buf, L"\\ntdll.dll"); } } -#endif +#endif /* __USE_UNICODE_API_ */ so = XZALLOC (struct so_list); so->lm_info = (struct lm_info *) xmalloc (sizeof (struct lm_info)); so->lm_info->load_addr = load_addr; strcpy (so->so_original_name, name); #ifndef __CYGWIN__ +#ifdef __USE_UNICODE_API_ + if (buf[0]) + { + WideCharToMultiByte (CP_ACP, 0, buf, wcslen (buf) + 1, bufa, sizeof bufa, + 0, 0); + strcpy (so->so_name, bufa); + } + else + strcpy (so->so_name, name); +#else /* not __USE_UNICODE_API_ */ strcpy (so->so_name, buf); +#endif /* not __USE_UNICODE_API_ */ #else +#ifdef __USE_UNICODE_API_ if (buf[0]) cygwin_conv_path (CCP_WIN_W_TO_POSIX, buf, so->so_name, SO_NAME_MAX_PATH_SIZE); @@ -690,6 +727,9 @@ windows_make_so (const char *name, LPVOI else error (_("dll path too long")); } +#else /* not __USE_UNICODE_API_ */ + cygwin_conv_to_posix_path (buf, so->so_name); +#endif /* not __USE_UNICODE_API_ */ /* Record cygwin1.dll .text start/end. */ p = strchr (so->so_name, '\0') - (sizeof ("/cygwin1.dll") - 1); if (p >= so->so_name && strcasecmp (p, "/cygwin1.dll") == 0) @@ -728,7 +768,7 @@ windows_make_so (const char *name, LPVOI static char * get_image_name (HANDLE h, void *address, int unicode) { -#ifdef __CYGWIN__ +#ifdef __USE_UNICODE_API_ static char buf[PATH_MAX]; #else static char buf[(2 * MAX_PATH) + 1]; @@ -763,12 +803,12 @@ get_image_name (HANDLE h, void *address, WCHAR *unicode_address = (WCHAR *) alloca (len * sizeof (WCHAR)); ReadProcessMemory (h, address_ptr, unicode_address, len * sizeof (WCHAR), &done); -#ifdef __CYGWIN__ +#ifdef __USE_UNICODE_API_ wcstombs (buf, unicode_address, PATH_MAX); #else WideCharToMultiByte (CP_ACP, 0, unicode_address, len, buf, sizeof buf, 0, 0); -#endif +#endif /* __USE_UNICODE_API_ */ } return buf; @@ -780,7 +820,7 @@ static int handle_load_dll (void *dummy) { LOAD_DLL_DEBUG_INFO *event = ¤t_event.u.LoadDll; -#ifdef __CYGWIN__ +#ifdef __USE_UNICODE_API_ char dll_buf[PATH_MAX]; #else char dll_buf[MAX_PATH + 1]; @@ -1825,9 +1865,13 @@ windows_detach (struct target_ops *ops, static char * windows_pid_to_exec_file (int pid) { -#ifdef __CYGWIN__ +#ifdef __USE_UNICODE_API_ static char path[PATH_MAX]; +#else /* not __USE_UNICODE_API_ */ + static char path[MAX_PATH + 1]; +#endif /* not __USE_UNICODE_API_ */ +#ifdef __CYGWIN__ /* Try to find exe name as symlink target of /proc/<pid>/exe */ int nchars; char procexe[sizeof ("/proc/4294967295/exe")]; @@ -1838,8 +1882,6 @@ windows_pid_to_exec_file (int pid) path[nchars] = '\0'; /* Got it */ return path; } -#else - static char path[MAX_PATH + 1]; #endif /* If we get here then either Cygwin is hosed, this isn't a Cygwin version @@ -1877,23 +1919,31 @@ static void windows_create_inferior (struct target_ops *ops, char *exec_file, char *allargs, char **in_env, int from_tty) { -#ifdef __CYGWIN__ +#ifdef __USE_UNICODE_API_ STARTUPINFOW si; wchar_t real_path[PATH_MAX]; wchar_t shell[PATH_MAX]; /* Path to shell */ - const char *sh; +#ifdef __CYGWIN__ wchar_t *toexec; - wchar_t *cygallargs; +#else /* not __CYGWIN__ */ + wchar_t toexec[PATH_MAX]; +#endif /* not __CYGWIN__ */ + wchar_t *uniallargs; wchar_t *args; size_t len; - int tty; - int ostdin, ostdout, ostderr; -#else - STARTUPINFOA si; - char real_path[PATH_MAX]; +#else /* not __USE_UNICODE_API_ */ + STARTUPINFO si; + char real_path[MAXPATHLEN]; char shell[MAX_PATH + 1]; /* Path to shell */ char *toexec; char *args; + char *newallargs; +#endif /* __USE_UNICODE_API_ */ + const char *sh; +#ifdef __CYGWIN__ + int tty; + int ostdin, ostdout, ostderr; +#else HANDLE tty; #endif PROCESS_INFORMATION pi; @@ -1917,35 +1967,69 @@ windows_create_inferior (struct target_o if (!useshell) { flags |= DEBUG_ONLY_THIS_PROCESS; +#ifdef __USE_UNICODE_API_ if (cygwin_conv_path (CCP_POSIX_TO_WIN_W, exec_file, real_path, PATH_MAX * sizeof (wchar_t)) < 0) error (_("Error starting executable: %d"), errno); +#else /* not __USE_UNICODE_API_ */ + cygwin_conv_to_win32_path (exec_file, real_path); +#endif /* not __USE_UNICODE_API_ */ toexec = real_path; +#ifdef __USE_UNICODE_API_ len = mbstowcs (NULL, allargs, 0) + 1; if (len == (size_t) -1) error (_("Error starting executable: %d"), errno); - cygallargs = (wchar_t *) alloca (len * sizeof (wchar_t)); - mbstowcs (cygallargs, allargs, len); + uniallargs = (wchar_t *) alloca (len * sizeof (wchar_t)); + mbstowcs (uniallargs, allargs, len); +#endif /* __USE_UNICODE_API_ */ } else { sh = getenv ("SHELL"); if (!sh) sh = "/bin/sh"; +#ifdef __USE_UNICODE_API_ if (cygwin_conv_path (CCP_POSIX_TO_WIN_W, sh, shell, PATH_MAX) < 0) error (_("Error starting executable via shell: %d"), errno); len = sizeof (L" -c 'exec '") + mbstowcs (NULL, exec_file, 0) + mbstowcs (NULL, allargs, 0) + 2; - cygallargs = (wchar_t *) alloca (len * sizeof (wchar_t)); - swprintf (cygallargs, len, L" -c 'exec %s %s'", exec_file, allargs); + uniallargs = (wchar_t *) alloca (len * sizeof (wchar_t)); + swprintf (uniallargs, len, L" -c 'exec %s %s'", exec_file, allargs); +#else /* not __USE_UNICODE_API_ */ + cygwin_conv_to_win32_path (sh, shell); + newallargs = alloca (sizeof (" -c 'exec '") + strlen (exec_file) + + strlen (allargs) + 2); + sprintf (newallargs, " -c 'exec %s %s'", exec_file, allargs); + allargs = newallargs; +#endif /* not __USE_UNICODE_API_ */ toexec = shell; flags |= DEBUG_PROCESS; } - args = (wchar_t *) alloca ((wcslen (toexec) + wcslen (cygallargs) + 2) +#else /* not __CYGWIN__ */ +#ifdef __USE_UNICODE_API_ + MultiByteToWideChar (CP_ACP, 0, exec_file, strlen (exec_file) + 1, toexec, + sizeof toexec); + uniallargs = (wchar_t *) alloca ((strlen (allargs) + 1) * sizeof (wchar_t)); + mbstowcs (uniallargs, allargs, len); +#else /* not __USE_UNICODE_API_ */ + toexec = exec_file; +#endif /* not __USE_UNICODE_API_ */ + flags |= DEBUG_ONLY_THIS_PROCESS; +#endif /* __CYGWIN__ */ +#ifdef __USE_UNICODE_API_ + args = (wchar_t *) alloca ((wcslen (toexec) + wcslen (uniallargs) + 2) * sizeof (wchar_t)); wcscpy (args, toexec); wcscat (args, L" "); - wcscat (args, cygallargs); + wcscat (args, uniallargs); +#else /* not __USE_UNICODE_API_ */ + args = alloca (strlen (toexec) + strlen (allargs) + 2); + strcpy (args, toexec); + strcat (args, " "); + strcat (args, allargs); +#endif /* not __USE_UNICODE_API_ */ + +#ifdef __CYGWIN__ /* Prepare the environment vars for CreateProcess. */ cygwin_internal (CW_SYNC_WINENV); @@ -1969,37 +2053,7 @@ windows_create_inferior (struct target_o dup2 (tty, 2); } } - - windows_init_thread_list (); - ret = CreateProcessW (0, - args, /* command line */ - NULL, /* Security */ - NULL, /* thread */ - TRUE, /* inherit handles */ - flags, /* start flags */ - NULL, /* environment */ - NULL, /* current directory */ - &si, - &pi); - if (tty >= 0) - { - close (tty); - dup2 (ostdin, 0); - dup2 (ostdout, 1); - dup2 (ostderr, 2); - close (ostdin); - close (ostdout); - close (ostderr); - } -#else - args = alloca (strlen (toexec) + strlen (allargs) + 2); - strcpy (args, toexec); - strcat (args, " "); - strcat (args, allargs); - - toexec = exec_file; - flags |= DEBUG_ONLY_THIS_PROCESS; - +#else /* not __CYGWIN__ */ if (!inferior_io_terminal) tty = INVALID_HANDLE_VALUE; else @@ -2021,8 +2075,20 @@ windows_create_inferior (struct target_o si.dwFlags |= STARTF_USESTDHANDLES; } } - +#endif /* not __CYGWIN__ */ windows_init_thread_list (); +#ifdef __USE_UNICODE_API_ + ret = CreateProcessW (0, + args, /* command line */ + NULL, /* Security */ + NULL, /* thread */ + TRUE, /* inherit handles */ + flags, /* start flags */ + NULL, /* environment */ + NULL, /* current directory */ + &si, + &pi); +#else /* not __USE_UNICODE_API_ */ ret = CreateProcessA (0, args, /* command line */ NULL, /* Security */ @@ -2033,6 +2099,19 @@ windows_create_inferior (struct target_o NULL, /* current directory */ &si, &pi); +#endif /* not _USE_UNICODE_API_ */ +#ifdef __CYGWIN__ + if (tty >= 0) + { + close (tty); + dup2 (ostdin, 0); + dup2 (ostdout, 1); + dup2 (ostderr, 2); + close (ostdin); + close (ostdout); + close (ostderr); + } +#else if (tty != INVALID_HANDLE_VALUE) CloseHandle (tty); #endif @@ -2300,9 +2379,10 @@ _initialize_windows_nat (void) init_windows_ops (); #ifdef __CYGWIN__ +#ifdef __USE_UNICODE_API_ cygwin_internal (CW_SET_DOS_FILE_WARNING, 0); #endif - +#endif c = add_com ("dll-symbols", class_files, dll_symbol_command, _("Load dll library symbols from FILE.")); set_cmd_completer (c, filename_completer); @@ -2485,7 +2565,7 @@ bad_EnumProcessModules (HANDLE w, HMODUL { return FALSE; } -#ifndef __CYGWIN__ +#ifndef __USE_UNICODE_API_ static DWORD WINAPI bad_GetModuleFileNameExA (HANDLE w, HMODULE x, LPSTR y, DWORD z) { @@ -2547,17 +2627,17 @@ _initialize_loadable (void) GetProcAddress (hm, "EnumProcessModules"); dyn_GetModuleInformation = (void *) GetProcAddress (hm, "GetModuleInformation"); -#ifndef __CYGWIN__ +#ifndef __USE_UNICODE_API_ dyn_GetModuleFileNameExA = (void *) GetProcAddress (hm, "GetModuleFileNameExA"); #else dyn_GetModuleFileNameExW = (void *) GetProcAddress (hm, "GetModuleFileNameExW"); -#endif +#endif /* __USE_UNICODE_API_ */ } if (!dyn_EnumProcessModules || !dyn_GetModuleInformation -#ifndef __CYGWIN__ +#ifndef __USE_UNICODE_API_ || !dyn_GetModuleFileNameExA #else || !dyn_GetModuleFileNameExW @@ -2568,7 +2648,7 @@ _initialize_loadable (void) wasn't found in psapi.dll. */ dyn_EnumProcessModules = bad_EnumProcessModules; dyn_GetModuleInformation = bad_GetModuleInformation; -#ifndef __CYGWIN__ +#ifndef __USE_UNICODE_API_ dyn_GetModuleFileNameExA = bad_GetModuleFileNameExA; #else dyn_GetModuleFileNameExW = bad_GetModuleFileNameExW; ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [RFC-v2] Reenable compilation with cygwin 1.5 versions 2010-03-04 15:32 ` [RFC-v2] " Pierre Muller @ 2010-03-04 16:38 ` Christopher Faylor 2010-03-06 19:27 ` Christopher Faylor 0 siblings, 1 reply; 10+ messages in thread From: Christopher Faylor @ 2010-03-04 16:38 UTC (permalink / raw) To: gdb-patches, Pierre Muller On Thu, Mar 04, 2010 at 04:32:38PM +0100, Pierre Muller wrote: >This new version of the patch that >tries to separate what is directly use of UNICODE versions >of Windows API from what is Cygwin API specific code. > > Following Christopher's suggestion, >the patch for remote-fileio.c defines a static >cygwin_conv_path function, with the minimum need to >the restricted usage made inside that file. > __USE_OLD_CYGWIN_API_ macro could be renamed something like >__PROVIDE_LOCAL_CYGWIN_CONV_PATH_... > This patch can now be considered as independent of the >windows-nat.c patch. When I said to define something I really meant use #define. I was hoping that most of the #ifdef __CYGWIN__ and __USE_OLD_CYGWIN_API stuff could be encapsulated at the top of the file. I've taken a rough stab at implementing what I meant and it does seem feasible but I don't have the time to do much right now (to say nothing of being not-extremely-interested in maintaining old Cygwin or MinGW versions). I'll send my proof-of-concept along sometime today. cgf ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [RFC-v2] Reenable compilation with cygwin 1.5 versions 2010-03-04 16:38 ` Christopher Faylor @ 2010-03-06 19:27 ` Christopher Faylor 2010-03-08 16:02 ` [RFA] " Pierre Muller 0 siblings, 1 reply; 10+ messages in thread From: Christopher Faylor @ 2010-03-06 19:27 UTC (permalink / raw) To: gdb-patches, Pierre Muller On Thu, Mar 04, 2010 at 11:38:38AM -0500, Christopher Faylor wrote: >On Thu, Mar 04, 2010 at 04:32:38PM +0100, Pierre Muller wrote: >>This new version of the patch that >>tries to separate what is directly use of UNICODE versions >>of Windows API from what is Cygwin API specific code. >> >> Following Christopher's suggestion, >>the patch for remote-fileio.c defines a static >>cygwin_conv_path function, with the minimum need to >>the restricted usage made inside that file. >> __USE_OLD_CYGWIN_API_ macro could be renamed something like >>__PROVIDE_LOCAL_CYGWIN_CONV_PATH_... >> This patch can now be considered as independent of the >>windows-nat.c patch. > >When I said to define something I really meant use #define. I was >hoping that most of the #ifdef __CYGWIN__ and __USE_OLD_CYGWIN_API stuff >could be encapsulated at the top of the file. I've taken a rough stab >at implementing what I meant and it does seem feasible but I don't have >the time to do much right now (to say nothing of being not-extremely-interested >in maintaining old Cygwin or MinGW versions). > >I'll send my proof-of-concept along sometime today. Actually, I'll check in the below as at least a first stab at getting this working. I haven't actually tried a mingw or older-cygwin build but I have kludged things to verify that windows-nat.c compiles when __CYGWIN__ is #undef'ed or when the API minor number is set to zero. This is only for windows-nat.c. I have no opinions about remote-fileio.c changes. cgf 2010-03-06 Christopher Faylor <me+cygwin@cgf.cx> * windows-nat.c: Reorganize #ifdef __CYGWIN__ considerations into one block. Define helper macros to reduce ifdefs in code. (get_module_name): Use cygwin_buf_t for buffer and __PMAX for buffer size. Call unadorned GetModuleFileNameEx rather than GetModuleFileNameEx*. (windows_make_so): Use __PMAX to denote maximum buffer size and cygwin_buf_t for buffer type. Use GetSystemDirectory{W,A} as appropriate. (get_image_name): Use __PMAX to denote maximum buffer size. (handle_load_dll): Likewise. (windows_pid_to_exec_file): Likewise. (windows_create_inferior): Add many accommodations for older Cygwin and non-Cygwin. (bad_GetModuleFileNameExW): Control inclusion of this function based on __USEWIDE conditional. (bad_GetModuleFileNameExA): Likewise. (_initialize_loadable): Just use real function names without the dyn_ part since they are defined earlier. Index: windows-nat.c =================================================================== RCS file: /cvs/src/src/gdb/windows-nat.c,v retrieving revision 1.204 diff -d -u -p -r1.204 windows-nat.c --- windows-nat.c 1 Mar 2010 09:09:24 -0000 1.204 +++ windows-nat.c 6 Mar 2010 19:22:52 -0000 @@ -41,6 +41,7 @@ #include <psapi.h> #ifdef __CYGWIN__ #include <sys/cygwin.h> +#include <cygwin/version.h> #endif #include <signal.h> @@ -71,11 +72,6 @@ #define DebugBreakProcess dyn_DebugBreakProcess #define DebugSetProcessKillOnExit dyn_DebugSetProcessKillOnExit #define EnumProcessModules dyn_EnumProcessModules -#ifndef __CYGWIN__ -#define GetModuleFileNameExA dyn_GetModuleFileNameExA -#else -#define GetModuleFileNameExW dyn_GetModuleFileNameExW -#endif #define GetModuleInformation dyn_GetModuleInformation #define LookupPrivilegeValueA dyn_LookupPrivilegeValueA #define OpenProcessToken dyn_OpenProcessToken @@ -87,13 +83,6 @@ static BOOL WINAPI (*DebugBreakProcess) static BOOL WINAPI (*DebugSetProcessKillOnExit) (BOOL); static BOOL WINAPI (*EnumProcessModules) (HANDLE, HMODULE *, DWORD, LPDWORD); -#ifndef __CYGWIN__ -static DWORD WINAPI (*GetModuleFileNameExA) (HANDLE, HMODULE, LPSTR, - DWORD); -#else -static DWORD WINAPI (*GetModuleFileNameExW) (HANDLE, HMODULE, LPWSTR, - DWORD); -#endif static BOOL WINAPI (*GetModuleInformation) (HANDLE, HMODULE, LPMODULEINFO, DWORD); static BOOL WINAPI (*LookupPrivilegeValueA)(LPCSTR, LPCSTR, PLUID); @@ -101,10 +90,39 @@ static BOOL WINAPI (*OpenProcessToken)(H static struct target_ops windows_ops; -#ifdef __CYGWIN__ +#undef STARTUPINFO +#undef CreateProcess +#undef GetModuleFileNameEx + +#ifndef __CYGWIN__ +# define __PMAX (MAX_PATH + 1) + static DWORD WINAPI (*GetModuleFileNameEx) (HANDLE, HMODULE, LPSTR, DWORD); +# define STARTUPINFO STARTUPINFOA +# define CreateProcess CreateProcessA +# define GetModuleFileNameEx_name "GetModuleFileNameExA" +# define bad_GetModuleFileNameEx bad_GetModuleFileNameExA +#else +# define __PMAX PATH_MAX /* The starting and ending address of the cygwin1.dll text segment. */ -static CORE_ADDR cygwin_load_start; -static CORE_ADDR cygwin_load_end; + static CORE_ADDR cygwin_load_start; + static CORE_ADDR cygwin_load_end; +# if CYGWIN_VERSION_DLL_MAKE_COMBINED(CYGWIN_VERSION_API_MAJOR,CYGWIN_VERSION_API_MINOR) >= 181 +# define __USEWIDE + typedef wchar_t cygwin_buf_t; + static DWORD WINAPI (*GetModuleFileNameEx) (HANDLE, HMODULE, LPWSTR, DWORD); +# define STARTUPINFO STARTUPINFOW +# define CreateProcess CreateProcessW +# define GetModuleFileNameEx_name "GetModuleFileNameExW" +# define bad_GetModuleFileNameEx bad_GetModuleFileNameExW +# else +# define cygwin_conv_path(op, from, to, size) cygwin_conv_to_full_posix_path (from, to) + typedef char cygwin_buf_t; + static DWORD WINAPI (*GetModuleFileNameEx) (HANDLE, HMODULE, LPSTR, DWORD); +# define STARTUPINFO STARTUPINFOA +# define CreateProcess CreateProcessA +# define GetModuleFileNameEx_name "GetModuleFileNameExA" +# define bad_GetModuleFileNameEx bad_GetModuleFileNameExA +# endif #endif static int have_saved_context; /* True if we've saved context from a cygwin signal. */ @@ -492,8 +510,8 @@ get_module_name (LPVOID base_address, ch HMODULE *DllHandle = dh_buf; /* Set to temporary storage for initial query */ DWORD cbNeeded; #ifdef __CYGWIN__ - wchar_t pathbuf[PATH_MAX]; /* Temporary storage prior to converting to - posix form. PATH_MAX is always enough + cygwin_buf_t pathbuf[__PMAX]; /* Temporary storage prior to converting to + posix form. __PMAX is always enough as long as SO_NAME_MAX_PATH_SIZE is defined as 512. */ #endif @@ -526,16 +544,16 @@ get_module_name (LPVOID base_address, ch /* Try to find the name of the given module */ #ifdef __CYGWIN__ /* Cygwin prefers that the path be in /x/y/z format */ - len = GetModuleFileNameExW (current_process_handle, - DllHandle[i], pathbuf, PATH_MAX); + len = GetModuleFileNameEx (current_process_handle, + DllHandle[i], pathbuf, __PMAX); if (len == 0) error (_("Error getting dll name: %lu."), GetLastError ()); if (cygwin_conv_path (CCP_WIN_W_TO_POSIX, pathbuf, dll_name_ret, - PATH_MAX) < 0) + __PMAX) < 0) error (_("Error converting dll name to POSIX: %d."), errno); #else - len = GetModuleFileNameExA (current_process_handle, - DllHandle[i], dll_name_ret, MAX_PATH); + len = GetModuleFileNameEx (current_process_handle, + DllHandle[i], dll_name_ret, __PMAX); if (len == 0) error (_("Error getting dll name: %u."), (unsigned) GetLastError ()); #endif @@ -630,8 +648,8 @@ windows_make_so (const char *name, LPVOI struct so_list *so; char *p; #ifndef __CYGWIN__ - char buf[MAX_PATH + 1]; - char cwd[MAX_PATH + 1]; + char buf[__PMAX]; + char cwd[__PMAX]; WIN32_FIND_DATA w32_fd; HANDLE h = FindFirstFile(name, &w32_fd); @@ -657,16 +675,23 @@ windows_make_so (const char *name, LPVOI strcat (buf, "\\ntdll.dll"); } #else - wchar_t buf[PATH_MAX]; + cygwin_buf_t buf[__PMAX]; - buf[0] = L'\0'; + buf[0] = 0; if (access (name, F_OK) != 0) { if (strcasecmp (name, "ntdll.dll") == 0) +#ifdef __USEWIDE { GetSystemDirectoryW (buf, sizeof (buf) / sizeof (wchar_t)); wcscat (buf, L"\\ntdll.dll"); } +#else + { + GetSystemDirectoryA (buf, sizeof (buf) / sizeof (wchar_t)); + strcat (buf, "\\ntdll.dll"); + } +#endif } #endif so = XZALLOC (struct so_list); @@ -729,9 +754,9 @@ static char * get_image_name (HANDLE h, void *address, int unicode) { #ifdef __CYGWIN__ - static char buf[PATH_MAX]; + static char buf[__PMAX]; #else - static char buf[(2 * MAX_PATH) + 1]; + static char buf[(2 * __PMAX) + 1]; #endif DWORD size = unicode ? sizeof (WCHAR) : sizeof (char); char *address_ptr; @@ -764,7 +789,7 @@ get_image_name (HANDLE h, void *address, ReadProcessMemory (h, address_ptr, unicode_address, len * sizeof (WCHAR), &done); #ifdef __CYGWIN__ - wcstombs (buf, unicode_address, PATH_MAX); + wcstombs (buf, unicode_address, __PMAX); #else WideCharToMultiByte (CP_ACP, 0, unicode_address, len, buf, sizeof buf, 0, 0); @@ -780,11 +805,7 @@ static int handle_load_dll (void *dummy) { LOAD_DLL_DEBUG_INFO *event = ¤t_event.u.LoadDll; -#ifdef __CYGWIN__ - char dll_buf[PATH_MAX]; -#else - char dll_buf[MAX_PATH + 1]; -#endif + char dll_buf[__PMAX]; char *dll_name = NULL; dll_buf[0] = dll_buf[sizeof (dll_buf) - 1] = '\0'; @@ -1428,6 +1449,7 @@ get_windows_debug_event (struct target_o (unsigned) current_event.dwProcessId, (unsigned) current_event.dwThreadId, "EXIT_THREAD_DEBUG_EVENT")); + if (current_event.dwThreadId != main_thread_id) { windows_delete_thread (ptid_build (current_event.dwProcessId, 0, @@ -1825,9 +1847,8 @@ windows_detach (struct target_ops *ops, static char * windows_pid_to_exec_file (int pid) { + static char path[__PMAX]; #ifdef __CYGWIN__ - static char path[PATH_MAX]; - /* Try to find exe name as symlink target of /proc/<pid>/exe */ int nchars; char procexe[sizeof ("/proc/4294967295/exe")]; @@ -1838,8 +1859,6 @@ windows_pid_to_exec_file (int pid) path[nchars] = '\0'; /* Got it */ return path; } -#else - static char path[MAX_PATH + 1]; #endif /* If we get here then either Cygwin is hosed, this isn't a Cygwin version @@ -1877,21 +1896,20 @@ static void windows_create_inferior (struct target_ops *ops, char *exec_file, char *allargs, char **in_env, int from_tty) { + STARTUPINFO si; #ifdef __CYGWIN__ - STARTUPINFOW si; - wchar_t real_path[PATH_MAX]; - wchar_t shell[PATH_MAX]; /* Path to shell */ + cygwin_buf_t real_path[__PMAX]; + cygwin_buf_t shell[__PMAX]; /* Path to shell */ const char *sh; - wchar_t *toexec; - wchar_t *cygallargs; - wchar_t *args; + cygwin_buf_t *toexec; + cygwin_buf_t *cygallargs; + cygwin_buf_t *args; size_t len; int tty; int ostdin, ostdout, ostderr; #else - STARTUPINFOA si; - char real_path[PATH_MAX]; - char shell[MAX_PATH + 1]; /* Path to shell */ + char real_path[__PMAX]; + char shell[__PMAX]; /* Path to shell */ char *toexec; char *args; HANDLE tty; @@ -1918,34 +1936,51 @@ windows_create_inferior (struct target_o { flags |= DEBUG_ONLY_THIS_PROCESS; if (cygwin_conv_path (CCP_POSIX_TO_WIN_W, exec_file, real_path, - PATH_MAX * sizeof (wchar_t)) < 0) + __PMAX * sizeof (cygwin_buf_t)) < 0) error (_("Error starting executable: %d"), errno); toexec = real_path; +#ifdef __USEWIDE len = mbstowcs (NULL, allargs, 0) + 1; if (len == (size_t) -1) error (_("Error starting executable: %d"), errno); cygallargs = (wchar_t *) alloca (len * sizeof (wchar_t)); mbstowcs (cygallargs, allargs, len); +#endif } else { sh = getenv ("SHELL"); if (!sh) sh = "/bin/sh"; - if (cygwin_conv_path (CCP_POSIX_TO_WIN_W, sh, shell, PATH_MAX) < 0) + if (cygwin_conv_path (CCP_POSIX_TO_WIN_W, sh, shell, __PMAX) < 0) error (_("Error starting executable via shell: %d"), errno); +#ifdef __USEWIDE len = sizeof (L" -c 'exec '") + mbstowcs (NULL, exec_file, 0) + mbstowcs (NULL, allargs, 0) + 2; cygallargs = (wchar_t *) alloca (len * sizeof (wchar_t)); swprintf (cygallargs, len, L" -c 'exec %s %s'", exec_file, allargs); +#else + cygallargs = (char *) alloca (sizeof (" -c 'exec '") + strlen (exec_file) + + strlen (allargs) + 2); + sprintf (cygallargs, " -c 'exec %s %s'", exec_file, allargs); +#endif toexec = shell; flags |= DEBUG_PROCESS; } - args = (wchar_t *) alloca ((wcslen (toexec) + wcslen (cygallargs) + 2) - * sizeof (wchar_t)); + +#ifdef __USEWIDE + args = (cygwin_buf_t *) alloca ((wcslen (toexec) + wcslen (cygallargs) + 2) + * sizeof (wchar_t)); wcscpy (args, toexec); wcscat (args, L" "); wcscat (args, cygallargs); +#else + args = (cygwin_buf_t *) alloca (strlen (toexec) + strlen (cygallargs) + 2); + strcpy (args, toexec); + strcat (args, " "); + strcat (args, cygallargs); +#endif + /* Prepare the environment vars for CreateProcess. */ cygwin_internal (CW_SYNC_WINENV); @@ -1971,16 +2006,16 @@ windows_create_inferior (struct target_o } windows_init_thread_list (); - ret = CreateProcessW (0, - args, /* command line */ - NULL, /* Security */ - NULL, /* thread */ - TRUE, /* inherit handles */ - flags, /* start flags */ - NULL, /* environment */ - NULL, /* current directory */ - &si, - &pi); + ret = CreateProcess (0, + args, /* command line */ + NULL, /* Security */ + NULL, /* thread */ + TRUE, /* inherit handles */ + flags, /* start flags */ + NULL, /* environment */ + NULL, /* current directory */ + &si, + &pi); if (tty >= 0) { close (tty); @@ -1992,12 +2027,12 @@ windows_create_inferior (struct target_o close (ostderr); } #else + toexec = exec_file; args = alloca (strlen (toexec) + strlen (allargs) + 2); strcpy (args, toexec); strcat (args, " "); strcat (args, allargs); - toexec = exec_file; flags |= DEBUG_ONLY_THIS_PROCESS; if (!inferior_io_terminal) @@ -2485,19 +2520,21 @@ bad_EnumProcessModules (HANDLE w, HMODUL { return FALSE; } -#ifndef __CYGWIN__ + +#ifdef __USEWIDE static DWORD WINAPI -bad_GetModuleFileNameExA (HANDLE w, HMODULE x, LPSTR y, DWORD z) +bad_GetModuleFileNameExW (HANDLE w, HMODULE x, LPWSTR y, DWORD z) { return 0; } #else static DWORD WINAPI -bad_GetModuleFileNameExW (HANDLE w, HMODULE x, LPWSTR y, DWORD z) +bad_GetModuleFileNameExA (HANDLE w, HMODULE x, LPSTR y, DWORD z) { return 0; } #endif + static BOOL WINAPI bad_GetModuleInformation (HANDLE w, HMODULE x, LPMODULEINFO y, DWORD z) { @@ -2520,22 +2557,22 @@ _initialize_loadable (void) hm = LoadLibrary ("kernel32.dll"); if (hm) { - dyn_DebugActiveProcessStop = (void *) + DebugActiveProcessStop = (void *) GetProcAddress (hm, "DebugActiveProcessStop"); - dyn_DebugBreakProcess = (void *) + DebugBreakProcess = (void *) GetProcAddress (hm, "DebugBreakProcess"); - dyn_DebugSetProcessKillOnExit = (void *) + DebugSetProcessKillOnExit = (void *) GetProcAddress (hm, "DebugSetProcessKillOnExit"); } /* Set variables to dummy versions of these processes if the function wasn't found in kernel32.dll. */ - if (!dyn_DebugBreakProcess) - dyn_DebugBreakProcess = bad_DebugBreakProcess; - if (!dyn_DebugActiveProcessStop || !dyn_DebugSetProcessKillOnExit) + if (!DebugBreakProcess) + DebugBreakProcess = bad_DebugBreakProcess; + if (!DebugActiveProcessStop || !DebugSetProcessKillOnExit) { - dyn_DebugActiveProcessStop = bad_DebugActiveProcessStop; - dyn_DebugSetProcessKillOnExit = bad_DebugSetProcessKillOnExit; + DebugActiveProcessStop = bad_DebugActiveProcessStop; + DebugSetProcessKillOnExit = bad_DebugSetProcessKillOnExit; } /* Load optional functions used for retrieving filename information @@ -2543,36 +2580,21 @@ _initialize_loadable (void) hm = LoadLibrary ("psapi.dll"); if (hm) { - dyn_EnumProcessModules = (void *) + EnumProcessModules = (void *) GetProcAddress (hm, "EnumProcessModules"); - dyn_GetModuleInformation = (void *) + GetModuleInformation = (void *) GetProcAddress (hm, "GetModuleInformation"); -#ifndef __CYGWIN__ - dyn_GetModuleFileNameExA = (void *) - GetProcAddress (hm, "GetModuleFileNameExA"); -#else - dyn_GetModuleFileNameExW = (void *) - GetProcAddress (hm, "GetModuleFileNameExW"); -#endif + GetModuleFileNameEx = (void *) + GetProcAddress (hm, GetModuleFileNameEx_name); } - if (!dyn_EnumProcessModules || !dyn_GetModuleInformation -#ifndef __CYGWIN__ - || !dyn_GetModuleFileNameExA -#else - || !dyn_GetModuleFileNameExW -#endif - ) + if (!EnumProcessModules || !GetModuleInformation || !GetModuleFileNameEx) { /* Set variables to dummy versions of these processes if the function wasn't found in psapi.dll. */ - dyn_EnumProcessModules = bad_EnumProcessModules; - dyn_GetModuleInformation = bad_GetModuleInformation; -#ifndef __CYGWIN__ - dyn_GetModuleFileNameExA = bad_GetModuleFileNameExA; -#else - dyn_GetModuleFileNameExW = bad_GetModuleFileNameExW; -#endif + EnumProcessModules = bad_EnumProcessModules; + GetModuleInformation = bad_GetModuleInformation; + GetModuleFileNameEx = bad_GetModuleFileNameEx; /* This will probably fail on Windows 9x/Me. Let the user know that we're missing some functionality. */ warning(_("cannot automatically find executable file or library to read symbols.\nUse \"file\" or \"dll\" command to load executable/libraries directly.")); @@ -2581,15 +2603,14 @@ _initialize_loadable (void) hm = LoadLibrary ("advapi32.dll"); if (hm) { - dyn_OpenProcessToken = (void *) - GetProcAddress (hm, "OpenProcessToken"); - dyn_LookupPrivilegeValueA = (void *) + OpenProcessToken = (void *) GetProcAddress (hm, "OpenProcessToken"); + LookupPrivilegeValueA = (void *) GetProcAddress (hm, "LookupPrivilegeValueA"); - dyn_AdjustTokenPrivileges = (void *) + AdjustTokenPrivileges = (void *) GetProcAddress (hm, "AdjustTokenPrivileges"); /* Only need to set one of these since if OpenProcessToken fails nothing else is needed. */ - if (!dyn_OpenProcessToken || !dyn_LookupPrivilegeValueA || !dyn_AdjustTokenPrivileges) - dyn_OpenProcessToken = bad_OpenProcessToken; + if (!OpenProcessToken || !LookupPrivilegeValueA || !AdjustTokenPrivileges) + OpenProcessToken = bad_OpenProcessToken; } } ^ permalink raw reply [flat|nested] 10+ messages in thread
* [RFA] Re: [RFC-v2] Reenable compilation with cygwin 1.5 versions 2010-03-06 19:27 ` Christopher Faylor @ 2010-03-08 16:02 ` Pierre Muller 2010-03-08 22:11 ` Christopher Faylor 0 siblings, 1 reply; 10+ messages in thread From: Pierre Muller @ 2010-03-08 16:02 UTC (permalink / raw) To: gdb-patches Thanks Christopher, your patch is almost enough to get GDB to compile again for 1.5 version Cygwins. There are three little problems left: canonicalize_file_name function seems new to the new Cygwin API as well as CW_SET_DOS_FILE_WARNING macro. After fixing these two, I also got one warning about cygallargs local that could be used un-initialized. The patch below fixes those three errors. Ideally, the cygwin_internal macro used should rather be of the form #ifdef __NEW_CYGWIN_API but Christopher did not seem to like such a macro... Are these patches OK? Pierre (Of course the remote-fileio.c patch also still needs to be accepted.) 2010-03-08 Pierre Muller <muller@ics.u-strasbg.fr> * windows-nat.c (canonicalize_file_name): New macro for old cygwin API support. (windows_create_inferior): Add missing cygallargs setting. (_initialize_windows_nat): Only call cygwin_internal CW_SET_DOS_FILE_WARNING for new Cygwin API. Index: windows-nat.c =================================================================== RCS file: /cvs/src/src/gdb/windows-nat.c,v retrieving revision 1.205 diff -u -p -r1.205 windows-nat.c --- windows-nat.c 6 Mar 2010 19:27:09 -0000 1.205 +++ windows-nat.c 8 Mar 2010 15:41:26 -0000 @@ -115,6 +115,7 @@ static struct target_ops windows_ops; # define GetModuleFileNameEx_name "GetModuleFileNameExW" # define bad_GetModuleFileNameEx bad_GetModuleFileNameExW # else +# define canonicalize_file_name(name) alloca(PATH_MAX); cygwin_conv_to_full_posix_path (name, rname) # define cygwin_conv_path(op, from, to, size) cygwin_conv_to_full_posix_path (from, to) typedef char cygwin_buf_t; static DWORD WINAPI (*GetModuleFileNameEx) (HANDLE, HMODULE, LPSTR, DWORD); @@ -1945,6 +1946,10 @@ windows_create_inferior (struct target_o error (_("Error starting executable: %d"), errno); cygallargs = (wchar_t *) alloca (len * sizeof (wchar_t)); mbstowcs (cygallargs, allargs, len); +#else + len = strlen (allargs) + 1; + cygallargs = (char *) alloca (len); + strcpy (cygallargs, allargs); #endif } else @@ -2335,8 +2340,10 @@ _initialize_windows_nat (void) init_windows_ops (); #ifdef __CYGWIN__ +#ifdef __USEWIDE cygwin_internal (CW_SET_DOS_FILE_WARNING, 0); #endif +#endif c = add_com ("dll-symbols", class_files, dll_symbol_command, _("Load dll library symbols from FILE.")); ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [RFA] Re: [RFC-v2] Reenable compilation with cygwin 1.5 versions 2010-03-08 16:02 ` [RFA] " Pierre Muller @ 2010-03-08 22:11 ` Christopher Faylor 2010-03-08 23:15 ` Pierre Muller 0 siblings, 1 reply; 10+ messages in thread From: Christopher Faylor @ 2010-03-08 22:11 UTC (permalink / raw) To: gdb-patches, Pierre Muller On Mon, Mar 08, 2010 at 05:02:24PM +0100, Pierre Muller wrote: >Are these patches OK? Although I didn't really succed in windows_create_inferior, the goal here is to reduce the amount of ifdef clutter in the code. So, I'd propose the below as a slightly less alternative to your version. cgf Index: windows-nat.c =================================================================== RCS file: /cvs/src/src/gdb/windows-nat.c,v retrieving revision 1.205 diff -d -u -p -r1.205 windows-nat.c --- windows-nat.c 6 Mar 2010 19:27:09 -0000 1.205 +++ windows-nat.c 8 Mar 2010 22:08:07 -0000 @@ -122,6 +122,7 @@ static struct target_ops windows_ops; # define CreateProcess CreateProcessA # define GetModuleFileNameEx_name "GetModuleFileNameExA" # define bad_GetModuleFileNameEx bad_GetModuleFileNameExA +# define CW_SET_DOS_FILE_WARNING -1 /* no-op this for older Cygwin */ # endif #endif @@ -706,7 +707,7 @@ windows_make_so (const char *name, LPVOI SO_NAME_MAX_PATH_SIZE); else { - char *rname = canonicalize_file_name (name); + char *rname = realpath (name, NULL); if (rname && strlen (rname) < SO_NAME_MAX_PATH_SIZE) { strcpy (so->so_name, rname); @@ -1945,6 +1946,8 @@ windows_create_inferior (struct target_o error (_("Error starting executable: %d"), errno); cygallargs = (wchar_t *) alloca (len * sizeof (wchar_t)); mbstowcs (cygallargs, allargs, len); +#else + cygallargs = allargs; #endif } else ^ permalink raw reply [flat|nested] 10+ messages in thread
* RE: [RFA] Re: [RFC-v2] Reenable compilation with cygwin 1.5 versions 2010-03-08 22:11 ` Christopher Faylor @ 2010-03-08 23:15 ` Pierre Muller 2010-03-09 19:12 ` Christopher Faylor 0 siblings, 1 reply; 10+ messages in thread From: Pierre Muller @ 2010-03-08 23:15 UTC (permalink / raw) To: gdb-patches > -----Message d'origine----- > De : gdb-patches-owner@sourceware.org [mailto:gdb-patches- > owner@sourceware.org] De la part de Christopher Faylor > Envoyé : Monday, March 08, 2010 11:11 PM > À : gdb-patches@sourceware.org; Pierre Muller > Objet : Re: [RFA] Re: [RFC-v2] Reenable compilation with cygwin 1.5 > versions > > On Mon, Mar 08, 2010 at 05:02:24PM +0100, Pierre Muller wrote: > >Are these patches OK? > > Although I didn't really succed in windows_create_inferior, the goal > here is to reduce the amount of ifdef clutter in the code. So, I'd > propose the below as a slightly less alternative to your version. As long as it allows use of old Cygwin API, I am happy. I checked your patch, but it still does not work completely (but this error was also in the one I submitted ...): The problem is that cygwin_conv_path function is called 4 times in windows-nat.c, two with CCP_WIN_W_TO_POSIX, for which old API function cygwin_conv_to_full_posix_path is fine, but also 2 times with CCP_POSIX_TO_WIN_W which should call cygwin_conv_to_win32_path. I adapted your version to get a running version with old Cygwin, feel free to commit it if you find it OK. Pierre PS: Concerning the remote-fileio.c code, I fear that using the earlier simpler approach of simple cygwin_conv_path macro definition discarding the first argument, might lead later to similar problems encountered here now. Index: windows-nat.c =================================================================== RCS file: /cvs/src/src/gdb/windows-nat.c,v retrieving revision 1.205 diff -u -p -r1.205 windows-nat.c --- windows-nat.c 6 Mar 2010 19:27:09 -0000 1.205 +++ windows-nat.c 8 Mar 2010 23:11:28 -0000 @@ -115,13 +115,19 @@ static struct target_ops windows_ops; # define GetModuleFileNameEx_name "GetModuleFileNameExW" # define bad_GetModuleFileNameEx bad_GetModuleFileNameExW # else -# define cygwin_conv_path(op, from, to, size) cygwin_conv_to_full_posix_path (from, to) +# define CCP_POSIX_TO_WIN_W 1 +# define CCP_WIN_W_TO_POSIX 3 +# define cygwin_conv_path(op, from, to, size) \ + (op == CCP_WIN_W_TO_POSIX) ? \ + cygwin_conv_to_full_posix_path (from, to) : \ + cygwin_conv_to_win32_path (from, to) typedef char cygwin_buf_t; static DWORD WINAPI (*GetModuleFileNameEx) (HANDLE, HMODULE, LPSTR, DWORD); # define STARTUPINFO STARTUPINFOA # define CreateProcess CreateProcessA # define GetModuleFileNameEx_name "GetModuleFileNameExA" # define bad_GetModuleFileNameEx bad_GetModuleFileNameExA +# define CW_SET_DOS_FILE_WARNING -1 /* no-op this for older Cygwin */ # endif #endif @@ -706,7 +712,7 @@ windows_make_so (const char *name, LPVOI SO_NAME_MAX_PATH_SIZE); else { - char *rname = canonicalize_file_name (name); + char *rname = realpath (name, NULL); if (rname && strlen (rname) < SO_NAME_MAX_PATH_SIZE) { strcpy (so->so_name, rname); @@ -1945,6 +1951,8 @@ windows_create_inferior (struct target_o error (_("Error starting executable: %d"), errno); cygallargs = (wchar_t *) alloca (len * sizeof (wchar_t)); mbstowcs (cygallargs, allargs, len); +#else + cygallargs = allargs; #endif } else ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [RFA] Re: [RFC-v2] Reenable compilation with cygwin 1.5 versions 2010-03-08 23:15 ` Pierre Muller @ 2010-03-09 19:12 ` Christopher Faylor 0 siblings, 0 replies; 10+ messages in thread From: Christopher Faylor @ 2010-03-09 19:12 UTC (permalink / raw) To: gdb-patches, Pierre Muller On Tue, Mar 09, 2010 at 12:15:58AM +0100, Pierre Muller wrote: > I adapted your version to get a running version with old Cygwin, >feel free to commit it if you find it OK. Thank you for fixing this thinko on my part. I've checked this in with this ChangeLog: 2010-03-09 Christopher Faylor <me+cygwin@cgf.cx> Pierre Muller <muller@ics.u-strasbg.fr> * windows-nat.c (cygwin_conv_path): Redefine to properly convert from/to posix/win32. (windows_make_so): Use non-Cygwin 1.7 specific function. (windows_create_inferior): Make sure that cygallargs points to original args in non Cygwin 1.7. case. cgf ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2010-03-09 19:12 UTC | newest] Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2010-03-03 16:54 [RFC] Reenable compilation with cygwin 1.5 versions Pierre Muller 2010-03-03 17:14 ` Corinna Vinschen 2010-03-03 20:30 ` Christopher Faylor 2010-03-04 15:32 ` [RFC-v2] " Pierre Muller 2010-03-04 16:38 ` Christopher Faylor 2010-03-06 19:27 ` Christopher Faylor 2010-03-08 16:02 ` [RFA] " Pierre Muller 2010-03-08 22:11 ` Christopher Faylor 2010-03-08 23:15 ` Pierre Muller 2010-03-09 19:12 ` Christopher Faylor
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox