gdb: Introduce 'print max-depth' feature
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / max-depth.exp
1 # Copyright 2019 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 # Tests GDB's handling of 'set print max-depth'.
17
18 # Only test C++ if we are able. Always use C.
19 if { [skip_cplus_tests] || [get_compiler_info "c++"] } {
20 set lang {c}
21 } else {
22 set lang {c c++}
23 }
24
25 foreach l $lang {
26 set dir "$l"
27 remote_exec host "rm -rf [standard_output_file ${dir}]"
28 remote_exec host "mkdir -p [standard_output_file ${dir}]"
29 }
30
31 proc compile_and_run_tests { lang } {
32 global testfile
33 global srcfile
34 global binfile
35 global hex
36
37 standard_testfile .c
38
39 # Create the additional flags.
40 set flags "debug"
41 lappend flags $lang
42
43 set dir "$lang"
44 set binfile [standard_output_file ${dir}/${testfile}]
45 if { [prepare_for_testing "failed to prepare" "${binfile}" "${srcfile}" "${flags}"] } {
46 return 0
47 }
48
49 # Advance to main.
50 if { ![runto_main] } then {
51 fail "can't run to main"
52 return 0
53 }
54
55 # The max-depth setting has no effect as the anonymous scopes are
56 # ignored and the members are aggregated into the parent scope.
57 gdb_print_expr_at_depths "s1" {"{...}" \
58 "{x = 0, y = 0}"\
59 "{x = 0, y = 0}"}
60
61 gdb_print_expr_at_depths "s2" {"{...}" \
62 "{x = 0, y = 0, {z = 0, a = 0}}" \
63 "{x = 0, y = 0, {z = 0, a = 0}}"}
64
65 gdb_print_expr_at_depths "s3" {"{...}" \
66 "{x = 0, y = 0, {z = 0, a = 0, {b = 0, c = 0}}}" \
67 "{x = 0, y = 0, {z = 0, a = 0, {b = 0, c = 0}}}" \
68 "{x = 0, y = 0, {z = 0, a = 0, {b = 0, c = 0}}}"}
69
70 # Increasing max-depth unfurls more of the object.
71 gdb_print_expr_at_depths "s4" {"{...}" \
72 "{x = 0, y = 0, l1 = {...}}" \
73 "{x = 0, y = 0, l1 = {x = 0, y = 0, l2 = {...}}}" \
74 "{x = 0, y = 0, l1 = {x = 0, y = 0, l2 = {x = 0, y = 0}}}"}
75
76 # Check handling of unions, in this case 'raw' is printed instead of
77 # just {...} as this is not useful.
78 gdb_print_expr_at_depths "s5" {"{...}" \
79 "{{raw = {...}, {x = 0, y = 0, z = 0}}}" \
80 "{{raw = \\{0, 0, 0\\}, {x = 0, y = 0, z = 0}}}"}
81
82 # Check handling of typedefs.
83 gdb_print_expr_at_depths "s6" {"{...}" \
84 "{{raw = {...}, {x = 0, y = 0, z = 0}}}" \
85 "{{raw = \\{0, 0, 0\\}, {x = 0, y = 0, z = 0}}}"}
86
87 # Multiple anonymous structures in parallel.
88 gdb_print_expr_at_depths "s7" {"{...}" \
89 "{{x = 0, y = 0}, {z = 0, a = 0}, {b = 0, c = 0}}" \
90 "{{x = 0, y = 0}, {z = 0, a = 0}, {b = 0, c = 0}}"}
91
92 # Flip flop between named and anonymous. Expected to unfurl to the
93 # first non-anonymous type.
94 gdb_print_expr_at_depths "s8" {"{...}" \
95 "{x = 0, y = 0, d1 = {...}}" \
96 "{x = 0, y = 0, d1 = {z = 0, a = 0, {b = 0, c = 0}}}"}
97
98 # Imbalanced tree, this will unfurl one size more than the other as
99 # one side has more anonymous levels.
100 gdb_print_expr_at_depths "s9" {"{...}" \
101 "{x = 0, y = 0, {k = 0, j = 0, d1 = {...}}, d2 = {...}}" \
102 "{x = 0, y = 0, {k = 0, j = 0, d1 = {z = 0, a = 0, {b = 0, c = 0}}}, d2 = {z = 0, a = 0, {b = 0, c = 0}}}"}
103
104 # Arrays are treated as an extra level, while scalars are not.
105 gdb_print_expr_at_depths "s10" {"{...}" \
106 "{x = {...}, y = 0, {k = {...}, j = 0, d1 = {...}}, d2 = {...}}" \
107 "{x = \\{0, 0, 0, 0, 0, 0, 0, 0, 0, 0\\}, y = 0, {k = \\{0, 0, 0, 0, 0, 0, 0, 0, 0, 0\\}, j = 0, d1 = {z = 0, a = 0, {b = {...}, c = 0}}}, d2 = {z = 0, a = 0, {b = {...}, c = 0}}}" \
108 "{x = \\{0, 0, 0, 0, 0, 0, 0, 0, 0, 0\\}, y = 0, {k = \\{0, 0, 0, 0, 0, 0, 0, 0, 0, 0\\}, j = 0, d1 = {z = 0, a = 0, {b = \\{0, 0, 0, 0, 0, 0, 0, 0, 0, 0\\}, c = 0}}}, d2 = {z = 0, a = 0, {b = \\{0, 0, 0, 0, 0, 0, 0, 0, 0, 0\\}, c = 0}}}"}
109
110 # Strings are treated as scalars.
111 gdb_print_expr_at_depths "s11" {"{...}" \
112 "{x = 0, s = \"\\\\000\\\\000\\\\000\\\\000\\\\000\\\\000\\\\000\\\\000\\\\000\", {z = 0, a = 0}}"}
113
114
115 if { $lang == "c++" } {
116 gdb_print_expr_at_depths "c1" {"{...}" \
117 "{c1 = 1}" }
118 gdb_print_expr_at_depths "c2" { "{...}" "{c2 = 2}" }
119 gdb_print_expr_at_depths "c3" { "{...}" \
120 "{<C2> = {...}, c3 = 3}" \
121 "{<C2> = {c2 = 2}, c3 = 3}" }
122 gdb_print_expr_at_depths "c4" { "{...}" "{c4 = 4}" }
123 gdb_print_expr_at_depths "c5" { "{...}" \
124 "{<C4> = {...}, c5 = 5}" \
125 "{<C4> = {c4 = 4}, c5 = 5}" }
126 gdb_print_expr_at_depths "c6" { "{...}" \
127 "{<C5> = {...}, c6 = 6}" \
128 "{<C5> = {<C4> = {...}, c5 = 5}, c6 = 6}" \
129 "{<C5> = {<C4> = {c4 = 4}, c5 = 5}, c6 = 6}" }
130 gdb_print_expr_at_depths "c7" { "{...}" \
131 "{<C1> = {...}, <C3> = {...}, <C6> = {...}, c7 = 7}" \
132 "{<C1> = {c1 = 1}, <C3> = {<C2> = {...}, c3 = 3}, <C6> = {<C5> = {...}, c6 = 6}, c7 = 7}" \
133 "{<C1> = {c1 = 1}, <C3> = {<C2> = {c2 = 2}, c3 = 3}, <C6> = {<C5> = {<C4> = {...}, c5 = 5}, c6 = 6}, c7 = 7}" \
134 "{<C1> = {c1 = 1}, <C3> = {<C2> = {c2 = 2}, c3 = 3}, <C6> = {<C5> = {<C4> = {c4 = 4}, c5 = 5}, c6 = 6}, c7 = 7}" }
135
136 gdb_print_expr_at_depths "v1" [list "{...}" "{v1 = 1}" ]
137 gdb_print_expr_at_depths "v2" [list "{...}" \
138 "{<V1> = {...}, _vptr.V2 = $hex <VTT for V2>, v2 = 2}" \
139 "{<V1> = {v1 = 1}, _vptr.V2 = $hex <VTT for V2>, v2 = 2}" ]
140 gdb_print_expr_at_depths "v3" [list "{...}" \
141 "{<V1> = {...}, _vptr.V3 = $hex <VTT for V3>, v3 = 3}" \
142 "{<V1> = {v1 = 1}, _vptr.V3 = $hex <VTT for V3>, v3 = 3}" ]
143 gdb_print_expr_at_depths "v4" [list "{...}" \
144 "{<V2> = {...}, _vptr.V4 = $hex <vtable for V4\[^>\]+>, v4 = 4}" \
145 "{<V2> = {<V1> = {...}, _vptr.V2 = $hex <VTT for V4>, v2 = 2}, _vptr.V4 = $hex <vtable for V4\[^>\]+>, v4 = 4}" \
146 "{<V2> = {<V1> = {v1 = 1}, _vptr.V2 = $hex <VTT for V4>, v2 = 2}, _vptr.V4 = $hex <vtable for V4\[^>\]+>, v4 = 4}" ]
147 gdb_print_expr_at_depths "v5" [list "{...}" \
148 "{<V2> = {...}, _vptr.V5 = $hex <vtable for V5\[^>\]+>, v5 = 1}" \
149 "{<V2> = {<V1> = {...}, _vptr.V2 = $hex <VTT for V5>, v2 = 2}, _vptr.V5 = $hex <vtable for V5\[^>\]+>, v5 = 1}" \
150 "{<V2> = {<V1> = {v1 = 1}, _vptr.V2 = $hex <VTT for V5>, v2 = 2}, _vptr.V5 = $hex <vtable for V5\[^>\]+>, v5 = 1}" ]
151 gdb_print_expr_at_depths "v6" [list "{...}" \
152 "{<V2> = {...}, <V3> = {...}, _vptr.V6 = $hex <vtable for V6\[^>\]+>, v6 = 1}" \
153 "{<V2> = {<V1> = {...}, _vptr.V2 = $hex <vtable for V6\[^>\]+>, v2 = 2}, <V3> = {_vptr.V3 = $hex <VTT for V6>, v3 = 3}, _vptr.V6 = $hex <vtable for V6\[^>\]+>, v6 = 1}" \
154 "{<V2> = {<V1> = {v1 = 1}, _vptr.V2 = $hex <vtable for V6\[^>\]+>, v2 = 2}, <V3> = {_vptr.V3 = $hex <VTT for V6>, v3 = 3}, _vptr.V6 = $hex <vtable for V6\[^>\]+>, v6 = 1}" ]
155 gdb_print_expr_at_depths "v7" [list "{...}" \
156 "{<V4> = {...}, <V5> = {...}, <V6> = {...}, _vptr.V7 = $hex <vtable for V7\[^>\]+>, v7 = 1}" \
157 "{<V4> = {<V2> = {...}, _vptr.V4 = $hex <vtable for V7\[^>\]+>, v4 = 4}, <V5> = {_vptr.V5 = $hex <vtable for V7\[^>\]+>, v5 = 1}, <V6> = {<V3> = {...}, _vptr.V6 = $hex <vtable for V7\[^>\]+>, v6 = 1}, _vptr.V7 = $hex <vtable for V7\[^>\]+>, v7 = 1}" \
158 "{<V4> = {<V2> = {<V1> = {...}, _vptr.V2 = $hex <vtable for V7\[^>\]+>, v2 = 2}, _vptr.V4 = $hex <vtable for V7\[^>\]+>, v4 = 4}, <V5> = {_vptr.V5 = $hex <vtable for V7\[^>\]+>, v5 = 1}, <V6> = {<V3> = {_vptr.V3 = $hex <VTT for V7>, v3 = 3}, _vptr.V6 = $hex <vtable for V7\[^>\]+>, v6 = 1}, _vptr.V7 = $hex <vtable for V7\[^>\]+>, v7 = 1}" \
159 "{<V4> = {<V2> = {<V1> = {v1 = 1}, _vptr.V2 = $hex <vtable for V7\[^>\]+>, v2 = 2}, _vptr.V4 = $hex <vtable for V7\[^>\]+>, v4 = 4}, <V5> = {_vptr.V5 = $hex <vtable for V7\[^>\]+>, v5 = 1}, <V6> = {<V3> = {_vptr.V3 = $hex <VTT for V7>, v3 = 3}, _vptr.V6 = $hex <vtable for V7\[^>\]+>, v6 = 1}, _vptr.V7 = $hex <vtable for V7\[^>\]+>, v7 = 1}" ]
160 }
161 }
162
163 foreach_with_prefix l $lang {
164 compile_and_run_tests $l
165 }
This page took 0.047838 seconds and 4 git commands to generate.