Home | History | Annotate | Line # | Download | only in gdb.python
      1 # Copyright (C) 2008-2024 Free Software Foundation, Inc.
      2 
      3 # This program is free software; you can redistribute it and/or modify
      4 # it under the terms of the GNU General Public License as published by
      5 # the Free Software Foundation; either version 3 of the License, or
      6 # (at your option) any later version.
      7 #
      8 # This program is distributed in the hope that it will be useful,
      9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     11 # GNU General Public License for more details.
     12 #
     13 # You should have received a copy of the GNU General Public License
     14 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
     15 
     16 # This file is part of the GDB testsuite.  It tests PR 19743.
     17 
     18 load_lib mi-support.exp
     19 set MIFLAGS "-i=mi2"
     20 
     21 require allow_python_tests
     22 
     23 standard_testfile
     24 
     25 set pyfile ${testfile}-gdb.py
     26 
     27 if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
     28     untested "failed to compile"
     29     return -1
     30 }
     31 
     32 set remote_python_file [gdb_remote_download host ${srcdir}/${subdir}/${pyfile}]
     33 
     34 if {[mi_clean_restart]} {
     35     return
     36 }
     37 
     38 mi_gdb_test "set auto-load safe-path ${remote_python_file}" \
     39     {.*\^done} \
     40     "set safe-path"
     41 
     42 if [is_remote host] {
     43     set filename ${testfile}
     44     remote_download host ${binfile} ${filename}
     45 } else {
     46     set filename ${binfile}
     47 }
     48 
     49 mi_gdb_test "-file-exec-and-symbols ${filename}"  ".*\\^done" "file-exec-and-symbols operation"
     50 mi_gdb_load ${binfile}
     51 mi_runto_main
     52 
     53 
     54 # register the python event handlers with test-events command
     55 mi_gdb_test "test-events" \
     56     ".*~\"Event testers registered.*\\^done" \
     57     "register events"
     58 
     59 
     60 set lineno [gdb_get_line_number "i++;"]
     61 
     62 # set a breakpoint into the for loop
     63 mi_gdb_test "break ${srcfile}:$lineno" \
     64     ".*Breakpoint $decimal at 0x\[0-9a-fA-F\]+: file .*${srcfile}.*\\\.*\\^done" \
     65     "set the breakpoint"
     66 
     67 
     68 # resume the program
     69 mi_execute_to "exec-continue" "breakpoint-hit" "main" "" ".*$srcfile" "$lineno" { "" "disp=\"keep\"" } "continue"
     70 
     71 
     72 # test the python event handlers execution. The following checks are performed:
     73 # - python continue handler is executed
     74 # - the continue handler prints "info breakpoints" output in console format
     75 # - breakpoint is hit and python stop handler is executed
     76 # - the stop handler prints "info breakpoints" output in console format
     77 
     78 mi_gdb_test "python print (stop_handler_str)" \
     79 ".*stop_handler.*Num.*Type.*Disp.*Enb.*Address.*$decimal.*breakpoint.*keep.*y.* 0x\[0-9a-fA-F\]+.*${srcfile}.*" \
     80 "python stop handler ran"
     81 
     82 mi_gdb_test "python print (cont_handler_str)" \
     83 ".*continue_handler.*Num.*Type.*Disp.*Enb.*Address.*$decimal.*breakpoint.*keep.*y.* 0x\[0-9a-fA-F\]+.*${srcfile}.*" \
     84 "python continue handler ran"
     85 
     86 mi_gdb_exit
     87