Re: Getting to the source for a given C++ object

Alex Bennee
2005-08-11T09:27:07Z

On Wed, 2005-08-10 at 13:35 -0700, Jason Molenda wrote:
> On Aug 10, 2005, at 10:17 AM, Alex Bennee wrote:
>
> > I'm currently trying to debug a C++ program that makes heavy use of
> > templates and derived classes. Is there an easy way to get to the
> > actual
> > code for a given class pointer?
>
>
> I'm not sure exactly what you're looking for. ptype can tell you
> the class - is that what you want? e.g.
>
> (gdb) p beta
> $1 = { = {_vptr$A = 0x30b0, a1 = 200}, b1 = 201, b2 = 202}
> (gdb) ptype beta
> type = class B : public A {
> public:
> int b1;
> int b2;
>
> B(B const&);
> B(B const&);
> B();
> B();
> ~B();
> virtual ~B();
> virtual ~B();
> }

Thats useful, but its the derived information I want. Basically how can
I get from that to the code for the virtual function used by that
particular object.

The trouble is the class is specialised into a fair number of different
subclasses via templates. What I would ideally like is to do something
like "l beta.method" and be looking directly at the code for that
objects method call so I can set up breakpoints and the like.

--
Alex, homepage: http://www.bennee.com/~alex/
Actresses will happen in the best regulated families. -- Addison Mizner
and Oliver Herford, "The Entirely New Cynic's Calendar", 1905