* gdb.objc/basicclass.exp: Use standard_testfile.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / py-value.exp
CommitLineData
c5a57081 1# Copyright (C) 2008-2012 Free Software Foundation, Inc.
a08702d6
TJB
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# This file is part of the GDB testsuite. It tests the mechanism
17# exposing values to Python.
18
a2c09bd0
DE
19load_lib gdb-python.exp
20
5172aecb 21set testfile "py-value"
a08702d6
TJB
22set srcfile ${testfile}.c
23set binfile ${objdir}/${subdir}/${testfile}
db8e4570
UW
24
25# Build inferior to language specification.
26proc build_inferior {exefile lang} {
27 global srcdir subdir srcfile testfile hex
28
29 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${exefile}" executable "debug $lang"] != "" } {
30 untested "Couldn't compile ${srcfile} in $lang mode"
31 return -1
32 }
a08702d6
TJB
33}
34
a08702d6
TJB
35proc test_value_creation {} {
36 global gdb_prompt
37
38 gdb_py_test_silent_cmd "python i = gdb.Value (True)" "create boolean value" 1
39 gdb_py_test_silent_cmd "python i = gdb.Value (5)" "create integer value" 1
40 gdb_py_test_silent_cmd "python i = gdb.Value (5L)" "create long value" 1
41 gdb_py_test_silent_cmd "python f = gdb.Value (1.25)" "create double value" 1
42 gdb_py_test_silent_cmd "python a = gdb.Value ('string test')" "create 8-bit string value" 1
43 gdb_test "python print a" "\"string test\"" "print 8-bit string"
44 gdb_test "python print a.__class__" "<type 'gdb.Value'>" "verify type of 8-bit string"
45 gdb_py_test_silent_cmd "python a = gdb.Value (u'unicode test')" "create unicode value" 1
46 gdb_test "python print a" "\"unicode test\"" "print Unicode string"
47 gdb_test "python print a.__class__" "<type 'gdb.Value'>" "verify type of unicode string"
c0c6f777
TJB
48
49 # Test address attribute is None in a non-addressable value
50 gdb_test "python print 'result =', i.address" "= None" "Test address attribute in non-addressable value"
a08702d6
TJB
51}
52
53proc test_value_numeric_ops {} {
54 global gdb_prompt
55
56 gdb_py_test_silent_cmd "python i = gdb.Value (5)" "create first integer value" 0
57 gdb_py_test_silent_cmd "python j = gdb.Value (2)" "create second integer value" 0
58 gdb_py_test_silent_cmd "python f = gdb.Value (1.25)" "create first double value" 0
59 gdb_py_test_silent_cmd "python g = gdb.Value (2.5)" "create second double value" 0
60 gdb_test "python print 'result = ' + str(i+j)" " = 7" "add two integer values"
61 gdb_test "python print (i+j).__class__" "<type 'gdb.Value'>" "verify type of integer add result"
62
63 gdb_test "python print 'result = ' + str(f+g)" " = 3.75" "add two double values"
64 gdb_test "python print 'result = ' + str(i-j)" " = 3" "subtract two integer values"
65 gdb_test "python print 'result = ' + str(f-g)" " = -1.25" "subtract two double values"
66 gdb_test "python print 'result = ' + str(i*j)" " = 10" "multiply two integer values"
67 gdb_test "python print 'result = ' + str(f*g)" " = 3.125" "multiply two double values"
68 gdb_test "python print 'result = ' + str(i/j)" " = 2" "divide two integer values"
69 gdb_test "python print 'result = ' + str(f/g)" " = 0.5" "divide two double values"
70 gdb_test "python print 'result = ' + str(i%j)" " = 1" "take remainder of two integer values"
71 # Remainder of float is implemented in Python but not in GDB's value system.
72
73 gdb_test "python print 'result = ' + str(i**j)" " = 25" "integer value raised to the power of another integer value"
74 gdb_test "python print 'result = ' + str(g**j)" " = 6.25" "double value raised to the power of integer value"
75
76 gdb_test "python print 'result = ' + str(-i)" " = -5" "negated integer value"
77 gdb_test "python print 'result = ' + str(+i)" " = 5" "positive integer value"
78 gdb_test "python print 'result = ' + str(-f)" " = -1.25" "negated double value"
79 gdb_test "python print 'result = ' + str(+f)" " = 1.25" "positive double value"
80 gdb_test "python print 'result = ' + str(abs(j-i))" " = 3" "absolute of integer value"
81 gdb_test "python print 'result = ' + str(abs(f-g))" " = 1.25" "absolute of double value"
82
83 # Test gdb.Value mixed with Python types.
84
85 gdb_test "python print 'result = ' + str(i-1)" " = 4" "subtract integer value from python integer"
86 gdb_test "python print (i-1).__class__" "<type 'gdb.Value'>" "verify type of mixed integer subtraction result"
87 gdb_test "python print 'result = ' + str(f+1.5)" " = 2.75" "add double value with python float"
88
89 gdb_test "python print 'result = ' + str(1-i)" " = -4" "subtract python integer from integer value"
90 gdb_test "python print 'result = ' + str(1.5+f)" " = 2.75" "add python float with double value"
91
08c637de
TJB
92 # Conversion test.
93 gdb_test "print evalue" " = TWO"
89493308 94 gdb_test_no_output "python evalue = gdb.history (0)"
08c637de
TJB
95 gdb_test "python print int (evalue)" "2"
96
a08702d6
TJB
97 # Test pointer arithmethic
98
99 # First, obtain the pointers
de7ff789 100 gdb_test "print (void *) 2" ".*" ""
35ec993f 101 gdb_test_no_output "python a = gdb.history (0)" ""
de7ff789 102 gdb_test "print (void *) 5" ".*" ""
35ec993f 103 gdb_test_no_output "python b = gdb.history (0)" ""
a08702d6
TJB
104
105 gdb_test "python print 'result = ' + str(a+5)" " = 0x7" "add pointer value with python integer"
106 gdb_test "python print 'result = ' + str(b-2)" " = 0x3" "subtract python integer from pointer value"
107 gdb_test "python print 'result = ' + str(b-a)" " = 3" "subtract two pointer values"
108
109 # Test some invalid operations.
110
111 gdb_test_multiple "python print 'result = ' + str(i+'foo')" "catch error in python type conversion" {
112 -re "Argument to arithmetic operation not a number or boolean.*$gdb_prompt $" {pass "catch error in python type conversion"}
113 -re "result = .*$gdb_prompt $" {fail "catch error in python type conversion"}
114 -re "$gdb_prompt $" {fail "catch error in python type conversion"}
115 }
116
117 gdb_test_multiple "python print 'result = ' + str(i+gdb.Value('foo'))" "catch throw of GDB error" {
118 -re "Traceback.*$gdb_prompt $" {pass "catch throw of GDB error"}
119 -re "result = .*$gdb_prompt $" {fail "catch throw of GDB error"}
120 -re "$gdb_prompt $" {fail "catch throw of GDB error"}
121 }
122}
123
124proc test_value_boolean {} {
125 # First, define a useful function to test booleans.
126 gdb_py_test_multiple "define function to test booleans" \
127 "python" "" \
128 "def test_bool (val):" "" \
129 " if val:" "" \
130 " print 'yay'" "" \
131 " else:" "" \
132 " print 'nay'" "" \
133 "end" ""
134
135 gdb_test "py test_bool (gdb.Value (True))" "yay" "check evaluation of true boolean value in expression"
136
137 gdb_test "py test_bool (gdb.Value (False))" "nay" "check evaluation of false boolean value in expression"
138
139 gdb_test "py test_bool (gdb.Value (5))" "yay" "check evaluation of true integer value in expression"
140
141 gdb_test "py test_bool (gdb.Value (0))" "nay" "check evaluation of false integer value in expression"
142
143 gdb_test "py test_bool (gdb.Value (5.2))" "yay" "check evaluation of true integer value in expression"
144
145 gdb_test "py test_bool (gdb.Value (0.0))" "nay" "check evaluation of false integer value in expression"
146}
147
148proc test_value_compare {} {
149 gdb_test "py print gdb.Value (1) < gdb.Value (1)" "False" "less than, equal"
150 gdb_test "py print gdb.Value (1) < gdb.Value (2)" "True" "less than, less"
151 gdb_test "py print gdb.Value (2) < gdb.Value (1)" "False" "less than, greater"
152 gdb_test "py print gdb.Value (2) < None" "False" "less than, None"
153
154 gdb_test "py print gdb.Value (1) <= gdb.Value (1)" "True" "less or equal, equal"
155 gdb_test "py print gdb.Value (1) <= gdb.Value (2)" "True" "less or equal, less"
156 gdb_test "py print gdb.Value (2) <= gdb.Value (1)" "False" "less or equal, greater"
157 gdb_test "py print gdb.Value (2) <= None" "False" "less or equal, None"
158
159 gdb_test "py print gdb.Value (1) == gdb.Value (1)" "True" "equality of gdb.Values"
160 gdb_test "py print gdb.Value (1) == gdb.Value (2)" "False" "inequality of gdb.Values"
161 gdb_test "py print gdb.Value (1) == 1.0" "True" "equality of gdb.Value with Python value"
162 gdb_test "py print gdb.Value (1) == 2" "False" "inequality of gdb.Value with Python value"
163 gdb_test "py print gdb.Value (1) == None" "False" "inequality of gdb.Value with None"
164
165 gdb_test "py print gdb.Value (1) != gdb.Value (1)" "False" "inequality, false"
166 gdb_test "py print gdb.Value (1) != gdb.Value (2)" "True" "inequality, true"
167 gdb_test "py print gdb.Value (1) != None" "True" "inequality, None"
168
169 gdb_test "py print gdb.Value (1) > gdb.Value (1)" "False" "greater than, equal"
170 gdb_test "py print gdb.Value (1) > gdb.Value (2)" "False" "greater than, less"
171 gdb_test "py print gdb.Value (2) > gdb.Value (1)" "True" "greater than, greater"
172 gdb_test "py print gdb.Value (2) > None" "True" "greater than, None"
173
174 gdb_test "py print gdb.Value (1) >= gdb.Value (1)" "True" "greater or equal, equal"
175 gdb_test "py print gdb.Value (1) >= gdb.Value (2)" "False" "greater or equal, less"
176 gdb_test "py print gdb.Value (2) >= gdb.Value (1)" "True" "greater or equal, greater"
177 gdb_test "py print gdb.Value (2) >= None" "True" "greater or equal, None"
178}
179
180proc test_value_in_inferior {} {
181 global gdb_prompt
182 global testfile
183
184 gdb_breakpoint [gdb_get_line_number "break to inspect struct and union"]
a08702d6
TJB
185
186 gdb_continue_to_breakpoint "break to inspect struct and union"
187
188 # Just get inferior variable s in the value history, available to python.
189 gdb_test "print s" " = {a = 3, b = 5}" ""
190
08c637de 191 gdb_py_test_silent_cmd "python s = gdb.history (0)" "get value from history" 1
a08702d6
TJB
192
193 gdb_test "python print 'result = ' + str(s\['a'\])" " = 3" "access element inside struct using 8-bit string name"
194 gdb_test "python print 'result = ' + str(s\[u'a'\])" " = 3" "access element inside struct using unicode name"
195
196 # Test dereferencing the argv pointer
197
198 # Just get inferior variable argv the value history, available to python.
199 gdb_test "print argv" " = \\(char \\*\\*\\) 0x.*" ""
200
08c637de 201 gdb_py_test_silent_cmd "python argv = gdb.history (0)" "" 0
a08702d6
TJB
202 gdb_py_test_silent_cmd "python arg0 = argv.dereference ()" "dereference value" 1
203
204 # Check that the dereferenced value is sane
70362913
DJ
205 if { ! [target_info exists noargs] } {
206 gdb_test "python print arg0" "0x.*$testfile\"" "verify dereferenced value"
207 }
def2b000
TJB
208
209 # Smoke-test is_optimized_out attribute
210 gdb_test "python print 'result =', arg0.is_optimized_out" "= False" "Test is_optimized_out attribute"
c0c6f777
TJB
211
212 # Test address attribute
213 gdb_test "python print 'result =', arg0.address" "= 0x\[\[:xdigit:\]\]+" "Test address attribute"
fbb8f299 214
46f886f1
JK
215 # Test displaying a variable that is temporarily at a bad address.
216 # But if we can examine what's at memory address 0, then we'll also be
217 # able to display it without error. Don't run the test in that case.
218 set can_read_0 0
219 gdb_test_multiple "x 0" "memory at address 0" {
220 -re "0x0:\[ \t\]*Cannot access memory at address 0x0\r\n$gdb_prompt $" { }
221 -re "0x0:\[ \t\]*Error accessing memory address 0x0\r\n$gdb_prompt $" { }
222 -re "\r\n$gdb_prompt $" {
223 set can_read_0 1
224 }
225 }
226
621c8364 227 # Test memory error.
46f886f1
JK
228 set test "parse_and_eval with memory error"
229 if {$can_read_0} {
230 untested $test
231 } else {
232 gdb_test "python print gdb.parse_and_eval('*(int*)0')" "gdb.MemoryError: Cannot access memory at address 0x0.*" $test
233 }
621c8364 234
54d8a644
PK
235 # Test Python lazy value handling
236 set test "memory error and lazy values"
aa2071bd
PK
237 if {$can_read_0} {
238 untested $test
239 } else {
54d8a644
PK
240 gdb_test "python inval = gdb.parse_and_eval('*(int*)0')"
241 gdb_test "python print inval.is_lazy" "True"
242 gdb_test "python inval2 = inval+1" "gdb.MemoryError: Cannot access memory at address 0x0.*" $test
243 gdb_test "python inval.fetch_lazy ()" "gdb.MemoryError: Cannot access memory at address 0x0.*" $test
aa2071bd
PK
244 }
245 gdb_test "python argc_lazy = gdb.parse_and_eval('argc')"
54d8a644
PK
246 gdb_test "python argc_notlazy = gdb.parse_and_eval('argc')"
247 gdb_test "python argc_notlazy.fetch_lazy()"
248 gdb_test "python print argc_lazy.is_lazy" "True"
249 gdb_test "python print argc_notlazy.is_lazy" "False"
aa2071bd 250 gdb_test "print argc" " = 1" "sanity check argc"
54d8a644 251 gdb_test "python print argc_lazy.is_lazy" "\r\nTrue"
aa2071bd 252 gdb_test_no_output "set argc=2"
54d8a644
PK
253 gdb_test "python print argc_notlazy" "\r\n1"
254 gdb_test "python print argc_lazy" "\r\n2"
255 gdb_test "python print argc_lazy.is_lazy" "False"
aa2071bd 256
fbb8f299
PM
257 # Test string fetches, both partial and whole.
258 gdb_test "print st" "\"divide et impera\""
259 gdb_py_test_silent_cmd "python st = gdb.history (0)" "get value from history" 1
260 gdb_test "python print st.string ()" "divide et impera" "Test string with no length"
261 gdb_test "python print st.string (length = -1)" "divide et impera" "Test string (length = -1) is all of the string"
262 gdb_test "python print st.string (length = 6)" "divide"
263 gdb_test "python print \"---\"+st.string (length = 0)+\"---\"" "------" "Test string (length = 0) is empty"
264 gdb_test "python print len(st.string (length = 0))" "0" "Test length is 0"
265
266
267 # Fetch a string that has embedded nulls.
268 gdb_test "print nullst" "\"divide\\\\000et\\\\000impera\".*"
269 gdb_py_test_silent_cmd "python nullst = gdb.history (0)" "get value from history" 1
270 gdb_test "python print nullst.string ()" "divide" "Test string to first null"
271 # Python cannot print strings that contain the null (\0) character.
272 # For the purposes of this test, use repr()
273 gdb_py_test_silent_cmd "python nullst = nullst.string (length = 9)" "get string beyond null" 1
274 gdb_test "python print repr(nullst)" "u'divide\\\\x00et'"
a08702d6
TJB
275}
276
be759fcf
PM
277proc test_lazy_strings {} {
278
279 global hex
280
281 gdb_test "print sptr" "\"pointer\""
282 gdb_py_test_silent_cmd "python sptr = gdb.history (0)" "Get value from history" 1
283
284 gdb_py_test_silent_cmd "python lstr = sptr.lazy_string()" "Aquire lazy string" 1
285 gdb_test "python print lstr.type" "const char \*." "Test type name equality"
286 gdb_test "python print sptr.type" "const char \*." "Test type name equality"
fff5cc64
PM
287 gdb_test "print sn" "0x0"
288 gdb_py_test_silent_cmd "python snptr = gdb.history (0)" "Get value from history" 1
289 gdb_test "python snstr = snptr.lazy_string(length=5)" ".*Cannot create a lazy string with address.*" "Test lazy string"
290 gdb_py_test_silent_cmd "python snstr = snptr.lazy_string(length=0)" "Succesfully create a lazy string" 1
291 gdb_test "python print snstr.length" "0" "Test lazy string length"
292 gdb_test "python print snstr.address" "0" "Test lazy string address"
be759fcf
PM
293}
294
295
5374244e
PM
296proc test_inferior_function_call {} {
297 global gdb_prompt hex decimal
298
299 # Correct inferior call without arguments.
300 gdb_test "p/x fp1" " = $hex.*"
301 gdb_py_test_silent_cmd "python fp1 = gdb.history (0)" "get value from history" 1
302 gdb_test "python fp1 = fp1.dereference()" ""
303 gdb_test "python result = fp1()" ""
304 gdb_test "python print result" "void"
305
306 # Correct inferior call with arguments.
307 gdb_test "p/x fp2" " = $hex.*"
308 gdb_py_test_silent_cmd "python fp2 = gdb.history (0)" "get value from history" 1
309 gdb_test "python fp2 = fp2.dereference()" ""
310 gdb_test "python result2 = fp2(10,20)" ""
311 gdb_test "python print result2" "30"
312
313 # Incorrect to call an int value.
314 gdb_test "p i" " = $decimal.*"
315 gdb_py_test_silent_cmd "python i = gdb.history (0)" "get value from history" 1
316 gdb_test "python result3 = i()" ".*Value is not callable.*"
317
318 # Incorrect number of arguments.
319 gdb_test "p/x fp2" " = $hex.*"
320 gdb_py_test_silent_cmd "python fp3 = gdb.history (0)" "get value from history" 1
321 gdb_test "python fp3 = fp3.dereference()" ""
322 gdb_test "python result2 = fp3(10)" ".*Too few arguments in function call.*"
323}
324
89c73ade
TT
325# A few objfile tests.
326proc test_objfiles {} {
90556b8c
JK
327 gdb_test "python\nok=False\nfor file in gdb.objfiles():\n if 'py-value' in file.filename:\n ok=True\nprint ok\nend" "True" \
328 "py-value in file.filename"
89c73ade
TT
329
330 gdb_test "python print gdb.objfiles()\[0\].pretty_printers" "\\\[\\\]"
331
332 gdb_test "python gdb.objfiles()\[0\].pretty_printers = 0" \
333 "pretty_printers attribute must be a list.*Error while executing Python code."
334}
a08702d6 335
2c74e833
TT
336proc test_value_after_death {} {
337 # Construct a type while the inferior is still running.
338 gdb_py_test_silent_cmd "python ptrtype = gdb.lookup_type('PTR')" \
339 "create PTR type" 1
340
341 # Kill the inferior and remove the symbols.
342 gdb_test "kill" "" "kill the inferior" \
343 "Kill the program being debugged. .y or n. $" \
344 "y"
345 gdb_test "file" "" "Discard the symbols" \
346 "Discard symbol table from.*y or n. $" \
347 "y"
348
349 # Now create a value using that type. Relies on arg0, created by
350 # test_value_in_inferior.
351 gdb_py_test_silent_cmd "python castval = arg0.cast(ptrtype.pointer())" \
352 "cast arg0 to PTR" 1
353
354 # Make sure the type is deleted.
355 gdb_py_test_silent_cmd "python ptrtype = None" \
356 "delete PTR type" 1
357
358 # Now see if the value's type is still valid.
359 gdb_test "python print castval.type" "PTR ." \
360 "print value's type"
361}
362
2e4d963f
PM
363# Regression test for invalid subscript operations. The bug was that
364# the type of the value was not being checked before allowing a
365# subscript operation to proceed.
366
db8e4570 367proc test_subscript_regression {exefile lang} {
2e4d963f 368
db8e4570 369 global srcdir subdir
2e4d963f
PM
370
371 # Start with a fresh gdb.
372 gdb_exit
373 gdb_start
374 gdb_reinitialize_dir $srcdir/$subdir
db8e4570 375 gdb_load ${exefile}
2e4d963f
PM
376
377 if ![runto_main ] then {
378 perror "couldn't run to breakpoint"
379 return
380 }
381
382 if {$lang == "c++"} {
383 gdb_breakpoint [gdb_get_line_number "break to inspect pointer by reference"]
384 gdb_continue_to_breakpoint "break to inspect pointer by reference"
385
386 gdb_py_test_silent_cmd "print rptr_int" \
387 "Obtain address" 1
388 gdb_py_test_silent_cmd "python rptr = gdb.history(0)" \
389 "Obtains value from GDB" 1
390 gdb_test "python print rptr\[0\]" "2" "Check pointer passed as reference"
f9ffd4bb
TT
391
392 # Just the most basic test of dynamic_cast -- it is checked in
393 # the C++ tests.
394 gdb_test "python print bool(gdb.parse_and_eval('base').dynamic_cast(gdb.lookup_type('Derived').pointer()))" \
395 True
03f17ccf
TT
396
397 # Likewise.
398 gdb_test "python print gdb.parse_and_eval('base').dynamic_type" \
399 "Derived \[*\]"
400 # A static type case.
401 gdb_test "python print gdb.parse_and_eval('5').dynamic_type" \
402 "int"
2e4d963f
PM
403 }
404
405 gdb_breakpoint [gdb_get_line_number "break to inspect struct and union"]
406 gdb_continue_to_breakpoint "break to inspect struct and union"
407
408 gdb_py_test_silent_cmd "python intv = gdb.Value(1)" \
409 "Create a value for subscript test" 1
410 gdb_py_test_silent_cmd "python stringv = gdb.Value(\"foo\")" \
411 "Create a value for subscript test" 1
412
413 # Try to access an int with a subscript. This should fail.
414 gdb_test "python print intv" "1" "Baseline print of a Python value"
621c8364 415 gdb_test "python print intv\[0\]" "gdb.error: Cannot subscript requested type.*" \
2e4d963f
PM
416 "Attempt to access an integer with a subscript"
417
418 # Try to access a string with a subscript. This should pass.
419 gdb_test "python print stringv" "foo." "Baseline print of a Python value"
420 gdb_test "python print stringv\[0\]" "f." "Attempt to access a string with a subscript"
421
422 # Try to access an int array via a pointer with a subscript. This should pass.
423 gdb_py_test_silent_cmd "print p" "Build pointer to array" 1
424 gdb_py_test_silent_cmd "python pointer = gdb.history(0)" "" 1
425 gdb_test "python print pointer\[0\]" "1" "Access array via pointer with int subscript"
426 gdb_test "python print pointer\[intv\]" "2" "Access array via pointer with value subscript"
427
428 # Try to access a single dimension array with a subscript to the
429 # result. This should fail.
621c8364 430 gdb_test "python print pointer\[intv\]\[0\]" "gdb.error: Cannot subscript requested type.*" \
2e4d963f
PM
431 "Attempt to access an integer with a subscript"
432
433 # Lastly, test subscript access to an array with multiple
434 # dimensions. This should pass.
435 gdb_py_test_silent_cmd "print {\"fu \",\"foo\",\"bar\"}" "Build array" 1
436 gdb_py_test_silent_cmd "python marray = gdb.history(0)" "" 1
437 gdb_test "python print marray\[1\]\[2\]" "o." "Test multiple subscript"
438}
439
57a1d736
TT
440# A few tests of gdb.parse_and_eval.
441proc test_parse_and_eval {} {
442 gdb_test "python print gdb.parse_and_eval ('23')" "23" \
443 "parse_and_eval constant test"
444 gdb_test "python print gdb.parse_and_eval ('5 + 7')" "12" \
445 "parse_and_eval simple expression test"
446 gdb_test "python print type(gdb.parse_and_eval ('5 + 7'))" \
447 ".type 'gdb.Value'."\
448 "parse_and_eval type test"
449}
450
88d4aea7
PM
451# Test that values are hashable.
452proc test_value_hash {} {
453 gdb_py_test_multiple "Simple Python value dictionary" \
454 "python" "" \
455 "one = gdb.Value(1)" "" \
456 "two = gdb.Value(2)" "" \
457 "three = gdb.Value(3)" "" \
458 "vdict = {one:\"one str\",two:\"two str\",three:\"three str\"}" "" \
459 "end"
460 gdb_test "python print vdict\[one\]" "one str" "Test dictionary hash"
461 gdb_test "python print vdict\[two\]" "two str" "Test dictionary hash"
462 gdb_test "python print vdict\[three\]" "three str" "Test dictionary hash"
463 gdb_test "python print one.__hash__() == hash(one)" "True" "Test inbuilt hash"
88d4aea7
PM
464}
465
db8e4570
UW
466# Build C and C++ versions of executable
467build_inferior "${binfile}" "c"
468build_inferior "${binfile}-cxx" "c++"
88d4aea7 469
a08702d6
TJB
470# Start with a fresh gdb.
471
472gdb_exit
473gdb_start
474gdb_reinitialize_dir $srcdir/$subdir
475gdb_load ${binfile}
476
f6bbabf0
PM
477# Skip all tests if Python scripting is not enabled.
478if { [skip_python_tests] } { continue }
a08702d6
TJB
479
480test_value_creation
481test_value_numeric_ops
482test_value_boolean
483test_value_compare
89c73ade 484test_objfiles
57a1d736 485test_parse_and_eval
88d4aea7 486test_value_hash
adc13a14
PA
487
488# The following tests require execution.
489
490if ![runto_main] then {
491 fail "Can't run to main"
492 return 0
493}
494
a08702d6 495test_value_in_inferior
5374244e 496test_inferior_function_call
be759fcf 497test_lazy_strings
2c74e833 498test_value_after_death
2e4d963f 499
db8e4570
UW
500# Test either C or C++ values.
501test_subscript_regression "${binfile}" "c"
502test_subscript_regression "${binfile}-cxx" "c++"
This page took 0.60911 seconds and 4 git commands to generate.