2011-01-01 15:34:07 +00:00
|
|
|
# Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
|
2008-08-06 19:41:33 +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.
|
|
|
|
|
|
|
|
if $tracelevel then {
|
|
|
|
strace $tracelevel
|
|
|
|
}
|
|
|
|
|
2010-10-01 17:03:50 +00:00
|
|
|
load_lib gdb-python.exp
|
|
|
|
|
2010-08-11 12:48:24 +00:00
|
|
|
set testfile "python"
|
|
|
|
set srcfile ${testfile}.c
|
2010-08-19 17:00:58 +00:00
|
|
|
set srcfile1 ${testfile}-1.c
|
2010-08-11 12:48:24 +00:00
|
|
|
set binfile ${objdir}/${subdir}/${testfile}
|
|
|
|
|
2010-08-19 17:00:58 +00:00
|
|
|
if { [gdb_compile "${srcdir}/${subdir}/${srcfile} ${srcdir}/${subdir}/${srcfile1}" \
|
|
|
|
${binfile} executable {debug}] != "" } {
|
2010-08-11 12:48:24 +00:00
|
|
|
untested "Could not compile $binfile."
|
|
|
|
return -1
|
|
|
|
}
|
2008-08-06 19:41:33 +00:00
|
|
|
|
2010-08-11 12:48:24 +00:00
|
|
|
# Start with a fresh gdb.
|
2008-08-06 19:41:33 +00:00
|
|
|
gdb_exit
|
|
|
|
gdb_start
|
|
|
|
gdb_reinitialize_dir $srcdir/$subdir
|
|
|
|
|
2010-08-11 12:48:24 +00:00
|
|
|
# Skip all tests if Python scripting is not enabled.
|
|
|
|
if { [skip_python_tests] } { continue }
|
|
|
|
|
2008-08-06 19:41:33 +00:00
|
|
|
gdb_test_multiple "python print 23" "verify python support" {
|
|
|
|
-re "not supported.*$gdb_prompt $" {
|
|
|
|
unsupported "python support is disabled"
|
2010-01-18 06:31:24 +00:00
|
|
|
|
|
|
|
# If Python is not supported, verify that sourcing a python script
|
|
|
|
# causes an error.
|
|
|
|
gdb_test "source $srcdir/$subdir/source2.py" "Error in sourced command file:.*"
|
2008-08-06 19:41:33 +00:00
|
|
|
return -1
|
|
|
|
}
|
|
|
|
-re "$gdb_prompt $" {}
|
|
|
|
}
|
|
|
|
|
|
|
|
gdb_py_test_multiple "multi-line python command" \
|
|
|
|
"python" "" \
|
|
|
|
"print 23" "" \
|
|
|
|
"end" "23"
|
|
|
|
|
|
|
|
gdb_py_test_multiple "show python command" \
|
|
|
|
"define zzq" "Type commands for definition of .* just \"end\"\\.*" \
|
|
|
|
"python" "" \
|
|
|
|
"print 23" "" \
|
|
|
|
"end" "" \
|
|
|
|
"end" "" \
|
2009-01-14 20:40:09 +00:00
|
|
|
"show user zzq" "User command \"zzq\":.* python.*print 23.* end"
|
2008-08-16 20:36:30 +00:00
|
|
|
|
|
|
|
gdb_py_test_multiple "indented multi-line python command" \
|
|
|
|
"python" "" \
|
|
|
|
"def foo ():" "" \
|
|
|
|
" print 'hello, world!'" "" \
|
|
|
|
"foo ()" "" \
|
|
|
|
"end" "hello, world!"
|
2009-05-28 00:40:24 +00:00
|
|
|
|
2010-01-18 06:31:24 +00:00
|
|
|
gdb_test "source $srcdir/$subdir/source2.py" "yes"
|
|
|
|
|
2009-05-28 00:40:24 +00:00
|
|
|
gdb_test "python print gdb.current_objfile()" "None"
|
|
|
|
gdb_test "python print gdb.objfiles()" "\\\[\\\]"
|
2010-06-08 16:41:45 +00:00
|
|
|
|
|
|
|
# Test http://bugs.python.org/issue4434 workaround in configure.ac
|
|
|
|
gdb_test "python import itertools; print 'IMPOR'+'TED'" "IMPORTED" "pythonX.Y/lib-dynload/*.so"
|
2010-06-25 18:15:18 +00:00
|
|
|
|
|
|
|
gdb_test_no_output \
|
|
|
|
"python x = gdb.execute('printf \"%d\", 23', to_string = True)"
|
|
|
|
gdb_test "python print x" "23"
|
2010-08-07 15:00:39 +00:00
|
|
|
|
2010-08-11 20:54:12 +00:00
|
|
|
# Test post_event.
|
|
|
|
gdb_py_test_multiple "post event insertion" \
|
|
|
|
"python" "" \
|
|
|
|
"someVal = 0" "" \
|
2010-08-16 18:01:40 +00:00
|
|
|
"class Foo(object):" "" \
|
2010-08-11 20:54:12 +00:00
|
|
|
" def __call__(self):" "" \
|
|
|
|
" global someVal" "" \
|
|
|
|
" someVal += 1" "" \
|
|
|
|
"gdb.post_event(Foo())" "" \
|
|
|
|
"end" ""
|
|
|
|
|
|
|
|
gdb_test "python print someVal" "1" "test post event execution"
|
|
|
|
gdb_test "python gdb.post_event(str(1))" "RuntimeError: Posted event is not callable.*" "Test non callable class"
|
|
|
|
|
2010-08-07 15:00:39 +00:00
|
|
|
# Test (no) pagination of the executed command.
|
|
|
|
gdb_test "show height" {Number of lines gdb thinks are in a page is unlimited\.}
|
|
|
|
set lines 10
|
|
|
|
gdb_test_no_output "set height $lines"
|
|
|
|
|
|
|
|
set test "verify pagination beforehand"
|
|
|
|
gdb_test_multiple "python print \"\\n\" * $lines" $test {
|
|
|
|
-re "---Type <return> to continue, or q <return> to quit---$" {
|
|
|
|
pass $test
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gdb_test "q" "Quit" "verify pagination beforehand: q"
|
|
|
|
|
|
|
|
gdb_test "python if gdb.execute('python print \"\\\\n\" * $lines', to_string=True) == \"\\n\" * [expr $lines + 1]: print \"yes\"" "yes" "gdb.execute does not page"
|
|
|
|
|
|
|
|
set test "verify pagination afterwards"
|
|
|
|
gdb_test_multiple "python print \"\\n\" * $lines" $test {
|
|
|
|
-re "---Type <return> to continue, or q <return> to quit---$" {
|
|
|
|
pass $test
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gdb_test "q" "Quit" "verify pagination afterwards: q"
|
2010-08-11 12:48:24 +00:00
|
|
|
|
2010-09-11 16:00:27 +00:00
|
|
|
gdb_test_no_output "set height 0"
|
|
|
|
|
|
|
|
gdb_test_no_output "python a = gdb.execute('help', to_string=True)" "collect help from uiout"
|
|
|
|
|
|
|
|
gdb_test "python print a" ".*aliases -- Aliases of other commands.*" "verify help to uiout"
|
|
|
|
|
2010-11-23 13:33:23 +00:00
|
|
|
# Test PR 12212, using InfThread.selected_thread() when no inferior is
|
|
|
|
# loaded.
|
|
|
|
gdb_py_test_silent_cmd "python nothread = gdb.selected_thread()" "Attempt to aquire thread with no inferior" 1
|
|
|
|
gdb_test "python print nothread == None" "True" "Ensure that no threads are returned"
|
|
|
|
|
2010-08-11 12:48:24 +00:00
|
|
|
# Start with a fresh gdb.
|
|
|
|
clean_restart ${testfile}
|
|
|
|
|
|
|
|
# The following tests require execution.
|
|
|
|
|
|
|
|
if ![runto_main] then {
|
|
|
|
fail "Can't run to main"
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
runto [gdb_get_line_number "Break to end."]
|
|
|
|
|
|
|
|
# Test gdb.decode_line.
|
|
|
|
gdb_test "python gdb.decode_line(\"main.c:43\")" \
|
2010-11-12 20:49:43 +00:00
|
|
|
"gdb.error: No source file named main.c.*" "test decode_line no source named main"
|
2010-08-11 12:48:24 +00:00
|
|
|
|
|
|
|
gdb_py_test_silent_cmd "python symtab = gdb.decode_line()" "test decode_line current location" 1
|
|
|
|
gdb_test "python print len(symtab)" "2" "Test decode_line current location"
|
|
|
|
gdb_test "python print symtab\[0\]" "None" "Test decode_line expression parse"
|
|
|
|
gdb_test "python print len(symtab\[1\])" "1" "Test decode_line current location"
|
|
|
|
gdb_test "python print symtab\[1\]\[0\].symtab" "gdb/testsuite/gdb.python/python.c.*" "Test decode_line current locationn filename"
|
|
|
|
gdb_test "python print symtab\[1\]\[0\].line" "22" "Test decode_line current location line number"
|
|
|
|
|
|
|
|
gdb_py_test_silent_cmd "python symtab = gdb.decode_line(\"python.c:26 if foo\")" "test decode_line python.c:26" 1
|
|
|
|
gdb_test "python print len(symtab)" "2" "Test decode_line python.c:26 length"
|
|
|
|
gdb_test "python print symtab\[0\]" "if foo" "Test decode_line expression parse"
|
|
|
|
gdb_test "python print len(symtab\[1\])" "1" "Test decode_line python.c:26 length"
|
|
|
|
gdb_test "python print symtab\[1\]\[0\].symtab" "gdb/testsuite/gdb.python/python.c.*" "Test decode_line python.c:26 filename"
|
|
|
|
gdb_test "python print symtab\[1\]\[0\].line" "26" "Test decode_line python.c:26 line number"
|
|
|
|
|
|
|
|
gdb_test "python gdb.decode_line(\"randomfunc\")" \
|
2010-11-12 20:49:43 +00:00
|
|
|
"gdb.error: Function \"randomfunc\" not defined.*" "test decode_line randomfunc"
|
2010-08-11 12:48:24 +00:00
|
|
|
gdb_py_test_silent_cmd "python symtab = gdb.decode_line(\"func1\")" "test decode_line func1()" 1
|
|
|
|
gdb_test "python print len(symtab)" "2" "Test decode_line func1 length"
|
|
|
|
gdb_test "python print len(symtab\[1\])" "1" "Test decode_line func1 length"
|
2010-08-19 17:00:58 +00:00
|
|
|
gdb_test "python print symtab\[1\]\[0\].symtab" "gdb/testsuite/gdb.python/python-1.c.*" "Test decode_line func1 filename"
|
2010-08-11 12:48:24 +00:00
|
|
|
gdb_test "python print symtab\[1\]\[0\].line" "19" "Test decode_line func1 line number"
|