From: Tom de Vries via Gdb-patches <gdb-patches@sourceware.org>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH][gdb] Handle NOT_SUPPORTED_ERROR in rust-lex selftest
Date: Tue, 7 Jun 2022 14:17:14 +0200 [thread overview]
Message-ID: <20220607121713.GA22302@delia.home> (raw)
Hi,
When running selftest rust-lex on an openSUSE Leap 15.3 system with
glibc-locale-base and glibc-locale packages deinstalled, we run into:
...
$ gdb -q -batch -ex "maint selftest rust-lex"
Running selftest rust-lex.
Self test failed: Cannot convert between character sets `ANSI_X3.4-1968' and \
`UTF-32LE'
...
Fix this by skipping the selftests that run into NOT_SUPPORTED_ERROR.
This exposes that rust_parser::lex_string can leave the obstack in an
intermediate state when an error is throw, which makes subsequent selftests
fail. Fix this by finalizing the obstack using SCOPE_EXIT.
Tested on x86_64-linux.
https://sourceware.org/bugzilla/show_bug.cgi?id=29202
Any comments?
Thanks,
- Tom
[gdb] Handle NOT_SUPPORTED_ERROR in rust-lex selftest
---
gdb/rust-parse.c | 31 ++++++++++++++++++++++++-------
1 file changed, 24 insertions(+), 7 deletions(-)
diff --git a/gdb/rust-parse.c b/gdb/rust-parse.c
index f5eb63ec1e3..fb128367f66 100644
--- a/gdb/rust-parse.c
+++ b/gdb/rust-parse.c
@@ -687,6 +687,12 @@ rust_parser::lex_string ()
int is_byte = pstate->lexptr[0] == 'b';
int raw_length;
+ SCOPE_EXIT
+ {
+ current_string_val.length = obstack_object_size (&obstack);
+ current_string_val.ptr = (const char *) obstack_finish (&obstack);
+ };
+
if (is_byte)
++pstate->lexptr;
raw_length = starts_raw_string (pstate->lexptr);
@@ -747,8 +753,6 @@ rust_parser::lex_string ()
}
}
- current_string_val.length = obstack_object_size (&obstack);
- current_string_val.ptr = (const char *) obstack_finish (&obstack);
return is_byte ? BYTESTRING : STRING;
}
@@ -2146,14 +2150,23 @@ rust_language::parser (struct parser_state *state) const
/* A test helper that lexes a string, expecting a single token. */
-static void
+static bool
rust_lex_test_one (rust_parser *parser, const char *input, int expected)
{
int token;
parser->reset (input);
- token = parser->lex_one_token ();
+ try
+ {
+ token = parser->lex_one_token ();
+ }
+ catch (const gdb_exception &exc)
+ {
+ if (exc.error == NOT_SUPPORTED_ERROR)
+ return false;
+ throw;
+ }
SELF_CHECK (token == expected);
if (token)
@@ -2161,6 +2174,7 @@ rust_lex_test_one (rust_parser *parser, const char *input, int expected)
token = parser->lex_one_token ();
SELF_CHECK (token == 0);
}
+ return true;
}
/* Test that INPUT lexes as the integer VALUE. */
@@ -2169,7 +2183,8 @@ static void
rust_lex_int_test (rust_parser *parser, const char *input,
ULONGEST value, int kind)
{
- rust_lex_test_one (parser, input, kind);
+ if (!rust_lex_test_one (parser, input, kind))
+ return;
SELF_CHECK (parser->current_int_val.val == value);
}
@@ -2182,7 +2197,8 @@ rust_lex_exception_test (rust_parser *parser, const char *input,
try
{
/* The "kind" doesn't matter. */
- rust_lex_test_one (parser, input, DECIMAL_INTEGER);
+ if (!rust_lex_test_one (parser, input, DECIMAL_INTEGER))
+ return;
SELF_CHECK (0);
}
catch (const gdb_exception_error &except)
@@ -2198,7 +2214,8 @@ static void
rust_lex_stringish_test (rust_parser *parser, const char *input,
const char *value, int kind)
{
- rust_lex_test_one (parser, input, kind);
+ if (!rust_lex_test_one (parser, input, kind))
+ return;
SELF_CHECK (parser->get_string () == value);
}
reply other threads:[~2022-06-07 12:17 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220607121713.GA22302@delia.home \
--to=gdb-patches@sourceware.org \
--cc=tdevries@suse.de \
--cc=tom@tromey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox