This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 3/5] Extended-remote support for exec event tests


This patch updates several exec-related tests and some of the 
library functions in order to get them running with extended-remote.
There were three changes that were required, as follows:

In gdb.base/foll-exec.exp, the proc 'zap_session' is used repeatedly
to reset the state of the debugger before the next test.  Part of
that procedure is to 'set exec-file'.  For remote targets, it is
necessary to also 'set remote exec-file' to achieve the same
effect (and execute the correct binary file in the subsequent test).

In gdb.base/pie-execl.exp, there is an expect statement with an
expression that is used to match output from both gdb and the
program under debug.  For the remote target, this had to be 
split into two expressions, using $inferior_spawn_id to match
the output from the program.

Because I had encountered problems with extended-remote exec events
in non-stop mode in my manual testing, I added non-stop testing to
the non-ldr-exc-[1234].exp tests.  In order to set non-stop mode
for remote targets, it is necessary to 'set non-stop on' after gdb
has started, but before it connects to gdbserver.  The non-ldr-...
tests call 'clean_restart' in between tests, and it eventually calls
'gdb_start' which starts gdb and gdbserver and connects them.  By
adding a stop mode argument to clean_restart and gdb_start (in
both lib/gdb.exp and boards/native-extended-gdbserver.exp), it was
possible to set non-stop mode for remote targets.  Since the
arguments have a default value "all-stop", and only have an effect
when "non-stop" is passed, these changes do not affect any existing
test behavior.

Tested on x86_64 GNU/Linux with native, native-gdbserver, and
native-extended-gdbserver targets.

Thanks,
--Don

gdb/testsuite/
2015-07-15  Don Breazeal  <donb@codesourcery.com>

	* boards/native-extended-gdbserver.exp (gdb_start): Add
	argument 'mode' and set the stop mode before connecting.
	* gdb.base/foll-exec.exp (zap_session): For remote targets,
	set 'remote exec-file' as well as 'exec-file'.
	* gdb.base/pie-execl.exp (main): Use 'inferior_spawn_id' in
	an expect statement to match an expression with output from
	the program under debug.
	* gdb.threads/non-ldr-exc-1.exp (do_test, main): Add
	non-stop tests and pass stop mode argument to clean_restart.
	* gdb.threads/non-ldr-exc-2.exp: Likewise.
	* gdb.threads/non-ldr-exc-3.exp: Likewise.
	* gdb.threads/non-ldr-exc-4.exp: Likewise.
	* lib/gdb.exp (gdb_start): Add argument 'stop_mode', and set
	stop mode to non-stop if requested.
	(clean_restart): Add argument 'stop_mode' and pass to gdb_start.

---
 gdb/testsuite/boards/native-extended-gdbserver.exp |  8 +++++++-
 gdb/testsuite/gdb.base/foll-exec.exp               |  7 +++++++
 gdb/testsuite/gdb.base/pie-execl.exp               | 20 ++++++++++++++++++--
 gdb/testsuite/gdb.threads/non-ldr-exc-1.exp        | 16 +++++++++++-----
 gdb/testsuite/gdb.threads/non-ldr-exc-2.exp        | 22 ++++++++++++++++------
 gdb/testsuite/gdb.threads/non-ldr-exc-3.exp        | 22 ++++++++++++++++------
 gdb/testsuite/gdb.threads/non-ldr-exc-4.exp        | 16 +++++++++++-----
 gdb/testsuite/lib/gdb.exp                          | 12 ++++++++----
 8 files changed, 94 insertions(+), 29 deletions(-)

diff --git a/gdb/testsuite/boards/native-extended-gdbserver.exp b/gdb/testsuite/boards/native-extended-gdbserver.exp
index 744e044..4f43601 100644
--- a/gdb/testsuite/boards/native-extended-gdbserver.exp
+++ b/gdb/testsuite/boards/native-extended-gdbserver.exp
@@ -48,10 +48,16 @@ load_lib mi-support.exp
 # GDB is started.  Note nothing is needed for gdb_exit, since
 # gdbserver is started with --once, causing it to exit once GDB
 # disconnects.
-proc gdb_start { } {
+proc gdb_start { {stop_mode "all-stop"} } {
     # Spawn GDB.
     default_gdb_start
 
+    # Non-stop mode must be set before connecting to gdbserver for it
+    # to be enabled in gdbserver, so we set non-stop here.
+    if { $stop_mode == "non-stop" } then {
+        gdb_test_no_output "set non-stop on" "enable non-stop mode"
+    }
+
     # And then GDBserver, ready for extended-remote mode.
     gdbserver_start_multi
 
diff --git a/gdb/testsuite/gdb.base/foll-exec.exp b/gdb/testsuite/gdb.base/foll-exec.exp
index 5bea3ba..8b2eae0 100644
--- a/gdb/testsuite/gdb.base/foll-exec.exp
+++ b/gdb/testsuite/gdb.base/foll-exec.exp
@@ -68,6 +68,13 @@ proc zap_session {} {
     -re ".*$gdb_prompt $" {}
     timeout { fail "killing inferior (timeout)" ; return }
    }
+
+   # For remote targets the 'file' command doesn't change the exec-file,
+   # as it does for native targets.  In the remote case we must also use
+   # 'set remote exec-file'.
+   if [gdb_is_target_remote] then {
+     gdb_test_no_output "set remote exec-file $binfile" "reset remote exec-file to original file"
+   }
 }
 
 proc do_exec_tests {} {
diff --git a/gdb/testsuite/gdb.base/pie-execl.exp b/gdb/testsuite/gdb.base/pie-execl.exp
index 41411d5..56cd94e 100644
--- a/gdb/testsuite/gdb.base/pie-execl.exp
+++ b/gdb/testsuite/gdb.base/pie-execl.exp
@@ -16,6 +16,8 @@
 # The problem was due to amd64_skip_prologue attempting to access inferior
 # memory before the PIE (Position Independent Executable) gets relocated.
 
+global inferior_spawn_id
+
 if ![istarget *-linux*] {
     continue
 }
@@ -67,6 +69,7 @@ gdb_test_multiple "p/x &pie_execl_marker" $test {
 verbose -log "addr1 is $addr1"
 
 set test "continue"
+set matches_found 0
 gdb_test_multiple $test $test {
     -re "Error in re-setting breakpoint" {
 	fail $test
@@ -74,8 +77,21 @@ gdb_test_multiple $test $test {
     -re "Cannot access memory" {
 	fail $test
     }
-    -re "pie-execl: re-exec.*executing new program.*\r\nBreakpoint \[0-9\]+,\[^\r\n\]* pie_execl_marker .*\r\n$gdb_prompt $" {
-	pass $test
+    -re ".*executing new program.*\r\nBreakpoint \[0-9\]+,\[^\r\n\]* pie_execl_marker .*\r\n$gdb_prompt $" {
+        incr matches_found
+	if { $matches_found == 2 } {
+	    pass $test
+	} else {
+	    exp_continue
+	}
+    }
+    -i "$inferior_spawn_id" -re "pie-execl: re-exec" {
+        incr matches_found
+	if { $matches_found == 2 } {
+	    pass $test
+	} else {
+	    exp_continue
+	}
     }
 }
 
diff --git a/gdb/testsuite/gdb.threads/non-ldr-exc-1.exp b/gdb/testsuite/gdb.threads/non-ldr-exc-1.exp
index 69e5cc6..147e7f3 100644
--- a/gdb/testsuite/gdb.threads/non-ldr-exc-1.exp
+++ b/gdb/testsuite/gdb.threads/non-ldr-exc-1.exp
@@ -28,11 +28,11 @@ if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executab
     return -1
 }
 
-proc do_test { lock_sched } {
-    with_test_prefix "lock-sched$lock_sched" {
+proc do_test { lock_sched stop_mode } {
+    with_test_prefix "lock-sched$lock_sched,$stop_mode" {
 	global executable
 
-	clean_restart ${executable}
+	clean_restart ${executable} $stop_mode
 
 	if ![runto_main] {
 	    return -1
@@ -48,11 +48,17 @@ proc do_test { lock_sched } {
 	    gdb_test_no_output "set scheduler-locking on"
 	}
 
+	if { $stop_mode == "non-stop" } {
+	    gdb_test "thread 2" "Switching.*"
+	}
+
 	gdb_test "continue" \
 	    ".*is executing new program.*Breakpoint 1, main.* at .*" \
 	    "continue over exec"
     }
 }
 
-do_test 0
-do_test 1
+do_test 0 "all-stop"
+do_test 1 "all-stop"
+do_test 0 "non-stop"
+do_test 1 "non-stop"
diff --git a/gdb/testsuite/gdb.threads/non-ldr-exc-2.exp b/gdb/testsuite/gdb.threads/non-ldr-exc-2.exp
index 9386153..748ff11 100644
--- a/gdb/testsuite/gdb.threads/non-ldr-exc-2.exp
+++ b/gdb/testsuite/gdb.threads/non-ldr-exc-2.exp
@@ -29,18 +29,26 @@ if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executab
     return -1
 }
 
-proc do_test { lock_sched } {
-    with_test_prefix "lock-sched$lock_sched" {
+proc do_test { lock_sched stop_mode } {
+    with_test_prefix "lock-sched$lock_sched,$stop_mode" {
 	global executable
 
-	clean_restart ${executable}
+	clean_restart ${executable} $stop_mode
 
 	if ![runto_main] {
 	    return -1
 	}
 
 	gdb_breakpoint [gdb_get_line_number "break-here"]
-	gdb_continue_to_breakpoint "break-here" ".* break-here .*"
+	gdb_test_multiple "continue" "continue to breakpoint" {
+	    -re ".*Breakpoint.*break-here.*" {
+	        pass "continue to breakpoint"
+	    }
+	}
+
+	if { $stop_mode == "non-stop" } {
+	    gdb_test "thread 2" "Switching.*"
+	}
 
 	gdb_test "info threads" \
 	    "\r\n\[ \t\]*Id\[ \t\]+Target\[ \t\]+Id\[ \t\]+Frame\[ \t\]*\r\n\\* 2 *Thread \[^\r\n\]* at \[^\r\n\]*" \
@@ -59,5 +67,7 @@ proc do_test { lock_sched } {
     }
 }
 
-do_test 0
-do_test 1
+do_test 0 "all-stop"
+do_test 1 "all-stop"
+do_test 0 "non-stop"
+do_test 1 "non-stop"
diff --git a/gdb/testsuite/gdb.threads/non-ldr-exc-3.exp b/gdb/testsuite/gdb.threads/non-ldr-exc-3.exp
index cc7da1a..2dbcd81 100644
--- a/gdb/testsuite/gdb.threads/non-ldr-exc-3.exp
+++ b/gdb/testsuite/gdb.threads/non-ldr-exc-3.exp
@@ -31,18 +31,22 @@ if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executab
     return -1
 }
 
-proc do_test { lock_sched } {
-    with_test_prefix "lock-sched$lock_sched" {
+proc do_test { lock_sched stop_mode } {
+    with_test_prefix "lock-sched$lock_sched,$stop_mode" {
 	global executable
 
-	clean_restart ${executable}
+	clean_restart ${executable} $stop_mode
 
 	if ![runto_main] {
 	    return -1
 	}
 
 	gdb_breakpoint [gdb_get_line_number "break-here"]
-	gdb_continue_to_breakpoint "break-here" ".* break-here .*"
+	gdb_test_multiple "continue" "continue to breakpoint" {
+	    -re ".*Breakpoint.*break-here.*" {
+	        pass "continue to breakpoint"
+	    }
+	}
 
 	# Also test with sched-lock to make sure we can follow the
 	# non-leader thread execing even though the main thread wasn't
@@ -51,11 +55,17 @@ proc do_test { lock_sched } {
 	    gdb_test_no_output "set scheduler-locking on"
 	}
 
+	if { $stop_mode == "non-stop" } {
+	    gdb_test "thread 2" "Switching.*"
+	}
+
 	gdb_test "continue" \
 	    ".*is executing new program.*Breakpoint 1, main.* at .*" \
 	    "continue over exec"
     }
 }
 
-do_test 0
-do_test 1
+do_test 0 "all-stop"
+do_test 1 "all-stop"
+do_test 0 "non-stop"
+do_test 1 "non-stop"
diff --git a/gdb/testsuite/gdb.threads/non-ldr-exc-4.exp b/gdb/testsuite/gdb.threads/non-ldr-exc-4.exp
index a89b818..a9e5c5a 100644
--- a/gdb/testsuite/gdb.threads/non-ldr-exc-4.exp
+++ b/gdb/testsuite/gdb.threads/non-ldr-exc-4.exp
@@ -30,11 +30,11 @@ if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executab
     return -1
 }
 
-proc do_test { lock_sched } {
-    with_test_prefix "lock-sched$lock_sched" {
+proc do_test { lock_sched stop_mode } {
+    with_test_prefix "lock-sched$lock_sched,$stop_mode" {
 	global executable
 
-	clean_restart ${executable}
+	clean_restart ${executable} $stop_mode
 
 	if ![runto_main] {
 	    return -1
@@ -50,11 +50,17 @@ proc do_test { lock_sched } {
 	    gdb_test_no_output "set scheduler-locking on"
 	}
 
+	if { $stop_mode == "non-stop" } {
+	    gdb_test "thread 2" "Switching.*"
+	}
+
 	gdb_test "continue" \
 	    ".*is executing new program.*Breakpoint 1, main.* at .*" \
 	    "continue over exec"
     }
 }
 
-do_test 0
-do_test 1
+do_test 0 "all-stop"
+do_test 1 "all-stop"
+do_test 0 "non-stop"
+do_test 1 "non-stop"
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 0805de9..4ef72d1 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -3601,8 +3601,11 @@ proc gdb_spawn_with_cmdline_opts { cmdline_flags } {
 # Overridable function -- you can override this function in your
 # baseboard file.
 
-proc gdb_start { } {
+proc gdb_start { {stop_mode "all-stop"} } {
     default_gdb_start
+    if { $stop_mode == "non-stop" } {
+        gdb_test_no_output "set non-stop on" "enable non-stop mode"
+    }
 }
 
 proc gdb_exit { } {
@@ -4870,15 +4873,16 @@ proc build_executable { testname executable {sources ""} {options {debug}} } {
 }
 
 # Starts fresh GDB binary and loads EXECUTABLE into GDB. EXECUTABLE is
-# the basename of the binary.
+# the basename of the binary.  If MODE is "non-stop", then non-stop
+# mode will be enabled.
 # The return value is 0 for success, -1 for failure.
-proc clean_restart { executable } {
+proc clean_restart { executable {stop_mode "all-stop"} } {
     global srcdir
     global subdir
     set binfile [standard_output_file ${executable}]
 
     gdb_exit
-    gdb_start
+    gdb_start $stop_mode
     gdb_reinitialize_dir $srcdir/$subdir
     return [gdb_load ${binfile}]
 }
-- 
1.8.1.1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]