This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] [python] Add two different initialization checks for frame filters


This patch deals with two different initialization branches that need
to be checked in the frame filter code.  The first is just a check to
see if the variable gdb_python_initialized variable is set.

The second check is an exception to the "error and exit" rule that
Python frame filters follow.  If Python is initialized, but the
auto-load paths are either not configured correctly, or violate the
rules set forth by that policy, there is a case where the
gdb_python_initialized variable is set to True (as it should be, as
Python is initialized), but the frame filter code cannot load Python
written code it uses in the processing of frame filters.  If this is
the case, I think it is OK deviate from the error and exit rule as
nothing has been printed by GDB at that point.  In this one case GDB
will print the exception, and default to GDB's inbuilt backtrace code.
This is preferable to just printing an error message and no backtrace
at all.

What do you think?

Cheers,

Phil

2013-07-29  Phil Muldoon  <pmuldoon@redhat.com>

	PR python/15752

	* python/py-framefilter.c (apply_frame_filter): Check
	gdb_python_initialized.  Create new local label:
	cannot_initialize.  Use if the Python written code cannot be
	initialized.

--

diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c
index d62c596..1d5f054 100644
--- a/gdb/python/py-framefilter.c
+++ b/gdb/python/py-framefilter.c
@@ -1468,6 +1468,9 @@ apply_frame_filter (struct frame_info *frame, int flags,
   PyObject *item;
   htab_t levels_printed;
 
+  if (! gdb_python_initialized)
+    return PY_BT_NO_FILTERS;
+
   cleanups = ensure_python_env (gdbarch, current_language);
 
   TRY_CATCH (except, RETURN_MASK_ALL)
@@ -1483,7 +1486,7 @@ apply_frame_filter (struct frame_info *frame, int flags,
   iterable = bootstrap_python_frame_filters (frame, frame_low, frame_high);
 
   if (iterable == NULL)
-    goto error;
+    goto cannot_initialize;
 
   /* If iterable is None, then there are no frame filters registered.
      If this is the case, defer to default GDB printing routines in MI
@@ -1521,8 +1524,27 @@ apply_frame_filter (struct frame_info *frame, int flags,
   do_cleanups (cleanups);
   return success;
 
+  /* Exit and abandon backtrace on error, printing the exception that
+     is set.  */
  error:
   gdbpy_print_stack ();
   do_cleanups (cleanups);
   return PY_BT_ERROR;
+
+  /* Normally if there is an error GDB prints the exception, abandons
+     the backtrace and exits.  The user can then call "bt no-filters",
+     and get a default backtrace (it would be confusing to
+     automatically start a standard backtrace halfway through a Python
+     filtered backtrace).  However in the case where GDB cannot
+     initialize the frame filters (most likely due to incorrect auto
+     load paths), GDB has printed nothing.  In this case it is OK to
+     print the default backtrace after printing the error message.  GDB
+     returns PY_BT_NO_FILTERS here to signify there are no filters
+     after printing the initialization error.  This return code will
+     trigger a default backtrace.  */
+ cannot_initialize:
+  gdbpy_print_stack ();
+  do_cleanups (cleanups);
+  return PY_BT_NO_FILTERS;
+
 }
	


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]