From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25733 invoked by alias); 22 Jan 2014 16:50:33 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 25721 invoked by uid 89); 22 Jan 2014 16:50:32 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.2 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 22 Jan 2014 16:50:29 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s0MGoSfn028489 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 22 Jan 2014 11:50:28 -0500 Received: from barimba.redhat.com (ovpn-113-85.phx2.redhat.com [10.3.113.85]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s0MG01PC031078; Wed, 22 Jan 2014 11:00:13 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 2/3] fix erroneous error-handling in frame filter code Date: Wed, 22 Jan 2014 16:50:00 -0000 Message-Id: <1390406399-26664-3-git-send-email-tromey@redhat.com> In-Reply-To: <1390406399-26664-1-git-send-email-tromey@redhat.com> References: <1390406399-26664-1-git-send-email-tromey@redhat.com> X-SW-Source: 2014-01/txt/msg00870.txt.bz2 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-22 Tom Tromey 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-22 Tom Tromey PR python/16487: * gdb.python/py-framefilter.exp: Add test using "Error" filter. * gdb.python/py-framefilter.py (ErrorInName, ErrorFilter): New classes. --- gdb/ChangeLog | 6 ++++++ gdb/python/py-framefilter.c | 6 +++--- gdb/testsuite/ChangeLog | 7 +++++++ gdb/testsuite/gdb.python/py-framefilter.exp | 11 +++++++++++ gdb/testsuite/gdb.python/py-framefilter.py | 20 ++++++++++++++++++++ 5 files changed, 47 insertions(+), 3 deletions(-) diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c index c6a29ef..1a9f3e0 100644 --- a/gdb/python/py-framefilter.c +++ b/gdb/python/py-framefilter.c @@ -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; } diff --git a/gdb/testsuite/gdb.python/py-framefilter.exp b/gdb/testsuite/gdb.python/py-framefilter.exp index 106240b..905ad8c 100644 --- a/gdb/testsuite/gdb.python/py-framefilter.exp +++ b/gdb/testsuite/gdb.python/py-framefilter.exp @@ -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 diff --git a/gdb/testsuite/gdb.python/py-framefilter.py b/gdb/testsuite/gdb.python/py-framefilter.py index 25b3368..a085688 100644 --- a/gdb/testsuite/gdb.python/py-framefilter.py +++ b/gdb/testsuite/gdb.python/py-framefilter.py @@ -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() -- 1.8.1.4