1 # Copyright (C) 2021-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 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 require allow_python_tests 23 24 standard_testfile -main.cc 25 26 set srcfile_lib "${testfile}-lib.cc" 27 set python_event_handler_file "${srcdir}/${subdir}/${testfile}.py" 28 set libname "lib${testfile}" 29 set python_autoload_file "${srcdir}/${subdir}/${libname}.so-gdb.py" 30 set binfile_lib [standard_output_file "${libname}.so"] 31 32 # Compile library. 33 if { [gdb_compile_shlib ${srcdir}/${subdir}/${srcfile_lib} ${binfile_lib} \ 34 {debug c++}] != "" } { 35 return -1 36 } 37 38 # Compile main program. 39 if { [gdb_compile ${srcdir}/${subdir}/${srcfile} \ 40 ${binfile} \ 41 executable \ 42 [list debug c++ shlib=$binfile_lib]] != "" } { 43 return -1 44 } 45 46 clean_restart 47 48 # Make the -gdb.py script available to gdb, it is automatically loaded by 49 # gdb if it is put in the same directory as the library. 50 set remote_python_autoload_file \ 51 [gdb_remote_download host $python_autoload_file] 52 53 gdb_test_no_output \ 54 "set auto-load safe-path ${remote_python_autoload_file}" \ 55 "set auto-load safe-path" 56 57 # Load the Python file that defines a handler for the new_objfile event. 58 set remote_python_event_handler_file\ 59 [gdb_remote_download host $python_event_handler_file] 60 gdb_test_no_output "source ${remote_python_event_handler_file}" "load python file" 61 62 gdb_load ${binfile} 63 gdb_load_shlib $binfile_lib 64 65 if { ![runto_main] } { 66 return 67 } 68 69 if { [is_remote target ] } { 70 set target_sysroot 0 71 gdb_test_multiple "show sysroot" "" { 72 -re -wrap "\r\nThe current system root is \"target:.*\"\\." { 73 set target_sysroot 1 74 } 75 -re -wrap "" { 76 } 77 } 78 79 if { $target_sysroot } { 80 unsupported "sysroot start with target: -- auto-load not supported" 81 return 82 } 83 } 84 85 # Check that the new_objfile handler saw the pretty-printer. 86 gdb_test "print all_good" " = true" 87 88 # Check that the pretty-printer actually works. 89 gdb_test "info pretty-printer" "my_library.*MyClassTestLib.*" 90 gdb_breakpoint [gdb_get_line_number "break to inspect"] 91 gdb_test "continue" "Breakpoint $decimal, main .*" 92 gdb_test "print test" "MyClassTestLib object, id: 1.*" 93