Commit | Line | Data |
---|---|---|
2e62ab40 AB |
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 | |
669d0468 TV |
42 | if { "$lang" == "c++" } { |
43 | lappend flags "additional_flags=-std=c++11" | |
44 | } | |
2e62ab40 AB |
45 | |
46 | set dir "$lang" | |
47 | set binfile [standard_output_file ${dir}/${testfile}] | |
48 | if { [prepare_for_testing "failed to prepare" "${binfile}" "${srcfile}" "${flags}"] } { | |
49 | return 0 | |
50 | } | |
51 | ||
52 | # Advance to main. | |
53 | if { ![runto_main] } then { | |
54 | fail "can't run to main" | |
55 | return 0 | |
56 | } | |
57 | ||
58 | # The max-depth setting has no effect as the anonymous scopes are | |
59 | # ignored and the members are aggregated into the parent scope. | |
60 | gdb_print_expr_at_depths "s1" {"{...}" \ | |
61 | "{x = 0, y = 0}"\ | |
62 | "{x = 0, y = 0}"} | |
63 | ||
64 | gdb_print_expr_at_depths "s2" {"{...}" \ | |
65 | "{x = 0, y = 0, {z = 0, a = 0}}" \ | |
66 | "{x = 0, y = 0, {z = 0, a = 0}}"} | |
67 | ||
68 | gdb_print_expr_at_depths "s3" {"{...}" \ | |
69 | "{x = 0, y = 0, {z = 0, a = 0, {b = 0, c = 0}}}" \ | |
70 | "{x = 0, y = 0, {z = 0, a = 0, {b = 0, c = 0}}}" \ | |
71 | "{x = 0, y = 0, {z = 0, a = 0, {b = 0, c = 0}}}"} | |
72 | ||
73 | # Increasing max-depth unfurls more of the object. | |
74 | gdb_print_expr_at_depths "s4" {"{...}" \ | |
75 | "{x = 0, y = 0, l1 = {...}}" \ | |
76 | "{x = 0, y = 0, l1 = {x = 0, y = 0, l2 = {...}}}" \ | |
77 | "{x = 0, y = 0, l1 = {x = 0, y = 0, l2 = {x = 0, y = 0}}}"} | |
78 | ||
79 | # Check handling of unions, in this case 'raw' is printed instead of | |
80 | # just {...} as this is not useful. | |
81 | gdb_print_expr_at_depths "s5" {"{...}" \ | |
82 | "{{raw = {...}, {x = 0, y = 0, z = 0}}}" \ | |
83 | "{{raw = \\{0, 0, 0\\}, {x = 0, y = 0, z = 0}}}"} | |
84 | ||
85 | # Check handling of typedefs. | |
86 | gdb_print_expr_at_depths "s6" {"{...}" \ | |
87 | "{{raw = {...}, {x = 0, y = 0, z = 0}}}" \ | |
88 | "{{raw = \\{0, 0, 0\\}, {x = 0, y = 0, z = 0}}}"} | |
89 | ||
90 | # Multiple anonymous structures in parallel. | |
91 | gdb_print_expr_at_depths "s7" {"{...}" \ | |
92 | "{{x = 0, y = 0}, {z = 0, a = 0}, {b = 0, c = 0}}" \ | |
93 | "{{x = 0, y = 0}, {z = 0, a = 0}, {b = 0, c = 0}}"} | |
94 | ||
95 | # Flip flop between named and anonymous. Expected to unfurl to the | |
96 | # first non-anonymous type. | |
97 | gdb_print_expr_at_depths "s8" {"{...}" \ | |
98 | "{x = 0, y = 0, d1 = {...}}" \ | |
99 | "{x = 0, y = 0, d1 = {z = 0, a = 0, {b = 0, c = 0}}}"} | |
100 | ||
101 | # Imbalanced tree, this will unfurl one size more than the other as | |
102 | # one side has more anonymous levels. | |
103 | gdb_print_expr_at_depths "s9" {"{...}" \ | |
104 | "{x = 0, y = 0, {k = 0, j = 0, d1 = {...}}, d2 = {...}}" \ | |
105 | "{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}}}"} | |
106 | ||
107 | # Arrays are treated as an extra level, while scalars are not. | |
108 | gdb_print_expr_at_depths "s10" {"{...}" \ | |
109 | "{x = {...}, y = 0, {k = {...}, j = 0, d1 = {...}}, d2 = {...}}" \ | |
110 | "{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}}}" \ | |
111 | "{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}}}"} | |
112 | ||
113 | # Strings are treated as scalars. | |
114 | gdb_print_expr_at_depths "s11" {"{...}" \ | |
115 | "{x = 0, s = \"\\\\000\\\\000\\\\000\\\\000\\\\000\\\\000\\\\000\\\\000\\\\000\", {z = 0, a = 0}}"} | |
116 | ||
117 | ||
118 | if { $lang == "c++" } { | |
119 | gdb_print_expr_at_depths "c1" {"{...}" \ | |
120 | "{c1 = 1}" } | |
121 | gdb_print_expr_at_depths "c2" { "{...}" "{c2 = 2}" } | |
122 | gdb_print_expr_at_depths "c3" { "{...}" \ | |
123 | "{<C2> = {...}, c3 = 3}" \ | |
124 | "{<C2> = {c2 = 2}, c3 = 3}" } | |
125 | gdb_print_expr_at_depths "c4" { "{...}" "{c4 = 4}" } | |
126 | gdb_print_expr_at_depths "c5" { "{...}" \ | |
127 | "{<C4> = {...}, c5 = 5}" \ | |
128 | "{<C4> = {c4 = 4}, c5 = 5}" } | |
129 | gdb_print_expr_at_depths "c6" { "{...}" \ | |
130 | "{<C5> = {...}, c6 = 6}" \ | |
131 | "{<C5> = {<C4> = {...}, c5 = 5}, c6 = 6}" \ | |
132 | "{<C5> = {<C4> = {c4 = 4}, c5 = 5}, c6 = 6}" } | |
133 | gdb_print_expr_at_depths "c7" { "{...}" \ | |
134 | "{<C1> = {...}, <C3> = {...}, <C6> = {...}, c7 = 7}" \ | |
135 | "{<C1> = {c1 = 1}, <C3> = {<C2> = {...}, c3 = 3}, <C6> = {<C5> = {...}, c6 = 6}, c7 = 7}" \ | |
136 | "{<C1> = {c1 = 1}, <C3> = {<C2> = {c2 = 2}, c3 = 3}, <C6> = {<C5> = {<C4> = {...}, c5 = 5}, c6 = 6}, c7 = 7}" \ | |
137 | "{<C1> = {c1 = 1}, <C3> = {<C2> = {c2 = 2}, c3 = 3}, <C6> = {<C5> = {<C4> = {c4 = 4}, c5 = 5}, c6 = 6}, c7 = 7}" } | |
138 | ||
139 | gdb_print_expr_at_depths "v1" [list "{...}" "{v1 = 1}" ] | |
140 | gdb_print_expr_at_depths "v2" [list "{...}" \ | |
141 | "{<V1> = {...}, _vptr.V2 = $hex <VTT for V2>, v2 = 2}" \ | |
142 | "{<V1> = {v1 = 1}, _vptr.V2 = $hex <VTT for V2>, v2 = 2}" ] | |
143 | gdb_print_expr_at_depths "v3" [list "{...}" \ | |
144 | "{<V1> = {...}, _vptr.V3 = $hex <VTT for V3>, v3 = 3}" \ | |
145 | "{<V1> = {v1 = 1}, _vptr.V3 = $hex <VTT for V3>, v3 = 3}" ] | |
146 | gdb_print_expr_at_depths "v4" [list "{...}" \ | |
147 | "{<V2> = {...}, _vptr.V4 = $hex <vtable for V4\[^>\]+>, v4 = 4}" \ | |
148 | "{<V2> = {<V1> = {...}, _vptr.V2 = $hex <VTT for V4>, v2 = 2}, _vptr.V4 = $hex <vtable for V4\[^>\]+>, v4 = 4}" \ | |
149 | "{<V2> = {<V1> = {v1 = 1}, _vptr.V2 = $hex <VTT for V4>, v2 = 2}, _vptr.V4 = $hex <vtable for V4\[^>\]+>, v4 = 4}" ] | |
150 | gdb_print_expr_at_depths "v5" [list "{...}" \ | |
151 | "{<V2> = {...}, _vptr.V5 = $hex <vtable for V5\[^>\]+>, v5 = 1}" \ | |
152 | "{<V2> = {<V1> = {...}, _vptr.V2 = $hex <VTT for V5>, v2 = 2}, _vptr.V5 = $hex <vtable for V5\[^>\]+>, v5 = 1}" \ | |
153 | "{<V2> = {<V1> = {v1 = 1}, _vptr.V2 = $hex <VTT for V5>, v2 = 2}, _vptr.V5 = $hex <vtable for V5\[^>\]+>, v5 = 1}" ] | |
154 | gdb_print_expr_at_depths "v6" [list "{...}" \ | |
155 | "{<V2> = {...}, <V3> = {...}, _vptr.V6 = $hex <vtable for V6\[^>\]+>, v6 = 1}" \ | |
156 | "{<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}" \ | |
157 | "{<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}" ] | |
158 | gdb_print_expr_at_depths "v7" [list "{...}" \ | |
159 | "{<V4> = {...}, <V5> = {...}, <V6> = {...}, _vptr.V7 = $hex <vtable for V7\[^>\]+>, v7 = 1}" \ | |
160 | "{<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}" \ | |
161 | "{<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}" \ | |
162 | "{<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}" ] | |
163 | } | |
164 | } | |
165 | ||
166 | foreach_with_prefix l $lang { | |
167 | compile_and_run_tests $l | |
168 | } |