From patchwork Thu Sep 27 21:17:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Graham Markall X-Patchwork-Id: 29567 Received: (qmail 4885 invoked by alias); 27 Sep 2018 21:17:22 -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 4872 invoked by uid 89); 27 Sep 2018 21:17:21 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=HX-Received:sk:f13-v6m, gdb.execute, disappearing, UD:execute X-HELO: mail-wr1-f45.google.com Received: from mail-wr1-f45.google.com (HELO mail-wr1-f45.google.com) (209.85.221.45) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 27 Sep 2018 21:17:19 +0000 Received: by mail-wr1-f45.google.com with SMTP id z14-v6so4118999wrs.10 for ; Thu, 27 Sep 2018 14:17:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=from:to:cc:subject:date:message-id; bh=uhnlMKnLyOG8h5uhzcenFouvvks4HXkpNZg10MSKeF0=; b=W4jfp3pgSgpFqlhkVuukqG6emNMfarhesL8gnhIlbAZz31FjoeBYMJCpizRMbYe0U2 SGdtQ0nn6O4nhgNNEK/3XAaQBcBS8Z5G0oJ8VALFEZd/TEdsAzXSD1Xd7npfIbU4zGa3 R0HXHixj+dACwjk6XONbP/a00mw+WI9oNZ+nlXtUTBmLVufJJxwk5xNEHa5MHP0b2IUb sbnPh8rX690dD4dBfwlG6XGKsZqNyAGnsNHGlJplpE6hdZ4LH53ESFyssJN8rxcwI88o sP63S8XEfAJuVC977Fdm+Ra5ZMJTAmLUuO4zu4M4TRQI3XzcdS2er0VnbhSoab4jJrau PTjw== Return-Path: Received: from gm-x220.hq.big-grey.co.uk (14.27.187.81.in-addr.arpa. [81.187.27.14]) by smtp.gmail.com with ESMTPSA id i7-v6sm3281917wrb.30.2018.09.27.14.17.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 27 Sep 2018 14:17:16 -0700 (PDT) From: Graham Markall To: gdb-patches@sourceware.org Cc: Graham Markall Subject: [PATCH] [PR gdb/23718] Enable stdin on exception in execute_gdb_command Date: Thu, 27 Sep 2018 22:17:02 +0100 Message-Id: <20180927211702.1029-1-graham.markall@embecosm.com> X-IsSubscribed: yes This patch attempts to address https://sourceware.org/bugzilla/show_bug.cgi?id=23718 by re-enabling stdin whenever an exception is caught during gdb.execute() - however, I'm wondering if there are additional places where it might be useful to re-enable stdin other than the one added in the patch. I've run the testsuite and checked that this patch doesn't introduce any regressions on Linux on x86_64. This is my first patch for GDB - however, I do have write access to the binutils-gdb repository and my employer, Embecosm, has a copyright assignment on file. Commit message follows: When Python gdb.execute() is called, an exception could occur (e.g. the target disappearing), which is then converted into a Python exception. If stdin was disabled and an exception is caught, it is not necessarily re-enabled, because the exception doesn't propagate to the top level of the event loop, whose catch block would enable it, and we may also not hit normal_stop (), which would enable stdin. The result is that when execution of a Python script completes, GDB does not prompt or accept input, and is effectively hung. This change rectifies this issue by re-enabling stdin in the CATCH block of execute_gdb_command, prior to converting the exception to a Python exception. * gdb/python/python.c (execute_gdb_command): Call async_enable_stdin in CATCH block. --- gdb/ChangeLog | 5 +++++ gdb/python/python.c | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/gdb/python/python.c b/gdb/python/python.c index 8fbce78469..a85ba6b43e 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -625,6 +625,15 @@ execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw) } CATCH (except, RETURN_MASK_ALL) { + /* If an exception occurred then we won't hit normal_stop (), or have an + exception reach the top level of the event loop, which are the two + usual places in which stdin would be re-enabled. So, before we convert + the exception and continue back in Python, we need to re-enable it for + all UIs here. */ + SWITCH_THRU_ALL_UIS () + { + async_enable_stdin (); + } GDB_PY_HANDLE_EXCEPTION (except); } END_CATCH