From: Simon Marchi via Gdb-patches <gdb-patches@sourceware.org>
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 [thread overview]
Message-ID: <20210714045520.1623120-9-simon.marchi@polymtl.ca> (raw)
In-Reply-To: <20210714045520.1623120-1-simon.marchi@polymtl.ca>
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<char> 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<char> m_args;
+
+ /* The current working directory that will be used when starting
+ this inferior. */
+ gdb::unique_xmalloc_ptr<char> 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
next prev parent reply other threads:[~2021-07-14 4:59 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-14 4:55 [PATCH 00/16] Bunch of commands related cleanups Simon Marchi via Gdb-patches
2021-07-14 4:55 ` [PATCH 01/16] gdb/testsuite: split gdb.python/py-parameter.exp in procs Simon Marchi via Gdb-patches
2021-07-14 4:55 ` [PATCH 02/16] gdb.base/setshow.exp: use save_vars to save/restore gdb_prompt Simon Marchi via Gdb-patches
2021-07-14 4:55 ` [PATCH 03/16] gdb.base/setshow.exp: split in procs Simon Marchi via Gdb-patches
2021-07-14 4:55 ` [PATCH 04/16] gdb.base/setshow.exp: fix duplicate test name Simon Marchi via Gdb-patches
2021-07-14 4:55 ` [PATCH 05/16] gdb: un-share set_inferior_cwd declaration Simon Marchi via Gdb-patches
2021-07-14 4:55 ` [PATCH 06/16] gdb: remove inferior::{argc,argv} Simon Marchi via Gdb-patches
2021-07-14 4:55 ` [PATCH 07/16] gdb: add setter/getter for inferior arguments Simon Marchi via Gdb-patches
2021-07-14 4:55 ` Simon Marchi via Gdb-patches [this message]
2021-07-14 4:55 ` [PATCH 09/16] gdb: make inferior::m_args an std::string Simon Marchi via Gdb-patches
2021-07-14 4:55 ` [PATCH 10/16] gdb: make inferior::m_cwd " Simon Marchi via Gdb-patches
2021-07-14 4:55 ` [PATCH 11/16] gdb: make inferior::m_terminal " Simon Marchi via Gdb-patches
2021-07-14 4:55 ` [PATCH 12/16] gdb: rename cfunc to simple_func Simon Marchi via Gdb-patches
2021-07-14 4:55 ` [PATCH 13/16] gdb: remove cmd_list_element::function::sfunc Simon Marchi via Gdb-patches
2021-07-28 19:10 ` Tom Tromey
2021-07-28 21:17 ` Simon Marchi via Gdb-patches
2021-07-29 17:33 ` Tom Tromey
2021-07-14 4:55 ` [PATCH 14/16] gdb/testsuite: test get/set value of unregistered Guile parameter Simon Marchi via Gdb-patches
2021-07-23 19:42 ` Simon Marchi via Gdb-patches
2021-07-14 4:55 ` [PATCH 15/16] gdb: make cmd_list_element var an optional union Simon Marchi via Gdb-patches
2021-07-14 12:08 ` Lancelot SIX via Gdb-patches
2021-07-14 17:12 ` Lancelot SIX via Gdb-patches
2021-07-14 19:22 ` Simon Marchi via Gdb-patches
2021-07-14 23:22 ` Lancelot SIX via Gdb-patches
2021-07-19 14:32 ` Simon Marchi via Gdb-patches
2021-07-19 19:52 ` Simon Marchi via Gdb-patches
2021-07-20 23:03 ` Lancelot SIX via Gdb-patches
2021-07-23 19:56 ` Simon Marchi via Gdb-patches
2021-07-23 20:46 ` Lancelot SIX via Gdb-patches
2021-07-23 21:15 ` Simon Marchi via Gdb-patches
2021-07-23 22:55 ` Lancelot SIX via Gdb-patches
2021-07-24 2:04 ` Simon Marchi via Gdb-patches
2021-07-28 20:13 ` Tom Tromey
2021-07-28 20:45 ` Lancelot SIX via Gdb-patches
2021-07-29 17:47 ` Tom Tromey
2021-07-29 20:12 ` Lancelot SIX via Gdb-patches
2021-07-30 2:09 ` Simon Marchi via Gdb-patches
2021-07-30 17:47 ` Lancelot SIX via Gdb-patches
2021-07-18 15:44 ` Lancelot SIX via Gdb-patches
2021-07-19 14:19 ` Simon Marchi via Gdb-patches
2021-07-19 20:58 ` Lancelot SIX via Gdb-patches
2021-07-28 19:47 ` Tom Tromey
2021-07-28 20:59 ` Simon Marchi via Gdb-patches
2021-07-29 17:41 ` Tom Tromey
2021-07-29 17:44 ` Simon Marchi via Gdb-patches
2021-07-29 17:49 ` Tom Tromey
2021-07-29 18:00 ` Simon Marchi via Gdb-patches
2021-07-14 4:55 ` [PATCH 16/16] gdb: make string-like set show commands use std::string variable Simon Marchi via Gdb-patches
2021-07-28 20:27 ` Tom Tromey
2021-07-28 21:03 ` Simon Marchi via Gdb-patches
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210714045520.1623120-9-simon.marchi@polymtl.ca \
--to=gdb-patches@sourceware.org \
--cc=simon.marchi@polymtl.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox