This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: beta patch for PR 9065
- From: Daniel Jacobowitz <dan at codesourcery dot com>
- To: Chris Moller <cmoller at redhat dot com>
- Cc: gdb-patches at sourceware dot org
- Date: Tue, 16 Feb 2010 16:53:16 -0500
- Subject: Re: beta patch for PR 9065
- References: <4B7AE477.9060606@redhat.com>
On Tue, Feb 16, 2010 at 01:31:19PM -0500, Chris Moller wrote:
> [Question: Internally, this patch is based on "sizeof" which actually
> creates an int type that, in addition to just being printed, can be
> used for stuff like "set <var> = sizeof(<whatever>)". The gdb typeid
> doesn't even try to create an analogue to a type_info class, it just
> extracts the name from the appropriate type struct and creates a
> cstring type from it. Would it be good/essential for the
> implementation to instantiate a real type_info class? (That, I
> suspect, will be a lot more work...)]
What do folks use typeid for, in the wild? IMO, "ptype typeid(int)"
giving you a string would be very surprising.
It's been a while since I looked at this, but the typeinfo for a class
with RTTI should be available in the symbol table (_ZTI symbols). The
others might be available or not; we could look them up in the symbol
table, or allocate them dynamically.
We could synthesize a type_info object; the Itanium C++ ABI defines
the layout (section 2.9.5). But we might also have to synthesize its
name() method, as it is unlikely to be emitted out of line.
name() is supposed to return a mangled type name, too. I'm not sure
how able GDB is going to be to mangle type names; it's a very hard
problem w.r.t. templates.
The appliction or libstdc++ should have the typeinfos for anything
whose typeinfo was referenced...
> @@ -1897,6 +1923,8 @@
> {"struct", STRUCT, OP_NULL, 0},
> {"signed", SIGNED_KEYWORD, OP_NULL, 0},
> {"sizeof", SIZEOF, OP_NULL, 0},
> + {"typeid", TYPEID, OP_NULL, 0},
> + {"name", NAMELIT, OP_NULL, 0},
> {"double", DOUBLE_KEYWORD, OP_NULL, 0},
> {"false", FALSEKEYWORD, OP_NULL, 1},
> {"class", CLASS, OP_NULL, 1},
I bet adding "name" to this list will break any expression with "name"
in it, like "print name".
--
Daniel Jacobowitz
CodeSourcery