problems with C++11 templates?
Jason Vas Dias <[email protected]>
| Newsgroups | gmane.comp.gdb.devel |
|---|---|
| Message-ID | <CALyZvKyEAS=wwjnBEVfkZa3Cm21TupOWCxbj4op0fYkUrM5vag@mail.gmail.com> |
Good day -
I have a C++ program compiled with -std=gnu++17 , and
optimization options '-g3' (& -pthread) - there is a class template with
a static data member that resides in TLS :
template< ... >
class X
{ static thread_local X *_origin ;
...
X() { if(_nullptr == _origin) _origin = const_cast<X*>(this) ; ... }
...
};
template <...>
thread_local X<...>* X<...>::_origin = nullptr;
The program work fine when run outside GDB , and inside
GDB if I DO NOT attempt to set a breakpoint within X .
But if I try to insert a breakpoint in any member function
of X, particularly in a constructor, gdb gives me errors.
If I load the program in gdb ( 7.12.1 for Linux, glibc-2.25,
gcc-5.4.0 AND 6.3.0, other binutils all from version 2.28 ) ,
and type 'start' , and then break at the X<...>::X() constructor
outlined above:
(gdb) n
Breakpoint 2, X<...>::X (this=0x7fffffffd8d0) at ./X.h:148
148 { if(_nullptr == _origin) _origin = const_cast<X*>(this) ; .
(gdb) info symbol _origin
warning: RTTI symbol not found for class 'X<...>'
value has been optimized out
(gdb) n
Program received signal SIGSEGV, Segmentation fault.
...
148 { if( nullptr == _origin ) _origin = const_cast<X*>(this);
(gdb) q
Note this does NOT happen if I just run the program outside of GDB,
or in GDB, breaking at a later point, or do not attempt to examine
X::_origin in GDB .
This makes me think there is a problem with GDB here, and not with my program,
which compiles with '-Wall -Wextra -Werror' with no problems and never
core-dumps when run outside of GDB .
Has GDB 8.0's C++14+ support improved ?
I'm trying building gdb-8.0 and gcc-7.0 now .
I'd like to be able to debug my C++ programs and break at any
arbitrary constructor with GDB - but it is getting difficult if
advanced C++ features
such as 'thread_local' support are used.
Thanks in advance for any advice / responses.
Regards,
Jason