Home | History | Annotate | Line # | Download | only in gdb.multi
      1  1.1  christos # Copyright 2023 Free Software Foundation, Inc.
      2  1.1  christos 
      3  1.1  christos # This program is free software; you can redistribute it and/or modify
      4  1.1  christos # it under the terms of the GNU General Public License as published by
      5  1.1  christos # the Free Software Foundation; either version 3 of the License, or
      6  1.1  christos # (at your option) any later version.
      7  1.1  christos #
      8  1.1  christos # This program is distributed in the hope that it will be useful,
      9  1.1  christos # but WITHOUT ANY WARRANTY; without even the implied warranty of
     10  1.1  christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     11  1.1  christos # GNU General Public License for more details.
     12  1.1  christos #
     13  1.1  christos # You should have received a copy of the GNU General Public License
     14  1.1  christos # along with this program.  If not, see <http://www.gnu.org/licenses/>.
     15  1.1  christos 
     16  1.1  christos # Setup two inferiors.  Select one inferior and create a pending
     17  1.1  christos # thread specific breakpoint in the other inferior.
     18  1.1  christos #
     19  1.1  christos # Delete the selected inferior (the one for which the thread specific
     20  1.1  christos # breakpoint doesn't apply), and check that the breakpoint still exists.
     21  1.1  christos #
     22  1.1  christos # Repeat this process, but this time, create an inferior specific
     23  1.1  christos # breakpoint.
     24  1.1  christos 
     25  1.1  christos # The plain remote target can't do multiple inferiors.
     26  1.1  christos require !use_gdb_stub
     27  1.1  christos 
     28  1.1  christos standard_testfile
     29  1.1  christos 
     30  1.1  christos if {[prepare_for_testing "failed to prepare" $testfile $srcfile]} {
     31  1.1  christos     return -1
     32  1.1  christos }
     33  1.1  christos 
     34  1.1  christos # Setup for the tests.  Create two inferiors, both running the global
     35  1.1  christos # BINFILE, and proceed to main in both inferiors.  Delete all
     36  1.1  christos # breakpoints, and check that we do have two threads.
     37  1.1  christos #
     38  1.1  christos # Return true after a successful setup, otherwise, return false.
     39  1.1  christos proc test_setup {} {
     40  1.1  christos     clean_restart $::binfile
     41  1.1  christos 
     42  1.1  christos     if {![runto_main]} {
     43  1.1  christos 	return 0
     44  1.1  christos     }
     45  1.1  christos 
     46  1.1  christos     gdb_test "add-inferior -exec ${::binfile}" "Added inferior 2.*" \
     47  1.1  christos 	"add inferior 2"
     48  1.1  christos     gdb_test "inferior 2" "Switching to inferior 2 .*" \
     49  1.1  christos 	"select inferior 2"
     50  1.1  christos 
     51  1.1  christos     if {![runto_main]} {
     52  1.1  christos 	return 0
     53  1.1  christos     }
     54  1.1  christos 
     55  1.1  christos     delete_breakpoints
     56  1.1  christos 
     57  1.1  christos     gdb_test "info threads" \
     58  1.1  christos 	[multi_line \
     59  1.1  christos 	     "  Id\\s+Target Id\\s+Frame\\s*" \
     60  1.1  christos 	     "  1\\.1\\s+\[^\r\n\]+" \
     61  1.1  christos 	     "\\* 2\\.1\\s+\[^\r\n\]+"] \
     62  1.1  christos 	"check we have the expected threads"
     63  1.1  christos 
     64  1.1  christos     return 1
     65  1.1  christos }
     66  1.1  christos 
     67  1.1  christos # Assuming inferior 2 is already selected, kill the current inferior
     68  1.1  christos # (inferior 2), select inferior 1, and then remove inferior 2.
     69  1.1  christos proc kill_and_remove_inferior_2 {} {
     70  1.1  christos     gdb_test "kill" "" "kill inferior 2" \
     71  1.1  christos 	"Kill the program being debugged.*y or n. $" "y"
     72  1.1  christos 
     73  1.1  christos     gdb_test "inferior 1" "Switching to inferior 1 .*" \
     74  1.1  christos 	"select inferior 1"
     75  1.1  christos 
     76  1.1  christos     gdb_test_no_output "remove-inferiors 2"
     77  1.1  christos }
     78  1.1  christos 
     79  1.1  christos # Setup two inferiors, then create a breakpoint.  If BP_PENDING is
     80  1.1  christos # true then the breakpoint will be pending, otherwise, the breakpoint
     81  1.1  christos # will be non-pending.
     82  1.1  christos #
     83  1.1  christos # BP_TYPE is either 'thread' or 'inferior', and indicates if the
     84  1.1  christos # created breakpoint should be thread or inferior specific.
     85  1.1  christos #
     86  1.1  christos # The breakpoint is created while inferior 2 is selected, and the
     87  1.1  christos # thread/inferior restriction always identifies inferior 1.
     88  1.1  christos #
     89  1.1  christos # Then inferior 2 is killed and removed.
     90  1.1  christos #
     91  1.1  christos # Finally, check that the breakpoint still exists and correctly refers
     92  1.1  christos # to inferior 1.
     93  1.1  christos proc do_bp_test { bp_type bp_pending } {
     94  1.1  christos     if {![test_setup]} {
     95  1.1  christos 	return
     96  1.1  christos     }
     97  1.1  christos 
     98  1.1  christos     if { $bp_pending } {
     99  1.1  christos 	set bp_func "bar"
    100  1.1  christos     } else {
    101  1.1  christos 	set bp_func "foo"
    102  1.1  christos     }
    103  1.1  christos 
    104  1.1  christos     if { $bp_type eq "thread" } {
    105  1.1  christos 	set bp_restriction "thread 1.1"
    106  1.1  christos     } else {
    107  1.1  christos 	set bp_restriction "inferior 1"
    108  1.1  christos     }
    109  1.1  christos 
    110  1.1  christos     gdb_breakpoint "$bp_func $bp_restriction" allow-pending
    111  1.1  christos     set bp_number [get_integer_valueof "\$bpnum" "INVALID" \
    112  1.1  christos 		       "get b/p number for previous breakpoint"]
    113  1.1  christos 
    114  1.1  christos     if { $bp_restriction eq "thread 1.1" } {
    115  1.1  christos 	set bp_after_restriction "thread 1"
    116  1.1  christos     } else {
    117  1.1  christos 	set bp_after_restriction $bp_restriction
    118  1.1  christos     }
    119  1.1  christos 
    120  1.1  christos     if { $bp_pending } {
    121  1.1  christos 	set bp_pattern_before \
    122  1.1  christos 	    [multi_line \
    123  1.1  christos 		 "$bp_number\\s+breakpoint\\s+keep\\s+y\\s+<PENDING>\\s+${bp_func}" \
    124  1.1  christos 		 "\\s+stop only in [string_to_regexp $bp_restriction]"]
    125  1.1  christos 	set bp_pattern_after \
    126  1.1  christos 	    [multi_line \
    127  1.1  christos 		 "$bp_number\\s+breakpoint\\s+keep\\s+y\\s+<PENDING>\\s+${bp_func}" \
    128  1.1  christos 		 "\\s+stop only in [string_to_regexp $bp_after_restriction]"]
    129  1.1  christos     } else {
    130  1.1  christos 	set bp_pattern_before \
    131  1.1  christos 	    [multi_line \
    132  1.1  christos 		 "$bp_number\\s+breakpoint\\s+keep\\s+y\\s+$::hex in $bp_func at \[^\r\n\]+ inf 1" \
    133  1.1  christos 		 "\\s+stop only in [string_to_regexp $bp_restriction]"]
    134  1.1  christos 
    135  1.1  christos 	set bp_pattern_after \
    136  1.1  christos 	    [multi_line \
    137  1.1  christos 		 "$bp_number\\s+breakpoint\\s+keep\\s+y\\s+$::hex in $bp_func at \[^\r\n\]+" \
    138  1.1  christos 		 "\\s+stop only in [string_to_regexp $bp_after_restriction]"]
    139  1.1  christos     }
    140  1.1  christos 
    141  1.1  christos     gdb_test "info breakpoints" $bp_pattern_before \
    142  1.1  christos 	"info breakpoints before inferior removal"
    143  1.1  christos 
    144  1.1  christos     kill_and_remove_inferior_2
    145  1.1  christos 
    146  1.1  christos     gdb_test "info breakpoints" $bp_pattern_after \
    147  1.1  christos 	"info breakpoints after inferior removal"
    148  1.1  christos }
    149  1.1  christos 
    150  1.1  christos # Setup two inferiors, then create a dprintf.  If BP_PENDING is
    151  1.1  christos # true then the dprintf will be pending, otherwise, the dprintf
    152  1.1  christos # will be non-pending.
    153  1.1  christos #
    154  1.1  christos # The dprintf is created while inferior 2 is selected.  Then inferior
    155  1.1  christos # 2 is killed and removed.
    156  1.1  christos #
    157  1.1  christos # Finally, check that the dprintf still exists.
    158  1.1  christos proc do_dprintf_test { bp_pending } {
    159  1.1  christos     if {![test_setup]} {
    160  1.1  christos 	return
    161  1.1  christos     }
    162  1.1  christos 
    163  1.1  christos     if { $bp_pending } {
    164  1.1  christos 	set bp_func "bar"
    165  1.1  christos 
    166  1.1  christos 	gdb_test "dprintf $bp_func,\"in $bp_func\"" ".*" \
    167  1.1  christos 	    "create dprintf breakpoint" \
    168  1.1  christos 	    "Make dprintf pending on future shared library load\\? \\(y or .n.\\) $" "y"
    169  1.1  christos     } else {
    170  1.1  christos 	set bp_func "foo"
    171  1.1  christos 
    172  1.1  christos 	gdb_test "dprintf $bp_func,\"in $bp_func\"" ".*" \
    173  1.1  christos 	    "create dprintf breakpoint"
    174  1.1  christos     }
    175  1.1  christos 
    176  1.1  christos     set bp_number [get_integer_valueof "\$bpnum" "INVALID" \
    177  1.1  christos 		       "get b/p number for previous breakpoint"]
    178  1.1  christos 
    179  1.1  christos     if { $bp_pending } {
    180  1.1  christos 	set bp_pattern_before \
    181  1.1  christos 	    [multi_line \
    182  1.1  christos 		 "$bp_number\\s+dprintf\\s+keep\\s+y\\s+<PENDING>\\s+${bp_func}" \
    183  1.1  christos 		 "\\s+printf \"in $bp_func\""]
    184  1.1  christos 	set bp_pattern_after $bp_pattern_before
    185  1.1  christos     } else {
    186  1.1  christos 	set bp_pattern_before \
    187  1.1  christos 	    [multi_line \
    188  1.1  christos 		 "$bp_number\\s+dprintf\\s+keep\\s+y\\s+<MULTIPLE>\\s*" \
    189  1.1  christos 		 "\\s+printf \"in $bp_func\"" \
    190  1.1  christos 		 "$bp_number\\.1\\s+y\\s+$::hex in $bp_func at \[^\r\n\]+ inf 1" \
    191  1.1  christos 		 "$bp_number\\.2\\s+y\\s+$::hex in $bp_func at \[^\r\n\]+ inf 2"]
    192  1.1  christos 
    193  1.1  christos 	set bp_pattern_after \
    194  1.1  christos 	    [multi_line \
    195  1.1  christos 		 "$bp_number\\s+dprintf\\s+keep\\s+y\\s+$::hex in $bp_func at \[^\r\n\]+" \
    196  1.1  christos 		 "\\s+printf \"in $bp_func\""]
    197  1.1  christos     }
    198  1.1  christos 
    199  1.1  christos     gdb_test "info breakpoints" $bp_pattern_before \
    200  1.1  christos 	"info breakpoints before inferior removal"
    201  1.1  christos 
    202  1.1  christos     kill_and_remove_inferior_2
    203  1.1  christos 
    204  1.1  christos     gdb_test "info breakpoints" $bp_pattern_after \
    205  1.1  christos 	"info breakpoints after inferior removal"
    206  1.1  christos }
    207  1.1  christos 
    208  1.1  christos foreach_with_prefix bp_pending { true false } {
    209  1.1  christos     foreach_with_prefix bp_type { thread inferior } {
    210  1.1  christos 	do_bp_test $bp_type $bp_pending
    211  1.1  christos     }
    212  1.1  christos 
    213  1.1  christos     do_dprintf_test $bp_pending
    214  1.1  christos }
    215