public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/94845] New: DWARF function name doesn't match demangled name in base type template parameters
@ 2020-04-29 11:03 robert at ocallahan dot org
  2020-04-29 11:29 ` [Bug c++/94845] " robert at ocallahan dot org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: robert at ocallahan dot org @ 2020-04-29 11:03 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94845

            Bug ID: 94845
           Summary: DWARF function name doesn't match demangled name in
                    base type template parameters
           Product: gcc
           Version: 9.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: robert at ocallahan dot org
  Target Milestone: ---

Example:

template <typename T> void func(T s) {}
int main(void) {
  func<short>(-1);
  return 0;
}

$ g++ -g -o ~/tmp/test ~/tmp/test.cc && objdump -g ~/tmp/test|grep func
    <2a>   DW_AT_name        : (indirect string, offset: 0x0): func<short int>
    <31>   DW_AT_linkage_name: (indirect string, offset: 0x10): _Z4funcIsEvT_
$ c++filt _Z4funcIsEvT_
void func<short>(short)

It's unclear why 'short int' appears instead of just 'short'. It would be
simpler if they were consistent (and, well, shorter). clang++ generates
'short'.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/94845] DWARF function name doesn't match demangled name in base type template parameters
  2020-04-29 11:03 [Bug c++/94845] New: DWARF function name doesn't match demangled name in base type template parameters robert at ocallahan dot org
@ 2020-04-29 11:29 ` robert at ocallahan dot org
  2020-04-29 11:50 ` pinskia at gcc dot gnu.org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: robert at ocallahan dot org @ 2020-04-29 11:29 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94845

--- Comment #1 from robert at ocallahan dot org <robert at ocallahan dot org> ---
One case where this causes problems is implementing a debugger where you want
to be able to evaluate expressions containing type names. Type names containing
template type parameters that are base types need to be normalized to match the
type names in the debuginfo. g++ requires us to normalize those type names in a
way that's different from the C++ demangler and from clang++.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/94845] DWARF function name doesn't match demangled name in base type template parameters
  2020-04-29 11:03 [Bug c++/94845] New: DWARF function name doesn't match demangled name in base type template parameters robert at ocallahan dot org
  2020-04-29 11:29 ` [Bug c++/94845] " robert at ocallahan dot org
@ 2020-04-29 11:50 ` pinskia at gcc dot gnu.org
  2020-04-29 11:52 ` pinskia at gcc dot gnu.org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2020-04-29 11:50 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94845

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Hmm from http://wiki.dwarfstd.org/index.php?title=Best_Practices
For template instantiations, the DW_AT_name attribute should contain both the
source language name of the object and the template parameters that distinguish
one instantiation from another. The resulting string should be in the natural
form for the language, and should have a canonical representation (i.e.,
different producers should generate the same representation). For C++, the
string should match that produced by the target platform's canonical demangler;
spaces should only be inserted where syntactically required by the compiler.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/94845] DWARF function name doesn't match demangled name in base type template parameters
  2020-04-29 11:03 [Bug c++/94845] New: DWARF function name doesn't match demangled name in base type template parameters robert at ocallahan dot org
  2020-04-29 11:29 ` [Bug c++/94845] " robert at ocallahan dot org
  2020-04-29 11:50 ` pinskia at gcc dot gnu.org
@ 2020-04-29 11:52 ` pinskia at gcc dot gnu.org
  2020-04-29 12:00 ` pinskia at gcc dot gnu.org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2020-04-29 11:52 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94845

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
But that is just best practices, that does not mean an consumer of the dwarf
does not need to consume slightly different but still correct dwarf code.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/94845] DWARF function name doesn't match demangled name in base type template parameters
  2020-04-29 11:03 [Bug c++/94845] New: DWARF function name doesn't match demangled name in base type template parameters robert at ocallahan dot org
                   ` (2 preceding siblings ...)
  2020-04-29 11:52 ` pinskia at gcc dot gnu.org
@ 2020-04-29 12:00 ` pinskia at gcc dot gnu.org
  2020-04-29 12:19 ` robert at ocallahan dot org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2020-04-29 12:00 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94845

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
See also PR 81932 where we talked about 2 and 2u

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/94845] DWARF function name doesn't match demangled name in base type template parameters
  2020-04-29 11:03 [Bug c++/94845] New: DWARF function name doesn't match demangled name in base type template parameters robert at ocallahan dot org
                   ` (3 preceding siblings ...)
  2020-04-29 12:00 ` pinskia at gcc dot gnu.org
@ 2020-04-29 12:19 ` robert at ocallahan dot org
  2021-04-22 19:06 ` tromey at gcc dot gnu.org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: robert at ocallahan dot org @ 2020-04-29 12:19 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94845

--- Comment #5 from robert at ocallahan dot org <robert at ocallahan dot org> ---
We do our best to consume what g++ produces, but in the situation of comment #1
that is difficult. Whether or not it's "correct DWARF" is really irrelevant;
not matching the demangler causes real problems.

Thanks for the link to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81932. That
is very similar to the problem I'm facing. No strategy was decided on there,
but it seems to me that matching the demanged name would be a clear step in the
right direction. I can't see how it could *hurt*.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/94845] DWARF function name doesn't match demangled name in base type template parameters
  2020-04-29 11:03 [Bug c++/94845] New: DWARF function name doesn't match demangled name in base type template parameters robert at ocallahan dot org
                   ` (4 preceding siblings ...)
  2020-04-29 12:19 ` robert at ocallahan dot org
@ 2021-04-22 19:06 ` tromey at gcc dot gnu.org
  2021-04-22 22:49 ` robert at ocallahan dot org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: tromey at gcc dot gnu.org @ 2021-04-22 19:06 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94845

Tom Tromey <tromey at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tromey at gcc dot gnu.org

--- Comment #6 from Tom Tromey <tromey at gcc dot gnu.org> ---
gdb does this canonicalization precisely because the form
in the DWARF cannot be relied upon.
It would be great to remove this, because it is expensive.

One idea for a migration route would be for g++ to promise
to emit the same form that the demangler emits; then
add an attribute to the comp-unit DIE saying that the names
have been canonicalized.  (Or, I suppose gdb could use
producer sniffing; but I'd rather avoid that as much as possible.)

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/94845] DWARF function name doesn't match demangled name in base type template parameters
  2020-04-29 11:03 [Bug c++/94845] New: DWARF function name doesn't match demangled name in base type template parameters robert at ocallahan dot org
                   ` (5 preceding siblings ...)
  2021-04-22 19:06 ` tromey at gcc dot gnu.org
@ 2021-04-22 22:49 ` robert at ocallahan dot org
  2021-04-23  1:38 ` tromey at gcc dot gnu.org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: robert at ocallahan dot org @ 2021-04-22 22:49 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94845

--- Comment #7 from robert at ocallahan dot org <robert at ocallahan dot org> ---
So gdb reads DW_AT_name "func<short int>", parses it, reserializes it to
"func<short>", and uses that?

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/94845] DWARF function name doesn't match demangled name in base type template parameters
  2020-04-29 11:03 [Bug c++/94845] New: DWARF function name doesn't match demangled name in base type template parameters robert at ocallahan dot org
                   ` (6 preceding siblings ...)
  2021-04-22 22:49 ` robert at ocallahan dot org
@ 2021-04-23  1:38 ` tromey at gcc dot gnu.org
  2021-04-23  2:27 ` robert at ocallahan dot org
  2022-10-21 17:48 ` tromey at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: tromey at gcc dot gnu.org @ 2021-04-23  1:38 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94845

--- Comment #8 from Tom Tromey <tromey at gcc dot gnu.org> ---
(In reply to robert@ocallahan.org from comment #7)
> So gdb reads DW_AT_name "func<short int>", parses it, reserializes it to
> "func<short>", and uses that?

Yeah.  (Actually it's even worse than that, because at least one
compiler doesn't emit the template parameters in the name, so
in that case gdb will read the children of the DIE to try to
construct this form.)

I think the reasoning behind the canonicalization is two-fold.
First, I think we tried to get g++ changed, back in the day,
without success.

Second, gdb has to canonicalize user input anyway, so that
things like "print func<short int>(3)" or "break func<short int>"
work.  And once you have a canonicalizer it is simpler to just
use it to work around the problem.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/94845] DWARF function name doesn't match demangled name in base type template parameters
  2020-04-29 11:03 [Bug c++/94845] New: DWARF function name doesn't match demangled name in base type template parameters robert at ocallahan dot org
                   ` (7 preceding siblings ...)
  2021-04-23  1:38 ` tromey at gcc dot gnu.org
@ 2021-04-23  2:27 ` robert at ocallahan dot org
  2022-10-21 17:48 ` tromey at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: robert at ocallahan dot org @ 2021-04-23  2:27 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94845

--- Comment #9 from robert at ocallahan dot org <robert at ocallahan dot org> ---
That makes sense ... well, except implementing a full C++ parser and
reserializer is horrific.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/94845] DWARF function name doesn't match demangled name in base type template parameters
  2020-04-29 11:03 [Bug c++/94845] New: DWARF function name doesn't match demangled name in base type template parameters robert at ocallahan dot org
                   ` (8 preceding siblings ...)
  2021-04-23  2:27 ` robert at ocallahan dot org
@ 2022-10-21 17:48 ` tromey at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: tromey at gcc dot gnu.org @ 2022-10-21 17:48 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94845

--- Comment #10 from Tom Tromey <tromey at gcc dot gnu.org> ---
See also bug #49130 and bug #49537, which we filed when
gdb hit these same problems.

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2022-10-21 17:48 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-29 11:03 [Bug c++/94845] New: DWARF function name doesn't match demangled name in base type template parameters robert at ocallahan dot org
2020-04-29 11:29 ` [Bug c++/94845] " robert at ocallahan dot org
2020-04-29 11:50 ` pinskia at gcc dot gnu.org
2020-04-29 11:52 ` pinskia at gcc dot gnu.org
2020-04-29 12:00 ` pinskia at gcc dot gnu.org
2020-04-29 12:19 ` robert at ocallahan dot org
2021-04-22 19:06 ` tromey at gcc dot gnu.org
2021-04-22 22:49 ` robert at ocallahan dot org
2021-04-23  1:38 ` tromey at gcc dot gnu.org
2021-04-23  2:27 ` robert at ocallahan dot org
2022-10-21 17:48 ` tromey at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).