From: Simon Marchi <simon.marchi@polymtl.ca>
To: gdb-patches@sourceware.org
Subject: [PATCH 11/16] gdb: make inferior::m_terminal an std::string
Date: Wed, 14 Jul 2021 00:55:15 -0400 [thread overview]
Message-ID: <20210714045520.1623120-12-simon.marchi@polymtl.ca> (raw)
In-Reply-To: <20210714045520.1623120-1-simon.marchi@polymtl.ca>
Same idea as the previous patch, but for m_terminal.
Change-Id: If9367d5db8c976a4336680adca4ea5bc31ab64d2
---
gdb/infcmd.c | 6 ++----
gdb/inferior.c | 11 ++++-------
gdb/inferior.h | 18 ++++++++++--------
gdb/inflow.c | 46 ++++++++++++++++++---------------------------
gdb/mi/mi-cmd-env.c | 9 ++++++---
gdb/terminal.h | 2 +-
6 files changed, 41 insertions(+), 51 deletions(-)
diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index c02717631643..c183b60e81a8 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -115,13 +115,11 @@ show_inferior_tty_command (struct ui_file *file, int from_tty,
{
/* Note that we ignore the passed-in value in favor of computing it
directly. */
- const char *inferior_tty = current_inferior ()->tty ();
+ const std::string &inferior_tty = current_inferior ()->tty ();
- if (inferior_tty == nullptr)
- inferior_tty = "";
fprintf_filtered (gdb_stdout,
_("Terminal for future runs of program being debugged "
- "is \"%s\".\n"), inferior_tty);
+ "is \"%s\".\n"), inferior_tty.c_str ());
}
void
diff --git a/gdb/inferior.c b/gdb/inferior.c
index 74b1c65fa3da..40ab3e7e90b9 100644
--- a/gdb/inferior.c
+++ b/gdb/inferior.c
@@ -111,18 +111,15 @@ inferior::unpush_target (struct target_ops *t)
}
void
-inferior::set_tty (const char *terminal_name)
+inferior::set_tty (std::string terminal_name)
{
- if (terminal_name != nullptr && *terminal_name != '\0')
- m_terminal = make_unique_xstrdup (terminal_name);
- else
- m_terminal = NULL;
+ m_terminal = std::move (terminal_name);
}
-const char *
+const std::string &
inferior::tty ()
{
- return m_terminal.get ();
+ return m_terminal;
}
void
diff --git a/gdb/inferior.h b/gdb/inferior.h
index c52c38caa93e..2efe66ac009a 100644
--- a/gdb/inferior.h
+++ b/gdb/inferior.h
@@ -434,13 +434,15 @@ class inferior : public refcounted_object,
void add_continuation (std::function<void ()> &&cont);
void do_all_continuations ();
- /* Set/get file name for default use for standard in/out in the
- inferior. On Unix systems, we try to make TERMINAL_NAME the
- inferior's controlling terminal. If TERMINAL_NAME is nullptr or
- the empty string, then the inferior inherits GDB's terminal (or
- GDBserver's if spawning a remote process). */
- void set_tty (const char *terminal_name);
- const char *tty ();
+ /* Set/get file name for default use for standard in/out in the inferior.
+
+ On Unix systems, we try to make TERMINAL_NAME the inferior's controlling
+ terminal.
+
+ If TERMINAL_NAME is the empty string, then the inferior inherits GDB's
+ terminal (or GDBserver's if spawning a remote process). */
+ void set_tty (std::string terminal_name);
+ const std::string &tty ();
/* Set the argument string to use when running this inferior.
@@ -587,7 +589,7 @@ class inferior : public refcounted_object,
target_stack m_target_stack;
/* The name of terminal device to use for I/O. */
- gdb::unique_xmalloc_ptr<char> m_terminal;
+ std::string m_terminal;
/* The list of continuations. */
std::list<std::function<void ()>> m_continuations;
diff --git a/gdb/inflow.c b/gdb/inflow.c
index 970450632159..74dda702a8a9 100644
--- a/gdb/inflow.c
+++ b/gdb/inflow.c
@@ -65,7 +65,7 @@ struct terminal_info
/* The name of the tty (from the `tty' command) that we gave to the
inferior when it was started. */
- char *run_terminal = nullptr;
+ std::string run_terminal;
/* TTY state. We save it whenever the inferior stops, and restore
it when it resumes in the foreground. */
@@ -123,7 +123,7 @@ static sighandler_t sigquit_ours;
be) used as a transient global by new_tty_prefork,
create_tty_session, new_tty and new_tty_postfork, all called from
fork_inferior, while forking a new child. */
-static const char *inferior_thisrun_terminal;
+static std::string inferior_thisrun_terminal;
/* Track who owns GDB's terminal (is it GDB or some inferior?). While
target_terminal::is_ours() etc. tracks the core's intention and is
@@ -303,8 +303,8 @@ sharing_input_terminal (inferior *inf)
output was redirected to our terminal), and with a false
positive we just end up trying to save/restore terminal
settings when we didn't need to or we actually can't. */
- if (tinfo->run_terminal != NULL)
- res = is_gdb_terminal (tinfo->run_terminal);
+ if (!tinfo->run_terminal.empty ())
+ res = is_gdb_terminal (tinfo->run_terminal.c_str ());
/* If we still can't determine, assume yes. */
if (res == TRIBOOL_UNKNOWN)
@@ -603,7 +603,6 @@ static const struct inferior_key<terminal_info> inflow_inferior_data;
terminal_info::~terminal_info ()
{
- xfree (run_terminal);
xfree (ttystate);
}
@@ -643,15 +642,10 @@ copy_terminal_info (struct inferior *to, struct inferior *from)
tinfo_to = get_inflow_inferior_data (to);
tinfo_from = get_inflow_inferior_data (from);
- xfree (tinfo_to->run_terminal);
xfree (tinfo_to->ttystate);
*tinfo_to = *tinfo_from;
- if (tinfo_from->run_terminal)
- tinfo_to->run_terminal
- = xstrdup (tinfo_from->run_terminal);
-
if (tinfo_from->ttystate)
tinfo_to->ttystate
= serial_copy_tty_state (stdin_serial, tinfo_from->ttystate);
@@ -765,19 +759,19 @@ child_terminal_info (struct target_ops *self, const char *args, int from_tty)
\f
/* NEW_TTY_PREFORK is called before forking a new child process,
so we can record the state of ttys in the child to be formed.
- TTYNAME is null if we are to share the terminal with gdb;
- or points to a string containing the name of the desired tty.
+ TTYNAME is empty if we are to share the terminal with gdb;
+ otherwise it contains the name of the desired tty.
NEW_TTY is called in new child processes under Unix, which will
become debugger target processes. This actually switches to
the terminal specified in the NEW_TTY_PREFORK call. */
void
-new_tty_prefork (const char *ttyname)
+new_tty_prefork (std::string ttyname)
{
/* Save the name for later, for determining whether we and the child
are sharing a tty. */
- inferior_thisrun_terminal = ttyname;
+ inferior_thisrun_terminal = std::move (ttyname);
}
#if !defined(__GO32__) && !defined(_WIN32)
@@ -798,7 +792,7 @@ check_syscall (const char *msg, int result)
void
new_tty (void)
{
- if (inferior_thisrun_terminal == 0)
+ if (inferior_thisrun_terminal.empty ())
return;
#if !defined(__GO32__) && !defined(_WIN32)
int tty;
@@ -818,8 +812,8 @@ new_tty (void)
#endif
/* Now open the specified new terminal. */
- tty = open (inferior_thisrun_terminal, O_RDWR | O_NOCTTY);
- check_syscall (inferior_thisrun_terminal, tty);
+ tty = open (inferior_thisrun_terminal.c_str (), O_RDWR | O_NOCTTY);
+ check_syscall (inferior_thisrun_terminal.c_str (), tty);
/* Avoid use of dup2; doesn't exist on all systems. */
if (tty != 0)
@@ -854,7 +848,7 @@ new_tty (void)
/* NEW_TTY_POSTFORK is called after forking a new child process, and
adding it to the inferior table, to store the TTYNAME being used by
- the child, or null if it sharing the terminal with gdb. */
+ the child, or empty if it sharing the terminal with gdb. */
void
new_tty_postfork (void)
@@ -862,15 +856,11 @@ new_tty_postfork (void)
/* Save the name for later, for determining whether we and the child
are sharing a tty. */
- if (inferior_thisrun_terminal)
- {
- struct inferior *inf = current_inferior ();
- struct terminal_info *tinfo = get_inflow_inferior_data (inf);
-
- tinfo->run_terminal = xstrdup (inferior_thisrun_terminal);
- }
+ struct inferior *inf = current_inferior ();
+ struct terminal_info *tinfo = get_inflow_inferior_data (inf);
- inferior_thisrun_terminal = NULL;
+ tinfo->run_terminal = std::move (inferior_thisrun_terminal);
+ inferior_thisrun_terminal.clear ();
}
\f
@@ -894,7 +884,7 @@ set_sigint_trap (void)
struct inferior *inf = current_inferior ();
struct terminal_info *tinfo = get_inflow_inferior_data (inf);
- if (inf->attach_flag || tinfo->run_terminal)
+ if (inf->attach_flag || !tinfo->run_terminal.empty ())
{
osig = signal (SIGINT, pass_signal);
osig_set = 1;
@@ -927,7 +917,7 @@ create_tty_session (void)
#ifdef HAVE_SETSID
pid_t ret;
- if (!job_control || inferior_thisrun_terminal == 0)
+ if (!job_control || inferior_thisrun_terminal.empty ())
return 0;
ret = setsid ();
diff --git a/gdb/mi/mi-cmd-env.c b/gdb/mi/mi-cmd-env.c
index f7ee1e166eba..703c63251fd3 100644
--- a/gdb/mi/mi-cmd-env.c
+++ b/gdb/mi/mi-cmd-env.c
@@ -244,7 +244,10 @@ mi_cmd_env_dir (const char *command, char **argv, int argc)
void
mi_cmd_inferior_tty_set (const char *command, char **argv, int argc)
{
- current_inferior ()->set_tty (argv[0]);
+ if (argc > 0)
+ current_inferior ()->set_tty (argv[0]);
+ else
+ current_inferior ()->set_tty ("");
}
/* Print the inferior terminal device name. */
@@ -255,8 +258,8 @@ mi_cmd_inferior_tty_show (const char *command, char **argv, int argc)
if ( !mi_valid_noargs ("-inferior-tty-show", argc, argv))
error (_("-inferior-tty-show: Usage: No args"));
- const char *inferior_tty = current_inferior ()->tty ();
- if (inferior_tty != NULL)
+ const std::string &inferior_tty = current_inferior ()->tty ();
+ if (!inferior_tty.empty ())
current_uiout->field_string ("inferior_tty_terminal", inferior_tty);
}
diff --git a/gdb/terminal.h b/gdb/terminal.h
index e1f642b84665..186295e18f78 100644
--- a/gdb/terminal.h
+++ b/gdb/terminal.h
@@ -21,7 +21,7 @@
struct inferior;
-extern void new_tty_prefork (const char *);
+extern void new_tty_prefork (std::string ttyname);
extern void new_tty (void);
--
2.32.0
next prev parent reply other threads:[~2021-07-14 4:57 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
2021-07-14 4:55 ` [PATCH 01/16] gdb/testsuite: split gdb.python/py-parameter.exp in procs Simon Marchi
2021-07-14 4:55 ` [PATCH 02/16] gdb.base/setshow.exp: use save_vars to save/restore gdb_prompt Simon Marchi
2021-07-14 4:55 ` [PATCH 03/16] gdb.base/setshow.exp: split in procs Simon Marchi
2021-07-14 4:55 ` [PATCH 04/16] gdb.base/setshow.exp: fix duplicate test name Simon Marchi
2021-07-14 4:55 ` [PATCH 05/16] gdb: un-share set_inferior_cwd declaration Simon Marchi
2021-07-14 4:55 ` [PATCH 06/16] gdb: remove inferior::{argc,argv} Simon Marchi
2021-07-14 4:55 ` [PATCH 07/16] gdb: add setter/getter for inferior arguments Simon Marchi
2021-07-14 4:55 ` [PATCH 08/16] gdb: add setter/getter for inferior cwd Simon Marchi
2021-07-14 4:55 ` [PATCH 09/16] gdb: make inferior::m_args an std::string Simon Marchi
2021-07-14 4:55 ` [PATCH 10/16] gdb: make inferior::m_cwd " Simon Marchi
2021-07-14 4:55 ` Simon Marchi [this message]
2021-07-14 4:55 ` [PATCH 12/16] gdb: rename cfunc to simple_func Simon Marchi
2021-07-14 4:55 ` [PATCH 13/16] gdb: remove cmd_list_element::function::sfunc Simon Marchi
2021-07-28 19:10 ` Tom Tromey
2021-07-28 21:17 ` Simon Marchi
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
2021-07-23 19:42 ` Simon Marchi
2021-07-14 4:55 ` [PATCH 15/16] gdb: make cmd_list_element var an optional union Simon Marchi
2021-07-14 12:08 ` Lancelot SIX
2021-07-14 17:12 ` Lancelot SIX
2021-07-14 19:22 ` Simon Marchi
2021-07-14 23:22 ` Lancelot SIX
2021-07-19 14:32 ` Simon Marchi
2021-07-19 19:52 ` Simon Marchi
2021-07-20 23:03 ` Lancelot SIX
2021-07-23 19:56 ` Simon Marchi
2021-07-23 20:46 ` Lancelot SIX
2021-07-23 21:15 ` Simon Marchi
2021-07-23 22:55 ` Lancelot SIX
2021-07-24 2:04 ` Simon Marchi
2021-07-28 20:13 ` Tom Tromey
2021-07-28 20:45 ` Lancelot SIX
2021-07-29 17:47 ` Tom Tromey
2021-07-29 20:12 ` Lancelot SIX
2021-07-30 2:09 ` Simon Marchi
2021-07-30 17:47 ` Lancelot SIX
2021-07-18 15:44 ` Lancelot SIX
2021-07-19 14:19 ` Simon Marchi
2021-07-19 20:58 ` Lancelot SIX
2021-07-28 19:47 ` Tom Tromey
2021-07-28 20:59 ` Simon Marchi
2021-07-29 17:41 ` Tom Tromey
2021-07-29 17:44 ` Simon Marchi
2021-07-29 17:49 ` Tom Tromey
2021-07-29 18:00 ` Simon Marchi
2021-07-14 4:55 ` [PATCH 16/16] gdb: make string-like set show commands use std::string variable Simon Marchi
2021-07-28 20:27 ` Tom Tromey
2021-07-28 21:03 ` Simon Marchi
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-12-simon.marchi@polymtl.ca \
--to=simon.marchi@polymtl.ca \
--cc=gdb-patches@sourceware.org \
/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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).