From patchwork Sat Sep 15 07:24:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 29385 Received: (qmail 29600 invoked by alias); 15 Sep 2018 07:25:19 -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 29478 invoked by uid 89); 15 Sep 2018 07:25:08 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.8 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=unlimited, python.exp, UD:python.exp, pythonexp X-HELO: gateway34.websitewelcome.com Received: from gateway34.websitewelcome.com (HELO gateway34.websitewelcome.com) (192.185.150.114) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 15 Sep 2018 07:25:06 +0000 Received: from cm14.websitewelcome.com (cm14.websitewelcome.com [100.42.49.7]) by gateway34.websitewelcome.com (Postfix) with ESMTP id 2E07B98F88D for ; Sat, 15 Sep 2018 02:25:04 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id 14wygpqnrkBj614wyg0RqF; Sat, 15 Sep 2018 02:25:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To: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:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=JtzxIjlH6B+lZYQCqNJJQfLco1NCc8Fs+4QAtLqV1hs=; b=CEQO6vTI03O3jP5Y3rp4eMa6lC rxEKNym6aRU4I65T288jH2LsmdvvEeiOZZ7jYyFcENuQ9kMDTT7D2Cxx28M0ApQmLbsD22SaivYjr SiPyqnO7OnvcnL8YXqCKl3Mb9; Received: from 97-122-190-66.hlrn.qwest.net ([97.122.190.66]:41846 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1g14wx-00253W-Vw; Sat, 15 Sep 2018 02:25:04 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 4/7] Report Python errors coming from gdb.post_event Date: Sat, 15 Sep 2018 01:24:56 -0600 Message-Id: <20180915072459.14934-5-tom@tromey.com> In-Reply-To: <20180915072459.14934-1-tom@tromey.com> References: <20180915072459.14934-1-tom@tromey.com> PR python/14062 points out that errors coming from the gdb.post_event callback are not reported. This can make it hard to understand why your Python code in gdb isn't working. Because users have control over whether exceptions are printed at all, it seems good to simply have post_event report errors in the usual way. gdb/ChangeLog 2018-09-15 Tom Tromey PR python/14062: * python/python.c (gdbpy_run_events): Do not ignore exceptions. gdb/testsuite/ChangeLog 2018-09-15 Tom Tromey PR python/14062: * gdb.python/python.exp: Add test for post_event error. --- gdb/ChangeLog | 5 +++++ gdb/python/python.c | 3 +-- gdb/testsuite/ChangeLog | 5 +++++ gdb/testsuite/gdb.python/python.exp | 13 ++++++++++++- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/gdb/python/python.c b/gdb/python/python.c index e89c90f8d9f..66a43123a0a 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -1043,10 +1043,9 @@ gdbpy_run_events (int error, gdb_client_data client_data) if (gdbpy_event_list == NULL) gdbpy_event_list_end = &gdbpy_event_list; - /* Ignore errors. */ gdbpy_ref<> call_result (PyObject_CallObject (item->event, NULL)); if (call_result == NULL) - PyErr_Clear (); + gdbpy_print_stack (); Py_DECREF (item->event); xfree (item); diff --git a/gdb/testsuite/gdb.python/python.exp b/gdb/testsuite/gdb.python/python.exp index 1d7ea5b6b4b..7c753215c7f 100644 --- a/gdb/testsuite/gdb.python/python.exp +++ b/gdb/testsuite/gdb.python/python.exp @@ -134,7 +134,18 @@ gdb_py_test_multiple "post event insertion" \ "end" "" gdb_test "python print (someVal)" "1" "test post event execution" -gdb_test "python gdb.post_event(str(1))" "RuntimeError: Posted event is not callable.*" "test non callable class" +gdb_test "python gdb.post_event(str(1))" "RuntimeError: Posted event is not callable.*" \ + "test non callable class" + +send_gdb "python gdb.post_event(lambda: invalid())\n" +gdb_expect { + -re "name 'invalid' is not defined" { + pass "test post_event error on receipt" + } + default { + fail "test post_event error on receipt" + } +} # Test (no) pagination of the executed command. gdb_test "show height" {Number of lines gdb thinks are in a page is unlimited\.}