From: "Kenneth Rose" <kenrose@kenrose.org>
To: gdb@sourceware.org
Subject: Cast to result of whatis expression
Date: Tue, 07 Sep 2010 22:04:00 -0000 [thread overview]
Message-ID: <784f56871ebbe612785c8be91771a9a5.squirrel@webmail.kenrose.org> (raw)
Hi all,
I'm writing something similar to gdb-stl-views for some custom container
classes that we have. As opposed to the STL containers though, our
containers cast the datatype to void*. A minimalistic example looks like:
class ContainerBase
{
protected:
ContainerBase( void *x ) : m_x( x ) {}
void *m_x;
};
template<typename T>
class Container : public ContainerBase
{
public:
Container() : ContainerBase( new T ) {}
T& get() { return *static_cast<T*>( m_x ); }
};
Say I have the following code somewhere:
Container<int> foo;
I'd like to be able to have a gdb command like "pcontainer foo" that shows
me something like "The value in foo is 0". In terms of implementing such
a command, I cannot just call get() because I get the dreaded "Cannot
evaluate function -- may be inlined" message. I need to explicitly cast
foo.m_x to the appropriate type, but I'm at a loss as to how to get that
type from gdb. "whatis foo" gives me back "Container<int>". Is there
anyway of extracting the "int" part of that result and using that as the
type to cast to? The following is not valid, but this is what I'm going
for....
set $type = regex 'whatis foo' Container< \1 >
set $result = *(($type *) foo.m_x)
I'm using the stock GDB that ships with Mac OS X 10.6 (GNU gdb
6.3.50-20050815 (Apple version gdb-1461). I know... it's old.
Thanks for your help.
-- kenrose
P.S. - I could have something like "pcontainer foo int", but I'm trying to
avoid that since gdb already knows the type of foo (as Container<int>).
next reply other threads:[~2010-09-07 22:04 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-07 22:04 Kenneth Rose [this message]
2010-09-07 22:16 ` Tom Tromey
2010-09-10 18:09 ` Kenneth Rose
2010-09-10 19:57 ` Tom Tromey
-- strict thread matches above, loose matches on Subject: below --
2010-09-07 22:04 Kenneth Rose
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=784f56871ebbe612785c8be91771a9a5.squirrel@webmail.kenrose.org \
--to=kenrose@kenrose.org \
--cc=gdb@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox