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  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
  0 siblings, 1 reply; 9+ messages in thread
From: Daniel Jacobowitz @ 2002-07-09  9:27 UTC (permalink / raw)
  To: Daedalus; +Cc: gdb

On Tue, Jul 09, 2002 at 04:50:31PM +0100, Daedalus wrote:
> 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.

Right now, with your test case, I step into the virtual function's
thunk - end up at a random line - step again, and end up at the
beginning of the virtual function.  Which is annoying but not so bad. 
The line I end up at is the first line of the Derived class, which
isn't an entirely unreasonable place for the thunk to be but is still
probably wrong.  That is a minor GCC bug.

On the other hand, GDB should skip the thunk and step you right into
the function being called.  I'll try to think of a way to do this.

-- 
Daniel Jacobowitz                           Carnegie Mellon University
MontaVista Software                         Debian GNU/Linux Developer


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

* Re: Is Single step into C++ virtual thunk still broken?
  2002-07-09  9:27 ` Daniel Jacobowitz
@ 2002-07-09 11:44   ` Daedalus
  2002-07-09 11:51     ` Daniel Jacobowitz
  0 siblings, 1 reply; 9+ messages in thread
From: Daedalus @ 2002-07-09 11:44 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: gdb

On Tue, 2002-07-09 at 17:27, Daniel Jacobowitz wrote:
> 
> Right now, with your test case, I step into the virtual function's
> thunk - end up at a random line - step again, and end up at the
> beginning of the virtual function.  Which is annoying but not so bad. 
> The line I end up at is the first line of the Derived class, which
> isn't an entirely unreasonable place for the thunk to be but is still
> probably wrong.  That is a minor GCC bug.
> 
> On the other hand, GDB should skip the thunk and step you right into
> the function being called.  I'll try to think of a way to do this.
> 

If, as you suggest, a second step (s command) would take me into the
virtual function, I could live with the (minor) problem, but here the
first step command takes me to the closing } of the virtual function
(although if this is random as you suggest, it might not be significant)
and the second step (s) command takes me to the next statement after the
virtual function call, jumping it completely. Very inconvenient.

In order for me to try and replicate your behaviour, could you give me
some details?

I am running the very latest GNU gdb 2002-07-09-cvs, gcc 3.1 and I
compiled the example with
	gcc -g3 -lstdc++ thunk.cpp

Red Hat Linux 7.3

Andew Walrond
Project Icarus


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

* Re: Is Single step into C++ virtual thunk still broken?
  2002-07-09 11:44   ` Daedalus
@ 2002-07-09 11:51     ` Daniel Jacobowitz
  2002-07-09 13:10       ` Daedalus
  0 siblings, 1 reply; 9+ messages in thread
From: Daniel Jacobowitz @ 2002-07-09 11:51 UTC (permalink / raw)
  To: Daedalus; +Cc: gdb

On Tue, Jul 09, 2002 at 07:43:34PM +0100, Daedalus wrote:
> On Tue, 2002-07-09 at 17:27, Daniel Jacobowitz wrote:
> > 
> > Right now, with your test case, I step into the virtual function's
> > thunk - end up at a random line - step again, and end up at the
> > beginning of the virtual function.  Which is annoying but not so bad. 
> > The line I end up at is the first line of the Derived class, which
> > isn't an entirely unreasonable place for the thunk to be but is still
> > probably wrong.  That is a minor GCC bug.
> > 
> > On the other hand, GDB should skip the thunk and step you right into
> > the function being called.  I'll try to think of a way to do this.
> > 
> 
> If, as you suggest, a second step (s command) would take me into the
> virtual function, I could live with the (minor) problem, but here the
> first step command takes me to the closing } of the virtual function
> (although if this is random as you suggest, it might not be significant)
> and the second step (s) command takes me to the next statement after the
> virtual function call, jumping it completely. Very inconvenient.
> 
> In order for me to try and replicate your behaviour, could you give me
> some details?
> 
> I am running the very latest GNU gdb 2002-07-09-cvs, gcc 3.1 and I
> compiled the example with
> 	gcc -g3 -lstdc++ thunk.cpp
> 
> Red Hat Linux 7.3

With 3.0:

drow@nevyn:~/debugging/thunks% gcc-3.0 -g3 -lstdc++ -o vthunk vthunk.cc
drow@nevyn:~/debugging/thunks% gdb ./vthunk                            
GNU gdb 2002-04-01-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 "i386-linux"...
(gdb) b 53
Breakpoint 1 at 0x8048719: file vthunk.cc, line 53.
(gdb) r
Starting program: /home/drow/debugging/thunks/vthunk 

Breakpoint 1, main (argc=1, argv=0xbffff664) at vthunk.cc:53
53              p->VirtualFn();
(gdb) s
virtual thunk to Derived::VirtualFn() (this=0xbffff5e0) at vthunk.cc:23
23      {
(gdb) 
Derived::VirtualFn() (this=0x4001413c) at vthunk.cc:39
39              int a=1;
(gdb) 


With 3.1, same thing.  Curiously, with 2.95 we step right over it...  I
don't have time to investigate why at the moment.

(By the way, you really should use g++ to compile C++ code.)

-- 
Daniel Jacobowitz                           Carnegie Mellon University
MontaVista Software                         Debian GNU/Linux Developer


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

* Re: Is Single step into C++ virtual thunk still broken?
  2002-07-09 11:51     ` Daniel Jacobowitz
@ 2002-07-09 13:10       ` Daedalus
       [not found]         ` <20020709202005.GA23405@nevyn.them.org>
  0 siblings, 1 reply; 9+ messages in thread
From: Daedalus @ 2002-07-09 13:10 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: gdb

On Tue, 2002-07-09 at 19:51, Daniel Jacobowitz wrote:
> 
> With 3.0:
> 
> drow@nevyn:~/debugging/thunks% gcc-3.0 -g3 -lstdc++ -o vthunk vthunk.cc
> drow@nevyn:~/debugging/thunks% gdb ./vthunk                            
> GNU gdb 2002-04-01-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 "i386-linux"...
> (gdb) b 53
> Breakpoint 1 at 0x8048719: file vthunk.cc, line 53.
> (gdb) r
> Starting program: /home/drow/debugging/thunks/vthunk 
> 
> Breakpoint 1, main (argc=1, argv=0xbffff664) at vthunk.cc:53
> 53              p->VirtualFn();
> (gdb) s
> virtual thunk to Derived::VirtualFn() (this=0xbffff5e0) at vthunk.cc:23
> 23      {
> (gdb) 
> Derived::VirtualFn() (this=0x4001413c) at vthunk.cc:39
> 39              int a=1;
> (gdb) 
> 
> 
> With 3.1, same thing.  Curiously, with 2.95 we step right over it...  I
> don't have time to investigate why at the moment.
> 
> (By the way, you really should use g++ to compile C++ code.)
> 

Compared with my experience ( Using g++ ;) )

[daedalus@mojo thunk]$ g++ --version
g++ (GCC) 3.1
Copyright (C) 2002 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is
NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.

[daedalus@mojo thunk]$ g++ -g3 -lstdc++ -o thunk thunk.cpp
[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 0x80486ce: 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) 


Ho hum. Thanks for your input anyway.

Andrew Walrond
Project Icarus


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

* Re: Is Single step into C++ virtual thunk still broken?
       [not found]         ` <20020709202005.GA23405@nevyn.them.org>
@ 2002-07-09 16:13           ` Daedalus
  0 siblings, 0 replies; 9+ messages in thread
From: Daedalus @ 2002-07-09 16:13 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: 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.
> 

FYI, I tried the latest cvs version of gcc 3.2, and got the same
results.

Andrew Walrond


^ 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

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

On Mon, Jul 08, 2002 at 02:42:17PM +0100, Daedalus wrote:
> 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?

Probably, I'll look at it.  Could you do me the favor of a small test
program?


-- 
Daniel Jacobowitz                           Carnegie Mellon University
MontaVista Software                         Debian GNU/Linux Developer


^ 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