Home | History | Annotate | Line # | Download | only in gdb.base
      1  1.11  christos #   Copyright 2003-2024 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 # This file was created by Jeff Johnston. (jjohnstn (at) redhat.com)
     17   1.1  christos 
     18   1.1  christos #
     19   1.1  christos # test running programs
     20   1.1  christos #
     21   1.1  christos 
     22  1.11  christos require allow_shlib_tests
     23   1.1  christos 
     24   1.1  christos standard_testfile .c
     25   1.1  christos set libfile "pendshr"
     26   1.1  christos set libsrc  $srcdir/$subdir/$libfile.c
     27   1.1  christos set lib_sl  [standard_output_file $libfile.sl]
     28   1.1  christos 
     29   1.1  christos set lib_opts  debug
     30   1.1  christos set exec_opts [list debug shlib=$lib_sl]
     31   1.1  christos 
     32   1.1  christos if { [gdb_compile_shlib $libsrc $lib_sl $lib_opts] != ""
     33   1.1  christos      || [gdb_compile $srcdir/$subdir/$srcfile $binfile executable $exec_opts] != ""} {
     34   1.7  christos     untested "failed to compile"
     35   1.1  christos     return -1
     36   1.1  christos }
     37   1.1  christos 
     38  1.11  christos clean_restart
     39   1.1  christos 
     40   1.1  christos gdb_test_multiple "break pendfunc1" "set pending breakpoint" {
     41   1.1  christos      -re ".*Make breakpoint pending.*y or \\\[n\\\]. $" {
     42  1.12  christos 	    gdb_test "y" "Breakpoint.*pendfunc1.*pending." "set pending breakpoint, without symbols"
     43   1.1  christos      }
     44   1.1  christos }
     45   1.1  christos 
     46   1.1  christos # Complete the condition (PR 15413).
     47   1.1  christos gdb_test "complete condition " "condition 1"
     48   1.1  christos 
     49   1.1  christos gdb_test "info break" \
     50   1.1  christos     "Num     Type\[ \]+Disp Enb Address\[ \]+What.*
     51   1.1  christos \[0-9\]+\[\t \]+breakpoint     keep y.*PENDING.*pendfunc1.*" \
     52  1.12  christos "single pending breakpoint info, without symbols"
     53   1.1  christos 
     54  1.10  christos with_test_prefix "first load" {
     55  1.10  christos     gdb_load ${binfile}
     56  1.10  christos     gdb_load_shlib $lib_sl
     57  1.10  christos }
     58   1.1  christos 
     59   1.1  christos set pendfunc1_loc [gdb_get_line_number "y = x + 4" ${libfile}.c]
     60   1.1  christos 
     61   1.1  christos gdb_run_cmd
     62   1.1  christos 
     63   1.1  christos gdb_test "" \
     64   1.1  christos ".*Breakpoint.*pendfunc1.*at.*pendshr.c:$pendfunc1_loc.*y = x \\+ 4.*" \
     65   1.1  christos "run to resolved breakpoint 1 (without symbols)"
     66   1.1  christos 
     67  1.11  christos clean_restart
     68   1.1  christos 
     69  1.10  christos with_test_prefix "second load" {
     70  1.10  christos     gdb_load ${binfile}
     71  1.10  christos     gdb_load_shlib $lib_sl
     72  1.10  christos }
     73   1.1  christos 
     74   1.1  christos #
     75   1.1  christos # Test setting, querying, and modifying pending breakpoints
     76   1.1  christos #
     77   1.1  christos 
     78   1.1  christos gdb_test_multiple "break pendfunc1" "set pending breakpoint" {
     79   1.1  christos      -re ".*Make breakpoint pending.*y or \\\[n\\\]. $" {
     80   1.1  christos 	    gdb_test "y" "Breakpoint.*pendfunc1.*pending." "set pending breakpoint"
     81   1.1  christos      }
     82   1.1  christos }
     83   1.1  christos 
     84   1.1  christos gdb_test "info break" \
     85   1.1  christos     "Num     Type\[ \]+Disp Enb Address\[ \]+What.*
     86   1.1  christos \[0-9\]+\[\t \]+breakpoint     keep y.*PENDING.*pendfunc1.*" \
     87   1.1  christos "single pending breakpoint info"
     88   1.1  christos 
     89   1.1  christos #
     90   1.1  christos # Test breaking at existing function
     91   1.1  christos #
     92   1.1  christos 
     93   1.1  christos set mainline [gdb_get_line_number "break main here"]
     94   1.1  christos 
     95  1.10  christos gdb_test "break -q main" \
     96   1.1  christos     "Breakpoint.*at.* file .*$srcfile, line $mainline.*" \
     97   1.1  christos     "breakpoint function"
     98   1.1  christos 
     99   1.1  christos gdb_test "info break" \
    100   1.1  christos     "Num     Type\[ \]+Disp Enb Address\[ \]+What.*
    101   1.1  christos \[0-9\]+\[\t \]+breakpoint     keep y.*PENDING.*pendfunc1.*
    102   1.1  christos \[0-9\]+\[\t \]+breakpoint     keep y.* in main at .*$srcfile:$mainline" \
    103   1.1  christos "pending plus real breakpoint info"
    104   1.1  christos 
    105   1.1  christos 
    106   1.1  christos #
    107   1.1  christos # Test not setting a pending breakpoint
    108   1.1  christos #
    109   1.1  christos gdb_test "break pendfunc2" \
    110   1.1  christos     "" \
    111   1.1  christos     "Don't set pending breakpoint" \
    112   1.1  christos     ".*Make breakpoint pending.*y or \\\[n\\\]. $" \
    113   1.1  christos     "n"
    114   1.1  christos 
    115   1.1  christos #
    116   1.1  christos # Add condition to pending breakpoint
    117   1.1  christos #
    118   1.1  christos 
    119   1.1  christos gdb_test_no_output "condition 1 k == 1"
    120   1.1  christos 
    121   1.1  christos gdb_test "info break" \
    122   1.1  christos     "Num     Type\[ \]+Disp Enb Address\[ \]+What.*
    123   1.1  christos \[0-9\]+\[\t \]+breakpoint     keep y.*PENDING.*pendfunc1.*
    124   1.1  christos \[\t \]+stop only if k == 1.*
    125   1.1  christos \[0-9\]+\[\t \]+breakpoint     keep y.* in main at .*$srcfile:$mainline" \
    126   1.1  christos "pending plus condition"
    127   1.1  christos 
    128   1.1  christos #
    129   1.1  christos # Disable pending breakpoint
    130   1.1  christos #
    131   1.1  christos 
    132   1.1  christos gdb_test_no_output "disable 1"
    133   1.1  christos 
    134   1.1  christos gdb_test "info break" \
    135   1.1  christos     "Num     Type\[ \]+Disp Enb Address\[ \]+What.*
    136   1.1  christos \[0-9\]+\[\t \]+breakpoint     keep n.*PENDING.*pendfunc1.*
    137   1.1  christos \[\t \]+stop only if k == 1.*
    138   1.1  christos \[0-9\]+\[\t \]+breakpoint     keep y.* in main at .*$srcfile:$mainline" \
    139   1.1  christos "pending disabled"
    140   1.1  christos 
    141   1.1  christos #
    142   1.1  christos # Add commands to pending breakpoint
    143   1.1  christos #
    144   1.1  christos gdb_test "commands 1\nprint k\nend" "" \
    145   1.1  christos     "Set commands for pending breakpoint"
    146   1.1  christos 
    147   1.1  christos gdb_test "info break" \
    148   1.1  christos     "Num     Type\[ \]+Disp Enb Address\[ \]+What.*
    149   1.1  christos \[0-9\]+\[\t \]+breakpoint     keep n.*PENDING.*pendfunc1.*
    150   1.1  christos \[\t \]+stop only if k == 1.*
    151   1.1  christos \[\t \]+print k.*
    152   1.1  christos \[0-9\]+\[\t \]+breakpoint     keep y.* in main at .*$srcfile:$mainline" \
    153   1.1  christos "pending disabled plus commands"
    154   1.1  christos 
    155   1.1  christos #
    156   1.1  christos # Try a pending break for a line in a source file with a condition
    157   1.1  christos #
    158   1.1  christos 
    159   1.1  christos set bp2_loc [gdb_get_line_number "y = x + 4" ${libfile}.c]
    160   1.7  christos gdb_test_multiple "break pendshr.c:$bp2_loc if x > 3" "set pending breakpoint 2" {
    161   1.1  christos      -re ".*Make breakpoint pending.*y or \\\[n\\\]. $" {
    162   1.1  christos 	    gdb_test "y" "Breakpoint.*pendshr.c:$bp2_loc.*pending." \
    163   1.1  christos 		"Set pending breakpoint 2"
    164   1.1  christos      }
    165   1.1  christos }
    166   1.1  christos 
    167   1.1  christos gdb_test "info break" \
    168   1.1  christos     "Num     Type\[ \]+Disp Enb Address\[ \]+What.*
    169   1.1  christos \[0-9\]+\[\t \]+breakpoint     keep n.*PENDING.*pendfunc1.*
    170   1.1  christos \[\t \]+stop only if k == 1.*
    171   1.1  christos \[\t \]+print k.*
    172   1.1  christos \[0-9\]+\[\t \]+breakpoint     keep y.* in main at .*$srcfile:$mainline.*
    173  1.12  christos \[0-9\]+\[\t \]+breakpoint     keep y.*PENDING.*pendshr.c:$bp2_loc.*
    174  1.12  christos \\s+stop only if x > 3.*" \
    175   1.1  christos "multiple pending breakpoints"
    176   1.1  christos 
    177   1.1  christos 
    178   1.1  christos #
    179   1.1  christos # Try a pending break for a line in a source file with ignore count:
    180   1.1  christos #
    181   1.1  christos 
    182   1.1  christos set bp3_loc [gdb_get_line_number "printf" ${libfile}.c]
    183   1.7  christos gdb_test_multiple "break pendshr.c:$bp3_loc" "set pending breakpoint 3" {
    184   1.1  christos      -re ".*Make breakpoint pending.*y or \\\[n\\\]. $" {
    185   1.1  christos 	    gdb_test "y" "Breakpoint.*pendshr.c:$bp3_loc.*pending." \
    186   1.1  christos 		"Set pending breakpoint 3"
    187   1.1  christos      }
    188   1.1  christos }
    189   1.1  christos 
    190   1.1  christos gdb_test {ignore $bpnum 2} "Will ignore next 2 crossings of breakpoint .*" \
    191   1.1  christos     "set ignore count on pending breakpoint 3"
    192   1.1  christos 
    193   1.1  christos gdb_test "info break" \
    194   1.1  christos     "Num     Type\[ \]+Disp Enb Address\[ \]+What.*
    195   1.1  christos \[0-9\]+\[\t \]+breakpoint     keep n.*PENDING.*pendfunc1.*
    196   1.1  christos \[\t \]+stop only if k == 1.*
    197   1.1  christos \[\t \]+print k.*
    198   1.1  christos \[0-9\]+\[\t \]+breakpoint     keep y.* in main at .*$srcfile:$mainline.*
    199  1.12  christos \[0-9\]+\[\t \]+breakpoint     keep y.*PENDING.*pendshr.c:$bp2_loc.*
    200  1.12  christos \\s+stop only if x > 3.*
    201  1.12  christos \[0-9\]+\[\t \]+breakpoint     keep y.*PENDING.*pendshr.c:$bp3_loc.*
    202  1.12  christos \\s+ignore next 2 hits.*" \
    203   1.1  christos "multiple pending breakpoints 2"
    204   1.1  christos 
    205   1.1  christos #
    206   1.1  christos # Run to main which should resolve a pending breakpoint
    207   1.1  christos #
    208   1.1  christos 
    209   1.1  christos gdb_run_cmd
    210   1.1  christos gdb_test "" \
    211   1.1  christos ".*Breakpoint.*, main.*$mainline.*" \
    212   1.1  christos "running to main"
    213   1.1  christos 
    214   1.1  christos #
    215   1.1  christos # Re-enable the first pending breakpoint which should resolve
    216   1.1  christos #
    217   1.1  christos 
    218   1.1  christos gdb_test_no_output "enable 1" \
    219   1.1  christos "re-enabling pending breakpoint that can resolve instantly"
    220   1.1  christos 
    221   1.1  christos #
    222   1.1  christos # Continue to verify conditionals and commands for breakpoints are honored
    223   1.1  christos #
    224   1.1  christos 
    225   1.1  christos gdb_test "continue" \
    226   1.1  christos ".*Breakpoint.*pendfunc1.*at.*pendshr.c:$bp2_loc.*4;" \
    227   1.1  christos "continue to resolved breakpoint 2"
    228   1.1  christos 
    229   1.1  christos gdb_test "continue" \
    230   1.1  christos ".*Breakpoint.*pendfunc1.*at.*pendshr.c:$bp2_loc.*
    231  1.11  christos \\\$1 = 1" \
    232   1.1  christos "continue to resolved breakpoint 1"
    233   1.1  christos 
    234   1.1  christos #
    235   1.1  christos # Disable the other two breakpoints, and continue to the one with
    236   1.1  christos # the ignore count.  Make sure you hit it the third time, x should
    237   1.1  christos # be 3 then.
    238   1.1  christos #
    239   1.1  christos 
    240  1.10  christos gdb_test "disable 7" "" "disable breakpoint 7"
    241  1.10  christos gdb_test "disable 5" "" "disable breakpoint 5"
    242   1.1  christos 
    243   1.1  christos gdb_test "continue" \
    244   1.1  christos 	 ".*Breakpoint.*pendfunc1.*\\\(x=3\\\) at.*pendshr.c:$bp3_loc.*printf.*;" \
    245   1.1  christos "continue to resolved breakpoint 3"
    246   1.1  christos 
    247   1.1  christos delete_breakpoints
    248   1.1  christos 
    249   1.1  christos gdb_breakpoint "main"
    250   1.1  christos 
    251   1.1  christos #
    252   1.1  christos # Set non-existent pending breakpoint
    253   1.1  christos #
    254   1.1  christos gdb_test_multiple "break imaginary" "set imaginary pending breakpoint" {
    255   1.1  christos      -re ".*Make breakpoint pending.*y or \\\[n\\\]. $" {
    256   1.1  christos 	    gdb_test "y" "Breakpoint.*imaginary.*pending." \
    257   1.1  christos 		"set imaginary pending breakpoint"
    258   1.1  christos      }
    259   1.1  christos }
    260   1.1  christos 
    261   1.1  christos #
    262   1.1  christos # rerun program and make sure that any pending breakpoint remains and no
    263   1.1  christos # error messages are issued for the missing function
    264   1.1  christos #
    265   1.1  christos 
    266   1.1  christos rerun_to_main
    267   1.1  christos 
    268   1.1  christos gdb_test "info break" \
    269   1.1  christos     "Num     Type\[ \]+Disp Enb Address\[ \]+What.*
    270   1.1  christos \[0-9\]+\[\t \]+breakpoint     keep y.* in main at .*$srcfile:$mainline.*
    271   1.1  christos \[0-9\]+\[\t \]+breakpoint     keep y.*PENDING.*imaginary.*" \
    272   1.1  christos "verify pending breakpoint after restart"
    273  1.12  christos 
    274  1.12  christos # Test GDB's parsing of pending breakpoint thread and condition.
    275  1.12  christos 
    276  1.12  christos gdb_test_no_output "set breakpoint pending on"
    277  1.12  christos gdb_test "break foo if (unknown_var && another_unknown_var) thread 1" \
    278  1.12  christos     "Breakpoint $decimal \\(foo\\) pending\\."
    279  1.12  christos set bpnum [get_integer_valueof "\$bpnum" "*INVALID" \
    280  1.12  christos 	       "get number for foo breakpoint"]
    281  1.12  christos 
    282  1.12  christos if {[gdb_protocol_is_remote]} {
    283  1.12  christos     set evals_re "(?: \\(\[^) \]+ evals\\))?"
    284  1.12  christos } else {
    285  1.12  christos     set evals_re ""
    286  1.12  christos }
    287  1.12  christos 
    288  1.12  christos gdb_test "info breakpoints $bpnum" \
    289  1.12  christos     [multi_line \
    290  1.12  christos 	 "$bpnum\\s+breakpoint\\s+keep\\s+y\\s+<PENDING>\\s+foo" \
    291  1.12  christos 	 "\\s+stop only if \\(unknown_var && another_unknown_var\\)${evals_re}" \
    292  1.12  christos 	 "\\s+stop only in thread 1"] \
    293  1.12  christos     "check pending breakpoint on foo"
    294