forked from Imagelibrary/binutils-gdb
gdb: make set/show inferior-tty work with $_gdb_setting_str
Like the previous two commits, this commit fixes set/show inferior-tty to work with $_gdb_setting_str. Instead of using a scratch variable which is then pushed into the current inferior from a set callback, move to the API that allows for getters and setters, and store the value directly within the current inferior. Update an existing test to check the inferior-tty setting. Reviewed-By: Tom Tromey <tom@tromey.com>
This commit is contained in:
30
gdb/infcmd.c
30
gdb/infcmd.c
@@ -66,11 +66,6 @@ static void step_1 (int, int, const char *);
|
||||
#define ERROR_NO_INFERIOR \
|
||||
if (!target_has_execution ()) error (_("The program is not being run."));
|
||||
|
||||
/* Scratch area where 'set inferior-tty' will store user-provided value.
|
||||
We'll immediate copy it into per-inferior storage. */
|
||||
|
||||
static std::string inferior_io_terminal_scratch;
|
||||
|
||||
/* Pid of our debugged inferior, or 0 if no inferior now.
|
||||
Since various parts of infrun.c test this to see whether there is a program
|
||||
being debugged it should be nonzero (currently 3 is used) for remote
|
||||
@@ -94,15 +89,24 @@ static bool finish_print = true;
|
||||
|
||||
|
||||
|
||||
/* Store the new value passed to 'set inferior-tty'. */
|
||||
|
||||
static void
|
||||
set_inferior_tty_command (const char *args, int from_tty,
|
||||
struct cmd_list_element *c)
|
||||
set_tty_value (const std::string &tty)
|
||||
{
|
||||
/* CLI has assigned the user-provided value to inferior_io_terminal_scratch.
|
||||
Now route it to current inferior. */
|
||||
current_inferior ()->set_tty (inferior_io_terminal_scratch);
|
||||
current_inferior ()->set_tty (tty);
|
||||
}
|
||||
|
||||
/* Get the current 'inferior-tty' value. */
|
||||
|
||||
static const std::string &
|
||||
get_tty_value ()
|
||||
{
|
||||
return current_inferior ()->tty ();
|
||||
}
|
||||
|
||||
/* Implement 'show inferior-tty' command. */
|
||||
|
||||
static void
|
||||
show_inferior_tty_command (struct ui_file *file, int from_tty,
|
||||
struct cmd_list_element *c, const char *value)
|
||||
@@ -3136,14 +3140,14 @@ _initialize_infcmd ()
|
||||
|
||||
/* Add the filename of the terminal connected to inferior I/O. */
|
||||
auto tty_set_show
|
||||
= add_setshow_optional_filename_cmd ("inferior-tty", class_run,
|
||||
&inferior_io_terminal_scratch, _("\
|
||||
= add_setshow_optional_filename_cmd ("inferior-tty", class_run, _("\
|
||||
Set terminal for future runs of program being debugged."), _(" \
|
||||
Show terminal for future runs of program being debugged."), _(" \
|
||||
Usage: set inferior-tty [TTY]\n\n \
|
||||
If TTY is omitted, the default behavior of using the same terminal as GDB\n \
|
||||
is restored."),
|
||||
set_inferior_tty_command,
|
||||
set_tty_value,
|
||||
get_tty_value,
|
||||
show_inferior_tty_command,
|
||||
&setlist, &showlist);
|
||||
add_alias_cmd ("tty", tty_set_show.set, class_run, 0, &cmdlist);
|
||||
|
||||
@@ -30,6 +30,8 @@ with_test_prefix "setup inferior 1" {
|
||||
gdb_test_no_output "set environment FOO foo"
|
||||
gdb_test_no_output "set environment BAR bar"
|
||||
gdb_test_no_output "set inferior-tty some_tty"
|
||||
gdb_test {print $_gdb_setting_str("inferior-tty")} \
|
||||
" = \"some_tty\""
|
||||
}
|
||||
|
||||
# Check that properties of inferior 1 have been copied
|
||||
@@ -45,6 +47,8 @@ with_test_prefix "inferior 2" {
|
||||
gdb_test "show environment ENVVAR" "ENVVAR = var"
|
||||
gdb_test "show inferior-tty" \
|
||||
"Terminal for future runs of program being debugged is \"some_tty\"\."
|
||||
gdb_test {print $_gdb_setting_str("inferior-tty")} \
|
||||
" = \"some_tty\""
|
||||
}
|
||||
|
||||
# Change this second inferior, to check that the next clone-inferior
|
||||
@@ -54,6 +58,9 @@ with_test_prefix "update inferior 2" {
|
||||
gdb_test_no_output "set args foo"
|
||||
gdb_test_no_output "set cwd /somewhere/else"
|
||||
gdb_test_no_output "set environment FOO oof"
|
||||
gdb_test_no_output "set inferior-tty another_tty"
|
||||
gdb_test {print $_gdb_setting_str("inferior-tty")} \
|
||||
" = \"another_tty\""
|
||||
}
|
||||
|
||||
with_test_prefix "inferior 1" {
|
||||
@@ -67,6 +74,8 @@ with_test_prefix "inferior 1" {
|
||||
gdb_test "show environment ENVVAR" "ENVVAR = var"
|
||||
gdb_test "show inferior-tty" \
|
||||
"Terminal for future runs of program being debugged is \"some_tty\"\."
|
||||
gdb_test {print $_gdb_setting_str("inferior-tty")} \
|
||||
" = \"some_tty\""
|
||||
}
|
||||
|
||||
# Tweak inferior 1 a bit more.
|
||||
|
||||
@@ -70,6 +70,7 @@ foreach_with_prefix inf $inferiors {
|
||||
"switch to inferior ${inf} before set"
|
||||
gdb_test_no_output "set args inf${inf}-args"
|
||||
gdb_test_no_output "set cwd /inf${inf}-cwd"
|
||||
gdb_test_no_output "set inferior-tty /inf${inf}-tty"
|
||||
}
|
||||
|
||||
# Check settings are still correct for each inferior.
|
||||
@@ -84,19 +85,30 @@ foreach_with_prefix inf $inferiors {
|
||||
gdb_test "with cwd tmp-value -- print 1" " = 1"
|
||||
gdb_test "show cwd" "/inf${inf}-cwd.*"
|
||||
|
||||
gdb_test "with inferior-tty tmp-value -- print 1" " = 1"
|
||||
gdb_test "show inferior-tty" "/inf${inf}-tty.*"
|
||||
|
||||
# If the inferiors are running check $_gdb_setting_str and
|
||||
# $_gdb_setting return the correct values.
|
||||
if { $run } {
|
||||
gdb_test {print $_gdb_setting_str("args")} "\"inf${inf}-args\""
|
||||
gdb_test {print $_gdb_setting("args")} "\"inf${inf}-args\""
|
||||
|
||||
gdb_test {print $_gdb_setting_str("cwd")} "\"/inf${inf}-cwd\""
|
||||
gdb_test {print $_gdb_setting("cwd")} "\"/inf${inf}-cwd\""
|
||||
|
||||
gdb_test {print $_gdb_setting_str("inferior-tty")} \
|
||||
"\"/inf${inf}-tty\""
|
||||
gdb_test {print $_gdb_setting("inferior-tty")} \
|
||||
"\"/inf${inf}-tty\""
|
||||
}
|
||||
|
||||
# Check the settings can be read from Python.
|
||||
if { $run_python_tests } {
|
||||
gdb_test "python print(gdb.parameter('args'))" "inf${inf}-args"
|
||||
gdb_test "python print(gdb.parameter('cwd'))" "/inf${inf}-cwd"
|
||||
gdb_test "python print(gdb.parameter('inferior-tty'))" \
|
||||
"/inf${inf}-tty"
|
||||
}
|
||||
|
||||
# Check the settings can be read from Guile.
|
||||
@@ -105,5 +117,7 @@ foreach_with_prefix inf $inferiors {
|
||||
"inf${inf}-args"
|
||||
gdb_test "guile (print (parameter-value \"cwd\"))" \
|
||||
"/inf${inf}-cwd"
|
||||
gdb_test "guile (print (parameter-value \"inferior-tty\"))" \
|
||||
"/inf${inf}-tty"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user