Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] GDB testsuite: Suppress GCC's colored output
@ 2017-08-02 17:35 Andreas Arnez
  2017-08-02 20:22 ` Simon Marchi
       [not found] ` <86h8xn3833.fsf@gmail.com>
  0 siblings, 2 replies; 9+ messages in thread
From: Andreas Arnez @ 2017-08-02 17:35 UTC (permalink / raw)
  To: gdb-patches

Newer GCC versions yield colored diagnostic messages by default, which may
be useful when executing GDB interactively from a terminal.  But when run
from a GDB test case, the compiler output is written into gdb.log, where
such escape sequences are usually more inhibiting than helpful to the
evaluation of test results.  So this patch suppresses that.

gdb/testsuite/ChangeLog:

	* lib/gdb.exp (gdb_compile): Suppress GCC's coloring of messages.
---
 gdb/testsuite/lib/gdb.exp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 3d3eaab..9a5c27f 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -3552,6 +3552,9 @@ proc gdb_compile {source dest type options} {
 	}
     }
 
+    # Stop the compiler from producing colored output.
+    setenv GCC_COLORS ""
+
     set result [target_compile $source $dest $type $options]
 
     # Prune uninteresting compiler (and linker) output.
-- 
2.5.0


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

* Re: [PATCH] GDB testsuite: Suppress GCC's colored output
  2017-08-02 17:35 [PATCH] GDB testsuite: Suppress GCC's colored output Andreas Arnez
@ 2017-08-02 20:22 ` Simon Marchi
  2017-08-03 11:13   ` Andreas Arnez
       [not found] ` <86h8xn3833.fsf@gmail.com>
  1 sibling, 1 reply; 9+ messages in thread
From: Simon Marchi @ 2017-08-02 20:22 UTC (permalink / raw)
  To: Andreas Arnez; +Cc: gdb-patches

On 2017-08-02 19:35, Andreas Arnez wrote:
> Newer GCC versions yield colored diagnostic messages by default, which 
> may
> be useful when executing GDB interactively from a terminal.  But when 
> run
> from a GDB test case, the compiler output is written into gdb.log, 
> where
> such escape sequences are usually more inhibiting than helpful to the
> evaluation of test results.  So this patch suppresses that.

That's because you are not using the right viewer :).  Try "less -R 
gdb.log", you should see the rainbow.

> 
> gdb/testsuite/ChangeLog:
> 
> 	* lib/gdb.exp (gdb_compile): Suppress GCC's coloring of messages.
> ---
>  gdb/testsuite/lib/gdb.exp | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
> index 3d3eaab..9a5c27f 100644
> --- a/gdb/testsuite/lib/gdb.exp
> +++ b/gdb/testsuite/lib/gdb.exp
> @@ -3552,6 +3552,9 @@ proc gdb_compile {source dest type options} {
>  	}
>      }
> 
> +    # Stop the compiler from producing colored output.
> +    setenv GCC_COLORS ""
> +
>      set result [target_compile $source $dest $type $options]
> 
>      # Prune uninteresting compiler (and linker) output.

I was wondering why GCC showed colors even though it's not invoked 
"interactively".  Dejagnu uses expect's spawn to spawn processes, 
including the compiler.  spawn allocates a tty for the subprocess, which 
is what GCC checks to determine whether or not to enable colors.

You patch LGTM, but please leave the patch for review for a few days, 
then push it if nobody says anything.

Thanks!

Simon


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

* Re: [PATCH] GDB testsuite: Suppress GCC's colored output
  2017-08-02 20:22 ` Simon Marchi
@ 2017-08-03 11:13   ` Andreas Arnez
  0 siblings, 0 replies; 9+ messages in thread
From: Andreas Arnez @ 2017-08-03 11:13 UTC (permalink / raw)
  To: Simon Marchi; +Cc: gdb-patches

On Wed, Aug 02 2017, Simon Marchi wrote:

> On 2017-08-02 19:35, Andreas Arnez wrote:
>> Newer GCC versions yield colored diagnostic messages by default, which
>> may
>> be useful when executing GDB interactively from a terminal.  But when
>> run
>> from a GDB test case, the compiler output is written into gdb.log, where
>> such escape sequences are usually more inhibiting than helpful to the
>> evaluation of test results.  So this patch suppresses that.
>
> That's because you are not using the right viewer :).  Try "less -R 
> gdb.log", you should see the rainbow.

Right...  That's why I wrote "usually".  Such as when using "grep",
loading the file into an editor, pasting the error message into an
e-Mail, etc.

>
>>
>> gdb/testsuite/ChangeLog:
>>
>> 	* lib/gdb.exp (gdb_compile): Suppress GCC's coloring of messages.
>> ---
>>  gdb/testsuite/lib/gdb.exp | 3 +++
>>  1 file changed, 3 insertions(+)
>>
>> diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
>> index 3d3eaab..9a5c27f 100644
>> --- a/gdb/testsuite/lib/gdb.exp
>> +++ b/gdb/testsuite/lib/gdb.exp
>> @@ -3552,6 +3552,9 @@ proc gdb_compile {source dest type options} {
>>  	}
>>      }
>>
>> +    # Stop the compiler from producing colored output.
>> +    setenv GCC_COLORS ""
>> +
>>      set result [target_compile $source $dest $type $options]
>>
>>      # Prune uninteresting compiler (and linker) output.
>
> I was wondering why GCC showed colors even though it's not invoked
> "interactively".  Dejagnu uses expect's spawn to spawn processes,
> including the compiler.  spawn allocates a tty for the subprocess, which
> is what GCC checks to determine whether or not to enable colors.

Right.  If spawn used a pipe instead of a pseudo-tty, then GCC wouldn't
show colors.

> You patch LGTM, but please leave the patch for review for a few days, then
> push it if nobody says anything.

OK.

--
Andreas


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

* Re: [PATCH] GDB testsuite: Suppress GCC's colored output
       [not found] ` <86h8xn3833.fsf@gmail.com>
@ 2017-08-04 12:19   ` Simon Marchi
  2017-08-04 13:00     ` Yao Qi
  2017-08-08 18:29   ` Andreas Arnez
  1 sibling, 1 reply; 9+ messages in thread
From: Simon Marchi @ 2017-08-04 12:19 UTC (permalink / raw)
  To: Yao Qi; +Cc: Andreas Arnez, gdb-patches

On 2017-08-04 13:06, Yao Qi wrote:
> Andreas Arnez <arnez@linux.vnet.ibm.com> writes:
> 
> Hi Andreas,
> 
>> +    # Stop the compiler from producing colored output.
>> +    setenv GCC_COLORS ""
>> +
> 
> This doesn't work for remote host.  How about passing option
> -fno-color-diagnostics to compiler which supports that option?  Both 
> gcc
> (4.9 and later) and clang has this option.

My gcc (5.4) doesn't recognize it:

$ gcc -fno-color-diagnostics test.c
gcc: error: unrecognized command line option ‘-fno-color-diagnostics’

It knows about -fdiagnostics-color=never however, which clang seems to 
recognize as well.  It would be nice however not to restrict the 
compiler version used for testing just for this.  Can we write a small 
proc that checks if the compiler recognizes that flag and only include 
it if it does?

Simon


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

* Re: [PATCH] GDB testsuite: Suppress GCC's colored output
  2017-08-04 12:19   ` Simon Marchi
@ 2017-08-04 13:00     ` Yao Qi
  0 siblings, 0 replies; 9+ messages in thread
From: Yao Qi @ 2017-08-04 13:00 UTC (permalink / raw)
  To: Simon Marchi; +Cc: Andreas Arnez, gdb-patches

Simon Marchi <simon.marchi@polymtl.ca> writes:

> My gcc (5.4) doesn't recognize it:
>
> $ gcc -fno-color-diagnostics test.c
> gcc: error: unrecognized command line option ‘-fno-color-diagnostics’
>

Ah, sorry.  What I meant is -fdiagnostics-color=never.

> It knows about -fdiagnostics-color=never however, which clang seems to
> recognize as well.  It would be nice however not to restrict the
> compiler version used for testing just for this.  Can we write a small
> proc that checks if the compiler recognizes that flag and only include
> it if it does?

Yes, we can do that, but be careful on the recursive calls here.  We
want to pass -fdiagnostics-color=never to compiler during compilation,
but we need to check whether compiler understands this option or not.
When we test compiler, we may pass -fdiagnostics-color=never to compiler
to try to compile something again to see if compiler understands.

-- 
Yao (齐尧)


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

* Re: [PATCH] GDB testsuite: Suppress GCC's colored output
       [not found] ` <86h8xn3833.fsf@gmail.com>
  2017-08-04 12:19   ` Simon Marchi
@ 2017-08-08 18:29   ` Andreas Arnez
  2017-08-09 10:01     ` Simon Marchi
  2017-08-09 10:29     ` Yao Qi
  1 sibling, 2 replies; 9+ messages in thread
From: Andreas Arnez @ 2017-08-08 18:29 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb-patches

On Fri, Aug 04 2017, Yao Qi wrote:

> Andreas Arnez <arnez@linux.vnet.ibm.com> writes:
>
> Hi Andreas,
>
>> +    # Stop the compiler from producing colored output.
>> +    setenv GCC_COLORS ""
>> +
>
> This doesn't work for remote host.

Hm, what scenario are you referring to?  It *does* work with
"--target_board=native-gdbserver", at least on the system I've tested it
on.  And a cross-target config should work as well, right?

> How about passing option -fno-color-diagnostics to compiler which
> supports that option?  Both gcc (4.9 and later) and clang has this
> option.

Actually, clang only, AFAIK.  And I don't know that there is a
compatible option between GCC and clang for disabling colored
diagnostics.  Clang's manual page (1) mentions

  -f[no-]color-diagnostics

whereas GCC has 

  -fdiagnostics-color[=WHEN]
  -fno-diagnostics-color

So unless I missed something, we have to handle clang and GCC
separately.

See below for an alternative patch that tries the GCC option
"-fdiagnostics-color=never".  We could possibly enrich this and try
clang's "-fno-color-diagnostics" if that fails.


* (1) https://clang.llvm.org/docs/UsersManual.html

--
Andreas


Subject: [PATCH v2] GDB testsuite: Suppress GCC's colored output

Newer GCC versions yield colored diagnostic messages by default, which may
be useful when executing GDB interactively from a terminal.  But when run
from a GDB test case, the compiler output is written into gdb.log, where
such escape sequences are usually more inhibiting than helpful to the
evaluation of test results.  So this patch suppresses that.

gdb/testsuite/ChangeLog:

	* lib/gdb.exp (universal_compile_options): New caching proc.
	(gdb_compile): Suppress GCC's coloring of messages.
---
 gdb/testsuite/lib/gdb.exp | 30 +++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 3d3eaab..51bf848 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -3368,6 +3368,34 @@ proc gdb_wrapper_init { args } {
     set gdb_wrapper_target [current_target_name]
 }
 
+# Determine options that we always want to pass to the compiler.
+gdb_caching_proc universal_compile_options {
+    set me "universal_compile_options"
+    set options {}
+
+    set src [standard_temp_file ccopts[pid].c]
+    set obj [standard_temp_file ccopts[pid].o]
+
+    gdb_produce_source $src {
+	int foo(void) { return 0; }
+    }
+
+    # Try an option for disabling colored diagnostics.  Some compilers
+    # yield colored diagnostics by default (when run from a tty) unless
+    # such an option is specified.
+    set opt "additional_flags=-fdiagnostics-color=never"
+    set lines [target_compile $src $obj object [list "quiet" $opt]]
+    if [string match "" $lines] then {
+	# Seems to have worked; use the option.
+	lappend options $opt
+    }
+    file delete $src
+    file delete $obj
+
+    verbose "$me:  returning $options" 2
+    return $options
+}
+
 # Some targets need to always link a special object in.  Save its path here.
 global gdb_saved_set_unbuffered_mode_obj
 set gdb_saved_set_unbuffered_mode_obj ""
@@ -3419,7 +3447,7 @@ proc gdb_compile {source dest type options} {
 
     # Add platform-specific options if a shared library was specified using
     # "shlib=librarypath" in OPTIONS.
-    set new_options ""
+    set new_options [universal_compile_options]
     set shlib_found 0
     set shlib_load 0
     foreach opt $options {
-- 
2.5.0


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

* Re: [PATCH] GDB testsuite: Suppress GCC's colored output
  2017-08-08 18:29   ` Andreas Arnez
@ 2017-08-09 10:01     ` Simon Marchi
  2017-08-09 10:29     ` Yao Qi
  1 sibling, 0 replies; 9+ messages in thread
From: Simon Marchi @ 2017-08-09 10:01 UTC (permalink / raw)
  To: Andreas Arnez; +Cc: Yao Qi, gdb-patches

On 2017-08-08 20:28, Andreas Arnez wrote:
> On Fri, Aug 04 2017, Yao Qi wrote:
> 
>> Andreas Arnez <arnez@linux.vnet.ibm.com> writes:
>> 
>> Hi Andreas,
>> 
>>> +    # Stop the compiler from producing colored output.
>>> +    setenv GCC_COLORS ""
>>> +
>> 
>> This doesn't work for remote host.
> 
> Hm, what scenario are you referring to?  It *does* work with
> "--target_board=native-gdbserver", at least on the system I've tested 
> it
> on.  And a cross-target config should work as well, right?

I believe Yao meant "host" in the build/host/target sense.  The debugger 
and compiler you are producing run on the host machine, doing some 
compiling/debugging about the target architecture. Let's say you're 
working on x86, cross-compiling a GDB that should run on ARM to debug 
native programs on ARM.  You have

build: x86
host: arm
target: arm

When you run the GDB testsuite, it's on your x86 machine, but the GDB 
you built has to run on an ARM board, therefore you will have a remote 
host.  You would then most likely specify the same host and target 
(though they could be different), with --host_board=my-arm-board 
--target_board=my-arm-board.  The compilation of test cases also happens 
on the host, which means it will also be remote.  And that's where 
unsetting the GCC_COLORS environment variable on the build machine 
doesn't help.

>> How about passing option -fno-color-diagnostics to compiler which
>> supports that option?  Both gcc (4.9 and later) and clang has this
>> option.
> 
> Actually, clang only, AFAIK.  And I don't know that there is a
> compatible option between GCC and clang for disabling colored
> diagnostics.  Clang's manual page (1) mentions
> 
>   -f[no-]color-diagnostics
> 
> whereas GCC has
> 
>   -fdiagnostics-color[=WHEN]
>   -fno-diagnostics-color
> 
> So unless I missed something, we have to handle clang and GCC
> separately.
> 
> See below for an alternative patch that tries the GCC option
> "-fdiagnostics-color=never".  We could possibly enrich this and try
> clang's "-fno-color-diagnostics" if that fails.

clang actually supports -fdiagnostics-color=never from what I saw, even 
though it may not be documented.  So we can rely on that.

> * (1) https://clang.llvm.org/docs/UsersManual.html
> 
> --
> Andreas
> 
> 
> Subject: [PATCH v2] GDB testsuite: Suppress GCC's colored output
> 
> Newer GCC versions yield colored diagnostic messages by default, which 
> may
> be useful when executing GDB interactively from a terminal.  But when 
> run
> from a GDB test case, the compiler output is written into gdb.log, 
> where
> such escape sequences are usually more inhibiting than helpful to the
> evaluation of test results.  So this patch suppresses that.
> 
> gdb/testsuite/ChangeLog:
> 
> 	* lib/gdb.exp (universal_compile_options): New caching proc.
> 	(gdb_compile): Suppress GCC's coloring of messages.
> ---
>  gdb/testsuite/lib/gdb.exp | 30 +++++++++++++++++++++++++++++-
>  1 file changed, 29 insertions(+), 1 deletion(-)
> 
> diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
> index 3d3eaab..51bf848 100644
> --- a/gdb/testsuite/lib/gdb.exp
> +++ b/gdb/testsuite/lib/gdb.exp
> @@ -3368,6 +3368,34 @@ proc gdb_wrapper_init { args } {
>      set gdb_wrapper_target [current_target_name]
>  }
> 
> +# Determine options that we always want to pass to the compiler.
> +gdb_caching_proc universal_compile_options {
> +    set me "universal_compile_options"
> +    set options {}
> +
> +    set src [standard_temp_file ccopts[pid].c]
> +    set obj [standard_temp_file ccopts[pid].o]
> +
> +    gdb_produce_source $src {
> +	int foo(void) { return 0; }
> +    }
> +
> +    # Try an option for disabling colored diagnostics.  Some compilers
> +    # yield colored diagnostics by default (when run from a tty) 
> unless
> +    # such an option is specified.
> +    set opt "additional_flags=-fdiagnostics-color=never"
> +    set lines [target_compile $src $obj object [list "quiet" $opt]]
> +    if [string match "" $lines] then {
> +	# Seems to have worked; use the option.
> +	lappend options $opt
> +    }
> +    file delete $src
> +    file delete $obj
> +
> +    verbose "$me:  returning $options" 2
> +    return $options
> +}
> +
>  # Some targets need to always link a special object in.  Save its path 
> here.
>  global gdb_saved_set_unbuffered_mode_obj
>  set gdb_saved_set_unbuffered_mode_obj ""
> @@ -3419,7 +3447,7 @@ proc gdb_compile {source dest type options} {
> 
>      # Add platform-specific options if a shared library was specified 
> using
>      # "shlib=librarypath" in OPTIONS.
> -    set new_options ""
> +    set new_options [universal_compile_options]
>      set shlib_found 0
>      set shlib_load 0
>      foreach opt $options {

I have not tried it yet, but at first glance it seems on the right path.

Thanks,

Simon


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

* Re: [PATCH] GDB testsuite: Suppress GCC's colored output
  2017-08-08 18:29   ` Andreas Arnez
  2017-08-09 10:01     ` Simon Marchi
@ 2017-08-09 10:29     ` Yao Qi
  2017-08-14 18:32       ` Andreas Arnez
  1 sibling, 1 reply; 9+ messages in thread
From: Yao Qi @ 2017-08-09 10:29 UTC (permalink / raw)
  To: Andreas Arnez; +Cc: gdb-patches

Andreas Arnez <arnez@linux.vnet.ibm.com> writes:

Hi Andreas,

> gdb/testsuite/ChangeLog:
>
> 	* lib/gdb.exp (universal_compile_options): New caching proc.
> 	(gdb_compile): Suppress GCC's coloring of messages.

Patch is good to me.

-- 
Yao (齐尧)


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

* Re: [PATCH] GDB testsuite: Suppress GCC's colored output
  2017-08-09 10:29     ` Yao Qi
@ 2017-08-14 18:32       ` Andreas Arnez
  0 siblings, 0 replies; 9+ messages in thread
From: Andreas Arnez @ 2017-08-14 18:32 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb-patches

On Wed, Aug 09 2017, Yao Qi wrote:

> Andreas Arnez <arnez@linux.vnet.ibm.com> writes:
>
> Hi Andreas,
>
>> gdb/testsuite/ChangeLog:
>>
>> 	* lib/gdb.exp (universal_compile_options): New caching proc.
>> 	(gdb_compile): Suppress GCC's coloring of messages.
>
> Patch is good to me.

Thanks, pushed.

--
Andreas


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

end of thread, other threads:[~2017-08-14 18:32 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-02 17:35 [PATCH] GDB testsuite: Suppress GCC's colored output Andreas Arnez
2017-08-02 20:22 ` Simon Marchi
2017-08-03 11:13   ` Andreas Arnez
     [not found] ` <86h8xn3833.fsf@gmail.com>
2017-08-04 12:19   ` Simon Marchi
2017-08-04 13:00     ` Yao Qi
2017-08-08 18:29   ` Andreas Arnez
2017-08-09 10:01     ` Simon Marchi
2017-08-09 10:29     ` Yao Qi
2017-08-14 18:32       ` Andreas Arnez

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox