Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* Re: Is Single step into C++ virtual thunk still broken?
@ 2002-07-09  8:56 Daedalus
  2002-07-09  9:27 ` Daniel Jacobowitz
  0 siblings, 1 reply; 9+ messages in thread
From: Daedalus @ 2002-07-09  8:56 UTC (permalink / raw)
  To: gdb

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;
}
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////




^ permalink raw reply	[flat|nested] 9+ messages in thread
* Re: Is Single step into C++ virtual thunk still broken?
@ 2002-07-09 14:14 Daedalus
  0 siblings, 0 replies; 9+ messages in thread
From: Daedalus @ 2002-07-09 14:14 UTC (permalink / raw)
  To: gdb



On Tue, 2002-07-09 at 21:20, Daniel Jacobowitz wrote:
> 
> Does this persist if you use -static?  If so, please give me:
>   thunk.o (compile using g++ -g3 -c thunk.cpp)
>   thunk (compile using g++ -g3 -o thunk thunk.o -static)
> 
> and I'll see if I can figure out what's going wrong.  I doubt I can
run
> RH7.3 dynamically linked libraries.
> 

Sure does:

[daedalus@mojo thunk]$ g++ -g3 -c thunk.cpp
[daedalus@mojo thunk]$ ls
thunk.cpp  thunk.o
[daedalus@mojo thunk]$ g++ -g3 -o thunk thunk.o -static
[daedalus@mojo thunk]$ ls
thunk  thunk.cpp  thunk.o
[daedalus@mojo thunk]$ gdb ./thunk
GNU gdb 2002-07-09-cvs
Copyright 2002 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you
are
welcome to change it and/or distribute copies of it under certain
conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for
details.
This GDB was configured as "i686-pc-linux-gnu"...
(gdb) b 50
Breakpoint 1 at 0x804825e: file thunk.cpp, line 50.
(gdb) r
Starting program: /home/daedalus/src/thunk/thunk 

Breakpoint 1, main (argc=1, argv=0xbffff9f4) at thunk.cpp:50
50              p->VirtualFn();
(gdb) s
virtual thunk to Derived::VirtualFn() () at thunk.cpp:43
43      }
(gdb) s
main (argc=1, argv=0xbffff9f4) at thunk.cpp:51
51              return 0;
(gdb) 

Files attached

Andrew Walrond


^ permalink raw reply	[flat|nested] 9+ messages in thread
* Is Single step into C++ virtual thunk still broken?
@ 2002-07-08  6:47 Daedalus
  2002-07-08  6:52 ` Daniel Jacobowitz
  0 siblings, 1 reply; 9+ messages in thread
From: Daedalus @ 2002-07-08  6:47 UTC (permalink / raw)
  To: gdb

I have waded through the archives but can't find anything newer than 1
year ago discussing this.

I'm using latest cvs gdb and gcc3.1. and specifiying DWARF-2 debug info.

When I single step into a virtual member function of a polymorphic
object in my C++ app, the source display heads off to some random line
in a header file, and another single step takes me back to the next
source line after the virtual function.

Putting a breakpoint in the actual function being called works as
expected.

I quote from a message by Andrew Cagney, 28 Jun 2001:

*****************************
> - Skipping vtable thunks, if necessary


I don't know if this was ever discussed on this list.  As I understand 
it, v3 virtual function is sometimes called via a ``thunk''.  A 
``thunk'' pulls a rabbit out of a hat (finds the correct object to pass 
to the real function) and then passes control to the real function.

At present, if GDB stepped into a thunk it would find no line info, 
treat it like a library and just skip it - oops, step into virtual 
functions via thunks doesn't work.

One proposed solution is to mimic / generalize the shared library 
mechanism so that GDB will single step through it to the real function.

I think this bug is pretty serious since, GDB will, randomly loose 
control over the target.  I certainly think it is more serious than the 
constructor problem.
*****************************

Is this still broke, or am I missing something?

Andrew Walrond
Project Icarus


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2002-07-09 23:13 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-07-09  8:56 Is Single step into C++ virtual thunk still broken? Daedalus
2002-07-09  9:27 ` Daniel Jacobowitz
2002-07-09 11:44   ` Daedalus
2002-07-09 11:51     ` Daniel Jacobowitz
2002-07-09 13:10       ` Daedalus
     [not found]         ` <20020709202005.GA23405@nevyn.them.org>
2002-07-09 16:13           ` Daedalus
  -- strict thread matches above, loose matches on Subject: below --
2002-07-09 14:14 Daedalus
2002-07-08  6:47 Daedalus
2002-07-08  6:52 ` Daniel Jacobowitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox