[Converted from Gnats 1960] When I try expressions like print typeid(*this).name() I get the error No symbol "typeid" in current context. AFAIK, typeid is a C++ operator, not a local or global symbol. It would be very helpful if it were supported. Release: GNU gdb Red Hat Linux (6.1post-1.20040607.43rh)
From: "Grover, Alan" <grover@kuchera.com> To: <gdb-gnats@sources.redhat.com> Cc: Subject: Re: c++/1960: can't use typeid Date: Mon, 20 Jun 2005 07:36:25 -0400 The problem came about trying to debug a statement of the form: printf("Class id is %s\n", typeid(*this)); which works on most classes.=A0 One one class the printf seems to = complete (ie, the output appears on the console), but the process gets a = SIGSEGV and terminates at this point.=A0 Any ideas for debugging a = problem like that would be appreciated. Alan
I think this can easily be done for classes with vtables. For other types it does not appear to be easy; it may not even be possible.
(In reply to comment #2) > I think this can easily be done for classes with vtables. > For other types it does not appear to be easy; it may not > even be possible. We can be optimistic and try to find the symbol. For a type named T, we can just look up the symbol "typeinfo for T". E.g., from libstdc++ [...] 0000003be82eec80 V typeinfo for signed char 0000003be82eee60 V typeinfo for bool 0000003be82eece0 V typeinfo for char 0000003be82ee7a0 V typeinfo for double [...]
I have an initial patch for this.
CVSROOT: /cvs/src Module name: src Changes by: tromey@sourceware.org 2013-04-15 17:36:14 Modified files: gdb : ChangeLog NEWS breakpoint.c c-exp.y cp-abi.c cp-abi.h eval.c expprint.c gnu-v3-abi.c parse.c std-operator.def gdb/testsuite : ChangeLog Added files: gdb/testsuite/gdb.cp: typeid.cc typeid.exp Log message: PR c++/9065: * NEWS: Update. * breakpoint.c (watchpoint_exp_is_const): Add OP_TYPEID. * c-exp.y (TYPEID): New token. (exp): Add new TYPEID productions. (ident_tokens): Add "typeid". * cp-abi.c (cplus_typeid, cplus_typeid_type): New functions. * cp-abi.h (cplus_typeid, cplus_typeid_type): Declare. (struct cp_abi_ops) <get_typeid, get_typeid_type>: New fields. * eval.c (evaluate_subexp_standard) <OP_TYPEID>: New case. * expprint.c (dump_subexp_body_standard) <OP_TYPEID>: New case. * gnu-v3-abi.c (std_type_info_gdbarch_data): New global. (build_std_type_info_type, gnuv3_get_typeid_type) (gnuv3_get_typeid): New functions. (init_gnuv3_ops): Initialize std_type_info_gdbarch_data. Set new fields on ABI object. * parse.c (operator_length_standard) <OP_TYPEID>: New case. * std-operator.def (OP_TYPEID): New. gdb/testsuite * gdb.cp/typeid.cc: New file. * gdb.cp/typeid.exp: New file. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/ChangeLog.diff?cvsroot=src&r1=1.15412&r2=1.15413 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/NEWS.diff?cvsroot=src&r1=1.588&r2=1.589 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/breakpoint.c.diff?cvsroot=src&r1=1.754&r2=1.755 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/c-exp.y.diff?cvsroot=src&r1=1.116&r2=1.117 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/cp-abi.c.diff?cvsroot=src&r1=1.40&r2=1.41 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/cp-abi.h.diff?cvsroot=src&r1=1.25&r2=1.26 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/eval.c.diff?cvsroot=src&r1=1.181&r2=1.182 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/expprint.c.diff?cvsroot=src&r1=1.67&r2=1.68 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/gnu-v3-abi.c.diff?cvsroot=src&r1=1.82&r2=1.83 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/parse.c.diff?cvsroot=src&r1=1.139&r2=1.140 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/std-operator.def.diff?cvsroot=src&r1=1.10&r2=1.11 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/testsuite/ChangeLog.diff?cvsroot=src&r1=1.3624&r2=1.3625 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/testsuite/gdb.cp/typeid.cc.diff?cvsroot=src&r1=NONE&r2=1.1 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/testsuite/gdb.cp/typeid.exp.diff?cvsroot=src&r1=NONE&r2=1.1
Fix checked in.