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