From: Simon Marchi <simon.marchi@efficios.com>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH 06/13] gdb: check exact results in the canonicalize selftest
Date: Tue, 20 Oct 2026 12:17:28 -0400 [thread overview]
Message-ID: <20261020162054.2140671-7-simon.marchi@efficios.com> (raw)
In-Reply-To: <20261020162054.2140671-1-simon.marchi@efficios.com>
The canonicalize selftest uses should_be_the_same, which canonicalizes
two names and checks that the results are equal. This doesn't check
what the canonical form actually is: both names going through the same
wrong conversion would still pass.
Replace should_be_the_same with should_canonicalize_to, which
canonicalizes a name and compares the result to an expected string.
Convert the existing tests: each name that was passed to
should_be_the_same is now checked against the canonical form.
Change-Id: Iaaa4712255a4d140b8a9756ccca062f4dc251f13
---
gdb/cp-name-parser.c | 59 ++++++++++++++++++++++++--------------------
1 file changed, 32 insertions(+), 27 deletions(-)
diff --git a/gdb/cp-name-parser.c b/gdb/cp-name-parser.c
index 710ffafcfc13..8012d6cc0a20 100644
--- a/gdb/cp-name-parser.c
+++ b/gdb/cp-name-parser.c
@@ -1023,18 +1023,19 @@ cpname_yylex (cp_name_parser_YYSTYPE *lvalp,
#if GDB_SELF_TEST
+/* Check that canonicalizing NAME gives EXPECTED. */
+
static void
-should_be_the_same (const char *one, const char *two)
+should_canonicalize_to (const char *name, const char *expected)
{
- gdb::unique_xmalloc_ptr<char> cpone = cp_canonicalize_string (one);
- gdb::unique_xmalloc_ptr<char> cptwo = cp_canonicalize_string (two);
+ gdb::unique_xmalloc_ptr<char> canon = cp_canonicalize_string (name);
+ const char *result = canon != nullptr ? canon.get () : name;
- if (cpone != nullptr)
- one = cpone.get ();
- if (cptwo != nullptr)
- two = cptwo.get ();
+ if (!streq (result, expected))
+ debug_printf ("canonicalize: \"%s\" gave \"%s\", expected \"%s\"\n",
+ name, result, expected);
- SELF_CHECK (streq (one, two));
+ SELF_CHECK (streq (result, expected));
}
static void
@@ -1047,30 +1048,34 @@ should_parse (const char *name)
static void
canonicalize_tests ()
{
- should_be_the_same ("short int", "short");
- should_be_the_same ("int short", "short");
+ should_canonicalize_to ("short int", "short");
+ should_canonicalize_to ("int short", "short");
- should_be_the_same ("C<(char) 1>::m()", "C<(char) '\\001'>::m()");
- should_be_the_same ("x::y::z<1>", "x::y::z<0x01>");
- should_be_the_same ("x::y::z<1>", "x::y::z<01>");
- should_be_the_same ("x::y::z<(unsigned long long) 1>", "x::y::z<01ull>");
- should_be_the_same ("x::y::z<0b111>", "x::y::z<7>");
- should_be_the_same ("x::y::z<0b111>", "x::y::z<0t7>");
- should_be_the_same ("x::y::z<0b111>", "x::y::z<0D7>");
+ should_canonicalize_to ("C<(char) 1>::m()", "C<(char)1>::m()");
+ should_canonicalize_to ("C<(char) '\\001'>::m()", "C<(char)1>::m()");
+ should_canonicalize_to ("x::y::z<0x01>", "x::y::z<1>");
+ should_canonicalize_to ("x::y::z<01>", "x::y::z<1>");
+ should_canonicalize_to ("x::y::z<(unsigned long long) 1>", "x::y::z<1ull>");
+ should_canonicalize_to ("x::y::z<01ull>", "x::y::z<1ull>");
+ should_canonicalize_to ("x::y::z<0b111>", "x::y::z<7>");
+ should_canonicalize_to ("x::y::z<0t7>", "x::y::z<7>");
+ should_canonicalize_to ("x::y::z<0D7>", "x::y::z<7>");
- should_be_the_same ("x::y::z<0xff'ff>", "x::y::z<65535>");
+ should_canonicalize_to ("x::y::z<0xff'ff>", "x::y::z<65535>");
- should_be_the_same ("something<void ()>", "something< void() >");
- should_be_the_same ("something<void ()>", "something<void (void)>");
+ should_canonicalize_to ("something< void() >", "something<void()>");
+ should_canonicalize_to ("something<void (void)>", "something<void()>");
- should_be_the_same ("Foozle<int>::fogey<Empty<int> > (Empty<int>)",
- "Foozle<int>::fogey<Empty<int>> (Empty<int>)");
+ should_canonicalize_to ("Foozle<int>::fogey<Empty<int> > (Empty<int>)",
+ "Foozle<int>::fogey<Empty<int> >(Empty<int>)");
+ should_canonicalize_to ("Foozle<int>::fogey<Empty<int>> (Empty<int>)",
+ "Foozle<int>::fogey<Empty<int> >(Empty<int>)");
- should_be_the_same ("something :: operator new [ ]",
- "something::operator new[]");
- should_be_the_same ("something :: operator new",
- "something::operator new");
- should_be_the_same ("operator()", "operator ()");
+ should_canonicalize_to ("something :: operator new [ ]",
+ "something::operator new[]");
+ should_canonicalize_to ("something :: operator new",
+ "something::operator new");
+ should_canonicalize_to ("operator ()", "operator()");
}
/* Test the C++ name parser's handling of some inputs. */
--
2.56.0
next prev parent reply other threads:[~2026-10-20 16:23 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-20 16:17 [PATCH 00/13] Make the C++ name parser recognize more char literal forms Simon Marchi
2026-10-20 16:17 ` [PATCH 01/13] gdb: make demangle_parse_info own the memory its tree points into Simon Marchi
2026-10-20 16:17 ` [PATCH 02/13] gdb: remove p_allocated_size parameter of gdb_cplus_demangle_print Simon Marchi
2026-10-20 16:17 ` [PATCH 03/13] gdb: modernize mangled_name_to_comp and cp_class_name_from_physname Simon Marchi
2026-10-20 16:17 ` [PATCH 04/13] gdb: fix crash in "maint canonicalize" without argument Simon Marchi
2026-10-20 16:17 ` [PATCH 05/13] gdb: move C++ name parser parsing selftest to its own test Simon Marchi
2026-10-20 16:17 ` Simon Marchi [this message]
2026-10-21 15:21 ` [PATCH 06/13] gdb: check exact results in the canonicalize selftest Tom Tromey
2026-10-21 15:48 ` Simon Marchi
2026-10-21 16:56 ` Tom Tromey
2026-10-21 17:01 ` Simon Marchi
2026-10-21 17:48 ` Tom Tromey
2026-10-22 16:28 ` Simon Marchi
2026-10-20 16:17 ` [PATCH 07/13] gdb: extract lex_char_literal from cpname_yylex Simon Marchi
2026-10-21 15:22 ` Tom Tromey
2026-10-20 16:17 ` [PATCH 08/13] gdb: remove \^ escape sequence support from C++ name parser Simon Marchi
2026-10-20 16:17 ` [PATCH 09/13] gdb: remove backslash-newline handling from cp_parse_escape Simon Marchi
2026-10-20 16:17 ` [PATCH 10/13] gdb: fix out-of-bounds reads in lex_char_literal Simon Marchi
2026-10-20 16:17 ` [PATCH 11/13] gdb: handle hexadecimal escapes in C++ name parser Simon Marchi
2026-10-20 16:17 ` [PATCH 12/13] gdb: handle character literal encoding prefixes " Simon Marchi
2026-10-20 16:17 ` [PATCH 13/13] gdb: handle universal character names " Simon Marchi
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=20261020162054.2140671-7-simon.marchi@efficios.com \
--to=simon.marchi@efficios.com \
--cc=gdb-patches@sourceware.org \
/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