public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Testsuite: Ensure changing directory does not break the log file
@ 2019-02-21 10:34 Alan Hayward
  2019-02-21 22:40 ` Tom Tromey
  0 siblings, 1 reply; 5+ messages in thread
From: Alan Hayward @ 2019-02-21 10:34 UTC (permalink / raw)
  To: gdb-patches; +Cc: nd, Alan Hayward

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.

Tested with make check and native-gdbserver.

gdb/testsuite/ChangeLog:

2019-02-21  Alan Hayward  <alan.hayward@arm.com>

	* lib/gdb.exp (builtin_cd): rename of cd.
	(cd): Override builtin.
---
 gdb/testsuite/lib/gdb.exp | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index d05854329d..17e437956d 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -6284,5 +6284,24 @@ proc gdb_define_cmd {command command_list} {
     }
 }
 
+# Safe version of cd that ensures the log file is not stopped.
+
+rename cd builtin_cd
+
+proc cd { dir } {
+    # Get logfile, which will be prefixed with "-a ".
+    set saved_log [log_file -info]
+
+    # If the logfile is a relative path, reset it to an absolute path.
+    if { [regexp "^-a \[^/\]" $saved_log match] } {
+	set saved_log [string replace $saved_log 0 2]
+	log_file
+	log_file -a "[pwd]/$saved_log"
+    }
+
+    # Call the builtin version of cd.
+    builtin_cd $dir
+}
+
 # Always load compatibility stuff.
 load_lib future.exp
-- 
2.17.2 (Apple Git-113)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Testsuite: Ensure changing directory does not break the log file
  2019-02-21 10:34 [PATCH] Testsuite: Ensure changing directory does not break the log file Alan Hayward
@ 2019-02-21 22:40 ` Tom Tromey
  2019-02-22 12:36   ` Alan Hayward
  0 siblings, 1 reply; 5+ messages in thread
From: Tom Tromey @ 2019-02-21 22:40 UTC (permalink / raw)
  To: Alan Hayward; +Cc: gdb-patches, nd

>>>>> "Alan" == Alan Hayward <Alan.Hayward@arm.com> writes:

Alan> get_compiler_info switches to a new log file before checking the compiler
Alan> to ensure the checks are not logged.

Haha, that seems pretty gross.

Alan> The simpler and safer solution is to override the builtin cd function. The
Alan> new function checks the current log file and if the path is relative, then
Alan> it resets the logging using an absolute path. Finally it calls the builtin
Alan> cd.  This ensures get_compiler_info (and any other code) can correctly
Alan> backup and restore the current log file.

Makes sense to me.

Alan> +    if { [regexp "^-a \[^/\]" $saved_log match] } {

It may be better here to just extract the file name and either use "file normalize"
(could be done unconditionally) or look at it with "file pathtype".
See https://www.tcl.tk/man/tcl8.4/TclCmd/file.htm

Tom

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Testsuite: Ensure changing directory does not break the log file
  2019-02-21 22:40 ` Tom Tromey
@ 2019-02-22 12:36   ` Alan Hayward
  2019-02-22 14:21     ` Pedro Alves
  0 siblings, 1 reply; 5+ messages in thread
From: Alan Hayward @ 2019-02-22 12:36 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches, nd



> On 21 Feb 2019, at 22:40, Tom Tromey <tom@tromey.com> wrote:
> 
>>>>>> "Alan" == Alan Hayward <Alan.Hayward@arm.com> writes:
> 
> Alan> get_compiler_info switches to a new log file before checking the compiler
> Alan> to ensure the checks are not logged.
> 
> Haha, that seems pretty gross.

It was quite a fun issue to track down :)

> 
> Alan> The simpler and safer solution is to override the builtin cd function. The
> Alan> new function checks the current log file and if the path is relative, then
> Alan> it resets the logging using an absolute path. Finally it calls the builtin
> Alan> cd.  This ensures get_compiler_info (and any other code) can correctly
> Alan> backup and restore the current log file.
> 
> Makes sense to me.
> 
> Alan> +    if { [regexp "^-a \[^/\]" $saved_log match] } {
> 
> It may be better here to just extract the file name and either use "file normalize"
> (could be done unconditionally) or look at it with "file pathtype".
> See https://www.tcl.tk/man/tcl8.4/TclCmd/file.htm
> 
> Tom

Re-written using normalize and I also made the checking better.  With this version
it will be safe regardless of the arguments used for log_file.

This version ok?



diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index d05854329d..f052bd2f3d 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -6284,5 +6284,37 @@ proc gdb_define_cmd {command command_list} {
     }
 }

+# Safe version of cd that ensures the log file is not stopped.
+
+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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Testsuite: Ensure changing directory does not break the log file
  2019-02-22 12:36   ` Alan Hayward
@ 2019-02-22 14:21     ` Pedro Alves
  2019-02-22 17:10       ` Alan Hayward
  0 siblings, 1 reply; 5+ messages in thread
From: Pedro Alves @ 2019-02-22 14:21 UTC (permalink / raw)
  To: Alan Hayward, Tom Tromey; +Cc: gdb-patches, nd

On 02/22/2019 12:36 PM, Alan Hayward wrote:
> +# Safe version of cd that ensures the log file is not stopped.

This comment seems unclear to me, if you don't consider the email context.

What does it mean to "stop a file", for instance?

How about:

   # 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 } {

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Testsuite: Ensure changing directory does not break the log file
  2019-02-22 14:21     ` Pedro Alves
@ 2019-02-22 17:10       ` Alan Hayward
  0 siblings, 0 replies; 5+ messages in thread
From: Alan Hayward @ 2019-02-22 17:10 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Tom Tromey, gdb-patches, nd



> On 22 Feb 2019, at 14:21, Pedro Alves <palves@redhat.com> wrote:
> 
> On 02/22/2019 12:36 PM, Alan Hayward wrote:
>> +# Safe version of cd that ensures the log file is not stopped.
> 
> This comment seems unclear to me, if you don't consider the email context.
> 
> What does it mean to "stop a file", for instance?
> 
> How about:
> 
>   # 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.
> 

Ok, I’m happy with switching to that.  I wanted to keep the comment a
little more generic, but agreed it makes more sense this way.


Alan.



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-02-22 17:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-21 10:34 [PATCH] Testsuite: Ensure changing directory does not break the log file Alan Hayward
2019-02-21 22:40 ` Tom Tromey
2019-02-22 12:36   ` Alan Hayward
2019-02-22 14:21     ` Pedro Alves
2019-02-22 17:10       ` Alan Hayward

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).