Commit | Line | Data |
---|---|---|
b811d2c2 | 1 | # Copyright (C) 2019-2020 Free Software Foundation, Inc. |
2e62ab40 AB |
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 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. | |
19 | ||
20 | load_lib gdb-python.exp | |
21 | ||
22 | standard_testfile | |
23 | ||
24 | # Start with a fresh gdb. | |
25 | gdb_exit | |
26 | gdb_start | |
27 | ||
28 | # Skip all tests if Python scripting is not enabled. | |
29 | if { [skip_python_tests] } { continue } | |
30 | ||
31 | standard_testfile | |
32 | ||
33 | if { [prepare_for_testing "failed to prepare" $testfile $srcfile {debug}] } { | |
34 | return -1 | |
35 | } | |
36 | ||
37 | if ![runto_main ] then { | |
38 | return -1 | |
39 | } | |
40 | ||
41 | gdb_breakpoint [gdb_get_line_number "Break here"] | |
42 | gdb_continue_to_breakpoint "run to testing point" ".*Break here.*" | |
43 | ||
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" | |
47 | ||
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" \ | |
52 | [list \ | |
53 | "\{\\.\\.\\.\}" \ | |
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\}\}" \ | |
56 | ] | |
57 | ||
58 | gdb_print_expr_at_depths "*mm" \ | |
59 | [list \ | |
60 | "\{\\.\\.\\.\}" \ | |
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\}\}\}" \ | |
64 | ] | |
65 | } | |
66 | ||
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" \ | |
71 | [list \ | |
72 | "\{\\.\\.\\.\}" \ | |
73 | [multi_line \ | |
74 | " = \{" \ | |
75 | " \\\[\{" \ | |
76 | " a = 3," \ | |
77 | " b = 4" \ | |
78 | " \}\\\] = \{\\.\\.\\.\}," \ | |
79 | " \\\[\{" \ | |
80 | " a = 4," \ | |
81 | " b = 5" \ | |
82 | " \}\\\] = \{\\.\\.\\.\}," \ | |
83 | " \\\[\{" \ | |
84 | " a = 5," \ | |
85 | " b = 6" \ | |
86 | " \}\\\] = \{\\.\\.\\.\}" \ | |
87 | "\}" ] \ | |
88 | [multi_line \ | |
89 | " = \{" \ | |
90 | " \\\[\{" \ | |
91 | " a = 3," \ | |
92 | " b = 4" \ | |
93 | " \}\\\] = \{" \ | |
94 | " x = 0," \ | |
95 | " y = 1," \ | |
96 | " z = 2" \ | |
97 | " \}," \ | |
98 | " \\\[\{" \ | |
99 | " a = 4," \ | |
100 | " b = 5" \ | |
101 | " \}\\\] = \{" \ | |
102 | " x = 3," \ | |
103 | " y = 4," \ | |
104 | " z = 5" \ | |
105 | " \}," \ | |
106 | " \\\[\{" \ | |
107 | " a = 5," \ | |
108 | " b = 6" \ | |
109 | " \}\\\] = \{" \ | |
110 | " x = 6," \ | |
111 | " y = 7," \ | |
112 | " z = 8" \ | |
113 | " \}" \ | |
114 | "\}" ] \ | |
115 | ] | |
116 | ||
117 | gdb_print_expr_at_depths "*mm" \ | |
118 | [list \ | |
119 | "\{\\.\\.\\.\}" \ | |
120 | [multi_line \ | |
121 | " = \{" \ | |
122 | " \\\[$hex \"m1\"\\\] = \{\\.\\.\\.\}," \ | |
123 | " \\\[$hex \"m2\"\\\] = \{\\.\\.\\.\}" \ | |
124 | "\}" ] \ | |
125 | [multi_line \ | |
126 | " = \{" \ | |
127 | " \\\[$hex \"m1\"\\\] = \{" \ | |
128 | " \\\[\{" \ | |
129 | " a = 3," \ | |
130 | " b = 4" \ | |
131 | " \}\\\] = \{\\.\\.\\.\}," \ | |
132 | " \\\[\{" \ | |
133 | " a = 4," \ | |
134 | " b = 5" \ | |
135 | " \}\\\] = \{\\.\\.\\.\}," \ | |
136 | " \\\[\{" \ | |
137 | " a = 5," \ | |
138 | " b = 6" \ | |
139 | " \}\\\] = \{\\.\\.\\.\}" \ | |
140 | " \}," \ | |
141 | " \\\[$hex \"m2\"\\\] = \{" \ | |
142 | " \\\[\{" \ | |
143 | " a = 6," \ | |
144 | " b = 7" \ | |
145 | " \}\\\] = \{\\.\\.\\.\}," \ | |
146 | " \\\[\{" \ | |
147 | " a = 7," \ | |
148 | " b = 8" \ | |
149 | " \}\\\] = \{\\.\\.\\.\}," \ | |
150 | " \\\[\{" \ | |
151 | " a = 8," \ | |
152 | " b = 9" \ | |
153 | " \}\\\] = \{\\.\\.\\.\}" \ | |
154 | " \}" \ | |
155 | "\}" ] \ | |
156 | [multi_line \ | |
157 | " = \{" \ | |
158 | " \\\[$hex \"m1\"\\\] = \{" \ | |
159 | " \\\[\{" \ | |
160 | " a = 3," \ | |
161 | " b = 4" \ | |
162 | " \}\\\] = \{" \ | |
163 | " x = 0," \ | |
164 | " y = 1," \ | |
165 | " z = 2" \ | |
166 | " \}," \ | |
167 | " \\\[\{" \ | |
168 | " a = 4," \ | |
169 | " b = 5" \ | |
170 | " \}\\\] = \{" \ | |
171 | " x = 3," \ | |
172 | " y = 4," \ | |
173 | " z = 5" \ | |
174 | " \}," \ | |
175 | " \\\[\{" \ | |
176 | " a = 5," \ | |
177 | " b = 6" \ | |
178 | " \}\\\] = \{" \ | |
179 | " x = 6," \ | |
180 | " y = 7," \ | |
181 | " z = 8" \ | |
182 | " \}" \ | |
183 | " \}," \ | |
184 | " \\\[$hex \"m2\"\\\] = \{" \ | |
185 | " \\\[\{" \ | |
186 | " a = 6," \ | |
187 | " b = 7" \ | |
188 | " \}\\\] = \{" \ | |
189 | " x = 9," \ | |
190 | " y = 0," \ | |
191 | " z = 1" \ | |
192 | " \}," \ | |
193 | " \\\[\{" \ | |
194 | " a = 7," \ | |
195 | " b = 8" \ | |
196 | " \}\\\] = \{" \ | |
197 | " x = 2," \ | |
198 | " y = 3," \ | |
199 | " z = 4" \ | |
200 | " \}," \ | |
201 | " \\\[\{" \ | |
202 | " a = 8," \ | |
203 | " b = 9" \ | |
204 | " \}\\\] = \{" \ | |
205 | " x = 5," \ | |
206 | " y = 6," \ | |
207 | " z = 7" \ | |
208 | " \}" \ | |
209 | " \}" \ | |
210 | "\}" ] \ | |
211 | ] | |
212 | } | |
213 | ||
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 | |
216 | # printed value. | |
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" \ | |
224 | [list \ | |
225 | "\{\\.\\.\\.\}" \ | |
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\}\}" \ | |
228 | ] | |
229 | ||
230 | gdb_print_expr_at_depths "*mm" \ | |
231 | [list \ | |
232 | "\{\\.\\.\\.\}" \ | |
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\}\}\}" \ | |
236 | ] | |
237 | } | |
238 | } |