From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id OigmGGNf8GCqUQAAWB0awg (envelope-from ) for ; Thu, 15 Jul 2021 12:16:35 -0400 Received: by simark.ca (Postfix, from userid 112) id 530FA1EDF0; Thu, 15 Jul 2021 12:16:35 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 76E5B1E4A3 for ; Thu, 15 Jul 2021 12:16:34 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0AE213985039 for ; Thu, 15 Jul 2021 16:16:34 +0000 (GMT) Received: from rock.gnat.com (rock.gnat.com [205.232.38.15]) by sourceware.org (Postfix) with ESMTPS id 4CDCA3858031 for ; Thu, 15 Jul 2021 16:16:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4CDCA3858031 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 113DB117BF3; Thu, 15 Jul 2021 12:16:22 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at gnat.com Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id nRwciO9fBAU2; Thu, 15 Jul 2021 12:16:22 -0400 (EDT) Received: from murgatroyd.Home (71-211-145-10.hlrn.qwest.net [71.211.145.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPSA id C21AF117BE9; Thu, 15 Jul 2021 12:16:21 -0400 (EDT) From: Tom Tromey To: gdb-patches@sourceware.org Subject: [PATCH] Avoid expression parsing crash with unknown language Date: Thu, 15 Jul 2021 10:16:18 -0600 Message-Id: <20210715161618.234526-1-tromey@adacore.com> X-Mailer: git-send-email 2.26.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tom Tromey Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" PR gdb/28093 points out that gdb crashes when language is set to "unknown" and expression parsing is attempted. At first I thought this was a regression due to the expression rewrite, but it turns out that older versions crash as well. This patch avoids the crash by changing the default expression parser to throw an exception. I think this is preferable -- the current behavior of silently doing nothing does not really make sense. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28093 --- gdb/language.c | 4 ++-- gdb/testsuite/gdb.base/langs.exp | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/gdb/language.c b/gdb/language.c index 0d1e3848de8..45ce2ebcc92 100644 --- a/gdb/language.c +++ b/gdb/language.c @@ -825,8 +825,8 @@ class auto_or_unknown_language : public language_defn int parser (struct parser_state *ps) const override { - /* No parsing is done, just claim success. */ - return 1; + error (_("expression parsing not implemented for language \"%s\""), + natural_name ()); } /* See language.h. */ diff --git a/gdb/testsuite/gdb.base/langs.exp b/gdb/testsuite/gdb.base/langs.exp index 15908b0a19a..631401a8eab 100644 --- a/gdb/testsuite/gdb.base/langs.exp +++ b/gdb/testsuite/gdb.base/langs.exp @@ -111,6 +111,12 @@ if [runto csub] then { "set lang to minimal" gdb_test "print x" " = 5000" "print parameter value" + + # Ensure this at least does not crash. + gdb_test_no_output "set language unknown" + gdb_test "print x" \ + "expression parsing not implemented for language .Unknown." \ + "expression parsing does not crash for unknown" } set timeout $oldtimeout -- 2.26.3