aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.base/inferior-clone.exp
blob: eb2759428bc04cb0a9ca7787f6e97331f65060f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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\"\."
}