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 0488F3857813 for ; Wed, 14 Jul 2021 04:55:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0488F3857813 X-ASG-Debug-ID: 1626238521-0c856e67e219ef240001-fS2M51 Received: from smtp.ebox.ca (smtp.ebox.ca [96.127.255.82]) by barracuda.ebox.ca with ESMTP id ZRfHOb4asEAzb8lY (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 833EA441D64; 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 07/16] gdb: add setter/getter for inferior arguments Date: Wed, 14 Jul 2021 00:55:11 -0400 X-ASG-Orig-Subj: [PATCH 07/16] gdb: add setter/getter for inferior arguments Message-Id: <20210714045520.1623120-8-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-Virus-Scanned: by bsmtpd at ebox.ca X-Barracuda-Scan-Msg-Size: 7808 X-Barracuda-BRTS-Status: 1 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:26 -0000 Add args/set_args to the inferior class, remove the set_inferior_args and get_inferior_args functions, that would just be wrappers around them. Change-Id: If87d52f3402ce08be26c32897ae8915d9f6d1ea3 --- gdb/elf-none-tdep.c | 2 +- gdb/fbsd-tdep.c | 2 +- gdb/infcmd.c | 34 +++++++--------------------------- gdb/inferior.h | 36 +++++++++++++++++++++++++++++------- gdb/linux-tdep.c | 3 +-- gdb/procfs.c | 2 +- 6 files changed, 40 insertions(+), 39 deletions(-) diff --git a/gdb/elf-none-tdep.c b/gdb/elf-none-tdep.c index 52a6281290fa..0d94dc430403 100644 --- a/gdb/elf-none-tdep.c +++ b/gdb/elf-none-tdep.c @@ -49,7 +49,7 @@ elf_none_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, fname = lbasename (exe); psargs = std::string (exe); - const char *infargs = get_inferior_args (); + const char *infargs = current_inferior ()->args (); if (infargs != nullptr) psargs += " " + std::string (infargs); diff --git a/gdb/fbsd-tdep.c b/gdb/fbsd-tdep.c index eb792c36a54d..141d23662838 100644 --- a/gdb/fbsd-tdep.c +++ b/gdb/fbsd-tdep.c @@ -684,7 +684,7 @@ fbsd_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size) const char *fname = lbasename (get_exec_file (0)); std::string psargs = fname; - const char *infargs = get_inferior_args (); + const char *infargs = current_inferior ()->args (); if (infargs != NULL) psargs = psargs + " " + infargs; diff --git a/gdb/infcmd.c b/gdb/infcmd.c index 05115958a8f8..1407a3ea4664 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -124,33 +124,12 @@ show_inferior_tty_command (struct ui_file *file, int from_tty, "is \"%s\".\n"), inferior_tty); } -const char * -get_inferior_args (void) -{ - if (current_inferior ()->args == nullptr) - return ""; - - return current_inferior ()->args.get (); -} - -/* Set the arguments for the current inferior. Ownership of - NEWARGS is not transferred. */ - -void -set_inferior_args (const char *newargs) -{ - if (newargs != nullptr) - current_inferior ()->args = make_unique_xstrdup (newargs); - else - current_inferior ()->args.reset (); -} - void set_inferior_args_vector (int argc, char **argv) { gdb::array_view args (argv, argc); std::string n = construct_inferior_arguments (args); - set_inferior_args (n.c_str ()); + current_inferior ()->set_args (n.c_str ()); } /* Notice when `set args' is run. */ @@ -160,7 +139,7 @@ set_args_command (const char *args, int from_tty, struct cmd_list_element *c) { /* CLI has assigned the user-provided value to inferior_args_scratch. Now route it to current inferior. */ - set_inferior_args (inferior_args_scratch); + current_inferior ()->set_args (inferior_args_scratch); } /* Notice when `show args' is run. */ @@ -171,7 +150,8 @@ show_args_command (struct ui_file *file, int from_tty, { /* Note that we ignore the passed-in value in favor of computing it directly. */ - deprecated_show_value_hack (file, from_tty, c, get_inferior_args ()); + deprecated_show_value_hack (file, from_tty, c, + current_inferior ()->args ()); } /* Set the inferior current working directory. If CWD is NULL, unset @@ -471,7 +451,7 @@ run_command_1 (const char *args, int from_tty, enum run_how run_how) /* If there were other args, beside '&', process them. */ if (args != NULL) - set_inferior_args (args); + current_inferior ()->set_args (args); if (from_tty) { @@ -480,13 +460,13 @@ 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); - uiout->field_string ("infargs", get_inferior_args ()); + uiout->field_string ("infargs", current_inferior ()->args ()); uiout->text ("\n"); uiout->flush (); } run_target->create_inferior (exec_file, - std::string (get_inferior_args ()), + current_inferior ()->args (), current_inferior ()->environment.envp (), from_tty); /* to_create_inferior should push the target, so after this point we diff --git a/gdb/inferior.h b/gdb/inferior.h index af03887d63b3..c90abae73dbe 100644 --- a/gdb/inferior.h +++ b/gdb/inferior.h @@ -204,10 +204,6 @@ extern void post_create_inferior (int from_tty); extern void attach_command (const char *, int); -extern const char *get_inferior_args (void); - -extern void set_inferior_args (const char *); - extern void set_inferior_args_vector (int, char **); extern void registers_info (const char *, int); @@ -446,6 +442,30 @@ class inferior : public refcounted_object, void set_tty (const char *terminal_name); const char *tty (); + /* Set the argument string to use when running this inferior. + + Either nullptr or an empty string can be used to represent "no + arguments". */ + void set_args (const char *args) + { + if (args != nullptr && args[0] != '\0') + m_args = make_unique_xstrdup (args); + else + m_args.reset (); + }; + + /* Get the argument string to use when running this inferior. + + The return value is always non-nullptr. No arguments is represented by + an empty string. */ + const char *args () const + { + if (m_args == nullptr) + return ""; + + return m_args.get (); + } + /* Convenient handle (GDB inferior id). Unique across all inferiors. */ int num = 0; @@ -475,9 +495,6 @@ class inferior : public refcounted_object, /* The program space bound to this inferior. */ struct program_space *pspace = NULL; - /* The arguments string to use when running. */ - gdb::unique_xmalloc_ptr args; - /* The current working directory that will be used when starting this inferior. */ gdb::unique_xmalloc_ptr cwd; @@ -569,6 +586,11 @@ class inferior : public refcounted_object, /* The list of continuations. */ std::list> m_continuations; + + /* The arguments string to use when running. + + This is nullptr when there are not args. */ + gdb::unique_xmalloc_ptr m_args; }; /* Keep a registry of per-inferior data-pointers required by other GDB diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c index 8c0885ed5b49..99e868eed6e6 100644 --- a/gdb/linux-tdep.c +++ b/gdb/linux-tdep.c @@ -1804,7 +1804,6 @@ linux_fill_prpsinfo (struct elf_internal_linux_prpsinfo *p) char filename[100]; /* The basename of the executable. */ const char *basename; - const char *infargs; /* Temporary buffer. */ char *tmpstr; /* The valid states of a process, according to the Linux kernel. */ @@ -1848,7 +1847,7 @@ linux_fill_prpsinfo (struct elf_internal_linux_prpsinfo *p) strncpy (p->pr_fname, basename, sizeof (p->pr_fname) - 1); p->pr_fname[sizeof (p->pr_fname) - 1] = '\0'; - infargs = get_inferior_args (); + const char *infargs = current_inferior ()->args (); /* The arguments of the program. */ std::string psargs = fname.get (); diff --git a/gdb/procfs.c b/gdb/procfs.c index 529ee33df900..d764c95d422a 100644 --- a/gdb/procfs.c +++ b/gdb/procfs.c @@ -3613,7 +3613,7 @@ procfs_target::make_corefile_notes (bfd *obfd, int *note_size) strncpy (psargs, get_exec_file (0), sizeof (psargs)); psargs[sizeof (psargs) - 1] = 0; - inf_args = get_inferior_args (); + inf_args = current_inferior ()->args (); if (inf_args && *inf_args && (strlen (inf_args) < ((int) sizeof (psargs) - (int) strlen (psargs)))) -- 2.32.0