# ${srcdir} may be a relative path. We want to make sure we end up
# in the right directory - so make sure we know where it is.
-set mydir [pwd]
-cd ${srcdir}
-set fullsrcdir [pwd]
-cd ${mydir}
+with_cwd $srcdir {
+ set fullsrcdir [pwd]
+}
# If the directory name contains a '+' we must escape it, adding a backslash.
# If not, the test below will fail because it will interpret the '+' as a
# Build the test executable using relative paths not relative to the directory
# we'll run GDB from.
-set save_pwd [pwd]
-cd [standard_output_file {}]
-if { [gdb_compile [standard_output_file tmp-${srcfile}] "${testfile}" \
- executable {debug}] != "" } {
- cd $save_pwd
- return -1
+with_cwd [standard_output_file {}] {
+ if { [gdb_compile [standard_output_file tmp-${srcfile}] "${testfile}" \
+ executable {debug}] != "" } {
+ return -1
+ }
}
-cd $save_pwd
gdb_exit
gdb_start
return -1
}
-set saved_pwd [pwd]
-cd $srcdir
-set err [gdb_compile "${subdir}/${srcfile} ${subdir}/${srcfile2}" $binfile executable {debug}]
-cd $saved_pwd
-if { $err != "" } {
- untested "${srcfile} or ${srcfile2} compilation failed"
- return -1
+with_cwd $srcdir {
+ set err [gdb_compile "${subdir}/${srcfile} ${subdir}/${srcfile2}" $binfile executable {debug}]
+
+ if { $err != "" } {
+ untested "${srcfile} or ${srcfile2} compilation failed"
+ return -1
+ }
}
set result [catch "exec realpath ${srcdir}/${subdir}/${srcfile2}" realsrcfile2]
# ${srcdir} may be a relative path. We want to make sure we
# end up in the right directory - so make sure we know where
# it is.
- global srcdir
- set mydir [pwd]
- cd ${srcdir}
- set fullsrcdir [pwd]
- cd ${mydir}
+ with_cwd $::srcdir {
+ set fullsrcdir [pwd]
+ }
gdb_test "cd ${fullsrcdir}" \
"Working directory [string_to_regexp ${fullsrcdir}].*" \
return
}
- set original_dir [pwd]
set working_dir [standard_output_file ""]
- cd ${working_dir}
-
- set strip_dir [file normalize "${working_dir}/../.."]
-
- set new_srcfile [standard_output_file ${srcfile}]
- set fd [open "$new_srcfile" w]
- puts $fd "int
- main ()
- {
- return 0;
- }"
- close $fd
-
- set options \
- "debug additional_flags=-fdebug-prefix-map=${strip_dir}="
- if { [gdb_compile "${srcfile}" "${binfile}" \
- executable ${options}] != "" } {
- untested "failed to compile"
- return -1
+ with_cwd $working_dir {
+ set strip_dir [file normalize "${working_dir}/../.."]
+
+ set new_srcfile [standard_output_file ${srcfile}]
+ set fd [open "$new_srcfile" w]
+ puts $fd "int
+ main ()
+ {
+ return 0;
+ }"
+ close $fd
+
+ set options \
+ "debug additional_flags=-fdebug-prefix-map=${strip_dir}="
+ if { [gdb_compile "${srcfile}" "${binfile}" \
+ executable ${options}] != "" } {
+ untested "failed to compile"
+ return -1
+ }
}
- cd ${original_dir}
-
clean_restart ${binfile}
if { [ishost *-*-mingw*] } {
untested "objdir $objdir should be absolute"
return
}
-set saved_pwd [pwd]
-cd $srcdir/${subdir}/base/one
-set err1 [gdb_compile "thefile.cc" $objfile1 object $opts]
-cd $saved_pwd
-cd $srcdir/${subdir}/base/two
-set err2 [gdb_compile "thefile.cc" $objfile2 object $opts]
-cd $saved_pwd
-if { $err1 != "" || $err2 != "" } {
- untested "compilation failed"
- return -1
+
+with_cwd $srcdir/${subdir}/base/one {
+ if { [gdb_compile "thefile.cc" $objfile1 object $opts] != "" } {
+ untested "compilation failed"
+ return
+ }
+}
+
+with_cwd $srcdir/${subdir}/base/two {
+ if { [gdb_compile "thefile.cc" $objfile2 object $opts] != "" } {
+ untested "compilation failed"
+ return
+ }
}
if { [gdb_compile "$srcdir/${subdir}/$srcfile $objfile1 $objfile2" \
untested "objdir $objdir should be absolute"
return
}
-set saved_pwd [pwd]
-cd $srcdir/${subdir}/base/two
-set err [gdb_compile "../../${srcfile}" "${binfile}" executable $opts]
-cd $saved_pwd
-if { $err != "" } {
- untested "compilation failed"
- return -1
+
+with_cwd $srcdir/${subdir}/base/two {
+ if { [gdb_compile "../../${srcfile}" "${binfile}" executable $opts] != "" } {
+ untested "compilation failed"
+ return
+ }
}
clean_restart ${testfile}
# BUILDDIR.
proc target_compile_ada_from_dir {builddir source dest type options} {
- set saved_cwd [pwd]
-
global board
set board [target_info name]
set save_multilib_flag [board_info $board multilib_flags]
}
catch {
- cd $builddir
- return [target_compile $source $dest $type $options]
+ with_cwd $builddir {
+ return [target_compile $source $dest $type $options]
+ }
} result options
- cd $saved_cwd
if { $save_multilib_flag != "" } {
unset_board_info "multilib_flags"