public inbox for gdb-cvs@sourceware.org help / color / mirror / Atom feed
From: Simon Marchi <simark@sourceware.org> To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdbsupport: Let construct_inferior_arguments take gdb::array_view param Date: Mon, 25 May 2020 15:41:47 +0000 (GMT) [thread overview] Message-ID: <20200525154147.4C299383E80F@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=8c4b5f3d987c80a1746e3f198bb060d7d7671945 commit 8c4b5f3d987c80a1746e3f198bb060d7d7671945 Author: Michael Weghorn <m.weghorn@posteo.de> Date: Mon May 25 11:38:32 2020 -0400 gdbsupport: Let construct_inferior_arguments take gdb::array_view param Adapt the construct_inferior_arguments function to take a gdb::array_view<char * const> 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: * common-inferior.cc, common-inferior.h (construct_inferior_arguments): Adapt to take a gdb::array_view<char * const> parameter. Adapt call site. Change-Id: I1c6496c8c0b0eb3ef3fda96e9e3bd64c5e6cac3c Diff: --- gdb/infcmd.c | 5 +++-- gdbsupport/ChangeLog | 6 ++++++ gdbsupport/common-inferior.cc | 16 +++++++--------- gdbsupport/common-inferior.h | 5 ++++- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/gdb/infcmd.c b/gdb/infcmd.c index ffcc364f649..891da91c806 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<char * const> args (current_inferior ()->argv, + current_inferior ()->argc); + std::string n = construct_inferior_arguments (args); set_inferior_args (n.c_str ()); } diff --git a/gdbsupport/ChangeLog b/gdbsupport/ChangeLog index 67dcdeec07d..61b57ffc456 100644 --- a/gdbsupport/ChangeLog +++ b/gdbsupport/ChangeLog @@ -1,3 +1,9 @@ +2020-05-25 Michael Weghorn <m.weghorn@posteo.de> + + * common-inferior.cc, common-inferior.h (construct_inferior_arguments): + Adapt to take a gdb::array_view<char * const> parameter. + Adapt call site. + 2020-05-25 Michael Weghorn <m.weghorn@posteo.de> * common-inferior.cc, common-inferior.h (construct_inferior_arguments): diff --git a/gdbsupport/common-inferior.cc b/gdbsupport/common-inferior.cc index aa8be14c742..a67d1740a27 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<char * const> 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 5e9fc8b0b91..4362934cefd 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<char * const>); #endif /* COMMON_COMMON_INFERIOR_H */
reply other threads:[~2020-05-25 15:41 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20200525154147.4C299383E80F@sourceware.org \ --to=simark@sourceware.org \ --cc=gdb-cvs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).