Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / py-autoloaded-pretty-printers-in-newobjfile-event.exp
CommitLineData
88b9d363 1# Copyright (C) 2021-2022 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
22standard_testfile -main.cc
23
24set srcfile_lib "${testfile}-lib.cc"
25set python_event_handler_file "${srcdir}/${subdir}/${testfile}.py"
26set libname "lib${testfile}"
27set python_autoload_file "${srcdir}/${subdir}/${libname}.so-gdb.py"
28set binfile_lib [standard_output_file "${libname}.so"]
29
30# Start GDB first - needed for skip_python_tests.
31clean_restart
32
33# Skip all tests if Python scripting is not enabled.
34if { [skip_python_tests] } { continue }
35
36# Compile library.
37if { [gdb_compile_shlib ${srcdir}/${subdir}/${srcfile_lib} ${binfile_lib} \
38 {debug c++}] != "" } {
39 return -1
40}
41
42# Compile main program.
43if { [gdb_compile ${srcdir}/${subdir}/${srcfile} \
44 ${binfile} \
45 executable \
46 [list debug c++ shlib=$binfile_lib]] != "" } {
47 return -1
48}
49
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.
52set remote_python_autoload_file \
53 [gdb_remote_download host $python_autoload_file]
54
55gdb_test_no_output \
56 "set auto-load safe-path ${remote_python_autoload_file}" \
57 "set auto-load safe-path"
58
59# Load the Python file that defines a handler for the new_objfile event.
60set remote_python_event_handler_file\
61 [gdb_remote_download host $python_event_handler_file]
62gdb_test_no_output "source ${remote_python_event_handler_file}" "load python file"
63
64gdb_load ${binfile}
65
66gdb_test_no_output "set print pretty on"
67
68if { ![runto_main] } {
69 fail "failed to run to main"
70 return
71}
72
73# Check that the new_objfile handler saw the pretty-printer.
74gdb_test "print all_good" " = true"
75
76# Check that the pretty-printer actually works.
77gdb_test "info pretty-printer" "my_library.*MyClassTestLib.*"
78gdb_breakpoint [gdb_get_line_number "break to inspect"]
79gdb_test "continue" "Breakpoint $decimal, main .*"
80gdb_test "print test" "MyClassTestLib object, id: 1.*"
This page took 0.054862 seconds and 4 git commands to generate.