From 5374244e7a2a4849211f94c40762cde79ba1e08e Mon Sep 17 00:00:00 2001 From: Phil Muldoon Date: Tue, 27 Jul 2010 12:40:42 +0000 Subject: 2010-07-27 Phil Muldoon * python/py-value.c (valpy_call): New Function. 2010-07-27 Phil Muldoon * gdb.python/py-value.exp (test_inferior_function_call): New function. * gdb.python/py-value.c (func1): New function. (func2): Likewise. 2010-07-27 Phil Muldoon * gdb.texinfo (Values From Inferior): Add value inferior function call description. --- gdb/testsuite/gdb.python/py-value.c | 16 ++++++++++++++++ gdb/testsuite/gdb.python/py-value.exp | 30 ++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) (limited to 'gdb/testsuite/gdb.python') diff --git a/gdb/testsuite/gdb.python/py-value.c b/gdb/testsuite/gdb.python/py-value.c index be933b3..7481bd5 100644 --- a/gdb/testsuite/gdb.python/py-value.c +++ b/gdb/testsuite/gdb.python/py-value.c @@ -15,6 +15,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#include + struct s { int a; @@ -44,6 +46,16 @@ void ptr_ref(int*& rptr_int) } #endif +void func1 () +{ + printf ("void function called\n"); +} + +int func2 (int arg1, int arg2) +{ + return arg1 + arg2; +} + int main (int argc, char *argv[]) { @@ -53,6 +65,8 @@ main (int argc, char *argv[]) PTR x = &s; char st[17] = "divide et impera"; char nullst[17] = "divide\0et\0impera"; + void (*fp1) (void) = &func1; + int (*fp2) (int, int) = &func2; const char *sptr = "pointer"; const char *embed = "embedded x\201\202\203\204"; int a[3] = {1,2,3}; @@ -63,6 +77,8 @@ main (int argc, char *argv[]) s.a = 3; s.b = 5; u.a = 7; + (*fp1) (); + (*fp2) (10,20); #ifdef __cplusplus ptr_ref(ptr_i); diff --git a/gdb/testsuite/gdb.python/py-value.exp b/gdb/testsuite/gdb.python/py-value.exp index a24bc11..eaed9c7 100644 --- a/gdb/testsuite/gdb.python/py-value.exp +++ b/gdb/testsuite/gdb.python/py-value.exp @@ -276,6 +276,35 @@ proc test_lazy_strings {} { } +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()" "" + gdb_test "python print result" "void" + + # 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)" "" + gdb_test "python print result2" "30" + + # 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.*" +} + # A few objfile tests. proc test_objfiles {} { gdb_test "python\nok=False\nfor file in gdb.objfiles():\n if 'py-value' in file.filename:\n ok=True\nprint ok\nend" "True" @@ -435,6 +464,7 @@ if ![runto_main] then { } test_value_in_inferior +test_inferior_function_call test_lazy_strings test_value_after_death -- cgit v1.1