Discussion:
[Bug c++/20185] New: RTTI symbol not found for nested virtual class
scovich at gmail dot com
2016-05-31 19:07:29 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=20185

Bug ID: 20185
Summary: RTTI symbol not found for nested virtual class
Product: gdb
Version: 7.10
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
Assignee: unassigned at sourceware dot org
Reporter: scovich at gmail dot com
Target Milestone: ---

Consider the following multi-file toy program:

=== bug-bar.h =======
struct Foo {
virtual ~Foo() { }
virtual void foo()=0;
};

struct Bar {
struct BarFoo : Foo {
virtual void foo() { }
};
static Foo* getFoo();
};
=====================

=== bug-bar.cpp =====
#include "bug-bar.h"

Foo* Bar::getFoo() { return new BarFoo; }
=====================

=== bug.cpp =========
#include "bug-bar.h"
int main() {
Foo* f = Bar::getFoo();
f->foo();
}
=====================

The following steps show gdb is unable to find the RTTI info for the nested
virtual class BarFoo:

$ g++ -g -Wall -c scratch.cpp
$ g++ -g -Wall -c scratch-bar.cpp
$ g++ -g -Wall scratch.o scratch-bar.o
$ gdb a.out
Reading symbols from a.out...done.
(gdb) set print object
(gdb) start
(gdb) start
Temporary breakpoint 1 at 0x4007d5: file scratch.cpp, line 4.
Starting program: /home/ryan/experiments/a.out
Temporary breakpoint 1, main () at scratch.cpp:4
(gdb) next
(gdb) p f
$1 = (warning: RTTI symbol not found for class 'Bar::BarFoo'
warning: RTTI symbol not found for class 'Bar::BarFoo'
Foo *) 0x603010
(gdb) p f->foo()
warning: RTTI symbol not found for class 'Bar::BarFoo'
warning: RTTI symbol not found for class 'Bar::BarFoo'
warning: RTTI symbol not found for class 'Bar::BarFoo'
$2 = void


The problem goes away if I compile all three .cpp directly into a.out, or if
BarFoo is declared as a stand-alone class. It does not seem to matter where the
virtual functions are declared.
--
You are receiving this mail because:
You are on the CC list for the bug.
scovich at gmail dot com
2016-05-31 19:11:29 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=20185

--- Comment #1 from scovich at gmail dot com ---
Actually, I was wrong about the problem going away if the .cpp were directly
compiled to obtain a.out.
--
You are receiving this mail because:
You are on the CC list for the bug.
palves at redhat dot com
2016-08-08 23:44:16 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=20185

Pedro Alves <palves at redhat dot com> changed:

What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |WAITING
Last reconfirmed| |2016-08-08
CC| |palves at redhat dot com
Ever confirmed|0 |1

--- Comment #2 from Pedro Alves <palves at redhat dot com> ---
Works for me Fedora 23, with all of:

- gdb master (7.12.50.20160808-git)
- gdb 7.10.1
- gdb 7.11.1
- Fedora 23's gdb 7.10.1-31.fc23

In all of them I get:

(gdb) p f
$1 = (Bar::BarFoo *) 0x613c20

Maybe broken compiler/linker?
--
You are receiving this mail because:
You are on the CC list for the bug.
scovich at gmail dot com
2016-10-13 22:05:20 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=20185

--- Comment #3 from scovich at gmail dot com ---
I updated my toolchains to gcc-6.2.0, binutils-2.26 and gdb-7.10. The problem
still occurs if shared libraries are involved (which they are in the app I'm
trying to debug)

g++ -g -fPIC -c bug-bar.cpp
g++ -g -shared -Wl,-soname=libbar.so bug-bar.o -o libbar.so
g++ -g -c bug.cpp
g++ -g bug.o -L. -lbar
--
You are receiving this mail because:
You are on the CC list for the bug.
Loading...