1 # Copyright
(C
) 2021-2022 Free Software Foundation
, Inc.
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.
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.
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
/>.
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.
20 load_lib gdb
-python.exp
22 standard_testfile
-main.cc
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"]
30 # Start GDB first
- needed
for skip_python_tests.
33 # Skip all tests
if Python scripting is not enabled.
34 if { [skip_python_tests
] } { continue }
37 if { [gdb_compile_shlib $
{srcdir
}/$
{subdir
}/$
{srcfile_lib
} $
{binfile_lib
} \
38 {debug c
++}] != "" } {
42 #
Compile main
program.
43 if { [gdb_compile $
{srcdir
}/$
{subdir
}/$
{srcfile
} \
46 [list debug c
++ shlib
=$binfile_lib
]] != "" } {
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
]
56 "set auto-load safe-path ${remote_python_autoload_file}" \
57 "set auto-load safe-path"
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"
66 gdb_test_no_output
"set print pretty on"
68 if { ![runto_main
] } {
72 # Check that the new_objfile handler saw the pretty
-printer.
73 gdb_test
"print all_good" " = true"
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.*"