xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.python/py-pp-maint.exp (revision 8b657b0747480f8989760d71343d6dd33f8d4cf9)
1# Copyright (C) 2010-2023 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-based
17# pretty-printing for the CLI.
18
19if [is_remote host] {
20    untested "py-pp-maint.exp can only be run locally"
21    return -1
22}
23
24load_lib gdb-python.exp
25
26standard_testfile
27
28if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
29    return -1
30}
31
32# Skip all tests if Python scripting is not enabled.
33if { [skip_python_tests] } { continue }
34
35if {![runto_main]} {
36    return -1
37}
38
39gdb_test "b [gdb_get_line_number {break to inspect} ${testfile}.c ]" \
40    ".*Breakpoint.*"
41gdb_test "continue" ".*Breakpoint.*"
42
43set python_file [gdb_remote_download host ${srcdir}/${subdir}/${testfile}.py]
44
45gdb_test_no_output "source ${python_file}" "load python file"
46
47gdb_test "info pretty-printer" \
48    {.*function_lookup_test.*pp-test.*struct ss.*}
49
50gdb_test "info pretty-printer global .*function" \
51    {.*function_lookup_test.*}
52
53gdb_test "info pretty-printer .* pp-test" \
54    {.*pp-test.*struct ss.*}
55
56gdb_test "print flt" " = x=<42> y=<43>" \
57    "print flt enabled #1"
58
59gdb_test "print ss" " = a=<a=<1> b=<$hex>> b=<a=<2> b=<$hex>>" \
60    "print ss enabled #1"
61
62set num_pp 7
63
64gdb_test "disable pretty-printer" \
65    "$num_pp printers disabled.*0 of $num_pp printers enabled"
66
67gdb_test "enable pretty-printer" \
68    "$num_pp printers enabled.*$num_pp of $num_pp printers enabled" \
69    "first enable of all pretty printers"
70
71gdb_test "disable pretty-printer global" \
72    "$num_pp printers disabled.*0 of $num_pp printers enabled"
73
74gdb_test "enable pretty-printer" \
75    "$num_pp printers enabled.*$num_pp of $num_pp printers enabled" \
76    "second enable of all pretty printers"
77
78gdb_test "disable pretty-printer global lookup_function_lookup_test" \
79    "1 printer disabled.*[expr $num_pp - 1] of $num_pp printers enabled"
80
81gdb_test "disable pretty-printer global pp-test;.*" \
82    "[expr $num_pp - 2] printers disabled.*1 of $num_pp printers enabled"
83
84gdb_test "info pretty-printer global .*function" \
85    {.*function_lookup_test \[disabled\].*} \
86    "info pretty-printer for function, pretty-printer is disabled"
87
88gdb_test "info pretty-printer .* pp-test" \
89    {.*pp-test.*struct ss \[disabled\].*} \
90    "info pretty-printer for pp-test, pretty-printer is disabled"
91
92gdb_test "print flt" " = {x = 42, y = 43}" \
93    "print flt disabled"
94
95gdb_test "print ss" " = {a = {a = 1, b = $hex}, b = {a = 2, b = $hex}}" \
96    "print ss disabled"
97
98gdb_test "enable pretty-printer global lookup_function_lookup_test" \
99    "1 printer enabled.*2 of $num_pp printers enabled"
100
101# This doesn't enable any printers because each subprinter in the collection
102# is still individually disabled.  But this is still needed, to enable the
103# collection itself.
104gdb_test "enable pretty-printer global pp-test" \
105    "0 printers enabled.*2 of $num_pp printers enabled"
106
107gdb_test "enable pretty-printer global pp-test;.*ss.*" \
108    "2 printers enabled.*[expr $num_pp - 3] of $num_pp printers enabled"
109
110gdb_test "enable pretty-printer global pp-test;.*s.*" \
111    "2 printers enabled.*[expr $num_pp - 1] of $num_pp printers enabled"
112
113gdb_test "enable pretty-printer global pp-test;.*" \
114    "1 printer enabled.*$num_pp of $num_pp printers enabled"
115
116gdb_test "info pretty-printer" \
117    {.*function_lookup_test.*pp-test.*struct ss.*} \
118    "info pretty-printer after re-enabling"
119
120gdb_test "print flt" " = x=<42> y=<43>" \
121    "print flt re-enabled"
122
123gdb_test "print ss" " = a=<a=<1> b=<$hex>> b=<a=<2> b=<$hex>>" \
124    "print ss re-enabled"
125
126gdb_test_exact "print (enum flag_enum) (FOO_1)" \
127    { = 0x1 [FOO_1]}
128
129gdb_test_exact "print (enum flag_enum) (BAR_3)" \
130    { = 0x40 [BAR_3]}
131
132gdb_test_exact "print (enum flag_enum) (BAR_2 | FOO_2)" \
133    { = 0x22 [FOO_2 | BAR_2]}
134
135gdb_test_exact "print (enum flag_enum) (FOO_1 | FOO_2 | FOO_3)" \
136    { = 0x7 [FOO_1 | FOO_2 | FOO_3]}
137
138gdb_test_exact "print (enum flag_enum) (FOO_MASK)" \
139    { = 0x7 [FOO_1 | FOO_2 | FOO_3]}
140
141gdb_test_exact "print (enum flag_enum) (FOO_MASK | (BAR_MASK & ~BAR_2))" \
142    { = 0x57 [FOO_1 | FOO_2 | FOO_3 | BAR_1 | BAR_3]}
143
144gdb_test_exact "print (enum flag_enum) (0x4 + 0x8)" \
145    { = 0xc [FOO_3 | <unknown: 0x8>]}
146