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