forked from Imagelibrary/binutils-gdb
Consolidate some Python exception-printing functions
A few places in the Python code would either call gdbpy_print_stack, or throw a gdb "quit", depending on the pending exception. This patch consolidates these into a helper function. gdb/ChangeLog 2018-12-27 Tom Tromey <tom@tromey.com> * python/python-internal.h (gdbpy_print_stack_or_quit): Declare. * python/py-unwind.c (pyuw_sniffer): Use gdbpy_print_stack_or_quit. * python/py-framefilter.c (throw_quit_or_print_exception): Remove. (gdbpy_apply_frame_filter): Use gdbpy_print_stack_or_quit. * python/python.c (gdbpy_print_stack_or_quit): New function.
This commit is contained in:
@@ -1,3 +1,13 @@
|
|||||||
|
2018-12-27 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
|
* python/python-internal.h (gdbpy_print_stack_or_quit): Declare.
|
||||||
|
* python/py-unwind.c (pyuw_sniffer): Use
|
||||||
|
gdbpy_print_stack_or_quit.
|
||||||
|
* python/py-framefilter.c (throw_quit_or_print_exception):
|
||||||
|
Remove.
|
||||||
|
(gdbpy_apply_frame_filter): Use gdbpy_print_stack_or_quit.
|
||||||
|
* python/python.c (gdbpy_print_stack_or_quit): New function.
|
||||||
|
|
||||||
2018-12-27 Tom Tromey <tom@tromey.com>
|
2018-12-27 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
* python/py-value.c (convert_value_from_python): Use
|
* python/py-value.c (convert_value_from_python): Use
|
||||||
|
|||||||
@@ -1054,21 +1054,6 @@ bootstrap_python_frame_filters (struct frame_info *frame,
|
|||||||
return iterable.release ();
|
return iterable.release ();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* A helper function that will either print an exception or, if it is
|
|
||||||
a KeyboardException, throw a quit. This can only be called when
|
|
||||||
the Python exception is set. */
|
|
||||||
|
|
||||||
static void
|
|
||||||
throw_quit_or_print_exception ()
|
|
||||||
{
|
|
||||||
if (PyErr_ExceptionMatches (PyExc_KeyboardInterrupt))
|
|
||||||
{
|
|
||||||
PyErr_Clear ();
|
|
||||||
throw_quit ("Quit");
|
|
||||||
}
|
|
||||||
gdbpy_print_stack ();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* This is the only publicly exported function in this file. FRAME
|
/* This is the only publicly exported function in this file. FRAME
|
||||||
is the source frame to start frame-filter invocation. FLAGS is an
|
is the source frame to start frame-filter invocation. FLAGS is an
|
||||||
integer holding the flags for printing. The following elements of
|
integer holding the flags for printing. The following elements of
|
||||||
@@ -1139,7 +1124,7 @@ gdbpy_apply_frame_filter (const struct extension_language_defn *extlang,
|
|||||||
initialization error. This return code will trigger a
|
initialization error. This return code will trigger a
|
||||||
default backtrace. */
|
default backtrace. */
|
||||||
|
|
||||||
throw_quit_or_print_exception ();
|
gdbpy_print_stack_or_quit ();
|
||||||
return EXT_LANG_BT_NO_FILTERS;
|
return EXT_LANG_BT_NO_FILTERS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1162,7 +1147,7 @@ gdbpy_apply_frame_filter (const struct extension_language_defn *extlang,
|
|||||||
{
|
{
|
||||||
if (PyErr_Occurred ())
|
if (PyErr_Occurred ())
|
||||||
{
|
{
|
||||||
throw_quit_or_print_exception ();
|
gdbpy_print_stack_or_quit ();
|
||||||
return EXT_LANG_BT_ERROR;
|
return EXT_LANG_BT_ERROR;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -1196,7 +1181,7 @@ gdbpy_apply_frame_filter (const struct extension_language_defn *extlang,
|
|||||||
/* Do not exit on error printing a single frame. Print the
|
/* Do not exit on error printing a single frame. Print the
|
||||||
error and continue with other frames. */
|
error and continue with other frames. */
|
||||||
if (success == EXT_LANG_BT_ERROR)
|
if (success == EXT_LANG_BT_ERROR)
|
||||||
throw_quit_or_print_exception ();
|
gdbpy_print_stack_or_quit ();
|
||||||
}
|
}
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
|
|||||||
@@ -535,12 +535,7 @@ pyuw_sniffer (const struct frame_unwind *self, struct frame_info *this_frame,
|
|||||||
{
|
{
|
||||||
/* If the unwinder is cancelled due to a Ctrl-C, then propagate
|
/* If the unwinder is cancelled due to a Ctrl-C, then propagate
|
||||||
the Ctrl-C as a GDB exception instead of swallowing it. */
|
the Ctrl-C as a GDB exception instead of swallowing it. */
|
||||||
if (PyErr_ExceptionMatches (PyExc_KeyboardInterrupt))
|
gdbpy_print_stack_or_quit ();
|
||||||
{
|
|
||||||
PyErr_Clear ();
|
|
||||||
quit ();
|
|
||||||
}
|
|
||||||
gdbpy_print_stack ();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (pyo_unwind_info == Py_None)
|
if (pyo_unwind_info == Py_None)
|
||||||
|
|||||||
@@ -654,6 +654,7 @@ extern const struct language_defn *python_language;
|
|||||||
|
|
||||||
int gdbpy_print_python_errors_p (void);
|
int gdbpy_print_python_errors_p (void);
|
||||||
void gdbpy_print_stack (void);
|
void gdbpy_print_stack (void);
|
||||||
|
void gdbpy_print_stack_or_quit ();
|
||||||
void gdbpy_handle_exception () ATTRIBUTE_NORETURN;
|
void gdbpy_handle_exception () ATTRIBUTE_NORETURN;
|
||||||
|
|
||||||
gdbpy_ref<> python_string_to_unicode (PyObject *obj);
|
gdbpy_ref<> python_string_to_unicode (PyObject *obj);
|
||||||
|
|||||||
@@ -1268,6 +1268,20 @@ gdbpy_print_stack (void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Like gdbpy_print_stack, but if the exception is a
|
||||||
|
KeyboardException, throw a gdb "quit" instead. */
|
||||||
|
|
||||||
|
void
|
||||||
|
gdbpy_print_stack_or_quit ()
|
||||||
|
{
|
||||||
|
if (PyErr_ExceptionMatches (PyExc_KeyboardInterrupt))
|
||||||
|
{
|
||||||
|
PyErr_Clear ();
|
||||||
|
throw_quit ("Quit");
|
||||||
|
}
|
||||||
|
gdbpy_print_stack ();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Return a sequence holding all the Progspaces. */
|
/* Return a sequence holding all the Progspaces. */
|
||||||
|
|||||||
Reference in New Issue
Block a user