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