[binutils-gdb/gdb-8.3-branch] Testsuite: Ensure changing directory does not break the log file

Alan Hayward alahay01@sourceware.org
Wed Mar 6 10:10:00 GMT 2019


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=9b068afad22bfa9386b21762c91eaddd8ef691b4

commit 9b068afad22bfa9386b21762c91eaddd8ef691b4
Author: Alan Hayward <alan.hayward@arm.com>
Date:   Wed Mar 6 09:52:08 2019 +0000

    Testsuite: Ensure changing directory does not break the log file
    
    get_compiler_info switches to a new log file before checking the compiler
    to ensure the checks are not logged. Afterwards it restores back to using
    the original log file. However, the logfile uses a relative path name -
    if the current test has changed the current directory then all further
    output for the test will be lost.  This can confuse the code that collates
    the main gdb.log file at the end of a FORCE_PARALLEL run.
    
    fullpath-expand.exp calls gdb_compile after changing the current directory.
    
    The "Ensure stack protection is off for GCC" patch added a call to
    get_compiler_info from inside of gdb_compile, causing log file collection
    to break for FORCE_PARALLEL runs.
    
    The ideal solution would be to ensure the log file is always created using
    an absolute path name. However, this is set at multiple points in
    Makefile.in and in some instances just relies on dejagnu common code to set
    the log file directory to "."
    
    The simpler and safer solution is to override the builtin cd function. The
    new function checks the current log file and if the path is relative, then
    it resets the logging using an absolute path. Finally it calls the builtin
    cd.  This ensures get_compiler_info (and any other code) can correctly
    backup and restore the current log file.
    
    gdb/testsuite/ChangeLog:
    
    	* lib/gdb.exp (builtin_cd): rename of cd.
    	(cd): Override builtin.

Diff:
---
 gdb/testsuite/ChangeLog   |  5 +++++
 gdb/testsuite/lib/gdb.exp | 36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+)

diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 693fc15..48f7e8e 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2019-03-06  Alan Hayward  <alan.hayward@arm.com>
+
+	* lib/gdb.exp (builtin_cd): rename of cd.
+	(cd): Override builtin.
+
 2019-02-26  Tom Tromey  <tromey@adacore.com>
 
 	* gdb.python/py-value.exp (test_value_from_buffer): Check for
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index d058543..e429dca 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -6284,5 +6284,41 @@ proc gdb_define_cmd {command command_list} {
     }
 }
 
+# Override the 'cd' builtin with a version that ensures that the
+# log file keeps pointing at the same file.  We need this because
+# unfortunately the path to the log file is recorded using an
+# relative path name, and, we sometimes need to close/reopen the log
+# after changing the current directory.  See get_compiler_info.
+
+rename cd builtin_cd
+
+proc cd { dir } {
+
+    # Get the existing log file flags.
+    set log_file_info [log_file -info]
+
+    # Split the flags into args and file name.
+    set log_file_flags ""
+    set log_file_file ""
+    foreach arg [ split "$log_file_info" " "] {
+	if [string match "-*" $arg] {
+	    lappend log_file_flags $arg
+	} else {
+	    lappend log_file_file $arg
+	}
+    }
+
+    # If there was an existing file, ensure it is an absolute path, and then
+    # reset logging.
+    if { $log_file_file != "" } {
+	set log_file_file [file normalize $log_file_file]
+	log_file
+	log_file $log_file_flags "$log_file_file"
+    }
+
+    # Call the builtin version of cd.
+    builtin_cd $dir
+}
+
 # Always load compatibility stuff.
 load_lib future.exp



More information about the Gdb-cvs mailing list