From patchwork Thu Jan 16 00:48:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 37402 Received: (qmail 111829 invoked by alias); 16 Jan 2020 00:48:39 -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 111588 invoked by uid 89); 16 Jan 2020 00:48:29 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-19.4 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.1 spammy=threw X-HELO: mail-wr1-f53.google.com Received: from mail-wr1-f53.google.com (HELO mail-wr1-f53.google.com) (209.85.221.53) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 16 Jan 2020 00:48:26 +0000 Received: by mail-wr1-f53.google.com with SMTP id t2so17489679wrr.1 for ; Wed, 15 Jan 2020 16:48:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=uepDBFudLL5YsWGUZmIJYc1Gf15zfGkWgjVRQp1I6Xs=; b=IIvj5il8noN0vor2g5fICMV0bmcIM9YBp0g6mKgVoWo5oUhj1dbSJj3TL6Je/gu3W7 tBK1zB98qr9CQMs5/Tdgbv+zBioNangnF96eMrrq9iHolDfc4s6sZJx6TSYV5aeoVizP jCcWMXl2E8g6gS9eAV3ySv5cQ/uwYlkqSPWrv5Udlvem0IN18DC9i44r2lj4TiYClkrK /s5+KEFgszxZ4t4rZxnvKzSZRXlCihCjy625TdjyAujmv8BNHOpr6Gqz0n3wwEpHKXLd Q5QF9t19iAmVG4o8KSBvlYY04FuOsAwsJ0wFKHIItnqWDe7VQzIRTdHH0f9IWgZ2Wamy sY7g== Return-Path: Received: from localhost (host86-191-239-73.range86-191.btcentralplus.com. [86.191.239.73]) by smtp.gmail.com with ESMTPSA id i11sm27585549wrs.10.2020.01.15.16.48.23 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 15 Jan 2020 16:48:23 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Shahab Vahedi , Pedro Alves , Tom Tromey Subject: [PATCHv2 1/2] gdb/tui: Prevent exceptions from trying to cross readline Date: Thu, 16 Jan 2020 00:48:15 +0000 Message-Id: <7b66ec5655ca7eee42b5b210f29aff335406fb0d.1579135219.git.andrew.burgess@embecosm.com> In-Reply-To: References: In-Reply-To: References: X-IsSubscribed: yes From: Pedro Alves This is triggered by simply scrolling off the end of the dissasembly window. This commit doesn't fix the actual exception that is being thrown, which will still need to be fixed, but makes sure that we don't ever throw an exception out to readline. gdb/ChangeLog: yyyy-mm-dd Pedro Alves PR tui/9765 * tui/tui-io.c (tui_getc): Rename to ... (tui_getc_1): ... this. (tui_get): New, reimplent as try/catch wrapper around tui_getc_1. Change-Id: I2e32a401ab34404b2132ec82a3e1c17b9b723e41 --- gdb/tui/tui-io.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/gdb/tui/tui-io.c b/gdb/tui/tui-io.c index 9cb41104fe9..d9f23334f57 100644 --- a/gdb/tui/tui-io.c +++ b/gdb/tui/tui-io.c @@ -950,10 +950,12 @@ tui_dispatch_ctrl_char (unsigned int ch) return 0; } -/* Get a character from the command window. This is called from the - readline package. */ +/* Main worker for tui_getc. Get a character from the command window. + This is called from the readline package, but wrapped in a + try/catch by tui_getc. */ + static int -tui_getc (FILE *fp) +tui_getc_1 (FILE *fp) { int ch; WINDOW *w; @@ -1036,6 +1038,29 @@ tui_getc (FILE *fp) return ch; } +/* Get a character from the command window. This is called from the + readline package. */ + +static int +tui_getc (FILE *fp) +{ + try + { + return tui_getc_1 (fp); + } + catch (const gdb_exception &ex) + { + /* Just in case, don't ever let an exception escape to readline. + This shouldn't ever happen, but if it does, print the + exception instead of just crashing GDB. */ + exception_print (gdb_stderr, ex); + + /* If we threw an exception, it's because we recognized the + character. */ + return 0; + } +} + /* See tui-io.h. */ gdb::unique_xmalloc_ptr