From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1879) id C604E3858C83; Wed, 27 Apr 2022 00:19:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C604E3858C83 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Simon Marchi To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb/testsuite: use with_cwd where possible X-Act-Checkin: binutils-gdb X-Git-Author: Simon Marchi X-Git-Refname: refs/heads/master X-Git-Oldrev: 2538fcd3f4b6807f48de20982a2d9c584d98912b X-Git-Newrev: 019a5c62974523a3331911130c66350ef0a6f3c4 Message-Id: <20220427001908.C604E3858C83@sourceware.org> Date: Wed, 27 Apr 2022 00:19:08 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 27 Apr 2022 00:19:08 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D019a5c629745= 23a3331911130c66350ef0a6f3c4 commit 019a5c62974523a3331911130c66350ef0a6f3c4 Author: Simon Marchi Date: Fri Apr 22 09:16:59 2022 -0400 gdb/testsuite: use with_cwd where possible =20 I learned about with_cwd today. I spotted a few spots that could use it, to make the code more robust. =20 Change-Id: Ia23664cb827f25e79d31948e0c006a8dc61c33e1 Diff: --- gdb/testsuite/gdb.base/completion.exp | 7 ++--- gdb/testsuite/gdb.base/fullname.exp | 12 ++++---- gdb/testsuite/gdb.base/fullpath-expand.exp | 14 ++++----- gdb/testsuite/gdb.base/settings.exp | 8 ++---- gdb/testsuite/gdb.base/source-dir.exp | 41 +++++++++++++----------= ---- gdb/testsuite/gdb.linespec/break-ask.exp | 23 ++++++++------- gdb/testsuite/gdb.linespec/macro-relative.exp | 13 ++++----- gdb/testsuite/lib/ada.exp | 8 ++---- 8 files changed, 59 insertions(+), 67 deletions(-) diff --git a/gdb/testsuite/gdb.base/completion.exp b/gdb/testsuite/gdb.base= /completion.exp index 34a16af1491..0c58a1ab6b7 100644 --- a/gdb/testsuite/gdb.base/completion.exp +++ b/gdb/testsuite/gdb.base/completion.exp @@ -675,10 +675,9 @@ gdb_test "complete whatis &values\[0\]->z" \ =20 # ${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] +} =20 # If the directory name contains a '+' we must escape it, adding a backsla= sh. # If not, the test below will fail because it will interpret the '+' as a = diff --git a/gdb/testsuite/gdb.base/fullname.exp b/gdb/testsuite/gdb.base/f= ullname.exp index a264dc75322..f9faca87423 100644 --- a/gdb/testsuite/gdb.base/fullname.exp +++ b/gdb/testsuite/gdb.base/fullname.exp @@ -99,14 +99,12 @@ if { [gdb_breakpoint [standard_output_file tmp-${srcfil= e}]:${line} {no-message}] # Build the test executable using relative paths not relative to the direc= tory # we'll run GDB from. =20 -set save_pwd [pwd] -cd [standard_output_file {}] -if { [gdb_compile [standard_output_file tmp-${srcfile}] "${testfile}" \ - executable {debug}] !=3D "" } { - cd $save_pwd - return -1 +with_cwd [standard_output_file {}] { + if { [gdb_compile [standard_output_file tmp-${srcfile}] "${testfile}"= \ + executable {debug}] !=3D "" } { + return -1 + } } -cd $save_pwd =20 gdb_exit gdb_start diff --git a/gdb/testsuite/gdb.base/fullpath-expand.exp b/gdb/testsuite/gdb= .base/fullpath-expand.exp index efa8d63b1d4..b3890244997 100644 --- a/gdb/testsuite/gdb.base/fullpath-expand.exp +++ b/gdb/testsuite/gdb.base/fullpath-expand.exp @@ -25,13 +25,13 @@ if { [file pathtype $objdir] !=3D "absolute" } { return -1 } =20 -set saved_pwd [pwd] -cd $srcdir -set err [gdb_compile "${subdir}/${srcfile} ${subdir}/${srcfile2}" $binfile= executable {debug}] -cd $saved_pwd -if { $err !=3D "" } { - untested "${srcfile} or ${srcfile2} compilation failed" - return -1 +with_cwd $srcdir { + set err [gdb_compile "${subdir}/${srcfile} ${subdir}/${srcfile2}" $bin= file executable {debug}] + + if { $err !=3D "" } { + untested "${srcfile} or ${srcfile2} compilation failed" + return -1 + } } =20 set result [catch "exec realpath ${srcdir}/${subdir}/${srcfile2}" realsrcf= ile2] diff --git a/gdb/testsuite/gdb.base/settings.exp b/gdb/testsuite/gdb.base/s= ettings.exp index efd7f17d5cf..dafc5e4d8fd 100644 --- a/gdb/testsuite/gdb.base/settings.exp +++ b/gdb/testsuite/gdb.base/settings.exp @@ -585,11 +585,9 @@ proc test-string {variant} { # ${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] + } =20 gdb_test "cd ${fullsrcdir}" \ "Working directory [string_to_regexp ${fullsrcdir}].*" \ diff --git a/gdb/testsuite/gdb.base/source-dir.exp b/gdb/testsuite/gdb.base= /source-dir.exp index 21d4831688f..fff1c1f8717 100644 --- a/gdb/testsuite/gdb.base/source-dir.exp +++ b/gdb/testsuite/gdb.base/source-dir.exp @@ -87,31 +87,28 @@ proc test_truncated_comp_dir {} { return } =20 - 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=3D-fdebug-prefix-map=3D${strip_dir}=3D" - if { [gdb_compile "${srcfile}" "${binfile}" \ - executable ${options}] !=3D "" } { - 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=3D-fdebug-prefix-map=3D${strip_dir}=3D" + if { [gdb_compile "${srcfile}" "${binfile}" \ + executable ${options}] !=3D "" } { + untested "failed to compile" + return -1 + } } =20 - cd ${original_dir} - clean_restart ${binfile} =20 if { [ishost *-*-mingw*] } { diff --git a/gdb/testsuite/gdb.linespec/break-ask.exp b/gdb/testsuite/gdb.l= inespec/break-ask.exp index d73172de596..120c399acf2 100644 --- a/gdb/testsuite/gdb.linespec/break-ask.exp +++ b/gdb/testsuite/gdb.linespec/break-ask.exp @@ -28,16 +28,19 @@ if { [file pathtype $objdir] =3D=3D "relative" } { 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 !=3D "" || $err2 !=3D "" } { - untested "compilation failed" - return -1 + +with_cwd $srcdir/${subdir}/base/one { + if { [gdb_compile "thefile.cc" $objfile1 object $opts] !=3D "" } { + untested "compilation failed" + return + } +} + +with_cwd $srcdir/${subdir}/base/two { + if { [gdb_compile "thefile.cc" $objfile2 object $opts] !=3D "" } { + untested "compilation failed" + return + } } =20 if { [gdb_compile "$srcdir/${subdir}/$srcfile $objfile1 $objfile2" \ diff --git a/gdb/testsuite/gdb.linespec/macro-relative.exp b/gdb/testsuite/= gdb.linespec/macro-relative.exp index 609f290d8fb..67b779f5896 100644 --- a/gdb/testsuite/gdb.linespec/macro-relative.exp +++ b/gdb/testsuite/gdb.linespec/macro-relative.exp @@ -32,13 +32,12 @@ if { [file pathtype $objdir] =3D=3D "relative" } { 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 !=3D "" } { - untested "compilation failed" - return -1 + +with_cwd $srcdir/${subdir}/base/two { + if { [gdb_compile "../../${srcfile}" "${binfile}" executable $opts] != =3D "" } { + untested "compilation failed" + return + } } =20 clean_restart ${testfile} diff --git a/gdb/testsuite/lib/ada.exp b/gdb/testsuite/lib/ada.exp index 67581c89008..25f8193c974 100644 --- a/gdb/testsuite/lib/ada.exp +++ b/gdb/testsuite/lib/ada.exp @@ -18,8 +18,6 @@ # BUILDDIR. =20 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] @@ -39,10 +37,10 @@ proc target_compile_ada_from_dir {builddir source dest = type options} { } =20 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 =20 if { $save_multilib_flag !=3D "" } { unset_board_info "multilib_flags"