Bug 9489 - dangling pointer in TYPE_VPTR_BASETYPE when baseclass is in shared object
Summary: dangling pointer in TYPE_VPTR_BASETYPE when baseclass is in shared object
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: c++ (show other bugs)
Version: 6.7
: P3 normal
Target Milestone: 7.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-12-13 23:38 UTC by dje
Modified: 2010-01-22 21:51 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
base-in-so-segv.example (328 bytes, application/octet-stream)
, dje
Details

Note You need to log in before you can comment on or make changes to this bug.
Description dje 2007-12-13 23:38:01 UTC
[Converted from Gnats 2384]

The appended exampled illustrates a problem in gdb's handling of baseclasses in shared libraries. When gdb resolves type information for class "derived" from objfile base-in-so.x, it fills in the TYPE_VPTR_BASETYPE field with class "base" from objfile base-in-so-base.so.  When the program is rerun the type information for base-in-so-base.so is discarded leaving TYPE_VPTR_BASETYPE dangling.

Release:
6.7.1

Environment:
i386-linux

How-To-Repeat:
g++ -g -shared base-in-so-base.cc -o base-in-so-base.so
g++ -g base-in-so.cc -o base-in-so.x -Wl,-rpath,`pwd` base-in-so-base.so

gdb base-in-so.x
break base-in-so.cc:20
run
[hits breakpoint]
print d.meth()
$1 = 42
run
Start at beginning? y
[hits breakpoint]
print d.meth()
--> segv

If the program doesn't hit a segv, it may just be that gdb got lucky.  Putting in an assert will show the issue too:

--- gdbtypes.c~ 2007-12-13 15:20:59.062220000 -0800
+++ gdbtypes.c  2007-12-13 15:21:39.408302000 -0800
@@ -1307,6 +1307,7 @@ fill_in_vptr_fieldno (struct type *type)
          fill_in_vptr_fieldno (baseclass);
          if (TYPE_VPTR_FIELDNO (baseclass) >= 0)
            {
+             gdb_assert (TYPE_OBJFILE (type) == TYPE_OBJFILE (baseclass));
              TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (baseclass);
              TYPE_VPTR_BASETYPE (type) = TYPE_VPTR_BASETYPE (baseclass);
              break;
Comment 1 Tom Tromey 2010-01-22 21:51:10 UTC
This was fixed a while back.