1 # Copyright (C) 2010-2020 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 python pretty
17 # printer registration.
19 load_lib gdb-python.exp
23 if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
27 # Skip all tests if Python scripting is not enabled.
28 if { [skip_python_tests] } { continue }
30 set remote_python_file [gdb_remote_download host \
31 ${srcdir}/${subdir}/${testfile}.py]
34 fail "can't run to main"
38 proc prepare_test { } {
39 global testfile remote_python_file
41 # Start with a fresh gdb.
42 clean_restart ${testfile}
44 set run_to_here [gdb_get_line_number {break to inspect} ${testfile}.c ]
45 if ![runto ${testfile}.c:$run_to_here message] {
49 gdb_test_no_output "source ${remote_python_file}" "read file"
51 gdb_test_no_output "py progspace = gdb.current_progspace()"
52 gdb_test_no_output "py my_pretty_printer1 = build_pretty_printer1()"
53 gdb_test_no_output "py my_pretty_printer2 = build_pretty_printer2()"
58 proc test_printers { s_prefix } {
61 gdb_test "print flt" " = x=<42> y=<43>"
62 gdb_test "print s" " = ${s_prefix} a=<1> b=<$hex>"
65 # Test registration with verbose off.
67 with_test_prefix "verbose off" {
72 gdb_test_no_output "set verbose off"
74 gdb_test_no_output "py gdb.printing.register_pretty_printer(gdb, lookup_function_lookup_test)"
75 gdb_test_no_output "py gdb.printing.register_pretty_printer(progspace, my_pretty_printer1)"
80 # Test registration with verbose on.
82 with_test_prefix "verbose on" {
87 gdb_test_no_output "set verbose on"
89 gdb_test "py gdb.printing.register_pretty_printer(gdb, lookup_function_lookup_test)" \
90 "Registering global lookup_function_lookup_test pretty-printer ..."
91 gdb_test "py gdb.printing.register_pretty_printer(progspace, my_pretty_printer1)" \
92 "Registering pp-test pretty-printer for .*py-pp-registration ..."
97 # Exercise the "replace" argument to register_pretty_printer.
99 with_test_prefix "replace" {
104 gdb_test_no_output "py gdb.printing.register_pretty_printer(gdb, lookup_function_lookup_test)"
105 gdb_test_no_output "py gdb.printing.register_pretty_printer(progspace, my_pretty_printer1)"
106 gdb_test "py gdb.printing.register_pretty_printer(progspace, my_pretty_printer2, replace=False)" \
107 "RuntimeError: pretty-printer already registered: pp-test\r\nError while executing Python code."
109 with_test_prefix "test printers 1" {
113 gdb_test_no_output "py gdb.printing.register_pretty_printer(progspace, my_pretty_printer2, replace=True)"
115 with_test_prefix "test printers 2" {