From patchwork Tue Dec 24 17:39:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eli Zaretskii X-Patchwork-Id: 37087 Received: (qmail 51853 invoked by alias); 24 Dec 2019 17:39:59 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 51839 invoked by uid 89); 24 Dec 2019 17:39:59 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-15.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.1 spammy=regenerate, 9999 X-HELO: eggs.gnu.org Received: from eggs.gnu.org (HELO eggs.gnu.org) (209.51.188.92) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 24 Dec 2019 17:39:57 +0000 Received: from fencepost.gnu.org ([2001:470:142:3::e]:47451) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ijo9z-0006qx-SZ for gdb-patches@sourceware.org; Tue, 24 Dec 2019 12:39:55 -0500 Received: from [176.228.60.248] (port=4196 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1ijo9z-00043X-6i for gdb-patches@sourceware.org; Tue, 24 Dec 2019 12:39:55 -0500 Date: Tue, 24 Dec 2019 19:39:41 +0200 Message-Id: <83y2v1vd0i.fsf@gnu.org> From: Eli Zaretskii To: gdb-patches@sourceware.org Subject: [PATCH] Fix program invocation by gdbserver on MS-Windows X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-IsSubscribed: yes gdbserver doesn't construct the command-line correctly when it invokes programs on MS-Windows. For example, if you invoke gdbserver :9999 etags.exe --help and then connect from GDB and run the inferior, you will see: Remote debugging from host 127.0.0.1, port 3546 --help: no input files specified. Try '--help --help' for a complete list of options. Child exited with status 1 Which means that (a) the program exited abnormally; and (b) it received "--help" in argv[0]. This is because the way we construct the command line in win32-low.c is incorrect: we should prepend the program's name to the arguments. The patch below does that. OK to commit it? diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog index 028d1e9..29de8b6 100644 --- a/gdb/gdbserver/ChangeLog +++ b/gdb/gdbserver/ChangeLog @@ -1,3 +1,10 @@ +2019-12-24 Eli Zaretskii + + * win32-low.c (create_process): Prepend PROGRAM to ARGS when + preparing the command line for CreateProcess. + (win32_create_inferior): Reflect the program name in debugging + output that shows the process and its command line. + 2019-12-19 Christian Biesinger * configure: Regenerate. diff --git a/gdb/gdbserver/win32-low.c b/gdb/gdbserver/win32-low.c index 449ed5f..9aaed84 100644 --- a/gdb/gdbserver/win32-low.c +++ b/gdb/gdbserver/win32-low.c @@ -557,21 +557,25 @@ create_process (const char *program, char *args, { const char *inferior_cwd = get_inferior_cwd (); BOOL ret; + size_t argslen, proglen; + + proglen = strlen (program) + 1; + argslen = strlen (args) + proglen; #ifdef _WIN32_WCE wchar_t *p, *wprogram, *wargs, *wcwd = NULL; - size_t argslen; - wprogram = alloca ((strlen (program) + 1) * sizeof (wchar_t)); - mbstowcs (wprogram, program, strlen (program) + 1); + wprogram = (wchar_t *) alloca (proglen * sizeof (wchar_t)); + mbstowcs (wprogram, program, proglen); for (p = wprogram; *p; ++p) if (L'/' == *p) *p = L'\\'; - argslen = strlen (args); wargs = alloca ((argslen + 1) * sizeof (wchar_t)); - mbstowcs (wargs, args, argslen + 1); + wcscpy (wargs, wprogram); + wcscat (wargs, L" "); + mbstowcs (wargs + proglen, args, argslen + 1 - proglen); if (inferior_cwd != NULL) { @@ -599,20 +603,24 @@ Could not convert the expanded inferior cwd to wide-char.")); pi); /* proc info */ #else STARTUPINFOA si = { sizeof (STARTUPINFOA) }; - - ret = CreateProcessA (program, /* image name */ - args, /* command line */ - NULL, /* security */ - NULL, /* thread */ - TRUE, /* inherit handles */ - flags, /* start flags */ - NULL, /* environment */ + char *program_and_args = (char *) alloca (argslen + 1); + + strcpy (program_and_args, program); + strcat (program_and_args, " "); + strcat (program_and_args, args); + ret = CreateProcessA (program, /* image name */ + program_and_args, /* command line */ + NULL, /* security */ + NULL, /* thread */ + TRUE, /* inherit handles */ + flags, /* start flags */ + NULL, /* environment */ /* current directory */ (inferior_cwd == NULL ? NULL : gdb_tilde_expand (inferior_cwd).c_str()), - &si, /* start info */ - pi); /* proc info */ + &si, /* start info */ + pi); /* proc info */ #endif return ret; @@ -663,7 +671,7 @@ win32_create_inferior (const char *program, program = real_path; #endif - OUTMSG2 (("Command line is \"%s\"\n", args)); + OUTMSG2 (("Command line is \"%s %s\"\n", program, args)); #ifdef CREATE_NEW_PROCESS_GROUP flags |= CREATE_NEW_PROCESS_GROUP; @@ -686,12 +694,12 @@ win32_create_inferior (const char *program, if (!ret) { - error ("Error creating process \"%s%s\", (error %d): %s\n", + error ("Error creating process \"%s %s\", (error %d): %s\n", program, args, (int) err, strwinerror (err)); } else { - OUTMSG2 (("Process created: %s\n", (char *) args)); + OUTMSG2 (("Process created: %s %s\n", program, (char *) args)); } #ifndef _WIN32_WCE