public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
* [PATCH] Add minidump write utility
@ 2014-02-07 16:36 Jon TURNEY
  2014-02-07 17:14 ` Daniel Colascione
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Jon TURNEY @ 2014-02-07 16:36 UTC (permalink / raw)
  To: cygwin-patches

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


This patch adds a 'minidumper' utility, which functions identically to
'dumper' except it writes a Windows minidump, rather than a core file.
	
I'm not sure if this is of use to anyone but me, but since I've had the patch
sitting around for a couple of years, here it is...

2014-02-07  Jon TURNEY  <jon.turney@dronecode.org.uk>

	* minidumper.cc: New file.
	* Makefile.in (CYGWIN_BINS): Add minidumper.
	* utils.xml (minidumper): New section.

[-- Attachment #2: minidumper.patch --]
[-- Type: text/plain, Size: 9043 bytes --]

Index: utils/Makefile.in
===================================================================
RCS file: /cvs/src/src/winsup/utils/Makefile.in,v
retrieving revision 1.113
diff -u -u -p -r1.113 Makefile.in
--- utils/Makefile.in	19 Nov 2013 11:14:36 -0000	1.113
+++ utils/Makefile.in	14 Jan 2014 00:01:13 -0000
@@ -56,7 +56,7 @@ MINGW_CXX      := @MINGW_CXX@
 
 # List all binaries to be linked in Cygwin mode.  Each binary on this list
 # must have a corresponding .o of the same name.
-CYGWIN_BINS := ${addsuffix .exe,cygpath getconf getfacl ldd locale kill mkgroup \
+CYGWIN_BINS := ${addsuffix .exe,cygpath getconf getfacl ldd locale kill minidumper mkgroup \
         mkpasswd mount passwd pldd ps regtool setfacl setmetamode ssp tzset umount}
 
 # List all binaries to be linked in MinGW mode.  Each binary on this list
Index: utils/minidumper.cc
===================================================================
RCS file: utils/minidumper.cc
diff -N utils/minidumper.cc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ utils/minidumper.cc	14 Jan 2014 00:01:13 -0000
@@ -0,0 +1,225 @@
+/* minidumper.cc
+
+   Copyright 2012
+
+   This file is part of Cygwin.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License (file COPYING.dumper) for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
+*/
+
+#include <sys/cygwin.h>
+#include <cygwin/version.h>
+#include <getopt.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <windows.h>
+
+BOOL verbose = FALSE;
+
+typedef DWORD MINIDUMP_TYPE;
+
+typedef BOOL (WINAPI *MiniDumpWriteDump_type)(
+                                              HANDLE hProcess,
+                                              DWORD dwPid,
+                                              HANDLE hFile,
+                                              MINIDUMP_TYPE DumpType,
+                                              CONST void *ExceptionParam,
+                                              CONST void *UserStreamParam,
+                                              CONST void *allbackParam);
+
+static void
+minidump(DWORD pid, MINIDUMP_TYPE dump_type, const char *minidump_file)
+{
+  HANDLE dump_file;
+  HANDLE process;
+  MiniDumpWriteDump_type MiniDumpWriteDump_fp;
+  HMODULE module;
+
+  module = LoadLibrary("dbghelp.dll");
+  if (!module)
+    {
+      fprintf (stderr, "error loading DbgHelp\n");
+      return;
+    }
+
+  MiniDumpWriteDump_fp = (MiniDumpWriteDump_type)GetProcAddress(module, "MiniDumpWriteDump");
+  if (!MiniDumpWriteDump_fp)
+    {
+      fprintf (stderr, "error getting the address of MiniDumpWriteDump\n");
+      return;
+    }
+
+  dump_file = CreateFile(minidump_file,
+                         GENERIC_WRITE,
+                         0,
+                         NULL,
+                         CREATE_ALWAYS,
+                         FILE_ATTRIBUTE_NORMAL,
+                         NULL);
+  if (dump_file == INVALID_HANDLE_VALUE)
+    {
+      fprintf (stderr, "error opening file\n");
+      return;
+    }
+
+  process = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,
+                        FALSE,
+                        pid);
+  if (dump_file == INVALID_HANDLE_VALUE)
+    {
+      fprintf (stderr, "error opening process\n");
+      return;
+    }
+
+  BOOL success = (*MiniDumpWriteDump_fp)(process,
+                                         pid,
+                                         dump_file,
+                                         dump_type,
+                                         NULL,
+                                         NULL,
+                                         NULL);
+  if (success)
+    {
+      if (verbose)
+        printf ("minidump created successfully\n");
+    }
+  else
+    {
+      fprintf (stderr, "error creating minidump\n");
+    }
+
+  CloseHandle(process);
+  CloseHandle(dump_file);
+  FreeLibrary(module);
+}
+
+static void
+usage (FILE *stream, int status)
+{
+  fprintf (stream, "\
+Usage: %s [OPTION] FILENAME WIN32PID\n\
+\n\
+Write minidump from WIN32PID to FILENAME.dmp\n\
+\n\
+ -t, --type     minidump type flags\n\
+ -d, --verbose  be verbose while dumping\n\
+ -h, --help     output help information and exit\n\
+ -q, --quiet    be quiet while dumping (default)\n\
+ -V, --version  output version information and exit\n\
+\n", program_invocation_short_name);
+  exit (status);
+}
+
+struct option longopts[] = {
+  {"type", required_argument, NULL, 't'},
+  {"verbose", no_argument, NULL, 'd'},
+  {"help", no_argument, NULL, 'h'},
+  {"quiet", no_argument, NULL, 'q'},
+  {"version", no_argument, 0, 'V'},
+  {0, no_argument, NULL, 0}
+};
+const char *opts = "tdhqV";
+
+static void
+print_version ()
+{
+  printf ("minidumper (cygwin) %d.%d.%d\n"
+	  "Minidump write for Cygwin\n"
+	  "Copyright (C) 1999 - %s Red Hat, Inc.\n"
+	  "This is free software; see the source for copying conditions.  There is NO\n"
+	  "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n",
+	  CYGWIN_VERSION_DLL_MAJOR / 1000,
+	  CYGWIN_VERSION_DLL_MAJOR % 1000,
+	  CYGWIN_VERSION_DLL_MINOR,
+	  strrchr (__DATE__, ' ') + 1);
+}
+
+int
+main (int argc, char **argv)
+{
+  int opt;
+  const char *p = "";
+  DWORD pid;
+  MINIDUMP_TYPE dump_type = 0; // MINIDUMP_NORMAL
+
+  while ((opt = getopt_long (argc, argv, opts, longopts, NULL) ) != EOF)
+    switch (opt)
+      {
+      case 't':
+        {
+          char *endptr;
+          dump_type = strtoul(optarg, &endptr, 0);
+          if (*endptr != '\0')
+            {
+              fprintf (stderr, "syntax error in minidump type \"%s\" near character #%d.\n", optarg, (int) (endptr - optarg));
+              exit(1);
+            }
+        }
+        break;
+      case 'd':
+	verbose = TRUE;
+	break;
+      case 'q':
+	verbose = FALSE;
+	break;
+      case 'h':
+	usage (stdout, 0);
+      case 'V':
+	print_version ();
+	exit (0);
+      default:
+	fprintf (stderr, "Try `%s --help' for more information.\n",
+		 program_invocation_short_name);
+	exit (1);
+      }
+
+  if (argv && *(argv + optind) && *(argv + optind +1))
+    {
+      ssize_t len = cygwin_conv_path (CCP_POSIX_TO_WIN_A | CCP_RELATIVE,
+				      *(argv + optind), NULL, 0);
+      char *win32_name = (char *) alloca (len);
+      cygwin_conv_path (CCP_POSIX_TO_WIN_A | CCP_RELATIVE,  *(argv + optind),
+			win32_name, len);
+      if ((p = strrchr (win32_name, '\\')))
+	p++;
+      else
+	p = win32_name;
+
+      pid = strtoul (*(argv + optind + 1), NULL, 10);
+    }
+  else
+    {
+      usage (stderr, 1);
+      return -1;
+    }
+
+  char *minidump_file = (char *) malloc (strlen (p) + sizeof (".dmp"));
+  if (!minidump_file)
+    {
+      fprintf (stderr, "error allocating memory\n");
+      return -1;
+    }
+  sprintf (minidump_file, "%s.dmp", p);
+
+  if (verbose)
+    printf ("dumping process %u to %s using dump type flags 0x%x\n", (unsigned int)pid, minidump_file, (unsigned int)dump_type);
+
+  minidump(pid, dump_type, minidump_file);
+
+  free (minidump_file);
+
+  return 0;
+};
Index: utils/utils.xml
===================================================================
RCS file: /cvs/src/src/winsup/utils/utils.xml,v
retrieving revision 1.2
diff -u -u -p -r1.2 utils.xml
--- utils/utils.xml	10 May 2013 15:58:48 -0000	1.2
+++ utils/utils.xml	14 Jan 2014 00:01:13 -0000
@@ -833,6 +833,39 @@ bash$ locale noexpr
 
   </sect2>
 
+  <sect2 id="minidumper"><title>minidumper</title>
+
+  <screen>
+Usage: minidumper [OPTION] FILENAME WIN32PID
+
+Write minidump from WIN32PID to FILENAME.dmp
+
+-t, --type     minidump type flags
+-d, --verbose  be verbose while dumping
+-h, --help     output help information and exit
+-q, --quiet    be quiet while dumping (default)
+-V, --version  output version information and exit
+  </screen>
+
+  <para>
+    The <command>minidumper</command> utility can be used to create a
+    minidump of a running Windows process.  This minidump can be later
+    analysed using breakpad or Windows debugging tools.
+  </para>
+
+  <para>
+    <command>minidumper</command> can be used with cygwin's Just-In-Time
+    debugging facility in exactly the same way as <command>dumper</command>
+    (See <xref linkend="dumper"></xref>).
+  </para>
+
+  <para>
+    <command>minidumper</command> can also be started from the command line to
+    create a minidump of any running process.
+  </para>
+
+  </sect2>
+
   <sect2 id="mkgroup">
     <title>mkgroup</title>
 

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

* Re: [PATCH] Add minidump write utility
  2014-02-07 16:36 [PATCH] Add minidump write utility Jon TURNEY
@ 2014-02-07 17:14 ` Daniel Colascione
  2014-02-09 12:37   ` Jon TURNEY
  2014-02-07 17:44 ` Christopher Faylor
  2014-02-08 15:00 ` Jon TURNEY
  2 siblings, 1 reply; 11+ messages in thread
From: Daniel Colascione @ 2014-02-07 17:14 UTC (permalink / raw)
  To: cygwin-patches

May I recommend setting MiniDumpWithHandleData | 
MiniDumpWithFullMemoryInfo | MiniDumpWithThreadInfo | 
MiniDumpWithFullAuxiliaryState | MiniDumpIgnoreInaccessibleMemory | 
MiniDumpWithTokenInformation | MiniDumpWithModuleHeaders | 
MiniDumpWithIndirectlyReferencedMemory by default?

On 02/07/2014 08:36 AM, Jon TURNEY wrote:
>
> This patch adds a 'minidumper' utility, which functions identically to
> 'dumper' except it writes a Windows minidump, rather than a core file.
> 	
> I'm not sure if this is of use to anyone but me, but since I've had the patch
> sitting around for a couple of years, here it is...
>
> 2014-02-07  Jon TURNEY  <jon.turney@dronecode.org.uk>
>
> 	* minidumper.cc: New file.
> 	* Makefile.in (CYGWIN_BINS): Add minidumper.
> 	* utils.xml (minidumper): New section.
>

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

* Re: [PATCH] Add minidump write utility
  2014-02-07 16:36 [PATCH] Add minidump write utility Jon TURNEY
  2014-02-07 17:14 ` Daniel Colascione
@ 2014-02-07 17:44 ` Christopher Faylor
  2014-02-07 19:18   ` Corinna Vinschen
  2014-02-09 12:28   ` Jon TURNEY
  2014-02-08 15:00 ` Jon TURNEY
  2 siblings, 2 replies; 11+ messages in thread
From: Christopher Faylor @ 2014-02-07 17:44 UTC (permalink / raw)
  To: cygwin-patches

On Fri, Feb 07, 2014 at 04:36:01PM +0000, Jon TURNEY wrote:
>
>This patch adds a 'minidumper' utility, which functions identically to
>'dumper' except it writes a Windows minidump, rather than a core file.
>	
>I'm not sure if this is of use to anyone but me, but since I've had the patch
>sitting around for a couple of years, here it is...
>
>2014-02-07  Jon TURNEY  <jon.turney@dronecode.org.uk>
>
>	* minidumper.cc: New file.
>	* Makefile.in (CYGWIN_BINS): Add minidumper.
>	* utils.xml (minidumper): New section.

This is awesome.  Thanks.

Could you add Red Hat as the copyright holder, like dumper.cc?

You can feel free to check this in and update it as you see fit.

Thanks for doing this.

cgf

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

* Re: [PATCH] Add minidump write utility
  2014-02-07 17:44 ` Christopher Faylor
@ 2014-02-07 19:18   ` Corinna Vinschen
  2014-02-08 15:00     ` Jon TURNEY
  2014-02-09 12:28   ` Jon TURNEY
  1 sibling, 1 reply; 11+ messages in thread
From: Corinna Vinschen @ 2014-02-07 19:18 UTC (permalink / raw)
  To: cygwin-patches

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

On Feb  7 12:44, Christopher Faylor wrote:
> On Fri, Feb 07, 2014 at 04:36:01PM +0000, Jon TURNEY wrote:
> >
> >This patch adds a 'minidumper' utility, which functions identically to
> >'dumper' except it writes a Windows minidump, rather than a core file.
> >	
> >I'm not sure if this is of use to anyone but me, but since I've had the patch
> >sitting around for a couple of years, here it is...
> >
> >2014-02-07  Jon TURNEY  <jon.turney@dronecode.org.uk>
> >
> >	* minidumper.cc: New file.
> >	* Makefile.in (CYGWIN_BINS): Add minidumper.
> >	* utils.xml (minidumper): New section.
> 
> This is awesome.  Thanks.
> 
> Could you add Red Hat as the copyright holder, like dumper.cc?
> 
> You can feel free to check this in and update it as you see fit.
> 
> Thanks for doing this.

I agree, but, like some other parts of our utils, you don't have to put
the Red Hat copyright in there if you go with a BSD-style license, Jon.
Look at the header of ldd.cc.  This is fine for new Cygin utils.

Just one, really important point:  Would you mind to add documentation
for the tool and its usage to utils.xml?


Thanks a lot,
Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

[-- Attachment #2: Type: application/pgp-signature, Size: 819 bytes --]

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

* Re: [PATCH] Add minidump write utility
  2014-02-07 19:18   ` Corinna Vinschen
@ 2014-02-08 15:00     ` Jon TURNEY
  2014-02-08 17:18       ` Corinna Vinschen
  0 siblings, 1 reply; 11+ messages in thread
From: Jon TURNEY @ 2014-02-08 15:00 UTC (permalink / raw)
  To: cygwin-patches

On 07/02/2014 19:18, Corinna Vinschen wrote:
> On Feb  7 12:44, Christopher Faylor wrote:
>> On Fri, Feb 07, 2014 at 04:36:01PM +0000, Jon TURNEY wrote:
>>>
>>> This patch adds a 'minidumper' utility, which functions identically to
>>> 'dumper' except it writes a Windows minidump, rather than a core file.
>>> 	
>>> I'm not sure if this is of use to anyone but me, but since I've had the patch
>>> sitting around for a couple of years, here it is...
>>>
>>> 2014-02-07  Jon TURNEY  <jon.turney@dronecode.org.uk>
>>>
>>> 	* minidumper.cc: New file.
>>> 	* Makefile.in (CYGWIN_BINS): Add minidumper.
>>> 	* utils.xml (minidumper): New section.
>>
>> This is awesome.  Thanks.
>>
>> Could you add Red Hat as the copyright holder, like dumper.cc?
>>
>> You can feel free to check this in and update it as you see fit.
>>
>> Thanks for doing this.
> 
> I agree, but, like some other parts of our utils, you don't have to put
> the Red Hat copyright in there if you go with a BSD-style license, Jon.
> Look at the header of ldd.cc.  This is fine for new Cygin utils.

I prefer the GPL.  I will adjust the copyright holder as requested.

> Just one, really important point:  Would you mind to add documentation
> for the tool and its usage to utils.xml?

Um, I already did?

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

* Re: [PATCH] Add minidump write utility
  2014-02-07 16:36 [PATCH] Add minidump write utility Jon TURNEY
  2014-02-07 17:14 ` Daniel Colascione
  2014-02-07 17:44 ` Christopher Faylor
@ 2014-02-08 15:00 ` Jon TURNEY
  2014-02-08 20:49   ` Christopher Faylor
  2 siblings, 1 reply; 11+ messages in thread
From: Jon TURNEY @ 2014-02-08 15:00 UTC (permalink / raw)
  To: cygwin-patches

On 07/02/2014 16:36, Jon TURNEY wrote:
> 
> This patch adds a 'minidumper' utility, which functions identically to
> 'dumper' except it writes a Windows minidump, rather than a core file.
> 	
> I'm not sure if this is of use to anyone but me, but since I've had the patch
> sitting around for a couple of years, here it is...
> 
> 2014-02-07  Jon TURNEY  <jon.turney@dronecode.org.uk>
> 
> 	* minidumper.cc: New file.
> 	* Makefile.in (CYGWIN_BINS): Add minidumper.
> 	* utils.xml (minidumper): New section.
> 

Unfortunately there seems to be a bit of a problem with this patch. It seems
that cygwin assumes that the JIT debugger will terminate the debugged process.
 I'm not sure if that's always been the case.

Consider the following test case:

$ cat segv-test.c

int main(int argc, char *argv[])
{
  *(char *)0 = 0;
  return 0;
}
$ gcc -o segv-test.exe segv-test.c

$ export CYGWIN="error_start:C:\cygwin\bin\true.exe"

$ ./segv-test

seg-test crashes, true runs and exits, and segv-test spins.

dumper.exe does terminate the debugeee, but despite what utils.xml says about
this, I don't think this hasn't been a Windows API limitation since
DebugSetProcessKillOnExit() has existed.

I could fix this by making minidumper also terminate the dumped process, but
that doesn't seem the right approach.

I don't understand what debugging scenarios the waitloop part of
exceptions.cc:try_to_debug() is useful in, or why it doesn't wait until the
debugger process exits, so it's not clear to me how to fix this there, but
I'll note in passing that it seems that the thread's original priority is not
restored after running the debugger if waitloop=false, so perhaps at least the
following is needed:

--- cygwin/exceptions.cc        8 Jan 2014 16:51:20 -0000       1.432
+++ cygwin/exceptions.cc        8 Feb 2014 14:49:59 -0000
@@ -504,10 +504,8 @@

   if (!dbg)
     system_printf ("Failed to start debugger, %E");
-  else
+  else if (waitloop)
     {
-      if (!waitloop)
-       return dbg;
       SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_IDLE);
       while (!being_debugged ())
        Sleep (1);


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

* Re: [PATCH] Add minidump write utility
  2014-02-08 15:00     ` Jon TURNEY
@ 2014-02-08 17:18       ` Corinna Vinschen
  0 siblings, 0 replies; 11+ messages in thread
From: Corinna Vinschen @ 2014-02-08 17:18 UTC (permalink / raw)
  To: cygwin-patches

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

On Feb  8 15:00, Jon TURNEY wrote:
> On 07/02/2014 19:18, Corinna Vinschen wrote:
> > On Feb  7 12:44, Christopher Faylor wrote:
> >> On Fri, Feb 07, 2014 at 04:36:01PM +0000, Jon TURNEY wrote:
> >>>
> >>> This patch adds a 'minidumper' utility, which functions identically to
> >>> 'dumper' except it writes a Windows minidump, rather than a core file.
> >>> 	
> >>> I'm not sure if this is of use to anyone but me, but since I've had the patch
> >>> sitting around for a couple of years, here it is...
> >>>
> >>> 2014-02-07  Jon TURNEY  <jon.turney@dronecode.org.uk>
> >>>
> >>> 	* minidumper.cc: New file.
> >>> 	* Makefile.in (CYGWIN_BINS): Add minidumper.
> >>> 	* utils.xml (minidumper): New section.
> >>
> >> This is awesome.  Thanks.
> >>
> >> Could you add Red Hat as the copyright holder, like dumper.cc?
> >>
> >> You can feel free to check this in and update it as you see fit.
> >>
> >> Thanks for doing this.
> > 
> > I agree, but, like some other parts of our utils, you don't have to put
> > the Red Hat copyright in there if you go with a BSD-style license, Jon.
> > Look at the header of ldd.cc.  This is fine for new Cygin utils.
> 
> I prefer the GPL.  I will adjust the copyright holder as requested.

Ok, no worries at all.

> > Just one, really important point:  Would you mind to add documentation
> > for the tool and its usage to utils.xml?
> 
> Um, I already did?

Oh, *blush*.  No idea how I missed that.  Sorry!


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

[-- Attachment #2: Type: application/pgp-signature, Size: 819 bytes --]

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

* Re: [PATCH] Add minidump write utility
  2014-02-08 15:00 ` Jon TURNEY
@ 2014-02-08 20:49   ` Christopher Faylor
  2014-02-13 17:40     ` Jon TURNEY
  0 siblings, 1 reply; 11+ messages in thread
From: Christopher Faylor @ 2014-02-08 20:49 UTC (permalink / raw)
  To: cygwin-patches

On Sat, Feb 08, 2014 at 03:00:18PM +0000, Jon TURNEY wrote:
>On 07/02/2014 16:36, Jon TURNEY wrote:
>> 
>> This patch adds a 'minidumper' utility, which functions identically to
>> 'dumper' except it writes a Windows minidump, rather than a core file.
>> 	
>> I'm not sure if this is of use to anyone but me, but since I've had the patch
>> sitting around for a couple of years, here it is...
>> 
>> 2014-02-07  Jon TURNEY  <jon.turney@dronecode.org.uk>
>> 
>> 	* minidumper.cc: New file.
>> 	* Makefile.in (CYGWIN_BINS): Add minidumper.
>> 	* utils.xml (minidumper): New section.
>> 
>
>Unfortunately there seems to be a bit of a problem with this patch. It seems
>that cygwin assumes that the JIT debugger will terminate the debugged process.
> I'm not sure if that's always been the case.
>
>Consider the following test case:
>
>$ cat segv-test.c
>
>int main(int argc, char *argv[])
>{
>  *(char *)0 = 0;
>  return 0;
>}
>$ gcc -o segv-test.exe segv-test.c
>
>$ export CYGWIN="error_start:C:\cygwin\bin\true.exe"
>
>$ ./segv-test
>
>seg-test crashes, true runs and exits, and segv-test spins.
>
>dumper.exe does terminate the debugeee, but despite what utils.xml says about
>this, I don't think this hasn't been a Windows API limitation since
>DebugSetProcessKillOnExit() has existed.
>
>I could fix this by making minidumper also terminate the dumped process, but
>that doesn't seem the right approach.
>
>I don't understand what debugging scenarios the waitloop part of
>exceptions.cc:try_to_debug() is useful in, or why it doesn't wait until the
>debugger process exits, so it's not clear to me how to fix this there, but
>I'll note in passing that it seems that the thread's original priority is not
>restored after running the debugger if waitloop=false, so perhaps at least the
>following is needed:
>
>--- cygwin/exceptions.cc        8 Jan 2014 16:51:20 -0000       1.432
>+++ cygwin/exceptions.cc        8 Feb 2014 14:49:59 -0000
>@@ -504,10 +504,8 @@
>
>   if (!dbg)
>     system_printf ("Failed to start debugger, %E");
>-  else
>+  else if (waitloop)
>     {
>-      if (!waitloop)
>-       return dbg;
>       SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_IDLE);
>       while (!being_debugged ())
>        Sleep (1);

Go ahead and check in the above but I don't see how it would be possible
in a non-racy way for a dumper process to dump it's parents core unless
the parent was guaranteed to still be alive.

cgf

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

* Re: [PATCH] Add minidump write utility
  2014-02-07 17:44 ` Christopher Faylor
  2014-02-07 19:18   ` Corinna Vinschen
@ 2014-02-09 12:28   ` Jon TURNEY
  1 sibling, 0 replies; 11+ messages in thread
From: Jon TURNEY @ 2014-02-09 12:28 UTC (permalink / raw)
  To: cygwin-patches

On 07/02/2014 17:44, Christopher Faylor wrote:
> On Fri, Feb 07, 2014 at 04:36:01PM +0000, Jon TURNEY wrote:
>>
>> This patch adds a 'minidumper' utility, which functions identically to
>> 'dumper' except it writes a Windows minidump, rather than a core file.
>> 	
>> I'm not sure if this is of use to anyone but me, but since I've had the patch
>> sitting around for a couple of years, here it is...
>>
>> 2014-02-07  Jon TURNEY  <jon.turney@dronecode.org.uk>
>>
>> 	* minidumper.cc: New file.
>> 	* Makefile.in (CYGWIN_BINS): Add minidumper.
>> 	* utils.xml (minidumper): New section.
> 
> This is awesome.  Thanks.
> 
> Could you add Red Hat as the copyright holder, like dumper.cc?
> 
> You can feel free to check this in and update it as you see fit.

I've checked this in with the following adjustments:

- Fix copyright holder.
- Tweak CreateFile() invocation so we don't fail if the file already exists.
- For compatibility with dumper, terminate the dumped process after dumping
it.  Add option -n to disable this behaviour.

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

* Re: [PATCH] Add minidump write utility
  2014-02-07 17:14 ` Daniel Colascione
@ 2014-02-09 12:37   ` Jon TURNEY
  0 siblings, 0 replies; 11+ messages in thread
From: Jon TURNEY @ 2014-02-09 12:37 UTC (permalink / raw)
  To: cygwin-patches

On 07/02/2014 17:13, Daniel Colascione wrote:
> May I recommend setting MiniDumpWithHandleData | MiniDumpWithFullMemoryInfo |
> MiniDumpWithThreadInfo | MiniDumpWithFullAuxiliaryState |
> MiniDumpIgnoreInaccessibleMemory | MiniDumpWithTokenInformation |
> MiniDumpWithModuleHeaders | MiniDumpWithIndirectlyReferencedMemory by default?

This seems sensible, but I can't see a clear statement that it's safe to
assume that MiniDumpWriteDump() ignores dump type flags it doesn't understand,
so it might be necessary to check the version of dbghelp.dll as well.

Originally, I was thinking of adding some named dump levels, like those
described at [1], but that hasn't happened yet.

[1] http://www.debuginfo.com/articles/effminidumps2.html#strategies

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

* Re: [PATCH] Add minidump write utility
  2014-02-08 20:49   ` Christopher Faylor
@ 2014-02-13 17:40     ` Jon TURNEY
  0 siblings, 0 replies; 11+ messages in thread
From: Jon TURNEY @ 2014-02-13 17:40 UTC (permalink / raw)
  To: cygwin-patches

On 08/02/2014 20:49, Christopher Faylor wrote:
> On Sat, Feb 08, 2014 at 03:00:18PM +0000, Jon TURNEY wrote:
>> On 07/02/2014 16:36, Jon TURNEY wrote:
>> Unfortunately there seems to be a bit of a problem with this patch. It seems
>> that cygwin assumes that the JIT debugger will terminate the debugged process.
>> I'm not sure if that's always been the case.
[snip]
>> dumper.exe does terminate the debugeee, but despite what utils.xml says about
>> this, I don't think this hasn't been a Windows API limitation since
>> DebugSetProcessKillOnExit() has existed.
>>
>> I could fix this by making minidumper also terminate the dumped process, but
>> that doesn't seem the right approach.

On reflection, given the below, adding an option so that, when running
minidumper standalone, terminating the dumped process can be disabled, but
defaulting to behaving in the same way as dumper seems like an adequate
solution for the moment.

>> I don't understand what debugging scenarios the waitloop part of
>> exceptions.cc:try_to_debug() is useful in, or why it doesn't wait until the
>> debugger process exits, so it's not clear to me how to fix this there, but
>> I'll note in passing that it seems that the thread's original priority is not
>> restored after running the debugger if waitloop=false, so perhaps at least the
>> following is needed:
>>
>> --- cygwin/exceptions.cc        8 Jan 2014 16:51:20 -0000       1.432
>> +++ cygwin/exceptions.cc        8 Feb 2014 14:49:59 -0000
>> @@ -504,10 +504,8 @@
>>
>>   if (!dbg)
>>     system_printf ("Failed to start debugger, %E");
>> -  else
>> +  else if (waitloop)
>>     {
>> -      if (!waitloop)
>> -       return dbg;
>>       SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_IDLE);
>>       while (!being_debugged ())
>>        Sleep (1);
> 
> Go ahead and check in the above but I don't see how it would be possible
> in a non-racy way for a dumper process to dump it's parents core unless
> the parent was guaranteed to still be alive.

This is a good point.   I think I was expecting to achieve that by the parent
waiting until the error_start process exits, but of course, that isn't what is
wanted if it's a debugger.

Looking into this a bit more, according to this ChangeLog entry, this is
deliberate, so I think I'll leave this alone until I understand it better...

2003-02-13  Christopher Faylor

	* exceptions.cc (try_to_debug): Don't reset priority when returning
	from non-waitloop call.

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

end of thread, other threads:[~2014-02-13 17:40 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-07 16:36 [PATCH] Add minidump write utility Jon TURNEY
2014-02-07 17:14 ` Daniel Colascione
2014-02-09 12:37   ` Jon TURNEY
2014-02-07 17:44 ` Christopher Faylor
2014-02-07 19:18   ` Corinna Vinschen
2014-02-08 15:00     ` Jon TURNEY
2014-02-08 17:18       ` Corinna Vinschen
2014-02-09 12:28   ` Jon TURNEY
2014-02-08 15:00 ` Jon TURNEY
2014-02-08 20:49   ` Christopher Faylor
2014-02-13 17:40     ` Jon TURNEY

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