aboutsummaryrefslogtreecommitdiff
path: root/gdb/python/py-function.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2018-09-15 00:57:12 -0600
committerTom Tromey <tom@tromey.com>2018-09-23 23:15:12 -0600
commit2b4ad2fe4300489fd40dbe07e1675ff1cf0bee58 (patch)
tree457da478463cdd8a535b0337d9d19d0096c8805d /gdb/python/py-function.c
parentfd3ba736db19d4c7cd928f3735329339a8c8ef47 (diff)
downloadbinutils-2b4ad2fe4300489fd40dbe07e1675ff1cf0bee58.zip
binutils-2b4ad2fe4300489fd40dbe07e1675ff1cf0bee58.tar.gz
binutils-2b4ad2fe4300489fd40dbe07e1675ff1cf0bee58.tar.bz2
Consolidate gdb.GdbError handling
I noticed two nearly identical copies of the same code for handling gdb.GdbError. The only differences were in some error messages. These differences didn't seem very important, so this patch pulls the code out into a new function. 2018-09-23 Tom Tromey <tom@tromey.com> * python/py-function.c (fnpy_call): Use gdbpy_handle_exception. * python/py-cmd.c (cmdpy_function): Use gdbpy_handle_exception. * python/python-internal.h (gdbpy_handle_exception): Declare. * python/py-utils.c (gdbpy_handle_exception): New function.
Diffstat (limited to 'gdb/python/py-function.c')
-rw-r--r--gdb/python/py-function.c51
1 files changed, 1 insertions, 50 deletions
diff --git a/gdb/python/py-function.c b/gdb/python/py-function.c
index c461231..1900f0f 100644
--- a/gdb/python/py-function.c
+++ b/gdb/python/py-function.c
@@ -83,56 +83,7 @@ fnpy_call (struct gdbarch *gdbarch, const struct language_defn *language,
}
if (result == NULL)
- {
- PyObject *ptype, *pvalue, *ptraceback;
-
- 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. */
-
- gdb::unique_xmalloc_ptr<char>
- msg (gdbpy_exception_to_string (ptype, pvalue));
-
- 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.get ());
- else
- error (_("Error occurred in Python convenience function."));
- }
- else
- {
- Py_XDECREF (ptype);
- Py_XDECREF (pvalue);
- Py_XDECREF (ptraceback);
- error ("%s", msg.get ());
- }
- }
+ gdbpy_handle_exception ();
value = convert_value_from_python (result.get ());
if (value == NULL)