aboutsummaryrefslogtreecommitdiff
path: root/gdb/python/py-function.c
diff options
context:
space:
mode:
authorPhil Muldoon <pmuldoon@redhat.com>2011-03-22 09:38:16 +0000
committerPhil Muldoon <pmuldoon@redhat.com>2011-03-22 09:38:16 +0000
commit057758407cda4549e446ab0d061482ae6f7cd021 (patch)
tree6e8fd30479844b71cb0f42ecf9034cd8e7fd6116 /gdb/python/py-function.c
parent07aead7b6735a00e1d1fd4ce265a64bdfda15c77 (diff)
downloadgdb-057758407cda4549e446ab0d061482ae6f7cd021.zip
gdb-057758407cda4549e446ab0d061482ae6f7cd021.tar.gz
gdb-057758407cda4549e446ab0d061482ae6f7cd021.tar.bz2
2011-03-21 Phil Muldoon <pmuldoon@redhat.com>
PR python/12183 * python/py-function.c (fnpy_call): Treat GdbErrors differently to other error classes. Do not print stack trace. 2011-03-21 Phil Muldoon <pmuldoon@redhat.com> PR python/12183 * gdb.python/py-function.exp: Add GdbError tests.
Diffstat (limited to 'gdb/python/py-function.c')
-rw-r--r--gdb/python/py-function.c51
1 files changed, 49 insertions, 2 deletions
diff --git a/gdb/python/py-function.c b/gdb/python/py-function.c
index 47d916b..0c3e6f2 100644
--- a/gdb/python/py-function.c
+++ b/gdb/python/py-function.c
@@ -79,8 +79,55 @@ fnpy_call (struct gdbarch *gdbarch, const struct language_defn *language,
if (!result)
{
- gdbpy_print_stack ();
- error (_("Error while executing Python code."));
+ PyObject *ptype, *pvalue, *ptraceback;
+ char *msg;
+
+ PyErr_Fetch (&ptype, &pvalue, &ptraceback);
+
+ /* Try to fetch an error message contained within ptype, pvalue.
+ When fetching the error message we need to make our own copy,
+ we no longer own ptype, pvalue after the call to PyErr_Restore. */
+
+ msg = gdbpy_exception_to_string (ptype, pvalue);
+ make_cleanup (xfree, msg);
+
+ if (msg == NULL)
+ {
+ /* An error occurred computing the string representation of the
+ error message. This is rare, but we should inform the user. */
+
+ printf_filtered (_("An error occurred in a Python "
+ "convenience function\n"
+ "and then another occurred computing the "
+ "error message.\n"));
+ gdbpy_print_stack ();
+ }
+
+ /* Don't print the stack for gdb.GdbError exceptions.
+ It is generally used to flag user errors.
+
+ We also don't want to print "Error occurred in Python command"
+ for user errors. However, a missing message for gdb.GdbError
+ exceptions is arguably a bug, so we flag it as such. */
+
+ if (!PyErr_GivenExceptionMatches (ptype, gdbpy_gdberror_exc)
+ || msg == NULL || *msg == '\0')
+ {
+ PyErr_Restore (ptype, pvalue, ptraceback);
+ gdbpy_print_stack ();
+ if (msg != NULL && *msg != '\0')
+ error (_("Error occurred in Python convenience function: %s"),
+ msg);
+ else
+ error (_("Error occurred in Python convenience function."));
+ }
+ else
+ {
+ Py_XDECREF (ptype);
+ Py_XDECREF (pvalue);
+ Py_XDECREF (ptraceback);
+ error ("%s", msg);
+ }
}
value = convert_value_from_python (result);