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
(cherry picked from commit dcd482c1b7)

gdb/ChangeLog
2021-07-19  Tom Tromey  <tromey@adacore.com>

	PR gdb/28093
	* language.c (auto_or_unknown_language::parser): Call error.

gdb/testsuite/ChangeLog
2021-07-19  Tom Tromey  <tromey@adacore.com>

	PR gdb/28093
	* gdb.base/langs.exp: Add tests.
This commit is contained in:
Tom Tromey
2021-07-15 10:13:18 -06:00
parent 51799bd45f
commit e22715ce30
4 changed files with 18 additions and 2 deletions

View File

@@ -1,3 +1,8 @@
2021-07-19 Tom Tromey <tromey@adacore.com>
PR gdb/28093
* language.c (auto_or_unknown_language::parser): Call error.
2021-07-17 Sergey Belyashov <Sergey.Belyashov@gmail.com>
* Makefile.in (ALL_TARGET_OBS): Add z80-tdep.c.

View File

@@ -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. */

View File

@@ -1,3 +1,8 @@
2021-07-19 Tom Tromey <tromey@adacore.com>
PR gdb/28093
* gdb.base/langs.exp: Add tests.
2021-07-14 Tom de Vries <tdevries@suse.de>
* lib/gdb.exp (have_index): New proc.

View File

@@ -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