public inbox for insight@sourceware.org
 help / color / mirror / Atom feed
* MinGW patches for Insight
@ 2008-02-07  8:35 Dave Murphy
  2008-02-08 17:24 ` Dave Murphy
  0 siblings, 1 reply; 12+ messages in thread
From: Dave Murphy @ 2008-02-07  8:35 UTC (permalink / raw)
  To: insight

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

Hi,

I've finally got around to tidying up the patches I use to build Insight 
under MinGW which I'd like to submit for your approval. I do have an FSF 
assignment on file for gdb, do I need another one for Insight?

should the patches to sim/ppc/table.c, gdb/Makefile.in, gdb/configure.ac 
& gdb/configure be submitted to gdb instead?

The timer for the GUI in gdbtk.c should probably be replaced with some 
windows equivalent but ifdefing the code suffices for getting Insight 
built and running.

When Insight is started under windows it starts up with a console 
window, building insight with -mwindows removes this and looks a bit 
neater. This is the purpose of the INSIGHT_LDFLAGS I've added to replace 
WIN32LDAPP on the insight link commands. I'm not sure if this is the 
right thing to do, the cygwin build sets the latter to 
"-Wl,--subsystem,console".

The patch to tcl/win/tclWin32Dll.c is basically the one supplied by 
Andrew Stubbs in this message to the list - 
http://sourceware.org/ml/insight/2005-q3/msg00054.html . I should 
probably also mention that I need to set the executable for windows 2000 
compatibility to get it to start on my Windows XP Pro box, not yet 
tested with Vista.

Here's the complete changelog for the attached patchset generated 
against CVS HEAD this morning. I'm not quite sure of the correct format 
for this, any feedback gratefully received.

2008-02-07  Dave Murphy  <davem@devkitpro.org>

*gdb/Makefile.in
New variable INSIGHT_LDFLAGS, replaces WIN32LDAPP for linking insight

*gdb/configure.ac
New variable INSIGHT_LDFLAGS set to -mwindows under mingw
set tcl configdir to win under mingw32

*gdb/configure
regenerate

*gdb/gdbtk/generic/gdbtk-cmds.c
*gdb/gdbtk/generic/gdbtk-hooks.c
guard <sys/ioctl.h> with HAVE_SYS_IOCTL_H

*gdb/gdbtk/generic/gdbtk-interp.c
include <windows.h> under mingw32

*gdb/gdbtk/generic/gdbtk.c
guard <sys/ioctl.h> with HAVE_SYS_IOCTL_H
(gdbtk_start_timer, gdbtk_stop_timer) remove timer calls under mingw
(gdbtk_init) include windows specific commands under mingw without 
cygwin path commands

*gdb/gdbtk/library/download.itb
*gdb/gdbtk/library/interface.tcl
*gdb/gdbtk/library/prefs.tcl
*gdb/gdbtk/library/session.tcl
*gdb/gdbtk/library/srctextwin.itb
check ide_cygwin_path exists before using on windows

*gdb/gdbtk/library/targetselection.itb
(TargetSelection::default_port) default to /dev/com1 under cygwin, COM1 
under mingw
(TargetSelection::port_list) use /dev/com under cygwin, COM under mingw

*sim/ppc/table.c
(table_push) correct file read under mingw as well as cygwin

*tcl/win/tclWin32Dll.c
(DllMain, TclpCheckStackSpace) backport EXCEPTION_REGISTRATION code from 
TCL mainline

I've tested the resulting Insight builds for powerpc-eabi and arm-eabi 
targets, working well so far.

Dave


[-- Attachment #2: mingw-insight.patch --]
[-- Type: text/plain, Size: 22431 bytes --]

Index: gdb/Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/Makefile.in,v
retrieving revision 1.978
diff -u -r1.978 Makefile.in
--- gdb/Makefile.in	30 Jan 2008 07:17:31 -0000	1.978
+++ gdb/Makefile.in	7 Feb 2008 04:26:10 -0000
@@ -293,6 +293,7 @@
 X11_LIBS =
 
 WIN32LDAPP = @WIN32LDAPP@
+INSIGHT_LDFLAGS = @INSIGHT_LDFLAGS@
 
 LIBGUI = @LIBGUI@
 GUI_CFLAGS_X = @GUI_CFLAGS_X@
@@ -3081,7 +3082,7 @@
 insight$(EXEEXT): gdbtk-main.o libgdb.a $(ADD_DEPS) \
 		$(CDEPS) $(TDEPLIBS)
 	rm -f insight$(EXEEXT)
-	$(CC_LD) $(INTERNAL_LDFLAGS) $(WIN32LDAPP) \
+	$(CC_LD) $(INTERNAL_LDFLAGS) $(INSIGHT_LDFLAGS) \
 		-o insight$(EXEEXT) gdbtk-main.o libgdb.a \
 		$(TDEPLIBS) $(TUI_LIBRARY) $(CLIBS) $(LOADLIBES)
 
Index: gdb/configure
===================================================================
RCS file: /cvs/src/src/gdb/configure,v
retrieving revision 1.242
diff -u -r1.242 configure
--- gdb/configure	13 Jan 2008 12:23:04 -0000	1.242
+++ gdb/configure	7 Feb 2008 04:24:38 -0000
@@ -313,7 +313,7 @@
 ac_subdirs_all="$ac_subdirs_all gdbtk"
 ac_subdirs_all="$ac_subdirs_all multi-ice"
 ac_subdirs_all="$ac_subdirs_all gdbserver"
-ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS MAINTAINER_MODE_TRUE MAINTAINER_MODE_FALSE MAINT CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT CPP EGREP build build_cpu build_vendor build_os host host_cpu host_vendor host_os target target_cpu target_vendor target_os USE_NLS LIBINTL LIBINTL_DEP INCINTL XGETTEXT GMSGFMT POSUB CATALOGS DATADIRNAME INSTOBJEXT GENCAT CATOBJEXT localedir PACKAGE subdirs TARGET_OBS AWK INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA LN_S RANLIB ac_ct_RANLIB YACC AR ac_ct_AR DLLTOOL ac_ct_DLLTOOL WINDRES ac_ct_WINDRES MIG ac_ct_MIG READLINE READLINE_DEPS READLINE_CFLAGS HAVE_LIBEXPAT LIBEXPAT LTLIBEXPAT ALLOCA CONFIG_LDFLAGS TARGET_SYSTEM_ROOT TARGET_SYSTEM_ROOT_DEFINE WARN_CFLAGS WERROR_CFLAGS SER_HARDWIRE WIN32LIBS LIBGUI GUI_CFLAGS_X WIN32LDAPP TCL_VERSION TCL_MAJOR_VERSION TCL_MINOR_VERSION TCL_CC TCL_DEFS TCL_SHLIB_CFLAGS TCL_SHLIB_LD TCL_SHLIB_LD_LIBS TCL_SHLIB_SUFFIX TCL_DL_LIBS TCL_LD_FLAGS TCL_LD_SEARCH_FLAGS TCL_CC_SEARCH_FLAGS TCL_COMPAT_OBJS TCL_RANLIB TCL_BUILD_LIB_SPEC TCL_LIB_SPEC TCL_LIB_VERSIONS_OK TK_VERSION TK_DEFS TK_BUILD_INCLUDES TK_XINCLUDES TK_XLIBSW TK_BUILD_LIB_SPEC TK_LIB_SPEC TCLHDIR TKHDIR ITCLHDIR ITKHDIR ITCL_VERSION ITCL_DEFS ITCL_BUILD_INCLUDES ITCL_BUILD_LIB_SPEC ITCL_LIB_SPEC ITK_VERSION ITK_DEFS ITK_BUILD_INCLUDES ITK_BUILD_LIB_SPEC ITK_LIB_SPEC X_CFLAGS X_LDFLAGS X_LIBS TCL_DEPS TK_DEPS ITCLLIB ITCL_DEPS ITKLIB ITK_DEPS GDBTKLIBS GDBTK_CFLAGS GDBTK_SRC_DIR SIM SIM_OBS ENABLE_CFLAGS PROFILE_CFLAGS CONFIG_OBS CONFIG_DEPS CONFIG_SRCS CONFIG_ALL CONFIG_CLEAN CONFIG_INSTALL CONFIG_UNINSTALL target_subdir frags nm_h LIBICONV LIBOBJS LTLIBOBJS'
+ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS MAINTAINER_MODE_TRUE MAINTAINER_MODE_FALSE MAINT CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT CPP EGREP build build_cpu build_vendor build_os host host_cpu host_vendor host_os target target_cpu target_vendor target_os USE_NLS LIBINTL LIBINTL_DEP INCINTL XGETTEXT GMSGFMT POSUB CATALOGS DATADIRNAME INSTOBJEXT GENCAT CATOBJEXT localedir PACKAGE subdirs TARGET_OBS AWK INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA LN_S RANLIB ac_ct_RANLIB YACC AR ac_ct_AR DLLTOOL ac_ct_DLLTOOL WINDRES ac_ct_WINDRES MIG ac_ct_MIG READLINE READLINE_DEPS READLINE_CFLAGS HAVE_LIBEXPAT LIBEXPAT LTLIBEXPAT ALLOCA CONFIG_LDFLAGS TARGET_SYSTEM_ROOT TARGET_SYSTEM_ROOT_DEFINE WARN_CFLAGS WERROR_CFLAGS SER_HARDWIRE WIN32LIBS INSIGHT_LDFLAGS LIBGUI GUI_CFLAGS_X WIN32LDAPP TCL_VERSION TCL_MAJOR_VERSION TCL_MINOR_VERSION TCL_CC TCL_DEFS TCL_SHLIB_CFLAGS TCL_SHLIB_LD TCL_SHLIB_LD_LIBS TCL_SHLIB_SUFFIX TCL_DL_LIBS TCL_LD_FLAGS TCL_LD_SEARCH_FLAGS TCL_CC_SEARCH_FLAGS TCL_COMPAT_OBJS TCL_RANLIB TCL_BUILD_LIB_SPEC TCL_LIB_SPEC TCL_LIB_VERSIONS_OK TK_VERSION TK_DEFS TK_BUILD_INCLUDES TK_XINCLUDES TK_XLIBSW TK_BUILD_LIB_SPEC TK_LIB_SPEC TCLHDIR TKHDIR ITCLHDIR ITKHDIR ITCL_VERSION ITCL_DEFS ITCL_BUILD_INCLUDES ITCL_BUILD_LIB_SPEC ITCL_LIB_SPEC ITK_VERSION ITK_DEFS ITK_BUILD_INCLUDES ITK_BUILD_LIB_SPEC ITK_LIB_SPEC X_CFLAGS X_LDFLAGS X_LIBS TCL_DEPS TK_DEPS ITCLLIB ITCL_DEPS ITKLIB ITK_DEPS GDBTKLIBS GDBTK_CFLAGS GDBTK_SRC_DIR SIM SIM_OBS ENABLE_CFLAGS PROFILE_CFLAGS CONFIG_OBS CONFIG_DEPS CONFIG_SRCS CONFIG_ALL CONFIG_CLEAN CONFIG_INSTALL CONFIG_UNINSTALL target_subdir frags nm_h LIBICONV LIBOBJS LTLIBOBJS'
 ac_subst_files='host_makefile_frag'
 
 # Initialize some variables set by options.
@@ -7085,9 +7085,9 @@
     LIBS="$ac_save_LIBS"
 
 fi
-echo "$as_me:$LINENO: result: $ac_cv_libexpat" >&5
-echo "${ECHO_T}$ac_cv_libexpat" >&6
-  if test "$ac_cv_libexpat" = yes; then
+echo "$as_me:$LINENO: result: $ac_cv_libxpat" >&5
+echo "${ECHO_T}$ac_cv_libxpat" >&6
+  if test "$ac_cv_libet" = yes; then
     HAVE_LIBEXPAT=yes
 
 cat >>confdefs.h <<\_ACEOF
@@ -22986,10 +22986,12 @@
 _ACEOF
 
     WIN32LIBS="$WIN32LIBS -lws2_32"
+    INSIGHT_LDFLAGS="-mwindows"
     ;;
 esac
 
 
+
 # Add ELF support to GDB, but only if BFD includes ELF support.
 OLD_CFLAGS=$CFLAGS
 OLD_LDFLAGS=$LDFLAGS
@@ -23080,7 +23082,7 @@
 
 
 case "${host}" in
-*-*-cygwin*)
+*-*-cygwin* | *mingw32* )
     configdir="win"
     ;;
 *)
@@ -25532,6 +25534,7 @@
 s,@WERROR_CFLAGS@,$WERROR_CFLAGS,;t t
 s,@SER_HARDWIRE@,$SER_HARDWIRE,;t t
 s,@WIN32LIBS@,$WIN32LIBS,;t t
+s,@INSIGHT_LDFLAGS@,$INSIGHT_LDFLAGS,;t t
 s,@LIBGUI@,$LIBGUI,;t t
 s,@GUI_CFLAGS_X@,$GUI_CFLAGS_X,;t t
 s,@WIN32LDAPP@,$WIN32LDAPP,;t t
Index: gdb/configure.ac
===================================================================
RCS file: /cvs/src/src/gdb/configure.ac,v
retrieving revision 1.64
diff -u -r1.64 configure.ac
--- gdb/configure.ac	13 Jan 2008 12:23:05 -0000	1.64
+++ gdb/configure.ac	7 Feb 2008 04:24:26 -0000
@@ -1403,9 +1403,11 @@
 	       building for MinGW, but the POSIX API when building 
 	       for Cygwin.])
     WIN32LIBS="$WIN32LIBS -lws2_32"
+    INSIGHT_LDFLAGS="-mwindows"
     ;;
 esac	    
 AC_SUBST(WIN32LIBS)
+AC_SUBST(INSIGHT_LDFLAGS)
 
 # Add ELF support to GDB, but only if BFD includes ELF support.
 OLD_CFLAGS=$CFLAGS
@@ -1445,7 +1447,7 @@
 AC_SUBST(WIN32LDAPP)
 
 case "${host}" in
-*-*-cygwin*)
+*-*-cygwin* | *mingw32* )
     configdir="win"
     ;;
 *)
Index: gdb/gdbtk/generic/gdbtk-cmds.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/generic/gdbtk-cmds.c,v
retrieving revision 1.97
diff -u -r1.97 gdbtk-cmds.c
--- gdb/gdbtk/generic/gdbtk-cmds.c	21 Jun 2007 15:18:51 -0000	1.97
+++ gdb/gdbtk/generic/gdbtk-cmds.c	7 Feb 2008 03:43:06 -0000
@@ -57,7 +57,9 @@
 
 #include <signal.h>
 #include <fcntl.h>
+#ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
+#endif
 #include <sys/time.h>
 #include <sys/stat.h>
 
Index: gdb/gdbtk/generic/gdbtk-hooks.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/generic/gdbtk-hooks.c,v
retrieving revision 1.41
diff -u -r1.41 gdbtk-hooks.c
--- gdb/gdbtk/generic/gdbtk-hooks.c	23 Dec 2005 18:23:16 -0000	1.41
+++ gdb/gdbtk/generic/gdbtk-hooks.c	7 Feb 2008 03:43:19 -0000
@@ -51,7 +51,9 @@
 
 #include <signal.h>
 #include <fcntl.h>
+#ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
+#endif
 #include <sys/time.h>
 
 #include "gdb_string.h"
Index: gdb/gdbtk/generic/gdbtk-interp.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/generic/gdbtk-interp.c,v
retrieving revision 1.8
diff -u -r1.8 gdbtk-interp.c
--- gdb/gdbtk/generic/gdbtk-interp.c	23 Dec 2005 18:23:16 -0000	1.8
+++ gdb/gdbtk/generic/gdbtk-interp.c	6 Feb 2008 03:50:50 -0000
@@ -34,6 +34,12 @@
 #include "tk.h"
 #include "gdbtk.h"
 
+#ifdef __MINGW32__
+	#define WIN32_LEAN_AND_MEAN
+	#include <windows.h>
+#endif
+
+
 static void gdbtk_command_loop (void);
 static void hack_disable_interpreter_exec (char *, int);
 
Index: gdb/gdbtk/generic/gdbtk.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/generic/gdbtk.c,v
retrieving revision 1.45
diff -u -r1.45 gdbtk.c
--- gdb/gdbtk/generic/gdbtk.c	1 Dec 2006 02:09:24 -0000	1.45
+++ gdb/gdbtk/generic/gdbtk.c	7 Feb 2008 06:23:48 -0000
@@ -49,7 +49,9 @@
 
 #include <fcntl.h>
 #include <sys/stat.h>
+#ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
+#endif
 #include <sys/time.h>
 #include <signal.h>
 
@@ -63,6 +65,7 @@
 
 extern void _initialize_gdbtk (void);
 
+#ifndef __MINGW32__
 /* For unix natives, we use a timer to periodically keep the gui alive.
    See comments before x_event. */
 static sigset_t nullsigmask;
@@ -74,6 +77,7 @@
 {
   x_event (signo);
 }
+#endif
 
 /*
  * This variable controls the interaction with an external editor.
@@ -262,6 +266,7 @@
     {
       /* first time called, set up all the structs */
       first = 0;
+#ifndef __MINGW32__
       sigemptyset (&nullsigmask);
 
       act1.sa_handler = x_event_wrapper;
@@ -281,14 +286,17 @@
       it_off.it_interval.tv_usec = 0;
       it_off.it_value.tv_sec = 0;
       it_off.it_value.tv_usec = 0;
+#endif
     }
 
   if (target_should_use_timer (&current_target))
     {
       if (!gdbtk_timer_going)
 	{
+#ifndef __MINGW32__
 	  sigaction (SIGALRM, &act1, NULL);
 	  setitimer (ITIMER_REAL, &it_on, NULL);
+#endif
 	  gdbtk_timer_going = 1;
 	}
     }
@@ -302,8 +310,10 @@
   if (gdbtk_timer_going)
     {
       gdbtk_timer_going = 0;
+#ifndef __MINGW32__
       setitimer (ITIMER_REAL, &it_off, NULL);
       sigaction (SIGALRM, &act2, NULL);
+#endif
     }
   return;
 }
@@ -510,7 +520,7 @@
    * These are the commands to do some Windows Specific stuff...
    */
 
-#ifdef __CYGWIN32__
+#ifdef __WIN32__
   if (ide_create_messagebox_command (gdbtk_interp) != TCL_OK)
     error ("messagebox command initialization failed");
   /* On Windows, create a sizebox widget command */
@@ -522,6 +532,8 @@
     error ("windows print code initialization failed");
   if (ide_create_win_grab_command (gdbtk_interp) != TCL_OK)
     error ("grab support command initialization failed");
+#endif
+#ifdef __CYGWIN32__
   /* Path conversion functions.  */
   if (ide_create_cygwin_path_command (gdbtk_interp) != TCL_OK)
     error ("cygwin path command initialization failed");
Index: gdb/gdbtk/library/download.itb
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/library/download.itb,v
retrieving revision 1.11
diff -u -r1.11 download.itb
--- gdb/gdbtk/library/download.itb	23 Dec 2005 18:26:50 -0000	1.11
+++ gdb/gdbtk/library/download.itb	6 Feb 2008 04:30:59 -0000
@@ -207,7 +207,7 @@
     }
   }
 
-  if {[string compare $tcl_platform(platform) "windows"] == 0} {
+  if {[string compare $tcl_platform(platform) "windows"] == 0 && [llength [info commands ide_cygwin_path]]} {
     set f [ide_cygwin_path to_win32 $gdb_exe_name]
   } else {
     set f $gdb_exe_name
Index: gdb/gdbtk/library/interface.tcl
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/library/interface.tcl,v
retrieving revision 1.57
diff -u -r1.57 interface.tcl
--- gdb/gdbtk/library/interface.tcl	23 Dec 2005 18:26:50 -0000	1.57
+++ gdb/gdbtk/library/interface.tcl	6 Feb 2008 04:32:56 -0000
@@ -962,7 +962,7 @@
   }
   # Add the base dir for this file to the source search path.
   set root [file dirname $file]
-  if {$tcl_platform(platform) == "windows"} {
+  if {$tcl_platform(platform) == "windows" && [llength [info commands ide_cygwin_path]]} {
     set root [ide_cygwin_path to_posix $root]
     set file [ide_cygwin_path to_posix $file]
   }
Index: gdb/gdbtk/library/prefs.tcl
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/library/prefs.tcl,v
retrieving revision 1.34
diff -u -r1.34 prefs.tcl
--- gdb/gdbtk/library/prefs.tcl	19 Sep 2006 18:39:38 -0000	1.34
+++ gdb/gdbtk/library/prefs.tcl	6 Feb 2008 04:33:48 -0000
@@ -35,7 +35,7 @@
   global tcl_platform
 
   if {[info exists env(HOME)]} {
-    if {$tcl_platform(platform) == "windows"} {
+    if {$tcl_platform(platform) == "windows"  && [llength [info commands ide_cygwin_path]]} {
       set home [ide_cygwin_path to_win32 $env(HOME)]
     } else {
       set home $env(HOME)
Index: gdb/gdbtk/library/session.tcl
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/library/session.tcl,v
retrieving revision 1.16
diff -u -r1.16 session.tcl
--- gdb/gdbtk/library/session.tcl	23 Dec 2005 18:26:50 -0000	1.16
+++ gdb/gdbtk/library/session.tcl	7 Feb 2008 01:59:00 -0000
@@ -21,7 +21,7 @@
     global tcl_platform
 
     # Get real directory.
-    if {[string compare $tcl_platform(platform) "windows"] == 0} {
+    if {[string compare $tcl_platform(platform) "windows"] == 0 && [llength [info commands ide_cygwin_path]]} {
       set path [ide_cygwin_path to_win32 $path]
     }
     set save [pwd]
Index: gdb/gdbtk/library/srctextwin.itb
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/library/srctextwin.itb,v
retrieving revision 1.42
diff -u -r1.42 srctextwin.itb
--- gdb/gdbtk/library/srctextwin.itb	23 Dec 2005 18:26:50 -0000	1.42
+++ gdb/gdbtk/library/srctextwin.itb	7 Feb 2008 02:04:47 -0000
@@ -891,7 +891,7 @@
   } elseif {$f == ""} {
     set r 1
   } else {
-    if {[string compare $tcl_platform(platform) "windows"] == 0} {
+    if {[string compare $tcl_platform(platform) "windows"] == 0 && [llength [info commands ide_cygwin_path]]} {
       set f [ide_cygwin_path to_win32 $f]
     }
     if {[catch {file mtime $f} mtime]} {
@@ -2715,7 +2715,7 @@
     # out.
 
     if {$loadingSource} {
-      if {[string compare $tcl_platform(platform) "windows"] == 0} {
+      if {[string compare $tcl_platform(platform) "windows"] == 0 && [llength [info commands ide_cygwin_path]]} {
         set f [ide_cygwin_path to_win32 $name]
       } else {
         set f $name
Index: gdb/gdbtk/library/targetselection.itb
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/library/targetselection.itb,v
retrieving revision 1.20
diff -u -r1.20 targetselection.itb
--- gdb/gdbtk/library/targetselection.itb	1 Dec 2006 01:07:55 -0000	1.20
+++ gdb/gdbtk/library/targetselection.itb	7 Feb 2008 00:17:37 -0000
@@ -280,7 +280,13 @@
 itcl::body TargetSelection::default_port {} {
   global tcl_platform
   switch -regexp $tcl_platform(os) {
-    Windows { set port com1 }
+    Windows {
+      if { [llength [info commands ide_cygwin_path]] } {
+        set port "/dev/com1"
+      } else {
+        set port "COM1"
+      }
+    }
     Linux   { set port /dev/ttyS0 }
     SunOS   { set port /dev/ttya }
     AIX     { set port /dev/foo1 }
@@ -873,6 +879,11 @@
 #  METHOD:  port_list - return a list of valid ports for Windows
 # ------------------------------------------------------------------
 itcl::body TargetSelection::port_list {} {
+  if { [llength [info commands ide_cygwin_path]] } {
+    set device "/dev/com"
+  } else {
+    set device "COM"
+  }
   set plist ""
   # Scan com1 - com8 trying to open each one.
   # If permission is denied that means it is in use,
@@ -885,7 +896,7 @@
       # Failed.  Find out why.
       if {[string first "permission denied" $msg] != -1} {
 	# Port is there, but busy right now. That's OK.
-	lappend plist /dev/com$i
+	lappend plist $device$i
       } elseif {$i > 4} {

 	# if we've scanned the first 4 ports, then quit when we find no more 
 	set quit 1
@@ -893,7 +904,7 @@
     } else {
       # We got it.  Now close it and add to list.
       close $fd
-      lappend plist /dev/com$i
+      lappend plist $device$i
     }
   }
   return $plist
Index: sim/ppc/table.c
===================================================================
RCS file: /cvs/src/src/sim/ppc/table.c,v
retrieving revision 1.2
diff -u -r1.2 table.c
--- sim/ppc/table.c	12 Jan 2002 10:21:12 -0000	1.2
+++ sim/ppc/table.c	6 Feb 2008 05:07:41 -0000
@@ -128,7 +128,7 @@
   file->pos = file->buffer;
 
   /* read it in */
-#ifdef __CYGWIN32__
+#ifdef __WIN32__
   if ((file->size) && ((nr = read(fd, file->buffer, file->size)) <= 0)) {
 #else
   if ((nr = read(fd, file->buffer, file->size)) < file->size) {
Index: tcl/win/tclWin32Dll.c
===================================================================
RCS file: /cvs/src/src/tcl/win/tclWin32Dll.c,v
retrieving revision 1.11
diff -u -r1.11 tclWin32Dll.c
--- tcl/win/tclWin32Dll.c	1 Dec 2006 20:35:55 -0000	1.11
+++ tcl/win/tclWin32Dll.c	7 Feb 2008 05:54:10 -0000
@@ -41,9 +41,21 @@
 static int platformId;		/* Running under NT, or 95/98? */
 
 #ifdef HAVE_NO_SEH
-static void *ESP;
-static void *EBP;
-#endif /* HAVE_NO_SEH */
+/*
+ * Unlike Borland and Microsoft, we don't register exception handlers by
+ * pushing registration records onto the runtime stack. Instead, we register
+ * them by creating an EXCEPTION_REGISTRATION within the activation record.
+ */
+
+typedef struct EXCEPTION_REGISTRATION {
+    struct EXCEPTION_REGISTRATION *link;
+    EXCEPTION_DISPOSITION (*handler)(
+	    struct _EXCEPTION_RECORD*, void*, struct _CONTEXT*, void*);
+    void *ebp;
+    void *esp;
+    int status;
+} EXCEPTION_REGISTRATION;
+#endif
 
 /*
  * The following function tables are used to dispatch to either the
@@ -358,65 +370,102 @@
 int
 TclpCheckStackSpace()
 {
+
+#ifdef HAVE_NO_SEH
+    EXCEPTION_REGISTRATION registration;
+#endif
     int retval = 0;
 
     /*
-     * We can recurse only if there is at least TCL_WIN_STACK_THRESHOLD
-     * bytes of stack space left.  alloca() is cheap on windows; basically
-     * it just subtracts from the stack pointer causing the OS to throw an
-     * exception if the stack pointer is set below the bottom of the stack.
+     * We can recurse only if there is at least TCL_WIN_STACK_THRESHOLD bytes
+     * of stack space left. alloca() is cheap on windows; basically it just
+     * subtracts from the stack pointer causing the OS to throw an exception
+     * if the stack pointer is set below the bottom of the stack.
      */
 
 #ifdef HAVE_NO_SEH
     __asm__ __volatile__ (
-            "movl  %esp, _ESP" "\n\t"
-            "movl  %ebp, _EBP");
 
-    __asm__ __volatile__ (
-            "pushl $__except_checkstackspace_handler" "\n\t"
-            "pushl %fs:0" "\n\t"
-            "mov   %esp, %fs:0");
-#else
+	/*
+	 * Construct an EXCEPTION_REGISTRATION to protect the call to __alloca
+	 */
+
+	"leal	%[registration], %%edx"		"\n\t"
+	"movl	%%fs:0,		%%eax"		"\n\t"
+	"movl	%%eax,		0x0(%%edx)"	"\n\t" /* link */
+	"leal	1f,		%%eax"		"\n\t"
+	"movl	%%eax,		0x4(%%edx)"	"\n\t" /* handler */
+	"movl	%%ebp,		0x8(%%edx)"	"\n\t" /* ebp */
+	"movl	%%esp,		0xc(%%edx)"	"\n\t" /* esp */
+	"movl	%[error],	0x10(%%edx)"	"\n\t" /* status */
+
+	/*
+	 * Link the EXCEPTION_REGISTRATION on the chain
+	 */
+
+	"movl	%%edx,		%%fs:0"		"\n\t"
+
+	/*
+	 * Attempt a call to __alloca, to determine whether there's sufficient
+	 * memory to be had.
+	 */
+
+	"movl	%[size],	%%eax"		"\n\t"
+	"pushl	%%eax"				"\n\t"
+	"call	__alloca"			"\n\t"
+
+	/*
+	 * Come here on a normal exit. Recover the EXCEPTION_REGISTRATION and
+	 * store a TCL_OK status
+	 */
+
+	"movl	%%fs:0,		%%edx"		"\n\t"
+	"movl	%[ok],		%%eax"		"\n\t"
+	"movl	%%eax,		0x10(%%edx)"	"\n\t"
+	"jmp	2f"				"\n"
+
+	/*
+	 * Come here on an exception. Get the EXCEPTION_REGISTRATION that we
+	 * previously put on the chain.
+	 */
+
+	"1:"					"\t"
+	"movl	%%fs:0,		%%edx"		"\n\t"
+	"movl	0x8(%%edx),	%%edx"		"\n\t"
+
+	/*
+	 * Come here however we exited. Restore context from the
+	 * EXCEPTION_REGISTRATION in case the stack is unbalanced.
+	 */
+
+	"2:"					"\t"
+	"movl	0xc(%%edx),	%%esp"		"\n\t"
+	"movl	0x8(%%edx),	%%ebp"		"\n\t"
+	"movl	0x0(%%edx),	%%eax"		"\n\t"
+	"movl	%%eax,		%%fs:0"		"\n\t"
+
+	:
+	/* No outputs */
+	:
+	[registration]	"m"	(registration),
+	[ok]		"i"	(TCL_OK),
+	[error]		"i"	(TCL_ERROR),
+	[size]		"i"	(TCL_WIN_STACK_THRESHOLD)
+	:
+	"%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory"
+	);
+    retval = (registration.status == TCL_OK);
+
+#else /* !HAVE_NO_SEH */
     __try {
-#endif /* HAVE_NO_SEH */
 	alloca(TCL_WIN_STACK_THRESHOLD);
 	retval = 1;
-#ifdef HAVE_NO_SEH
-    __asm__ __volatile__ (
-            "jmp   checkstackspace_pop" "\n"
-            "checkstackspace_reentry:" "\n\t"
-            "movl  _ESP, %esp" "\n\t"
-            "movl  _EBP, %ebp");
-
-    __asm__ __volatile__ (
-            "checkstackspace_pop:" "\n\t"
-            "mov   (%esp), %eax" "\n\t"
-            "mov   %eax, %fs:0" "\n\t"
-            "add   $8, %esp");
-#else
     } __except (EXCEPTION_EXECUTE_HANDLER) {}
 #endif /* HAVE_NO_SEH */
 
-    /*
-     * Avoid using control flow statements in the SEH guarded block!
-     */
     return retval;
 }
-#ifdef HAVE_NO_SEH
-static
-__attribute__ ((cdecl,used))
-EXCEPTION_DISPOSITION
-_except_checkstackspace_handler(
-    struct _EXCEPTION_RECORD *ExceptionRecord,
-    void *EstablisherFrame,
-    struct _CONTEXT *ContextRecord,
-    void *DispatcherContext)
-{
-    __asm__ __volatile__ (
-            "jmp checkstackspace_reentry");
-    return 0; /* Function does not return */
-}
-#endif /* HAVE_NO_SEH */
+
 \f
 /*
  *----------------------------------------------------------------------

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

* Re: MinGW patches for Insight
  2008-02-07  8:35 MinGW patches for Insight Dave Murphy
@ 2008-02-08 17:24 ` Dave Murphy
  2008-02-08 18:05   ` Mike Frysinger
  0 siblings, 1 reply; 12+ messages in thread
From: Dave Murphy @ 2008-02-08 17:24 UTC (permalink / raw)
  To: insight

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

Hi again,

After some more testing it looks like the -mwindows switch I added to 
insight is responsible for the failure to start on WinXP so I've removed 
that from my patch set.

Updated patch attached.

I'm still not sure how best to format the changelog entries. Should I be 
sending a patchset for each directory where changes are made?

Dave

[-- Attachment #2: insight-mingw.patch --]
[-- Type: text/plain, Size: 17102 bytes --]

2008-02-07  Dave Murphy  <davem@devkitpro.org>

	*configure.ac
	set tcl configdir to win under mingw32

	*gdb/configure
	regenerate

	*gdbtk-cmds.c
	*gdbtk-hooks.c
	guard <sys/ioctl.h> with HAVE_SYS_IOCTL_H

	*gdbtk-interp.c
	include <windows.h> under mingw32

	*gdbtk.c
	guard <sys/ioctl.h> with HAVE_SYS_IOCTL_H
	(gdbtk_start_timer, gdbtk_stop_timer) remove timer calls under mingw
	(gdbtk_init) include windows specific commands under mingw without cygwin path commands

	*download.itb
	*interface.tcl
	*prefs.tcl
	*session.tcl
	*srctextwin.itb
	check ide_cygwin_path exists before using on windows

	*targetselection.itb
	(TargetSelection::default_port) default to /dev/com1 under cygwin, COM1 under mingw
	(TargetSelection::port_list) use /dev/com under cygwin, COM under mingw

	*table.c
	(table_push) correct file read under mingw as well as cygwin

	*tclWin32Dll.c
	(TclpCheckStackSpace) backport EXCEPTION_REGISTRATION code from TCL mainline

Index: gdb/configure
===================================================================
RCS file: /cvs/src/src/gdb/configure,v
retrieving revision 1.242
diff -u -r1.242 configure
--- gdb/configure	13 Jan 2008 12:23:04 -0000	1.242
+++ gdb/configure	8 Feb 2008 16:07:33 -0000
@@ -7085,9 +7085,9 @@
     LIBS="$ac_save_LIBS"
 
 fi
-echo "$as_me:$LINENO: result: $ac_cv_libexpat" >&5
-echo "${ECHO_T}$ac_cv_libexpat" >&6
-  if test "$ac_cv_libexpat" = yes; then
+echo "$as_me:$LINENO: result: $ac_cv_libxpat" >&5
+echo "${ECHO_T}$ac_cv_libxpat" >&6
+  if test "$ac_cv_libet" = yes; then
     HAVE_LIBEXPAT=yes
 
 cat >>confdefs.h <<\_ACEOF
@@ -23080,7 +23080,7 @@
 
 
 case "${host}" in
-*-*-cygwin*)
+*-*-cygwin* | *mingw32* )
     configdir="win"
     ;;
 *)
Index: gdb/configure.ac
===================================================================
RCS file: /cvs/src/src/gdb/configure.ac,v
retrieving revision 1.64
diff -u -r1.64 configure.ac
--- gdb/configure.ac	13 Jan 2008 12:23:05 -0000	1.64
+++ gdb/configure.ac	8 Feb 2008 15:42:43 -0000
@@ -1445,7 +1445,7 @@
 AC_SUBST(WIN32LDAPP)
 
 case "${host}" in
-*-*-cygwin*)
+*-*-cygwin* | *mingw32* )
     configdir="win"
     ;;
 *)
Index: gdb/gdbtk/generic/gdbtk-cmds.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/generic/gdbtk-cmds.c,v
retrieving revision 1.97
diff -u -r1.97 gdbtk-cmds.c
--- gdb/gdbtk/generic/gdbtk-cmds.c	21 Jun 2007 15:18:51 -0000	1.97
+++ gdb/gdbtk/generic/gdbtk-cmds.c	7 Feb 2008 03:43:06 -0000
@@ -57,7 +57,9 @@
 
 #include <signal.h>
 #include <fcntl.h>
+#ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
+#endif
 #include <sys/time.h>
 #include <sys/stat.h>
 
Index: gdb/gdbtk/generic/gdbtk-hooks.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/generic/gdbtk-hooks.c,v
retrieving revision 1.41
diff -u -r1.41 gdbtk-hooks.c
--- gdb/gdbtk/generic/gdbtk-hooks.c	23 Dec 2005 18:23:16 -0000	1.41
+++ gdb/gdbtk/generic/gdbtk-hooks.c	7 Feb 2008 03:43:19 -0000
@@ -51,7 +51,9 @@
 
 #include <signal.h>
 #include <fcntl.h>
+#ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
+#endif
 #include <sys/time.h>
 
 #include "gdb_string.h"
Index: gdb/gdbtk/generic/gdbtk-interp.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/generic/gdbtk-interp.c,v
retrieving revision 1.8
diff -u -r1.8 gdbtk-interp.c
--- gdb/gdbtk/generic/gdbtk-interp.c	23 Dec 2005 18:23:16 -0000	1.8
+++ gdb/gdbtk/generic/gdbtk-interp.c	6 Feb 2008 03:50:50 -0000
@@ -34,6 +34,12 @@
 #include "tk.h"
 #include "gdbtk.h"
 
+#ifdef __MINGW32__
+	#define WIN32_LEAN_AND_MEAN
+	#include <windows.h>
+#endif
+
+
 static void gdbtk_command_loop (void);
 static void hack_disable_interpreter_exec (char *, int);
 
Index: gdb/gdbtk/generic/gdbtk.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/generic/gdbtk.c,v
retrieving revision 1.45
diff -u -r1.45 gdbtk.c
--- gdb/gdbtk/generic/gdbtk.c	1 Dec 2006 02:09:24 -0000	1.45
+++ gdb/gdbtk/generic/gdbtk.c	7 Feb 2008 06:23:48 -0000
@@ -49,7 +49,9 @@
 
 #include <fcntl.h>
 #include <sys/stat.h>
+#ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
+#endif
 #include <sys/time.h>
 #include <signal.h>
 
@@ -63,6 +65,7 @@
 
 extern void _initialize_gdbtk (void);
 
+#ifndef __MINGW32__
 /* For unix natives, we use a timer to periodically keep the gui alive.
    See comments before x_event. */
 static sigset_t nullsigmask;
@@ -74,6 +77,7 @@
 {
   x_event (signo);
 }
+#endif
 
 /*
  * This variable controls the interaction with an external editor.
@@ -262,6 +266,7 @@
     {
       /* first time called, set up all the structs */
       first = 0;
+#ifndef __MINGW32__
       sigemptyset (&nullsigmask);
 
       act1.sa_handler = x_event_wrapper;
@@ -281,14 +286,17 @@
       it_off.it_interval.tv_usec = 0;
       it_off.it_value.tv_sec = 0;
       it_off.it_value.tv_usec = 0;
+#endif
     }
 
   if (target_should_use_timer (&current_target))
     {
       if (!gdbtk_timer_going)
 	{
+#ifndef __MINGW32__
 	  sigaction (SIGALRM, &act1, NULL);
 	  setitimer (ITIMER_REAL, &it_on, NULL);
+#endif
 	  gdbtk_timer_going = 1;
 	}
     }
@@ -302,8 +310,10 @@
   if (gdbtk_timer_going)
     {
       gdbtk_timer_going = 0;
+#ifndef __MINGW32__
       setitimer (ITIMER_REAL, &it_off, NULL);
       sigaction (SIGALRM, &act2, NULL);
+#endif
     }
   return;
 }
@@ -510,7 +520,7 @@
    * These are the commands to do some Windows Specific stuff...
    */
 
-#ifdef __CYGWIN32__
+#ifdef __WIN32__
   if (ide_create_messagebox_command (gdbtk_interp) != TCL_OK)
     error ("messagebox command initialization failed");
   /* On Windows, create a sizebox widget command */
@@ -522,6 +532,8 @@
     error ("windows print code initialization failed");
   if (ide_create_win_grab_command (gdbtk_interp) != TCL_OK)
     error ("grab support command initialization failed");
+#endif
+#ifdef __CYGWIN32__
   /* Path conversion functions.  */
   if (ide_create_cygwin_path_command (gdbtk_interp) != TCL_OK)
     error ("cygwin path command initialization failed");
Index: gdb/gdbtk/library/download.itb
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/library/download.itb,v
retrieving revision 1.11
diff -u -r1.11 download.itb
--- gdb/gdbtk/library/download.itb	23 Dec 2005 18:26:50 -0000	1.11
+++ gdb/gdbtk/library/download.itb	6 Feb 2008 04:30:59 -0000
@@ -207,7 +207,7 @@
     }
   }
 
-  if {[string compare $tcl_platform(platform) "windows"] == 0} {
+  if {[string compare $tcl_platform(platform) "windows"] == 0 && [llength [info commands ide_cygwin_path]]} {
     set f [ide_cygwin_path to_win32 $gdb_exe_name]
   } else {
     set f $gdb_exe_name
Index: gdb/gdbtk/library/interface.tcl
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/library/interface.tcl,v
retrieving revision 1.57
diff -u -r1.57 interface.tcl
--- gdb/gdbtk/library/interface.tcl	23 Dec 2005 18:26:50 -0000	1.57
+++ gdb/gdbtk/library/interface.tcl	6 Feb 2008 04:32:56 -0000
@@ -962,7 +962,7 @@
   }
   # Add the base dir for this file to the source search path.
   set root [file dirname $file]
-  if {$tcl_platform(platform) == "windows"} {
+  if {$tcl_platform(platform) == "windows" && [llength [info commands ide_cygwin_path]]} {
     set root [ide_cygwin_path to_posix $root]
     set file [ide_cygwin_path to_posix $file]
   }
Index: gdb/gdbtk/library/prefs.tcl
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/library/prefs.tcl,v
retrieving revision 1.34
diff -u -r1.34 prefs.tcl
--- gdb/gdbtk/library/prefs.tcl	19 Sep 2006 18:39:38 -0000	1.34
+++ gdb/gdbtk/library/prefs.tcl	6 Feb 2008 04:33:48 -0000
@@ -35,7 +35,7 @@
   global tcl_platform
 
   if {[info exists env(HOME)]} {
-    if {$tcl_platform(platform) == "windows"} {
+    if {$tcl_platform(platform) == "windows"  && [llength [info commands ide_cygwin_path]]} {
       set home [ide_cygwin_path to_win32 $env(HOME)]
     } else {
       set home $env(HOME)
Index: gdb/gdbtk/library/session.tcl
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/library/session.tcl,v
retrieving revision 1.16
diff -u -r1.16 session.tcl
--- gdb/gdbtk/library/session.tcl	23 Dec 2005 18:26:50 -0000	1.16
+++ gdb/gdbtk/library/session.tcl	7 Feb 2008 01:59:00 -0000
@@ -21,7 +21,7 @@
     global tcl_platform
 
     # Get real directory.
-    if {[string compare $tcl_platform(platform) "windows"] == 0} {
+    if {[string compare $tcl_platform(platform) "windows"] == 0 && [llength [info commands ide_cygwin_path]]} {
       set path [ide_cygwin_path to_win32 $path]
     }
     set save [pwd]
Index: gdb/gdbtk/library/srctextwin.itb
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/library/srctextwin.itb,v
retrieving revision 1.42
diff -u -r1.42 srctextwin.itb
--- gdb/gdbtk/library/srctextwin.itb	23 Dec 2005 18:26:50 -0000	1.42
+++ gdb/gdbtk/library/srctextwin.itb	7 Feb 2008 02:04:47 -0000
@@ -891,7 +891,7 @@
   } elseif {$f == ""} {
     set r 1
   } else {
-    if {[string compare $tcl_platform(platform) "windows"] == 0} {
+    if {[string compare $tcl_platform(platform) "windows"] == 0 && [llength [info commands ide_cygwin_path]]} {
       set f [ide_cygwin_path to_win32 $f]
     }
     if {[catch {file mtime $f} mtime]} {
@@ -2715,7 +2715,7 @@
     # out.
 
     if {$loadingSource} {
-      if {[string compare $tcl_platform(platform) "windows"] == 0} {
+      if {[string compare $tcl_platform(platform) "windows"] == 0 && [llength [info commands ide_cygwin_path]]} {
         set f [ide_cygwin_path to_win32 $name]
       } else {
         set f $name
Index: gdb/gdbtk/library/targetselection.itb
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/library/targetselection.itb,v
retrieving revision 1.20
diff -u -r1.20 targetselection.itb
--- gdb/gdbtk/library/targetselection.itb	1 Dec 2006 01:07:55 -0000	1.20
+++ gdb/gdbtk/library/targetselection.itb	7 Feb 2008 00:17:37 -0000
@@ -280,7 +280,13 @@
 itcl::body TargetSelection::default_port {} {
   global tcl_platform
   switch -regexp $tcl_platform(os) {
-    Windows { set port com1 }
+    Windows {
+      if { [llength [info commands ide_cygwin_path]] } {
+        set port "/dev/com1"
+      } else {
+        set port "COM1"
+      }
+    }
     Linux   { set port /dev/ttyS0 }
     SunOS   { set port /dev/ttya }
     AIX     { set port /dev/foo1 }
@@ -873,6 +879,11 @@
 #  METHOD:  port_list - return a list of valid ports for Windows
 # ------------------------------------------------------------------
 itcl::body TargetSelection::port_list {} {
+  if { [llength [info commands ide_cygwin_path]] } {
+    set device "/dev/com"
+  } else {
+    set device "COM"
+  }
   set plist ""
   # Scan com1 - com8 trying to open each one.
   # If permission is denied that means it is in use,
@@ -885,7 +896,7 @@
       # Failed.  Find out why.
       if {[string first "permission denied" $msg] != -1} {
 	# Port is there, but busy right now. That's OK.
-	lappend plist /dev/com$i
+	lappend plist $device$i
       } elseif {$i > 4} {
 	# if we've scanned the first 4 ports, then quit when we find no more 
 	set quit 1
@@ -893,7 +904,7 @@
     } else {
       # We got it.  Now close it and add to list.
       close $fd
-      lappend plist /dev/com$i
+      lappend plist $device$i
     }
   }
   return $plist
Index: sim/ppc/table.c
===================================================================
RCS file: /cvs/src/src/sim/ppc/table.c,v
retrieving revision 1.2
diff -u -r1.2 table.c
--- sim/ppc/table.c	12 Jan 2002 10:21:12 -0000	1.2
+++ sim/ppc/table.c	6 Feb 2008 05:07:41 -0000
@@ -128,7 +128,7 @@
   file->pos = file->buffer;
 
   /* read it in */
-#ifdef __CYGWIN32__
+#ifdef __WIN32__
   if ((file->size) && ((nr = read(fd, file->buffer, file->size)) <= 0)) {
 #else
   if ((nr = read(fd, file->buffer, file->size)) < file->size) {
Index: tcl/win/tclWin32Dll.c
===================================================================
RCS file: /cvs/src/src/tcl/win/tclWin32Dll.c,v
retrieving revision 1.11
diff -u -r1.11 tclWin32Dll.c
--- tcl/win/tclWin32Dll.c	1 Dec 2006 20:35:55 -0000	1.11
+++ tcl/win/tclWin32Dll.c	7 Feb 2008 05:54:10 -0000
@@ -41,9 +41,21 @@
 static int platformId;		/* Running under NT, or 95/98? */
 
 #ifdef HAVE_NO_SEH
-static void *ESP;
-static void *EBP;
-#endif /* HAVE_NO_SEH */
+/*
+ * Unlike Borland and Microsoft, we don't register exception handlers by
+ * pushing registration records onto the runtime stack. Instead, we register
+ * them by creating an EXCEPTION_REGISTRATION within the activation record.
+ */
+
+typedef struct EXCEPTION_REGISTRATION {
+    struct EXCEPTION_REGISTRATION *link;
+    EXCEPTION_DISPOSITION (*handler)(
+	    struct _EXCEPTION_RECORD*, void*, struct _CONTEXT*, void*);
+    void *ebp;
+    void *esp;
+    int status;
+} EXCEPTION_REGISTRATION;
+#endif
 
 /*
  * The following function tables are used to dispatch to either the
@@ -358,65 +370,102 @@
 int
 TclpCheckStackSpace()
 {
+
+#ifdef HAVE_NO_SEH
+    EXCEPTION_REGISTRATION registration;
+#endif
     int retval = 0;
 
     /*
-     * We can recurse only if there is at least TCL_WIN_STACK_THRESHOLD
-     * bytes of stack space left.  alloca() is cheap on windows; basically
-     * it just subtracts from the stack pointer causing the OS to throw an
-     * exception if the stack pointer is set below the bottom of the stack.
+     * We can recurse only if there is at least TCL_WIN_STACK_THRESHOLD bytes
+     * of stack space left. alloca() is cheap on windows; basically it just
+     * subtracts from the stack pointer causing the OS to throw an exception
+     * if the stack pointer is set below the bottom of the stack.
      */
 
 #ifdef HAVE_NO_SEH
     __asm__ __volatile__ (
-            "movl  %esp, _ESP" "\n\t"
-            "movl  %ebp, _EBP");
 
-    __asm__ __volatile__ (
-            "pushl $__except_checkstackspace_handler" "\n\t"
-            "pushl %fs:0" "\n\t"
-            "mov   %esp, %fs:0");
-#else
+	/*
+	 * Construct an EXCEPTION_REGISTRATION to protect the call to __alloca
+	 */
+
+	"leal	%[registration], %%edx"		"\n\t"
+	"movl	%%fs:0,		%%eax"		"\n\t"
+	"movl	%%eax,		0x0(%%edx)"	"\n\t" /* link */
+	"leal	1f,		%%eax"		"\n\t"
+	"movl	%%eax,		0x4(%%edx)"	"\n\t" /* handler */
+	"movl	%%ebp,		0x8(%%edx)"	"\n\t" /* ebp */
+	"movl	%%esp,		0xc(%%edx)"	"\n\t" /* esp */
+	"movl	%[error],	0x10(%%edx)"	"\n\t" /* status */
+
+	/*
+	 * Link the EXCEPTION_REGISTRATION on the chain
+	 */
+
+	"movl	%%edx,		%%fs:0"		"\n\t"
+
+	/*
+	 * Attempt a call to __alloca, to determine whether there's sufficient
+	 * memory to be had.
+	 */
+
+	"movl	%[size],	%%eax"		"\n\t"
+	"pushl	%%eax"				"\n\t"
+	"call	__alloca"			"\n\t"
+
+	/*
+	 * Come here on a normal exit. Recover the EXCEPTION_REGISTRATION and
+	 * store a TCL_OK status
+	 */
+
+	"movl	%%fs:0,		%%edx"		"\n\t"
+	"movl	%[ok],		%%eax"		"\n\t"
+	"movl	%%eax,		0x10(%%edx)"	"\n\t"
+	"jmp	2f"				"\n"
+
+	/*
+	 * Come here on an exception. Get the EXCEPTION_REGISTRATION that we
+	 * previously put on the chain.
+	 */
+
+	"1:"					"\t"
+	"movl	%%fs:0,		%%edx"		"\n\t"
+	"movl	0x8(%%edx),	%%edx"		"\n\t"
+
+	/*
+	 * Come here however we exited. Restore context from the
+	 * EXCEPTION_REGISTRATION in case the stack is unbalanced.
+	 */
+
+	"2:"					"\t"
+	"movl	0xc(%%edx),	%%esp"		"\n\t"
+	"movl	0x8(%%edx),	%%ebp"		"\n\t"
+	"movl	0x0(%%edx),	%%eax"		"\n\t"
+	"movl	%%eax,		%%fs:0"		"\n\t"
+
+	:
+	/* No outputs */
+	:
+	[registration]	"m"	(registration),
+	[ok]		"i"	(TCL_OK),
+	[error]		"i"	(TCL_ERROR),
+	[size]		"i"	(TCL_WIN_STACK_THRESHOLD)
+	:
+	"%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory"
+	);
+    retval = (registration.status == TCL_OK);
+
+#else /* !HAVE_NO_SEH */
     __try {
-#endif /* HAVE_NO_SEH */
 	alloca(TCL_WIN_STACK_THRESHOLD);
 	retval = 1;
-#ifdef HAVE_NO_SEH
-    __asm__ __volatile__ (
-            "jmp   checkstackspace_pop" "\n"
-            "checkstackspace_reentry:" "\n\t"
-            "movl  _ESP, %esp" "\n\t"
-            "movl  _EBP, %ebp");
-
-    __asm__ __volatile__ (
-            "checkstackspace_pop:" "\n\t"
-            "mov   (%esp), %eax" "\n\t"
-            "mov   %eax, %fs:0" "\n\t"
-            "add   $8, %esp");
-#else
     } __except (EXCEPTION_EXECUTE_HANDLER) {}
 #endif /* HAVE_NO_SEH */
 
-    /*
-     * Avoid using control flow statements in the SEH guarded block!
-     */
     return retval;
 }
-#ifdef HAVE_NO_SEH
-static
-__attribute__ ((cdecl,used))
-EXCEPTION_DISPOSITION
-_except_checkstackspace_handler(
-    struct _EXCEPTION_RECORD *ExceptionRecord,
-    void *EstablisherFrame,
-    struct _CONTEXT *ContextRecord,
-    void *DispatcherContext)
-{
-    __asm__ __volatile__ (
-            "jmp checkstackspace_reentry");
-    return 0; /* Function does not return */
-}
-#endif /* HAVE_NO_SEH */
+
 \f
 /*
  *----------------------------------------------------------------------

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

* Re: MinGW patches for Insight
  2008-02-08 17:24 ` Dave Murphy
@ 2008-02-08 18:05   ` Mike Frysinger
  2008-02-08 23:17     ` Dave Murphy
  0 siblings, 1 reply; 12+ messages in thread
From: Mike Frysinger @ 2008-02-08 18:05 UTC (permalink / raw)
  To: insight; +Cc: Dave Murphy

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

On Friday 08 February 2008, Dave Murphy wrote:
> I'm still not sure how best to format the changelog entries. Should I be
> sending a patchset for each directory where changes are made?

you do it based upon the ChangeLog files that already exist.  look at the file 
you change, and then walk up directories until you hit the first ChangeLog 
file.

>   2008-02-07  Dave Murphy  <davem@devkitpro.org>
>
>         *configure.ac
>         set tcl configdir to win under mingw32

if you look at the existing ChangeLog entries, you'll see these are formatted 
wrong.  it's something like:
	* file (relevant scope in file where applicable): Description of change.

>         *gdb/configure
>         regenerate

while you are supposed to say you regenerated things, you dont actually 
include the changes to configure in patches that get posted to mailing lists 
and such.  generated files are not interesting and tend to contain a lot of 
noise.

> --- gdb/configure.ac    13 Jan 2008 12:23:05 -0000      1.64
> +++ gdb/configure.ac    8 Feb 2008 15:42:43 -0000
> @@ -1445,7 +1445,7 @@
>  AC_SUBST(WIN32LDAPP)
>  
>  case "${host}" in
> -*-*-cygwin*)
> +*-*-cygwin* | *mingw32* )
>      configdir="win"
>      ;;
>  *)

what about 64bit mingw ?

> --- gdb/gdbtk/generic/gdbtk-interp.c    23 Dec 2005 18:23:16 -0000      1.8
> +++ gdb/gdbtk/generic/gdbtk-interp.c    6 Feb 2008 03:50:50 -0000
> @@ -34,6 +34,12 @@
>  #include "tk.h"
>  #include "gdbtk.h"
>  
> +#ifdef __MINGW32__
> +       #define WIN32_LEAN_AND_MEAN
> +       #include <windows.h>
> +#endif

never put whitespace before the #:
#ifdef __MINGW32__
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
#endif
-mike

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 827 bytes --]

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

* Re: MinGW patches for Insight
  2008-02-08 18:05   ` Mike Frysinger
@ 2008-02-08 23:17     ` Dave Murphy
  2008-02-08 23:34       ` Mike Frysinger
  2008-02-09  0:03       ` Keith Seitz
  0 siblings, 2 replies; 12+ messages in thread
From: Dave Murphy @ 2008-02-08 23:17 UTC (permalink / raw)
  To: Mike Frysinger; +Cc: insight

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

Mike Frysinger wrote:
> On Friday 08 February 2008, Dave Murphy wrote:
>   
>> I'm still not sure how best to format the changelog entries. Should I be
>> sending a patchset for each directory where changes are made?
>>     
>
> you do it based upon the ChangeLog files that already exist.  look at the file 
> you change, and then walk up directories until you hit the first ChangeLog 
> file.
>   

Thanks for the advice Mike, much appreciated.

Updated patch with suggested changes attached. I've submitted the ppc 
sim patch to the gdb patches list instead.

Dave

[-- Attachment #2: insight-mingw.patch --]
[-- Type: text/plain, Size: 16085 bytes --]


2008-02-07  Dave Murphy  <davem@devkitpro.org>

	* configure.ac :set tcl configdir to win under mingw
	* configure : regenerate


gdb/gdbtk/generic/

2008-02-07  Dave Murphy  <davem@devkitpro.org>

	* gdbtk-cmds.c : guard <sys/ioctl.h> with HAVE_SYS_IOCTL_H
	* gdbtk-hooks.c : ditto
	* gdbtk.c : ditto
	* gdbtk-interp.c : include <windows.h> under mingw32
	(gdbtk_start_timer, gdbtk_stop_timer): remove timer calls under mingw
	(gdbtk_init): include windows specific commands under mingw without cygwin
	path commands

gdb/gdbtk/library/

2008-02-07  Dave Murphy  <davem@devkitpro.org>

	* download.itb (Download::download_it) : check ide_cygwin_path exists
	before using on windows 
	* interface.tcl (_open_file) : ditto
	* prefs.tcl : (pref_read) : ditto
	* session.tcl : ( _exe_name) : ditto
	* srctextwin.itb : 
	(SrcTextWin::_mtime_changed, SrcTextWin::LoadFromCache) : ditto
	* targetselection.itb (TargetSelection::default_port) : default to
	/dev/com1 under cygwin, COM1 under mingw
	(TargetSelection::port_list) : use /dev/com under cygwin, COM under mingw

tcl/win

2008-02-07  Dave Murphy  <davem@devkitpro.org>

	* tclWin32Dll.c (TclpCheckStackSpace) : backport EXCEPTION_REGISTRATION code
	from TCL mainline


Index: gdb/configure.ac
===================================================================
RCS file: /cvs/src/src/gdb/configure.ac,v
retrieving revision 1.64
diff -u -r1.64 configure.ac
--- gdb/configure.ac	13 Jan 2008 12:23:05 -0000	1.64
+++ gdb/configure.ac	8 Feb 2008 20:41:52 -0000
@@ -1445,7 +1445,7 @@
 AC_SUBST(WIN32LDAPP)
 
 case "${host}" in
-*-*-cygwin*)
+*-*-cygwin* | *-*-mingw* )
     configdir="win"
     ;;
 *)
Index: gdb/gdbtk/generic/gdbtk-cmds.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/generic/gdbtk-cmds.c,v
retrieving revision 1.97
diff -u -r1.97 gdbtk-cmds.c
--- gdb/gdbtk/generic/gdbtk-cmds.c	21 Jun 2007 15:18:51 -0000	1.97
+++ gdb/gdbtk/generic/gdbtk-cmds.c	7 Feb 2008 03:43:06 -0000
@@ -57,7 +57,9 @@
 
 #include <signal.h>
 #include <fcntl.h>
+#ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
+#endif
 #include <sys/time.h>
 #include <sys/stat.h>
 
Index: gdb/gdbtk/generic/gdbtk-hooks.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/generic/gdbtk-hooks.c,v
retrieving revision 1.41
diff -u -r1.41 gdbtk-hooks.c
--- gdb/gdbtk/generic/gdbtk-hooks.c	23 Dec 2005 18:23:16 -0000	1.41
+++ gdb/gdbtk/generic/gdbtk-hooks.c	7 Feb 2008 03:43:19 -0000
@@ -51,7 +51,9 @@
 
 #include <signal.h>
 #include <fcntl.h>
+#ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
+#endif
 #include <sys/time.h>
 
 #include "gdb_string.h"
Index: gdb/gdbtk/generic/gdbtk-interp.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/generic/gdbtk-interp.c,v
retrieving revision 1.8
diff -u -r1.8 gdbtk-interp.c
--- gdb/gdbtk/generic/gdbtk-interp.c	23 Dec 2005 18:23:16 -0000	1.8
+++ gdb/gdbtk/generic/gdbtk-interp.c	8 Feb 2008 20:46:44 -0000
@@ -34,6 +34,12 @@
 #include "tk.h"
 #include "gdbtk.h"
 
+#ifdef __MINGW32__
+# define WIN32_LEAN_AND_MEAN
+# include <windows.h>
+#endif
+
+
 static void gdbtk_command_loop (void);
 static void hack_disable_interpreter_exec (char *, int);
 
Index: gdb/gdbtk/generic/gdbtk.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/generic/gdbtk.c,v
retrieving revision 1.45
diff -u -r1.45 gdbtk.c
--- gdb/gdbtk/generic/gdbtk.c	1 Dec 2006 02:09:24 -0000	1.45
+++ gdb/gdbtk/generic/gdbtk.c	7 Feb 2008 06:23:48 -0000
@@ -49,7 +49,9 @@
 
 #include <fcntl.h>
 #include <sys/stat.h>
+#ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
+#endif
 #include <sys/time.h>
 #include <signal.h>
 
@@ -63,6 +65,7 @@
 
 extern void _initialize_gdbtk (void);
 
+#ifndef __MINGW32__
 /* For unix natives, we use a timer to periodically keep the gui alive.
    See comments before x_event. */
 static sigset_t nullsigmask;
@@ -74,6 +77,7 @@
 {
   x_event (signo);
 }
+#endif
 
 /*
  * This variable controls the interaction with an external editor.
@@ -262,6 +266,7 @@
     {
       /* first time called, set up all the structs */
       first = 0;
+#ifndef __MINGW32__
       sigemptyset (&nullsigmask);
 
       act1.sa_handler = x_event_wrapper;
@@ -281,14 +286,17 @@
       it_off.it_interval.tv_usec = 0;
       it_off.it_value.tv_sec = 0;
       it_off.it_value.tv_usec = 0;
+#endif
     }
 
   if (target_should_use_timer (&current_target))
     {
       if (!gdbtk_timer_going)
 	{
+#ifndef __MINGW32__
 	  sigaction (SIGALRM, &act1, NULL);
 	  setitimer (ITIMER_REAL, &it_on, NULL);
+#endif
 	  gdbtk_timer_going = 1;
 	}
     }
@@ -302,8 +310,10 @@
   if (gdbtk_timer_going)
     {
       gdbtk_timer_going = 0;
+#ifndef __MINGW32__
       setitimer (ITIMER_REAL, &it_off, NULL);
       sigaction (SIGALRM, &act2, NULL);
+#endif
     }
   return;
 }
@@ -510,7 +520,7 @@
    * These are the commands to do some Windows Specific stuff...
    */
 
-#ifdef __CYGWIN32__
+#ifdef __WIN32__
   if (ide_create_messagebox_command (gdbtk_interp) != TCL_OK)
     error ("messagebox command initialization failed");
   /* On Windows, create a sizebox widget command */
@@ -522,6 +532,8 @@
     error ("windows print code initialization failed");
   if (ide_create_win_grab_command (gdbtk_interp) != TCL_OK)
     error ("grab support command initialization failed");
+#endif
+#ifdef __CYGWIN32__
   /* Path conversion functions.  */
   if (ide_create_cygwin_path_command (gdbtk_interp) != TCL_OK)
     error ("cygwin path command initialization failed");
Index: gdb/gdbtk/library/download.itb
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/library/download.itb,v
retrieving revision 1.11
diff -u -r1.11 download.itb
--- gdb/gdbtk/library/download.itb	23 Dec 2005 18:26:50 -0000	1.11
+++ gdb/gdbtk/library/download.itb	6 Feb 2008 04:30:59 -0000
@@ -207,7 +207,7 @@
     }
   }
 
-  if {[string compare $tcl_platform(platform) "windows"] == 0} {
+  if {[string compare $tcl_platform(platform) "windows"] == 0 && [llength [info commands ide_cygwin_path]]} {
     set f [ide_cygwin_path to_win32 $gdb_exe_name]
   } else {
     set f $gdb_exe_name
Index: gdb/gdbtk/library/interface.tcl
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/library/interface.tcl,v
retrieving revision 1.57
diff -u -r1.57 interface.tcl
--- gdb/gdbtk/library/interface.tcl	23 Dec 2005 18:26:50 -0000	1.57
+++ gdb/gdbtk/library/interface.tcl	6 Feb 2008 04:32:56 -0000
@@ -962,7 +962,7 @@
   }
   # Add the base dir for this file to the source search path.
   set root [file dirname $file]
-  if {$tcl_platform(platform) == "windows"} {
+  if {$tcl_platform(platform) == "windows" && [llength [info commands ide_cygwin_path]]} {
     set root [ide_cygwin_path to_posix $root]
     set file [ide_cygwin_path to_posix $file]
   }
Index: gdb/gdbtk/library/prefs.tcl
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/library/prefs.tcl,v
retrieving revision 1.34
diff -u -r1.34 prefs.tcl
--- gdb/gdbtk/library/prefs.tcl	19 Sep 2006 18:39:38 -0000	1.34
+++ gdb/gdbtk/library/prefs.tcl	6 Feb 2008 04:33:48 -0000
@@ -35,7 +35,7 @@
   global tcl_platform
 
   if {[info exists env(HOME)]} {
-    if {$tcl_platform(platform) == "windows"} {
+    if {$tcl_platform(platform) == "windows"  && [llength [info commands ide_cygwin_path]]} {
       set home [ide_cygwin_path to_win32 $env(HOME)]
     } else {
       set home $env(HOME)
Index: gdb/gdbtk/library/session.tcl
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/library/session.tcl,v
retrieving revision 1.16
diff -u -r1.16 session.tcl
--- gdb/gdbtk/library/session.tcl	23 Dec 2005 18:26:50 -0000	1.16
+++ gdb/gdbtk/library/session.tcl	7 Feb 2008 01:59:00 -0000
@@ -21,7 +21,7 @@
     global tcl_platform
 
     # Get real directory.
-    if {[string compare $tcl_platform(platform) "windows"] == 0} {
+    if {[string compare $tcl_platform(platform) "windows"] == 0 && [llength [info commands ide_cygwin_path]]} {
       set path [ide_cygwin_path to_win32 $path]
     }
     set save [pwd]
Index: gdb/gdbtk/library/srctextwin.itb
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/library/srctextwin.itb,v
retrieving revision 1.42
diff -u -r1.42 srctextwin.itb
--- gdb/gdbtk/library/srctextwin.itb	23 Dec 2005 18:26:50 -0000	1.42
+++ gdb/gdbtk/library/srctextwin.itb	7 Feb 2008 02:04:47 -0000
@@ -891,7 +891,7 @@
   } elseif {$f == ""} {
     set r 1
   } else {
-    if {[string compare $tcl_platform(platform) "windows"] == 0} {
+    if {[string compare $tcl_platform(platform) "windows"] == 0 && [llength [info commands ide_cygwin_path]]} {
       set f [ide_cygwin_path to_win32 $f]
     }
     if {[catch {file mtime $f} mtime]} {
@@ -2715,7 +2715,7 @@
     # out.
 
     if {$loadingSource} {
-      if {[string compare $tcl_platform(platform) "windows"] == 0} {
+      if {[string compare $tcl_platform(platform) "windows"] == 0 && [llength [info commands ide_cygwin_path]]} {
         set f [ide_cygwin_path to_win32 $name]
       } else {
         set f $name
Index: gdb/gdbtk/library/targetselection.itb
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/library/targetselection.itb,v
retrieving revision 1.20
diff -u -r1.20 targetselection.itb
--- gdb/gdbtk/library/targetselection.itb	1 Dec 2006 01:07:55 -0000	1.20
+++ gdb/gdbtk/library/targetselection.itb	7 Feb 2008 00:17:37 -0000
@@ -280,7 +280,13 @@
 itcl::body TargetSelection::default_port {} {
   global tcl_platform
   switch -regexp $tcl_platform(os) {
-    Windows { set port com1 }
+    Windows {
+      if { [llength [info commands ide_cygwin_path]] } {
+        set port "/dev/com1"
+      } else {
+        set port "COM1"
+      }
+    }
     Linux   { set port /dev/ttyS0 }
     SunOS   { set port /dev/ttya }
     AIX     { set port /dev/foo1 }
@@ -873,6 +879,11 @@
 #  METHOD:  port_list - return a list of valid ports for Windows
 # ------------------------------------------------------------------
 itcl::body TargetSelection::port_list {} {
+  if { [llength [info commands ide_cygwin_path]] } {
+    set device "/dev/com"
+  } else {
+    set device "COM"
+  }
   set plist ""
   # Scan com1 - com8 trying to open each one.
   # If permission is denied that means it is in use,
@@ -885,7 +896,7 @@
       # Failed.  Find out why.
       if {[string first "permission denied" $msg] != -1} {
 	# Port is there, but busy right now. That's OK.
-	lappend plist /dev/com$i
+	lappend plist $device$i
       } elseif {$i > 4} {
 	# if we've scanned the first 4 ports, then quit when we find no more 
 	set quit 1
@@ -893,7 +904,7 @@
     } else {
       # We got it.  Now close it and add to list.
       close $fd
-      lappend plist /dev/com$i
+      lappend plist $device$i
     }
   }
   return $plist
Index: tcl/win/tclWin32Dll.c
===================================================================
RCS file: /cvs/src/src/tcl/win/tclWin32Dll.c,v
retrieving revision 1.11
diff -u -r1.11 tclWin32Dll.c
--- tcl/win/tclWin32Dll.c	1 Dec 2006 20:35:55 -0000	1.11
+++ tcl/win/tclWin32Dll.c	7 Feb 2008 05:54:10 -0000
@@ -41,9 +41,21 @@
 static int platformId;		/* Running under NT, or 95/98? */
 
 #ifdef HAVE_NO_SEH
-static void *ESP;
-static void *EBP;
-#endif /* HAVE_NO_SEH */
+/*
+ * Unlike Borland and Microsoft, we don't register exception handlers by
+ * pushing registration records onto the runtime stack. Instead, we register
+ * them by creating an EXCEPTION_REGISTRATION within the activation record.
+ */
+
+typedef struct EXCEPTION_REGISTRATION {
+    struct EXCEPTION_REGISTRATION *link;
+    EXCEPTION_DISPOSITION (*handler)(
+	    struct _EXCEPTION_RECORD*, void*, struct _CONTEXT*, void*);
+    void *ebp;
+    void *esp;
+    int status;
+} EXCEPTION_REGISTRATION;
+#endif
 
 /*
  * The following function tables are used to dispatch to either the
@@ -358,65 +370,102 @@
 int
 TclpCheckStackSpace()
 {
+
+#ifdef HAVE_NO_SEH
+    EXCEPTION_REGISTRATION registration;
+#endif
     int retval = 0;
 
     /*
-     * We can recurse only if there is at least TCL_WIN_STACK_THRESHOLD
-     * bytes of stack space left.  alloca() is cheap on windows; basically
-     * it just subtracts from the stack pointer causing the OS to throw an
-     * exception if the stack pointer is set below the bottom of the stack.
+     * We can recurse only if there is at least TCL_WIN_STACK_THRESHOLD bytes
+     * of stack space left. alloca() is cheap on windows; basically it just
+     * subtracts from the stack pointer causing the OS to throw an exception
+     * if the stack pointer is set below the bottom of the stack.
      */
 
 #ifdef HAVE_NO_SEH
     __asm__ __volatile__ (
-            "movl  %esp, _ESP" "\n\t"
-            "movl  %ebp, _EBP");
 
-    __asm__ __volatile__ (
-            "pushl $__except_checkstackspace_handler" "\n\t"
-            "pushl %fs:0" "\n\t"
-            "mov   %esp, %fs:0");
-#else
+	/*
+	 * Construct an EXCEPTION_REGISTRATION to protect the call to __alloca
+	 */
+
+	"leal	%[registration], %%edx"		"\n\t"
+	"movl	%%fs:0,		%%eax"		"\n\t"
+	"movl	%%eax,		0x0(%%edx)"	"\n\t" /* link */
+	"leal	1f,		%%eax"		"\n\t"
+	"movl	%%eax,		0x4(%%edx)"	"\n\t" /* handler */
+	"movl	%%ebp,		0x8(%%edx)"	"\n\t" /* ebp */
+	"movl	%%esp,		0xc(%%edx)"	"\n\t" /* esp */
+	"movl	%[error],	0x10(%%edx)"	"\n\t" /* status */
+
+	/*
+	 * Link the EXCEPTION_REGISTRATION on the chain
+	 */
+
+	"movl	%%edx,		%%fs:0"		"\n\t"
+
+	/*
+	 * Attempt a call to __alloca, to determine whether there's sufficient
+	 * memory to be had.
+	 */
+
+	"movl	%[size],	%%eax"		"\n\t"
+	"pushl	%%eax"				"\n\t"
+	"call	__alloca"			"\n\t"
+
+	/*
+	 * Come here on a normal exit. Recover the EXCEPTION_REGISTRATION and
+	 * store a TCL_OK status
+	 */
+
+	"movl	%%fs:0,		%%edx"		"\n\t"
+	"movl	%[ok],		%%eax"		"\n\t"
+	"movl	%%eax,		0x10(%%edx)"	"\n\t"
+	"jmp	2f"				"\n"
+
+	/*
+	 * Come here on an exception. Get the EXCEPTION_REGISTRATION that we
+	 * previously put on the chain.
+	 */
+
+	"1:"					"\t"
+	"movl	%%fs:0,		%%edx"		"\n\t"
+	"movl	0x8(%%edx),	%%edx"		"\n\t"
+
+	/*
+	 * Come here however we exited. Restore context from the
+	 * EXCEPTION_REGISTRATION in case the stack is unbalanced.
+	 */
+
+	"2:"					"\t"
+	"movl	0xc(%%edx),	%%esp"		"\n\t"
+	"movl	0x8(%%edx),	%%ebp"		"\n\t"
+	"movl	0x0(%%edx),	%%eax"		"\n\t"
+	"movl	%%eax,		%%fs:0"		"\n\t"
+
+	:
+	/* No outputs */
+	:
+	[registration]	"m"	(registration),
+	[ok]		"i"	(TCL_OK),
+	[error]		"i"	(TCL_ERROR),
+	[size]		"i"	(TCL_WIN_STACK_THRESHOLD)
+	:
+	"%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory"
+	);
+    retval = (registration.status == TCL_OK);
+
+#else /* !HAVE_NO_SEH */
     __try {
-#endif /* HAVE_NO_SEH */
 	alloca(TCL_WIN_STACK_THRESHOLD);
 	retval = 1;
-#ifdef HAVE_NO_SEH
-    __asm__ __volatile__ (
-            "jmp   checkstackspace_pop" "\n"
-            "checkstackspace_reentry:" "\n\t"
-            "movl  _ESP, %esp" "\n\t"
-            "movl  _EBP, %ebp");
-
-    __asm__ __volatile__ (
-            "checkstackspace_pop:" "\n\t"
-            "mov   (%esp), %eax" "\n\t"
-            "mov   %eax, %fs:0" "\n\t"
-            "add   $8, %esp");
-#else
     } __except (EXCEPTION_EXECUTE_HANDLER) {}
 #endif /* HAVE_NO_SEH */
 
-    /*
-     * Avoid using control flow statements in the SEH guarded block!
-     */
     return retval;
 }
-#ifdef HAVE_NO_SEH
-static
-__attribute__ ((cdecl,used))
-EXCEPTION_DISPOSITION
-_except_checkstackspace_handler(
-    struct _EXCEPTION_RECORD *ExceptionRecord,
-    void *EstablisherFrame,
-    struct _CONTEXT *ContextRecord,
-    void *DispatcherContext)
-{
-    __asm__ __volatile__ (
-            "jmp checkstackspace_reentry");
-    return 0; /* Function does not return */
-}
-#endif /* HAVE_NO_SEH */
+
 \f
 /*
  *----------------------------------------------------------------------

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

* Re: MinGW patches for Insight
  2008-02-08 23:17     ` Dave Murphy
@ 2008-02-08 23:34       ` Mike Frysinger
  2008-02-09  0:03       ` Keith Seitz
  1 sibling, 0 replies; 12+ messages in thread
From: Mike Frysinger @ 2008-02-08 23:34 UTC (permalink / raw)
  To: Dave Murphy; +Cc: insight

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

On Friday 08 February 2008, Dave Murphy wrote:
> Mike Frysinger wrote:
> > On Friday 08 February 2008, Dave Murphy wrote:
> >  
> >
> >> I'm still not sure how best to format the changelog entries. Should I be
> >> sending a patchset for each directory where changes are made?
> >>    
> >
> > you do it based upon the ChangeLog files that already exist.  look at the
> > file you change, and then walk up directories until you hit the first
> > ChangeLog file.
> >  
>
> Thanks for the advice Mike, much appreciated.
>
> Updated patch with suggested changes attached. I've submitted the ppc
> sim patch to the gdb patches list instead.

now if only they'd get merged ... ive been using out of tree mingw patches for 
a while because all the ones posted to the list receive no response :(

> Dave
> insight-mingw.patch
>   2008-02-07  Dave Murphy  <davem@devkitpro.org>
>
>         * configure.ac :set tcl configdir to win under mingw
>         * configure : regenerate

no space after the file name and before the colon.  the message after the 
colon tends to be a proper english sentence.  so here it'd read:
	* configure.ac: Set tcl configdir to win under mingw.
	* configure: Regenerate.
-mike

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 827 bytes --]

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

* Re: MinGW patches for Insight
  2008-02-08 23:17     ` Dave Murphy
  2008-02-08 23:34       ` Mike Frysinger
@ 2008-02-09  0:03       ` Keith Seitz
  2008-02-09  1:24         ` Keith Seitz
  2008-02-09  1:51         ` Dave Murphy
  1 sibling, 2 replies; 12+ messages in thread
From: Keith Seitz @ 2008-02-09  0:03 UTC (permalink / raw)
  To: Dave Murphy; +Cc: Mike Frysinger, insight

Dave Murphy wrote:

> Thanks for the advice Mike, much appreciated.

Yes, ditto, Mike, for taking a peek at this for me, too. It helps to 
have extra eyeballs on this.

> Updated patch with suggested changes attached. I've submitted the ppc 
> sim patch to the gdb patches list instead.

I noticed that you're having to distinguish between windows and mingw in 
a lot of places... I think I'm going to have to whack the use of 
"tcl_platform(platform)" in favor of a procedure that returns "cygwin", 
"mingw", or "unix". If I check something in quickly, would you be 
adverse to updating your patch? Or I could wait until after this is all 
committed.

I don't see any problems with your changes to the insight code base. 
Your changes there (although numerous) are small/trivial enough that I'm 
going to forgo asking you to jump through the hoops of getting an 
assignment for Red Hat.

I'll also approve the changes to tcl/, but I'll have to take your word 
for it, since I don't have any way to test this. Hopefully a more 
cygwin-savvy developer out there will chime in with any comments.

I'm curious: have any of these Tcl mingw patches made their way 
upstream? Do they even care any more?

In any case, if your re-write your ChangeLog entries as Mike suggests, 
I'll see about applying your patches and getting them committed.

Thanks!
Keith

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

* Re: MinGW patches for Insight
  2008-02-09  0:03       ` Keith Seitz
@ 2008-02-09  1:24         ` Keith Seitz
  2008-02-09  1:55           ` Dave Murphy
  2008-02-09  2:32           ` Dave Murphy
  2008-02-09  1:51         ` Dave Murphy
  1 sibling, 2 replies; 12+ messages in thread
From: Keith Seitz @ 2008-02-09  1:24 UTC (permalink / raw)
  To: Dave Murphy; +Cc: insight

Keith Seitz wrote:
> If I check something in quickly, would you be 
> adverse to updating your patch? Or I could wait until after this is all 
> committed.

I've committed a change which does this. Instead of adding the "[llength 
[info commands ...]]" stuff everywhere, you can simply check if 
gdbtk_platform(os) is cygwin or mingw. [gdbtk_platform(platform) will 
still be "windows".]

Keith

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

* Re: MinGW patches for Insight
  2008-02-09  0:03       ` Keith Seitz
  2008-02-09  1:24         ` Keith Seitz
@ 2008-02-09  1:51         ` Dave Murphy
  1 sibling, 0 replies; 12+ messages in thread
From: Dave Murphy @ 2008-02-09  1:51 UTC (permalink / raw)
  To: Keith Seitz; +Cc: Mike Frysinger, insight

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

Keith Seitz wrote:
> I noticed that you're having to distinguish between windows and mingw 
> in a lot of places... I think I'm going to have to whack the use of 
> "tcl_platform(platform)" in favor of a procedure that returns 
> "cygwin", "mingw", or "unix". If I check something in quickly, would 
> you be adverse to updating your patch? Or I could wait until after 
> this is all committed.
>

I'm not sure that would help - I had considered just stubbing 
ide_cygwin_path on mingw so there was no path conversion but back in 
this message - http://sourceware.org/ml/insight/2007-q2/msg00112.html 
Chris Faylor said that cygwin uses the /dev/comN format for serial 
ports. With a windows native binary produced by mingw we can only access 
the COM form. Checking for the existence of the ide_cyqwin_path command 
gives us a handy way to differentiate when setting up the port list. I'm 
not sure but I think splitting "windows" into "mingw" & "cygwin" would 
complicate things a little more, unless I misunderstood what you're 
suggesting.

> I don't see any problems with your changes to the insight code base. 
> Your changes there (although numerous) are small/trivial enough that 
> I'm going to forgo asking you to jump through the hoops of getting an 
> assignment for Red Hat.
>
> I'll also approve the changes to tcl/, but I'll have to take your word 
> for it, since I don't have any way to test this. Hopefully a more 
> cygwin-savvy developer out there will chime in with any comments.
>
> I'm curious: have any of these Tcl mingw patches made their way 
> upstream? Do they even care any more?

The latest Tcl/Tk sources build OOB for mingw, I just took enough to fix 
the problem - the hint originally came from Andrew Stubbs when he posted 
the patch back at http://sourceware.org/ml/insight/2005-q3/msg00056.html

The relevant file is 
http://tcl.cvs.sourceforge.net/tcl/tcl/win/tclWin32Dll.c?revision=1.49&view=markup 
(SF changed their cvs host naming since Andrew posted that message)

Most of the Tcl patches are in the gdbtk library for Insight relating to 
path conversion.

Hopefully the attached patch & changelog is suitable, thanks again for 
all the advice.

Dave

[-- Attachment #2: insight-mingw.patch --]
[-- Type: text/plain, Size: 16067 bytes --]


2008-02-07  Dave Murphy  <davem@devkitpro.org>

	* configure.ac: set tcl configdir to win under mingw
	* configure: regenerate


gdb/gdbtk/generic/

2008-02-07  Dave Murphy  <davem@devkitpro.org>

	* gdbtk-cmds.c: guard <sys/ioctl.h> with HAVE_SYS_IOCTL_H
	* gdbtk-hooks.c: ditto
	* gdbtk.c: ditto
	* gdbtk-interp.c: include <windows.h> under mingw32
	(gdbtk_start_timer, gdbtk_stop_timer): remove timer calls under mingw
	(gdbtk_init): include windows specific commands under mingw without cygwin
	path commands

gdb/gdbtk/library/

2008-02-07  Dave Murphy  <davem@devkitpro.org>

	* download.itb (Download::download_it): check ide_cygwin_path exists
	before using on windows 
	* interface.tcl (_open_file): ditto
	* prefs.tcl (pref_read): ditto
	* session.tcl ( _exe_name): ditto
	* srctextwin.itb 
	(SrcTextWin::_mtime_changed, SrcTextWin::LoadFromCache): ditto
	* targetselection.itb (TargetSelection::default_port): default to
	/dev/com1 under cygwin, COM1 under mingw
	(TargetSelection::port_list): use /dev/com under cygwin, COM under mingw

tcl/win

2008-02-07  Dave Murphy  <davem@devkitpro.org>

	* tclWin32Dll.c (TclpCheckStackSpace) : backport EXCEPTION_REGISTRATION code
	from TCL mainline


Index: gdb/configure.ac
===================================================================
RCS file: /cvs/src/src/gdb/configure.ac,v
retrieving revision 1.64
diff -u -r1.64 configure.ac
--- gdb/configure.ac	13 Jan 2008 12:23:05 -0000	1.64
+++ gdb/configure.ac	8 Feb 2008 20:41:52 -0000
@@ -1445,7 +1445,7 @@
 AC_SUBST(WIN32LDAPP)
 
 case "${host}" in
-*-*-cygwin*)
+*-*-cygwin* | *-*-mingw* )
     configdir="win"
     ;;
 *)
Index: gdb/gdbtk/generic/gdbtk-cmds.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/generic/gdbtk-cmds.c,v
retrieving revision 1.97
diff -u -r1.97 gdbtk-cmds.c
--- gdb/gdbtk/generic/gdbtk-cmds.c	21 Jun 2007 15:18:51 -0000	1.97
+++ gdb/gdbtk/generic/gdbtk-cmds.c	7 Feb 2008 03:43:06 -0000
@@ -57,7 +57,9 @@
 
 #include <signal.h>
 #include <fcntl.h>
+#ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
+#endif
 #include <sys/time.h>
 #include <sys/stat.h>
 
Index: gdb/gdbtk/generic/gdbtk-hooks.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/generic/gdbtk-hooks.c,v
retrieving revision 1.41
diff -u -r1.41 gdbtk-hooks.c
--- gdb/gdbtk/generic/gdbtk-hooks.c	23 Dec 2005 18:23:16 -0000	1.41
+++ gdb/gdbtk/generic/gdbtk-hooks.c	7 Feb 2008 03:43:19 -0000
@@ -51,7 +51,9 @@
 
 #include <signal.h>
 #include <fcntl.h>
+#ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
+#endif
 #include <sys/time.h>
 
 #include "gdb_string.h"
Index: gdb/gdbtk/generic/gdbtk-interp.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/generic/gdbtk-interp.c,v
retrieving revision 1.8
diff -u -r1.8 gdbtk-interp.c
--- gdb/gdbtk/generic/gdbtk-interp.c	23 Dec 2005 18:23:16 -0000	1.8
+++ gdb/gdbtk/generic/gdbtk-interp.c	8 Feb 2008 20:46:44 -0000
@@ -34,6 +34,12 @@
 #include "tk.h"
 #include "gdbtk.h"
 
+#ifdef __MINGW32__
+# define WIN32_LEAN_AND_MEAN
+# include <windows.h>
+#endif
+
+
 static void gdbtk_command_loop (void);
 static void hack_disable_interpreter_exec (char *, int);
 
Index: gdb/gdbtk/generic/gdbtk.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/generic/gdbtk.c,v
retrieving revision 1.45
diff -u -r1.45 gdbtk.c
--- gdb/gdbtk/generic/gdbtk.c	1 Dec 2006 02:09:24 -0000	1.45
+++ gdb/gdbtk/generic/gdbtk.c	7 Feb 2008 06:23:48 -0000
@@ -49,7 +49,9 @@
 
 #include <fcntl.h>
 #include <sys/stat.h>
+#ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
+#endif
 #include <sys/time.h>
 #include <signal.h>
 
@@ -63,6 +65,7 @@
 
 extern void _initialize_gdbtk (void);
 
+#ifndef __MINGW32__
 /* For unix natives, we use a timer to periodically keep the gui alive.
    See comments before x_event. */
 static sigset_t nullsigmask;
@@ -74,6 +77,7 @@
 {
   x_event (signo);
 }
+#endif
 
 /*
  * This variable controls the interaction with an external editor.
@@ -262,6 +266,7 @@
     {
       /* first time called, set up all the structs */
       first = 0;
+#ifndef __MINGW32__
       sigemptyset (&nullsigmask);
 
       act1.sa_handler = x_event_wrapper;
@@ -281,14 +286,17 @@
       it_off.it_interval.tv_usec = 0;
       it_off.it_value.tv_sec = 0;
       it_off.it_value.tv_usec = 0;
+#endif
     }
 
   if (target_should_use_timer (&current_target))
     {
       if (!gdbtk_timer_going)
 	{
+#ifndef __MINGW32__
 	  sigaction (SIGALRM, &act1, NULL);
 	  setitimer (ITIMER_REAL, &it_on, NULL);
+#endif
 	  gdbtk_timer_going = 1;
 	}
     }
@@ -302,8 +310,10 @@
   if (gdbtk_timer_going)
     {
       gdbtk_timer_going = 0;
+#ifndef __MINGW32__
       setitimer (ITIMER_REAL, &it_off, NULL);
       sigaction (SIGALRM, &act2, NULL);
+#endif
     }
   return;
 }
@@ -510,7 +520,7 @@
    * These are the commands to do some Windows Specific stuff...
    */
 
-#ifdef __CYGWIN32__
+#ifdef __WIN32__
   if (ide_create_messagebox_command (gdbtk_interp) != TCL_OK)
     error ("messagebox command initialization failed");
   /* On Windows, create a sizebox widget command */
@@ -522,6 +532,8 @@
     error ("windows print code initialization failed");
   if (ide_create_win_grab_command (gdbtk_interp) != TCL_OK)
     error ("grab support command initialization failed");
+#endif
+#ifdef __CYGWIN32__
   /* Path conversion functions.  */
   if (ide_create_cygwin_path_command (gdbtk_interp) != TCL_OK)
     error ("cygwin path command initialization failed");
Index: gdb/gdbtk/library/download.itb
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/library/download.itb,v
retrieving revision 1.11
diff -u -r1.11 download.itb
--- gdb/gdbtk/library/download.itb	23 Dec 2005 18:26:50 -0000	1.11
+++ gdb/gdbtk/library/download.itb	6 Feb 2008 04:30:59 -0000
@@ -207,7 +207,7 @@
     }
   }
 
-  if {[string compare $tcl_platform(platform) "windows"] == 0} {
+  if {[string compare $tcl_platform(platform) "windows"] == 0 && [llength [info commands ide_cygwin_path]]} {
     set f [ide_cygwin_path to_win32 $gdb_exe_name]
   } else {
     set f $gdb_exe_name
Index: gdb/gdbtk/library/interface.tcl
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/library/interface.tcl,v
retrieving revision 1.57
diff -u -r1.57 interface.tcl
--- gdb/gdbtk/library/interface.tcl	23 Dec 2005 18:26:50 -0000	1.57
+++ gdb/gdbtk/library/interface.tcl	6 Feb 2008 04:32:56 -0000
@@ -962,7 +962,7 @@
   }
   # Add the base dir for this file to the source search path.
   set root [file dirname $file]
-  if {$tcl_platform(platform) == "windows"} {
+  if {$tcl_platform(platform) == "windows" && [llength [info commands ide_cygwin_path]]} {
     set root [ide_cygwin_path to_posix $root]
     set file [ide_cygwin_path to_posix $file]
   }
Index: gdb/gdbtk/library/prefs.tcl
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/library/prefs.tcl,v
retrieving revision 1.34
diff -u -r1.34 prefs.tcl
--- gdb/gdbtk/library/prefs.tcl	19 Sep 2006 18:39:38 -0000	1.34
+++ gdb/gdbtk/library/prefs.tcl	6 Feb 2008 04:33:48 -0000
@@ -35,7 +35,7 @@
   global tcl_platform
 
   if {[info exists env(HOME)]} {
-    if {$tcl_platform(platform) == "windows"} {
+    if {$tcl_platform(platform) == "windows"  && [llength [info commands ide_cygwin_path]]} {
       set home [ide_cygwin_path to_win32 $env(HOME)]
     } else {
       set home $env(HOME)
Index: gdb/gdbtk/library/session.tcl
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/library/session.tcl,v
retrieving revision 1.16
diff -u -r1.16 session.tcl
--- gdb/gdbtk/library/session.tcl	23 Dec 2005 18:26:50 -0000	1.16
+++ gdb/gdbtk/library/session.tcl	7 Feb 2008 01:59:00 -0000
@@ -21,7 +21,7 @@
     global tcl_platform
 
     # Get real directory.
-    if {[string compare $tcl_platform(platform) "windows"] == 0} {
+    if {[string compare $tcl_platform(platform) "windows"] == 0 && [llength [info commands ide_cygwin_path]]} {
       set path [ide_cygwin_path to_win32 $path]
     }
     set save [pwd]
Index: gdb/gdbtk/library/srctextwin.itb
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/library/srctextwin.itb,v
retrieving revision 1.42
diff -u -r1.42 srctextwin.itb
--- gdb/gdbtk/library/srctextwin.itb	23 Dec 2005 18:26:50 -0000	1.42
+++ gdb/gdbtk/library/srctextwin.itb	7 Feb 2008 02:04:47 -0000
@@ -891,7 +891,7 @@
   } elseif {$f == ""} {
     set r 1
   } else {
-    if {[string compare $tcl_platform(platform) "windows"] == 0} {
+    if {[string compare $tcl_platform(platform) "windows"] == 0 && [llength [info commands ide_cygwin_path]]} {
       set f [ide_cygwin_path to_win32 $f]
     }
     if {[catch {file mtime $f} mtime]} {
@@ -2715,7 +2715,7 @@
     # out.
 
     if {$loadingSource} {
-      if {[string compare $tcl_platform(platform) "windows"] == 0} {
+      if {[string compare $tcl_platform(platform) "windows"] == 0 && [llength [info commands ide_cygwin_path]]} {
         set f [ide_cygwin_path to_win32 $name]
       } else {
         set f $name
Index: gdb/gdbtk/library/targetselection.itb
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/library/targetselection.itb,v
retrieving revision 1.20
diff -u -r1.20 targetselection.itb
--- gdb/gdbtk/library/targetselection.itb	1 Dec 2006 01:07:55 -0000	1.20
+++ gdb/gdbtk/library/targetselection.itb	7 Feb 2008 00:17:37 -0000
@@ -280,7 +280,13 @@
 itcl::body TargetSelection::default_port {} {
   global tcl_platform
   switch -regexp $tcl_platform(os) {
-    Windows { set port com1 }
+    Windows {
+      if { [llength [info commands ide_cygwin_path]] } {
+        set port "/dev/com1"
+      } else {
+        set port "COM1"
+      }
+    }
     Linux   { set port /dev/ttyS0 }
     SunOS   { set port /dev/ttya }
     AIX     { set port /dev/foo1 }
@@ -873,6 +879,11 @@
 #  METHOD:  port_list - return a list of valid ports for Windows
 # ------------------------------------------------------------------
 itcl::body TargetSelection::port_list {} {
+  if { [llength [info commands ide_cygwin_path]] } {
+    set device "/dev/com"
+  } else {
+    set device "COM"
+  }
   set plist ""
   # Scan com1 - com8 trying to open each one.
   # If permission is denied that means it is in use,
@@ -885,7 +896,7 @@
       # Failed.  Find out why.
       if {[string first "permission denied" $msg] != -1} {
 	# Port is there, but busy right now. That's OK.
-	lappend plist /dev/com$i
+	lappend plist $device$i
       } elseif {$i > 4} {
 	# if we've scanned the first 4 ports, then quit when we find no more 
 	set quit 1
@@ -893,7 +904,7 @@
     } else {
       # We got it.  Now close it and add to list.
       close $fd
-      lappend plist /dev/com$i
+      lappend plist $device$i
     }
   }
   return $plist
Index: tcl/win/tclWin32Dll.c
===================================================================
RCS file: /cvs/src/src/tcl/win/tclWin32Dll.c,v
retrieving revision 1.11
diff -u -r1.11 tclWin32Dll.c
--- tcl/win/tclWin32Dll.c	1 Dec 2006 20:35:55 -0000	1.11
+++ tcl/win/tclWin32Dll.c	7 Feb 2008 05:54:10 -0000
@@ -41,9 +41,21 @@
 static int platformId;		/* Running under NT, or 95/98? */
 
 #ifdef HAVE_NO_SEH
-static void *ESP;
-static void *EBP;
-#endif /* HAVE_NO_SEH */
+/*
+ * Unlike Borland and Microsoft, we don't register exception handlers by
+ * pushing registration records onto the runtime stack. Instead, we register
+ * them by creating an EXCEPTION_REGISTRATION within the activation record.
+ */
+
+typedef struct EXCEPTION_REGISTRATION {
+    struct EXCEPTION_REGISTRATION *link;
+    EXCEPTION_DISPOSITION (*handler)(
+	    struct _EXCEPTION_RECORD*, void*, struct _CONTEXT*, void*);
+    void *ebp;
+    void *esp;
+    int status;
+} EXCEPTION_REGISTRATION;
+#endif
 
 /*
  * The following function tables are used to dispatch to either the
@@ -358,65 +370,102 @@
 int
 TclpCheckStackSpace()
 {
+
+#ifdef HAVE_NO_SEH
+    EXCEPTION_REGISTRATION registration;
+#endif
     int retval = 0;
 
     /*
-     * We can recurse only if there is at least TCL_WIN_STACK_THRESHOLD
-     * bytes of stack space left.  alloca() is cheap on windows; basically
-     * it just subtracts from the stack pointer causing the OS to throw an
-     * exception if the stack pointer is set below the bottom of the stack.
+     * We can recurse only if there is at least TCL_WIN_STACK_THRESHOLD bytes
+     * of stack space left. alloca() is cheap on windows; basically it just
+     * subtracts from the stack pointer causing the OS to throw an exception
+     * if the stack pointer is set below the bottom of the stack.
      */
 
 #ifdef HAVE_NO_SEH
     __asm__ __volatile__ (
-            "movl  %esp, _ESP" "\n\t"
-            "movl  %ebp, _EBP");
 
-    __asm__ __volatile__ (
-            "pushl $__except_checkstackspace_handler" "\n\t"
-            "pushl %fs:0" "\n\t"
-            "mov   %esp, %fs:0");
-#else
+	/*
+	 * Construct an EXCEPTION_REGISTRATION to protect the call to __alloca
+	 */
+
+	"leal	%[registration], %%edx"		"\n\t"
+	"movl	%%fs:0,		%%eax"		"\n\t"
+	"movl	%%eax,		0x0(%%edx)"	"\n\t" /* link */
+	"leal	1f,		%%eax"		"\n\t"
+	"movl	%%eax,		0x4(%%edx)"	"\n\t" /* handler */
+	"movl	%%ebp,		0x8(%%edx)"	"\n\t" /* ebp */
+	"movl	%%esp,		0xc(%%edx)"	"\n\t" /* esp */
+	"movl	%[error],	0x10(%%edx)"	"\n\t" /* status */
+
+	/*
+	 * Link the EXCEPTION_REGISTRATION on the chain
+	 */
+
+	"movl	%%edx,		%%fs:0"		"\n\t"
+
+	/*
+	 * Attempt a call to __alloca, to determine whether there's sufficient
+	 * memory to be had.
+	 */
+
+	"movl	%[size],	%%eax"		"\n\t"
+	"pushl	%%eax"				"\n\t"
+	"call	__alloca"			"\n\t"
+
+	/*
+	 * Come here on a normal exit. Recover the EXCEPTION_REGISTRATION and
+	 * store a TCL_OK status
+	 */
+
+	"movl	%%fs:0,		%%edx"		"\n\t"
+	"movl	%[ok],		%%eax"		"\n\t"
+	"movl	%%eax,		0x10(%%edx)"	"\n\t"
+	"jmp	2f"				"\n"
+
+	/*
+	 * Come here on an exception. Get the EXCEPTION_REGISTRATION that we
+	 * previously put on the chain.
+	 */
+
+	"1:"					"\t"
+	"movl	%%fs:0,		%%edx"		"\n\t"
+	"movl	0x8(%%edx),	%%edx"		"\n\t"
+
+	/*
+	 * Come here however we exited. Restore context from the
+	 * EXCEPTION_REGISTRATION in case the stack is unbalanced.
+	 */
+
+	"2:"					"\t"
+	"movl	0xc(%%edx),	%%esp"		"\n\t"
+	"movl	0x8(%%edx),	%%ebp"		"\n\t"
+	"movl	0x0(%%edx),	%%eax"		"\n\t"
+	"movl	%%eax,		%%fs:0"		"\n\t"
+
+	:
+	/* No outputs */
+	:
+	[registration]	"m"	(registration),
+	[ok]		"i"	(TCL_OK),
+	[error]		"i"	(TCL_ERROR),
+	[size]		"i"	(TCL_WIN_STACK_THRESHOLD)
+	:
+	"%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory"
+	);
+    retval = (registration.status == TCL_OK);
+
+#else /* !HAVE_NO_SEH */
     __try {
-#endif /* HAVE_NO_SEH */
 	alloca(TCL_WIN_STACK_THRESHOLD);
 	retval = 1;
-#ifdef HAVE_NO_SEH
-    __asm__ __volatile__ (
-            "jmp   checkstackspace_pop" "\n"
-            "checkstackspace_reentry:" "\n\t"
-            "movl  _ESP, %esp" "\n\t"
-            "movl  _EBP, %ebp");
-
-    __asm__ __volatile__ (
-            "checkstackspace_pop:" "\n\t"
-            "mov   (%esp), %eax" "\n\t"
-            "mov   %eax, %fs:0" "\n\t"
-            "add   $8, %esp");
-#else
     } __except (EXCEPTION_EXECUTE_HANDLER) {}
 #endif /* HAVE_NO_SEH */
 
-    /*
-     * Avoid using control flow statements in the SEH guarded block!
-     */
     return retval;
 }
-#ifdef HAVE_NO_SEH
-static
-__attribute__ ((cdecl,used))
-EXCEPTION_DISPOSITION
-_except_checkstackspace_handler(
-    struct _EXCEPTION_RECORD *ExceptionRecord,
-    void *EstablisherFrame,
-    struct _CONTEXT *ContextRecord,
-    void *DispatcherContext)
-{
-    __asm__ __volatile__ (
-            "jmp checkstackspace_reentry");
-    return 0; /* Function does not return */
-}
-#endif /* HAVE_NO_SEH */
+
 \f
 /*
  *----------------------------------------------------------------------

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

* Re: MinGW patches for Insight
  2008-02-09  1:24         ` Keith Seitz
@ 2008-02-09  1:55           ` Dave Murphy
  2008-02-09  2:32           ` Dave Murphy
  1 sibling, 0 replies; 12+ messages in thread
From: Dave Murphy @ 2008-02-09  1:55 UTC (permalink / raw)
  To: Keith Seitz; +Cc: insight

Keith Seitz wrote:
> I've committed a change which does this. Instead of adding the 
> "[llength [info commands ...]]" stuff everywhere, you can simply check 
> if gdbtk_platform(os) is cygwin or mingw. [gdbtk_platform(platform) 
> will still be "windows".]
>

Whoops, I just sent another update of the patchset without looking at 
the list. I'll update & have a look now.

Dave

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

* Re: MinGW patches for Insight
  2008-02-09  1:24         ` Keith Seitz
  2008-02-09  1:55           ` Dave Murphy
@ 2008-02-09  2:32           ` Dave Murphy
  2008-03-03 23:28             ` Keith Seitz
  1 sibling, 1 reply; 12+ messages in thread
From: Dave Murphy @ 2008-02-09  2:32 UTC (permalink / raw)
  To: Keith Seitz; +Cc: insight

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

Keith Seitz wrote:
> Keith Seitz wrote:
>> If I check something in quickly, would you be adverse to updating your 
>> patch? Or I could wait until after this is all committed.
> 
> I've committed a change which does this. Instead of adding the "[llength 
> [info commands ...]]" stuff everywhere, you can simply check if 
> gdbtk_platform(os) is cygwin or mingw. [gdbtk_platform(platform) will 
> still be "windows".]
> 



I did misunderstand what you meant with cygwin/mingw, that's excellent 
Keith, many many thanks.

My updated patchset is attached, just shout if you need anything else 
changed.


Dave

[-- Attachment #2: insight-mingw.patch --]
[-- Type: text/plain, Size: 14037 bytes --]


2008-02-09  Dave Murphy  <davem@devkitpro.org>

	* configure.ac: set tcl configdir to win under mingw
	* configure: regenerate


gdb/gdbtk/generic/

2008-02-09  Dave Murphy  <davem@devkitpro.org>

	* gdbtk-cmds.c: guard <sys/ioctl.h> with HAVE_SYS_IOCTL_H
	* gdbtk-hooks.c: ditto
	* gdbtk.c: ditto
	* gdbtk-interp.c: include <windows.h> under mingw32
	(gdbtk_start_timer, gdbtk_stop_timer): remove timer calls under mingw
	(gdbtk_init): include windows specific commands under mingw without cygwin
	path commands

gdb/gdbtk/library/

2008-02-09  Dave Murphy  <davem@devkitpro.org>

	* download.itb (Download::download_it): only use ide_cygwin_path to_win32 on cygwin
	* interface.tcl (_open_file): ditto
	* prefs.tcl (pref_read): ditto
	* targetselection.itb (TargetSelection::default_port): default to
	/dev/com1 under cygwin, COM1 under mingw
	(TargetSelection::port_list): use /dev/com under cygwin, COM under mingw

tcl/win

2008-02-09  Dave Murphy  <davem@devkitpro.org>

	* tclWin32Dll.c (TclpCheckStackSpace) : backport EXCEPTION_REGISTRATION code
	from TCL mainline

Index: gdb/configure.ac
===================================================================
RCS file: /cvs/src/src/gdb/configure.ac,v
retrieving revision 1.64
diff -u -r1.64 configure.ac
--- gdb/configure.ac	13 Jan 2008 12:23:05 -0000	1.64
+++ gdb/configure.ac	8 Feb 2008 20:41:52 -0000
@@ -1445,7 +1445,7 @@
 AC_SUBST(WIN32LDAPP)
 
 case "${host}" in
-*-*-cygwin*)
+*-*-cygwin* | *-*-mingw* )
     configdir="win"
     ;;
 *)
Index: gdb/gdbtk/generic/gdbtk-cmds.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/generic/gdbtk-cmds.c,v
retrieving revision 1.97
diff -u -r1.97 gdbtk-cmds.c
--- gdb/gdbtk/generic/gdbtk-cmds.c	21 Jun 2007 15:18:51 -0000	1.97
+++ gdb/gdbtk/generic/gdbtk-cmds.c	7 Feb 2008 03:43:06 -0000
@@ -57,7 +57,9 @@
 
 #include <signal.h>
 #include <fcntl.h>
+#ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
+#endif
 #include <sys/time.h>
 #include <sys/stat.h>
 
Index: gdb/gdbtk/generic/gdbtk-hooks.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/generic/gdbtk-hooks.c,v
retrieving revision 1.41
diff -u -r1.41 gdbtk-hooks.c
--- gdb/gdbtk/generic/gdbtk-hooks.c	23 Dec 2005 18:23:16 -0000	1.41
+++ gdb/gdbtk/generic/gdbtk-hooks.c	7 Feb 2008 03:43:19 -0000
@@ -51,7 +51,9 @@
 
 #include <signal.h>
 #include <fcntl.h>
+#ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
+#endif
 #include <sys/time.h>
 
 #include "gdb_string.h"
Index: gdb/gdbtk/generic/gdbtk-interp.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/generic/gdbtk-interp.c,v
retrieving revision 1.8
diff -u -r1.8 gdbtk-interp.c
--- gdb/gdbtk/generic/gdbtk-interp.c	23 Dec 2005 18:23:16 -0000	1.8
+++ gdb/gdbtk/generic/gdbtk-interp.c	8 Feb 2008 20:46:44 -0000
@@ -34,6 +34,12 @@
 #include "tk.h"
 #include "gdbtk.h"
 
+#ifdef __MINGW32__
+# define WIN32_LEAN_AND_MEAN
+# include <windows.h>
+#endif
+
+
 static void gdbtk_command_loop (void);
 static void hack_disable_interpreter_exec (char *, int);
 
Index: gdb/gdbtk/generic/gdbtk.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/generic/gdbtk.c,v
retrieving revision 1.45
diff -u -r1.45 gdbtk.c
--- gdb/gdbtk/generic/gdbtk.c	1 Dec 2006 02:09:24 -0000	1.45
+++ gdb/gdbtk/generic/gdbtk.c	7 Feb 2008 06:23:48 -0000
@@ -49,7 +49,9 @@
 
 #include <fcntl.h>
 #include <sys/stat.h>
+#ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
+#endif
 #include <sys/time.h>
 #include <signal.h>
 
@@ -63,6 +65,7 @@
 
 extern void _initialize_gdbtk (void);
 
+#ifndef __MINGW32__
 /* For unix natives, we use a timer to periodically keep the gui alive.
    See comments before x_event. */
 static sigset_t nullsigmask;
@@ -74,6 +77,7 @@
 {
   x_event (signo);
 }
+#endif
 
 /*
  * This variable controls the interaction with an external editor.
@@ -262,6 +266,7 @@
     {
       /* first time called, set up all the structs */
       first = 0;
+#ifndef __MINGW32__
       sigemptyset (&nullsigmask);
 
       act1.sa_handler = x_event_wrapper;
@@ -281,14 +286,17 @@
       it_off.it_interval.tv_usec = 0;
       it_off.it_value.tv_sec = 0;
       it_off.it_value.tv_usec = 0;
+#endif
     }
 
   if (target_should_use_timer (&current_target))
     {
       if (!gdbtk_timer_going)
 	{
+#ifndef __MINGW32__
 	  sigaction (SIGALRM, &act1, NULL);
 	  setitimer (ITIMER_REAL, &it_on, NULL);
+#endif
 	  gdbtk_timer_going = 1;
 	}
     }
@@ -302,8 +310,10 @@
   if (gdbtk_timer_going)
     {
       gdbtk_timer_going = 0;
+#ifndef __MINGW32__
       setitimer (ITIMER_REAL, &it_off, NULL);
       sigaction (SIGALRM, &act2, NULL);
+#endif
     }
   return;
 }
@@ -510,7 +520,7 @@
    * These are the commands to do some Windows Specific stuff...
    */
 
-#ifdef __CYGWIN32__
+#ifdef __WIN32__
   if (ide_create_messagebox_command (gdbtk_interp) != TCL_OK)
     error ("messagebox command initialization failed");
   /* On Windows, create a sizebox widget command */
@@ -522,6 +532,8 @@
     error ("windows print code initialization failed");
   if (ide_create_win_grab_command (gdbtk_interp) != TCL_OK)
     error ("grab support command initialization failed");
+#endif
+#ifdef __CYGWIN32__
   /* Path conversion functions.  */
   if (ide_create_cygwin_path_command (gdbtk_interp) != TCL_OK)
     error ("cygwin path command initialization failed");
Index: gdb/gdbtk/library/download.itb
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/library/download.itb,v
retrieving revision 1.12
diff -u -r1.12 download.itb
--- gdb/gdbtk/library/download.itb	9 Feb 2008 01:23:42 -0000	1.12
+++ gdb/gdbtk/library/download.itb	9 Feb 2008 02:05:33 -0000
@@ -206,7 +206,7 @@
     }
   }
 
-  if {[string compare $gdbtk_platform(platform) "windows"] == 0} {
+  if {[string compare $gdbtk_platform(os) "cygwin"] == 0} {
     set f [ide_cygwin_path to_win32 $gdb_exe_name]
   } else {
     set f $gdb_exe_name
Index: gdb/gdbtk/library/interface.tcl
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/library/interface.tcl,v
retrieving revision 1.58
diff -u -r1.58 interface.tcl
--- gdb/gdbtk/library/interface.tcl	9 Feb 2008 01:23:42 -0000	1.58
+++ gdb/gdbtk/library/interface.tcl	9 Feb 2008 02:05:55 -0000
@@ -962,7 +962,7 @@
   }
   # Add the base dir for this file to the source search path.
   set root [file dirname $file]
-  if {$gdbtk_platform(platform) == "windows"} {
+  if {$gdbtk_platform(os) == "cygwin"} {
     set root [ide_cygwin_path to_posix $root]
     set file [ide_cygwin_path to_posix $file]
   }
Index: gdb/gdbtk/library/prefs.tcl
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/library/prefs.tcl,v
retrieving revision 1.35
diff -u -r1.35 prefs.tcl
--- gdb/gdbtk/library/prefs.tcl	9 Feb 2008 01:23:42 -0000	1.35
+++ gdb/gdbtk/library/prefs.tcl	9 Feb 2008 02:06:28 -0000
@@ -35,7 +35,7 @@
   global gdbtk_platform
 
   if {[info exists env(HOME)]} {
-    if {$gdbtk_platform(platform) == "windows"} {
+    if {$gdbtk_platform(os) == "cygwin"} {
       set home [ide_cygwin_path to_win32 $env(HOME)]
     } else {
       set home $env(HOME)
Index: gdb/gdbtk/library/targetselection.itb
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/library/targetselection.itb,v
retrieving revision 1.21
diff -u -r1.21 targetselection.itb
--- gdb/gdbtk/library/targetselection.itb	9 Feb 2008 01:23:43 -0000	1.21
+++ gdb/gdbtk/library/targetselection.itb	9 Feb 2008 02:09:53 -0000
@@ -280,7 +280,8 @@
 itcl::body TargetSelection::default_port {} {
   global gdbtk_platform
   switch -regexp $gdbtk_platform(os) {
-    cygwin  { set port com1 }
+    cygwin  { set port /dev/com1 }
+    mingw   { set port COM1 }
     Linux   { set port /dev/ttyS0 }
     SunOS   { set port /dev/ttya }
     AIX     { set port /dev/foo1 }
@@ -873,6 +874,12 @@
 #  METHOD:  port_list - return a list of valid ports for Windows
 # ------------------------------------------------------------------
 itcl::body TargetSelection::port_list {} {
+  global gdbtk_platform
+  if {[string compare $gdbtk_platform(os) "cygwin"] == 0} {
+    set device "/dev/com"
+  } else {
+    set device "COM"
+  }
   set plist ""
   # Scan com1 - com8 trying to open each one.
   # If permission is denied that means it is in use,
@@ -885,7 +892,7 @@
       # Failed.  Find out why.
       if {[string first "permission denied" $msg] != -1} {
 	# Port is there, but busy right now. That's OK.
-	lappend plist /dev/com$i
+	lappend plist $device$i
       } elseif {$i > 4} {
 	# if we've scanned the first 4 ports, then quit when we find no more 
 	set quit 1
@@ -893,7 +900,7 @@
     } else {
       # We got it.  Now close it and add to list.
       close $fd
-      lappend plist /dev/com$i
+      lappend plist $device$i
     }
   }
   return $plist
Index: tcl/win/tclWin32Dll.c
===================================================================
RCS file: /cvs/src/src/tcl/win/tclWin32Dll.c,v
retrieving revision 1.11
diff -u -r1.11 tclWin32Dll.c
--- tcl/win/tclWin32Dll.c	1 Dec 2006 20:35:55 -0000	1.11
+++ tcl/win/tclWin32Dll.c	7 Feb 2008 05:54:10 -0000
@@ -41,9 +41,21 @@
 static int platformId;		/* Running under NT, or 95/98? */
 
 #ifdef HAVE_NO_SEH
-static void *ESP;
-static void *EBP;
-#endif /* HAVE_NO_SEH */
+/*
+ * Unlike Borland and Microsoft, we don't register exception handlers by
+ * pushing registration records onto the runtime stack. Instead, we register
+ * them by creating an EXCEPTION_REGISTRATION within the activation record.
+ */
+
+typedef struct EXCEPTION_REGISTRATION {
+    struct EXCEPTION_REGISTRATION *link;
+    EXCEPTION_DISPOSITION (*handler)(
+	    struct _EXCEPTION_RECORD*, void*, struct _CONTEXT*, void*);
+    void *ebp;
+    void *esp;
+    int status;
+} EXCEPTION_REGISTRATION;
+#endif
 
 /*
  * The following function tables are used to dispatch to either the
@@ -358,65 +370,102 @@
 int
 TclpCheckStackSpace()
 {
+
+#ifdef HAVE_NO_SEH
+    EXCEPTION_REGISTRATION registration;
+#endif
     int retval = 0;
 
     /*
-     * We can recurse only if there is at least TCL_WIN_STACK_THRESHOLD
-     * bytes of stack space left.  alloca() is cheap on windows; basically
-     * it just subtracts from the stack pointer causing the OS to throw an
-     * exception if the stack pointer is set below the bottom of the stack.
+     * We can recurse only if there is at least TCL_WIN_STACK_THRESHOLD bytes
+     * of stack space left. alloca() is cheap on windows; basically it just
+     * subtracts from the stack pointer causing the OS to throw an exception
+     * if the stack pointer is set below the bottom of the stack.
      */
 
 #ifdef HAVE_NO_SEH
     __asm__ __volatile__ (
-            "movl  %esp, _ESP" "\n\t"
-            "movl  %ebp, _EBP");
 
-    __asm__ __volatile__ (
-            "pushl $__except_checkstackspace_handler" "\n\t"
-            "pushl %fs:0" "\n\t"
-            "mov   %esp, %fs:0");
-#else
+	/*
+	 * Construct an EXCEPTION_REGISTRATION to protect the call to __alloca
+	 */
+
+	"leal	%[registration], %%edx"		"\n\t"
+	"movl	%%fs:0,		%%eax"		"\n\t"
+	"movl	%%eax,		0x0(%%edx)"	"\n\t" /* link */
+	"leal	1f,		%%eax"		"\n\t"
+	"movl	%%eax,		0x4(%%edx)"	"\n\t" /* handler */
+	"movl	%%ebp,		0x8(%%edx)"	"\n\t" /* ebp */
+	"movl	%%esp,		0xc(%%edx)"	"\n\t" /* esp */
+	"movl	%[error],	0x10(%%edx)"	"\n\t" /* status */
+
+	/*
+	 * Link the EXCEPTION_REGISTRATION on the chain
+	 */
+
+	"movl	%%edx,		%%fs:0"		"\n\t"
+
+	/*
+	 * Attempt a call to __alloca, to determine whether there's sufficient
+	 * memory to be had.
+	 */
+
+	"movl	%[size],	%%eax"		"\n\t"
+	"pushl	%%eax"				"\n\t"
+	"call	__alloca"			"\n\t"
+
+	/*
+	 * Come here on a normal exit. Recover the EXCEPTION_REGISTRATION and
+	 * store a TCL_OK status
+	 */
+
+	"movl	%%fs:0,		%%edx"		"\n\t"
+	"movl	%[ok],		%%eax"		"\n\t"
+	"movl	%%eax,		0x10(%%edx)"	"\n\t"
+	"jmp	2f"				"\n"
+
+	/*
+	 * Come here on an exception. Get the EXCEPTION_REGISTRATION that we
+	 * previously put on the chain.
+	 */
+
+	"1:"					"\t"
+	"movl	%%fs:0,		%%edx"		"\n\t"
+	"movl	0x8(%%edx),	%%edx"		"\n\t"
+
+	/*
+	 * Come here however we exited. Restore context from the
+	 * EXCEPTION_REGISTRATION in case the stack is unbalanced.
+	 */
+
+	"2:"					"\t"
+	"movl	0xc(%%edx),	%%esp"		"\n\t"
+	"movl	0x8(%%edx),	%%ebp"		"\n\t"
+	"movl	0x0(%%edx),	%%eax"		"\n\t"
+	"movl	%%eax,		%%fs:0"		"\n\t"
+
+	:
+	/* No outputs */
+	:
+	[registration]	"m"	(registration),
+	[ok]		"i"	(TCL_OK),
+	[error]		"i"	(TCL_ERROR),
+	[size]		"i"	(TCL_WIN_STACK_THRESHOLD)
+	:
+	"%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory"
+	);
+    retval = (registration.status == TCL_OK);
+
+#else /* !HAVE_NO_SEH */
     __try {
-#endif /* HAVE_NO_SEH */
 	alloca(TCL_WIN_STACK_THRESHOLD);
 	retval = 1;
-#ifdef HAVE_NO_SEH
-    __asm__ __volatile__ (
-            "jmp   checkstackspace_pop" "\n"
-            "checkstackspace_reentry:" "\n\t"
-            "movl  _ESP, %esp" "\n\t"
-            "movl  _EBP, %ebp");
-
-    __asm__ __volatile__ (
-            "checkstackspace_pop:" "\n\t"
-            "mov   (%esp), %eax" "\n\t"
-            "mov   %eax, %fs:0" "\n\t"
-            "add   $8, %esp");
-#else
     } __except (EXCEPTION_EXECUTE_HANDLER) {}
 #endif /* HAVE_NO_SEH */
 
-    /*
-     * Avoid using control flow statements in the SEH guarded block!
-     */
     return retval;
 }
-#ifdef HAVE_NO_SEH
-static
-__attribute__ ((cdecl,used))
-EXCEPTION_DISPOSITION
-_except_checkstackspace_handler(
-    struct _EXCEPTION_RECORD *ExceptionRecord,
-    void *EstablisherFrame,
-    struct _CONTEXT *ContextRecord,
-    void *DispatcherContext)
-{
-    __asm__ __volatile__ (
-            "jmp checkstackspace_reentry");
-    return 0; /* Function does not return */
-}
-#endif /* HAVE_NO_SEH */
+
 \f
 /*
  *----------------------------------------------------------------------

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

* Re: MinGW patches for Insight
  2008-02-09  2:32           ` Dave Murphy
@ 2008-03-03 23:28             ` Keith Seitz
  2008-03-12 12:31               ` Dave Murphy
  0 siblings, 1 reply; 12+ messages in thread
From: Keith Seitz @ 2008-03-03 23:28 UTC (permalink / raw)
  To: Dave Murphy; +Cc: insight

Dave Murphy wrote:

> My updated patchset is attached, just shout if you need anything else 
> changed.

I apologize for the delay, but I have finally reviewed this patch and 
tested it (on my ancient cygwin box). I've made some corrections to your 
ChangeLogs, but I have otherwise committed everything as submitted.

Thank you for the patches!
Keith

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

* Re: MinGW patches for Insight
  2008-03-03 23:28             ` Keith Seitz
@ 2008-03-12 12:31               ` Dave Murphy
  0 siblings, 0 replies; 12+ messages in thread
From: Dave Murphy @ 2008-03-12 12:31 UTC (permalink / raw)
  To: Keith Seitz; +Cc: insight

Keith Seitz wrote:
> Dave Murphy wrote:
> 
>> My updated patchset is attached, just shout if you need anything else 
>> changed.
> 
> I apologize for the delay, but I have finally reviewed this patch and 
> tested it (on my ancient cygwin box). I've made some corrections to your 
> ChangeLogs, but I have otherwise committed everything as submitted.
> 
> Thank you for the patches!

My pleasure, thank you *so* much for accepting and applying these.

Dave

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

end of thread, other threads:[~2008-03-12 12:31 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-07  8:35 MinGW patches for Insight Dave Murphy
2008-02-08 17:24 ` Dave Murphy
2008-02-08 18:05   ` Mike Frysinger
2008-02-08 23:17     ` Dave Murphy
2008-02-08 23:34       ` Mike Frysinger
2008-02-09  0:03       ` Keith Seitz
2008-02-09  1:24         ` Keith Seitz
2008-02-09  1:55           ` Dave Murphy
2008-02-09  2:32           ` Dave Murphy
2008-03-03 23:28             ` Keith Seitz
2008-03-12 12:31               ` Dave Murphy
2008-02-09  1:51         ` Dave Murphy

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).