]>
Commit | Line | Data |
---|---|---|
1d506c26 | 1 | # Copyright (C) 2008-2024 Free Software Foundation, Inc. |
a6bac58e TT |
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 | ||
a2c09bd0 DE |
19 | load_lib gdb-python.exp |
20 | ||
d82e5429 | 21 | require allow_python_tests |
79749205 | 22 | |
b4a58790 | 23 | standard_testfile |
a6bac58e TT |
24 | |
25 | # Start with a fresh gdb. | |
26 | gdb_exit | |
27 | gdb_start | |
f6bbabf0 | 28 | |
db8e4570 UW |
29 | proc run_lang_tests {exefile lang} { |
30 | global srcdir subdir srcfile testfile hex | |
31 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${exefile}" executable "debug $lang"] != "" } { | |
84c93cd5 | 32 | untested "failed to compile in $lang mode" |
a6bac58e TT |
33 | return -1 |
34 | } | |
35 | ||
36 | set nl "\[\r\n\]+" | |
37 | ||
38 | # Start with a fresh gdb. | |
9b2234b0 | 39 | clean_restart $exefile |
a6bac58e | 40 | |
b0e16ca5 | 41 | if {![runto_main]} { |
a6bac58e TT |
42 | return |
43 | } | |
44 | ||
89493308 | 45 | gdb_test_no_output "set print pretty on" |
a6bac58e | 46 | |
3714a195 AB |
47 | gdb_breakpoint [gdb_get_line_number "break to inspect" ${testfile}.c] |
48 | gdb_continue_to_breakpoint "break to inspect" ".*break to inspect.*" | |
49 | ||
f24fce77 | 50 | |
8448e842 TT |
51 | set remote_python_file [gdb_remote_download host \ |
52 | ${srcdir}/${subdir}/${testfile}.py] | |
f24fce77 | 53 | |
72ca0410 | 54 | gdb_test_no_output "source ${remote_python_file}" "load python file" |
a6bac58e TT |
55 | |
56 | gdb_test "print ss" " = a=< a=<1> b=<$hex>> b=< a=<2> b=<$hex>>" | |
57 | gdb_test "print ssa\[1\]" " = a=< a=<5> b=<$hex>> b=< a=<6> b=<$hex>>" | |
58 | gdb_test "print ssa" " = {a=< a=<3> b=<$hex>> b=< a=<4> b=<$hex>>, a=< a=<5> b=<$hex>> b=< a=<6> b=<$hex>>}" | |
59 | ||
91158a56 TT |
60 | gdb_test "print arraystruct" " = {$nl *y = 7, *$nl *x = { a=<23> b=<$hex>, a=<24> b=<$hex>} *$nl *}" |
61 | ||
0625771b LS |
62 | # Test that when a pretty-printer returns a gdb.Value in its to_string, we |
63 | # call the pretty-printer of that value too. | |
64 | gdb_test "print tsrvw" " = Inner to_string 1989" | |
65 | ||
a6bac58e TT |
66 | if {$lang == "c++"} { |
67 | gdb_test "print cps" "= a=<8> b=<$hex>" | |
68 | gdb_test "print cpss" " = {$nl *zss = 9, *$nl *s = a=<10> b=<$hex>$nl}" | |
69 | gdb_test "print cpssa\[0\]" " = {$nl *zss = 11, *$nl *s = a=<12> b=<$hex>$nl}" | |
70 | gdb_test "print cpssa\[1\]" " = {$nl *zss = 13, *$nl *s = a=<14> b=<$hex>$nl}" | |
71 | gdb_test "print cpssa" " = {{$nl *zss = 11, *$nl *s = a=<12> b=<$hex>$nl *}, {$nl *zss = 13, *$nl *s = a=<14> b=<$hex>$nl *}}" | |
72 | gdb_test "print sss" "= a=<15> b=< a=<8> b=<$hex>>" | |
73 | gdb_test "print ref" "= a=<15> b=< a=<8> b=<$hex>>" | |
74 | gdb_test "print derived" \ | |
75 | " = \{.*<Vbase1> = pp class name: Vbase1.*<Vbase2> = \{.*<VirtualTest> = pp value variable is: 1,.*members of Vbase2:.*_vptr.Vbase2 = $hex.*<Vbase3> = \{.*members of Vbase3.*members of Derived:.*value = 2.*" | |
3714a195 AB |
76 | gdb_test "print ns " "\"embedded\\\\000null\\\\000string\"" \ |
77 | "print ns with default element limit" | |
78 | gdb_test_no_output "set print elements 3" | |
79 | gdb_test "print ns" "emb\.\.\.." \ | |
80 | "print ns with element limit of 3" | |
81 | gdb_test_no_output "set print elements 10" | |
82 | gdb_test "print ns" "embedded\\\\000n\.\.\.." \ | |
83 | "print ns with element limit of 10" | |
84 | gdb_test_no_output "set print elements 200" | |
3c0e3120 TT |
85 | |
86 | gdb_test "print has_member" \ | |
87 | "= a=<23> b=<$hex <has_static_member::global>>.*" | |
88 | gdb_test "print has_static_member::global" \ | |
89 | "= a=<23> b=<$hex <has_static_member::global>>" | |
a6bac58e TT |
90 | } |
91 | ||
20c6f1e1 YQ |
92 | if { ![is_address_zero_readable] } { |
93 | gdb_test "print ns2" \ | |
94 | ".error reading variable: Cannot access memory at address 0x0." | |
95 | } | |
621c8364 | 96 | |
269f82e5 PP |
97 | gdb_test "print x" " = \"this is x\"" |
98 | gdb_test "print cstring" " = \"const string\"" | |
a6bac58e | 99 | |
a81766d8 | 100 | gdb_test "print estring" " = \"embedded x\\\\201\\\\202\\\\203\\\\204\"" |
bf7b9cd9 SM |
101 | if { ![is_address_zero_readable] } { |
102 | gdb_test "print estring3" \ | |
103 | " = <error reading variable: Cannot create a lazy string with address 0x0, and a non-zero length.>" | |
104 | } | |
3a772aa4 TT |
105 | |
106 | gdb_test_no_output "python pp_ls_encoding = 'UTF-8'" | |
107 | gdb_test "print estring2" "\"embedded \", <incomplete sequence \\\\302>" | |
108 | ||
80b6e756 | 109 | gdb_test_no_output "set python print-stack full" |
e1ab1f9c JK |
110 | gdb_test "print hint_error" "Exception: hint failed\r\nhint_error_val" |
111 | ||
9f9aa852 AB |
112 | gdb_test "print c" " = container \"container\" with 2 elements = {$nl *.0. = 23,$nl *.1. = 72$nl}" \ |
113 | "print c, pretty printing on, default display hint" | |
114 | ||
b1f3973b AB |
115 | gdb_test_no_output "set variable c.is_array_p=1" |
116 | gdb_test "print c" " = container \"container\" with 2 elements = \\{23, 72\\}" \ | |
117 | "print c, pretty printing on, display hint is now array" | |
118 | ||
119 | # Setting is_map_p while _is_array_p is also set will cause the | |
120 | # display_hint method to raise an exception (see py-prettyprint.py). | |
9f9aa852 | 121 | gdb_test_no_output "set variable c.is_map_p=1" |
b1f3973b AB |
122 | |
123 | # This test checks what happens when the display hint throws an | |
124 | # error. GDB just treats this as though the display hint was | |
125 | # None. | |
126 | set py_exception \ | |
127 | [multi_line \ | |
128 | "Traceback\[^\r\n\]+" \ | |
129 | "\\s+File \"\[^\r\n\]+/py-prettyprint.py\", line \[0-9\]+, in display_hint" \ | |
13123da8 | 130 | "\\s+raise Exception\[^\r\n\]+" \ |
b1f3973b AB |
131 | "Exception: invalid object state found in display_hint"] |
132 | gdb_test "print c" \ | |
133 | [multi_line \ | |
134 | " = ${py_exception}" \ | |
135 | "container \"container\" with 2 elements = {" \ | |
136 | "\\s+\\\[0\\\] = 23," \ | |
137 | "\\s+\\\[1\\\] = 72" \ | |
138 | "}"] \ | |
139 | "print c, pretty printing on, exception raised from display_hint" | |
140 | ||
141 | # Unset is_array_p so that display_hint no longer raises an | |
142 | # exception. | |
143 | gdb_test_no_output "set variable c.is_array_p=0" | |
144 | ||
9f9aa852 AB |
145 | gdb_test "print c" " = container \"container\" with 2 elements = \{$nl \\\[23\\\] = 72$nl\}" \ |
146 | "print c, pretty printing on, display hint is now map" | |
a6bac58e | 147 | |
79f283fe | 148 | gdb_test "print nstype" " = {$nl *.0. = 7,$nl *.1. = 42$nl}" |
a81766d8 TT |
149 | |
150 | gdb_test_no_output "set print pretty off" | |
151 | gdb_test "print nstype" " = {.0. = 7, .1. = 42}" \ | |
152 | "print nstype on one line" | |
153 | ||
9f9aa852 AB |
154 | # Now we have pretty printing turned off, try printing 'c' again. |
155 | gdb_test "print c" " = container \"container\" with 2 elements = \{\\\[23\\\] = 72\}" \ | |
156 | "print c, pretty printing off, display hint is now map" | |
157 | ||
158 | gdb_test_no_output "set variable c.is_map_p=0" | |
159 | gdb_test "print c" " = container \"container\" with 2 elements = \{\\\[0\\\] = 23, \\\[1\\\] = 72\}" \ | |
160 | "print c, pretty printing off, default display hint" | |
161 | ||
c973d0aa PA |
162 | # Check that GDB doesn't lose typedefs when looking for a printer. |
163 | gdb_test "print an_int" " = -1" | |
164 | gdb_test "print (int) an_int" " = -1" | |
165 | gdb_test "print (int_type) an_int" " = type=int_type, val=-1" | |
166 | ||
167 | gdb_test "print an_int_type" " = type=int_type, val=1" | |
168 | gdb_test "print (int_type) an_int_type" " = type=int_type, val=1" | |
169 | ||
170 | gdb_test "print an_int_type2" " = type=int_type2, val=2" | |
171 | gdb_test "print (int) an_int_type2" " = 2" | |
172 | gdb_test "print (int_type) an_int_type2" " = type=int_type, val=2" | |
173 | gdb_test "print (int_type2) an_int_type2" " = type=int_type2, val=2" | |
174 | ||
332cf4c9 TT |
175 | # PR python/16047: it is ok for a pretty printer not to have a |
176 | # to_string method. | |
177 | gdb_test "print (int_type3) an_int_type2" " = {s = 27}" | |
178 | ||
fda326dd | 179 | gdb_continue_to_end |
a6bac58e TT |
180 | } |
181 | ||
1aac008f TT |
182 | with_test_prefix c { |
183 | if { [run_lang_tests "${binfile}" "c"] == -1 } { | |
184 | return | |
185 | } | |
e70b6e8e | 186 | } |
1aac008f TT |
187 | with_test_prefix c++ { |
188 | if { [run_lang_tests "${binfile}-cxx" "c++"] == -1 } { | |
189 | return | |
190 | } | |
e70b6e8e | 191 | } |
967cf477 DE |
192 | |
193 | # Run various other tests. | |
194 | ||
9b2234b0 | 195 | clean_restart $binfile |
967cf477 | 196 | |
b0e16ca5 | 197 | if {![runto_main]} { |
967cf477 DE |
198 | return |
199 | } | |
200 | ||
8448e842 TT |
201 | set remote_python_file [gdb_remote_download host \ |
202 | ${srcdir}/${subdir}/${testfile}.py] | |
967cf477 | 203 | |
72ca0410 | 204 | gdb_test_no_output "source ${remote_python_file}" "load python file" |
967cf477 | 205 | |
8f043999 JK |
206 | gdb_breakpoint [gdb_get_line_number "eval-break"] |
207 | gdb_continue_to_breakpoint "eval-break" ".* eval-break .*" | |
208 | ||
209 | gdb_test "info locals" "eval9 = eval=<123456789>" | |
210 | ||
3714a195 AB |
211 | gdb_breakpoint [gdb_get_line_number "break to inspect" ${testfile}.c ] |
212 | gdb_continue_to_breakpoint "break to inspect" ".*break to inspect.*" | |
8f043999 | 213 | |
967cf477 DE |
214 | gdb_test "print ss" " = a=< a=<1> b=<$hex>> b=< a=<2> b=<$hex>>" \ |
215 | "print ss enabled #1" | |
216 | ||
f6978de9 | 217 | gdb_test_no_output "python disable_lookup_function ()" |
967cf477 DE |
218 | |
219 | gdb_test "print ss" " = {a = {a = 1, b = $hex}, b = {a = 2, b = $hex}}" \ | |
220 | "print ss disabled" | |
221 | ||
f6978de9 | 222 | gdb_test_no_output "python enable_lookup_function ()" |
967cf477 DE |
223 | |
224 | gdb_test "print ss" " = a=< a=<1> b=<$hex>> b=< a=<2> b=<$hex>>" \ | |
225 | "print ss enabled #2" | |
d8edc8b7 PW |
226 | |
227 | gdb_test "print -raw-values -- ss" " = {a = {a = 1, b = $hex}, b = {a = 2, b = $hex}}" \ | |
228 | "print -raw-values -- ss" | |
229 | ||
230 | gdb_test "print -raw-values on -- ss" " = {a = {a = 1, b = $hex}, b = {a = 2, b = $hex}}" \ | |
231 | "print -raw-values on -- ss" | |
232 | ||
233 | gdb_test "with print raw-values -- print ss" " = {a = {a = 1, b = $hex}, b = {a = 2, b = $hex}}" \ | |
234 | "with print raw-values -- print ss" | |
235 | ||
236 | # Test interaction between /r format and raw-values option: | |
237 | # When /r is not present, raw-values option tells to bypass (or not) the pretty printers. | |
238 | # (these cases are tested above). | |
239 | # When /r is present, it must override the option raw-values off. | |
240 | gdb_test "print /r ss" " = {a = {a = 1, b = $hex}, b = {a = 2, b = $hex}}" | |
241 | ||
242 | gdb_test "with print raw-values off -- print /r ss" " = {a = {a = 1, b = $hex}, b = {a = 2, b = $hex}}" | |
243 | ||
244 | gdb_test "print -raw-values off -- /r ss" " = {a = {a = 1, b = $hex}, b = {a = 2, b = $hex}}" | |
245 | ||
246 |