[2/4] testsuite: Add option to capture GDB debug

Message ID 20190423130624.94781-3-alan.hayward@arm.com
State New
Headers show
Series
  • Capture GDB debug when running the testsuite
Related show

Commit Message

Alan Hayward April 23, 2019, 1:06 p.m.
Add both board option and environment variable which enables gdb
debug via a comma separated list and sends it to the file gdb.debug,
located in the output directory for the current test.  Document this.

Add support for the environment variable in the Makefile.

The testsuite can be run with gdb debug enabled in the following way:

	make check GDB_DEBUG="infrun,target,remote"

gdb/testsuite/ChangeLog:

2019-04-23  Alan Hayward  <alan.hayward@arm.com>

	* Makefile.in: Pass through GDB_DEBUG.
	* README (Testsuite Parameters): Add GDB_DEBUG.
        (gdb,debug): Add board setting.
 	* lib/gdb.exp (default_gdb_start): Start debugging.
 	(gdb_debug_enabled): New procedure.
 	(gdb_debug_init): Likewise.
---
 gdb/testsuite/Makefile.in |  6 ++++-
 gdb/testsuite/README      | 16 +++++++++++++
 gdb/testsuite/lib/gdb.exp | 49 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 70 insertions(+), 1 deletion(-)

-- 
2.20.1 (Apple Git-117)

Comments

Tom Tromey April 25, 2019, 2:31 p.m. | #1
>>>>> "Alan" == Alan Hayward <Alan.Hayward@arm.com> writes:


Alan> @@ -1716,6 +1716,8 @@ proc default_gdb_start { } {
Alan>  	    warning "Couldn't set the width to 0."
Alan>  	}
Alan>      }
Alan> +
Alan> +    gdb_debug_init

One question I have is how this interacts with tests that run gdb
multiple times.  Is there just one log?

Alan> +    if ![info exists gdbdebug] {

I think it's preferable to brace expressions, like "if {![info exists...]}".
I guess it's just stylistic though.

Alan> +  # First ensure logging is off.
Alan> +  gdb_test_no_output "set logging off"

Related to the multiple gdb invocations question -- I think this will
result in duplicate test names, so something extra should probably be
done here.

thanks,
Tom
Alan Hayward April 25, 2019, 3:12 p.m. | #2
Thanks for the reviews. I’ll push patch 4, and repost the others
with the suggested changes.


> On 25 Apr 2019, at 15:31, Tom Tromey <tom@tromey.com> wrote:

> 

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

> 

> Alan> @@ -1716,6 +1716,8 @@ proc default_gdb_start { } {

> Alan>  	    warning "Couldn't set the width to 0."

> Alan>  	}

> Alan>      }

> Alan> +

> Alan> +    gdb_debug_init

> 

> One question I have is how this interacts with tests that run gdb

> multiple times.  Is there just one log?


By default the log files are opened in append mode. So everything should
happily go to a single file. I’ll double check.

> 

> Alan> +    if ![info exists gdbdebug] {

> 

> I think it's preferable to brace expressions, like "if {![info exists...]}".

> I guess it's just stylistic though.


Ok.

> 

> Alan> +  # First ensure logging is off.

> Alan> +  gdb_test_no_output "set logging off"

> 

> Related to the multiple gdb invocations question -- I think this will

> result in duplicate test names, so something extra should probably be

> done here.

> 


I can switch this to use “send_gdb” in the same way "set height 0” is used.
It’ll also stop the number of passes increasing when debug is enabled.


> thanks,

> Tom


Oh, and earlier I got a mailbox full bounce back from your email when I sent
the reply to the PIE email:
"550 5.0.350 Remote server returned an error -> 550 Mailbox is full / Blocks limit exceeded / Inode limit exceeded”


Alan.

Patch

diff --git a/gdb/testsuite/Makefile.in b/gdb/testsuite/Makefile.in
index 6ee4fc36f0..6625512d50 100644
--- a/gdb/testsuite/Makefile.in
+++ b/gdb/testsuite/Makefile.in
@@ -52,6 +52,8 @@  RUNTESTFLAGS =
 
 FORCE_PARALLEL =
 
+GDB_DEBUG =
+
 # Default number of iterations that we will use to run the testsuite
 # if the user does not specify the RACY_ITER environment variable
 # (e.g., when the user calls the make rule directly from the command
@@ -162,13 +164,15 @@  check-read1:
 # status.
 TIMESTAMP = $(if $(TS),| $(srcdir)/print-ts.py $(if $(TS_FORMAT),$(TS_FORMAT),),)
 
+gdb_debug = $(if $(GDB_DEBUG),GDB_DEBUG=$(GDB_DEBUG) ; export GDB_DEBUG ;,)
+
 # All the hair to invoke dejagnu.  A given invocation can just append
 # $(RUNTESTFLAGS)
 DO_RUNTEST = \
 	rootme=`pwd`; export rootme; \
 	srcdir=${srcdir} ; export srcdir ; \
 	EXPECT=${EXPECT} ; export EXPECT ; \
-	EXEEXT=${EXEEXT} ; export EXEEXT ; \
+	EXEEXT=${EXEEXT} ; export EXEEXT ; $(gdb_debug) \
         $(RPATH_ENVVAR)=$$rootme/../../expect:$$rootme/../../libstdc++:$$rootme/../../tk/unix:$$rootme/../../tcl/unix:$$rootme/../../bfd:$$rootme/../../opcodes:$$$(RPATH_ENVVAR); \
 	export $(RPATH_ENVVAR); \
 	if [ -f $${rootme}/../../expect/expect ] ; then  \
diff --git a/gdb/testsuite/README b/gdb/testsuite/README
index db90ea4698..e17f218da8 100644
--- a/gdb/testsuite/README
+++ b/gdb/testsuite/README
@@ -293,6 +293,15 @@  can do:
 
 	make check TS=1 TS_FORMAT='[%b %H:%S]'
 
+GDB_DEBUG
+
+When set gdb debug is sent to the file gdb.debug in the test output
+directory.  It should be set to a comma separated list of gdb debug
+components.
+For example, to turn on debugging for infrun and target, you can do:
+
+	make check GDB_DEBUG="infrun,target"
+
 Race detection
 **************
 
@@ -497,6 +506,13 @@  gdb,nopie_flag
   The flag required to force the compiler to produce non-position-independent
   executables.
 
+gdb,debug
+
+  When set gdb debug is sent to the file gdb.debug in the test output
+  directory.  It should be set to a comma separated list of gdb debug
+  components. For example, to turn on debugging for infrun and target, set to
+  "infrun,target".
+
 Testsuite Organization
 **********************
 
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 1176fdded1..896cd80741 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -1716,6 +1716,8 @@  proc default_gdb_start { } {
 	    warning "Couldn't set the width to 0."
 	}
     }
+
+    gdb_debug_init
     return 0
 }
 
@@ -6361,5 +6363,52 @@  proc gdb_supported_languages {} {
 		opencl rust minimal ada]
 }
 
+# Check if debugging is enabled for gdb.
+
+proc gdb_debug_enabled { } {
+    global gdbdebug
+
+    # If not already read, get the debug setting from environment or board setting.
+    if ![info exists gdbdebug] {
+	global env
+	if [info exists env(GDB_DEBUG)] {
+	    set gdbdebug $env(GDB_DEBUG)
+	} elseif [target_info exists gdb,debug] {
+	    set gdbdebug [target_info gdb,debug]
+	} else {
+	    return 0
+	}
+    }
+
+    # Ensure it not empty.
+    return [expr { $gdbdebug != "" }]
+}
+
+# Turn on debugging if enabled, or reset if already on.
+
+proc gdb_debug_init { } {
+
+  if ![gdb_debug_enabled] {
+    return;
+  }
+
+  # First ensure logging is off.
+  gdb_test_no_output "set logging off"
+
+  set debugfile [standard_output_file gdb.debug]
+  gdb_test_no_output "set logging file $debugfile"
+
+  gdb_test_no_output "set logging debugredirect"
+
+  global gdbdebug
+
+  foreach entry [split $gdbdebug ,] {
+    gdb_test_no_output "set debug $entry 1"
+  }
+
+  # Now that everything is set, enable logging.
+  gdb_test "set logging on" ".*" "Enable logging"
+}
+
 # Always load compatibility stuff.
 load_lib future.exp