20e8cdc586d1741eb7bbe173529275d6ef1c978c
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / py-pp-registration.exp
1 # Copyright (C) 2010-2016 Free Software Foundation, Inc.
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
19 load_lib gdb-python.exp
20
21 standard_testfile
22
23 if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
24 return -1
25 }
26
27 # Skip all tests if Python scripting is not enabled.
28 if { [skip_python_tests] } { continue }
29
30 set remote_python_file [gdb_remote_download host \
31 ${srcdir}/${subdir}/${testfile}.py]
32
33 if ![runto_main ] {
34 fail "can't run to main"
35 return -1
36 }
37
38 proc 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
49 gdb_test_no_output "python exec (open ('${remote_python_file}').read ())" \
50 "read file"
51
52 gdb_test_no_output "py progspace = gdb.current_progspace()"
53 gdb_test_no_output "py my_pretty_printer1 = build_pretty_printer1()"
54 gdb_test_no_output "py my_pretty_printer2 = build_pretty_printer2()"
55
56 return 1
57 }
58
59 proc test_printers { s_prefix } {
60 global hex
61
62 gdb_test "print flt" " = x=<42> y=<43>" \
63 "print flt"
64 gdb_test "print s" " = ${s_prefix} a=<1> b=<$hex>" \
65 "print s"
66 }
67
68 # Test registration with verbose off.
69
70 with_test_prefix "verbose off" {
71 if ![prepare_test] {
72 return -1
73 }
74
75 gdb_test_no_output "set verbose off"
76
77 gdb_test_no_output "py gdb.printing.register_pretty_printer(gdb, lookup_function_lookup_test)"
78 gdb_test_no_output "py gdb.printing.register_pretty_printer(progspace, my_pretty_printer1)"
79
80 test_printers "s1"
81 }
82
83 # Test registration with verbose on.
84
85 with_test_prefix "verbose on" {
86 if ![prepare_test] {
87 return -1
88 }
89
90 gdb_test_no_output "set verbose on"
91
92 gdb_test "py gdb.printing.register_pretty_printer(gdb, lookup_function_lookup_test)" \
93 "Registering global lookup_function_lookup_test pretty-printer ..."
94 gdb_test "py gdb.printing.register_pretty_printer(progspace, my_pretty_printer1)" \
95 "Registering pp-test pretty-printer for .*/py-pp-registration ..."
96
97 test_printers "s1"
98 }
99
100 # Exercise the "replace" argument to register_pretty_printer.
101
102 with_test_prefix "replace" {
103 if ![prepare_test] {
104 return -1
105 }
106
107 gdb_test_no_output "py gdb.printing.register_pretty_printer(gdb, lookup_function_lookup_test)"
108 gdb_test_no_output "py gdb.printing.register_pretty_printer(progspace, my_pretty_printer1)"
109 gdb_test "py gdb.printing.register_pretty_printer(progspace, my_pretty_printer2, replace=False)" \
110 "RuntimeError: pretty-printer already registered: pp-test\r\nError while executing Python code."
111
112 with_test_prefix "test printers 1" {
113 test_printers "s1"
114 }
115
116 gdb_test_no_output "py gdb.printing.register_pretty_printer(progspace, my_pretty_printer2, replace=True)"
117
118 with_test_prefix "test printers 2" {
119 test_printers "s2"
120 }
121 }
This page took 0.032267 seconds and 4 git commands to generate.