2014-01-01 03:54:24 +00:00
|
|
|
# Copyright (C) 2008-2014 Free Software Foundation, Inc.
|
2008-10-16 03:54:00 +00:00
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
# This file is part of the GDB testsuite. It tests the mechanism
|
|
|
|
# exposing values to Python.
|
|
|
|
|
2010-10-01 17:03:50 +00:00
|
|
|
load_lib gdb-python.exp
|
|
|
|
|
* gdb.python/lib-types.exp: Use standard_testfile,
prepare_for_testing.
* gdb.python/py-block.exp: Use standard_testfile.
* gdb.python/py-breakpoint.exp: Use standard_testfile.
* gdb.python/py-events.exp: Use standard_testfile,
standard_output_file.
* gdb.python/py-evsignal.exp: Use standard_testfile.
* gdb.python/py-evethreads.exp: Use standard_testfile.
* gdb.python/py-explore-cc.exp: Use standard_testfile.
* gdb.python/py-explore.exp: Use standard_testfile.
* gdb.python/py-finish-breakpoint.exp: Use standard_testfile,
standard_output_file.
* gdb.python/py-finish-breakpoint2.exp: Use standard_testfile,
prepare_for_testing.
* gdb.python/py-frame-inline.exp: Use standard_testfile.
* gdb.python/py-frame.exp: Use standard_testfile.
* gdb.python/py-inferior.exp: Use standard_testfile.
* gdb.python/py-infthread.exp: Use standard_testfile.
* gdb.python/py-mi.exp: Use standard_testfile.
* gdb.python/py-objfile-script.exp: Use standard_testfile,
build_executable.
* gdb.python/py-objfile.exp: Use standard_testfile.
* gdb.python/py-pp-maint.exp: Use standard_testfile,
prepare_for_testing.
* gdb.python/py-prettyprint.exp: Use standard_testfile.
* gdb.python/py-progspace.exp: Use standard_testfile,
build_executable.
* gdb.python/py-prompt.exp: Use standard_testfile,
build_executable.
* gdb.python/py-section-script.exp: Use standard_testfile,
build_executable.
* gdb.python/py-shared.exp: Use standard_testfile,
standard_output_file, clean_restart.
* gdb.python/py-symbol.exp: Use standard_output_file,
prepare_for_testing.
* gdb.python/py-symtab.exp: Use standard_output_file,
prepare_for_testing
* gdb.python/py-template.exp: Use standard_testfile.
* gdb.python/py-type.exp: Use standard_testfile.
* gdb.python/py-value-cc.exp: Use standard_testfile.
* gdb.python/py-value.exp: Use standard_testfile.
* gdb.python/python.exp: Use standard_testfile, build_executable.
2012-06-22 17:59:33 +00:00
|
|
|
standard_testfile
|
2011-07-26 18:38:55 +00:00
|
|
|
|
|
|
|
# Build inferior to language specification.
|
2013-08-07 23:51:45 +00:00
|
|
|
# LANG is one of "c" or "c++".
|
2011-07-26 18:38:55 +00:00
|
|
|
proc build_inferior {exefile lang} {
|
|
|
|
global srcdir subdir srcfile testfile hex
|
|
|
|
|
2013-08-07 23:51:45 +00:00
|
|
|
# Use different names for .o files based on the language.
|
|
|
|
# For Fission, the debug info goes in foo.dwo and we don't want,
|
|
|
|
# for example, a C++ compile to clobber the dwo of a C compile.
|
|
|
|
# ref: http://gcc.gnu.org/wiki/DebugFission
|
|
|
|
switch ${lang} {
|
|
|
|
"c" { set filename ${testfile}.o }
|
|
|
|
"c++" { set filename ${testfile}-cxx.o }
|
|
|
|
}
|
|
|
|
set objfile [standard_output_file $filename]
|
|
|
|
|
|
|
|
if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${objfile}" object "debug $lang"] != ""
|
|
|
|
|| [gdb_compile "${objfile}" "${exefile}" executable "debug $lang"] != "" } {
|
2011-07-26 18:38:55 +00:00
|
|
|
untested "Couldn't compile ${srcfile} in $lang mode"
|
|
|
|
return -1
|
|
|
|
}
|
2013-08-07 23:51:45 +00:00
|
|
|
return 0
|
2008-10-16 03:54:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
proc test_value_creation {} {
|
|
|
|
global gdb_prompt
|
2012-12-10 21:22:21 +00:00
|
|
|
global gdb_py_is_py3k
|
2008-10-16 03:54:00 +00:00
|
|
|
|
|
|
|
gdb_py_test_silent_cmd "python i = gdb.Value (True)" "create boolean value" 1
|
|
|
|
gdb_py_test_silent_cmd "python i = gdb.Value (5)" "create integer value" 1
|
2012-12-10 21:22:21 +00:00
|
|
|
if { $gdb_py_is_py3k == 0 } {
|
|
|
|
gdb_py_test_silent_cmd "python i = gdb.Value (5L)" "create long value" 1
|
|
|
|
}
|
2008-10-16 03:54:00 +00:00
|
|
|
gdb_py_test_silent_cmd "python f = gdb.Value (1.25)" "create double value" 1
|
|
|
|
gdb_py_test_silent_cmd "python a = gdb.Value ('string test')" "create 8-bit string value" 1
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print (a)" "\"string test\"" "print 8-bit string"
|
|
|
|
gdb_test "python print (a.__class__)" "<(type|class) 'gdb.Value'>" "verify type of 8-bit string"
|
|
|
|
if { $gdb_py_is_py3k == 0 } {
|
|
|
|
gdb_py_test_silent_cmd "python a = gdb.Value (u'unicode test')" "create unicode value" 1
|
|
|
|
gdb_test "python print (a)" "\"unicode test\"" "print Unicode string"
|
|
|
|
gdb_test "python print (a.__class__)" "<(type|class) 'gdb.Value'>" "verify type of unicode string"
|
|
|
|
}
|
2009-03-29 21:11:11 +00:00
|
|
|
|
|
|
|
# Test address attribute is None in a non-addressable value
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print ('result = %s' % i.address)" "= None" "Test address attribute in non-addressable value"
|
2008-10-16 03:54:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
proc test_value_numeric_ops {} {
|
|
|
|
global gdb_prompt
|
|
|
|
|
|
|
|
gdb_py_test_silent_cmd "python i = gdb.Value (5)" "create first integer value" 0
|
|
|
|
gdb_py_test_silent_cmd "python j = gdb.Value (2)" "create second integer value" 0
|
|
|
|
gdb_py_test_silent_cmd "python f = gdb.Value (1.25)" "create first double value" 0
|
|
|
|
gdb_py_test_silent_cmd "python g = gdb.Value (2.5)" "create second double value" 0
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print ('result = ' + str(i+j))" " = 7" "add two integer values"
|
|
|
|
gdb_test "python print ((i+j).__class__)" "<(type|class) 'gdb.Value'>" "verify type of integer add result"
|
|
|
|
|
|
|
|
gdb_test "python print ('result = ' + str(f+g))" " = 3.75" "add two double values"
|
|
|
|
gdb_test "python print ('result = ' + str(i-j))" " = 3" "subtract two integer values"
|
|
|
|
gdb_test "python print ('result = ' + str(f-g))" " = -1.25" "subtract two double values"
|
|
|
|
gdb_test "python print ('result = ' + str(i*j))" " = 10" "multiply two integer values"
|
|
|
|
gdb_test "python print ('result = ' + str(f*g))" " = 3.125" "multiply two double values"
|
|
|
|
gdb_test "python print ('result = ' + str(i/j))" " = 2" "divide two integer values"
|
|
|
|
gdb_test "python print ('result = ' + str(f/g))" " = 0.5" "divide two double values"
|
|
|
|
gdb_test "python print ('result = ' + str(i%j))" " = 1" "take remainder of two integer values"
|
2008-10-16 03:54:00 +00:00
|
|
|
# Remainder of float is implemented in Python but not in GDB's value system.
|
|
|
|
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print ('result = ' + str(i**j))" " = 25" "integer value raised to the power of another integer value"
|
|
|
|
gdb_test "python print ('result = ' + str(g**j))" " = 6.25" "double value raised to the power of integer value"
|
2008-10-16 03:54:00 +00:00
|
|
|
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print ('result = ' + str(-i))" " = -5" "negated integer value"
|
|
|
|
gdb_test "python print ('result = ' + str(+i))" " = 5" "positive integer value"
|
|
|
|
gdb_test "python print ('result = ' + str(-f))" " = -1.25" "negated double value"
|
|
|
|
gdb_test "python print ('result = ' + str(+f))" " = 1.25" "positive double value"
|
|
|
|
gdb_test "python print ('result = ' + str(abs(j-i)))" " = 3" "absolute of integer value"
|
|
|
|
gdb_test "python print ('result = ' + str(abs(f-g)))" " = 1.25" "absolute of double value"
|
2008-10-16 03:54:00 +00:00
|
|
|
|
|
|
|
# Test gdb.Value mixed with Python types.
|
|
|
|
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print ('result = ' + str(i-1))" " = 4" "subtract integer value from python integer"
|
|
|
|
gdb_test "python print ((i-1).__class__)" "<(type|class) 'gdb.Value'>" "verify type of mixed integer subtraction result"
|
|
|
|
gdb_test "python print ('result = ' + str(f+1.5))" " = 2.75" "add double value with python float"
|
2008-10-16 03:54:00 +00:00
|
|
|
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print ('result = ' + str(1-i))" " = -4" "subtract python integer from integer value"
|
|
|
|
gdb_test "python print ('result = ' + str(1.5+f))" " = 2.75" "add python float with double value"
|
2008-10-16 03:54:00 +00:00
|
|
|
|
2009-02-04 21:55:40 +00:00
|
|
|
# Conversion test.
|
|
|
|
gdb_test "print evalue" " = TWO"
|
2010-06-02 21:50:56 +00:00
|
|
|
gdb_test_no_output "python evalue = gdb.history (0)"
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print (int (evalue))" "2"
|
2009-02-04 21:55:40 +00:00
|
|
|
|
2008-10-16 03:54:00 +00:00
|
|
|
# Test pointer arithmethic
|
|
|
|
|
|
|
|
# First, obtain the pointers
|
2010-06-08 22:58:03 +00:00
|
|
|
gdb_test "print (void *) 2" ".*" ""
|
2010-06-03 23:54:18 +00:00
|
|
|
gdb_test_no_output "python a = gdb.history (0)" ""
|
2010-06-08 22:58:03 +00:00
|
|
|
gdb_test "print (void *) 5" ".*" ""
|
2010-06-03 23:54:18 +00:00
|
|
|
gdb_test_no_output "python b = gdb.history (0)" ""
|
2008-10-16 03:54:00 +00:00
|
|
|
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print ('result = ' + str(a+5))" " = 0x7( <.*>)?" "add pointer value with python integer"
|
|
|
|
gdb_test "python print ('result = ' + str(b-2))" " = 0x3( <.*>)?" "subtract python integer from pointer value"
|
|
|
|
gdb_test "python print ('result = ' + str(b-a))" " = 3" "subtract two pointer values"
|
2008-10-16 03:54:00 +00:00
|
|
|
|
|
|
|
# Test some invalid operations.
|
|
|
|
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test_multiple "python print ('result = ' + str(i+'foo'))" "catch error in python type conversion" {
|
2008-10-16 03:54:00 +00:00
|
|
|
-re "Argument to arithmetic operation not a number or boolean.*$gdb_prompt $" {pass "catch error in python type conversion"}
|
|
|
|
-re "result = .*$gdb_prompt $" {fail "catch error in python type conversion"}
|
|
|
|
-re "$gdb_prompt $" {fail "catch error in python type conversion"}
|
|
|
|
}
|
|
|
|
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test_multiple "python print ('result = ' + str(i+gdb.Value('foo')))" "catch throw of GDB error" {
|
2008-10-16 03:54:00 +00:00
|
|
|
-re "Traceback.*$gdb_prompt $" {pass "catch throw of GDB error"}
|
|
|
|
-re "result = .*$gdb_prompt $" {fail "catch throw of GDB error"}
|
|
|
|
-re "$gdb_prompt $" {fail "catch throw of GDB error"}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
proc test_value_boolean {} {
|
|
|
|
# First, define a useful function to test booleans.
|
|
|
|
gdb_py_test_multiple "define function to test booleans" \
|
|
|
|
"python" "" \
|
|
|
|
"def test_bool (val):" "" \
|
|
|
|
" if val:" "" \
|
2012-12-10 21:22:21 +00:00
|
|
|
" print ('yay')" "" \
|
2008-10-16 03:54:00 +00:00
|
|
|
" else:" "" \
|
2012-12-10 21:22:21 +00:00
|
|
|
" print ('nay')" "" \
|
2008-10-16 03:54:00 +00:00
|
|
|
"end" ""
|
|
|
|
|
|
|
|
gdb_test "py test_bool (gdb.Value (True))" "yay" "check evaluation of true boolean value in expression"
|
|
|
|
|
|
|
|
gdb_test "py test_bool (gdb.Value (False))" "nay" "check evaluation of false boolean value in expression"
|
|
|
|
|
|
|
|
gdb_test "py test_bool (gdb.Value (5))" "yay" "check evaluation of true integer value in expression"
|
|
|
|
|
|
|
|
gdb_test "py test_bool (gdb.Value (0))" "nay" "check evaluation of false integer value in expression"
|
|
|
|
|
|
|
|
gdb_test "py test_bool (gdb.Value (5.2))" "yay" "check evaluation of true integer value in expression"
|
|
|
|
|
|
|
|
gdb_test "py test_bool (gdb.Value (0.0))" "nay" "check evaluation of false integer value in expression"
|
|
|
|
}
|
|
|
|
|
|
|
|
proc test_value_compare {} {
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "py print (gdb.Value (1) < gdb.Value (1))" "False" "less than, equal"
|
|
|
|
gdb_test "py print (gdb.Value (1) < gdb.Value (2))" "True" "less than, less"
|
|
|
|
gdb_test "py print (gdb.Value (2) < gdb.Value (1))" "False" "less than, greater"
|
|
|
|
gdb_test "py print (gdb.Value (2) < None)" "False" "less than, None"
|
|
|
|
|
|
|
|
gdb_test "py print (gdb.Value (1) <= gdb.Value (1))" "True" "less or equal, equal"
|
|
|
|
gdb_test "py print (gdb.Value (1) <= gdb.Value (2))" "True" "less or equal, less"
|
|
|
|
gdb_test "py print (gdb.Value (2) <= gdb.Value (1))" "False" "less or equal, greater"
|
|
|
|
gdb_test "py print (gdb.Value (2) <= None)" "False" "less or equal, None"
|
|
|
|
|
|
|
|
gdb_test "py print (gdb.Value (1) == gdb.Value (1))" "True" "equality of gdb.Values"
|
|
|
|
gdb_test "py print (gdb.Value (1) == gdb.Value (2))" "False" "inequality of gdb.Values"
|
|
|
|
gdb_test "py print (gdb.Value (1) == 1.0)" "True" "equality of gdb.Value with Python value"
|
|
|
|
gdb_test "py print (gdb.Value (1) == 2)" "False" "inequality of gdb.Value with Python value"
|
|
|
|
gdb_test "py print (gdb.Value (1) == None)" "False" "inequality of gdb.Value with None"
|
|
|
|
|
|
|
|
gdb_test "py print (gdb.Value (1) != gdb.Value (1))" "False" "inequality, false"
|
|
|
|
gdb_test "py print (gdb.Value (1) != gdb.Value (2))" "True" "inequality, true"
|
|
|
|
gdb_test "py print (gdb.Value (1) != None)" "True" "inequality, None"
|
|
|
|
|
|
|
|
gdb_test "py print (gdb.Value (1) > gdb.Value (1))" "False" "greater than, equal"
|
|
|
|
gdb_test "py print (gdb.Value (1) > gdb.Value (2))" "False" "greater than, less"
|
|
|
|
gdb_test "py print (gdb.Value (2) > gdb.Value (1))" "True" "greater than, greater"
|
|
|
|
gdb_test "py print (gdb.Value (2) > None)" "True" "greater than, None"
|
|
|
|
|
|
|
|
gdb_test "py print (gdb.Value (1) >= gdb.Value (1))" "True" "greater or equal, equal"
|
|
|
|
gdb_test "py print (gdb.Value (1) >= gdb.Value (2))" "False" "greater or equal, less"
|
|
|
|
gdb_test "py print (gdb.Value (2) >= gdb.Value (1))" "True" "greater or equal, greater"
|
|
|
|
gdb_test "py print (gdb.Value (2) >= None)" "True" "greater or equal, None"
|
2008-10-16 03:54:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
proc test_value_in_inferior {} {
|
|
|
|
global gdb_prompt
|
|
|
|
global testfile
|
2012-12-10 21:22:21 +00:00
|
|
|
global gdb_py_is_py3k
|
2008-10-16 03:54:00 +00:00
|
|
|
|
|
|
|
gdb_breakpoint [gdb_get_line_number "break to inspect struct and union"]
|
|
|
|
|
|
|
|
gdb_continue_to_breakpoint "break to inspect struct and union"
|
|
|
|
|
|
|
|
# Just get inferior variable s in the value history, available to python.
|
|
|
|
gdb_test "print s" " = {a = 3, b = 5}" ""
|
|
|
|
|
2009-02-04 21:55:40 +00:00
|
|
|
gdb_py_test_silent_cmd "python s = gdb.history (0)" "get value from history" 1
|
2008-10-16 03:54:00 +00:00
|
|
|
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print ('result = ' + str(s\['a'\]))" " = 3" "access element inside struct using 8-bit string name"
|
|
|
|
if { $gdb_py_is_py3k == 0 } {
|
|
|
|
gdb_test "python print ('result = ' + str(s\[u'a'\]))" " = 3" "access element inside struct using unicode name"
|
|
|
|
}
|
2008-10-16 03:54:00 +00:00
|
|
|
|
|
|
|
# Test dereferencing the argv pointer
|
|
|
|
|
|
|
|
# Just get inferior variable argv the value history, available to python.
|
|
|
|
gdb_test "print argv" " = \\(char \\*\\*\\) 0x.*" ""
|
|
|
|
|
2009-02-04 21:55:40 +00:00
|
|
|
gdb_py_test_silent_cmd "python argv = gdb.history (0)" "" 0
|
2008-10-16 03:54:00 +00:00
|
|
|
gdb_py_test_silent_cmd "python arg0 = argv.dereference ()" "dereference value" 1
|
|
|
|
|
|
|
|
# Check that the dereferenced value is sane
|
2010-02-16 21:13:10 +00:00
|
|
|
if { ! [target_info exists noargs] } {
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print (arg0)" "0x.*$testfile\"" "verify dereferenced value"
|
2010-02-16 21:13:10 +00:00
|
|
|
}
|
2009-03-26 20:58:11 +00:00
|
|
|
|
|
|
|
# Smoke-test is_optimized_out attribute
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print ('result = %s' % arg0.is_optimized_out)" "= False" "Test is_optimized_out attribute"
|
2009-03-29 21:11:11 +00:00
|
|
|
|
|
|
|
# Test address attribute
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print ('result = %s' % arg0.address)" "= 0x\[\[:xdigit:\]\]+" "Test address attribute"
|
2009-07-10 10:35:17 +00:00
|
|
|
|
2011-10-01 11:02:11 +00:00
|
|
|
# Test displaying a variable that is temporarily at a bad address.
|
|
|
|
# But if we can examine what's at memory address 0, then we'll also be
|
|
|
|
# able to display it without error. Don't run the test in that case.
|
2014-08-07 08:09:38 +00:00
|
|
|
set can_read_0 [is_address_zero_readable]
|
2011-10-01 11:02:11 +00:00
|
|
|
|
2010-11-12 20:49:43 +00:00
|
|
|
# Test memory error.
|
2011-10-01 11:02:11 +00:00
|
|
|
set test "parse_and_eval with memory error"
|
|
|
|
if {$can_read_0} {
|
|
|
|
untested $test
|
|
|
|
} else {
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print (gdb.parse_and_eval('*(int*)0'))" "gdb.MemoryError: Cannot access memory at address 0x0.*" $test
|
2011-10-01 11:02:11 +00:00
|
|
|
}
|
2010-11-12 20:49:43 +00:00
|
|
|
|
2011-10-25 18:35:49 +00:00
|
|
|
# Test Python lazy value handling
|
|
|
|
set test "memory error and lazy values"
|
2011-10-03 16:15:26 +00:00
|
|
|
if {$can_read_0} {
|
|
|
|
untested $test
|
|
|
|
} else {
|
2011-10-25 18:35:49 +00:00
|
|
|
gdb_test "python inval = gdb.parse_and_eval('*(int*)0')"
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print (inval.is_lazy)" "True"
|
2011-10-25 18:35:49 +00:00
|
|
|
gdb_test "python inval2 = inval+1" "gdb.MemoryError: Cannot access memory at address 0x0.*" $test
|
|
|
|
gdb_test "python inval.fetch_lazy ()" "gdb.MemoryError: Cannot access memory at address 0x0.*" $test
|
2011-10-03 16:15:26 +00:00
|
|
|
}
|
|
|
|
gdb_test "python argc_lazy = gdb.parse_and_eval('argc')"
|
2011-10-25 18:35:49 +00:00
|
|
|
gdb_test "python argc_notlazy = gdb.parse_and_eval('argc')"
|
|
|
|
gdb_test "python argc_notlazy.fetch_lazy()"
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print (argc_lazy.is_lazy)" "True"
|
|
|
|
gdb_test "python print (argc_notlazy.is_lazy)" "False"
|
2011-10-03 16:15:26 +00:00
|
|
|
gdb_test "print argc" " = 1" "sanity check argc"
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print (argc_lazy.is_lazy)" "\r\nTrue"
|
2011-10-03 16:15:26 +00:00
|
|
|
gdb_test_no_output "set argc=2"
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print (argc_notlazy)" "\r\n1"
|
|
|
|
gdb_test "python print (argc_lazy)" "\r\n2"
|
|
|
|
gdb_test "python print (argc_lazy.is_lazy)" "False"
|
2011-10-03 16:15:26 +00:00
|
|
|
|
2009-07-10 10:35:17 +00:00
|
|
|
# Test string fetches, both partial and whole.
|
|
|
|
gdb_test "print st" "\"divide et impera\""
|
|
|
|
gdb_py_test_silent_cmd "python st = gdb.history (0)" "get value from history" 1
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print (st.string ())" "divide et impera" "Test string with no length"
|
|
|
|
gdb_test "python print (st.string (length = -1))" "divide et impera" "Test string (length = -1) is all of the string"
|
|
|
|
gdb_test "python print (st.string (length = 6))" "divide"
|
|
|
|
gdb_test "python print (\"---\"+st.string (length = 0)+\"---\")" "------" "Test string (length = 0) is empty"
|
|
|
|
gdb_test "python print (len(st.string (length = 0)))" "0" "Test length is 0"
|
2009-07-10 10:35:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Fetch a string that has embedded nulls.
|
|
|
|
gdb_test "print nullst" "\"divide\\\\000et\\\\000impera\".*"
|
|
|
|
gdb_py_test_silent_cmd "python nullst = gdb.history (0)" "get value from history" 1
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print (nullst.string ())" "divide" "Test string to first null"
|
2009-07-10 10:35:17 +00:00
|
|
|
# Python cannot print strings that contain the null (\0) character.
|
|
|
|
# For the purposes of this test, use repr()
|
|
|
|
gdb_py_test_silent_cmd "python nullst = nullst.string (length = 9)" "get string beyond null" 1
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print (repr(nullst))" "u?'divide\\\\x00et'"
|
2013-12-11 00:20:08 +00:00
|
|
|
|
|
|
|
# Test fetching a string longer than its declared (in C) size.
|
|
|
|
# PR 16286
|
|
|
|
gdb_py_test_silent_cmd "python xstr = gdb.parse_and_eval('xstr')" "get xstr" 1
|
|
|
|
gdb_test "python print xstr\['text'\].string (length = xstr\['length'\])" "x{100}" \
|
|
|
|
"read string beyond declared size"
|
2008-10-16 03:54:00 +00:00
|
|
|
}
|
|
|
|
|
2010-01-14 08:03:37 +00:00
|
|
|
proc test_lazy_strings {} {
|
|
|
|
|
|
|
|
global hex
|
|
|
|
|
|
|
|
gdb_test "print sptr" "\"pointer\""
|
|
|
|
gdb_py_test_silent_cmd "python sptr = gdb.history (0)" "Get value from history" 1
|
|
|
|
|
|
|
|
gdb_py_test_silent_cmd "python lstr = sptr.lazy_string()" "Aquire lazy string" 1
|
2013-11-24 00:03:47 +00:00
|
|
|
gdb_test "python print (lstr.type)" "const char \*." "Test lazy-string type name equality"
|
|
|
|
gdb_test "python print (sptr.type)" "const char \*." "Test string type name equality"
|
2014-08-07 08:10:51 +00:00
|
|
|
|
|
|
|
# Prevent symbol on address 0x0 being printed.
|
|
|
|
gdb_test_no_output "set print symbol off"
|
2010-04-08 10:28:42 +00:00
|
|
|
gdb_test "print sn" "0x0"
|
2014-08-07 08:10:51 +00:00
|
|
|
|
2010-04-08 10:28:42 +00:00
|
|
|
gdb_py_test_silent_cmd "python snptr = gdb.history (0)" "Get value from history" 1
|
|
|
|
gdb_test "python snstr = snptr.lazy_string(length=5)" ".*Cannot create a lazy string with address.*" "Test lazy string"
|
|
|
|
gdb_py_test_silent_cmd "python snstr = snptr.lazy_string(length=0)" "Succesfully create a lazy string" 1
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print (snstr.length)" "0" "Test lazy string length"
|
|
|
|
gdb_test "python print (snstr.address)" "0" "Test lazy string address"
|
2010-01-14 08:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-27 12:40:42 +00:00
|
|
|
proc test_inferior_function_call {} {
|
|
|
|
global gdb_prompt hex decimal
|
|
|
|
|
|
|
|
# Correct inferior call without arguments.
|
|
|
|
gdb_test "p/x fp1" " = $hex.*"
|
|
|
|
gdb_py_test_silent_cmd "python fp1 = gdb.history (0)" "get value from history" 1
|
|
|
|
gdb_test "python fp1 = fp1.dereference()" ""
|
|
|
|
gdb_test "python result = fp1()" ""
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print (result)" "void"
|
2010-07-27 12:40:42 +00:00
|
|
|
|
|
|
|
# Correct inferior call with arguments.
|
|
|
|
gdb_test "p/x fp2" " = $hex.*"
|
|
|
|
gdb_py_test_silent_cmd "python fp2 = gdb.history (0)" "get value from history" 1
|
|
|
|
gdb_test "python fp2 = fp2.dereference()" ""
|
|
|
|
gdb_test "python result2 = fp2(10,20)" ""
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print (result2)" "30"
|
2010-07-27 12:40:42 +00:00
|
|
|
|
|
|
|
# Incorrect to call an int value.
|
|
|
|
gdb_test "p i" " = $decimal.*"
|
|
|
|
gdb_py_test_silent_cmd "python i = gdb.history (0)" "get value from history" 1
|
|
|
|
gdb_test "python result3 = i()" ".*Value is not callable.*"
|
|
|
|
|
|
|
|
# Incorrect number of arguments.
|
|
|
|
gdb_test "p/x fp2" " = $hex.*"
|
|
|
|
gdb_py_test_silent_cmd "python fp3 = gdb.history (0)" "get value from history" 1
|
|
|
|
gdb_test "python fp3 = fp3.dereference()" ""
|
|
|
|
gdb_test "python result2 = fp3(10)" ".*Too few arguments in function call.*"
|
|
|
|
}
|
|
|
|
|
2009-05-28 00:40:24 +00:00
|
|
|
# A few objfile tests.
|
|
|
|
proc test_objfiles {} {
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python\nok=False\nfor file in gdb.objfiles():\n if 'py-value' in file.filename:\n ok=True\nprint (ok)\nend" "True" \
|
2011-04-24 09:04:38 +00:00
|
|
|
"py-value in file.filename"
|
2009-05-28 00:40:24 +00:00
|
|
|
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print (gdb.objfiles()\[0\].pretty_printers)" "\\\[\\\]"
|
2009-05-28 00:40:24 +00:00
|
|
|
|
|
|
|
gdb_test "python gdb.objfiles()\[0\].pretty_printers = 0" \
|
|
|
|
"pretty_printers attribute must be a list.*Error while executing Python code."
|
|
|
|
}
|
2008-10-16 03:54:00 +00:00
|
|
|
|
2009-05-28 00:47:20 +00:00
|
|
|
proc test_value_after_death {} {
|
|
|
|
# Construct a type while the inferior is still running.
|
|
|
|
gdb_py_test_silent_cmd "python ptrtype = gdb.lookup_type('PTR')" \
|
|
|
|
"create PTR type" 1
|
|
|
|
|
|
|
|
# Kill the inferior and remove the symbols.
|
|
|
|
gdb_test "kill" "" "kill the inferior" \
|
|
|
|
"Kill the program being debugged. .y or n. $" \
|
|
|
|
"y"
|
|
|
|
gdb_test "file" "" "Discard the symbols" \
|
|
|
|
"Discard symbol table from.*y or n. $" \
|
|
|
|
"y"
|
|
|
|
|
|
|
|
# Now create a value using that type. Relies on arg0, created by
|
|
|
|
# test_value_in_inferior.
|
|
|
|
gdb_py_test_silent_cmd "python castval = arg0.cast(ptrtype.pointer())" \
|
|
|
|
"cast arg0 to PTR" 1
|
|
|
|
|
|
|
|
# Make sure the type is deleted.
|
|
|
|
gdb_py_test_silent_cmd "python ptrtype = None" \
|
|
|
|
"delete PTR type" 1
|
|
|
|
|
|
|
|
# Now see if the value's type is still valid.
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print (castval.type)" "PTR ." \
|
2009-05-28 00:47:20 +00:00
|
|
|
"print value's type"
|
|
|
|
}
|
|
|
|
|
2009-09-21 09:32:28 +00:00
|
|
|
# Regression test for invalid subscript operations. The bug was that
|
|
|
|
# the type of the value was not being checked before allowing a
|
|
|
|
# subscript operation to proceed.
|
|
|
|
|
2011-07-26 18:38:55 +00:00
|
|
|
proc test_subscript_regression {exefile lang} {
|
2009-09-21 09:32:28 +00:00
|
|
|
# Start with a fresh gdb.
|
2012-09-06 17:52:38 +00:00
|
|
|
clean_restart ${exefile}
|
2009-09-21 09:32:28 +00:00
|
|
|
|
|
|
|
if ![runto_main ] then {
|
|
|
|
perror "couldn't run to breakpoint"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if {$lang == "c++"} {
|
|
|
|
gdb_breakpoint [gdb_get_line_number "break to inspect pointer by reference"]
|
|
|
|
gdb_continue_to_breakpoint "break to inspect pointer by reference"
|
|
|
|
|
|
|
|
gdb_py_test_silent_cmd "print rptr_int" \
|
|
|
|
"Obtain address" 1
|
|
|
|
gdb_py_test_silent_cmd "python rptr = gdb.history(0)" \
|
|
|
|
"Obtains value from GDB" 1
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print (rptr\[0\])" "2" "Check pointer passed as reference"
|
2010-08-23 20:29:19 +00:00
|
|
|
|
|
|
|
# Just the most basic test of dynamic_cast -- it is checked in
|
|
|
|
# the C++ tests.
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print (bool(gdb.parse_and_eval('base').dynamic_cast(gdb.lookup_type('Derived').pointer())))" \
|
2010-08-23 20:29:19 +00:00
|
|
|
True
|
2010-08-30 20:28:31 +00:00
|
|
|
|
|
|
|
# Likewise.
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print (gdb.parse_and_eval('base').dynamic_type)" \
|
2010-08-30 20:28:31 +00:00
|
|
|
"Derived \[*\]"
|
2014-03-21 13:42:50 +00:00
|
|
|
gdb_test "python print (gdb.parse_and_eval('base_ref').dynamic_type)" \
|
|
|
|
"Derived \[&\]"
|
2010-08-30 20:28:31 +00:00
|
|
|
# A static type case.
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print (gdb.parse_and_eval('5').dynamic_type)" \
|
2010-08-30 20:28:31 +00:00
|
|
|
"int"
|
2009-09-21 09:32:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gdb_breakpoint [gdb_get_line_number "break to inspect struct and union"]
|
|
|
|
gdb_continue_to_breakpoint "break to inspect struct and union"
|
|
|
|
|
|
|
|
gdb_py_test_silent_cmd "python intv = gdb.Value(1)" \
|
|
|
|
"Create a value for subscript test" 1
|
|
|
|
gdb_py_test_silent_cmd "python stringv = gdb.Value(\"foo\")" \
|
|
|
|
"Create a value for subscript test" 1
|
|
|
|
|
|
|
|
# Try to access an int with a subscript. This should fail.
|
2013-11-24 00:03:47 +00:00
|
|
|
gdb_test "python print (intv)" "1" "Baseline print of an int Python value"
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print (intv\[0\])" "gdb.error: Cannot subscript requested type.*" \
|
2009-09-21 09:32:28 +00:00
|
|
|
"Attempt to access an integer with a subscript"
|
|
|
|
|
|
|
|
# Try to access a string with a subscript. This should pass.
|
2013-11-24 00:03:47 +00:00
|
|
|
gdb_test "python print (stringv)" "foo." "Baseline print of a string Python value"
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print (stringv\[0\])" "f." "Attempt to access a string with a subscript"
|
2009-09-21 09:32:28 +00:00
|
|
|
|
|
|
|
# Try to access an int array via a pointer with a subscript. This should pass.
|
|
|
|
gdb_py_test_silent_cmd "print p" "Build pointer to array" 1
|
|
|
|
gdb_py_test_silent_cmd "python pointer = gdb.history(0)" "" 1
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print (pointer\[0\])" "1" "Access array via pointer with int subscript"
|
|
|
|
gdb_test "python print (pointer\[intv\])" "2" "Access array via pointer with value subscript"
|
2009-09-21 09:32:28 +00:00
|
|
|
|
|
|
|
# Try to access a single dimension array with a subscript to the
|
|
|
|
# result. This should fail.
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print (pointer\[intv\]\[0\])" "gdb.error: Cannot subscript requested type.*" \
|
2009-09-21 09:32:28 +00:00
|
|
|
"Attempt to access an integer with a subscript"
|
|
|
|
|
|
|
|
# Lastly, test subscript access to an array with multiple
|
|
|
|
# dimensions. This should pass.
|
|
|
|
gdb_py_test_silent_cmd "print {\"fu \",\"foo\",\"bar\"}" "Build array" 1
|
|
|
|
gdb_py_test_silent_cmd "python marray = gdb.history(0)" "" 1
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print (marray\[1\]\[2\])" "o." "Test multiple subscript"
|
2009-09-21 09:32:28 +00:00
|
|
|
}
|
|
|
|
|
2009-12-03 18:30:02 +00:00
|
|
|
# A few tests of gdb.parse_and_eval.
|
|
|
|
proc test_parse_and_eval {} {
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print (gdb.parse_and_eval ('23'))" "23" \
|
2009-12-03 18:30:02 +00:00
|
|
|
"parse_and_eval constant test"
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print (gdb.parse_and_eval ('5 + 7'))" "12" \
|
2009-12-03 18:30:02 +00:00
|
|
|
"parse_and_eval simple expression test"
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print (type(gdb.parse_and_eval ('5 + 7')))" \
|
|
|
|
".(type|class) 'gdb.Value'."\
|
2009-12-03 18:30:02 +00:00
|
|
|
"parse_and_eval type test"
|
|
|
|
}
|
|
|
|
|
2010-05-14 11:11:28 +00:00
|
|
|
# Test that values are hashable.
|
|
|
|
proc test_value_hash {} {
|
|
|
|
gdb_py_test_multiple "Simple Python value dictionary" \
|
|
|
|
"python" "" \
|
|
|
|
"one = gdb.Value(1)" "" \
|
|
|
|
"two = gdb.Value(2)" "" \
|
|
|
|
"three = gdb.Value(3)" "" \
|
|
|
|
"vdict = {one:\"one str\",two:\"two str\",three:\"three str\"}" "" \
|
|
|
|
"end"
|
2012-12-10 21:22:21 +00:00
|
|
|
gdb_test "python print (vdict\[one\])" "one str" "Test dictionary hash"
|
|
|
|
gdb_test "python print (vdict\[two\])" "two str" "Test dictionary hash"
|
|
|
|
gdb_test "python print (vdict\[three\])" "three str" "Test dictionary hash"
|
|
|
|
gdb_test "python print (one.__hash__() == hash(one))" "True" "Test inbuilt hash"
|
2010-05-14 11:11:28 +00:00
|
|
|
}
|
|
|
|
|
2013-08-07 23:51:45 +00:00
|
|
|
# Build C version of executable. C++ is built later.
|
|
|
|
if { [build_inferior "${binfile}" "c"] < 0 } {
|
|
|
|
return -1
|
|
|
|
}
|
2010-05-14 11:11:28 +00:00
|
|
|
|
2008-10-16 03:54:00 +00:00
|
|
|
# Start with a fresh gdb.
|
2012-09-06 17:52:38 +00:00
|
|
|
clean_restart ${binfile}
|
2008-10-16 03:54:00 +00:00
|
|
|
|
2010-02-24 11:11:17 +00:00
|
|
|
# Skip all tests if Python scripting is not enabled.
|
|
|
|
if { [skip_python_tests] } { continue }
|
2008-10-16 03:54:00 +00:00
|
|
|
|
|
|
|
test_value_creation
|
|
|
|
test_value_numeric_ops
|
|
|
|
test_value_boolean
|
|
|
|
test_value_compare
|
2009-05-28 00:40:24 +00:00
|
|
|
test_objfiles
|
2009-12-03 18:30:02 +00:00
|
|
|
test_parse_and_eval
|
2010-05-14 11:11:28 +00:00
|
|
|
test_value_hash
|
2008-10-24 18:54:03 +00:00
|
|
|
|
|
|
|
# The following tests require execution.
|
|
|
|
|
|
|
|
if ![runto_main] then {
|
|
|
|
fail "Can't run to main"
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2008-10-16 03:54:00 +00:00
|
|
|
test_value_in_inferior
|
2010-07-27 12:40:42 +00:00
|
|
|
test_inferior_function_call
|
2010-01-14 08:03:37 +00:00
|
|
|
test_lazy_strings
|
2009-05-28 00:47:20 +00:00
|
|
|
test_value_after_death
|
2009-09-21 09:32:28 +00:00
|
|
|
|
2011-07-26 18:38:55 +00:00
|
|
|
# Test either C or C++ values.
|
2013-08-07 23:51:45 +00:00
|
|
|
|
2011-07-26 18:38:55 +00:00
|
|
|
test_subscript_regression "${binfile}" "c"
|
2013-08-07 23:51:45 +00:00
|
|
|
|
|
|
|
if ![skip_cplus_tests] {
|
|
|
|
if { [build_inferior "${binfile}-cxx" "c++"] < 0 } {
|
|
|
|
return -1
|
|
|
|
}
|
2013-11-24 00:03:47 +00:00
|
|
|
with_test_prefix "c++" {
|
|
|
|
test_subscript_regression "${binfile}-cxx" "c++"
|
|
|
|
}
|
2013-08-07 23:51:45 +00:00
|
|
|
}
|