]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - gdb/testsuite/gdb.python/py-function.exp
Update copyright year range in all GDB files.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.python / py-function.exp
index 461295de42e9812fc6fe31f6a532b727c7e90afc..76cc57d81c97700646a0f87fa5fa505a9ff52063 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2009, 2010 Free Software Foundation, Inc.
+# Copyright (C) 2009-2019 Free Software Foundation, Inc.
 
 # 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
 # This file is part of the GDB testsuite.  It tests the mechanism
 # exposing convenience functions to Python.
 
-if $tracelevel then {
-    strace $tracelevel
-}
-
-# Usage: gdb_py_test_multiple NAME INPUT RESULT {INPUT RESULT}...
-# Run a test named NAME, consisting of multiple lines of input.
-# After each input line INPUT, search for result line RESULT.
-# Succeed if all results are seen; fail otherwise.
-proc gdb_py_test_multiple {name args} {
-    global gdb_prompt
-    foreach {input result} $args {
-       if {[gdb_test_multiple $input "$name - $input" {
-           -re "\[\r\n\]*($result)\[\r\n\]+($gdb_prompt | *>)$" {
-               pass "$name - $input"
-           }
-       }]} {
-           return 1
-       }
-    }
-    return 0
-}
+load_lib gdb-python.exp
 
 # Start with a fresh gdb.
 
@@ -44,13 +24,8 @@ gdb_exit
 gdb_start
 gdb_reinitialize_dir $srcdir/$subdir
 
-gdb_test_multiple "python print 'hello, world!'" "verify python support" {
-    -re "not supported.*$gdb_prompt $" {
-      unsupported "python support is disabled"
-      return -1
-    }
-    -re "$gdb_prompt $"        {}
-}
+# Skip all tests if Python scripting is not enabled.
+if { [skip_python_tests] } { continue }
 
 gdb_py_test_multiple "input convenience function" \
   "python" "" \
@@ -90,3 +65,44 @@ gdb_py_test_multiple "input int-returning function" \
 
 gdb_test "print \$yes() && \$yes()" " = 1" "call yes with &&"
 gdb_test "print \$yes() || \$yes()" " = 1" "call yes with ||"
+
+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" ""
+
+gdb_test_no_output "set python print-stack full"
+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."
+
+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."