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 A5DF73972021 for ; Wed, 14 Jul 2021 04:57:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A5DF73972021 X-ASG-Debug-ID: 1626238641-0c856e6cd51c9e5d0001-fS2M51 Received: from smtp.ebox.ca (smtp.ebox.ca [96.127.255.82]) by barracuda.ebox.ca with ESMTP id Tz7bm8wSz2Lf1nX4 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 14 Jul 2021 00:57: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 9E706441B21; Wed, 14 Jul 2021 00:57: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 08/16] gdb: add setter/getter for inferior cwd Date: Wed, 14 Jul 2021 00:55:12 -0400 X-ASG-Orig-Subj: [PATCH 08/16] gdb: add setter/getter for inferior cwd Message-Id: <20210714045520.1623120-9-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: 1626238641 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: 4647 X-Barracuda-Spam-Score: 0.50 X-Barracuda-Spam-Status: No, SCORE=0.50 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=8.0 tests=BSF_RULE7568M X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.91193 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 0.50 BSF_RULE7568M Custom Rule 7568M X-Spam-Status: No, score=-16.8 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:57:24 -0000 Add cwd/set_cwd to the inferior class, remove set_inferior_args. Keep get_inferior_args, because it is used from fork_inferior, in shared code. The cwd could eventually be passed as a parameter eventually, though, I think that would be cleaner. Change-Id: Ifb72ea865d7e6f9a491308f0d5c1595579d8427e --- gdb/infcmd.c | 24 ++++-------------------- gdb/inferior.h | 27 +++++++++++++++++++++++---- gdb/remote.c | 2 +- gdb/windows-nat.c | 2 +- 4 files changed, 29 insertions(+), 26 deletions(-) diff --git a/gdb/infcmd.c b/gdb/infcmd.c index 1407a3ea4664..be6031d29364 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -154,28 +154,12 @@ show_args_command (struct ui_file *file, int from_tty, current_inferior ()->args ()); } -/* Set the inferior current working directory. If CWD is NULL, unset - the directory. */ - -static void -set_inferior_cwd (const char *cwd) -{ - struct inferior *inf = current_inferior (); - - gdb_assert (inf != NULL); - - if (cwd == NULL) - inf->cwd.reset (); - else - inf->cwd.reset (xstrdup (cwd)); -} - /* See gdbsupport/common-inferior.h. */ const char * get_inferior_cwd () { - return current_inferior ()->cwd.get (); + return current_inferior ()->cwd (); } /* Handle the 'set cwd' command. */ @@ -184,9 +168,9 @@ static void set_cwd_command (const char *args, int from_tty, struct cmd_list_element *c) { if (*inferior_cwd_scratch == '\0') - set_inferior_cwd (NULL); + current_inferior ()->set_cwd (nullptr); else - set_inferior_cwd (inferior_cwd_scratch); + current_inferior ()->set_cwd (inferior_cwd_scratch); } /* Handle the 'show cwd' command. */ @@ -195,7 +179,7 @@ static void show_cwd_command (struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value) { - const char *cwd = get_inferior_cwd (); + const char *cwd = current_inferior ()->cwd (); if (cwd == NULL) fprintf_filtered (gdb_stdout, diff --git a/gdb/inferior.h b/gdb/inferior.h index c90abae73dbe..0b28e7e4766d 100644 --- a/gdb/inferior.h +++ b/gdb/inferior.h @@ -466,6 +466,25 @@ class inferior : public refcounted_object, return m_args.get (); } + /* Set the inferior current working directory. + + If CWD is NULL, unset the directory. */ + void set_cwd (const char *cwd) + { + if (cwd == NULL) + m_cwd.reset (); + else + m_cwd.reset (xstrdup (cwd)); + } + + /* Get the inferior current working directory. + + Return nullptr if the current working directory is not specified. */ + const char *cwd () const + { + return m_cwd.get (); + } + /* Convenient handle (GDB inferior id). Unique across all inferiors. */ int num = 0; @@ -495,10 +514,6 @@ class inferior : public refcounted_object, /* The program space bound to this inferior. */ struct program_space *pspace = NULL; - /* The current working directory that will be used when starting - this inferior. */ - gdb::unique_xmalloc_ptr cwd; - /* The terminal state as set by the last target_terminal::terminal_* call. */ target_terminal_state terminal_state = target_terminal_state::is_ours; @@ -591,6 +606,10 @@ class inferior : public refcounted_object, This is nullptr when there are not args. */ gdb::unique_xmalloc_ptr m_args; + + /* The current working directory that will be used when starting + this inferior. */ + gdb::unique_xmalloc_ptr m_cwd; }; /* Keep a registry of per-inferior data-pointers required by other GDB diff --git a/gdb/remote.c b/gdb/remote.c index 96e2750cd322..a0726a00f05c 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -10397,7 +10397,7 @@ remote_target::extended_remote_set_inferior_cwd () { if (packet_support (PACKET_QSetWorkingDir) != PACKET_DISABLE) { - const char *inferior_cwd = get_inferior_cwd (); + const char *inferior_cwd = current_inferior ()->cwd (); remote_state *rs = get_remote_state (); if (inferior_cwd != NULL) diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index 05d95ea7d6ad..9526149311b1 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -2558,7 +2558,7 @@ windows_nat_target::create_inferior (const char *exec_file, if (!exec_file) error (_("No executable specified, use `target exec'.")); - const char *inferior_cwd = get_inferior_cwd (); + const char *inferior_cwd = current_inferior ()->cwd (); std::string expanded_infcwd; if (inferior_cwd != NULL) { -- 2.32.0