From patchwork Tue Apr 19 16:05:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leonardo Boquillon X-Patchwork-Id: 11805 Received: (qmail 58252 invoked by alias); 19 Apr 2016 16:05:57 -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 58170 invoked by uid 89); 19 Apr 2016 16:05:56 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=Immediately, Hx-languages-length:1875, callbacks, Hx-spam-relays-external:sk:leonard X-HELO: mail-qg0-f54.google.com Received: from mail-qg0-f54.google.com (HELO mail-qg0-f54.google.com) (209.85.192.54) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 19 Apr 2016 16:05:45 +0000 Received: by mail-qg0-f54.google.com with SMTP id v14so11821622qge.0 for ; Tue, 19 Apr 2016 09:05:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id; bh=YPS/zkJ94+9v8DkpegxbNNqlNxSuU+z994D+y0mPZa8=; b=luYGPD4+V619Vz+zAsjG3ApgL3uv1UpXj+UnMNSIpAPP1qq8pIxBTGgvTgGdvze/1r S4V/nG3sOzSSh9EuGyeGAam3C950WdeaEIPMf+cMKIddL9wsOfasD7/jttukHotVaGCX HYvoQ4eWiSeROMYz7oZlwKHNqWUiyida7GQXwat6iH0mVIO9UR3ozxrrSFxkuLJziU6s mD5e71c7qpH4rS1u4z8/jLpAOTv6X8hN5O+W9RTqYX/j8BwctRWbajNVDTfgZs3KOz0b EBPv4LaZNvGYVcWzPowunX+F6683wUkkgRzaBuF0jBKhEhLbDbNT/mQdOVJImsLbweR0 +ywA== X-Gm-Message-State: AOPr4FXRscIBrpC2j5azC/D6Crjc2sR1CqPFkMivC/QyoIWMy2VNJ4VsrrnIuQKjhNGru14w X-Received: by 10.140.93.166 with SMTP id d35mr4511900qge.29.1461081943201; Tue, 19 Apr 2016 09:05:43 -0700 (PDT) Received: from leonardo.dominio.tallertechnologies.com ([200.69.202.173]) by smtp.gmail.com with ESMTPSA id n124sm22373297qhc.37.2016.04.19.09.05.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 19 Apr 2016 09:05:42 -0700 (PDT) From: Leonardo Boquillon To: gdb-patches@sourceware.org, tom@tromey.com Subject: [RFC][PATCH] Fix for Bugzilla #14062 (Exceptions in callbacks posted by gdb.post_event are silently ignored) Date: Tue, 19 Apr 2016 13:05:36 -0300 Message-Id: <1461081936-13813-1-git-send-email-leonardo.boquillon@tallertechnologies.com> Hi, This is a proposal for fixing this issue: https://sourceware.org/bugzilla/show_bug.cgi?id=14062 When we issue a gdb.post_event with a given callable object, any exceptions that occur when invoking the callable are ignored. This patch should be enough to let to the user know that an exception occured, however the output looks like: (gdb) python gdb.post_event(lambda: invalid()) (gdb) Python Exception global name 'invalid' is not defined: As we can see, the gdb prompt appears before the Python error message, which may be confusing. This happens because gdb.post_event results in a successful call to gdbpy_post_event (which places the event in gdb's internal queue) and thus the gdb prompt is shown. Immediately after, gdb invokes the callable through gdbpy_run_events, and only then the exception arises and the error message is shown. I'm attaching the patch that makes gdb stop ignoring Python errors. However, I'm not sure how to fix the output. I'm willing to go on and fix it myself if it's not too hard, though this should probably be handled by someone who knows the internals better than me. Since this is just an RFC, I'm not including a ChangeLog nor unit tests for now. Thanks! --- gdb/python/python.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gdb/python/python.c b/gdb/python/python.c index 9c972ec..8841b39 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -953,7 +953,10 @@ gdbpy_run_events (int error, gdb_client_data client_data) /* Ignore errors. */ call_result = PyObject_CallObject (item->event, NULL); if (call_result == NULL) - PyErr_Clear (); + { + gdbpy_print_stack (); + PyErr_Clear (); + } Py_XDECREF (call_result); Py_DECREF (item->event);