From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 37020 invoked by alias); 15 Mar 2016 12:53:06 -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 37002 invoked by uid 89); 15 Mar 2016 12:53:05 -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=HTo:U*tom, HX-Envelope-From:sk:leonard X-HELO: mail-qk0-f173.google.com Received: from mail-qk0-f173.google.com (HELO mail-qk0-f173.google.com) (209.85.220.173) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 15 Mar 2016 12:52:55 +0000 Received: by mail-qk0-f173.google.com with SMTP id s5so6227807qkd.0 for ; Tue, 15 Mar 2016 05:52:55 -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=5TM2GPPifvsHTJXfkRi2o/wdamL0OAYSYCOk9oq8JJE=; b=Uq7ubHk8jz4O3y4PFYWujwtEcPOkYvxmlnS8jyOe3vtOqNPIrSoMRWXu3/7n6ksvC6 Fs36cGI3ET+9PyKhfEykeZu8bf6Qzqn0BwOwxZML7dvmf/QvGPU01aNNUEYlblTJfDL3 KKStrFrL4zlLik75OmERrAhhaSu2l53jG+Ix2n9WHEEJBk4aDmKHwaNztO1WVPkLcaCQ xwRoEUds121e2qAT87hl1xAV0Dt7N28oCGp6weT0neuM3cC+PBVZVSKW9gzNQPgiq2ye zctnFPFyH8yH9k7ZTVDpO4TpeP+dBAnU4K99HARdW/EOdO5kqA8KqKTKHG0uktJWJi0H H6Jw== X-Gm-Message-State: AD7BkJJl6QmpsY6GRVy56JUW3Gc+QqfCtDUVAQ/KFJd0TRZuTMItMY6ykRTeNbMzZn4AYFDI X-Received: by 10.55.214.17 with SMTP id t17mr38134706qki.95.1458046371516; Tue, 15 Mar 2016 05:52:51 -0700 (PDT) Received: from leonardo.dominio.tallertechnologies.com ([200.69.202.173]) by smtp.gmail.com with ESMTPSA id u202sm12648146qka.43.2016.03.15.05.52.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 15 Mar 2016 05:52:51 -0700 (PDT) From: Leonardo Boquillon To: gdb-patches@sourceware.org, tom@tromey.com Subject: [PING][PATCH] Python: Fix Python error when "Quit"ting a paged info pretty-printers Date: Tue, 15 Mar 2016 12:53:00 -0000 Message-Id: <1458046365-21110-1-git-send-email-leonardo.boquillon@tallertechnologies.com> X-SW-Source: 2016-03/txt/msg00230.txt.bz2 Right now the "Quit" command used in the output paging is handled as an exception. If we issue a "Quit" while outputting the registered pretty-printers list, the Python handling layer will catch it and think it's a Python error. The fix is to check if the error coming from Python is a Quit signal. If it is, do not handle it as an error and resume the execution normally. Is this ok to commit? I have a company-wide copyright assignment and a coworker of mine is a write-after-approval maintainer. gdb/ChangeLog: 2016-03-08 Leonardo Boquillon * python/py-cmd.c (cmdpy_function): Handle the "Quit" exception. --- gdb/python/py-cmd.c | 85 +++++++++++++++++++++++++++++------------------------ 1 file changed, 47 insertions(+), 38 deletions(-) diff --git a/gdb/python/py-cmd.c b/gdb/python/py-cmd.c index af6c5cf..edcaf79 100644 --- a/gdb/python/py-cmd.c +++ b/gdb/python/py-cmd.c @@ -165,46 +165,55 @@ cmdpy_function (struct cmd_list_element *command, char *args, int from_tty) we no longer own ptype, pvalue after the call to PyErr_Restore. */ msg = gdbpy_exception_to_string (ptype, pvalue); - make_cleanup (xfree, msg); - - if (msg == NULL) - { - /* An error occurred computing the string representation of the - error message. This is rare, but we should inform the user. */ - printf_filtered (_("An error occurred in a Python command\n" - "and then another occurred computing the " - "error message.\n")); - gdbpy_print_stack (); - } - - /* Don't print the stack for gdb.GdbError exceptions. - It is generally used to flag user errors. - - We also don't want to print "Error occurred in Python command" - for user errors. However, a missing message for gdb.GdbError - exceptions is arguably a bug, so we flag it as such. */ - - if (! PyErr_GivenExceptionMatches (ptype, gdbpy_gdberror_exc) - || msg == NULL || *msg == '\0') - { - PyErr_Restore (ptype, pvalue, ptraceback); - gdbpy_print_stack (); - if (msg != NULL && *msg != '\0') - error (_("Error occurred in Python command: %s"), msg); + /* We need to check this because the "Quit" command used in the output + paging is handled as an exception. If we issue a "Quit" while + outputting the registered pretty-printers list, the Python handling + layer will catch it and think it's a Python error */ + if (strncmp(msg, "Quit", 5)) + { + if (msg == NULL) + { + /* An error occurred computing the string representation of the + error message. This is rare, but we should inform the user.*/ + printf_filtered (_("An error occurred in a Python command\n" + "and then another occurred computing the " + "error message.\n")); + gdbpy_print_stack (); + } + + /* Don't print the stack for gdb.GdbError exceptions. + It is generally used to flag user errors. + + We also don't want to print "Error occurred in Python command" + for user errors. However, a missing message for gdb.GdbError + exceptions is arguably a bug, so we flag it as such. */ + + if (! PyErr_GivenExceptionMatches (ptype, gdbpy_gdberror_exc) + || msg == NULL || *msg == '\0') + { + PyErr_Restore (ptype, pvalue, ptraceback); + gdbpy_print_stack (); + if (msg != NULL && *msg != '\0') + error (_("Error occurred in Python command: %s"), msg); + else + error (_("Error occurred in Python command.")); + } else - error (_("Error occurred in Python command.")); - } - else - { - Py_XDECREF (ptype); - Py_XDECREF (pvalue); - Py_XDECREF (ptraceback); - error ("%s", msg); - } - } + { + Py_XDECREF (ptype); + Py_XDECREF (pvalue); + Py_XDECREF (ptraceback); + error ("%s", msg); + } + } // ELSE: This was not an error just quit signal. Do nothing. - Py_DECREF (result); - do_cleanups (cleanup); + make_cleanup (xfree, msg); + } + else + { + Py_DECREF (result); + do_cleanups (cleanup); + } } /* Helper function for the Python command completers (both "pure" -- 1.9.1