From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2201) id 58D693844030; Fri, 31 Jul 2020 13:01:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 58D693844030 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Jon TURNEY To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: Add --nokill dumper option X-Act-Checkin: newlib-cygwin X-Git-Author: Jon Turney X-Git-Refname: refs/heads/master X-Git-Oldrev: ba283d8777b617696342cad1f973e22b03bc7c74 X-Git-Newrev: a5218ff7721bd5df023f576a0e9afb8f099c3b09 Message-Id: <20200731130131.58D693844030@sourceware.org> Date: Fri, 31 Jul 2020 13:01:31 +0000 (GMT) X-BeenThere: cygwin-cvs@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component git logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 31 Jul 2020 13:01:31 -0000 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=a5218ff7721bd5df023f576a0e9afb8f099c3b09 commit a5218ff7721bd5df023f576a0e9afb8f099c3b09 Author: Jon Turney Date: Mon Jul 6 14:51:32 2020 +0100 Cygwin: Add --nokill dumper option Add --nokill option to dumper, for compatibility with minidumper, and to assist with testing. Diff: --- winsup/doc/utils.xml | 10 +++++++--- winsup/utils/dumper.cc | 20 +++++++++++++++++++- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/winsup/doc/utils.xml b/winsup/doc/utils.xml index 8b92bfdf1..22bd86904 100644 --- a/winsup/doc/utils.xml +++ b/winsup/doc/utils.xml @@ -496,6 +496,7 @@ dumper [OPTION] FILENAME WIN32PID Options +-n, --nokill don't terminate the dumped process -d, --verbose be verbose while dumping -h, --help output help information and exit -q, --quiet be quiet while dumping (default) @@ -519,9 +520,12 @@ error_start=x:\path\to\dumper.exe be started whenever some program encounters a fatal error. dumper can be also be started from the command - line to create a core dump of any running process. Unfortunately, because - of a Windows API limitation, when a core dump is created and - dumper exits, the target process is terminated too. + line to create a core dump of any running process. + + For historical reasons, unless the -n option + is given, after the core dump is created and when the + dumper exits, the target process is also + terminated. To save space in the core dump, dumper doesn't write those portions of the target process's memory space that are loaded diff --git a/winsup/utils/dumper.cc b/winsup/utils/dumper.cc index 36dbf9dbb..3eb4af275 100644 --- a/winsup/utils/dumper.cc +++ b/winsup/utils/dumper.cc @@ -64,6 +64,7 @@ __attribute__ ((packed)) note_header; BOOL verbose = FALSE; +BOOL nokill = FALSE; int deb_printf (const char *format,...) { @@ -716,7 +717,19 @@ dumper::collect_process_information () current_event.dwThreadId, DBG_CONTINUE); } + failed: + if (nokill) + { + if (!DebugActiveProcessStop (pid)) + { + fprintf (stderr, "Cannot detach from process #%u, error %ld", + (unsigned int) pid, (long) GetLastError ()); + } + } + /* Otherwise, the debuggee is terminated when this process exits + (as DebugSetProcessKillOnExit() defaults to TRUE) */ + /* set debugee free */ if (sync_with_debugee) SetEvent (sync_with_debugee); @@ -960,6 +973,7 @@ Usage: %s [OPTION] FILENAME WIN32PID\n\ \n\ Dump core from WIN32PID to FILENAME.core\n\ \n\ + -n, --nokill don't terminate the dumped process\n\ -d, --verbose be verbose while dumping\n\ -h, --help output help information and exit\n\ -q, --quiet be quiet while dumping (default)\n\ @@ -969,13 +983,14 @@ Dump core from WIN32PID to FILENAME.core\n\ } struct option longopts[] = { + {"nokill", no_argument, NULL, 'n'}, {"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 = "dhqV"; +const char *opts = "ndhqV"; static void print_version () @@ -1001,6 +1016,9 @@ main (int argc, char **argv) while ((opt = getopt_long (argc, argv, opts, longopts, NULL) ) != EOF) switch (opt) { + case 'n': + nokill = TRUE; + break; case 'd': verbose = TRUE; break;