2a011ebd45acbc0d760693ddaa6e09179a1c902a
[binutils-gdb.git] / gdb / testsuite / gdb.python / py-format-string.exp
1 # Copyright (C) 2009-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 the
17 # gdb.Value.format_string () method.
18
19 load_lib gdb-python.exp
20
21 require allow_python_tests
22
23 standard_testfile
24
25 gdb_exit
26 gdb_start
27
28 # Build inferior to language specification.
29 proc build_inferior {exefile lang} {
30 global srcdir subdir srcfile testfile hex
31
32 set flags [list debug $lang]
33 if { $lang == "c" } {
34 lappend flags additional_flags=-std=c99
35 }
36
37 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${exefile}" \
38 executable $flags] != "" } {
39 untested "failed to compile in $lang mode"
40 return -1
41 }
42
43 return 0
44 }
45
46 # Restart GDB.
47 proc prepare_gdb {exefile} {
48 global srcdir subdir srcfile testfile hex
49
50 clean_restart $exefile
51
52 if {![runto_main]} {
53 return
54 }
55
56 # Load the pretty printer.
57 set remote_python_file \
58 [gdb_remote_download host ${srcdir}/${subdir}/${testfile}.py]
59 gdb_test_no_output "source ${remote_python_file}" "load python file"
60
61 runto_bp "break here"
62 }
63
64 # Set breakpoint and run to that breakpoint.
65 proc runto_bp {bp} {
66 gdb_breakpoint [gdb_get_line_number $bp]
67 gdb_continue_to_breakpoint $bp
68 }
69
70 # Set an option using the GDB command in $set_cmd, execute $body, and then
71 # restore the option using the GDB command in $unset_cmd.
72 proc with_temp_option { set_cmd unset_cmd body } {
73 with_test_prefix $set_cmd {
74 gdb_test "$set_cmd" ".*"
75 uplevel 1 $body
76 gdb_test "$unset_cmd" ".*"
77 }
78 }
79
80 # A regular expression for a pointer.
81 set default_pointer_regexp "0x\[a-fA-F0-9\]+"
82
83 # A regular expression for a non-expanded C++ reference.
84 #
85 # Stringifying a C++ reference produces an address preceeded by a "@" in
86 # Python, but, by default, the C++ reference/class is expanded by the
87 # GDB print command.
88 set default_ref_regexp "@${default_pointer_regexp}"
89
90 # The whole content of the C variable a_big_string, i.e. the whole English
91 # alphabet repeated 10 times.
92 set whole_big_string ""
93 set alphabet "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
94 for {set i 0} {$i < 10} {incr i} {
95 append whole_big_string $alphabet
96 }
97 unset alphabet
98
99 # Produces a potentially cut down version of $whole_big_string like GDB
100 # would represent it.
101 # $max is the maximum number of characters allowed in the string (but
102 # the return value may contain more to accound for the extra quotes and
103 # "..." added by GDB).
104 proc get_cut_big_string { max } {
105 global whole_big_string
106
107 set whole_size [string length $whole_big_string]
108 if { $max > $whole_size } {
109 return "\"${whole_big_string}\""
110 }
111
112 set cut_string [string range $whole_big_string 0 [expr $max - 1]]
113 return "\"${cut_string}\"..."
114 }
115
116 # A dictionary mapping from C variable names to their default string
117 # representation when using str () or gdb.Value.format_string () with
118 # no arguments.
119 # This usually matches what the print command prints if used with no
120 # options, except for C++ references which are not expanded by
121 # default in Python. See the comment above $default_ref_regexp.
122 set default_regexp_dict [dict create \
123 "a_point_t" "Pretty Point \\(42, 12\\)" \
124 "a_point_t_pointer" $default_pointer_regexp \
125 "a_point_t_ref" "Pretty Point \\(42, 12\\)" \
126 "another_point" "Pretty Point \\(123, 456\\)" \
127 "a_struct_with_point" "\\{the_point = Pretty Point \\(42, 12\\)\\}" \
128 "a_struct_with_union" "\\{the_union = \\{an_int = 707406378, a_char = 42 '\\*'\\}\\}" \
129 "an_enum" "ENUM_BAR" \
130 "a_string" "${default_pointer_regexp} \"hello world\"" \
131 "a_binary_string" "${default_pointer_regexp} \"hello\"" \
132 "a_binary_string_array" "\"hello\\\\000world\"" \
133 "a_big_string" [get_cut_big_string 200] \
134 "an_array" "\\{2, 3, 5\\}" \
135 "an_array_with_repetition" "\\{1, 3 <repeats 12 times>, 5, 5, 5\\}" \
136 "a_symbol_pointer" "${default_pointer_regexp} <global_symbol>" \
137 "a_base_ref" "${default_ref_regexp}" \
138 ]
139
140 # A sentinel value to pass to function to get them to use a default value
141 # instead.
142 # Note that we cannot use $undefined for default arguments in function
143 # definitions as we would just get the literal "$undefined" string, so
144 # we need to repeat the string.
145 set undefined "\000UNDEFINED\000"
146
147 # Return $value if it's not $undefined, otherwise return the default value
148 # (from $default_regexp_dict) for the variable $var.
149 proc get_value_or_default { var value } {
150 global undefined
151 if { $value != $undefined } {
152 return $value
153 }
154
155 global default_regexp_dict
156 return [dict get $default_regexp_dict $var]
157 }
158
159 # Check that using gdb.Value.format_string on the value representing the
160 # variable $var produces $expected.
161 proc check_format_string {
162 var
163 opts
164 { expected "\000UNDEFINED\000" }
165 { name "\000UNDEFINED\000" }
166 } {
167 global undefined
168
169 set expected [get_value_or_default $var $expected]
170 if { $name == $undefined } {
171 set name "${var} with option ${opts}"
172 }
173
174 gdb_test \
175 "python print (gdb.parse_and_eval ('${var}').format_string (${opts}))" \
176 $expected \
177 $name
178 }
179
180 # Check that printing $var with no options set, produces the expected
181 # output.
182 proc check_var_with_no_opts {
183 var
184 { expected "\000UNDEFINED\000" }
185 } {
186 set expected [get_value_or_default $var $expected]
187
188 with_test_prefix "${var}" {
189 check_format_string \
190 $var \
191 "" \
192 $expected \
193 "no opts"
194 # str () should behave like gdb.Value.format_string () with no args.
195 gdb_test \
196 "python print (str (gdb.parse_and_eval ('${var}')))" \
197 $expected \
198 "str"
199 }
200 }
201
202 # Check that printing $var with $opt set to True and set to False,
203 # produces the expected output.
204 proc check_var_with_bool_opt {
205 opt
206 var
207 { true_expected "\000UNDEFINED\000" }
208 { false_expected "\000UNDEFINED\000" }
209 } {
210 set true_expected [get_value_or_default $var $true_expected]
211 set false_expected [get_value_or_default $var $false_expected]
212
213 with_test_prefix "${var} with option ${opt}" {
214 # Option set to True.
215 check_format_string \
216 $var \
217 "${opt}=True" \
218 $true_expected \
219 "${opt}=true"
220 # Option set to False.
221 check_format_string \
222 $var \
223 "${opt}=False" \
224 $false_expected \
225 "${opt}=false"
226 }
227 }
228
229 # Test gdb.Value.format_string with no options.
230 proc_with_prefix test_no_opts {} {
231 global current_lang
232
233 check_var_with_no_opts "a_point_t"
234 check_var_with_no_opts "a_point_t_pointer"
235 check_var_with_no_opts "another_point"
236 check_var_with_no_opts "a_struct_with_union"
237 check_var_with_no_opts "an_enum"
238 check_var_with_no_opts "a_string"
239 check_var_with_no_opts "a_binary_string"
240 check_var_with_no_opts "a_binary_string_array"
241 check_var_with_no_opts "a_big_string"
242 check_var_with_no_opts "an_array"
243 check_var_with_no_opts "an_array_with_repetition"
244 check_var_with_no_opts "a_symbol_pointer"
245
246 if { $current_lang == "c++" } {
247 # Nothing changes in all of the C++ tests because deref_refs is not
248 # True.
249 check_var_with_no_opts "a_point_t_ref"
250 check_var_with_no_opts "a_base_ref"
251 }
252 }
253
254 # Test the raw option for gdb.Value.format_string.
255 proc_with_prefix test_raw {} {
256 global current_lang
257 global default_ref_regexp
258
259 check_var_with_bool_opt "raw" "a_point_t" \
260 "{x = 42, y = 12}"
261 check_var_with_bool_opt "raw" "a_point_t_pointer"
262 check_var_with_bool_opt "raw" "another_point" \
263 "{x = 123, y = 456}"
264 check_var_with_bool_opt "raw" "a_struct_with_union"
265 check_var_with_bool_opt "raw" "an_enum"
266 check_var_with_bool_opt "raw" "a_string"
267 check_var_with_bool_opt "raw" "a_binary_string"
268 check_var_with_bool_opt "raw" "a_binary_string_array"
269 check_var_with_bool_opt "raw" "a_big_string"
270 check_var_with_bool_opt "raw" "an_array"
271 check_var_with_bool_opt "raw" "an_array_with_repetition"
272 check_var_with_bool_opt "raw" "a_symbol_pointer"
273
274 if { $current_lang == "c++" } {
275 check_var_with_bool_opt "raw" "a_point_t_ref" \
276 ${default_ref_regexp}
277 check_var_with_bool_opt "raw" "a_base_ref"
278 }
279
280 with_temp_option \
281 "disable pretty-printer '' test_lookup_function" \
282 "enable pretty-printer '' test_lookup_function" {
283 check_var_with_no_opts "a_point_t" \
284 "{x = 42, y = 12}"
285 check_var_with_bool_opt "raw" "a_point_t" \
286 "{x = 42, y = 12}" \
287 "{x = 42, y = 12}"
288 }
289 }
290
291 # Test the pretty_arrays option for gdb.Value.format_string.
292 proc_with_prefix test_pretty_arrays {} {
293 global current_lang
294
295 set an_array_pretty "\\{\[\r\n\]+ 2,\[\r\n\]+ 3,\[\r\n\]+ 5\[\r\n\]+\\}"
296 set an_array_with_repetition_pretty \
297 "\\{\[\r\n\]+ 1,\[\r\n\]+ 3 <repeats 12 times>,\[\r\n\]+ 5,\[\r\n\]+ 5,\[\r\n\]+ 5\[\r\n\]+\\}"
298
299 check_var_with_bool_opt "pretty_arrays" "a_point_t"
300 check_var_with_bool_opt "pretty_arrays" "a_point_t_pointer"
301 check_var_with_bool_opt "pretty_arrays" "another_point"
302 check_var_with_bool_opt "pretty_arrays" "a_struct_with_union"
303 check_var_with_bool_opt "pretty_arrays" "an_enum"
304 check_var_with_bool_opt "pretty_arrays" "a_string"
305 check_var_with_bool_opt "pretty_arrays" "a_binary_string"
306 check_var_with_bool_opt "pretty_arrays" "a_binary_string_array"
307 check_var_with_bool_opt "pretty_arrays" "a_big_string"
308 check_var_with_bool_opt "pretty_arrays" "an_array" \
309 $an_array_pretty
310 check_var_with_bool_opt "pretty_arrays" "an_array_with_repetition" \
311 $an_array_with_repetition_pretty
312 check_var_with_bool_opt "pretty_arrays" "a_symbol_pointer"
313
314 if { $current_lang == "c++" } {
315 check_var_with_bool_opt "pretty_arrays" "a_point_t_ref"
316 check_var_with_bool_opt "pretty_arrays" "a_base_ref"
317 }
318
319 with_temp_option "set print array on" "set print array off" {
320 check_var_with_no_opts "an_array" \
321 $an_array_pretty
322 check_var_with_bool_opt "pretty_arrays" "an_array" \
323 $an_array_pretty
324
325 check_var_with_no_opts "an_array_with_repetition" \
326 $an_array_with_repetition_pretty
327 check_var_with_bool_opt "pretty_arrays" "an_array_with_repetition" \
328 $an_array_with_repetition_pretty
329 }
330 }
331
332 # Test the pretty_structs option for gdb.Value.format_string.
333 proc_with_prefix test_pretty_structs {} {
334 global current_lang
335
336 set a_struct_with_union_pretty \
337 "\\{\[\r\n\]+ the_union = \\{\[\r\n\]+ an_int = 707406378,\[\r\n\]+ a_char = 42 '\\*'\[\r\n\]+ \\}\[\r\n\]+\\}"
338
339 check_var_with_bool_opt "pretty_structs" "a_point_t"
340 check_var_with_bool_opt "pretty_structs" "a_point_t_pointer"
341 check_var_with_bool_opt "pretty_structs" "another_point"
342 check_var_with_bool_opt "pretty_structs" "a_struct_with_union" \
343 $a_struct_with_union_pretty
344 check_var_with_bool_opt "pretty_structs" "an_enum"
345 check_var_with_bool_opt "pretty_structs" "a_string"
346 check_var_with_bool_opt "pretty_structs" "a_binary_string"
347 check_var_with_bool_opt "pretty_structs" "a_binary_string_array"
348 check_var_with_bool_opt "pretty_structs" "a_big_string"
349 check_var_with_bool_opt "pretty_structs" "an_array"
350 check_var_with_bool_opt "pretty_structs" "an_array_with_repetition"
351 check_var_with_bool_opt "pretty_structs" "a_symbol_pointer"
352
353 if { $current_lang == "c++" } {
354 check_var_with_bool_opt "pretty_structs" "a_point_t_ref"
355 check_var_with_bool_opt "pretty_structs" "a_base_ref"
356 }
357
358 with_temp_option "set print structs on" "set print structs off" {
359 check_var_with_no_opts "a_struct_with_union"
360 check_var_with_bool_opt "pretty_structs" "a_struct_with_union" \
361 $a_struct_with_union_pretty
362 }
363
364 # point_t is usually printed through the pretty printer.
365 # Try disabling it.
366 with_temp_option \
367 "disable pretty-printer '' test_lookup_function" \
368 "enable pretty-printer '' test_lookup_function" {
369 check_var_with_no_opts "a_point_t" \
370 "{x = 42, y = 12}"
371 check_var_with_bool_opt "pretty_structs" "a_point_t" \
372 "\\{\[\r\n\]+ x = 42, *\[\r\n\]+ y = 12\[\r\n\]+\\}" \
373 "{x = 42, y = 12}" \
374 }
375 }
376
377 # Test the array_indexes option for gdb.Value.format_string.
378 proc_with_prefix test_array_indexes {} {
379 global current_lang
380
381 set an_array_with_indexes "\\{\\\[0\\\] = 2, \\\[1\\\] = 3, \\\[2\\\] = 5\\}"
382 set an_array_with_repetition_with_indexes \
383 "\\{\\\[0\\\] = 1, \\\[1\\\] = 3 <repeats 12 times>, \\\[13\\\] = 5, \\\[14\\\] = 5, \\\[15\\\] = 5\\}"
384
385 check_var_with_bool_opt "array_indexes" "a_point_t"
386 check_var_with_bool_opt "array_indexes" "a_point_t_pointer"
387 check_var_with_bool_opt "array_indexes" "another_point"
388 check_var_with_bool_opt "array_indexes" "a_struct_with_union"
389 check_var_with_bool_opt "array_indexes" "an_enum"
390 check_var_with_bool_opt "array_indexes" "a_string"
391 check_var_with_bool_opt "array_indexes" "a_binary_string"
392 check_var_with_bool_opt "array_indexes" "a_binary_string_array"
393 check_var_with_bool_opt "array_indexes" "a_big_string"
394 check_var_with_bool_opt "array_indexes" "an_array" \
395 $an_array_with_indexes
396 check_var_with_bool_opt "array_indexes" "an_array_with_repetition" \
397 $an_array_with_repetition_with_indexes
398 check_var_with_bool_opt "array_indexes" "a_symbol_pointer"
399
400 if { $current_lang == "c++" } {
401 check_var_with_bool_opt "array_indexes" "a_point_t_ref"
402 check_var_with_bool_opt "array_indexes" "a_base_ref"
403 }
404
405 with_temp_option \
406 "set print array-indexes on" \
407 "set print array-indexes off" {
408 check_var_with_no_opts "an_array" \
409 $an_array_with_indexes
410 check_var_with_bool_opt "array_indexes" "an_array" \
411 $an_array_with_indexes
412
413 check_var_with_no_opts "an_array_with_repetition" \
414 $an_array_with_repetition_with_indexes
415 check_var_with_bool_opt "array_indexes" "an_array_with_repetition" \
416 $an_array_with_repetition_with_indexes
417 }
418 }
419
420 # Test the symbols option for gdb.Value.format_string.
421 proc_with_prefix test_symbols {} {
422 global undefined
423 global current_lang
424 global default_pointer_regexp
425
426 check_var_with_bool_opt "symbols" "a_point_t"
427 check_var_with_bool_opt "symbols" "a_point_t_pointer"
428 check_var_with_bool_opt "symbols" "another_point"
429 check_var_with_bool_opt "symbols" "a_struct_with_union"
430 check_var_with_bool_opt "symbols" "an_enum"
431 check_var_with_bool_opt "symbols" "a_string"
432 check_var_with_bool_opt "symbols" "a_binary_string"
433 check_var_with_bool_opt "symbols" "a_binary_string_array"
434 check_var_with_bool_opt "symbols" "a_big_string"
435 check_var_with_bool_opt "symbols" "an_array"
436 check_var_with_bool_opt "symbols" "an_array_with_repetition"
437 check_var_with_bool_opt "symbols" "a_symbol_pointer" \
438 $undefined \
439 $default_pointer_regexp
440
441 if { $current_lang == "c++" } {
442 check_var_with_bool_opt "symbols" "a_point_t_ref"
443 check_var_with_bool_opt "symbols" "a_base_ref"
444 }
445
446 with_temp_option "set print symbol off" "set print symbol on" {
447 check_var_with_no_opts "a_symbol_pointer" \
448 $default_pointer_regexp
449 check_var_with_bool_opt "symbols" "a_symbol_pointer" \
450 $undefined \
451 $default_pointer_regexp
452 }
453 }
454
455 # Test the unions option for gdb.Value.format_string.
456 proc_with_prefix test_unions {} {
457 global undefined
458 global current_lang
459
460 check_var_with_bool_opt "unions" "a_point_t"
461 check_var_with_bool_opt "unions" "a_point_t_pointer"
462 check_var_with_bool_opt "unions" "another_point"
463 check_var_with_bool_opt "unions" "a_struct_with_union" \
464 $undefined \
465 "\\{the_union = \\{...\\}\\}"
466 check_var_with_bool_opt "unions" "an_enum"
467 check_var_with_bool_opt "unions" "a_string"
468 check_var_with_bool_opt "unions" "a_binary_string"
469 check_var_with_bool_opt "unions" "a_binary_string_array"
470 check_var_with_bool_opt "unions" "a_big_string"
471 check_var_with_bool_opt "unions" "an_array"
472 check_var_with_bool_opt "unions" "an_array_with_repetition"
473 check_var_with_bool_opt "unions" "a_symbol_pointer"
474
475 if { $current_lang == "c++" } {
476 check_var_with_bool_opt "unions" "a_point_t_ref"
477 check_var_with_bool_opt "unions" "a_base_ref"
478 }
479
480 with_temp_option "set print union off" "set print union on" {
481 check_var_with_no_opts "a_struct_with_union" \
482 "\\{the_union = \\{...\\}\\}"
483 check_var_with_bool_opt "unions" "a_struct_with_union" \
484 $undefined \
485 "\\{the_union = \\{...\\}\\}"
486 }
487 }
488
489 # Test the address option for gdb.Value.format_string.
490 proc_with_prefix test_address {} {
491 global undefined
492 global current_lang
493
494 check_var_with_bool_opt "address" "a_point_t"
495 check_var_with_bool_opt "address" "a_point_t_pointer" \
496 $undefined \
497 ""
498 check_var_with_bool_opt "address" "another_point"
499 check_var_with_bool_opt "symbols" "a_struct_with_union"
500 check_var_with_bool_opt "address" "an_enum"
501 check_var_with_bool_opt "address" "a_string" \
502 $undefined \
503 "\"hello world\""
504 check_var_with_bool_opt "address" "a_binary_string" \
505 $undefined \
506 "\"hello\""
507 check_var_with_bool_opt "address" "a_binary_string_array"
508 check_var_with_bool_opt "address" "a_big_string"
509 check_var_with_bool_opt "address" "an_array"
510 check_var_with_bool_opt "address" "an_array_with_repetition"
511 check_var_with_bool_opt "address" "a_symbol_pointer" \
512 $undefined \
513 "<global_symbol>"
514
515 if { $current_lang == "c++" } {
516 check_var_with_bool_opt "address" "a_point_t_ref"
517 check_var_with_bool_opt "address" "a_base_ref" \
518 $undefined \
519 ""
520 }
521
522 with_temp_option "set print address off" "set print address on" {
523 check_var_with_no_opts "a_string" \
524 "\"hello world\""
525 check_var_with_bool_opt "address" "a_string" \
526 $undefined \
527 "\"hello world\""
528 }
529 }
530
531 # Test the nibbles option for gdb.Value.format_string.
532 proc_with_prefix test_nibbles {} {
533 global current_lang
534
535 set opts "format='t', nibbles=True"
536 with_test_prefix $opts {
537 if { $current_lang == "c" } {
538 set binary_pointer_regexp "\[ 0-1\]+"
539 gdb_test "python print (gdb.Value (42).format_string (${opts}))" \
540 "0010 1010" \
541 "42 with option ${opts}"
542
543 check_format_string "a_point_t" $opts \
544 [string_to_regexp "Pretty Point (0010 1010, 1100)"]
545 check_format_string "a_point_t_pointer" $opts \
546 $binary_pointer_regexp
547 check_format_string "another_point" $opts \
548 [string_to_regexp "Pretty Point (0111 1011, 0001 1100 1000)"]
549
550 check_format_string "a_struct_with_union" $opts \
551 "\\{the_union = \\{an_int = 0010 1010 0010 1010 0010 1010 0010 1010, a_char = 0010 1010\\}\\}"
552 check_format_string "an_enum" $opts \
553 "0001"
554 check_format_string "a_string" $opts \
555 $binary_pointer_regexp
556 check_format_string "a_binary_string" $opts \
557 $binary_pointer_regexp
558 check_format_string "a_binary_string_array" $opts \
559 "\\{0110 1000, 0110 0101, 0110 1100, 0110 1100, 0110 1111, 0, 0111 0111, 0110 1111, 0111 0010, 0110 1100, 0110 0100, 0\\}"
560 check_format_string "a_big_string" $opts \
561 "\\{0100 0001, 0100 0010, 0100 0011, 0100 0100, 0100 0101, \[, 0-1\]+\.\.\.\\}"
562 check_format_string "an_array" $opts \
563 "\\{0010, 0011, 0101\\}"
564 check_format_string "an_array_with_repetition" $opts \
565 "\\{0001, 0011 <repeats 12 times>, 0101, 0101, 0101\\}"
566 check_format_string "a_symbol_pointer" $opts \
567 $binary_pointer_regexp
568 }
569 if { $current_lang == "c++" } {
570 set binary_pointer_regexp "\['0-1\]+"
571 gdb_test "python print (gdb.Value (42).format_string (${opts}))" \
572 "0010'1010" \
573 "42 with option ${opts}"
574
575 check_format_string "a_point_t" $opts \
576 [string_to_regexp "Pretty Point (0010'1010, 1100)"]
577 check_format_string "a_point_t_pointer" $opts \
578 $binary_pointer_regexp
579 check_format_string "another_point" $opts \
580 [string_to_regexp "Pretty Point (0111'1011, 0001'1100'1000)"]
581
582 check_format_string "a_struct_with_union" $opts \
583 "\\{the_union = \\{an_int = 0010'1010'0010'1010'0010'1010'0010'1010, a_char = 0010'1010\\}\\}"
584 check_format_string "an_enum" $opts \
585 "0001"
586 check_format_string "a_string" $opts \
587 $binary_pointer_regexp
588 check_format_string "a_binary_string" $opts \
589 $binary_pointer_regexp
590 check_format_string "a_binary_string_array" $opts \
591 "\\{0110'1000, 0110'0101, 0110'1100, 0110'1100, 0110'1111, 0, 0111'0111, 0110'1111, 0111'0010, 0110'1100, 0110'0100, 0\\}"
592 check_format_string "a_big_string" $opts \
593 "\\{0100'0001, 0100'0010, 0100'0011, 0100'0100, 0100'0101, \[, '0-1\]+\.\.\.\\}"
594 check_format_string "an_array" $opts \
595 "\\{0010, 0011, 0101\\}"
596 check_format_string "an_array_with_repetition" $opts \
597 "\\{0001, 0011 <repeats 12 times>, 0101, 0101, 0101\\}"
598 check_format_string "a_symbol_pointer" $opts \
599 $binary_pointer_regexp
600
601 check_format_string "a_point_t_ref" $opts \
602 [string_to_regexp "Pretty Point (0010'1010, 1100)"]
603 check_format_string "a_base_ref" $opts
604 }
605 }
606 }
607
608 # Test the deref_refs option for gdb.Value.format_string.
609 proc_with_prefix test_deref_refs {} {
610 global current_lang
611 global default_pointer_regexp
612 global default_ref_regexp
613 global decimal
614
615 check_var_with_bool_opt "deref_refs" "a_point_t"
616 check_var_with_bool_opt "deref_refs" "a_point_t_pointer"
617 check_var_with_bool_opt "deref_refs" "another_point"
618 check_var_with_bool_opt "deref_refs" "a_struct_with_union"
619 check_var_with_bool_opt "deref_refs" "an_enum"
620 check_var_with_bool_opt "deref_refs" "a_string"
621 check_var_with_bool_opt "deref_refs" "a_binary_string"
622 check_var_with_bool_opt "deref_refs" "a_binary_string_array"
623 check_var_with_bool_opt "deref_refs" "a_big_string"
624 check_var_with_bool_opt "deref_refs" "an_array"
625 check_var_with_bool_opt "deref_refs" "an_array_with_repetition"
626 check_var_with_bool_opt "deref_refs" "a_symbol_pointer"
627
628 if { $current_lang == "c++" } {
629 check_var_with_bool_opt "deref_refs" "a_point_t_ref"
630 check_var_with_bool_opt "deref_refs" "a_base_ref" \
631 "${default_ref_regexp}: \\{_vptr\[.\$\]Base = ${default_pointer_regexp} <vtable for Deriv\\+$decimal>, a = 42, static a_static_member = 2019\\}"
632 }
633 }
634
635 # Test the actual_objects option for gdb.Value.format_string.
636 proc_with_prefix test_actual_objects {} {
637 global current_lang
638
639 check_var_with_bool_opt "actual_objects" "a_point_t"
640 check_var_with_bool_opt "actual_objects" "a_point_t_pointer"
641 check_var_with_bool_opt "actual_objects" "another_point"
642 check_var_with_bool_opt "actual_objects" "a_struct_with_union"
643 check_var_with_bool_opt "actual_objects" "an_enum"
644 check_var_with_bool_opt "actual_objects" "a_string"
645 check_var_with_bool_opt "actual_objects" "a_binary_string"
646 check_var_with_bool_opt "actual_objects" "a_binary_string_array"
647 check_var_with_bool_opt "actual_objects" "a_big_string"
648 check_var_with_bool_opt "actual_objects" "an_array"
649 check_var_with_bool_opt "actual_objects" "an_array_with_repetition"
650 check_var_with_bool_opt "actual_objects" "a_symbol_pointer"
651
652 if { $current_lang == "c++" } {
653 # Nothing changes in all of the C++ tests because deref_refs is not
654 # True.
655 check_var_with_bool_opt "actual_objects" "a_point_t_ref"
656 check_var_with_bool_opt "actual_objects" "a_base_ref"
657
658 with_temp_option "set print object on" "set print object off" {
659 check_var_with_no_opts "a_point_t_ref"
660 check_var_with_bool_opt "actual_objects" "a_point_t_ref"
661
662 check_var_with_no_opts "a_base_ref"
663 check_var_with_bool_opt "actual_objects" "a_base_ref"
664 }
665 }
666 }
667
668 # Test the static_members option for gdb.Value.format_string.
669 proc_with_prefix test_static_members {} {
670 global current_lang
671
672 check_var_with_bool_opt "static_members" "a_point_t"
673 check_var_with_bool_opt "static_members" "a_point_t_pointer"
674 check_var_with_bool_opt "static_members" "another_point"
675 check_var_with_bool_opt "static_members" "a_struct_with_union"
676 check_var_with_bool_opt "static_members" "an_enum"
677 check_var_with_bool_opt "static_members" "a_string"
678 check_var_with_bool_opt "static_members" "a_binary_string"
679 check_var_with_bool_opt "static_members" "a_binary_string_array"
680 check_var_with_bool_opt "static_members" "a_big_string"
681 check_var_with_bool_opt "static_members" "an_array"
682 check_var_with_bool_opt "static_members" "an_array_with_repetition"
683 check_var_with_bool_opt "static_members" "a_symbol_pointer"
684
685 if { $current_lang == "c++" } {
686 # Nothing changes in all of the C++ tests because deref_refs is not
687 # True.
688 check_var_with_bool_opt "static_members" "a_point_t_ref"
689 check_var_with_bool_opt "static_members" "a_base_ref"
690
691 with_temp_option \
692 "set print static-members off" \
693 "set print static-members on" {
694 check_var_with_no_opts "a_point_t_ref"
695 check_var_with_bool_opt "static_members" "a_point_t_ref"
696
697 check_var_with_no_opts "a_base_ref"
698 check_var_with_bool_opt "static_members" "a_base_ref"
699 }
700 }
701 }
702
703 # Test the max_elements option for gdb.Value.format_string.
704 # SETTING is the print setting to verify, either "elements"
705 # or "characters". UNLIMITED is the numeric value to use
706 # for the "unlimited" setting.
707
708 proc test_max_string_one { setting unlimited } {
709 global current_lang
710 global default_pointer_regexp
711
712 # 200 is the default maximum number of elements, so setting it should
713 # not change the output.
714 set opts "max_$setting=200"
715 with_test_prefix $opts {
716 check_format_string "a_point_t" $opts
717 check_format_string "a_point_t_pointer" $opts
718 check_format_string "another_point" $opts
719 check_format_string "a_struct_with_union" $opts
720 check_format_string "an_enum" $opts
721 check_format_string "a_string" $opts
722 check_format_string "a_binary_string" $opts
723 check_format_string "a_binary_string_array" $opts
724 check_format_string "a_big_string" $opts
725 if { $setting == "elements" } {
726 check_format_string "an_array" $opts
727 check_format_string "an_array_with_repetition" $opts
728 }
729 check_format_string "a_symbol_pointer" $opts
730
731 if { $current_lang == "c++" } {
732 check_format_string "a_point_t_ref" $opts
733 check_format_string "a_base_ref" $opts
734 }
735 }
736
737 set opts "max_$setting=3"
738 with_test_prefix $opts {
739 check_format_string "a_point_t" $opts
740 check_format_string "a_point_t_pointer" $opts
741 check_format_string "another_point" $opts
742 check_format_string "a_struct_with_union" $opts
743 check_format_string "an_enum" $opts
744 check_format_string "a_string" $opts \
745 "${default_pointer_regexp} \"hel\"..."
746 check_format_string "a_binary_string" $opts \
747 "${default_pointer_regexp} \"hel\"..."
748 # This will print four characters instead of three, see
749 # <https://sourceware.org/bugzilla/show_bug.cgi?id=24331>.
750 check_format_string "a_binary_string_array" $opts \
751 "\"hel\"..."
752 check_format_string "a_big_string" $opts \
753 [get_cut_big_string 3]
754 if { $setting == "elements"} {
755 check_format_string "an_array" $opts
756 check_format_string "an_array_with_repetition" $opts \
757 "\\{1, 3 <repeats 12 times>...\\}"
758 }
759 check_format_string "a_symbol_pointer" $opts
760
761 if { $current_lang == "c++" } {
762 check_format_string "a_point_t_ref" $opts
763 check_format_string "a_base_ref" $opts
764 }
765 }
766
767 # Both 1,000 (we don't have that many elements) and unlimited should
768 # mean no truncation.
769 foreach opts [list "max_$setting=1000" "max_$setting=$unlimited"] {
770 with_test_prefix $opts {
771 check_format_string "a_point_t" $opts
772 check_format_string "a_point_t_pointer" $opts
773 check_format_string "another_point" $opts
774 check_format_string "a_struct_with_union" $opts
775 check_format_string "an_enum" $opts
776 check_format_string "a_string" $opts
777 check_format_string "a_binary_string" $opts
778 check_format_string "a_binary_string_array" $opts
779 check_format_string "a_big_string" $opts \
780 [get_cut_big_string 1000]
781 if { $setting == "elements"} {
782 check_format_string "an_array" $opts
783 check_format_string "an_array_with_repetition" $opts
784 }
785 check_format_string "a_symbol_pointer" $opts
786
787 if { $current_lang == "c++" } {
788 check_format_string "a_point_t_ref" $opts
789 check_format_string "a_base_ref" $opts
790 }
791 }
792 }
793
794 with_temp_option "set print $setting 4" "set print $setting 200" {
795 check_format_string "a_string" "" \
796 "${default_pointer_regexp} \"hell\"..."
797 check_format_string "a_binary_string" "" \
798 "${default_pointer_regexp} \"hell\"..."
799 check_format_string "a_binary_string_array" "" \
800 "\"hell\"..."
801 if { $setting == "elements"} {
802 check_format_string "an_array_with_repetition" "" \
803 "\\{1, 3 <repeats 12 times>...\\}"
804 }
805 }
806 }
807
808 proc_with_prefix test_max_string {} {
809 foreach_with_prefix setting { "elements" "characters" } {
810 test_max_string_one $setting \
811 [string map {elements 0 characters 4294967295} $setting]
812 }
813 }
814
815 # Test the max_depth option for gdb.Value.format_string.
816 proc_with_prefix test_max_depth {} {
817 set opts "max_depth=-1"
818 with_test_prefix $opts {
819 check_format_string "a_struct_with_union" $opts
820 check_format_string "a_point_t" $opts "Pretty Point \\(42, 12\\)"
821 check_format_string "a_struct_with_point" $opts
822 }
823 set opts "max_depth=0"
824 with_test_prefix $opts {
825 check_format_string "a_struct_with_union" $opts "\\{\.\.\.\\}"
826 check_format_string "a_point_t" $opts "Pretty Point \\(42, 12\\)"
827 check_format_string "a_struct_with_point" $opts "\\{\.\.\.\\}"
828 }
829 set opts "max_depth=1"
830 with_test_prefix $opts {
831 check_format_string "a_struct_with_union" $opts "\\{the_union = \\{\.\.\.\\}\\}"
832 check_format_string "a_point_t" $opts "Pretty Point \\(42, 12\\)"
833 check_format_string "a_struct_with_point" $opts
834 }
835 set opts "max_depth=2"
836 with_test_prefix $opts {
837 check_format_string "a_struct_with_union" $opts
838 check_format_string "a_point_t" $opts "Pretty Point \\(42, 12\\)"
839 check_format_string "a_struct_with_point" $opts
840 }
841 }
842
843 # Test the repeat_threshold option for gdb.Value.format_string.
844 proc_with_prefix test_repeat_threshold {} {
845 global current_lang
846 global default_pointer_regexp
847
848 # 10 is the default threshold for repeated items, so setting it should
849 # not change the output.
850 set opts "repeat_threshold=10"
851 with_test_prefix $opts {
852 check_format_string "a_point_t" $opts
853 check_format_string "a_point_t_pointer" $opts
854 check_format_string "another_point" $opts
855 check_format_string "a_struct_with_union" $opts
856 check_format_string "an_enum" $opts
857 check_format_string "a_string" $opts
858 check_format_string "a_binary_string" $opts
859 check_format_string "a_binary_string_array" $opts
860 check_format_string "a_big_string" $opts
861 check_format_string "an_array" $opts
862 check_format_string "an_array_with_repetition" $opts
863 check_format_string "a_symbol_pointer" $opts
864
865 if { $current_lang == "c++" } {
866 check_format_string "a_point_t_ref" $opts
867 check_format_string "a_base_ref" $opts
868 }
869 }
870
871 set opts "repeat_threshold=1"
872 with_test_prefix $opts {
873 check_format_string "a_point_t" $opts
874 check_format_string "a_point_t_pointer" $opts
875 check_format_string "another_point" $opts
876 check_format_string "a_struct_with_union" $opts
877 check_format_string "an_enum" $opts
878 check_format_string "a_string" $opts \
879 "${default_pointer_regexp} \"he\", 'l' <repeats 2 times>, \"o world\""
880 check_format_string "a_binary_string" $opts \
881 "${default_pointer_regexp} \"he\", 'l' <repeats 2 times>, \"o\""
882 check_format_string "a_binary_string_array" $opts \
883 "\"he\", 'l' <repeats 2 times>, \"o\\\\000world\""
884 check_format_string "a_big_string" $opts
885 check_format_string "an_array" $opts
886 check_format_string "an_array_with_repetition" $opts \
887 "\\{1, 3 <repeats 12 times>, 5 <repeats 3 times>\\}"
888
889 check_format_string "a_symbol_pointer" $opts
890
891 if { $current_lang == "c++" } {
892 check_format_string "a_point_t_ref" $opts
893 check_format_string "a_base_ref" $opts
894 }
895 }
896
897 set opts "repeat_threshold=3"
898 with_test_prefix $opts {
899 check_format_string "a_point_t" $opts
900 check_format_string "a_point_t_pointer" $opts
901 check_format_string "another_point" $opts
902 check_format_string "a_struct_with_union" $opts
903 check_format_string "an_enum" $opts
904 check_format_string "a_string" $opts
905 check_format_string "a_binary_string" $opts
906 check_format_string "a_binary_string_array" $opts
907 check_format_string "a_big_string" $opts
908 check_format_string "an_array" $opts
909 check_format_string "an_array_with_repetition" $opts
910 check_format_string "a_symbol_pointer" $opts
911
912 if { $current_lang == "c++" } {
913 check_format_string "a_point_t_ref" $opts
914 check_format_string "a_base_ref" $opts
915 }
916 }
917
918 # Both 100 (we don't have that many repeated elements) and 0 (unlimited)
919 # should mean no truncation.
920 foreach opts { "repeat_threshold=100" "repeat_threshold=0" } {
921 with_test_prefix $opts {
922 check_format_string "a_point_t" $opts
923 check_format_string "a_point_t_pointer" $opts
924 check_format_string "another_point" $opts
925 check_format_string "a_struct_with_union" $opts
926 check_format_string "an_enum" $opts
927 check_format_string "a_string" $opts
928 check_format_string "a_binary_string" $opts
929 check_format_string "a_binary_string_array" $opts
930 check_format_string "a_big_string" $opts
931 check_format_string "an_array" $opts
932 check_format_string "an_array_with_repetition" $opts \
933 "\\{1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 5, 5\\}"
934 check_format_string "a_symbol_pointer" $opts
935
936 if { $current_lang == "c++" } {
937 check_format_string "a_point_t_ref" $opts
938 check_format_string "a_base_ref" $opts
939 }
940 }
941 }
942
943 with_temp_option "set print repeats 1" "set print repeats 10" {
944 check_format_string "an_array_with_repetition" "" \
945 "\\{1, 3 <repeats 12 times>, 5 <repeats 3 times>\\}"
946 }
947 }
948
949 # Test the format option for gdb.Value.format_string.
950 proc_with_prefix test_format {} {
951 global current_lang
952 global default_pointer_regexp
953
954 # Hexadecimal.
955 set opts "format='x'"
956 with_test_prefix $opts {
957 gdb_test "python print (gdb.Value (42).format_string (${opts}))" \
958 "0x2a" \
959 "42 with option ${opts}"
960
961 check_format_string "a_point_t" $opts \
962 "Pretty Point \\(0x2a, 0xc\\)"
963 check_format_string "a_point_t_pointer" $opts
964 check_format_string "another_point" $opts \
965 "Pretty Point \\(0x7b, 0x1c8\\)"
966 check_format_string "a_struct_with_union" $opts \
967 "\\{the_union = \\{an_int = 0x2a2a2a2a, a_char = 0x2a\\}\\}"
968 check_format_string "an_enum" $opts \
969 "0x1"
970 check_format_string "a_string" $opts \
971 $default_pointer_regexp
972 check_format_string "a_binary_string" $opts \
973 $default_pointer_regexp
974 check_format_string "a_binary_string_array" $opts \
975 "\\{0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x0, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x0\\}"
976 check_format_string "a_big_string" $opts \
977 "\\{0x41, 0x42, 0x43, 0x44, 0x45, \[, x0-9a-f\]+\.\.\.\\}"
978 check_format_string "an_array" $opts \
979 "\\{0x2, 0x3, 0x5\\}"
980 check_format_string "an_array_with_repetition" $opts \
981 "\\{0x1, 0x3 <repeats 12 times>, 0x5, 0x5, 0x5\\}"
982 check_format_string "a_symbol_pointer" $opts \
983 $default_pointer_regexp
984
985 if { $current_lang == "c++" } {
986 check_format_string "a_point_t_ref" $opts \
987 "Pretty Point \\(0x2a, 0xc\\)"
988 check_format_string "a_base_ref" $opts
989 }
990 }
991
992 # Binary.
993 set opts "format='t'"
994 with_test_prefix $opts {
995 set binary_pointer_regexp "\[0-1\]+"
996 gdb_test "python print (gdb.Value (42).format_string (${opts}))" \
997 "101010" \
998 "42 with option ${opts}"
999
1000 check_format_string "a_point_t" $opts \
1001 "Pretty Point \\(101010, 1100\\)"
1002 check_format_string "a_point_t_pointer" $opts \
1003 $binary_pointer_regexp
1004 check_format_string "another_point" $opts \
1005 "Pretty Point \\(1111011, 111001000\\)"
1006 check_format_string "a_struct_with_union" $opts \
1007 "\\{the_union = \\{an_int = 101010001010100010101000101010, a_char = 101010\\}\\}"
1008 check_format_string "an_enum" $opts \
1009 "1"
1010 check_format_string "a_string" $opts \
1011 $binary_pointer_regexp
1012 check_format_string "a_binary_string" $opts \
1013 $binary_pointer_regexp
1014 check_format_string "a_binary_string_array" $opts \
1015 "\\{1101000, 1100101, 1101100, 1101100, 1101111, 0, 1110111, 1101111, 1110010, 1101100, 1100100, 0\\}"
1016 check_format_string "a_big_string" $opts \
1017 "\\{1000001, 1000010, 1000011, 1000100, 1000101, \[, 0-1\]+\.\.\.\\}"
1018 check_format_string "an_array" $opts \
1019 "\\{10, 11, 101\\}"
1020 check_format_string "an_array_with_repetition" $opts \
1021 "\\{1, 11 <repeats 12 times>, 101, 101, 101\\}"
1022 check_format_string "a_symbol_pointer" $opts \
1023 $binary_pointer_regexp
1024
1025 if { $current_lang == "c++" } {
1026 check_format_string "a_point_t_ref" $opts \
1027 "Pretty Point \\(101010, 1100\\)"
1028 check_format_string "a_base_ref" $opts
1029 }
1030 }
1031
1032 # Decimal.
1033 set opts "format='d'"
1034 with_test_prefix $opts {
1035 set decimal_pointer_regexp "\[0-9\]+"
1036 gdb_test "python print (gdb.Value (0x2a).format_string (${opts}))" \
1037 "42" \
1038 "0x2a with option ${opts}"
1039
1040 check_format_string "a_point_t" $opts
1041 check_format_string "a_point_t_pointer" $opts \
1042 $decimal_pointer_regexp
1043 check_format_string "another_point" $opts
1044 check_format_string "a_struct_with_union" $opts \
1045 "\\{the_union = \\{an_int = 707406378, a_char = 42\\}\\}"
1046 check_format_string "an_enum" $opts \
1047 "1"
1048 check_format_string "a_string" $opts \
1049 $decimal_pointer_regexp
1050 check_format_string "a_binary_string" $opts \
1051 $decimal_pointer_regexp
1052 check_format_string "a_binary_string_array" $opts \
1053 "\\{104, 101, 108, 108, 111, 0, 119, 111, 114, 108, 100, 0\\}"
1054 check_format_string "a_big_string" $opts \
1055 "\\{65, 66, 67, 68, 69, \[, 0-9\]+\.\.\.\\}"
1056 check_format_string "an_array" $opts
1057 check_format_string "an_array_with_repetition" $opts
1058 check_format_string "a_symbol_pointer" $opts \
1059 $decimal_pointer_regexp
1060
1061 if { $current_lang == "c++" } {
1062 check_format_string "a_point_t_ref" $opts
1063 check_format_string "a_base_ref" $opts
1064 }
1065 }
1066 }
1067
1068 # Test mixing options.
1069 proc_with_prefix test_mixed {} {
1070 global current_lang
1071 global default_ref_regexp
1072 global default_pointer_regexp
1073 global decimal
1074
1075 check_format_string "a_point_t" \
1076 "raw=True, format='x'" \
1077 "\\{x = 0x2a, y = 0xc\\}"
1078
1079 check_format_string "an_array" \
1080 "array_indexes=True, pretty_arrays=True" \
1081 "\\{\[\r\n\]+ \\\[0\\\] = 2,\[\r\n\]+ \\\[1\\\] = 3,\[\r\n\]+ \\\[2\\\] = 5\[\r\n\]+\\}"
1082
1083 check_format_string "a_struct_with_union" \
1084 "pretty_structs=True, unions=False" \
1085 "\\{\[\r\n\]+ the_union = \\{\.\.\.\\}\[\r\n\]+\\}"
1086
1087 check_format_string "a_symbol_pointer" \
1088 "symbols=False, format='d'" \
1089 "\[0-9\]+"
1090
1091 if { $current_lang == "c++" } {
1092 check_format_string "a_point_t_ref" \
1093 "deref_refs=True, actual_objects=True, raw=True" \
1094 "${default_ref_regexp}: \\{x = 42, y = 12\\}"
1095
1096 check_format_string "a_base_ref" \
1097 "deref_refs=True, static_members=False" \
1098 "${default_ref_regexp}: \\{_vptr\[.\$\]Base = ${default_pointer_regexp} <vtable for Deriv\\+$decimal>, a = 42\\}"
1099 }
1100 }
1101
1102 # Test passing invalid arguments to gdb.Value.format_string.
1103 proc_with_prefix test_invalid_args {} {
1104 check_format_string \
1105 "a_point_t" \
1106 "12" \
1107 "TypeError: format_string\\(\\) takes 0 positional arguments but 1 were given.*"
1108
1109 check_format_string \
1110 "a_point_t" \
1111 "invalid=True" \
1112 "TypeError: 'invalid' is an invalid keyword argument for this function.*"
1113
1114 check_format_string \
1115 "a_point_t" \
1116 "raw='hello'" \
1117 "TypeError: argument 1 must be bool, not str.*"
1118
1119 check_format_string \
1120 "a_point_t" \
1121 "format='xd'" \
1122 "ValueError: a single character is required.*"
1123 }
1124
1125 # Check the styling argument to format_string. This function needs to
1126 # be called with TERM set such that styling can be applied.
1127 proc test_styling {} {
1128 gdb_test "python print(gdb.parse_and_eval(\"a_point_t\").format_string(styling=True, raw=True))" \
1129 "{[style x variable] = 42, [style y variable] = 12}"
1130 }
1131
1132 # Test the gdb.print_options API.
1133 proc test_print_options {} {
1134 gdb_test_no_output "set print elements 500"
1135 gdb_test "python print(gdb.print_options()\['max_elements'\])" "500" \
1136 "examine max elements"
1137 gdb_test "python print('format' in gdb.print_options())" "False" \
1138 "examine format"
1139
1140 check_format_string "a_point_t" "format='t', nibbles=True" \
1141 "Pretty Point \\(0010.1010, 1100\\)" \
1142 "print in binary to fetch options"
1143 gdb_test "python print(saved_options\['format'\] == 't')" "True" \
1144 "format was set"
1145 gdb_test "python print(saved_options\['nibbles'\])" "True" \
1146 "nibbles was set"
1147
1148 check_format_string "a_point_t" "summary=True" \
1149 "No Data" \
1150 "print in summary mode"
1151 gdb_test "python print(saved_options\['summary'\])" "True" \
1152 "summary was set"
1153 }
1154
1155 # Run all the tests in common for both C and C++.
1156 proc_with_prefix test_all_common {} {
1157 # No options.
1158 test_no_opts
1159 # Single options set to True/False.
1160 test_raw
1161 test_pretty_arrays
1162 test_pretty_structs
1163 test_array_indexes
1164 test_symbols
1165 test_unions
1166 test_address
1167 test_nibbles
1168 test_deref_refs
1169 test_actual_objects
1170 test_static_members
1171 test_max_string
1172 test_max_depth
1173 test_repeat_threshold
1174 test_format
1175 # Multiple options mixed together.
1176 test_mixed
1177 # Various error conditions.
1178 test_invalid_args
1179 test_print_options
1180 }
1181
1182 # The current language ("c" or "c++" while running tests).
1183 set current_lang ""
1184
1185 with_test_prefix "format_string" {
1186 # Perform C Tests.
1187 if { [build_inferior "${binfile}" "c"] == 0 } {
1188 with_test_prefix "lang_c" {
1189 save_vars { env(TERM) } {
1190 # We run all of these tests in an environment where styling
1191 # could work, but we only expect the final call to
1192 # test_styling to actually produce any styled output.
1193 setenv TERM ansi
1194 set current_lang "c"
1195 prepare_gdb "${binfile}"
1196 test_all_common
1197 test_styling
1198 }
1199 }
1200 }
1201
1202 # Perform C++ Tests.
1203 if { [build_inferior "${binfile}-cxx" "c++"] == 0 } {
1204 with_test_prefix "lang_cpp" {
1205 set current_lang "c++"
1206 prepare_gdb "${binfile}-cxx"
1207 test_all_common
1208 }
1209 }
1210 }