From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id iGE4M6Ru7mCsIgAAWB0awg (envelope-from ) for ; Wed, 14 Jul 2021 00:57:08 -0400 Received: by simark.ca (Postfix, from userid 112) id CF46A1E54D; Wed, 14 Jul 2021 00:57:08 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 1F3591E54D for ; Wed, 14 Jul 2021 00:57:08 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CCA413855038 for ; Wed, 14 Jul 2021 04:57:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CCA413855038 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1626238627; bh=yYZWLKhgiDQGLP7mVD5MNUCkQZcqmnMC808J4cYc6to=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=I7bEWGCJxzpqDv9aHt8BqyfqnOdQw9AogGzOKJZRgS+BLRNwts5ClChZMEmotS1XQ XGX9FLNYnGdScw9IRK/R7G/j0DgXZG8016C9xZI57iLd09bl8iJAuR//SwR1rVle9R G4IDMO0swSTNeWIiyZ0zaxHiRZUQ7VgiwhpJTa4I= Received: from barracuda.ebox.ca (barracuda.ebox.ca [96.127.255.19]) by sourceware.org (Postfix) with ESMTPS id 457EE3857423 for ; Wed, 14 Jul 2021 04:55:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 457EE3857423 X-ASG-Debug-ID: 1626238521-0c856e6cd51c9e4e0001-fS2M51 Received: from smtp.ebox.ca (smtp.ebox.ca [96.127.255.82]) by barracuda.ebox.ca with ESMTP id K1Wyy02xN1WwyoT2 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 14 Jul 2021 00:55:21 -0400 (EDT) X-Barracuda-Envelope-From: simon.marchi@polymtl.ca X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from simark.localdomain (192-222-157-6.qc.cable.ebox.net [192.222.157.6]) by smtp.ebox.ca (Postfix) with ESMTP id 711C0441B21; Wed, 14 Jul 2021 00:55:21 -0400 (EDT) X-Barracuda-RBL-IP: 192.222.157.6 X-Barracuda-Effective-Source-IP: 192-222-157-6.qc.cable.ebox.net[192.222.157.6] X-Barracuda-Apparent-Source-IP: 192.222.157.6 To: gdb-patches@sourceware.org Subject: [PATCH 06/16] gdb: remove inferior::{argc,argv} Date: Wed, 14 Jul 2021 00:55:10 -0400 X-ASG-Orig-Subj: [PATCH 06/16] gdb: remove inferior::{argc,argv} Message-Id: <20210714045520.1623120-7-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210714045520.1623120-1-simon.marchi@polymtl.ca> References: <20210714045520.1623120-1-simon.marchi@polymtl.ca> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Barracuda-Connect: smtp.ebox.ca[96.127.255.82] X-Barracuda-Start-Time: 1626238521 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://96.127.255.19:443/cgi-mod/mark.cgi X-Barracuda-BRTS-Status: 1 X-Virus-Scanned: by bsmtpd at ebox.ca X-Barracuda-Scan-Msg-Size: 3798 X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=8.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.91193 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 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: , From: Simon Marchi via Gdb-patches Reply-To: Simon Marchi Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" There are currently two states that the inferior args can be stored. The main one is the `args` field, where they are stored as a single string. The other one is the `argc`/`argv` fields. This last one is only used for arguments passed in GDB's command line. And the only outcome is that when get_inferior_args is called, `argc`/`argv` are serialized into `args`. So really, `argc`/`argv` is just a staging area before moving the arguments in `args`. Simplify this by only keeping the `args` field. Change set_inferior_args_vector to immediately serialize the arguments into `args`, work that would be done in get_inferior_args later anyway. The only time where this work would be "wasted" is when the user passes some arguments on the command line, but does not end up running the program. But that just seems unlikely. And it's not that much work. Change-Id: Ica0b9859397c095f6530350c8fb3c36905f2044a --- gdb/infcmd.c | 24 +++++------------------- gdb/inferior.h | 9 --------- 2 files changed, 5 insertions(+), 28 deletions(-) diff --git a/gdb/infcmd.c b/gdb/infcmd.c index a7b520cdd169..05115958a8f8 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -127,16 +127,8 @@ show_inferior_tty_command (struct ui_file *file, int from_tty, const char * get_inferior_args (void) { - if (current_inferior ()->argc != 0) - { - gdb::array_view args (current_inferior ()->argv, - current_inferior ()->argc); - std::string n = construct_inferior_arguments (args); - set_inferior_args (n.c_str ()); - } - - if (current_inferior ()->args == NULL) - current_inferior ()->args = make_unique_xstrdup (""); + if (current_inferior ()->args == nullptr) + return ""; return current_inferior ()->args.get (); } @@ -151,16 +143,14 @@ set_inferior_args (const char *newargs) current_inferior ()->args = make_unique_xstrdup (newargs); else current_inferior ()->args.reset (); - - current_inferior ()->argc = 0; - current_inferior ()->argv = 0; } void set_inferior_args_vector (int argc, char **argv) { - current_inferior ()->argc = argc; - current_inferior ()->argv = argv; + gdb::array_view args (argv, argc); + std::string n = construct_inferior_arguments (args); + set_inferior_args (n.c_str ()); } /* Notice when `set args' is run. */ @@ -490,15 +480,11 @@ run_command_1 (const char *args, int from_tty, enum run_how run_how) if (exec_file) uiout->field_string ("execfile", exec_file); uiout->spaces (1); - /* We call get_inferior_args() because we might need to compute - the value now. */ uiout->field_string ("infargs", get_inferior_args ()); uiout->text ("\n"); uiout->flush (); } - /* We call get_inferior_args() because we might need to compute - the value now. */ run_target->create_inferior (exec_file, std::string (get_inferior_args ()), current_inferior ()->environment.envp (), diff --git a/gdb/inferior.h b/gdb/inferior.h index 6662a3bde463..af03887d63b3 100644 --- a/gdb/inferior.h +++ b/gdb/inferior.h @@ -478,15 +478,6 @@ class inferior : public refcounted_object, /* The arguments string to use when running. */ gdb::unique_xmalloc_ptr args; - /* The size of elements in argv. */ - int argc = 0; - - /* The vector version of arguments. If ARGC is nonzero, - then we must compute ARGS from this (via the target). - This is always coming from main's argv and therefore - should never be freed. */ - char **argv = NULL; - /* The current working directory that will be used when starting this inferior. */ gdb::unique_xmalloc_ptr cwd; -- 2.32.0