* [PATCH] Avoid expression parsing crash with unknown language @ 2021-07-15 16:16 Tom Tromey 2021-07-15 16:28 ` Pedro Alves 0 siblings, 1 reply; 5+ messages in thread From: Tom Tromey @ 2021-07-15 16:16 UTC (permalink / raw) To: gdb-patches; +Cc: Tom Tromey 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 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Avoid expression parsing crash with unknown language 2021-07-15 16:16 [PATCH] Avoid expression parsing crash with unknown language Tom Tromey @ 2021-07-15 16:28 ` Pedro Alves 2021-07-15 19:06 ` Tom Tromey 0 siblings, 1 reply; 5+ messages in thread From: Pedro Alves @ 2021-07-15 16:28 UTC (permalink / raw) To: Tom Tromey, gdb-patches On 2021-07-15 5:16 p.m., Tom Tromey wrote: > 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 Looks good, thanks! ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Avoid expression parsing crash with unknown language 2021-07-15 16:28 ` Pedro Alves @ 2021-07-15 19:06 ` Tom Tromey 2021-07-17 18:37 ` Joel Brobecker 0 siblings, 1 reply; 5+ messages in thread From: Tom Tromey @ 2021-07-15 19:06 UTC (permalink / raw) To: Pedro Alves; +Cc: gdb-patches, Tom Tromey >> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28093 Pedro> Looks good, thanks! Thanks. I wonder if this should be put on the 11 branch as well? It's not a regression but OTOH the patch is small & pretty obvious. Tom ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Avoid expression parsing crash with unknown language 2021-07-15 19:06 ` Tom Tromey @ 2021-07-17 18:37 ` Joel Brobecker 2021-07-19 17:08 ` Tom Tromey 0 siblings, 1 reply; 5+ messages in thread From: Joel Brobecker @ 2021-07-17 18:37 UTC (permalink / raw) To: Tom Tromey; +Cc: Joel Brobecker, gdb-patches > >> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28093 > > Pedro> Looks good, thanks! > > Thanks. I wonder if this should be put on the 11 branch as well? > It's not a regression but OTOH the patch is small & pretty obvious. That seems like a good idea to me too. Thanks Tom. -- Joel ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Avoid expression parsing crash with unknown language 2021-07-17 18:37 ` Joel Brobecker @ 2021-07-19 17:08 ` Tom Tromey 0 siblings, 0 replies; 5+ messages in thread From: Tom Tromey @ 2021-07-19 17:08 UTC (permalink / raw) To: Joel Brobecker; +Cc: gdb-patches, Tom Tromey >>>>> "Joel" == Joel Brobecker <brobecker@adacore.com> writes: >> >> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28093 >> Pedro> Looks good, thanks! >> >> Thanks. I wonder if this should be put on the 11 branch as well? >> It's not a regression but OTOH the patch is small & pretty obvious. Joel> That seems like a good idea to me too. Ok, I wrote a ChangeLog entry and pushed it. Tom ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-07-19 17:09 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2021-07-15 16:16 [PATCH] Avoid expression parsing crash with unknown language Tom Tromey 2021-07-15 16:28 ` Pedro Alves 2021-07-15 19:06 ` Tom Tromey 2021-07-17 18:37 ` Joel Brobecker 2021-07-19 17:08 ` Tom Tromey
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox