From patchwork Tue Sep 18 12:28:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 29436 Received: (qmail 128459 invoked by alias); 18 Sep 2018 12:29:38 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 128444 invoked by uid 89); 18 Sep 2018 12:29:37 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: gateway20.websitewelcome.com Received: from gateway20.websitewelcome.com (HELO gateway20.websitewelcome.com) (192.185.50.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 18 Sep 2018 12:29:35 +0000 Received: from cm16.websitewelcome.com (cm16.websitewelcome.com [100.42.49.19]) by gateway20.websitewelcome.com (Postfix) with ESMTP id 0122F400DC12A for ; Tue, 18 Sep 2018 07:29:34 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id 2F7hgjGrBaSey2F83g9XT4; Tue, 18 Sep 2018 07:29:33 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version :Content-Type:Content-Transfer-Encoding:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=3pmn30tjpErf64hVFgMyIqcIh+sXmB6g+EjqcQqvtTY=; b=hvgIlCEaYe+4/BTlfqC0H7I5uY VjsdOM7hHYhlV0viBnl/WrJl6EHkEXPGcwwkDLeljWZVci74MtpCdfBKVlqIKLHuy4wupK1v3hxHj +4hEvhIyu+VmtGWpna3Bjzt78; Received: from 97-122-190-66.hlrn.qwest.net ([97.122.190.66]:44386 helo=pokyo.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1g2F7h-001Pbz-Dl; Tue, 18 Sep 2018 07:28:57 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Fix Python gdb.Breakpoint.location crash Date: Tue, 18 Sep 2018 06:28:53 -0600 Message-Id: <20180918122853.19426-1-tom@tromey.com> I noticed today that gdb.Breakpoint.location will crash when applied to a catchpoint made with "catch throw". The bug is that "catch throw" makes a breakpoint that is of type bp_breakpoint, but which does not have a location. Regression tested on x86-64 Fedora 28. gdb/ChangeLog 2018-09-18 Tom Tromey * python/py-breakpoint.c (bppy_get_location): Handle a bp_breakpoint without a location. gdb/testsuite/ChangeLog 2018-09-18 Tom Tromey * gdb.python/py-breakpoint.exp (check_last_event): Check location of a "throw" catchpoint. --- gdb/ChangeLog | 5 +++++ gdb/python/py-breakpoint.c | 7 ++++++- gdb/testsuite/ChangeLog | 5 +++++ gdb/testsuite/gdb.python/py-breakpoint.exp | 5 +++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index ddd2782d99c..3649111235c 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2018-09-18 Tom Tromey + + * python/py-breakpoint.c (bppy_get_location): Handle a + bp_breakpoint without a location. + 2018-09-18 Rainer Orth * utils.c (dump_core) [HAVE_SETRLIMIT]: Cast RLIM_INFINITY to diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c index e1db674647a..94afd503e92 100644 --- a/gdb/python/py-breakpoint.c +++ b/gdb/python/py-breakpoint.c @@ -391,7 +391,12 @@ bppy_get_location (PyObject *self, void *closure) if (obj->bp->type != bp_breakpoint) Py_RETURN_NONE; - str = event_location_to_string (obj->bp->location.get ()); + struct event_location *location = obj->bp->location.get (); + /* "catch throw" makes a breakpoint of type bp_breakpoint that does + not have a location. */ + if (location == nullptr) + Py_RETURN_NONE; + str = event_location_to_string (location); if (! str) str = ""; return host_string_to_python_string (str); diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index ad74bfdbf74..572494dba62 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-09-18 Tom Tromey + + * gdb.python/py-breakpoint.exp (check_last_event): Check location + of a "throw" catchpoint. + 2018-09-17 Simon Marchi PR python/23669 diff --git a/gdb/testsuite/gdb.python/py-breakpoint.exp b/gdb/testsuite/gdb.python/py-breakpoint.exp index 3ce0ea11dea..7d5fbccad3b 100644 --- a/gdb/testsuite/gdb.python/py-breakpoint.exp +++ b/gdb/testsuite/gdb.python/py-breakpoint.exp @@ -616,6 +616,11 @@ proc_with_prefix test_bkpt_explicit_loc {} { gdb_test "python bp1 = gdb.Breakpoint (function=\"blah\")" \ "Function \"blah\" not defined.*" \ "set invalid explicit breakpoint by missing function" + + delete_breakpoints + gdb_test "catch throw" "Catchpoint .* \\(throw\\)" + gdb_test "python print (gdb.breakpoints()\[0\].location)" None \ + "Examine location of catchpoint" } proc_with_prefix test_bkpt_qualified {} {