]>
Commit | Line | Data |
---|---|---|
28e7fd62 | 1 | # Copyright 1998-2013 Free Software Foundation, Inc. |
c906108c SS |
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 | |
e22f8b7c | 5 | # the Free Software Foundation; either version 3 of the License, or |
c906108c | 6 | # (at your option) any later version. |
e22f8b7c | 7 | # |
c906108c SS |
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. | |
e22f8b7c | 12 | # |
c906108c | 13 | # You should have received a copy of the GNU General Public License |
e22f8b7c | 14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
c906108c | 15 | |
c906108c SS |
16 | # This file was written by Elena Zannoni (ezannoni@cygnus.com) |
17 | ||
18 | # This file is part of the gdb testsuite | |
19 | # | |
20 | # tests for pointer arithmetic and pointer dereferencing | |
21 | # with integer type variables and pointers to integers | |
22 | # | |
23 | ||
c906108c SS |
24 | # |
25 | # test running programs | |
26 | # | |
c906108c SS |
27 | |
28 | set testfile "pointers" | |
29 | set srcfile ${testfile}.c | |
30 | set binfile ${objdir}/${subdir}/${testfile} | |
31 | ||
fc91c6c2 | 32 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } { |
b60f0898 JB |
33 | untested pointers.exp |
34 | return -1 | |
c906108c SS |
35 | } |
36 | ||
4c93b1db | 37 | if [get_compiler_info] { |
ae59b1da | 38 | return -1 |
085dd6e6 | 39 | } |
c906108c SS |
40 | |
41 | gdb_exit | |
42 | gdb_start | |
43 | gdb_reinitialize_dir $srcdir/$subdir | |
44 | gdb_load ${binfile} | |
45 | ||
46 | ||
47 | # | |
48 | # set it up at a breakpoint so we can play with the variable values | |
49 | # | |
50 | ||
51 | if ![runto_main] then { | |
52 | perror "couldn't run to breakpoint" | |
53 | continue | |
54 | } | |
55 | ||
a0b3c4fd | 56 | gdb_test "next " "more_code.*;" "continuing after dummy()" |
c906108c SS |
57 | |
58 | ||
59 | # | |
60 | # let's see if gdb catches some illegal operations on pointers | |
61 | # | |
62 | # I must comment these out because strict type checking is not | |
63 | # supported in this version of GDB. I do not really know | |
64 | # what the expected gdb reply is. | |
65 | # | |
66 | ||
67 | #send_gdb "print v_int_pointer2 = &v_int_pointer\n" | |
68 | #gdb_expect { | |
69 | # -re ".*.*$gdb_prompt $" { | |
70 | # pass "illegal pointer assignment rejected" | |
71 | # } | |
72 | # -re ".*$gdb_prompt $" { fail "illegal pointer assignment rejected" } | |
73 | # timeout { fail "(timeout) illegal pointer assignment rejected" } | |
74 | # } | |
75 | ||
76 | ||
77 | #send_gdb "print v_unsigned_int_pointer = &v_int\n" | |
78 | #gdb_expect { | |
79 | # -re ".*.*$gdb_prompt $" { | |
80 | # pass "illegal pointer assignment rejected" | |
81 | # } | |
82 | # -re ".*$gdb_prompt $" { fail "illegal pointer assignment rejected" } | |
83 | # timeout { fail "(timeout) ilegal pointer assignment rejected" } | |
84 | # } | |
85 | ||
86 | #send_gdb "print v_unsigned_int_pointer == v_double_pointer\n" | |
87 | #gdb_expect { | |
88 | # -re ".*.*$gdb_prompt $" { | |
89 | # pass "illegal pointer operation (+) rejected" | |
90 | # } | |
91 | # -re ".*$gdb_prompt $" { fail "illegal pointer operation (+) rejected" } | |
92 | # timeout { fail "(timeout) illegal pointer operation (+) rejected" } | |
93 | # } | |
94 | ||
95 | ||
96 | #send_gdb "print v_unsigned_int_pointer * v_double_pointer\n" | |
97 | #gdb_expect { | |
98 | # -re ".*Argument to arithmetic operation not a number or boolean.*$gdb_prompt $" { | |
99 | # pass "illegal pointer operation (*) rejected" | |
100 | # } | |
101 | # -re ".*$gdb_prompt $" { fail "illegal pointer operation (*) rejected" } | |
102 | # timeout { fail "(timeout) illegal pointer operation (*) rejected" } | |
103 | # } | |
104 | ||
105 | ||
106 | #send_gdb "print v_unsigned_int_pointer = v_double_pointer\n" | |
107 | #gdb_expect { | |
108 | # -re ".*.*$gdb_prompt $" { | |
109 | # pass "ilegal pointer assignment rejected" | |
110 | # } | |
111 | # -re ".*$gdb_prompt $" { fail "illegal pointer assignment rejected" } | |
112 | # timeout { fail "(timeout) illegal pointer assignment rejected" } | |
113 | # } | |
114 | ||
115 | ||
116 | #send_gdb "print v_unsigned_int_pointer = v_unsigned_int\n" | |
117 | #gdb_expect { | |
118 | # -re ".*.*$gdb_prompt $" { | |
119 | # pass "illegal pointer assignment rejected" | |
120 | # } | |
121 | # -re ".*$gdb_prompt $" { fail "illegal pointer assignment rejected" } | |
122 | # timeout { fail "(timeout) illegal pointer assignment rejected" } | |
123 | # } | |
124 | ||
27d3a1a2 MS |
125 | gdb_test_no_output "set variable v_int_pointer=&v_int_array\[0\]" \ |
126 | "set pointer to beginning of array" | |
127 | gdb_test_no_output "set variable v_int_pointer2=&v_int_array\[1\]" \ | |
128 | "set pointer to end of array" | |
c906108c SS |
129 | |
130 | ||
65731a6b | 131 | gdb_test "print *v_int_pointer" " = 6" "print object pointed to" |
c906108c | 132 | |
65731a6b | 133 | gdb_test "print *v_int_pointer2" " = 18" "print object pointed to \#2" |
c906108c | 134 | |
65731a6b MS |
135 | gdb_test "print v_int_pointer == v_int_pointer2" " = $false" \ |
136 | "pointer1==pointer2" | |
137 | ||
138 | gdb_test "print v_int_pointer != v_int_pointer2" " = $true" \ | |
139 | "pointer1!=pointer2" | |
140 | ||
141 | gdb_test "print v_int_pointer <= v_int_pointer2" " = $true" \ | |
142 | "pointer1<=pointer2" | |
143 | ||
144 | gdb_test "print v_int_pointer >= v_int_pointer2" " = $false" \ | |
145 | "pointer1>=pointer2" | |
146 | ||
147 | gdb_test "print v_int_pointer < v_int_pointer2" " = $true" \ | |
148 | "pointer1<pointer2" | |
149 | ||
150 | gdb_test "print v_int_pointer > v_int_pointer2" " = $false" \ | |
151 | "pointer1>pointer2" | |
c906108c | 152 | |
27d3a1a2 MS |
153 | gdb_test_no_output "set variable y = *v_int_pointer++" \ |
154 | "set y = *v_int_pointer++" | |
65731a6b MS |
155 | gdb_test "print y" " = 6" "pointer assignment" |
156 | gdb_test "print *v_int_pointer" " = 18" "and post-increment" | |
c906108c SS |
157 | |
158 | ||
159 | ||
27d3a1a2 MS |
160 | gdb_test_no_output "set variable y = *--v_int_pointer2" \ |
161 | "set y = *--v_int_pointer2" | |
65731a6b MS |
162 | gdb_test "print y" " = 6" "pointer assignment" |
163 | gdb_test "print *v_int_pointer2" " = 6" "and pre-decrement" | |
164 | ||
165 | ||
166 | ||
27d3a1a2 | 167 | gdb_test_no_output "set variable y =v_int_pointer-v_int_pointer2" \ |
65731a6b MS |
168 | "set y =v_int_pointer-v_int_pointer2" |
169 | gdb_test "print y" " = 1" "pointer1-pointer2" | |
170 | ||
171 | ||
27d3a1a2 | 172 | gdb_test_no_output "set variable v_int_pointer=v_int_array" \ |
65731a6b MS |
173 | "set v_int_pointer=v_int_array" |
174 | gdb_test "print *v_int_pointer" " = 6" \ | |
175 | "print array element through pointer" | |
176 | ||
177 | gdb_test "print *(v_int_pointer+1)" " = 18" \ | |
178 | "print array element through pointer \#2" | |
179 | ||
c906108c SS |
180 | |
181 | # test print elements of array through pointers | |
182 | ||
65731a6b MS |
183 | gdb_test "print (*rptr)\[0\]" " = 0" \ |
184 | "print array element through pointer \#3" | |
185 | ||
186 | gdb_test "print (*rptr)\[1\]" " = 1" \ | |
187 | "print array element through pointer \#4" | |
188 | ||
189 | gdb_test "print (*rptr)\[2\]" " = 2" \ | |
190 | "print array element through pointer \#5" | |
c906108c | 191 | |
27d3a1a2 | 192 | gdb_test_no_output "set variable rptr = rptr+1" "increment rptr" |
c906108c | 193 | |
65731a6b MS |
194 | gdb_test "print (*rptr)\[0\]" " = 3" \ |
195 | "print array element through pointer \#6" | |
adf40b2e | 196 | |
65731a6b MS |
197 | gdb_test "print (*rptr)\[1\]" " = 4" \ |
198 | "print array element through pointer \#7" | |
adf40b2e | 199 | |
65731a6b MS |
200 | gdb_test "print (*rptr)\[2\]" " = 5" \ |
201 | "print array element through pointer \#8" | |
adf40b2e | 202 | |
65731a6b MS |
203 | gdb_test "print *( *(matrix+1) +2)" " = 5" \ |
204 | "print array element w/ pointer arithmetic" | |
adf40b2e | 205 | |
65731a6b MS |
206 | gdb_test "print **ptr_to_ptr_to_float" " = 100" \ |
207 | "print through ptr to ptr" | |
adf40b2e | 208 | |
65731a6b MS |
209 | # tests for pointers |
210 | # with elementary type variables and pointers. | |
211 | # | |
adf40b2e | 212 | |
de7ff789 | 213 | gdb_test "break marker1" ".*" "" |
65731a6b MS |
214 | gdb_test "cont" "Break.* marker1 \\(\\) at .*:$decimal.*" \ |
215 | continue to marker1" | |
216 | gdb_test "up" "more_code.*" "up from marker1" | |
217 | ||
218 | gdb_test "print *pUC" " = 21 \'.025\'.*" "print value of *pUC" | |
adf40b2e | 219 | |
65731a6b | 220 | gdb_test "ptype pUC" "type = unsigned char \\*" "ptype pUC" |
adf40b2e | 221 | |
65731a6b | 222 | gdb_test "print *pS" " = -14" "print value of *pS" |
adf40b2e | 223 | |
65731a6b | 224 | gdb_test_multiple "ptype pS" "ptype pS" { |
adf40b2e JM |
225 | -re "type = short \\*.*$gdb_prompt $" { pass "ptype pS" } |
226 | -re "type = short int \\*.*$gdb_prompt $" { pass "ptype pS" } | |
65731a6b | 227 | } |
adf40b2e | 228 | |
65731a6b | 229 | gdb_test "print *pUS" " = 7" "print value of *pUS" |
adf40b2e | 230 | |
65731a6b | 231 | gdb_test_multiple "ptype pUS" "ptype pUS" { |
adf40b2e JM |
232 | -re "type = unsigned short \\*.*$gdb_prompt $" { pass "ptype pUS" } |
233 | -re "type = short unsigned int \\*.*$gdb_prompt $" { pass "ptype pUS" } | |
adf40b2e JM |
234 | } |
235 | ||
65731a6b | 236 | gdb_test "print *pI" " = 102" "print value of *pI" |
adf40b2e | 237 | |
65731a6b | 238 | gdb_test "ptype pI" "type = int \\*" "ptype pI" |
adf40b2e | 239 | |
65731a6b MS |
240 | gdb_test "print *pUI" " = 1002" "print value of *pUI" |
241 | ||
242 | gdb_test "ptype pUI" "type = unsigned int \\*" "ptype pUI" | |
243 | ||
244 | gdb_test "print *pL" " = -234" "print value of *pL" | |
adf40b2e | 245 | |
65731a6b MS |
246 | gdb_test_multiple "ptype pL" "ptype pL" { |
247 | -re "type = long \\*.*$gdb_prompt $" { pass "ptype pL" } | |
248 | -re "type = long int \\*.*$gdb_prompt $" { pass "ptype pL" } | |
249 | } | |
adf40b2e | 250 | |
65731a6b | 251 | gdb_test "print *pUL" " = 234" "print value of *pUL" |
adf40b2e | 252 | |
65731a6b | 253 | gdb_test_multiple "ptype pUL" "ptype pUL" { |
adf40b2e JM |
254 | -re "type = unsigned long \\*.*$gdb_prompt $" { pass "ptype pUL" } |
255 | -re "type = long unsigned int \\*.*$gdb_prompt $" { pass "ptype pUL" } | |
adf40b2e JM |
256 | } |
257 | ||
65731a6b | 258 | gdb_test "print *pF" " = 1.2\[0-9\]*e\\+0?10" "print value of *pF" |
adf40b2e | 259 | |
65731a6b | 260 | gdb_test "ptype pF" "type = float \\*" "ptype pF" |
adf40b2e | 261 | |
65731a6b | 262 | gdb_test "print *pD" " = -1.2\[0-9\]*e\\-0?37" "print value of *pD" |
adf40b2e | 263 | |
65731a6b | 264 | gdb_test "ptype pD" "type = double \\*" "ptype pD" |
adf40b2e | 265 | |
65731a6b MS |
266 | gdb_test "print ******ppppppC" " = 65 \'A\'" \ |
267 | "print value of ******ppppppC" | |
adf40b2e | 268 | |
65731a6b | 269 | gdb_test "ptype pC" "type = char \\*" "ptype pC" |
adf40b2e | 270 | |
65731a6b | 271 | gdb_test "ptype ppC" "type = char \\*\\*" "ptype ppC" |
adf40b2e | 272 | |
65731a6b MS |
273 | gdb_test "ptype pppC" "type = char \\*\\*\\*" "ptype pppC" |
274 | ||
275 | gdb_test "ptype ppppC" "type = char \\*\\*\\*\\*" "ptype ppppC" | |
276 | ||
277 | gdb_test "ptype pppppC" "type = char \\*\\*\\*\\*\\*" "ptype pppppC" | |
278 | ||
279 | gdb_test "ptype ppppppC" "type = char \\*\\*\\*\\*\\*\\*" "ptype ppppppC" | |
adf40b2e | 280 | |
f3134b88 TT |
281 | # Regression test for a crash. |
282 | ||
283 | gdb_test "p instance.array_variable + 0" \ | |
9cb709b6 | 284 | " = \\(long (int )?\\*\\) 0x\[0-9a-f\]* <instance>" |