]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.python/py-autoloaded-pretty-printers-in-newobjfile-event.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.python / py-autoloaded-pretty-printers-in-newobjfile-event.exp
CommitLineData
1d506c26 1# Copyright (C) 2021-2024 Free Software Foundation, Inc.
2c473def
MW
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
20load_lib gdb-python.exp
21
d82e5429 22require allow_python_tests
79749205 23
2c473def
MW
24standard_testfile -main.cc
25
26set srcfile_lib "${testfile}-lib.cc"
27set python_event_handler_file "${srcdir}/${subdir}/${testfile}.py"
28set libname "lib${testfile}"
29set python_autoload_file "${srcdir}/${subdir}/${libname}.so-gdb.py"
30set binfile_lib [standard_output_file "${libname}.so"]
31
2c473def
MW
32# Compile library.
33if { [gdb_compile_shlib ${srcdir}/${subdir}/${srcfile_lib} ${binfile_lib} \
34 {debug c++}] != "" } {
35 return -1
36}
37
38# Compile main program.
39if { [gdb_compile ${srcdir}/${subdir}/${srcfile} \
40 ${binfile} \
41 executable \
42 [list debug c++ shlib=$binfile_lib]] != "" } {
43 return -1
44}
45
79749205
TT
46clean_restart
47
2c473def
MW
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.
50set remote_python_autoload_file \
51 [gdb_remote_download host $python_autoload_file]
52
53gdb_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.
58set remote_python_event_handler_file\
59 [gdb_remote_download host $python_event_handler_file]
60gdb_test_no_output "source ${remote_python_event_handler_file}" "load python file"
61
62gdb_load ${binfile}
ddc003b7 63gdb_load_shlib $binfile_lib
2c473def 64
2c473def 65if { ![runto_main] } {
2c473def
MW
66 return
67}
68
ddc003b7
TV
69if { [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
2c473def
MW
85# Check that the new_objfile handler saw the pretty-printer.
86gdb_test "print all_good" " = true"
87
88# Check that the pretty-printer actually works.
89gdb_test "info pretty-printer" "my_library.*MyClassTestLib.*"
90gdb_breakpoint [gdb_get_line_number "break to inspect"]
91gdb_test "continue" "Breakpoint $decimal, main .*"
92gdb_test "print test" "MyClassTestLib object, id: 1.*"