aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite
diff options
context:
space:
mode:
authorLancelot SIX <lancelot.six@amd.com>2021-12-06 05:23:42 -0500
committerLancelot SIX <lancelot.six@amd.com>2021-12-29 03:27:38 -0500
commit003aae076207dbf32f98ba846158fc32669ef85f (patch)
tree9d10c1c387f413469d7e8428096bb5e2d5ee8fde /gdb/testsuite
parent39907652260b9adc16958e0cbeefa9bc98e9106a (diff)
downloadgdb-003aae076207dbf32f98ba846158fc32669ef85f.zip
gdb-003aae076207dbf32f98ba846158fc32669ef85f.tar.gz
gdb-003aae076207dbf32f98ba846158fc32669ef85f.tar.bz2
gdb: Copy inferior properties in clone-inferior
This commit ensures that the following settings are cloned from one inferior to the new one when processing the clone-inferior command: - inferior-tty - environment variables - cwd - args Some of those parameters can be passed as command line arguments to GDB (-args and -tty), so one could expect the clone-inferior to respect those flags. The following debugging session illustrates that: gdb -nx -quiet -batch \ -ex "show args" \ -ex "show inferior-tty" \ -ex "clone-inferior" \ -ex "inferior 2" \ -ex "show args" \ -ex "show inferior-tty" \ -tty=/some/tty \ -args echo foo bar Argument list to give program being debugged when it is started is "foo bar". Terminal for future runs of program being debugged is "/some/tty". [New inferior 2] Added inferior 2. [Switching to inferior 2 [<null>] (/bin/echo)] Argument list to give program being debugged when it is started is "". Terminal for future runs of program being debugged is "". The other properties this commit copies on clone (i.e. CWD and the environment variables) are included since they are related (in the sense that they influence the runtime behavior of the program) even if they cannot be directly set using command line switches. There is a chance that this patch changes existing user workflow. I think that this change is mostly harmless. If users want to start a new inferior based on an existing one, they probably already propagate those settings to the new inferior in some way. Tested on x86_64-linux. Change-Id: I3b1f28b662f246228b37bb24c2ea1481567b363d
Diffstat (limited to 'gdb/testsuite')
-rw-r--r--gdb/testsuite/gdb.base/inferior-clone.exp93
1 files changed, 93 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.base/inferior-clone.exp b/gdb/testsuite/gdb.base/inferior-clone.exp
new file mode 100644
index 0000000..bb43be6
--- /dev/null
+++ b/gdb/testsuite/gdb.base/inferior-clone.exp
@@ -0,0 +1,93 @@
+# Copyright (C) 2021 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# This testcase checks that the clone-inferior command copies important
+# properties from the original to the new inferior such CWD, args and env.
+
+# Add an environment variable that can be modified later for each inferior
+# in GDB.
+set env(ENVVAR) var
+
+# This test does not need a binfile.
+clean_restart
+
+# Set custom properties for Inferior 1
+with_test_prefix "setup inferior 1" {
+ gdb_test_no_output "set args foo bar 'b a z'"
+ gdb_test_no_output "set cwd /any/where"
+ 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"
+}
+
+# Check that properties of inferior 1 have been copied
+with_test_prefix "inferior 2" {
+ gdb_test "clone-inferior" "Added inferior 2"
+ gdb_test "inferior 2" "\[Switching to inferior 2 \[<null>\] (.*)\]" "change inferior"
+ gdb_test "show args" \
+ "Argument list to give program being debugged when it is started is \"foo bar 'b a z'\"\."
+ gdb_test "show cwd" \
+ "Current working directory that will be used when starting the inferior is \"/any/where\"\."
+ gdb_test "show environment FOO" "FOO = foo"
+ gdb_test "show environment BAR" "BAR = bar"
+ gdb_test "show environment ENVVAR" "ENVVAR = var"
+ gdb_test "show inferior-tty" \
+ "Terminal for future runs of program being debugged is \"some_tty\"\."
+}
+
+# Change this second inferior, to check that the next clone-inferior
+# clones from the active inferior, and changing the values for inferior 2
+# does not interfere with values on inferior 1.
+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"
+}
+
+with_test_prefix "inferior 1" {
+ gdb_test "inferior 1" "\[Switching to inferior 1 \[<null>\] (.*)\]" "change inferior"
+ gdb_test "show args" \
+ "Argument list to give program being debugged when it is started is \"foo bar 'b a z'\"\."
+ gdb_test "show cwd" \
+ "Current working directory that will be used when starting the inferior is \"/any/where\"\."
+ gdb_test "show environment FOO" "FOO = foo"
+ gdb_test "show environment BAR" "BAR = bar"
+ gdb_test "show environment ENVVAR" "ENVVAR = var"
+ gdb_test "show inferior-tty" \
+ "Terminal for future runs of program being debugged is \"some_tty\"\."
+}
+
+# Tweak inferior 1 a bit more.
+with_test_prefix "update inferior 1" {
+ gdb_test_no_output "unset environment FOO"
+ gdb_test_no_output "unset environment ENVVAR"
+}
+
+
+# Check that the values observed on inferior 3 are those copied from
+# inferior 1.
+with_test_prefix "inferior 3" {
+ gdb_test "clone-inferior" "Added inferior 3"
+ gdb_test "inferior 3" "\[Switching to inferior 3 \[<null>\] (.*)\]" "change inferior"
+ gdb_test "show args" \
+ "Argument list to give program being debugged when it is started is \"foo bar 'b a z'\"\."
+ gdb_test "show cwd" \
+ "Current working directory that will be used when starting the inferior is \"/any/where\"\."
+ gdb_test "show environment FOO" "Environment variable \"FOO\" not defined\."
+ gdb_test "show environment BAR" "BAR = bar"
+ gdb_test "show environment ENVVAR" "Environment variable \"ENVVAR\" not defined\."
+ gdb_test "show inferior-tty" \
+ "Terminal for future runs of program being debugged is \"some_tty\"\."
+}