1 # Copyright (C) 2010-2024 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-based
17 # pretty-printing for the CLI.
19 require {!is_remote host}
21 load_lib gdb-python.exp
23 require allow_python_tests
27 if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
35 gdb_test "b [gdb_get_line_number {break to inspect} ${testfile}.c ]" \
37 gdb_test "continue" ".*Breakpoint.*"
39 set python_file [gdb_remote_download host ${srcdir}/${subdir}/${testfile}.py]
41 gdb_test_no_output "source ${python_file}" "load python file"
43 gdb_test "info pretty-printer" \
44 {.*function_lookup_test.*pp-test.*struct ss.*}
46 gdb_test "info pretty-printer global .*function" \
47 {.*function_lookup_test.*}
49 gdb_test "info pretty-printer .* pp-test" \
50 {.*pp-test.*struct ss.*}
52 gdb_test "print flt" " = x=<42> y=<43>" \
53 "print flt enabled #1"
55 gdb_test "print ss" " = a=<a=<1> b=<$hex>> b=<a=<2> b=<$hex>>" \
60 gdb_test "disable pretty-printer" \
61 "$num_pp printers disabled.*0 of $num_pp printers enabled"
63 gdb_test "enable pretty-printer" \
64 "$num_pp printers enabled.*$num_pp of $num_pp printers enabled" \
65 "first enable of all pretty printers"
67 gdb_test "disable pretty-printer global" \
68 "$num_pp printers disabled.*0 of $num_pp printers enabled"
70 gdb_test "enable pretty-printer" \
71 "$num_pp printers enabled.*$num_pp of $num_pp printers enabled" \
72 "second enable of all pretty printers"
74 gdb_test "disable pretty-printer global lookup_function_lookup_test" \
75 "1 printer disabled.*[expr $num_pp - 1] of $num_pp printers enabled"
77 gdb_test "disable pretty-printer global pp-test;.*" \
78 "[expr $num_pp - 2] printers disabled.*1 of $num_pp printers enabled"
80 gdb_test "info pretty-printer global .*function" \
81 {.*function_lookup_test \[disabled\].*} \
82 "info pretty-printer for function, pretty-printer is disabled"
84 gdb_test "info pretty-printer .* pp-test" \
85 {.*pp-test.*struct ss \[disabled\].*} \
86 "info pretty-printer for pp-test, pretty-printer is disabled"
88 gdb_test "print flt" " = {x = 42, y = 43}" \
91 gdb_test "print ss" " = {a = {a = 1, b = $hex}, b = {a = 2, b = $hex}}" \
94 gdb_test "enable pretty-printer global lookup_function_lookup_test" \
95 "1 printer enabled.*2 of $num_pp printers enabled"
97 # This doesn't enable any printers because each subprinter in the collection
98 # is still individually disabled. But this is still needed, to enable the
100 gdb_test "enable pretty-printer global pp-test" \
101 "0 printers enabled.*2 of $num_pp printers enabled"
103 gdb_test "enable pretty-printer global pp-test;.*ss.*" \
104 "2 printers enabled.*[expr $num_pp - 3] of $num_pp printers enabled"
106 gdb_test "enable pretty-printer global pp-test;.*s.*" \
107 "2 printers enabled.*[expr $num_pp - 1] of $num_pp printers enabled"
109 gdb_test "enable pretty-printer global pp-test;.*" \
110 "1 printer enabled.*$num_pp of $num_pp printers enabled"
112 gdb_test "info pretty-printer" \
113 {.*function_lookup_test.*pp-test.*struct ss.*} \
114 "info pretty-printer after re-enabling"
116 gdb_test "print flt" " = x=<42> y=<43>" \
117 "print flt re-enabled"
119 gdb_test "print ss" " = a=<a=<1> b=<$hex>> b=<a=<2> b=<$hex>>" \
120 "print ss re-enabled"
122 gdb_test_exact "print (enum flag_enum) (FOO_1)" \
125 gdb_test_exact "print (enum flag_enum) (BAR_3)" \
128 gdb_test_exact "print (enum flag_enum) (BAR_2 | FOO_2)" \
129 { = 0x22 [FOO_2 | BAR_2]}
131 gdb_test_exact "print (enum flag_enum) (FOO_1 | FOO_2 | FOO_3)" \
132 { = 0x7 [FOO_1 | FOO_2 | FOO_3]}
134 gdb_test_exact "print (enum flag_enum) (FOO_MASK)" \
135 { = 0x7 [FOO_1 | FOO_2 | FOO_3]}
137 gdb_test_exact "print (enum flag_enum) (FOO_MASK | (BAR_MASK & ~BAR_2))" \
138 { = 0x57 [FOO_1 | FOO_2 | FOO_3 | BAR_1 | BAR_3]}
140 gdb_test_exact "print (enum flag_enum) (0x4 + 0x8)" \
141 { = 0xc [FOO_3 | <unknown: 0x8>]}