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 10EB838930E9 for ; Wed, 29 Apr 2020 15:46:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 10EB838930E9 Received: by mail-qt1-x841.google.com with SMTP id c23so2189305qtp.11 for ; Wed, 29 Apr 2020 08:46:00 -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=ujVDmK4qH2mUXu5iRN+0QZgXNnLl16kH62Tmms4EEPc=; b=ghUrxSfIwI/VoY5gfGson5OehNiLZSVCo3L9ie4p43BpYN11ueoMT2rUSdkGaVkg7Y GAaUtrUEhrMDeXaaHuEih6qW1sYCM0yp+dGGCrAKbEEQIqeh61vtuSVUb/cYp1gALnQU Rx7MF01o8kxzlFNXfzBay4dVKmEFfDpO0dLlD4cfvIDvqV+Z73+L8nfdzRDOl8KfddAm xDJChanX9kSdFDAxtKnu8yXK2SPbj4o3AjwTqUt6hux+AdA+JJVeGd4h9yQwogJub7xS OH+R5rJNJ4VUEZE3Irl0rnldltwb0AKNoD4zezxmmlqu+RMzRqoOIAL1tkCWTyNhaGhT Yy6A== X-Gm-Message-State: AGi0PuaxtwgG5Ag7oduHLIo7P453boLvnCjaauu0/4RkEbpvB6d7kcw3 FFiC2UhxwGcOl3mts8x7a+ntMjikFIOC1ZtV4U0dBQ== X-Google-Smtp-Source: APiQypLKSTThEC4e3Yxt69vdGxDIdFH6Rv4le5Fcm7ihYqZRNcjV4tvfOyCmEECq/D+sBy0YwOtMfbmFeA5JqIqyhoM= X-Received: by 2002:ac8:6b53:: with SMTP id x19mr33965699qts.322.1588175159299; Wed, 29 Apr 2020 08:45:59 -0700 (PDT) MIME-Version: 1.0 References: <20200429111638.1327262-1-m.weghorn@posteo.de> <20200429111638.1327262-3-m.weghorn@posteo.de> In-Reply-To: From: Christian Biesinger Date: Wed, 29 Apr 2020 10:45:22 -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=-35.2 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:46:10 -0000 On Wed, Apr 29, 2020 at 10:25 AM Christian Biesinger wrote: > > 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. Oh, I see now that this patch applies on top of the other patch series you sent. > > 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 > >