Re: gdb 8.x - g++ 7.x compatibility

Jonathan Wakely <[email protected]>
Newsgroups gmane.comp.gcc.devel,gmane.comp.gdb.devel
Message-ID <CAH6eHdSepOk-v7jgV_-KQ2T_3-ABnuoj+SLT4cDo=HdJE4DEwQ@mail.gmail.com>
On 7 February 2018 at 17:03, Simon Marchi <[email protected]> wrote:
> On 2018-02-07 11:50, Jonathan Wakely wrote:
>>
>> On 7 February 2018 at 16:36, Simon Marchi wrote:
>>>
>>> On 2018-02-07 11:26, Michael Matz wrote:
>>>>
>>>>
>>>> Hi,
>>>>
>>>> On Wed, 7 Feb 2018, Simon Marchi wrote:
>>>>
>>>>> This addresses the issue of how to do good software design in GDB to
>>>>> support different producers cleanly, but I think we have some issues
>>>>> even before that, like how to support g++ 7.3 and up.  I'll try to
>>>>> summarize the issue quickly. It's now possible to end up with two
>>>>> templated classes with the same name that differ only by the signedness
>>>>> of their non-type template parameter.  One is Foo<int N> and the other
>>>>> is Foo<unsigned int N> (the 10 is unsigned).  Until 7.3, g++ would
>>>>> generate names like Foo<10> for the former and names like Foo<10u> for
>>>>> the later (in the DW_AT_name attribute of the classes' DIEs). Since
>>>>> 7.3,
>>>>> it produces Foo<10> for both.
>>>>
>>>>
>>>>
>>>> Yeah, gdb needs a way to lookup types by name, and since the change
>>>> DW_AT_name can't be used for this anymore.  Either that needs to be
>>>> fixed/reverted, or we do the more obvious thing: since types in C++ have
>>>> linkage it makes sense to add the linkage (i.e. mangled) name to the
>>>> types
>>>> DIE using the traditional DW_AT_MIPS_linkage_name.
>>>>
>>>> That latter solution would have the advantage that you don't need to
>>>> demangle anything anymore.  From vtable you get to typeinfo, from there
>>>> for typeinfo name, and that contains the mangled type name (without _Z
>>>> prefix).
>>>
>>>
>>>
>>> But do struct/classes have mangled names?
>>
>>
>> Yes.

Why would they not have a mangled name?

> Interesting.  What do they look like, and in what context do they appear?

Anywhere you need a name for linkage purposes, such as in a function
signature, or as a template argument of another type, or in the
std::type_info::name() for the type etc. etc.

$ g++ -o test.o -c -x c++ - <<< 'struct X {}; void f(X) {}
template<typename T> struct Y { }; void g(Y<X>) {}' && nm
--defined-only test.o
0000000000000000 T _Z1f1X
0000000000000007 T _Z1g1YI1XE

The mangled name for X is "X" and the mangled name for Y<X> is "YI1XE"
which includes the name "X".

This isn't really on-topic for solving the GDB type lookup problem though.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.