Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@efficios.com>
To: Tom Tromey <tom@tromey.com>, Simon Marchi <simark@simark.ca>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 06/13] gdb: check exact results in the canonicalize selftest
Date: Fri, 6 Nov 2026 14:24:29 -0500	[thread overview]
Message-ID: <391abdd3-8bba-4702-9a84-0c4086ea6b85@efficios.com> (raw)
In-Reply-To: <87y0b7xfv0.fsf@tromey.com>

On 11/5/26 2:01 PM, Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi <simark@simark.ca> writes:
> 
>>> What I mean is that my wish is that gdb internals shouldn't care about
>>> the precise spelling that the canonicalizer spits out.
> 
> Simon>     template <unsigned char N>
> Simon>     struct C {};
> Simon>     C<0> c;
> ...
> Simon>     C<(unsigned char)'\x00'>
> ...
> Simon>     C<(unsigned char)0>
> 
> Simon> If the user does:
> Simon>     (gdb) ptype C<0>
> Simon> GDB does does not find the type.  They would have to do:
> 
> Simon> To implement this, strncmp_iw_with_mode will need to have some form of
> Simon> integer literal parsing, but it will be limited to just what can
> Simon> possibly be found in a canonical name.
> 
> Ok, thanks for the explanation.
> 
> Let me start by saying I kind of hate making the strcmp*iw* functions
> more intelligent.  I'd rather they not exist at all, though TBH I don't
> know how achievable that is.  I guess my main reason is that they seem
> fairly hairy and fragile for a task that seems like it could be done
> more straightforwardly (and maybe, to some degree, this is shown to be
> true in the cooked indexer).

I agree that the strcmp*iw* functions are not fun to work with, but I
don't see any way out of this since the index keys are just plain
strings.

> So I'm not exactly neutral.  That said, in this particular case it seems
> to me that the underlying problem is something that can be solved
> directly in the name canonicalizer.
> 
> That is, if we want C<(unsigned char) 0> to be equivalent to various
> other spellings, including C<0>, then a good solution is to use C<0> as
> the canonical form.
> 
> This is pretty much the reason canonicalization is done at all: to iron
> over the differences between the various possible spellings.  This makes
> gdb indifferent to the spelling, but more importantly means that the
> user doesn't need to know exactly what the compiler decided to emit in
> the debuginfo.
> 
> Did you consider this approach and reject it for some reason?

I don't recall trying this, no.  Perhaps this would help fix the most
obvious cases of GDB not finding what the user wants, but I don't know
if it would introduce any ambiguities or false positive matches.

> I guess a counter to this would be if there is a case where it's
> important to distinguish C<0> from C<(unsigned char) 0>.  But if there
> is, then maybe the proposed strcmp*iw* patch would be a problem here too?

I think there is a case for distinguishing them, but I don't know if
it's the index's job to do that.  The program could legitimately have C<0> (where the
parameter is an int) and C<(unsigned char) 0> (where the parameter is an
unsigned char).  If the user asks for:

  (gdb) ptype C<(unsigned char) 0>

versus

  (gdb) ptype C<(int) 0>

then it would be better to find the more specific match.  But maybe the
index's job is to return all potential matches, and it is the caller's
job to do some more thorough checks, filtering and sorting, once the CU
is expanded.

> FWIW I also have a dream of making the canonicalizer less intelligent as
> well.  Like I wonder if the parser can be replaced with something closer
> to a tokenizer.  The reason to do this is that C++ keeps growing and the
> canonicalizer isn't really keeping up.

I don't really understand the difference between the two.

That being said:

 - Even if the exact canonical form is not necessarily important and
   could change over time, I am still of the opinion that it helps to
   see what it currently is in the tests, which is why I prefer if
   the tests check for the exact result of the canonicalizer.  There is
   nothing preventing us updating these tests should the canonical form
   change.

 - Some patches if this series are still probably relevant in any, for
   instance to teach cp-name-parser about some integer forms (e.g. hex
   escapes), so that cp-name-parser is able to ingest what clang
   produces.

Simon

  reply	other threads:[~2026-11-06 19:25 UTC|newest]

Thread overview: 24+ 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 ` [PATCH 06/13] gdb: check exact results in the canonicalize selftest Simon Marchi
2026-10-21 15:21   ` 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-11-05 19:01               ` Tom Tromey
2026-11-06 19:24                 ` Simon Marchi [this message]
2026-11-20 21:25             ` Tom Tromey
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=391abdd3-8bba-4702-9a84-0c4086ea6b85@efficios.com \
    --to=simon.marchi@efficios.com \
    --cc=gdb-patches@sourceware.org \
    --cc=simark@simark.ca \
    --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