From: Tom Tromey Date: Thu, 15 Jul 2021 16:13:18 +0000 (-0600) Subject: Avoid expression parsing crash with unknown language X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=dcd482c1b756d9da2130552a6eb58b852d6efb97;p=binutils-gdb.git Avoid expression parsing crash with unknown language 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 --- 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 @@ public: 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