From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qt1-x841.google.com (mail-qt1-x841.google.com [IPv6:2607:f8b0:4864:20::841]) by sourceware.org (Postfix) with ESMTPS id 8F319395A82A for ; Wed, 29 Apr 2020 15:26:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 8F319395A82A Received: by mail-qt1-x841.google.com with SMTP id i68so2159900qtb.5 for ; Wed, 29 Apr 2020 08:26:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=G+j9I1NsWbP3gtxxOi29mrTgVVdteabrGYFIgGZZcLc=; b=sAPPdqBYdzST632iDYeJLmMRkkX5g+5NAuF0C9cRllNhajsp4f1uRgQHs7u0it25Nr OcszFK8Eb5BziOqczDVTo/93VDhex455HGqlPb09LI9sbqXrfH+d4XU1D3X+maIeRcNQ 6efejrn5JP+ZD20pjL/2tB4CrlraneYPSpFRHzwHoKMdYGeXifmjEOvBIAg98uDNhJzY k5SKbkgg3hF9OHpcdIaVqA25ZunLSU6KlVEZnWGisE70Z1IDzeic9dt4JM0bT2lxPTJO H32MSEvKrWLoD7vB4nh2/f0wC5BzHUHVTQdH+EpS+5eJQ2yFYSyPFmuMAKaQFiT1vdBt yXzg== X-Gm-Message-State: AGi0PuYF9OR7Y1KrXXEy2RT3XlEVPr8mDO23AKVvOpb21NTHVhnNz2PQ r6rLks8e0wj5I9DIv942fHopX6R+/b6IUplHTt2fjkKp X-Google-Smtp-Source: APiQypK+TlkiQkPiSlw0FfqdlWqwTuM/jxSk8+BxQ+Fu11KFPN3WE1LmeZ2nFa8iIeMswq9pf78d8enZBKI5hiSG6h4= X-Received: by 2002:ac8:67d2:: with SMTP id r18mr34565145qtp.161.1588173992703; Wed, 29 Apr 2020 08:26:32 -0700 (PDT) MIME-Version: 1.0 References: <20200429111638.1327262-1-m.weghorn@posteo.de> <20200429111638.1327262-3-m.weghorn@posteo.de> In-Reply-To: <20200429111638.1327262-3-m.weghorn@posteo.de> From: Christian Biesinger Date: Wed, 29 Apr 2020 10:25:55 -0500 Message-ID: Subject: Re: [PATCH 1/4] gdbsupport: Extend construct_inferior_arguments to allow handling all stringify_args cases To: Michael Weghorn Cc: gdb-patches Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-34.6 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL 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 15:26:35 -0000 On Wed, Apr 29, 2020 at 6:17 AM Michael Weghorn via Gdb-patches wrote: > > 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. Can you clarify which revision your patch is against? My files look nothing like the ones you are patching. > 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; While changing this, I would just move the declaration to the line where it is first used. > > 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 >