[RFC/PATCH] Disable styling when running in batch mode

Message ID 20190218110353.5160-1-alan.hayward@arm.com
State New
Headers show
Series
  • [RFC/PATCH] Disable styling when running in batch mode
Related show

Commit Message

Alan Hayward Feb. 18, 2019, 11:04 a.m.
The GCC Guality testsuite within GCC compiles C/C++ files in GCC at
various optimization levels then debugs them in GDB, checking that
program values can be read.  This is done within the dejagnu framework.

The new style options in GDB have broken many of the tests due to the
testsuite being unable to process the new control characters.  The fix
in Guality is to either to improve the string matching or to disable
styling on the cli or init file (after checking gdb is recent enough
to support styling).

This fix will also need making an any other testsuites in the wild
that use GDB.

An alternative would be to automatically disable styling when using GDB
in batch mode.  The reasoning here is that batch mode is only used when
automating GDB and any output will be processed later either with text
processing tools or viewed in text editors, many of these will not
correctly handle the control characters by default.  This ensures GDB
continues to work as expected.  Anyone who explicitly wants styling in
batch mode can enable it either in the init file or adding to the batch
file - but that would not be the standard use case.

Patch simply disables style after reading the batch command flag, before
reading in the init file or batch file.

gdb/ChangeLog:

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

	* main.c (captured_main_1): Disable styling in batch mode.
---
 gdb/main.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

-- 
2.17.2 (Apple Git-113)

Comments

Eli Zaretskii Feb. 18, 2019, 4 p.m. | #1
> From: Alan Hayward <Alan.Hayward@arm.com>

> CC: nd <nd@arm.com>, Alan Hayward <Alan.Hayward@arm.com>

> Date: Mon, 18 Feb 2019 11:04:01 +0000

> 

> Patch simply disables style after reading the batch command flag, before

> reading in the init file or batch file.

> 

> gdb/ChangeLog:

> 

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

> 

> 	* main.c (captured_main_1): Disable styling in batch mode.


If this is accepted, it should be documented in the GDB manual and in
NEWS.

Thanks.
Tom Tromey Feb. 19, 2019, 5:36 p.m. | #2
>>>>> "Alan" == Alan Hayward <Alan.Hayward@arm.com> writes:


Alan> Patch simply disables style after reading the batch command flag, before
Alan> reading in the init file or batch file.

I had left this enabled intentionally, but after thinking about it, I
think your rationale makes sense; and in any case the rare user who
wants batch mode with styling can use -iex or the like to re-enable it.

So, I think the patch is ok.

thanks,
Tom
Alan Hayward Feb. 20, 2019, 11:46 a.m. | #3
> On 19 Feb 2019, at 17:36, Tom Tromey <tom@tromey.com> wrote:

> 

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

> 

> Alan> Patch simply disables style after reading the batch command flag, before

> Alan> reading in the init file or batch file.

> 

> I had left this enabled intentionally, but after thinking about it, I

> think your rationale makes sense; and in any case the rare user who

> wants batch mode with styling can use -iex or the like to re-enable it.

> 

> So, I think the patch is ok.

> 


Thanks.
In addition to the patch, I’ve been wondering if we want a command line
argument to explicitly enable or disable style. I think the answer is no,
because it’s better for the user to add to the init file or batch script.
(But thought that it is worth mentioning).


> On 18 Feb 2019, at 16:00, Eli Zaretskii <eliz@gnu.org> wrote:

> 

>> From: Alan Hayward <Alan.Hayward@arm.com>

>> CC: nd <nd@arm.com>, Alan Hayward <Alan.Hayward@arm.com>

>> Date: Mon, 18 Feb 2019 11:04:01 +0000

>> 

>> Patch simply disables style after reading the batch command flag, before

>> reading in the init file or batch file.

>> 

>> gdb/ChangeLog:

>> 

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

>> 

>> 	* main.c (captured_main_1): Disable styling in batch mode.

> 

> If this is accepted, it should be documented in the GDB manual and in

> NEWS.

> 

> Thanks.


Agreed. I’ll post a patch for this later this week.



Alan.
Tom Tromey Feb. 20, 2019, 6:14 p.m. | #4
>>>>> "Alan" == Alan Hayward <Alan.Hayward@arm.com> writes:


Alan> In addition to the patch, I’ve been wondering if we want a command line
Alan> argument to explicitly enable or disable style. I think the answer is no,

I agree, let's not -- it's easy enough to do with -ex/-iex/etc, and
styling doesn't seem so very important that it deserves a new command
line option.

Tom

Patch

diff --git a/gdb/main.c b/gdb/main.c
index a7283902fe..e14dd06fa8 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -47,6 +47,7 @@ 
 #include "common/signals-state-save-restore.h"
 #include <vector>
 #include "common/pathstuff.h"
+#include "cli/cli-style.h"
 
 /* The selected interpreter.  This will be used as a set command
    variable, so it should always be malloc'ed - since
@@ -850,7 +851,12 @@  captured_main_1 (struct captured_main_args *context)
       }
 
     if (batch_flag)
-      quiet = 1;
+      {
+	quiet = 1;
+
+	/* Disable all output styling when running in batch mode.  */
+	cli_styling = 0;
+      }
   }
 
   save_original_signals_state (quiet);