[PATCH 06/13] gdb: check exact results in the canonicalize selftest

Tom Tromey tom@tromey.com
Thu Nov 5 19:01:07 GMT 2026


>>>>> "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).

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

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.

thanks,
Tom


More information about the Gdb-patches mailing list