1 # Copyright (C) 2019-2020 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 tests GDB's python pretty printing of nested map like
17 # structures using structures as keys and values, it then tests how
18 # 'set print max-depth' affects this printing.
20 load_lib gdb-python.exp
24 # Start with a fresh gdb.
28 # Skip all tests if Python scripting is not enabled.
29 if { [skip_python_tests] } { continue }
33 if { [prepare_for_testing "failed to prepare" $testfile $srcfile {debug}] } {
37 if ![runto_main ] then {
41 gdb_breakpoint [gdb_get_line_number "Break here"]
42 gdb_continue_to_breakpoint "run to testing point" ".*Break here.*"
44 set remote_python_file [gdb_remote_download host \
45 ${srcdir}/${subdir}/${testfile}.py]
46 gdb_test_no_output "source ${remote_python_file}" "load python file"
48 # Test printing with 'set print pretty off'.
49 gdb_test_no_output "set print pretty off"
50 with_test_prefix "pretty=off" {
51 gdb_print_expr_at_depths "*m1" \
54 "\{\\\[\{a = 3, b = 4\}\\\] = \{\\.\\.\\.\}, \\\[\{a = 4, b = 5\}\\\] = \{\\.\\.\\.\}, \\\[\{a = 5, b = 6\}\\\] = \{\\.\\.\\.\}\}" \
55 "\{\\\[\{a = 3, b = 4\}\\\] = \{x = 0, y = 1, z = 2\}, \\\[\{a = 4, b = 5\}\\\] = \{x = 3, y = 4, z = 5\}, \\\[\{a = 5, b = 6\}\\\] = \{x = 6, y = 7, z = 8\}\}" \
58 gdb_print_expr_at_depths "*mm" \
61 "\{\\\[$hex \"m1\"\\\] = \{\\.\\.\\.\}, \\\[$hex \"m2\"\\\] = \{\\.\\.\\.\}\}" \
62 "\{\\\[$hex \"m1\"\\\] = \{\\\[\{a = 3, b = 4\}\\\] = \{\\.\\.\\.\}, \\\[\{a = 4, b = 5\}\\\] = \{\\.\\.\\.\}, \\\[\{a = 5, b = 6\}\\\] = \{\\.\\.\\.\}\}, \\\[$hex \"m2\"\\\] = \{\\\[\{a = 6, b = 7\}\\\] = \{\\.\\.\\.\}, \\\[\{a = 7, b = 8\}\\\] = \{\\.\\.\\.\}, \\\[\{a = 8, b = 9\}\\\] = \{\\.\\.\\.\}\}\}" \
63 "\{\\\[$hex \"m1\"\\\] = \{\\\[\{a = 3, b = 4\}\\\] = \{x = 0, y = 1, z = 2\}, \\\[\{a = 4, b = 5\}\\\] = \{x = 3, y = 4, z = 5\}, \\\[\{a = 5, b = 6\}\\\] = \{x = 6, y = 7, z = 8\}\}, \\\[$hex \"m2\"\\\] = \{\\\[\{a = 6, b = 7\}\\\] = \{x = 9, y = 0, z = 1\}, \\\[\{a = 7, b = 8\}\\\] = \{x = 2, y = 3, z = 4\}, \\\[\{a = 8, b = 9\}\\\] = \{x = 5, y = 6, z = 7\}\}\}" \
67 # Now again, but with 'set print pretty on'.
68 gdb_test_no_output "set print pretty on"
69 with_test_prefix "pretty=on" {
70 gdb_print_expr_at_depths "*m1" \
78 " \}\\\] = \{\\.\\.\\.\}," \
82 " \}\\\] = \{\\.\\.\\.\}," \
86 " \}\\\] = \{\\.\\.\\.\}" \
117 gdb_print_expr_at_depths "*mm" \
122 " \\\[$hex \"m1\"\\\] = \{\\.\\.\\.\}," \
123 " \\\[$hex \"m2\"\\\] = \{\\.\\.\\.\}" \
127 " \\\[$hex \"m1\"\\\] = \{" \
131 " \}\\\] = \{\\.\\.\\.\}," \
135 " \}\\\] = \{\\.\\.\\.\}," \
139 " \}\\\] = \{\\.\\.\\.\}" \
141 " \\\[$hex \"m2\"\\\] = \{" \
145 " \}\\\] = \{\\.\\.\\.\}," \
149 " \}\\\] = \{\\.\\.\\.\}," \
153 " \}\\\] = \{\\.\\.\\.\}" \
158 " \\\[$hex \"m1\"\\\] = \{" \
184 " \\\[$hex \"m2\"\\\] = \{" \
214 # Test printing with 'set print pretty off', but this time display a
215 # top level string (returned from the to_string method) as part of the
217 gdb_test_no_output "set mm->show_header=1"
218 gdb_test_no_output "set m1->show_header=1"
219 gdb_test_no_output "set m2->show_header=1"
220 with_test_prefix "headers=on" {
221 gdb_test_no_output "set print pretty off"
222 with_test_prefix "pretty=off" {
223 gdb_print_expr_at_depths "*m1" \
226 "pp_map = \{\\\[\{a = 3, b = 4\}\\\] = \{\\.\\.\\.\}, \\\[\{a = 4, b = 5\}\\\] = \{\\.\\.\\.\}, \\\[\{a = 5, b = 6\}\\\] = \{\\.\\.\\.\}\}" \
227 "pp_map = \{\\\[\{a = 3, b = 4\}\\\] = \{x = 0, y = 1, z = 2\}, \\\[\{a = 4, b = 5\}\\\] = \{x = 3, y = 4, z = 5\}, \\\[\{a = 5, b = 6\}\\\] = \{x = 6, y = 7, z = 8\}\}" \
230 gdb_print_expr_at_depths "*mm" \
233 "pp_map_map = \{\\\[$hex \"m1\"\\\] = \{\\.\\.\\.\}, \\\[$hex \"m2\"\\\] = \{\\.\\.\\.\}\}" \
234 "pp_map_map = \{\\\[$hex \"m1\"\\\] = pp_map = \{\\\[\{a = 3, b = 4\}\\\] = \{\\.\\.\\.\}, \\\[\{a = 4, b = 5\}\\\] = \{\\.\\.\\.\}, \\\[\{a = 5, b = 6\}\\\] = \{\\.\\.\\.\}\}, \\\[$hex \"m2\"\\\] = pp_map = \{\\\[\{a = 6, b = 7\}\\\] = \{\\.\\.\\.\}, \\\[\{a = 7, b = 8\}\\\] = \{\\.\\.\\.\}, \\\[\{a = 8, b = 9\}\\\] = \{\\.\\.\\.\}\}\}" \
235 "pp_map_map = \{\\\[$hex \"m1\"\\\] = pp_map = \{\\\[\{a = 3, b = 4\}\\\] = \{x = 0, y = 1, z = 2\}, \\\[\{a = 4, b = 5\}\\\] = \{x = 3, y = 4, z = 5\}, \\\[\{a = 5, b = 6\}\\\] = \{x = 6, y = 7, z = 8\}\}, \\\[$hex \"m2\"\\\] = pp_map = \{\\\[\{a = 6, b = 7\}\\\] = \{x = 9, y = 0, z = 1\}, \\\[\{a = 7, b = 8\}\\\] = \{x = 2, y = 3, z = 4\}, \\\[\{a = 8, b = 9\}\\\] = \{x = 5, y = 6, z = 7\}\}\}" \