]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.python/py-pp-registration.exp
Update copyright year range in all GDB files.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.python / py-pp-registration.exp
CommitLineData
42a4f53d 1# Copyright (C) 2010-2019 Free Software Foundation, Inc.
34f5f757
DE
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 python pretty
17# printer registration.
18
19load_lib gdb-python.exp
20
21standard_testfile
22
5b362f04 23if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
34f5f757
DE
24 return -1
25}
26
27# Skip all tests if Python scripting is not enabled.
28if { [skip_python_tests] } { continue }
29
30set remote_python_file [gdb_remote_download host \
31 ${srcdir}/${subdir}/${testfile}.py]
32
33if ![runto_main ] {
bc6c7af4 34 fail "can't run to main"
34f5f757
DE
35 return -1
36}
37
38proc prepare_test { } {
39 global testfile remote_python_file
40
41 # Start with a fresh gdb.
42 clean_restart ${testfile}
43
44 set run_to_here [gdb_get_line_number {break to inspect} ${testfile}.c ]
45 if ![runto ${testfile}.c:$run_to_here message] {
46 return 0
47 }
48
72ca0410 49 gdb_test_no_output "source ${remote_python_file}" "read file"
34f5f757
DE
50
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()"
54
55 return 1
56}
57
58proc test_printers { s_prefix } {
59 global hex
60
61 gdb_test "print flt" " = x=<42> y=<43>" \
62 "print flt"
63 gdb_test "print s" " = ${s_prefix} a=<1> b=<$hex>" \
64 "print s"
65}
66
67# Test registration with verbose off.
68
69with_test_prefix "verbose off" {
70 if ![prepare_test] {
71 return -1
72 }
73
74 gdb_test_no_output "set verbose off"
75
76 gdb_test_no_output "py gdb.printing.register_pretty_printer(gdb, lookup_function_lookup_test)"
77 gdb_test_no_output "py gdb.printing.register_pretty_printer(progspace, my_pretty_printer1)"
78
79 test_printers "s1"
80}
81
82# Test registration with verbose on.
83
84with_test_prefix "verbose on" {
85 if ![prepare_test] {
86 return -1
87 }
88
89 gdb_test_no_output "set verbose on"
90
91 gdb_test "py gdb.printing.register_pretty_printer(gdb, lookup_function_lookup_test)" \
92 "Registering global lookup_function_lookup_test pretty-printer ..."
93 gdb_test "py gdb.printing.register_pretty_printer(progspace, my_pretty_printer1)" \
94 "Registering pp-test pretty-printer for .*/py-pp-registration ..."
95
96 test_printers "s1"
97}
98
99# Exercise the "replace" argument to register_pretty_printer.
100
101with_test_prefix "replace" {
102 if ![prepare_test] {
103 return -1
104 }
105
106 gdb_test_no_output "py gdb.printing.register_pretty_printer(gdb, lookup_function_lookup_test)"
107 gdb_test_no_output "py gdb.printing.register_pretty_printer(progspace, my_pretty_printer1)"
108 gdb_test "py gdb.printing.register_pretty_printer(progspace, my_pretty_printer2, replace=False)" \
109 "RuntimeError: pretty-printer already registered: pp-test\r\nError while executing Python code."
110
d60a9221
SDJ
111 with_test_prefix "test printers 1" {
112 test_printers "s1"
113 }
34f5f757
DE
114
115 gdb_test_no_output "py gdb.printing.register_pretty_printer(progspace, my_pretty_printer2, replace=True)"
116
d60a9221
SDJ
117 with_test_prefix "test printers 2" {
118 test_printers "s2"
119 }
34f5f757 120}