Skip to content

Commit 6ef2312

Browse files
committed
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.
1 parent ec9c275 commit 6ef2312

5 files changed

Lines changed: 29 additions & 24 deletions

File tree

‎gdb/ChangeLog‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
2018-12-27 Tom Tromey <tom@tromey.com>
2+
3+
* python/python-internal.h (gdbpy_print_stack_or_quit): Declare.
4+
* python/py-unwind.c (pyuw_sniffer): Use
5+
gdbpy_print_stack_or_quit.
6+
* python/py-framefilter.c (throw_quit_or_print_exception):
7+
Remove.
8+
(gdbpy_apply_frame_filter): Use gdbpy_print_stack_or_quit.
9+
* python/python.c (gdbpy_print_stack_or_quit): New function.
10+
111
2018-12-27 Tom Tromey <tom@tromey.com>
212

313
* python/py-value.c (convert_value_from_python): Use

‎gdb/python/py-framefilter.c‎

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,21 +1054,6 @@ bootstrap_python_frame_filters (struct frame_info *frame,
10541054
return iterable.release ();
10551055
}
10561056

1057-
/* A helper function that will either print an exception or, if it is
1058-
a KeyboardException, throw a quit. This can only be called when
1059-
the Python exception is set. */
1060-
1061-
static void
1062-
throw_quit_or_print_exception ()
1063-
{
1064-
if (PyErr_ExceptionMatches (PyExc_KeyboardInterrupt))
1065-
{
1066-
PyErr_Clear ();
1067-
throw_quit ("Quit");
1068-
}
1069-
gdbpy_print_stack ();
1070-
}
1071-
10721057
/* This is the only publicly exported function in this file. FRAME
10731058
is the source frame to start frame-filter invocation. FLAGS is an
10741059
integer holding the flags for printing. The following elements of
@@ -1139,7 +1124,7 @@ gdbpy_apply_frame_filter (const struct extension_language_defn *extlang,
11391124
initialization error. This return code will trigger a
11401125
default backtrace. */
11411126

1142-
throw_quit_or_print_exception ();
1127+
gdbpy_print_stack_or_quit ();
11431128
return EXT_LANG_BT_NO_FILTERS;
11441129
}
11451130

@@ -1162,7 +1147,7 @@ gdbpy_apply_frame_filter (const struct extension_language_defn *extlang,
11621147
{
11631148
if (PyErr_Occurred ())
11641149
{
1165-
throw_quit_or_print_exception ();
1150+
gdbpy_print_stack_or_quit ();
11661151
return EXT_LANG_BT_ERROR;
11671152
}
11681153
break;
@@ -1196,7 +1181,7 @@ gdbpy_apply_frame_filter (const struct extension_language_defn *extlang,
11961181
/* Do not exit on error printing a single frame. Print the
11971182
error and continue with other frames. */
11981183
if (success == EXT_LANG_BT_ERROR)
1199-
throw_quit_or_print_exception ();
1184+
gdbpy_print_stack_or_quit ();
12001185
}
12011186

12021187
return success;

‎gdb/python/py-unwind.c‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -535,12 +535,7 @@ pyuw_sniffer (const struct frame_unwind *self, struct frame_info *this_frame,
535535
{
536536
/* If the unwinder is cancelled due to a Ctrl-C, then propagate
537537
the Ctrl-C as a GDB exception instead of swallowing it. */
538-
if (PyErr_ExceptionMatches (PyExc_KeyboardInterrupt))
539-
{
540-
PyErr_Clear ();
541-
quit ();
542-
}
543-
gdbpy_print_stack ();
538+
gdbpy_print_stack_or_quit ();
544539
return 0;
545540
}
546541
if (pyo_unwind_info == Py_None)

‎gdb/python/python-internal.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,7 @@ extern const struct language_defn *python_language;
654654

655655
int gdbpy_print_python_errors_p (void);
656656
void gdbpy_print_stack (void);
657+
void gdbpy_print_stack_or_quit ();
657658
void gdbpy_handle_exception () ATTRIBUTE_NORETURN;
658659

659660
gdbpy_ref<> python_string_to_unicode (PyObject *obj);

‎gdb/python/python.c‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,6 +1268,20 @@ gdbpy_print_stack (void)
12681268
}
12691269
}
12701270

1271+
/* Like gdbpy_print_stack, but if the exception is a
1272+
KeyboardException, throw a gdb "quit" instead. */
1273+
1274+
void
1275+
gdbpy_print_stack_or_quit ()
1276+
{
1277+
if (PyErr_ExceptionMatches (PyExc_KeyboardInterrupt))
1278+
{
1279+
PyErr_Clear ();
1280+
throw_quit ("Quit");
1281+
}
1282+
gdbpy_print_stack ();
1283+
}
1284+
12711285

12721286

12731287
/* Return a sequence holding all the Progspaces. */

0 commit comments

Comments
 (0)