fix erroneous error-handling in frame filter code
authorTom Tromey <tromey@redhat.com>
Wed, 22 Jan 2014 15:44:41 +0000 (08:44 -0700)
committerTom Tromey <tromey@redhat.com>
Thu, 23 Jan 2014 15:03:51 +0000 (08:03 -0700)
This fixes PR python/16487.

The bug here is that the function-name-handling code in py_print_frame
had a small logic error (really a misplaced closing brace).  This
error could lead to a Py_DECREF(NULL), which crashes.

This patch fixes the bug in the obvious way.

Built and regtested on x86-64 Fedora 18.  New test case included.

2014-01-23  Tom Tromey  <tromey@redhat.com>

PR python/16487:
* python/py-framefilter.c (py_print_frame): Don't call Py_DECREF
on a NULL pointer.  Move "goto error" to correct place.

2014-01-23  Tom Tromey  <tromey@redhat.com>

PR python/16487:
* gdb.python/py-framefilter.exp: Add test using "Error" filter.
* gdb.python/py-framefilter.py (ErrorInName, ErrorFilter): New
classes.

gdb/ChangeLog
gdb/python/py-framefilter.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.python/py-framefilter.exp
gdb/testsuite/gdb.python/py-framefilter.py

index 861f01b2397e242d6b39aab711b6c339b7afe190..2e09ef6c46121c1016c05340c3e8e48eb0fde697 100644 (file)
@@ -1,3 +1,9 @@
+2014-01-23  Tom Tromey  <tromey@redhat.com>
+
+       PR python/16487:
+       * python/py-framefilter.c (py_print_frame): Don't call Py_DECREF
+       on a NULL pointer.  Move "goto error" to correct place.
+
 2014-01-23  Tom Tromey  <tromey@redhat.com>
 
        PR python/16491:
index c6a29ef159f82776cba61a9d4e542c5fd768520c..1a9f3e05989ad4f88875f96258d6db024e9d0bd4 100644 (file)
@@ -1218,11 +1218,11 @@ py_print_frame (PyObject *filter, int flags, enum py_frame_args args_type,
                  gdbpy_convert_exception (except);
                  goto error;
                }
+             Py_DECREF (py_func);
            }
-         Py_DECREF (py_func);
+         else
+           goto error;
        }
-      else
-       goto error;
     }
 
 
index 4e11cd1e14272137a2d75c4c9907ab8632ce5dac..b41a16704ed4120b7bbe44eb8ae003e321d104c8 100644 (file)
@@ -1,3 +1,10 @@
+2014-01-23  Tom Tromey  <tromey@redhat.com>
+
+       PR python/16487:
+       * gdb.python/py-framefilter.exp: Add test using "Error" filter.
+       * gdb.python/py-framefilter.py (ErrorInName, ErrorFilter): New
+       classes.
+
 2014-01-23  Tom Tromey  <tromey@redhat.com>
 
        PR python/16491:
index 106240b287250bdb473df238ee1cc00d64a97f2f..905ad8c0977e379626fcbc30f8762d5e567d3acc 100644 (file)
@@ -177,6 +177,17 @@ gdb_test "bt 1" \
     "#0  end_func \\(foo=21, bar=\"Param\", fb=, bf=\{nothing = \"Foo Bar\", f = 42, s = 19\}\\) at .*py-framefilter.c.*" \
     "bt 1 no addresss"
 
+gdb_test_no_output "set python print-stack message" \
+    "Set python print-stack to message for Error filter"
+gdb_test_no_output  "enable frame-filter global Error" \
+    "enable frame-filter global Error"
+set test "bt 1 with Error filter"
+gdb_test_multiple "bt 1" $test {
+    -re "Python Exception .*whoops:.*$gdb_prompt $" {
+       pass $test
+    }
+}
+
 remote_file host delete ${remote_python_file}
 
 # Test with no debuginfo
index 25b3368e5e960554ea25643c0aebed16ed3d154d..a08568881e7ccf7440ceadf944cf4c406bdf6e7b 100644 (file)
@@ -128,5 +128,25 @@ class FrameElider ():
     def filter (self, frame_iter):
         return ElidingIterator (frame_iter)
 
+# A simple decorator that gives an error when computing the function.
+class ErrorInName(FrameDecorator):
+    def __init__(self, frame):
+        FrameDecorator.__init__(self, frame)
+
+    def function(self):
+        raise RuntimeError('whoops')
+
+# A filter that supplies buggy frames.  Disabled by default.
+class ErrorFilter():
+    def __init__ (self):
+        self.name = "Error"
+        self.priority = 1
+        self.enabled = False
+        gdb.frame_filters [self.name] = self
+
+    def filter(self, frame_iter):
+        return itertools.imap(ErrorInName, frame_iter)
+
 FrameFilter()
 FrameElider()
+ErrorFilter()
This page took 0.084071 seconds and 4 git commands to generate.