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 6E727393EC2E for ; Wed, 13 May 2020 09:48:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 6E727393EC2E Received: from submission (posteo.de [89.146.220.130]) by mout02.posteo.de (Postfix) with ESMTPS id C14A62400FB for ; Wed, 13 May 2020 11:48:18 +0200 (CEST) Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 49MVGn5ZSmz6tmJ; Wed, 13 May 2020 11:48:17 +0200 (CEST) From: Michael Weghorn To: gdb-patches@sourceware.org Cc: Michael Weghorn Subject: [PATCH v4 3/9] gdbsupport: Let construct_inferior_arguments take gdb::array_view param Date: Wed, 13 May 2020 11:47:52 +0200 Message-Id: <20200513094758.523845-3-m.weghorn@posteo.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200513094758.523845-1-m.weghorn@posteo.de> References: <20200429111638.1327262-1-m.weghorn@posteo.de> <20200513094758.523845-1-m.weghorn@posteo.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, 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, 13 May 2020 09:48:22 -0000 Adapt the construct_inferior_arguments function to take a gdb::array_view parameter instead of a char * array and an int indicating the length and adapt the only call site. This will allow calling it more simply in a follow-up patch introducing more uses of the function. gdbsupport/ChangeLog: 2020-05-13 Michael Weghorn * common-inferior.cc, common-inferior.h (construct_inferior_arguments): Adapt to take a gdb::array_view parameter. Adapt call site. --- gdb/infcmd.c | 5 +++-- gdbsupport/common-inferior.cc | 16 +++++++--------- gdbsupport/common-inferior.h | 5 ++++- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/gdb/infcmd.c b/gdb/infcmd.c index a7c037837c..14066eaae1 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -151,8 +151,9 @@ get_inferior_args (void) { if (current_inferior ()->argc != 0) { - std::string n = construct_inferior_arguments (current_inferior ()->argc, - current_inferior ()->argv); + gdb::array_view args (current_inferior ()->argv, + current_inferior ()->argc); + std::string n = construct_inferior_arguments (args); set_inferior_args (n.c_str ()); } diff --git a/gdbsupport/common-inferior.cc b/gdbsupport/common-inferior.cc index aa8be14c74..a67d1740a2 100644 --- a/gdbsupport/common-inferior.cc +++ b/gdbsupport/common-inferior.cc @@ -28,10 +28,8 @@ bool startup_with_shell = true; /* See common-inferior.h. */ std::string -construct_inferior_arguments (int argc, char * const *argv) +construct_inferior_arguments (gdb::array_view argv) { - gdb_assert (argc >= 0); - std::string result; if (startup_with_shell) @@ -48,7 +46,7 @@ construct_inferior_arguments (int argc, char * const *argv) static const char special[] = "\"!#$&*()\\|[]{}<>?'`~^; \t\n"; static const char quote = '\''; #endif - for (int i = 0; i < argc; ++i) + for (int i = 0; i < argv.size (); ++i) { if (i > 0) result += ' '; @@ -103,19 +101,19 @@ construct_inferior_arguments (int argc, char * const *argv) { /* In this case we can't handle arguments that contain spaces, tabs, or newlines -- see breakup_args(). */ - for (int i = 0; i < argc; ++i) + for (char *arg : argv) { - char *cp = strchr (argv[i], ' '); + char *cp = strchr (arg, ' '); if (cp == NULL) - cp = strchr (argv[i], '\t'); + cp = strchr (arg, '\t'); if (cp == NULL) - cp = strchr (argv[i], '\n'); + cp = strchr (arg, '\n'); if (cp != NULL) error (_("can't handle command-line " "argument containing whitespace")); } - for (int i = 0; i < argc; ++i) + for (int i = 0; i < argv.size (); ++i) { if (i > 0) result += " "; diff --git a/gdbsupport/common-inferior.h b/gdbsupport/common-inferior.h index 5e9fc8b0b9..4362934cef 100644 --- a/gdbsupport/common-inferior.h +++ b/gdbsupport/common-inferior.h @@ -21,6 +21,8 @@ #ifndef COMMON_COMMON_INFERIOR_H #define COMMON_COMMON_INFERIOR_H +#include "gdbsupport/array-view.h" + /* Return the exec wrapper to be used when starting the inferior, or NULL otherwise. */ extern const char *get_exec_wrapper (); @@ -60,6 +62,7 @@ extern bool startup_with_shell; /* Compute command-line string given argument vector. This does the same shell processing as fork_inferior. */ -extern std::string construct_inferior_arguments (int, char * const *); +extern std::string +construct_inferior_arguments (gdb::array_view); #endif /* COMMON_COMMON_INFERIOR_H */ -- 2.26.2