From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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) From: Simon Marchi 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-Spam-Status: No, score=-16.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_QUARANTINE, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_SOFTFAIL, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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, 14 Jul 2021 04:55:25 -0000 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