Home | History | Annotate | Line # | Download | only in gdb.python
py-autoloaded-pretty-printers-in-newobjfile-event.exp revision 1.1.1.1
      1 # Copyright (C) 2021-2023 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 that Python pretty-printers
     17 # defined in a Python script that is autoloaded are registered when an event
     18 # handler for the new_objfile event is called.
     19 
     20 load_lib gdb-python.exp
     21 
     22 standard_testfile -main.cc
     23 
     24 set srcfile_lib "${testfile}-lib.cc"
     25 set python_event_handler_file "${srcdir}/${subdir}/${testfile}.py"
     26 set libname "lib${testfile}"
     27 set python_autoload_file "${srcdir}/${subdir}/${libname}.so-gdb.py"
     28 set binfile_lib [standard_output_file "${libname}.so"]
     29 
     30 # Start GDB first - needed for skip_python_tests.
     31 clean_restart
     32 
     33 # Skip all tests if Python scripting is not enabled.
     34 if { [skip_python_tests] } { continue }
     35 
     36 # Compile library.
     37 if { [gdb_compile_shlib ${srcdir}/${subdir}/${srcfile_lib} ${binfile_lib} \
     38       {debug c++}] != "" } {
     39     return -1
     40 }
     41 
     42 # Compile main program.
     43 if { [gdb_compile ${srcdir}/${subdir}/${srcfile} \
     44       ${binfile} \
     45       executable \
     46       [list debug c++ shlib=$binfile_lib]] != "" } {
     47     return -1
     48 }
     49 
     50 # Make the -gdb.py script available to gdb, it is automatically loaded by
     51 # gdb if it is put in the same directory as the library.
     52 set remote_python_autoload_file \
     53     [gdb_remote_download host $python_autoload_file]
     54 
     55 gdb_test_no_output \
     56     "set auto-load safe-path ${remote_python_autoload_file}" \
     57     "set auto-load safe-path"
     58 
     59 # Load the Python file that defines a handler for the new_objfile event.
     60 set remote_python_event_handler_file\
     61     [gdb_remote_download host $python_event_handler_file]
     62 gdb_test_no_output "source ${remote_python_event_handler_file}" "load python file"
     63 
     64 gdb_load ${binfile}
     65 
     66 gdb_test_no_output "set print pretty on"
     67 
     68 if { ![runto_main] } {
     69     return
     70 }
     71 
     72 # Check that the new_objfile handler saw the pretty-printer.
     73 gdb_test "print all_good" " = true"
     74 
     75 # Check that the pretty-printer actually works.
     76 gdb_test "info pretty-printer" "my_library.*MyClassTestLib.*"
     77 gdb_breakpoint [gdb_get_line_number "break to inspect"]
     78 gdb_test "continue" "Breakpoint $decimal, main .*"
     79 gdb_test "print test" "MyClassTestLib object, id: 1.*"
     80