From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout02.posteo.de (mout02.posteo.de [185.67.36.66]) by sourceware.org (Postfix) with ESMTPS id C800B3896805 for ; Thu, 30 Apr 2020 06:02:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org C800B3896805 Received: from submission (posteo.de [89.146.220.130]) by mout02.posteo.de (Postfix) with ESMTPS id ED3E82400FB for ; Thu, 30 Apr 2020 08:02:15 +0200 (CEST) Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 49CPsy4vRyz6tmL; Thu, 30 Apr 2020 08:02:14 +0200 (CEST) Subject: [PATCH v2 1/4] gdbsupport: Extend construct_inferior_arguments to allow handling all stringify_args cases To: Christian Biesinger , gdb-patches References: <20200429111638.1327262-1-m.weghorn@posteo.de> <20200429111638.1327262-3-m.weghorn@posteo.de> From: Michael Weghorn Message-ID: Date: Thu, 30 Apr 2020 08:02:14 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-24.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Apr 2020 06:02:21 -0000 On 29/04/2020 17.25, Christian Biesinger wrote: >> diff --git a/gdb/infcmd.c b/gdb/infcmd.c >> index 8f7482347c..7ad931f9b4 100644 >> --- a/gdb/infcmd.c >> +++ b/gdb/infcmd.c >> @@ -151,12 +151,11 @@ get_inferior_args (void) >> { >> if (current_inferior ()->argc != 0) >> { >> - char *n; >> + std::string n; > > While changing this, I would just move the declaration to the line > where it is first used. > Done now. A new version of the patch follows. (I haven't updated the other patches of the series, since those remain unchanged.) --- Allow construct_inferior_arguments to handle zero args and have it return a std::string, similar to how stringify_argv in gdbsupport/common-utils does. Also, add a const qualifier for the second parameter, since it is only read, not written to. The intention is to replace some existing uses of stringify_argv by construct_inferior_arguments in a subsequent step, since construct_inferior_arguments properly handles special characters, while stringify_argv doesn't. 2020-04-29 Michael Weghorn * common-inferior.cc, common-inferior.h (construct_inferior_arguments): Adapt to handle zero args and return a std::string. Adapt call site. --- gdb/infcmd.c | 7 ++----- gdbsupport/common-inferior.cc | 19 +++++++++++-------- gdbsupport/common-inferior.h | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/gdb/infcmd.c b/gdb/infcmd.c index 8f7482347c..3ac64b3164 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -151,12 +151,9 @@ get_inferior_args (void) { if (current_inferior ()->argc != 0) { - char *n; - - n = construct_inferior_arguments (current_inferior ()->argc, + std::string n = construct_inferior_arguments (current_inferior ()->argc, current_inferior ()->argv); - set_inferior_args (n); - xfree (n); + set_inferior_args (n.c_str()); } if (current_inferior ()->args == NULL) diff --git a/gdbsupport/common-inferior.cc b/gdbsupport/common-inferior.cc index 71b9a11e02..3f117d5ef0 100644 --- a/gdbsupport/common-inferior.cc +++ b/gdbsupport/common-inferior.cc @@ -28,15 +28,15 @@ bool startup_with_shell = true; /* Compute command-line string given argument vector. This does the same shell processing as fork_inferior. */ -char * -construct_inferior_arguments (int argc, char **argv) +std::string +construct_inferior_arguments (int argc, char * const *argv) { - char *result; + gdb_assert (argc >= 0); + if (argc == 0 || argv[0] == NULL) { + return ""; + } - /* ARGC should always be at least 1, but we double check this - here. This is also needed to silence -Werror-stringop - warnings. */ - gdb_assert (argc > 0); + char *result; if (startup_with_shell) { @@ -145,5 +145,8 @@ construct_inferior_arguments (int argc, char **argv) } } - return result; + std::string str_result(result); + xfree (result); + + return str_result; } diff --git a/gdbsupport/common-inferior.h b/gdbsupport/common-inferior.h index eb60c8f13b..0b11e7d6a5 100644 --- a/gdbsupport/common-inferior.h +++ b/gdbsupport/common-inferior.h @@ -58,6 +58,6 @@ extern void set_inferior_cwd (const char *cwd); the target is started up with a shell. */ extern bool startup_with_shell; -extern char *construct_inferior_arguments (int, char **); +extern std::string construct_inferior_arguments (int, char * const *); #endif /* COMMON_COMMON_INFERIOR_H */ -- 2.26.2