1 # This testcase is part of GDB
, the GNU debugger.
3 # Copyright
2017-2024 Free Software Foundation
, Inc.
5 # This
program is free software
; you can redistribute it and
/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation
; either version
3 of the License
, or
8 #
(at your option
) any later version.
10 # This
program is distributed in the hope that it will be useful
,
11 # but WITHOUT
ANY WARRANTY
; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License
for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this
program.
If not
, see
<http
://www.gnu.org
/licenses
/>.
22 if { [prepare_for_testing
"failed to prepare" $testfile $srcfile debug] } {
26 # Test that tilde expansion works fine.
28 proc_with_prefix test_tilde_expansion
{ } {
29 global decimal gdb_prompt hex
31 gdb_test_no_output
"set cwd ~/" "set inferior cwd to ~/ dir"
33 if { ![runto_main
] } {
37 gdb_breakpoint
[gdb_get_line_number
"break-here"]
38 gdb_continue_to_breakpoint
"break-here" ".* break-here .*"
41 set test
"print home var"
42 gdb_test_multiple
"print home" $test {
43 -re
"\\\$$decimal = $hex \"\(.+\)\"\r\n$gdb_prompt $" {
44 set home $expect_out
(1,string
)
50 untested
"could not retrieve home var"
55 set test
"print dir var"
56 gdb_test_multiple
"print dir" $test {
57 -re
"\\\$$decimal = \"\(.+\)\"\(, .*repeats.*\)?\r\n$gdb_prompt $" {
58 set curdir $expect_out
(1,string
)
63 if { $curdir
== "" } {
64 untested
"could not retrieve dir var"
68 gdb_assert
[string equal $curdir $home
] \
69 "successfully chdir'd into home"
72 # The temporary directory that we will use to start the inferior.
73 set tmpdir
[standard_output_file
""]
75 # Test that when we
"set cwd" the inferior will be started under the
76 # correct working directory and GDB will not be affected by this.
78 proc_with_prefix test_cd_into_dir
{ } {
79 global decimal gdb_prompt tmpdir
81 set gdb_cwd_before_run
""
82 set test
"pwd before run"
83 gdb_test_multiple
"pwd" $test {
84 -re
"Working directory \(.*\)\.\r\n$gdb_prompt $" {
85 set gdb_cwd_before_run $expect_out
(1,string
)
90 if { $gdb_cwd_before_run
== "" } {
91 untested
"could not obtain GDB cwd before run"
95 # This test only makes sense
if $tmpdir
!= $gdb_cwd_before_run
96 if { ![gdb_assert
![string equal $tmpdir $gdb_cwd_before_run
] \
97 "make sure that tmpdir and GDB's cwd are different"] } {
101 gdb_test_no_output
"set cwd $tmpdir" "set inferior cwd to temp dir"
103 if { ![runto_main
] } {
107 gdb_breakpoint
[gdb_get_line_number
"break-here"]
108 gdb_continue_to_breakpoint
"break-here" ".* break-here .*"
110 gdb_test
"print dir" "\\\$$decimal = \"$tmpdir\", .*" \
111 "inferior cwd is correctly set"
113 set gdb_cwd_after_run
""
114 set test
"pwd after run"
115 gdb_test_multiple
"pwd" $test {
116 -re
"Working directory \(.*\)\.\r\n$gdb_prompt $" {
117 set gdb_cwd_after_run $expect_out
(1,string
)
122 if { $gdb_cwd_after_run
== "" } {
123 untested
"could not obtain GDB cwd after run"
127 gdb_assert
[string equal $gdb_cwd_before_run $gdb_cwd_after_run
] \
128 "GDB cwd is unchanged after running inferior"
131 # Test that executing
"set cwd" without arguments will reset the
132 # inferior
's cwd setting to its previous state.
134 proc_with_prefix test_cwd_reset { } {
135 global decimal gdb_prompt tmpdir
139 gdb_test_multiple "pwd" $test {
140 -re "Working directory \(.*\)\.\r\n$gdb_prompt $" {
141 set gdb_cwd $expect_out(1,string)
145 if { $gdb_cwd == "" } {
146 untested "could not obtain GDB cwd"
150 # This test only makes sense if $tmpdir != $gdb_cwd.
151 if { ![gdb_assert ![string equal $tmpdir $gdb_cwd] \
152 "make sure that tmpdir and GDB's cwd are different
"] } {
156 gdb_test_no_output
"set cwd $tmpdir" "set inferior cwd to temp dir"
158 with_test_prefix
"running with set cwd" {
159 if { ![runto_main
] } {
164 gdb_breakpoint
[gdb_get_line_number
"break-here"]
165 gdb_continue_to_breakpoint
"break-here" ".* break-here .*"
167 gdb_test
"print dir" "\\\$$decimal = \"$tmpdir\", .*" \
168 "inferior cwd is correctly set"
170 # Reset the inferior
's cwd.
171 gdb_test_no_output "set cwd" "resetting inferior cwd"
173 with_test_prefix "running without set cwd" {
174 if { ![runto_main] } {
178 gdb_breakpoint [gdb_get_line_number "break-here"]
179 gdb_continue_to_breakpoint "break-here" ".* break-here .*"
181 gdb_test "print dir" "\\\$$decimal = \"$gdb_cwd\", .*" \
182 "inferior cwd got reset correctly"
187 clean_restart $binfile
189 clean_restart $binfile