This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Cannot call virtual function in gdb
- To: gcc at gcc dot gnu dot org
- Subject: Cannot call virtual function in gdb
- From: Marco Man-Fai Yu <yumf at chasingwind dot com>
- Date: Wed, 02 Aug 2000 00:53:50 -0700
- cc: yumf at cisc dot chasingwind dot com
- Reply-To: yumf at ultimatech dot com
Hi,
I have trouble calling virtual functions inside gdb. If this is
more relevant to gdb than gcc, please let me know so that I can post
it to gdb's mailing list.
The system is a Linux box running Debian 2.1.
Linux cisc 2.2.14 #8 Mon Apr 24 23:45:12 PDT 2000 i686 unknown
The gdb that comes with this distribution is version 4.17 and the g++
compiler I'm using is 2.95.1.
Here's a short program to illustrate the problem.
--------- foo.cc --------------------------------
#include <iostream>
class Base
{
public:
virtual void Do();
};
void Base::Do()
{
cerr << "Base::Do\n";
}
class Derived : public Base
{
public:
virtual void Do();
};
void Derived::Do()
{
cerr << "Derived::Do\n";
}
int main (int argc, char* argv[])
{
Base b;
b.Do();
Derived d;
d.Do();
}
---------------------------------------------------
I compile it as usual with
g++ -g -o foo foo.cc
and here's the gdb transcript.
GNU gdb 4.17.m68k.objc.threads.hwwp.fpu.gnat
Copyright 1998 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 "i486-pc-linux-gnu"...
(gdb) b main
Breakpoint 1 at 0x804a196: file foo.cc, line 28.
(gdb) list
19
20
21 void Derived::Do()
22 {
23 cerr << "Derived::Do\n";
24 }
25
26 int main (int argc, char* argv[])
27 {
28 Base b;
(gdb) r
Starting program: /auto/home/yumf/tmp/foo
Breakpoint 1, main (argc=1, argv=0xbffff794) at foo.cc:28
(gdb) n
(gdb) p b.Do()
I'm confused: virtual function table has bad type
(gdb) c
Continuing.
Base::Do
Derived::Do
Program exited normally.
(gdb)
----------------------------------
As you can see, gdb prints an error message if I try to run b.Do().
Please let me know if you need more information. Any help or hints is
greatly appreciated.
Thank you,
Marco Yu
yumf@ultimatech.com