aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.python/py-nested-maps.exp
blob: 81dd99ca2c9600eb85e4985d91862c274ed623a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# Copyright (C) 2019 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# This tests GDB's python pretty printing of nested map like
# structures using structures as keys and values, it then tests how
# 'set print max-depth' affects this printing.

load_lib gdb-python.exp

standard_testfile

# Start with a fresh gdb.
gdb_exit
gdb_start

# Skip all tests if Python scripting is not enabled.
if { [skip_python_tests] } { continue }

standard_testfile

if { [prepare_for_testing "failed to prepare" $testfile $srcfile {debug}] } {
    return -1
}

if ![runto_main ] then {
    return -1
}

gdb_breakpoint [gdb_get_line_number "Break here"]
gdb_continue_to_breakpoint "run to testing point" ".*Break here.*"

set remote_python_file [gdb_remote_download host \
			    ${srcdir}/${subdir}/${testfile}.py]
gdb_test_no_output "source ${remote_python_file}" "load python file"

# Test printing with 'set print pretty off'.
gdb_test_no_output "set print pretty off"
with_test_prefix "pretty=off" {
    gdb_print_expr_at_depths "*m1" \
	[list \
	     "\{\\.\\.\\.\}" \
	     "\{\\\[\{a = 3, b = 4\}\\\] = \{\\.\\.\\.\}, \\\[\{a = 4, b = 5\}\\\] = \{\\.\\.\\.\}, \\\[\{a = 5, b = 6\}\\\] = \{\\.\\.\\.\}\}" \
	     "\{\\\[\{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\}\}" \
	    ]

    gdb_print_expr_at_depths "*mm" \
	[list \
	     "\{\\.\\.\\.\}" \
	     "\{\\\[$hex \"m1\"\\\] = \{\\.\\.\\.\}, \\\[$hex \"m2\"\\\] = \{\\.\\.\\.\}\}" \
	     "\{\\\[$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\}\\\] = \{\\.\\.\\.\}\}\}" \
	     "\{\\\[$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\}\}\}" \
	    ]
}

# Now again, but with 'set print pretty on'.
gdb_test_no_output "set print pretty on"
with_test_prefix "pretty=on" {
    gdb_print_expr_at_depths "*m1" \
	[list \
	     "\{\\.\\.\\.\}" \
	     [multi_line \
		  " = \{" \
		  "  \\\[\{" \
		  "    a = 3," \
		  "    b = 4" \
		  "  \}\\\] = \{\\.\\.\\.\}," \
		  "  \\\[\{" \
		  "    a = 4," \
		  "    b = 5" \
		  "  \}\\\] = \{\\.\\.\\.\}," \
		  "  \\\[\{" \
		  "    a = 5," \
		  "    b = 6" \
		  "  \}\\\] = \{\\.\\.\\.\}" \
		  "\}" ] \
	     [multi_line \
		  " = \{" \
		  "  \\\[\{" \
		  "    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" \
		  "  \}" \
		  "\}" ] \
	    ]

     gdb_print_expr_at_depths "*mm" \
	[list \
	     "\{\\.\\.\\.\}" \
	     [multi_line \
		  " = \{" \
		  "  \\\[$hex \"m1\"\\\] = \{\\.\\.\\.\}," \
		  "  \\\[$hex \"m2\"\\\] = \{\\.\\.\\.\}" \
		  "\}" ] \
	     [multi_line \
		  " = \{" \
		  "  \\\[$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" \
		  "    \}\\\] = \{\\.\\.\\.\}" \
		  "  \}" \
		  "\}" ] \
	     [multi_line \
		  " = \{" \
		  "  \\\[$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" \
		  "    \}" \
		  "  \}" \
		  "\}" ] \
	    ]
}

# Test printing with 'set print pretty off', but this time display a
# top level string (returned from the to_string method) as part of the
# printed value.
gdb_test_no_output "set mm->show_header=1"
gdb_test_no_output "set m1->show_header=1"
gdb_test_no_output "set m2->show_header=1"
with_test_prefix "headers=on" {
    gdb_test_no_output "set print pretty off"
    with_test_prefix "pretty=off" {
	gdb_print_expr_at_depths "*m1" \
	    [list \
		 "\{\\.\\.\\.\}" \
		 "pp_map = \{\\\[\{a = 3, b = 4\}\\\] = \{\\.\\.\\.\}, \\\[\{a = 4, b = 5\}\\\] = \{\\.\\.\\.\}, \\\[\{a = 5, b = 6\}\\\] = \{\\.\\.\\.\}\}" \
		 "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\}\}" \
		]

	gdb_print_expr_at_depths "*mm" \
	    [list \
		 "\{\\.\\.\\.\}" \
		 "pp_map_map = \{\\\[$hex \"m1\"\\\] = \{\\.\\.\\.\}, \\\[$hex \"m2\"\\\] = \{\\.\\.\\.\}\}" \
		 "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\}\\\] = \{\\.\\.\\.\}\}\}" \
		 "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\}\}\}" \
		]
    }
}