Home | History | Annotate | Line # | Download | only in gdb.server
stop-reply-no-thread-multi.exp revision 1.1
      1  1.1  christos # This testcase is part of GDB, the GNU debugger.
      2  1.1  christos #
      3  1.1  christos # Copyright 2021-2023 Free Software Foundation, Inc.
      4  1.1  christos #
      5  1.1  christos # This program is free software; you can redistribute it and/or modify
      6  1.1  christos # it under the terms of the GNU General Public License as published by
      7  1.1  christos # the Free Software Foundation; either version 3 of the License, or
      8  1.1  christos # (at your option) any later version.
      9  1.1  christos #
     10  1.1  christos # This program is distributed in the hope that it will be useful,
     11  1.1  christos # but WITHOUT ANY WARRANTY; without even the implied warranty of
     12  1.1  christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13  1.1  christos # GNU General Public License for more details.
     14  1.1  christos #
     15  1.1  christos # You should have received a copy of the GNU General Public License
     16  1.1  christos # along with this program.  If not, see <http://www.gnu.org/licenses/>.
     17  1.1  christos 
     18  1.1  christos # Test how GDB handles the case where a target either doesn't use 'T'
     19  1.1  christos # packets at all or doesn't include a thread-id in a 'T' packet, AND,
     20  1.1  christos # where the test program contains multiple threads.
     21  1.1  christos #
     22  1.1  christos # In general if multiple threads are executing and the target doesn't
     23  1.1  christos # include a thread-id in its stop response then GDB will not be able
     24  1.1  christos # to correctly figure out which thread the stop applies to.
     25  1.1  christos #
     26  1.1  christos # However, this test covers a very specific case, there are multiple
     27  1.1  christos # threads but only a single thread is actually executing.  So, when
     28  1.1  christos # the stop comes from the target, without a thread-id, GDB should be
     29  1.1  christos # able to correctly figure out which thread has stopped.
     30  1.1  christos 
     31  1.1  christos load_lib gdbserver-support.exp
     32  1.1  christos 
     33  1.1  christos if { [skip_gdbserver_tests] } {
     34  1.1  christos     verbose "skipping gdbserver tests"
     35  1.1  christos     return -1
     36  1.1  christos }
     37  1.1  christos 
     38  1.1  christos standard_testfile
     39  1.1  christos if { [build_executable "failed to prepare" $testfile $srcfile {debug pthreads}] == -1 } {
     40  1.1  christos     return -1
     41  1.1  christos }
     42  1.1  christos 
     43  1.1  christos # Run the tests with different features of GDBserver disabled.
     44  1.1  christos # TARGET_NON_STOP is passed to "maint set target-non-stop".
     45  1.1  christos proc run_test { target_non_stop disable_feature } {
     46  1.1  christos     global binfile gdb_prompt decimal hex
     47  1.1  christos     global GDBFLAGS
     48  1.1  christos 
     49  1.1  christos     save_vars { GDBFLAGS } {
     50  1.1  christos 	append GDBFLAGS " -ex \"maint set target-non-stop $target_non_stop\""
     51  1.1  christos 
     52  1.1  christos 	# If GDB and GDBserver are both running locally, set the sysroot to avoid
     53  1.1  christos 	# reading files via the remote protocol.
     54  1.1  christos 	if { ![is_remote host] && ![is_remote target] } {
     55  1.1  christos 	    set GDBFLAGS "$GDBFLAGS -ex \"set sysroot\""
     56  1.1  christos 	}
     57  1.1  christos 
     58  1.1  christos 	clean_restart ${binfile}
     59  1.1  christos     }
     60  1.1  christos 
     61  1.1  christos     # Make sure we're disconnected, in case we're testing with an
     62  1.1  christos     # extended-remote board, therefore already connected.
     63  1.1  christos     gdb_test "disconnect" ".*"
     64  1.1  christos 
     65  1.1  christos     set packet_arg ""
     66  1.1  christos     if { $disable_feature != "" } {
     67  1.1  christos 	set packet_arg "--disable-packet=${disable_feature}"
     68  1.1  christos     }
     69  1.1  christos     set res [gdbserver_start $packet_arg $binfile]
     70  1.1  christos     set gdbserver_protocol [lindex $res 0]
     71  1.1  christos     set gdbserver_gdbport [lindex $res 1]
     72  1.1  christos 
     73  1.1  christos     # Disable XML-based thread listing, and multi-process extensions.
     74  1.1  christos     gdb_test_no_output "set remote threads-packet off"
     75  1.1  christos     gdb_test_no_output "set remote multiprocess-feature-packet off"
     76  1.1  christos 
     77  1.1  christos     set res [gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport]
     78  1.1  christos     if ![gdb_assert {$res == 0} "connect"] {
     79  1.1  christos 	return
     80  1.1  christos     }
     81  1.1  christos 
     82  1.1  christos     # There should be only one thread listed at this point.
     83  1.1  christos     gdb_test_multiple "info threads" "" {
     84  1.1  christos 	-re "2 Thread.*$gdb_prompt $" {
     85  1.1  christos 	    fail $gdb_test_name
     86  1.1  christos 	}
     87  1.1  christos 	-re "has terminated.*$gdb_prompt $" {
     88  1.1  christos 	    fail $gdb_test_name
     89  1.1  christos 	}
     90  1.1  christos 	-re "\\\* 1\[\t \]*Thread\[^\r\n\]*\r\n$gdb_prompt $" {
     91  1.1  christos 	    pass $gdb_test_name
     92  1.1  christos 	}
     93  1.1  christos     }
     94  1.1  christos 
     95  1.1  christos     gdb_breakpoint "unlock_worker"
     96  1.1  christos     gdb_continue_to_breakpoint "run to unlock_worker"
     97  1.1  christos 
     98  1.1  christos     # There should be two threads at this point with thread 1 selected.
     99  1.1  christos     gdb_test "info threads" \
    100  1.1  christos 	"\\\* 1\[\t \]*Thread\[^\r\n\]*\r\n  2\[\t \]*Thread\[^\r\n\]*" \
    101  1.1  christos 	"second thread should now exist"
    102  1.1  christos 
    103  1.1  christos     # Switch threads.
    104  1.1  christos     gdb_test "thread 2" ".*" "switch to second thread"
    105  1.1  christos 
    106  1.1  christos     # Now turn on scheduler-locking so that when we step thread 2 only
    107  1.1  christos     # that one thread will be set running.
    108  1.1  christos     gdb_test_no_output "set scheduler-locking on"
    109  1.1  christos 
    110  1.1  christos     # Single step thread 2.  Only the one thread will step.  When the
    111  1.1  christos     # thread stops, if the stop packet doesn't include a thread-id
    112  1.1  christos     # then GDB should still understand which thread stopped.
    113  1.1  christos     gdb_test_multiple "stepi" "" {
    114  1.1  christos 	-re -wrap "Thread 1 received signal SIGTRAP.*" {
    115  1.1  christos 	    fail $gdb_test_name
    116  1.1  christos 	}
    117  1.1  christos 	-re -wrap "$hex.*$decimal.*while \\(worker_blocked\\).*" {
    118  1.1  christos 	    pass $gdb_test_name
    119  1.1  christos 	}
    120  1.1  christos     }
    121  1.1  christos 
    122  1.1  christos     # Check that thread 2 is still selected.
    123  1.1  christos     gdb_test "info threads" \
    124  1.1  christos 	"  1\[\t \]*Thread\[^\r\n\]*\r\n\\\* 2\[\t \]*Thread\[^\r\n\]*" \
    125  1.1  christos 	"second thread should still be selected after stepi"
    126  1.1  christos 
    127  1.1  christos     # Turn scheduler locking off again so that when we continue all
    128  1.1  christos     # threads will be set running.
    129  1.1  christos     gdb_test_no_output "set scheduler-locking off"
    130  1.1  christos 
    131  1.1  christos     # Continue until exit.  The server sends a 'W' with no PID.
    132  1.1  christos     # Bad GDB gave an error like below when target is nonstop:
    133  1.1  christos     #  (gdb) c
    134  1.1  christos     #  Continuing.
    135  1.1  christos     #  No process or thread specified in stop reply: W00
    136  1.1  christos     gdb_continue_to_end "" continue 1
    137  1.1  christos }
    138  1.1  christos 
    139  1.1  christos # Disable different features within gdbserver:
    140  1.1  christos #
    141  1.1  christos # Tthread: Start GDBserver, with ";thread:NNN" in T stop replies disabled,
    142  1.1  christos #          emulating old gdbservers when debugging single-threaded programs.
    143  1.1  christos #
    144  1.1  christos # T: Start GDBserver with the entire 'T' stop reply packet disabled,
    145  1.1  christos #    GDBserver will instead send the 'S' stop reply.
    146  1.1  christos #
    147  1.1  christos # Also test both all-stop and non-stop variants of the remote
    148  1.1  christos # protocol.
    149  1.1  christos foreach_with_prefix target-non-stop {"off" "on"} {
    150  1.1  christos     foreach_with_prefix to_disable { "" Tthread T } {
    151  1.1  christos 	run_test ${target-non-stop} $to_disable
    152  1.1  christos     }
    153  1.1  christos }
    154