From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout01.posteo.de (mout01.posteo.de [185.67.36.65]) by sourceware.org (Postfix) with ESMTPS id 1587E3893648 for ; Wed, 29 Apr 2020 11:16:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 1587E3893648 Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id F2125160062 for ; Wed, 29 Apr 2020 13:16:53 +0200 (CEST) Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 49BwvT2B3Nz6tml; Wed, 29 Apr 2020 13:16:53 +0200 (CEST) From: Michael Weghorn To: gdb-patches@sourceware.org Subject: [PATCH 1/4] gdbsupport: Extend construct_inferior_arguments to allow handling all stringify_args cases Date: Wed, 29 Apr 2020 13:16:35 +0200 Message-Id: <20200429111638.1327262-3-m.weghorn@posteo.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200429111638.1327262-1-m.weghorn@posteo.de> References: <20200429111638.1327262-1-m.weghorn@posteo.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-21.8 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: Wed, 29 Apr 2020 11:17:02 -0000 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 | 5 ++--- gdbsupport/common-inferior.cc | 19 +++++++++++-------- gdbsupport/common-inferior.h | 2 +- 3 files changed, 14 insertions(+), 12 deletions(-) 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; 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