2012-01-04 08:28:28 +00:00
|
|
|
# Copyright (C) 2009-2012 Free Software Foundation, Inc.
|
gdb/
2009-03-05 Tom Tromey <tromey@redhat.com>
Add support for convenience functions in Python.
* Makefile.in (SUBDIR_PYTHON_OBS): Add python-function.o.
(SUBDIR_PYTHON_SRCS): Add python-function.c.
(python-function.o): New target.
* eval.c: Include "python/python.h" and <ctype.h>.
(evaluate_subexp_standard): Handle values of type
TYPE_CODE_INTERNAL_FUNCTION.
* gdbtypes.h (type_code): Add TYPE_CODE_INTERNAL_FUNCTION.
* parse.c (write_exp_string): Remove duplicate word in comment.
* python/python-function.c: New file.
* python/python-internal.h (gdbpy_initialize_functions): Add
prototype.
* python/python.c (_initialize_python): Call
gdbpy_initialize_functions.
* valprint.c (value_check_printable): Handle values of type
TYPE_CODE_INTERNAL_FUNCTION.
* value.c: Include "cli/cli-decode.h".
(internal_function): New struct.
(functionlist, internal_fn_type): New static variables.
(lookup_only_internalvar,
lookup_internalvar): Add const qualifier to name argument.
(create_internalvar): Likewise. Initialize new field.
(set_internal_var): Fix typo in comment. Don't allow assignment
to canonical variable.
(value_create_internal_function, value_internal_function_name,
call_internal_function, function_command, function_destroyer,
add_internal_function): New functions.
(_initialize_values): Create `function' placeholder command.
Initialize internal_fn_type.
* value.h (lookup_only_internalvar, create_internalvar,
lookup_internalvar): Add const qualifier to name argument.
(internal_function_fn, add_internal_function, call_internal_function,
value_internal_function_name): Add prototypes.
(struct internalvar) <canonical>: New field.
gdb/doc/
2008-03-05 Tom Tromey <tromey@redhat.com>
* gdb.texinfo (Convenience Vars): Document convenience functions.
(Functions In Python): New node.
(Python API): Update.
gdb/testsuite/
2009-03-05 Thiago Jung Bauermann <bauerman@br.ibm.com>
* gdb.python/python-function.exp: New file.
2009-03-21 03:03:56 +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 convenience functions to Python.
|
|
|
|
|
2011-01-10 11:00:24 +00:00
|
|
|
load_lib gdb-python.exp
|
gdb/
2009-03-05 Tom Tromey <tromey@redhat.com>
Add support for convenience functions in Python.
* Makefile.in (SUBDIR_PYTHON_OBS): Add python-function.o.
(SUBDIR_PYTHON_SRCS): Add python-function.c.
(python-function.o): New target.
* eval.c: Include "python/python.h" and <ctype.h>.
(evaluate_subexp_standard): Handle values of type
TYPE_CODE_INTERNAL_FUNCTION.
* gdbtypes.h (type_code): Add TYPE_CODE_INTERNAL_FUNCTION.
* parse.c (write_exp_string): Remove duplicate word in comment.
* python/python-function.c: New file.
* python/python-internal.h (gdbpy_initialize_functions): Add
prototype.
* python/python.c (_initialize_python): Call
gdbpy_initialize_functions.
* valprint.c (value_check_printable): Handle values of type
TYPE_CODE_INTERNAL_FUNCTION.
* value.c: Include "cli/cli-decode.h".
(internal_function): New struct.
(functionlist, internal_fn_type): New static variables.
(lookup_only_internalvar,
lookup_internalvar): Add const qualifier to name argument.
(create_internalvar): Likewise. Initialize new field.
(set_internal_var): Fix typo in comment. Don't allow assignment
to canonical variable.
(value_create_internal_function, value_internal_function_name,
call_internal_function, function_command, function_destroyer,
add_internal_function): New functions.
(_initialize_values): Create `function' placeholder command.
Initialize internal_fn_type.
* value.h (lookup_only_internalvar, create_internalvar,
lookup_internalvar): Add const qualifier to name argument.
(internal_function_fn, add_internal_function, call_internal_function,
value_internal_function_name): Add prototypes.
(struct internalvar) <canonical>: New field.
gdb/doc/
2008-03-05 Tom Tromey <tromey@redhat.com>
* gdb.texinfo (Convenience Vars): Document convenience functions.
(Functions In Python): New node.
(Python API): Update.
gdb/testsuite/
2009-03-05 Thiago Jung Bauermann <bauerman@br.ibm.com>
* gdb.python/python-function.exp: New file.
2009-03-21 03:03:56 +00:00
|
|
|
|
|
|
|
# Start with a fresh gdb.
|
|
|
|
|
|
|
|
gdb_exit
|
|
|
|
gdb_start
|
|
|
|
gdb_reinitialize_dir $srcdir/$subdir
|
|
|
|
|
2010-02-24 11:11:17 +00:00
|
|
|
# Skip all tests if Python scripting is not enabled.
|
|
|
|
if { [skip_python_tests] } { continue }
|
gdb/
2009-03-05 Tom Tromey <tromey@redhat.com>
Add support for convenience functions in Python.
* Makefile.in (SUBDIR_PYTHON_OBS): Add python-function.o.
(SUBDIR_PYTHON_SRCS): Add python-function.c.
(python-function.o): New target.
* eval.c: Include "python/python.h" and <ctype.h>.
(evaluate_subexp_standard): Handle values of type
TYPE_CODE_INTERNAL_FUNCTION.
* gdbtypes.h (type_code): Add TYPE_CODE_INTERNAL_FUNCTION.
* parse.c (write_exp_string): Remove duplicate word in comment.
* python/python-function.c: New file.
* python/python-internal.h (gdbpy_initialize_functions): Add
prototype.
* python/python.c (_initialize_python): Call
gdbpy_initialize_functions.
* valprint.c (value_check_printable): Handle values of type
TYPE_CODE_INTERNAL_FUNCTION.
* value.c: Include "cli/cli-decode.h".
(internal_function): New struct.
(functionlist, internal_fn_type): New static variables.
(lookup_only_internalvar,
lookup_internalvar): Add const qualifier to name argument.
(create_internalvar): Likewise. Initialize new field.
(set_internal_var): Fix typo in comment. Don't allow assignment
to canonical variable.
(value_create_internal_function, value_internal_function_name,
call_internal_function, function_command, function_destroyer,
add_internal_function): New functions.
(_initialize_values): Create `function' placeholder command.
Initialize internal_fn_type.
* value.h (lookup_only_internalvar, create_internalvar,
lookup_internalvar): Add const qualifier to name argument.
(internal_function_fn, add_internal_function, call_internal_function,
value_internal_function_name): Add prototypes.
(struct internalvar) <canonical>: New field.
gdb/doc/
2008-03-05 Tom Tromey <tromey@redhat.com>
* gdb.texinfo (Convenience Vars): Document convenience functions.
(Functions In Python): New node.
(Python API): Update.
gdb/testsuite/
2009-03-05 Thiago Jung Bauermann <bauerman@br.ibm.com>
* gdb.python/python-function.exp: New file.
2009-03-21 03:03:56 +00:00
|
|
|
|
|
|
|
gdb_py_test_multiple "input convenience function" \
|
|
|
|
"python" "" \
|
|
|
|
"class test_func (gdb.Function):" "" \
|
|
|
|
" def __init__ (self):" "" \
|
|
|
|
" super (test_func, self).__init__ (\"test_func\")" "" \
|
|
|
|
" def invoke (self, arg):" "" \
|
|
|
|
" return \"test_func output, arg = %s\" % arg.string ()" "" \
|
|
|
|
"test_func ()" "" \
|
|
|
|
"end" ""
|
|
|
|
|
|
|
|
gdb_test "print \$test_func (\"ugh\")" "= \"test_func output, arg = ugh\"" "call function"
|
2009-03-21 03:13:02 +00:00
|
|
|
|
|
|
|
# Test returning a gdb.Value from the function. This segfaulted GDB at one point.
|
|
|
|
|
|
|
|
gdb_py_test_multiple "input value-returning convenience function" \
|
|
|
|
"python" "" \
|
|
|
|
"class Double (gdb.Function):" "" \
|
|
|
|
" def __init__ (self):" "" \
|
|
|
|
" super (Double, self).__init__ (\"double\")" "" \
|
|
|
|
" def invoke (self, n):" "" \
|
|
|
|
" return n*2" "" \
|
|
|
|
"Double ()" "" \
|
|
|
|
"end" ""
|
|
|
|
|
|
|
|
gdb_test "print \$double (1)" "= 2" "call value-returning function"
|
2009-09-22 17:39:54 +00:00
|
|
|
|
|
|
|
gdb_py_test_multiple "input int-returning function" \
|
|
|
|
"python" "" \
|
|
|
|
"class Yes(gdb.Function):" "" \
|
|
|
|
" def __init__(self):" "" \
|
|
|
|
" gdb.Function.__init__(self, 'yes')" "" \
|
|
|
|
" def invoke(self):" "" \
|
|
|
|
" return 1" "" \
|
|
|
|
"Yes ()" "" \
|
|
|
|
"end" ""
|
|
|
|
|
|
|
|
gdb_test "print \$yes() && \$yes()" " = 1" "call yes with &&"
|
|
|
|
gdb_test "print \$yes() || \$yes()" " = 1" "call yes with ||"
|
2011-03-22 09:38:16 +00:00
|
|
|
|
|
|
|
gdb_py_test_multiple "Test GDBError" \
|
|
|
|
"python" "" \
|
|
|
|
"class GDBError(gdb.Function):" "" \
|
|
|
|
" def __init__(self):" "" \
|
|
|
|
" gdb.Function.__init__(self, 'gdberror')" "" \
|
|
|
|
" def invoke(self):" "" \
|
|
|
|
" raise gdb.GdbError(\"This is a GdbError\")" "" \
|
|
|
|
"GDBError ()" "" \
|
|
|
|
"end" ""
|
|
|
|
|
|
|
|
gdb_test "print \$gdberror()" "This is a GdbError.*" \
|
|
|
|
"Test GdbError. There should not be a stack trace"
|
|
|
|
|
|
|
|
gdb_py_test_multiple "Test Normal Error" \
|
|
|
|
"python" "" \
|
|
|
|
"class NormalError(gdb.Function):" "" \
|
|
|
|
" def __init__(self):" "" \
|
|
|
|
" gdb.Function.__init__(self, 'normalerror')" "" \
|
|
|
|
" def invoke(self):" "" \
|
|
|
|
" raise RuntimeError(\"This is a Normal Error\")" "" \
|
|
|
|
"NormalError ()" "" \
|
|
|
|
"end" ""
|
|
|
|
|
2011-12-16 15:55:40 +00:00
|
|
|
gdb_test_no_output "set python print-stack full"
|
2011-03-22 09:38:16 +00:00
|
|
|
gdb_test "print \$normalerror()" "Traceback.*File.*line 5.*in invoke.*RuntimeError.*This is a Normal Error.*" \
|
|
|
|
"Test a Runtime error. There should be a stack trace."
|
2011-05-13 04:34:25 +00:00
|
|
|
|
|
|
|
gdb_py_test_multiple "input command-calling function" \
|
|
|
|
"python" "" \
|
|
|
|
"class CallCommand(gdb.Function):" "" \
|
|
|
|
" def __init__(self):" "" \
|
|
|
|
" gdb.Function.__init__(self, 'call_command')" "" \
|
|
|
|
" def invoke(self):" "" \
|
|
|
|
" return gdb.execute('print 1', to_string=True)" "" \
|
|
|
|
"CallCommand ()" "" \
|
|
|
|
"end" ""
|
|
|
|
|
|
|
|
gdb_test_no_output "set var \$foo = \$call_command()" "Setting a value from a function which executes a command."
|
|
|
|
# There was a bug where GDB would segfault in the second call, so try calling again.
|
|
|
|
gdb_test_no_output "set var \$foo = \$call_command()" "Setting a value from a function which executes a command, again."
|