Commit | Line | Data |
---|---|---|
d4f3574e | 1 | # Tests for anonymous union support. |
0b302171 JB |
2 | # Copyright 1998-1999, 2003-2004, 2007-2012 Free Software Foundation, |
3 | # Inc. | |
c906108c SS |
4 | |
5 | # This program is free software; you can redistribute it and/or modify | |
6 | # it under the terms of the GNU General Public License as published by | |
e22f8b7c | 7 | # the Free Software Foundation; either version 3 of the License, or |
c906108c | 8 | # (at your option) any later version. |
e22f8b7c | 9 | # |
c906108c SS |
10 | # This program is distributed in the hope that it will be useful, |
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | # GNU General Public License for more details. | |
e22f8b7c | 14 | # |
c906108c | 15 | # You should have received a copy of the GNU General Public License |
e22f8b7c | 16 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
c906108c | 17 | |
c906108c SS |
18 | # Written by Satish Pai <pai@apollo.hp.com> 1997-08-19 |
19 | ||
20 | # This file is part of the gdb testsuite | |
21 | ||
c906108c SS |
22 | # |
23 | # test running programs | |
24 | # | |
25 | ||
c906108c | 26 | |
d4f3574e SS |
27 | if { [skip_cplus_tests] } { continue } |
28 | ||
f5f3a911 | 29 | standard_testfile .cc |
d4f3574e | 30 | |
f5f3a911 TT |
31 | if {[prepare_for_testing $testfile.exp $testfile $srcfile {debug c++}]} { |
32 | return -1 | |
c906108c SS |
33 | } |
34 | ||
c906108c SS |
35 | if ![runto_main] then { |
36 | perror "couldn't run to breakpoint" | |
37 | continue | |
38 | } | |
39 | ||
f8d3bf8f | 40 | gdb_test_no_output "set width 0" |
c906108c SS |
41 | |
42 | #send_gdb "ptype foo\n" | |
43 | #gdb_expect { | |
44 | # -re "\r\n$gdb_prompt $" { | |
45 | # pass "ptype foo" | |
46 | # } | |
47 | # -re ".*$gdb_prompt $" { fail "ptype foo" } | |
48 | # timeout { fail "(timeout) ptype foo" } | |
49 | #} | |
50 | ||
51 | #send_gdb "ptype bar\n" | |
52 | #gdb_expect { | |
53 | # -re "\r\n$gdb_prompt $" { | |
54 | # pass "ptype foo" | |
55 | # } | |
56 | # -re ".*$gdb_prompt $" { fail "ptype foo" } | |
57 | # timeout { fail "(timeout) ptype foo" } | |
58 | #} | |
59 | ||
60 | # NOTE: Add -- ptype foo.x, etc. when things are working | |
61 | ||
a0b3c4fd | 62 | #Initialize foo |
f8d3bf8f | 63 | gdb_test "next" "40\[ \t\]*foo.paper = 33;" "next 1" |
a0b3c4fd | 64 | |
c906108c | 65 | # Print out the big anon union. |
f8d3bf8f MS |
66 | gdb_test "print foo" \ |
67 | "\\$\[0-9\]* = \{num1 = \{zero = 0, one = 0\}, \{pebble = 0, x = \{rock = 0, rock2 = 0\}, \{qux = 0, mux = 0\}, boulder = 0\}, \{paper = 0, cloth = 0\}, num2 = \{two = 0, three = 0\}\}" \ | |
68 | "print foo 1" | |
c906108c SS |
69 | |
70 | # Step over assignment to member | |
71 | ||
f8d3bf8f | 72 | gdb_test "next" "41\[ \t\]*foo.pebble = 44;" "next 2" |
c906108c SS |
73 | |
74 | # Now print out anon union again | |
f8d3bf8f MS |
75 | gdb_test "print foo" \ |
76 | "\\$\[0-9\]* = \{num1 = \{zero = 0, one = 0\}, \{pebble = 0, x = \{rock = 0, rock2 = 0\}, \{qux = 0, mux = 0\}, boulder = 0\}, \{paper = 33, cloth = 33\}, num2 = \{two = 0, three = 0\}\}" \ | |
77 | "print foo 2" | |
c906108c SS |
78 | |
79 | # Modify the member just set | |
f8d3bf8f | 80 | gdb_test_no_output "set var foo.cloth = 35" "set var foo.cloth" |
c906108c SS |
81 | |
82 | # Now print out anon union again to see if the right member was set | |
f8d3bf8f MS |
83 | gdb_test "print foo" \ |
84 | "\\$\[0-9\]* = \{num1 = \{zero = 0, one = 0\}, \{pebble = 0, x = \{rock = 0, rock2 = 0\}, \{qux = 0, mux = 0\}, boulder = 0\}, \{paper = 35, cloth = 35\}, num2 = \{two = 0, three = 0\}\}" \ | |
85 | "print foo 3" | |
c906108c SS |
86 | |
87 | # Step over next assignment to member | |
88 | ||
f8d3bf8f | 89 | gdb_test "next" "42\[ \t\]*foo.mux = 55;" "next 3" |
c906108c SS |
90 | |
91 | # Now print out anon union again | |
f8d3bf8f MS |
92 | gdb_test "print foo" \ |
93 | "\\$\[0-9\]* = \{num1 = \{zero = 0, one = 0\}, \{pebble = 44, x = \{rock = 44, rock2 = 0\}, \{qux = 44, mux = 44\}, boulder = 44\}, \{paper = 35, cloth = 35\}, num2 = \{two = 0, three = 0\}\}" \ | |
94 | "print foo 4" | |
c906108c SS |
95 | |
96 | # Modify the member just set | |
f8d3bf8f | 97 | gdb_test_no_output "set var foo.pebble = 45" "set var foo.pebble" |
c906108c SS |
98 | |
99 | # Now print out anon union again to see if the right member was set | |
f8d3bf8f MS |
100 | gdb_test "print foo" \ |
101 | "\\$\[0-9\]* = \{num1 = \{zero = 0, one = 0\}, \{pebble = 45, x = \{rock = 45, rock2 = 0\}, \{qux = 45, mux = 45\}, boulder = 45\}, \{paper = 35, cloth = 35\}, num2 = \{two = 0, three = 0\}\}" \ | |
102 | "print foo 5" | |
c906108c SS |
103 | |
104 | # Modify another member at a different level | |
f8d3bf8f | 105 | gdb_test_no_output "set var foo.qux = 46" "set var foo.qux" |
c906108c SS |
106 | |
107 | # Now print out anon union again to see if the right member was set | |
f8d3bf8f MS |
108 | gdb_test "print foo" \ |
109 | "\\$\[0-9\]* = \{num1 = \{zero = 0, one = 0\}, \{pebble = 46, x = \{rock = 46, rock2 = 0\}, \{qux = 46, mux = 46\}, boulder = 46\}, \{paper = 35, cloth = 35\}, num2 = \{two = 0, three = 0\}\}" \ | |
110 | "print foo 6" | |
c906108c SS |
111 | |
112 | # Modify the member at another level, but not the first one in the union | |
f8d3bf8f | 113 | gdb_test_no_output "set var foo.mux = 47" "set var foo.mux" |
c906108c SS |
114 | |
115 | # Now print out anon union again to see if things worked | |
f8d3bf8f MS |
116 | gdb_test "print foo" \ |
117 | "\\$\[0-9\]* = \{num1 = \{zero = 0, one = 0\}, \{pebble = 47, x = \{rock = 47, rock2 = 0\}, \{qux = 47, mux = 47\}, boulder = 47\}, \{paper = 35, cloth = 35\}, num2 = \{two = 0, three = 0\}\}" \ | |
118 | "print foo 7" | |
c906108c SS |
119 | |
120 | # Modify a member of a struct in an anon union | |
f8d3bf8f | 121 | gdb_test_no_output "set var foo.x.rock = 48" "set var foo.x.rock" |
c906108c SS |
122 | |
123 | # Now print out anon union again to see if things worked | |
f8d3bf8f MS |
124 | gdb_test "print foo" \ |
125 | "\\$\[0-9\]* = \{num1 = \{zero = 0, one = 0\}, \{pebble = 48, x = \{rock = 48, rock2 = 0\}, \{qux = 48, mux = 48\}, boulder = 48\}, \{paper = 35, cloth = 35\}, num2 = \{two = 0, three = 0\}\}" \ | |
126 | "print foo 8" | |
c906108c SS |
127 | |
128 | # Modify a member of a struct in an anon union, but something | |
129 | # that doesn't alias to some other union member | |
f8d3bf8f | 130 | gdb_test_no_output "set var foo.x.rock2 = 49" "set var foo.x.rock2" |
c906108c SS |
131 | |
132 | # Now print out anon union again to see if things worked | |
f8d3bf8f MS |
133 | gdb_test "print foo" \ |
134 | "\\$\[0-9\]* = \{num1 = \{zero = 0, one = 0\}, \{pebble = 48, x = \{rock = 48, rock2 = 49\}, \{qux = 48, mux = 48\}, boulder = 48\}, \{paper = 35, cloth = 35\}, num2 = \{two = 0, three = 0\}\}" \ | |
135 | "print foo 9" | |
c906108c | 136 | |
a0b3c4fd | 137 | # Step over next four assignments |
f8d3bf8f | 138 | gdb_test "next 4" "53\[ \t\]*w = 45;" "next 4" |
c906108c SS |
139 | |
140 | # Tests for anon unions that are not members of a class or struct | |
141 | ||
f8d3bf8f | 142 | gdb_test "print w" "\\$\[0-9\]* = 0" "print w 1" |
a0b3c4fd | 143 | |
f8d3bf8f | 144 | gdb_test "print z" "\\$\[0-9\]* = 0" "print z 1" |
c906108c SS |
145 | |
146 | # Step over next assignment to w | |
f8d3bf8f | 147 | gdb_test "next" "55\[ \t\]*int j = 0;" "next 5" |
c906108c SS |
148 | |
149 | # See if the change in value is noticed | |
f8d3bf8f | 150 | gdb_test "print w" "\\$\[0-9\]* = 45" "print w 2" |
c906108c SS |
151 | |
152 | # See if z shows the same value | |
31e43e98 | 153 | gdb_test "print z" "\\$\[0-9\]* = 45" "print z 2" |
c906108c SS |
154 | |
155 | # Set the anon union member | |
f8d3bf8f | 156 | gdb_test_no_output "set var z = 27" "set var z" |
c906108c SS |
157 | |
158 | # See if the change in value is noticed | |
f8d3bf8f | 159 | gdb_test "print w" "\\$\[0-9\]* = 27" "print w 3" |
c906108c SS |
160 | |
161 | # See if z shows the same value | |
f8d3bf8f | 162 | gdb_test "print z" "\\$\[0-9\]* = 27" "print z 3" |