MingW and MiniDumps

Started by Magnus Haganderabout 15 years ago9 messages
#1Magnus Hagander
magnus@hagander.net

Seems at least one mingw machine is missing the definitions for
minidumps. It does seem to have the header (dbghelp.h) that's
required, but with incomplete contents?

Can someone who has a working mingw environment look for the
definitions? See
http://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=narwhal&dt=2010-12-19%2017%3A00%3A01
for ref on what's missing.

If they're not defined on mingw, I'm inclined to just not bother
building the crashdump functionality at all on mingw. It's likely less
useful there since mingw doesn't use windows compatible symbol tables,
but it might still be a bit useful due to our "export everything"
approach.

--
 Magnus Hagander
 Me: http://www.hagander.net/
 Work: http://www.redpill-linpro.com/

#2Andrew Dunstan
andrew@dunslane.net
In reply to: Magnus Hagander (#1)
Re: MingW and MiniDumps

On 12/19/2010 12:23 PM, Magnus Hagander wrote:

Seems at least one mingw machine is missing the definitions for
minidumps. It does seem to have the header (dbghelp.h) that's
required, but with incomplete contents?

Can someone who has a working mingw environment look for the
definitions? See
http://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=narwhal&dt=2010-12-19%2017%3A00%3A01
for ref on what's missing.

If they're not defined on mingw, I'm inclined to just not bother
building the crashdump functionality at all on mingw. It's likely less
useful there since mingw doesn't use windows compatible symbol tables,
but it might still be a bit useful due to our "export everything"
approach.

I can't find either the header or the symbols.

cheers

andrew

#3Magnus Hagander
magnus@hagander.net
In reply to: Andrew Dunstan (#2)
Re: MingW and MiniDumps

On Sun, Dec 19, 2010 at 20:58, Andrew Dunstan <andrew@dunslane.net> wrote:

On 12/19/2010 12:23 PM, Magnus Hagander wrote:

Seems at least one mingw machine is missing the definitions for
minidumps. It does seem to have the header (dbghelp.h) that's
required, but with incomplete contents?

Can someone who has a working mingw environment look for the
definitions? See

http://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=narwhal&amp;dt=2010-12-19%2017%3A00%3A01
for ref on what's missing.

If they're not defined on mingw, I'm inclined to just not bother
building the crashdump functionality at all on mingw. It's likely less
useful there since mingw doesn't use windows compatible symbol tables,
but it might still be a bit useful due to our "export everything"
approach.

I can't find either the header or the symbols.

That's weird - from what I can tell, at least narwahl isn't
complaining about a missing include file, just the undefined symbols.
Different versions of mingw perhaps?

--
 Magnus Hagander
 Me: http://www.hagander.net/
 Work: http://www.redpill-linpro.com/

#4Andrew Dunstan
andrew@dunslane.net
In reply to: Magnus Hagander (#3)
Re: MingW and MiniDumps

On 12/19/2010 03:09 PM, Magnus Hagander wrote:

I can't find either the header or the symbols.

That's weird - from what I can tell, at least narwahl isn't
complaining about a missing include file, just the undefined symbols.
Different versions of mingw perhaps?

Maybe. I have no idea where narwhal got its version of dbghelp.h. I
copied the file from the SDK directory to mingw's include directory and
the build then ran perfectly. I think therefore the right thing is to
have a configure test for the file and for MINIDUMP_TYPE on win32, and
only build in crashdump if it passes those tests.

cheers

andrew

#5Tom Lane
tgl@sss.pgh.pa.us
In reply to: Andrew Dunstan (#4)
Re: MingW and MiniDumps

Andrew Dunstan <andrew@dunslane.net> writes:

Maybe. I have no idea where narwhal got its version of dbghelp.h. I
copied the file from the SDK directory to mingw's include directory and
the build then ran perfectly. I think therefore the right thing is to
have a configure test for the file and for MINIDUMP_TYPE on win32, and
only build in crashdump if it passes those tests.

mmm ... how ya gonna do that on the MSVC side of things?

regards, tom lane

#6Magnus Hagander
magnus@hagander.net
In reply to: Tom Lane (#5)
Re: MingW and MiniDumps

On Mon, Dec 20, 2010 at 19:24, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Andrew Dunstan <andrew@dunslane.net> writes:

Maybe. I have no idea where narwhal got its version of dbghelp.h. I
copied the file from the SDK directory to mingw's include directory and
the build then ran perfectly. I think therefore the right thing is to
have a configure test for the file and for MINIDUMP_TYPE on win32, and
only build in crashdump if it passes those tests.

+1.

mmm ... how ya gonna do that on the MSVC side of things?

MSVC always has the Platform SDK. So it has the required headers.

There was one symbol missing from an older version of the platform
sdk, but it's not really one we need...

--
 Magnus Hagander
 Me: http://www.hagander.net/
 Work: http://www.redpill-linpro.com/

#7Andrew Dunstan
andrew@dunslane.net
In reply to: Magnus Hagander (#6)
1 attachment(s)
Re: MingW and MiniDumps

On 12/20/2010 01:25 PM, Magnus Hagander wrote:

On Mon, Dec 20, 2010 at 19:24, Tom Lane<tgl@sss.pgh.pa.us> wrote:

Andrew Dunstan<andrew@dunslane.net> writes:

Maybe. I have no idea where narwhal got its version of dbghelp.h. I
copied the file from the SDK directory to mingw's include directory and
the build then ran perfectly. I think therefore the right thing is to
have a configure test for the file and for MINIDUMP_TYPE on win32, and
only build in crashdump if it passes those tests.

+1.

Suggested patch attached.

cheers

andrew

Attachments:

crashdump.patchtext/x-patch; name=crashdump.patchDownload
diff --git a/configure b/configure
index 51d27d8..388cf34 100755
--- a/configure
+++ b/configure
@@ -667,6 +667,7 @@ PTHREAD_CFLAGS
 PTHREAD_LIBS
 PTHREAD_CC
 acx_pthread_config
+have_win32_dbghelp
 HAVE_IPV6
 LIBOBJS
 OSSP_UUID_LIBS
@@ -20926,6 +20927,128 @@ cat >>confdefs.h <<\_ACEOF
 #define HAVE_SYMLINK 1
 _ACEOF
 
+  { $as_echo "$as_me:$LINENO: checking for MINIDUMP_TYPE" >&5
+$as_echo_n "checking for MINIDUMP_TYPE... " >&6; }
+if test "${ac_cv_type_MINIDUMP_TYPE+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  ac_cv_type_MINIDUMP_TYPE=no
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#include <string.h>
+#include <dbghelp.h>
+
+int
+main ()
+{
+if (sizeof (MINIDUMP_TYPE))
+       return 0;
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#include <string.h>
+#include <dbghelp.h>
+
+int
+main ()
+{
+if (sizeof ((MINIDUMP_TYPE)))
+	  return 0;
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  :
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_cv_type_MINIDUMP_TYPE=yes
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_type_MINIDUMP_TYPE" >&5
+$as_echo "$ac_cv_type_MINIDUMP_TYPE" >&6; }
+if test "x$ac_cv_type_MINIDUMP_TYPE" = x""yes; then
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_MINIDUMP_TYPE 1
+_ACEOF
+
+pgac_minidump_type=yes
+else
+  pgac_minidump_type=no
+fi
+
+fi
+if test x"$pgac_minidump_type" = x"yes" ; then
+  have_win32_dbghelp=yes
+
+else
+  have_win32_dbghelp=no
+
 fi
 
 if test "$with_readline" = yes; then
diff --git a/configure.in b/configure.in
index b999b94..8ee2152 100644
--- a/configure.in
+++ b/configure.in
@@ -1350,6 +1350,16 @@ if test "$PORTNAME" = "win32"; then
   AC_LIBOBJ(win32error)
   AC_DEFINE([HAVE_SYMLINK], 1,
             [Define to 1 if you have the `symlink' function.])
+  AC_CHECK_TYPES(MINIDUMP_TYPE, [pgac_minidump_type=yes], [pgac_minidump_type=no], [
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#include <string.h>
+#include <dbghelp.h>])
+fi
+if test x"$pgac_minidump_type" = x"yes" ; then
+  AC_SUBST(have_win32_dbghelp,yes)
+else
+  AC_SUBST(have_win32_dbghelp,no)
 fi
 
 if test "$with_readline" = yes; then
diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index 7a61a5a..ebeee0c 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -363,6 +363,9 @@ ELF_SYSTEM= @ELF_SYS@
 # Backend stack size limit has to be hard-wired on Windows (it's in bytes)
 WIN32_STACK_RLIMIT=4194304
 
+# Set if we have a working win32 crashdump header
+have_win32_dbghelp = @have_win32_dbghelp@
+
 # Pull in platform-specific magic
 include $(top_builddir)/src/Makefile.port
 
diff --git a/src/backend/main/main.c b/src/backend/main/main.c
index 6065e8c..d3f9bcd 100644
--- a/src/backend/main/main.c
+++ b/src/backend/main/main.c
@@ -85,7 +85,7 @@ main(int argc, char *argv[])
 	 * If supported on the current platform, set up a handler to be called if
 	 * the backend/postmaster crashes with a fatal signal or exception.
 	 */
-#ifdef WIN32
+#if defined(WIN32) && defined(HAVE_MINIDUMP_TYPE)
 	pgwin32_install_crashdump_handler();
 #endif
 
diff --git a/src/backend/port/win32/Makefile b/src/backend/port/win32/Makefile
index d00c334..820a3b3 100644
--- a/src/backend/port/win32/Makefile
+++ b/src/backend/port/win32/Makefile
@@ -12,6 +12,9 @@ subdir = src/backend/port/win32
 top_builddir = ../../../..
 include $(top_builddir)/src/Makefile.global
 
-OBJS = timer.o socket.o signal.o security.o mingwcompat.o crashdump.o
+OBJS = timer.o socket.o signal.o security.o mingwcompat.o
+ifeq ($(have_win32_dbghelp), yes)
+OBJS += crashdump.o
+endif
 
 include $(top_srcdir)/src/backend/common.mk
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index fd169b6..613ef89 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -342,6 +342,9 @@
 /* Define to 1 if you have the <memory.h> header file. */
 #undef HAVE_MEMORY_H
 
+/* Define to 1 if the system has the type `MINIDUMP_TYPE'. */
+#undef HAVE_MINIDUMP_TYPE
+
 /* Define to 1 if you have the <netinet/in.h> header file. */
 #undef HAVE_NETINET_IN_H
 
diff --git a/src/include/pg_config.h.win32 b/src/include/pg_config.h.win32
index 2a383b6..79b8036 100644
--- a/src/include/pg_config.h.win32
+++ b/src/include/pg_config.h.win32
@@ -258,6 +258,9 @@
 /* Define to 1 if you have the <memory.h> header file. */
 #define HAVE_MEMORY_H 1
 
+/* Define to 1 if the system has the type `MINIDUMP_TYPE'. */
+#define HAVE_MINIDUMP_TYPE 1
+
 /* Define to 1 if you have the <netinet/in.h> header file. */
 #define HAVE_NETINET_IN_H 1
 
#8Magnus Hagander
magnus@hagander.net
In reply to: Andrew Dunstan (#7)
Re: MingW and MiniDumps

On Sun, Dec 26, 2010 at 01:10, Andrew Dunstan <andrew@dunslane.net> wrote:

On 12/20/2010 01:25 PM, Magnus Hagander wrote:

On Mon, Dec 20, 2010 at 19:24, Tom Lane<tgl@sss.pgh.pa.us>  wrote:

Andrew Dunstan<andrew@dunslane.net>  writes:

Maybe. I have no idea where narwhal got its version of dbghelp.h. I
copied the file from the SDK directory to mingw's include directory and
the build then ran perfectly. I think therefore the right thing is to
have a configure test for the file and for MINIDUMP_TYPE on win32, and
only build in crashdump if it passes those tests.

+1.

Suggested patch attached.

I wonder if we need to actually care about which enum values are
actually within the symbol. But let's try it this way first and see
what the buildfarm has to say about that.

Doesn't this break the msvc build? (Sorry, don't have one up to test
right now).. You moved the crashdump.o file to a separate line from
OBS, which I believe will make the msvc build system loose it. So
you'll have to explicitly add it back on msvc, in Mkvcbuild.pm.

Other than that, looks good.

--
 Magnus Hagander
 Me: http://www.hagander.net/
 Work: http://www.redpill-linpro.com/

#9Andrew Dunstan
andrew@dunslane.net
In reply to: Magnus Hagander (#8)
Re: MingW and MiniDumps

On 12/26/2010 04:35 AM, Magnus Hagander wrote:

On Sun, Dec 26, 2010 at 01:10, Andrew Dunstan<andrew@dunslane.net> wrote:

On 12/20/2010 01:25 PM, Magnus Hagander wrote:

On Mon, Dec 20, 2010 at 19:24, Tom Lane<tgl@sss.pgh.pa.us> wrote:

Andrew Dunstan<andrew@dunslane.net> writes:

Maybe. I have no idea where narwhal got its version of dbghelp.h. I
copied the file from the SDK directory to mingw's include directory and
the build then ran perfectly. I think therefore the right thing is to
have a configure test for the file and for MINIDUMP_TYPE on win32, and
only build in crashdump if it passes those tests.

+1.

Suggested patch attached.

I wonder if we need to actually care about which enum values are
actually within the symbol. But let's try it this way first and see
what the buildfarm has to say about that.

Doesn't this break the msvc build? (Sorry, don't have one up to test
right now).. You moved the crashdump.o file to a separate line from
OBS, which I believe will make the msvc build system loose it. So
you'll have to explicitly add it back on msvc, in Mkvcbuild.pm.

I think it will actually be OK. If not I'll fix it.

Other than that, looks good.

OK. applied.

cheers

andrew