[v2] testsuite: Add option to capture gdbserver debug

Message ID 20190417154501.30972-1-alan.hayward@arm.com
State New, archived
Headers

Commit Message

Alan Hayward April 17, 2019, 3:45 p.m. UTC
  Add both board option and environment variable which enables gdbserver
debug and sends it to the file gdbserver.log, 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 gdbserver debug enabled in the following way:

	make check GDBSERVER_DEBUG=all

Disable tspeed.exp when debugging to prevent the log file filling
many gigabytes then timing out.

gdb/testsuite/ChangeLog:

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

	* Makefile.in: Pass through GDBSERVER_DEBUG.
        * README (Testsuite Parameters): Add GDBSERVER_DEBUG.
        (gdbserver,debug): Add board setting.
        * gdb.trace/tspeed.exp: Skip when debugging.
	* lib/gdb.exp (gdbserver_debug_enabled): New procedure.
	* lib/gdbserver-support.exp: Likewise
---
 gdb/testsuite/Makefile.in               |  6 +++-
 gdb/testsuite/README                    | 19 +++++++++++++
 gdb/testsuite/gdb.trace/tspeed.exp      |  5 ++++
 gdb/testsuite/lib/gdb.exp               |  8 ++++++
 gdb/testsuite/lib/gdbserver-support.exp | 38 ++++++++++++++++++++++++-
 5 files changed, 74 insertions(+), 2 deletions(-)

-- 
2.20.1 (Apple Git-117)
  

Patch

diff --git a/gdb/testsuite/Makefile.in b/gdb/testsuite/Makefile.in
index 6ee4fc36f0..8d46fe15be 100644
--- a/gdb/testsuite/Makefile.in
+++ b/gdb/testsuite/Makefile.in
@@ -52,6 +52,8 @@  RUNTESTFLAGS =
 
 FORCE_PARALLEL =
 
+GDBSERVER_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),),)
 
+gdbserver_debug = $(if $(GDBSERVER_DEBUG),GDBSERVER_DEBUG=$(GDBSERVER_DEBUG) ; export GDBSERVER_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 ; $(gdbserver_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..40286aca04 100644
--- a/gdb/testsuite/README
+++ b/gdb/testsuite/README
@@ -293,6 +293,17 @@  can do:
 
 	make check TS=1 TS_FORMAT='[%b %H:%S]'
 
+GDBSERVER_DEBUG
+
+When set gdbserver debug is sent to the file gdbserver.log in the test
+output directory.  Valid values are:
+	debug  - turn on gdbserver debug.
+	remote - turn on gdbserver remote debug.
+	all - turn on all the above debug options.
+For example, to turn on all gdbserver debugging, you can do:
+
+	make check GDBSERVER_DEBUG=all
+
 Race detection
 **************
 
@@ -497,6 +508,14 @@  gdb,nopie_flag
   The flag required to force the compiler to produce non-position-independent
   executables.
 
+gdbserver,debug
+
+  When set gdbserver debug is sent to the file gdbserver.log in the test
+  output directory.  Valid values are:
+  "debug"  - turn on gdbserver debug.
+  "remote" - turn on gdbserver remote debug.
+  "all" - turn on all the above debug options.
+
 Testsuite Organization
 **********************
 
diff --git a/gdb/testsuite/gdb.trace/tspeed.exp b/gdb/testsuite/gdb.trace/tspeed.exp
index 6fd812e4f6..9afec64acf 100644
--- a/gdb/testsuite/gdb.trace/tspeed.exp
+++ b/gdb/testsuite/gdb.trace/tspeed.exp
@@ -19,6 +19,11 @@  if {[skip_shlib_tests]} {
     return 0
 }
 
+# Do not run if gdbsever debug is enabled - the output file is many Gb.
+if [gdbserver_debug_enabled] {
+    return 0
+}
+
 standard_testfile
 set executable $testfile
 
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 1176fdded1..00c35fd605 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -6361,5 +6361,13 @@  proc gdb_supported_languages {} {
 		opencl rust minimal ada]
 }
 
+
+# Check if debugging is enabled for gdbserver.
+
+proc gdbserver_debug_enabled { } {
+    # Always disabled for GDB only setups.
+    return 0
+}
+
 # Always load compatibility stuff.
 load_lib future.exp
diff --git a/gdb/testsuite/lib/gdbserver-support.exp b/gdb/testsuite/lib/gdbserver-support.exp
index 2cb64f7d2f..e6f875bebe 100644
--- a/gdb/testsuite/lib/gdbserver-support.exp
+++ b/gdb/testsuite/lib/gdbserver-support.exp
@@ -283,12 +283,26 @@  proc gdbserver_start { options arguments } {
 	# If gdbserver_reconnect will be called $gdbserver_reconnect_p must be
 	# set to true already during gdbserver_start.
 	global gdbserver_reconnect_p
+	global srcdir
+	global subdir
 	if {![info exists gdbserver_reconnect_p] || !$gdbserver_reconnect_p} {
 	    # GDB client could accidentally connect to a stale server.
-	    # append gdbserver_command " --debug --once"
 	    append gdbserver_command " --once"
 	}
 
+	# Enable debug if set.
+	if [gdbserver_debug_enabled] {
+	    global gdbserverdebug
+	    set debugfile [standard_output_file gdbserver.log]
+	    if { $gdbserverdebug == "debug" } {
+		append gdbserver_command " --debug --debug-file=$debugfile"
+	    } elseif { $gdbserverdebug == "remote" } {
+		append gdbserver_command " --remote-debug --debug-file=$debugfile"
+	    } elseif { $gdbserverdebug == "all" } {
+		append gdbserver_command " --debug --remote-debug --debug-file=$debugfile"
+	    }
+	}
+
 	if { $options != "" } {
 	    append gdbserver_command " $options"
 	}
@@ -561,3 +575,25 @@  proc mi_gdbserver_start_multi { } {
 
     return [mi_gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport]
 }
+
+# Check if debugging is enabled for gdbserver.
+
+proc gdbserver_debug_enabled { } {
+    global gdbserverdebug
+
+    # If not already read, get the debug setting from environment or board setting.
+    if ![info exists gdbserverdebug] {
+	global env
+	if [info exists env(GDBSERVER_DEBUG)] {
+	    set gdbserverdebug $env(GDBSERVER_DEBUG)
+	} elseif [target_info exists gdbserver,debug] {
+	    set gdbserverdebug [target_info gdbserver,debug]
+	} else {
+	    return 0
+	}
+    }
+
+    # Only return success on valid values.
+    return [expr { $gdbserverdebug == "debug" || $gdbserverdebug == "remote"
+		   || $gdbserverdebug == "all" }]
+}