public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [RFC] mingw port: Allow use of cvs GDB on Windows 95
@ 2011-02-04 13:06 Compte ICS
  2011-02-04 13:57 ` Pierre Muller
  0 siblings, 1 reply; 8+ messages in thread
From: Compte ICS @ 2011-02-04 13:06 UTC (permalink / raw)
  To: gdb-patches

  I wanted to test current GDB on windows 95
systems, but CancelIo function is not present in Windows 95
kernel32 DLL which leads to a failure at startup of GDB.

  According to
http://www.codeguru.com/forum/showthread.php?t=80410

CancelIo calls can be emulated on windows 95.
My patch simply installs a substitute that
calls CloseHandle instead.

  I don't really care for remote serial connections 
on windows 95 machines, but the currently
compiled GDB cannot be loaded on a windows 95 machine
because CancelIo is assumed to be present.

  I tried to check the existing code
to see if I should reopen the handle, but to me it
rather seems that a call to CloseHandle is missing
for the normal case... Indeed, CancelIo
is called from ser_windows_close, and it seems
that the handle cannot be used anymore.
  Does anyone use this serial connection?
Is this handle still valid afterwards? Or should it be 
close inside ser_windows_close in all cases?

  In any case, the code should function unchanged for all
systems that have CancelIo, and allows
to use GDB on windows 95 again (even if I am not sure
that serial communication will work...).

  Comments welcome,

Pierre Muller


2011-02-04  Pierre Muller  <muller@ics.u-strasbg.fr>

	* src/gdb/ser-mingw.c (CancelIo): New macro for dynamically loaded
	DLL entry.
	(win95_cancelio): New function.
	(_initialize_ser_windows): Use LoadLirary/GetProcAddress
	to check for existence of CancelIo function in kernel32
	and substitute with win95_cancelio if not found.

Index: src/gdb/ser-mingw.c
===================================================================
RCS file: /cvs/src/src/gdb/ser-mingw.c,v
retrieving revision 1.26
diff -u -p -r1.26 ser-mingw.c
--- src/gdb/ser-mingw.c	11 Jan 2011 21:53:23 -0000	1.26
+++ src/gdb/ser-mingw.c	3 Feb 2011 10:28:53 -0000
@@ -45,6 +45,21 @@ struct ser_windows_state
   HANDLE except_event;
 };
 
+/* CancelIo is not available for Windows 95 OS,
+   so we need to use LoadLibrary/GetProcAddress to avoid
+   a startup failure.  */
+#define CancelIo dyn_CancelIo
+
+static BOOL WINAPI (*CancelIo) (HANDLE);
+
+/* Create a subtitute function for Windows 95, that 
+   simply closes the handle.  */
+static BOOL WINAPI
+win95_cancelio (HANDLE h)
+{
+  return CloseHandle (h);
+}
+
 /* Open up a real live device for serial I/O.  */
 
 static int
@@ -1208,8 +1223,21 @@ _initialize_ser_windows (void)
   WSADATA wsa_data;
   struct serial_ops *ops;
 
-  /* First register the serial port driver.  */
+  HMODULE hm = NULL;
+
+  /* First find out if kernel32 exports CancelIo function.
+     If it doesn't use win95_cancelio substitute.  */
+  hm = LoadLibrary ("kernel32.dll");
+  if (hm)
+    {
+      CancelIo = (void *) GetProcAddress (hm, "CancelIo");
+      FreeLibrary (hm);
+    }
+
+  if (!CancelIo)
+    CancelIo = (void *) win95_cancelio;
 
+  /* Now register the serial port driver.  */
   ops = XMALLOC (struct serial_ops);
   memset (ops, 0, sizeof (struct serial_ops));
   ops->name = "hardwire";



^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: [RFC] mingw port: Allow use of cvs GDB on Windows 95
  2011-02-04 13:06 [RFC] mingw port: Allow use of cvs GDB on Windows 95 Compte ICS
@ 2011-02-04 13:57 ` Pierre Muller
  2011-02-05 20:38   ` [RFA] " Pierre Muller
  0 siblings, 1 reply; 8+ messages in thread
From: Pierre Muller @ 2011-02-04 13:57 UTC (permalink / raw)
  To: gdb-patches

  After more debugging on
a more recent windows system,
I now think that the close of the 
file descriptor scb->fd in ser_windows_close
that was created using a call
to _open_osfhandle with the HANDLE associated with
the serial port also closes that handle.
  If this is correct, it probably means
that the CloseHandle call that I added to
win95_cancelio is not even necessary...

  Does anyone know if the fact
that calling close on the return value of _open_osfhandle
also close the real handle used in the call?
 The windows online documentation didn't seem really
explicit...

Pierre Muller.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [RFA] mingw port: Allow use of cvs GDB on Windows 95
  2011-02-04 13:57 ` Pierre Muller
@ 2011-02-05 20:38   ` Pierre Muller
  2011-02-21 11:06     ` Joel Brobecker
  0 siblings, 1 reply; 8+ messages in thread
From: Pierre Muller @ 2011-02-05 20:38 UTC (permalink / raw)
  To: gdb-patches

  After these checks, I submit now a simpler patch:
if CancelIo is not exported in kernel32, simply don't 
do anything instead.

  This allows use of current CVS GDB on windows 95 OS.

  Is this patch OK?

Pierre Muller


2011-02-05  Pierre Muller  <muller@ics.u-strasbg.fr>

	Allow use of mingw native on Windows 95 OS.
	* src/gdb/ser-mingw.c (CancelIo): New macro for dynamically loaded
	DLL entry.
	(ser_windows_close): Only call CancelIo if function exists.
	(_initialize_ser_windows): Use LoadLirary/GetProcAddress
	to check for existence of CancelIo function in kernel32 DLL.

Index: src/gdb/ser-mingw.c
===================================================================
RCS file: /cvs/src/src/gdb/ser-mingw.c,v
retrieving revision 1.26
diff -u -p -r1.26 ser-mingw.c
--- src/gdb/ser-mingw.c	11 Jan 2011 21:53:23 -0000	1.26
+++ src/gdb/ser-mingw.c	5 Feb 2011 17:28:07 -0000
@@ -45,6 +45,13 @@ struct ser_windows_state
   HANDLE except_event;
 };
 
+/* CancelIo is not available for Windows 95 OS,
+   so we need to use LoadLibrary/GetProcAddress to avoid
+   a startup failure.  */
+#define CancelIo dyn_CancelIo
+
+static BOOL WINAPI (*CancelIo) (HANDLE);
+
 /* Open up a real live device for serial I/O.  */
 
 static int
@@ -217,7 +224,8 @@ ser_windows_close (struct serial *scb)
   struct ser_windows_state *state;
 
   /* Stop any pending selects.  */
-  CancelIo ((HANDLE) _get_osfhandle (scb->fd));
+  if (CancelIo)
+    CancelIo ((HANDLE) _get_osfhandle (scb->fd));
   state = scb->state;
   CloseHandle (state->ov.hEvent);
   CloseHandle (state->except_event);
@@ -1207,9 +1215,19 @@ _initialize_ser_windows (void)
 {
   WSADATA wsa_data;
   struct serial_ops *ops;
+  HMODULE hm = NULL;
 
-  /* First register the serial port driver.  */
+  /* First find out if kernel32 exports CancelIo function.  */
+  hm = LoadLibrary ("kernel32.dll");
+  if (hm)
+    {
+      CancelIo = (void *) GetProcAddress (hm, "CancelIo");
+      FreeLibrary (hm);
+    }
+  else
+    CancelIo = NULL;
 
+  /* Now register the serial port driver.  */
   ops = XMALLOC (struct serial_ops);
   memset (ops, 0, sizeof (struct serial_ops));
   ops->name = "hardwire";

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFA] mingw port: Allow use of cvs GDB on Windows 95
  2011-02-05 20:38   ` [RFA] " Pierre Muller
@ 2011-02-21 11:06     ` Joel Brobecker
  2011-02-21 11:58       ` Pierre Muller
  0 siblings, 1 reply; 8+ messages in thread
From: Joel Brobecker @ 2011-02-21 11:06 UTC (permalink / raw)
  To: Pierre Muller; +Cc: gdb-patches

> 2011-02-05  Pierre Muller  <muller@ics.u-strasbg.fr>
> 
> 	Allow use of mingw native on Windows 95 OS.
> 	* src/gdb/ser-mingw.c (CancelIo): New macro for dynamically loaded
> 	DLL entry.
> 	(ser_windows_close): Only call CancelIo if function exists.
> 	(_initialize_ser_windows): Use LoadLirary/GetProcAddress
> 	to check for existence of CancelIo function in kernel32 DLL.

I was hoping that someone with more Windows knowledge would be able
to review this patch, but oh well...

This patch looks OK to me (ie, no risk that I can see for the other
platforms).  Just a couple of remarks:

> +/* CancelIo is not available for Windows 95 OS,
> +   so we need to use LoadLibrary/GetProcAddress to avoid
> +   a startup failure.  */

I find that the length of your lines are consistently really short
and inconsistent.  I think it makes it harder to read.  The above
can be reformatted to:

/* CancelIo is not available for Windows 95 OS, so we need to use
   LoadLibrary/GetProcAddress to avoid a startup failure.  */

(but I think you could also look at your editor to see if there is
anything that's contributing to this, especially the inconsistency
- are you using fixed fonts?)

> +#define CancelIo dyn_CancelIo
> +
> +static BOOL WINAPI (*CancelIo) (HANDLE);

I would *personally* keep these two together, to make it clearer
that the comment above applies to both.  Just a thought, so don't
feel obligated to follow the suggestion if you don't agree.

>    /* Stop any pending selects.  */
> -  CancelIo ((HANDLE) _get_osfhandle (scb->fd));
> +  if (CancelIo)
> +    CancelIo ((HANDLE) _get_osfhandle (scb->fd));

Can you add a comment explaining why it's OK to not call CancelIo
if it is not defined? I think you were trying to get more info
about this on this list - whatever information that you might have
gleaned...

The patch is pre-approved once the comments are addressed.

-- 
Joel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: [RFA] mingw port: Allow use of cvs GDB on Windows 95
  2011-02-21 11:06     ` Joel Brobecker
@ 2011-02-21 11:58       ` Pierre Muller
  2011-02-21 12:52         ` Joel Brobecker
  0 siblings, 1 reply; 8+ messages in thread
From: Pierre Muller @ 2011-02-21 11:58 UTC (permalink / raw)
  To: 'Joel Brobecker'; +Cc: gdb-patches

> > 2011-02-05  Pierre Muller  <muller@ics.u-strasbg.fr>
> >
> > 	Allow use of mingw native on Windows 95 OS.
> > 	* src/gdb/ser-mingw.c (CancelIo): New macro for dynamically
> loaded
> > 	DLL entry.
> > 	(ser_windows_close): Only call CancelIo if function exists.
> > 	(_initialize_ser_windows): Use LoadLirary/GetProcAddress
> > 	to check for existence of CancelIo function in kernel32 DLL.
> 
> I was hoping that someone with more Windows knowledge would be able
> to review this patch, but oh well...

  Thanks for doing this!
 
> This patch looks OK to me (ie, no risk that I can see for the other
> platforms).  Just a couple of remarks:
> 
> > +/* CancelIo is not available for Windows 95 OS,
> > +   so we need to use LoadLibrary/GetProcAddress to avoid
> > +   a startup failure.  */
> 
> I find that the length of your lines are consistently really short
> and inconsistent.  I think it makes it harder to read.  The above
> can be reformatted to:
> 
> /* CancelIo is not available for Windows 95 OS, so we need to use
>    LoadLibrary/GetProcAddress to avoid a startup failure.  */
> 
> (but I think you could also look at your editor to see if there is
> anything that's contributing to this, especially the inconsistency
> - are you using fixed fonts?)

  No, it's just that I do like to have sentences in their own lines...
I should try to adhere closer to GNU standards...

 
> > +#define CancelIo dyn_CancelIo
> > +
> > +static BOOL WINAPI (*CancelIo) (HANDLE);
> 
> I would *personally* keep these two together, to make it clearer
> that the comment above applies to both.  Just a thought, so don't
> feel obligated to follow the suggestion if you don't agree.

I removed the empty line in between.
 
> >    /* Stop any pending selects.  */
> > -  CancelIo ((HANDLE) _get_osfhandle (scb->fd));
> > +  if (CancelIo)
> > +    CancelIo ((HANDLE) _get_osfhandle (scb->fd));
> 
> Can you add a comment explaining why it's OK to not call CancelIo
> if it is not defined? I think you were trying to get more info
> about this on this list - whatever information that you might have
> gleaned...

  I added some explanation, see below.

> The patch is pre-approved once the comments are addressed.

Thanks for the approval,
for the record, here is what I just committed.


Pierre Muller
GDB pascal language maintainer

Index: ChangeLog
===================================================================
RCS file: /cvs/src/src/gdb/ChangeLog,v
retrieving revision 1.12615
diff -u -p -r1.12615 ChangeLog
--- ChangeLog	21 Feb 2011 08:38:10 -0000	1.12615
+++ ChangeLog	21 Feb 2011 11:46:15 -0000
@@ -1,3 +1,12 @@
+2011-02-21  Pierre Muller  <muller@ics.u-strasbg.fr>
+
+	Allow use of mingw native on Windows 95 OS.
+	* src/gdb/ser-mingw.c (CancelIo): New macro for dynamically loaded
+	DLL entry.
+	(ser_windows_close): Only call CancelIo if function exists.
+	(_initialize_ser_windows): Use LoadLirary/GetProcAddress
+	to check for existence of CancelIo function in kernel32 DLL.
+
 2011-02-21  Hui Zhu  <teawater@gmail.com>
 
 	* Makefile.in (HFILES_NO_SRCDIR): Add printcmd.h.
Index: ser-mingw.c
===================================================================
RCS file: /cvs/src/src/gdb/ser-mingw.c,v
retrieving revision 1.26
diff -u -p -r1.26 ser-mingw.c
--- ser-mingw.c	11 Jan 2011 21:53:23 -0000	1.26
+++ ser-mingw.c	21 Feb 2011 11:46:15 -0000
@@ -45,6 +45,11 @@ struct ser_windows_state
   HANDLE except_event;
 };
 
+/* CancelIo is not available for Windows 95 OS, so we need to use
+   LoadLibrary/GetProcAddress to avoid a startup failure.  */
+#define CancelIo dyn_CancelIo
+static BOOL WINAPI (*CancelIo) (HANDLE);
+
 /* Open up a real live device for serial I/O.  */
 
 static int
@@ -216,8 +221,12 @@ ser_windows_close (struct serial *scb)
 {
   struct ser_windows_state *state;
 
-  /* Stop any pending selects.  */
-  CancelIo ((HANDLE) _get_osfhandle (scb->fd));
+  /* Stop any pending selects. On Windows 95 OS, CancelIo function does not
+     exist. In that case, it can be replaced by a call to CloseHandle, but
+     this is not necessary here as we do close the Windows handle by
calling
+     close (scb->fd) below.  */
+  if (CancelIo)
+    CancelIo ((HANDLE) _get_osfhandle (scb->fd));
   state = scb->state;
   CloseHandle (state->ov.hEvent);
   CloseHandle (state->except_event);
@@ -1208,8 +1217,19 @@ _initialize_ser_windows (void)
   WSADATA wsa_data;
   struct serial_ops *ops;
 
-  /* First register the serial port driver.  */
+  HMODULE hm = NULL;
+
+  /* First find out if kernel32 exports CancelIo function.  */
+  hm = LoadLibrary ("kernel32.dll");
+  if (hm)
+    {
+      CancelIo = (void *) GetProcAddress (hm, "CancelIo");
+      FreeLibrary (hm);
+    }
+  else
+    CancelIo = NULL;
 
+  /* Now register the serial port driver.  */
   ops = XMALLOC (struct serial_ops);
   memset (ops, 0, sizeof (struct serial_ops));
   ops->name = "hardwire";

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFA] mingw port: Allow use of cvs GDB on Windows 95
  2011-02-21 11:58       ` Pierre Muller
@ 2011-02-21 12:52         ` Joel Brobecker
  2011-02-21 13:35           ` Pierre Muller
  0 siblings, 1 reply; 8+ messages in thread
From: Joel Brobecker @ 2011-02-21 12:52 UTC (permalink / raw)
  To: Pierre Muller; +Cc: gdb-patches

> +  /* Stop any pending selects. On Windows 95 OS, CancelIo function does not
> +     exist. In that case, it can be replaced by a call to CloseHandle, but
> +     this is not necessary here as we do close the Windows handle by
> calling
> +     close (scb->fd) below.  */

Thanks for adding the comment.  You forgot to add a second space after
the period on the second line... And while I'm nitpicking (I really
apologize), we had a discussion about line length and sort of agreed
on a "soft" limit of 70 characters, and a hard limit of 79, or 80.
Can you try a little shorter lines? (ironic, I know). I promise,
I wouldn't be nitpicking if you weren't going to touch it :).

-- 
Joel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: [RFA] mingw port: Allow use of cvs GDB on Windows 95
  2011-02-21 12:52         ` Joel Brobecker
@ 2011-02-21 13:35           ` Pierre Muller
  2011-02-21 14:59             ` Joel Brobecker
  0 siblings, 1 reply; 8+ messages in thread
From: Pierre Muller @ 2011-02-21 13:35 UTC (permalink / raw)
  To: 'Joel Brobecker'; +Cc: gdb-patches



> -----Message d'origine-----
> De : gdb-patches-owner@sourceware.org [mailto:gdb-patches-
> owner@sourceware.org] De la part de Joel Brobecker
> Envoyé : lundi 21 février 2011 12:58
> À : Pierre Muller
> Cc : gdb-patches@sourceware.org
> Objet : Re: [RFA] mingw port: Allow use of cvs GDB on Windows 95
> 
> > +  /* Stop any pending selects. On Windows 95 OS, CancelIo function
> does not
> > +     exist. In that case, it can be replaced by a call to
> CloseHandle, but
> > +     this is not necessary here as we do close the Windows handle by
> > calling
> > +     close (scb->fd) below.  */
> 
> Thanks for adding the comment.  You forgot to add a second space after
> the period on the second line... 
  And on the first line too...
> And while I'm nitpicking (I really
> apologize), we had a discussion about line length and sort of agreed
> on a "soft" limit of 70 characters, and a hard limit of 79, or 80.
> Can you try a little shorter lines? (ironic, I know). I promise,
> I wouldn't be nitpicking if you weren't going to touch it :).
  I can at least try...
see below, but if I remove "CloseHandle," from the second line,
it gets a line length of 62, which is too short, so that I presumed
that as long as the line length with it is less than 80, it is still OK?

Just tell me if this is correct.

Pierre

PS: I just saw that I also have an unwanted "src/gdb/" in my
ChangeLog entry that I will fix at the same time...


ChangeLog entry:

2011-02-21  Pierre Muller  <muller@ics.u-strasbg.fr>

	* ser-mingw.c (ser_windows_close): Reformat comment to better
conform
	to GNU coding standards.

Index: ser-mingw.c
===================================================================
RCS file: /cvs/src/src/gdb/ser-mingw.c,v
retrieving revision 1.27
diff -u -p -r1.27 ser-mingw.c
--- ser-mingw.c 21 Feb 2011 11:47:12 -0000      1.27
+++ ser-mingw.c 21 Feb 2011 12:43:59 -0000
@@ -221,10 +221,10 @@ ser_windows_close (struct serial *scb)
 {
   struct ser_windows_state *state;

-  /* Stop any pending selects. On Windows 95 OS, CancelIo function does not
-     exist. In that case, it can be replaced by a call to CloseHandle, but
-     this is not necessary here as we do close the Windows handle by
calling
-     close (scb->fd) below.  */
+  /* Stop any pending selects.  On Windows 95 OS, CancelIo function does
+     not exist.  In that case, it can be replaced by a call to CloseHandle,
+     but this is not necessary here as we do close the Windows handle
+     by calling close (scb->fd) below.  */
   if (CancelIo)
     CancelIo ((HANDLE) _get_osfhandle (scb->fd));
   state = scb->state;

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFA] mingw port: Allow use of cvs GDB on Windows 95
  2011-02-21 13:35           ` Pierre Muller
@ 2011-02-21 14:59             ` Joel Brobecker
  0 siblings, 0 replies; 8+ messages in thread
From: Joel Brobecker @ 2011-02-21 14:59 UTC (permalink / raw)
  To: Pierre Muller; +Cc: gdb-patches

> 2011-02-21  Pierre Muller  <muller@ics.u-strasbg.fr>
> 
> 	* ser-mingw.c (ser_windows_close): Reformat comment to better
> conform
> 	to GNU coding standards.

That's great. As long as we are not exceeding 80 chars without reason,
I think we're good.

Thanks again,
-- 
Joel

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2011-02-21 13:35 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-04 13:06 [RFC] mingw port: Allow use of cvs GDB on Windows 95 Compte ICS
2011-02-04 13:57 ` Pierre Muller
2011-02-05 20:38   ` [RFA] " Pierre Muller
2011-02-21 11:06     ` Joel Brobecker
2011-02-21 11:58       ` Pierre Muller
2011-02-21 12:52         ` Joel Brobecker
2011-02-21 13:35           ` Pierre Muller
2011-02-21 14:59             ` Joel Brobecker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).