Home | History | Annotate | Line # | Download | only in gdb.threads
      1  1.1  christos # This testcase is part of GDB, the GNU debugger.
      2  1.1  christos 
      3  1.9  christos # Copyright 2014-2024 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 standard_testfile
     19  1.1  christos 
     20  1.1  christos # Run the test proper.  THREADED indicates whether to build a threaded
     21  1.1  christos # program and spawn several threads before trying to kill the program.
     22  1.1  christos 
     23  1.1  christos proc test {threaded} {
     24  1.6  christos     global testfile srcfile decimal
     25  1.1  christos 
     26  1.1  christos     with_test_prefix [expr ($threaded)?"threaded":"non-threaded"] {
     27  1.1  christos 
     28  1.1  christos 	set options {debug}
     29  1.1  christos 	if {$threaded} {
     30  1.1  christos 	    lappend options "pthreads"
     31  1.1  christos 	    lappend options "additional_flags=-DUSE_THREADS"
     32  1.1  christos 	    set prog ${testfile}_threads
     33  1.1  christos 	} else {
     34  1.1  christos 	    set prog ${testfile}_nothreads
     35  1.1  christos 	}
     36  1.1  christos 
     37  1.1  christos 	if {[prepare_for_testing "failed to prepare" $prog $srcfile $options] == -1} {
     38  1.1  christos 	    return -1
     39  1.1  christos 	}
     40  1.1  christos 
     41  1.8  christos 	if {![runto_main]} {
     42  1.1  christos 	    return
     43  1.1  christos 	}
     44  1.1  christos 
     45  1.1  christos 	set linenum [gdb_get_line_number "set break here"]
     46  1.1  christos 	gdb_breakpoint "$srcfile:$linenum"
     47  1.1  christos 	gdb_continue_to_breakpoint "break here" ".*break here.*"
     48  1.1  christos 
     49  1.1  christos 	if {$threaded} {
     50  1.4  christos 	    gdb_test "info threads" "1.*2.*3.*4.*5.*6.*" "all threads started"
     51  1.1  christos 	}
     52  1.1  christos 
     53  1.1  christos 	# This kills and ensures no output other than the prompt comes out,
     54  1.1  christos 	# like:
     55  1.1  christos 	#
     56  1.1  christos 	#  (gdb) kill
     57  1.1  christos 	#  Kill the program being debugged? (y or n) y
     58  1.1  christos 	#  (gdb)
     59  1.1  christos 	#
     60  1.1  christos 	# If we instead saw more output, like e.g., with an extended-remote
     61  1.1  christos 	# connection:
     62  1.1  christos 	#
     63  1.1  christos 	#  (gdb) kill
     64  1.1  christos 	#  Kill the program being debugged? (y or n) y
     65  1.1  christos 	#  Remote connection closed
     66  1.1  christos 	#  (gdb)
     67  1.1  christos 	#
     68  1.1  christos 	# the above would mean that the remote end crashed.
     69  1.1  christos 
     70  1.6  christos 	gdb_test_multiple "kill" "kill" {
     71  1.6  christos 	    -re "Kill the program being debugged\\? \\(y or n\\) $" {
     72  1.6  christos 		gdb_test "y" "\\\[Inferior $decimal \\(.*\\) killed\\\]" "kill"
     73  1.6  christos 	    }
     74  1.6  christos 	}
     75  1.1  christos     }
     76  1.1  christos }
     77  1.1  christos 
     78  1.1  christos foreach threaded {true false} {
     79  1.1  christos     test $threaded
     80  1.1  christos }
     81