Created attachment 6531 [details] gdb-fix-crash-when-checking-for-ctor-of-lambda by Thomas Voß Using GDB to debug this test case: http://pastebin.ubuntu.com/1062024/ causes it to crash in is_ctor_or_dtor. Attached here patch by Thomas Voß that fixes it. This is description: «It turns out that gdb crashes as it tries to determine whether a field of a lambda is a or ctor/dtor, given the fields name. Apparently, the field's name is NULL and I added a check for that, bailing out and returning 0 ("no, this is neither a dtor nor a ctor"). GDB behaves normally when being run on the test program mentioned before. Patch is attached, generated with quilt.» See launchpad bug http://pad.lv/1006860 for reference.
Please post any patches to gdb-patches at sourceware.org.
I reproduced the bug. I don't think this is the correct fix. What seems to be happening here is that we are trying to compute the physname for a type that is a pointer to a member function of an unnamed structure type. Because it is unnamed, c_type_print_base falls through to printing the body of the structure, instead of its name. This then crashes. Maybe NULL checks in is_constructor_name and is_destructor_name would be ok; though I am not sure. But even if those were there we would still be seeing very weird results here.
BTW I reproduced using the reported test case: #include <sigc++/sigc++.h> #if __cplusplus >= 201100L || defined (__GXX_EXPERIMENTAL_CXX0X__) #include <type_traits> namespace sigc { template <typename Functor> struct functor_trait<Functor, false> { typedef decltype (::sigc::mem_fun(std::declval<Functor&>(), &Functor::operator())) _intermediate; typedef typename _intermediate::result_type result_type; typedef Functor functor_type; }; } #endif int main() { sigc::slot <bool> slot3 = [] () -> bool { return true; }; sigc::slot <bool, int> slot4 = [] (int) -> bool { return true; }; while (1); } and building it on Fedora 16 with g++ -std=c++0x -g -o pr pr.cc $(pkg-config --cflags sigc++-2.0) $(pkg-config --libs sigc++-2.0) Simplest way to see it is "gdb -readnow pr"
I think Tom is correct. IMO the questionable thing done here is asking c_type_print_base to print details of the type when we have a pointer member/method whose containing class/struct is anonymous (TYPE_NAME (type) == NULL). That just doesn't seem right. I believe the proper fix is simply for c_type_print_varspec_prefix to honor the SHOW parameter when it is calling other c_type_print_* functions. In this function, the only cases which do not pass SHOW to the other type printing functions are MEMBERPTR and METHODPTR, exactly where we are seeing problems. I'm working on a test case for this now, and will submit a patch when it is finished. [It requires hand-written DWARF.]
CVSROOT: /cvs/src Module name: src Changes by: kseitz@sourceware.org 2012-08-19 19:37:51 Modified files: gdb : ChangeLog c-typeprint.c gdb/testsuite : ChangeLog Added files: gdb/testsuite/gdb.dwarf2: dw2-anon-mptr.exp dw2-anon-mptr.S Log message: PR c++/14365 * c-typeprint.c (c_type_print_varspec_prefix): Pass -1 for SHOW to c_type_print_base for METHODPTR and MEMBERPTR. * gdb.dwarf2/dw2-anon-mptr.exp: New file. * gdb.dwarf2/dw2-anon-mptr.S: New file. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/ChangeLog.diff?cvsroot=src&r1=1.14602&r2=1.14603 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/c-typeprint.c.diff?cvsroot=src&r1=1.75&r2=1.76 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/testsuite/ChangeLog.diff?cvsroot=src&r1=1.3343&r2=1.3344 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/testsuite/gdb.dwarf2/dw2-anon-mptr.exp.diff?cvsroot=src&r1=NONE&r2=1.1 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/testsuite/gdb.dwarf2/dw2-anon-mptr.S.diff?cvsroot=src&r1=NONE&r2=1.1
I have committed a patch to fix this. If there are any further problems, please let me know.