This is the mail archive of the gdb@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Is Single step into C++ virtual thunk still broken?


Well, after a bit of investigation, I have come up  with this simple C++
code which gdb gets a bit wrong.

Having class Base as a *virtual* base class of class Derived seems to
cause the problem. Take out virtual and everything works fine.

Anyway, to see what I mean, stick a breakpoint in the code where
indicated, then single step into the virtual function. gdb ends up on
the last line of the virtual function, rather than the first. If you
move the function to another file, it can just end up somewhere random.
Take out the virtual as indicated and everything works fine

Let me know what you think.

Andrew

PS Are you a gdb maintainer? Whatever, thanks for the help.

#include <cstdio>
using namespace std;
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
class Base
{
	int a;
public:
	virtual bool VirtualFn()=0;
};
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
// Remove virtual from the following line and everything works fine
class Intermediate1 : public virtual Base
{
	int b;
public:
	virtual bool VirtualFn();
};
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
class Derived : public Intermediate1
{
	int d;
public:
	virtual bool VirtualFn();
};
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
bool Intermediate1::VirtualFn()
{
	printf("This Intermediate1::Virtual Function");
	return true;
}
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
bool Derived::VirtualFn()
{
	int a=1;
	int b=2;
	int c=a+b;
	printf("This Base::Virtual Function");
	return true;
	//Single step ends up here if 'virtual' is left in above
}
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
int main(int argc,char* argv[])
{
	Derived d;
	Base* p = &d;
	//Put your breakpoint on the next line and single step...
	p->VirtualFn();
	return 0;
}
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]