1 # Copyright (C) 2009, 2010, 2011 Free Software Foundation, Inc.
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.
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.
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/>.
16 # This file is part of the GDB testsuite. It tests the mechanism
17 # exposing convenience functions to Python.
23 load_lib gdb-python.exp
25 # Start with a fresh gdb.
29 gdb_reinitialize_dir $srcdir/$subdir
31 # Skip all tests if Python scripting is not enabled.
32 if { [skip_python_tests] } { continue }
34 gdb_py_test_multiple "input convenience function" \
36 "class test_func (gdb.Function):" "" \
37 " def __init__ (self):" "" \
38 " super (test_func, self).__init__ (\"test_func\")" "" \
39 " def invoke (self, arg):" "" \
40 " return \"test_func output, arg = %s\" % arg.string ()" "" \
44 gdb_test "print \$test_func (\"ugh\")" "= \"test_func output, arg = ugh\"" "call function"
46 # Test returning a gdb.Value from the function. This segfaulted GDB at one point.
48 gdb_py_test_multiple "input value-returning convenience function" \
50 "class Double (gdb.Function):" "" \
51 " def __init__ (self):" "" \
52 " super (Double, self).__init__ (\"double\")" "" \
53 " def invoke (self, n):" "" \
58 gdb_test "print \$double (1)" "= 2" "call value-returning function"
60 gdb_py_test_multiple "input int-returning function" \
62 "class Yes(gdb.Function):" "" \
63 " def __init__(self):" "" \
64 " gdb.Function.__init__(self, 'yes')" "" \
65 " def invoke(self):" "" \
70 gdb_test "print \$yes() && \$yes()" " = 1" "call yes with &&"
71 gdb_test "print \$yes() || \$yes()" " = 1" "call yes with ||"