[RFA 3/3] PR python/19293 - invalidate frame cache when unwinders change

Tom Tromey tom@tromey.com
Sat Jun 11 02:42:00 GMT 2016


PR python/19293 notes that when a Python unwinder is disabled, the
frame cache is not invalidated.  This means that disabling an unwinder
doesn't have any immediate effect -- but in my experience it's often
the case that I want to enable or disable an unwinder in order to see
what happens.

This patch adds a new gdb.invalidate_cached_frames function and
arranges for the relevant bits of library code to call it.  I've only
partially documented this function, considering a warning sufficient
without going into all the reasons ordinary code should not call it.
The name of the new function was taken from a comment in frame.h next
to reinit_frame_cache.

No new test as I think the updates to the existing test are sufficient
to show that the code is working as intended.

Built and regtested on x86-64 Fedora 23.

2016-06-09  Tom Tromey  <tom@tromey.com>

	PR python/19293:
	* python/lib/gdb/command/unwinders.py (do_enable_unwinder): Call
	gdb.invalidate_cached_frames.
	* python/lib/gdb/unwinder.py (register_unwinder): Call
	gdb.invalidate_cached_frames.
	* python/python.c (gdbpy_invalidate_cached_frames): New function.
	(python_GdbMethods): Add entry for invalidate_cached_frames.

2016-06-09  Tom Tromey  <tom@tromey.com>

	PR python/19293:
	* python.texi (Frames In Python): Document
	gdb.invalidate_cached_frames.

2016-06-10  Tom Tromey  <tom@tromey.com>

	PR python/19293:
	* gdb.python/py-unwind-maint.exp: Update tests.
---
 gdb/ChangeLog                                | 10 ++++++++++
 gdb/doc/ChangeLog                            |  6 ++++++
 gdb/doc/python.texi                          |  9 +++++++++
 gdb/python/lib/gdb/command/unwinders.py      |  2 ++
 gdb/python/lib/gdb/unwinder.py               |  1 +
 gdb/python/python.c                          | 13 +++++++++++++
 gdb/testsuite/ChangeLog                      |  5 +++++
 gdb/testsuite/gdb.python/py-unwind-maint.exp | 11 +++++++++--
 8 files changed, 55 insertions(+), 2 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index a64977e..58e9c66 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,15 @@
 2016-06-09  Tom Tromey  <tom@tromey.com>
 
+	PR python/19293:
+	* python/lib/gdb/command/unwinders.py (do_enable_unwinder): Call
+	gdb.invalidate_cached_frames.
+	* python/lib/gdb/unwinder.py (register_unwinder): Call
+	gdb.invalidate_cached_frames.
+	* python/python.c (gdbpy_invalidate_cached_frames): New function.
+	(python_GdbMethods): Add entry for invalidate_cached_frames.
+
+2016-06-09  Tom Tromey  <tom@tromey.com>
+
 	* python/python.c (gdbpy_parameter): Now static.
 	* python/python-internal.h (gdbpy_parameter): Don't declare.
 
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index a01d545..a010562 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,9 @@
+2016-06-09  Tom Tromey  <tom@tromey.com>
+
+	PR python/19293:
+	* python.texi (Frames In Python): Document
+	gdb.invalidate_cached_frames.
+
 2016-06-09  Toshihito Kikuchi  <k.toshihito@yahoo.de>
 
 	* gdb.texinfo (Examining Memory): Document negative repeat
diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
index 6623d8e..7682940 100644
--- a/gdb/doc/python.texi
+++ b/gdb/doc/python.texi
@@ -3838,6 +3838,15 @@ frames, as expressed by the given @var{reason} code (an integer, see the
 @code{unwind_stop_reason} method further down in this section).
 @end defun
 
+@findex gdb.invalidate_cached_frames
+@defun gdb.invalidate_cached_frames
+@value{GDBN} internally keeps a cache of the frames that have been
+unwound.  This function causes invalidates this cache.
+
+This function should not generally be called by ordinary Python code.
+It is documented for the sake of completeness.
+@end defun
+
 A @code{gdb.Frame} object has the following methods:
 
 @defun Frame.is_valid ()
diff --git a/gdb/python/lib/gdb/command/unwinders.py b/gdb/python/lib/gdb/command/unwinders.py
index a9b9d8a..8fd0136 100644
--- a/gdb/python/lib/gdb/command/unwinders.py
+++ b/gdb/python/lib/gdb/command/unwinders.py
@@ -136,6 +136,8 @@ def do_enable_unwinder(arg, flag):
         if locus_re.match(objfile.filename):
             total += do_enable_unwinder1(objfile.frame_unwinders, name_re,
                                          flag)
+    if total > 0:
+        gdb.invalidate_cached_frames()
     print("%d unwinder%s %s" % (total, "" if total == 1 else "s",
                                 "enabled" if flag else "disabled"))
 
diff --git a/gdb/python/lib/gdb/unwinder.py b/gdb/python/lib/gdb/unwinder.py
index 14b2758..67a37cb 100644
--- a/gdb/python/lib/gdb/unwinder.py
+++ b/gdb/python/lib/gdb/unwinder.py
@@ -92,3 +92,4 @@ def register_unwinder(locus, unwinder, replace=False):
                                    unwinder.name)
         i += 1
     locus.frame_unwinders.insert(0, unwinder)
+    gdb.invalidate_cached_frames()
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 9c4ddda..62c9bde 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -884,6 +884,13 @@ gdbpy_find_pc_line (PyObject *self, PyObject *args)
   return result;
 }
 
+static PyObject *
+gdbpy_invalidate_cached_frames (PyObject *self, PyObject *args)
+{
+  reinit_frame_cache ();
+  Py_RETURN_NONE;
+}
+
 /* Read a file as Python code.
    This is the extension_language_script_ops.script_sourcer "method".
    FILE is the file to load.  FILENAME is name of the file FILE.
@@ -2070,6 +2077,12 @@ Return the selected inferior object." },
   { "inferiors", gdbpy_inferiors, METH_NOARGS,
     "inferiors () -> (gdb.Inferior, ...).\n\
 Return a tuple containing all inferiors." },
+
+  { "invalidate_cached_frames", gdbpy_invalidate_cached_frames, METH_NOARGS,
+    "invalidate_cached_frames () -> None.\n\
+Invalidate any cached frame objects in gdb.\n\
+Intended for internal use only." },
+
   {NULL, NULL, 0, NULL}
 };
 
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 7d2b144..bc46282 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,5 +1,10 @@
 2016-06-10  Tom Tromey  <tom@tromey.com>
 
+	PR python/19293:
+	* gdb.python/py-unwind-maint.exp: Update tests.
+
+2016-06-10  Tom Tromey  <tom@tromey.com>
+
 	PR rust/20110:
 	* gdb.rust/expr.exp: Add test for integer constant larger than
 	i32.
diff --git a/gdb/testsuite/gdb.python/py-unwind-maint.exp b/gdb/testsuite/gdb.python/py-unwind-maint.exp
index e89d284..3a98cb1 100644
--- a/gdb/testsuite/gdb.python/py-unwind-maint.exp
+++ b/gdb/testsuite/gdb.python/py-unwind-maint.exp
@@ -34,7 +34,11 @@ if ![runto_main ] then {
     return -1
 }
 
-gdb_test "source ${pyfile}" "Python script imported" "import python scripts"
+gdb_test_sequence "source ${pyfile}" "import python scripts" {
+    "Python script imported"
+    "py_unwind_maint_ps_unwinder called"
+    "global_unwinder called"
+}
 
 gdb_test_sequence "info unwinder" "Show all unwinders" {
     "Global:"
@@ -50,7 +54,10 @@ gdb_test_sequence "continue" "Unwinders called" {
     "global_unwinder called"
 }
 
-gdb_test "disable unwinder global .*" "1 unwinder disabled" "Unwinder disabled"
+gdb_test_sequence "disable unwinder global .*" "Unwinder disabled" {
+    "1 unwinder disabled"
+    "py_unwind_maint_ps_unwinder called"
+}
 
 gdb_test_sequence "info unwinder" "Show with global unwinder disabled" {
     "Global:"
-- 
2.5.5



More information about the Gdb-patches mailing list