From: "Doug Evans" <dje@google.com>
To: gdb-patches@sourceware.org
Cc: "Jim Blandy" <jimb@codesourcery.com>
Subject: [RFA] patch for 2384, dangling TYPE_VPTR_BASETYPE
Date: Fri, 14 Dec 2007 00:26:00 -0000 [thread overview]
Message-ID: <e394668d0712131610w432ee506t38cfd4abfbf6ed7a@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 569 bytes --]
I think(!) this patch is reasonable. It seems to be in line with what
Jim has in mind
(based on my interpretation of your comments Jim on the gdb list -
please correct
me if I'm wrong of course).
When gdb resolves type information for class "derived" from objfile
gdb2384 (from the testcase), it fills in the TYPE_VPTR_BASETYPE field
with class "base"
from objfile gdb2384-base.so. When the program is rerun the type
information for base-in-so-base.so is discarded leaving
TYPE_VPTR_BASETYPE dangling.
Ok to check in? Or any suggestions for what's needed instead?
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: gdb-071213-2384-1.patch --]
[-- Type: text/x-patch; name=gdb-071213-2384-1.patch, Size: 5659 bytes --]
2007-12-13 Doug Evans <dje@google.com>
PR 2384
* gdbtypes.c (fill_in_vptr_fieldno): Don't set TYPE_VPTR_FIELDNO,
TYPE_VPTR_BASETYPE if from different objfile.
* gdb.cp/gdb2384.exp: New file.
* gdb.cp/gdb2384.cc: New file.
* gdb.cp/gdb2384-base.h: New file.
* gdb.cp/gdb2384-base.cc: New file.
Index: gdbtypes.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbtypes.c,v
retrieving revision 1.140
diff -u -p -u -p -r1.140 gdbtypes.c
--- gdbtypes.c 4 Dec 2007 23:33:00 -0000 1.140
+++ gdbtypes.c 13 Dec 2007 23:59:35 -0000
@@ -1307,8 +1307,13 @@ fill_in_vptr_fieldno (struct type *type)
fill_in_vptr_fieldno (baseclass);
if (TYPE_VPTR_FIELDNO (baseclass) >= 0)
{
- TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (baseclass);
- TYPE_VPTR_BASETYPE (type) = TYPE_VPTR_BASETYPE (baseclass);
+ /* If the type comes from a different objfile we can't use it
+ here, it may have a different lifetime. PR 2384 */
+ if (TYPE_OBJFILE (type) == TYPE_OBJFILE (baseclass))
+ {
+ TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (baseclass);
+ TYPE_VPTR_BASETYPE (type) = TYPE_VPTR_BASETYPE (baseclass);
+ }
break;
}
}
Index: testsuite/gdb.cp/gdb2384-base.cc
===================================================================
RCS file: testsuite/gdb.cp/gdb2384-base.cc
diff -N testsuite/gdb.cp/gdb2384-base.cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ testsuite/gdb.cp/gdb2384-base.cc 13 Dec 2007 23:59:35 -0000
@@ -0,0 +1,12 @@
+#include "gdb2384-base.h"
+
+base::base (int _x)
+ : x (_x)
+{
+}
+
+int
+base::meth ()
+{
+ return x;
+}
Index: testsuite/gdb.cp/gdb2384-base.h
===================================================================
RCS file: testsuite/gdb.cp/gdb2384-base.h
diff -N testsuite/gdb.cp/gdb2384-base.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ testsuite/gdb.cp/gdb2384-base.h 13 Dec 2007 23:59:35 -0000
@@ -0,0 +1,7 @@
+class base
+{
+ public:
+ base (int _x);
+ int x;
+ virtual int meth ();
+};
Index: testsuite/gdb.cp/gdb2384.cc
===================================================================
RCS file: testsuite/gdb.cp/gdb2384.cc
diff -N testsuite/gdb.cp/gdb2384.cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ testsuite/gdb.cp/gdb2384.cc 13 Dec 2007 23:59:35 -0000
@@ -0,0 +1,22 @@
+#include "gdb2384-base.h"
+
+class derived : public base
+{
+ public:
+ derived (int);
+};
+
+derived::derived (int _x)
+ : base (_x)
+{
+}
+
+int g;
+
+int
+main ()
+{
+ derived d (42);
+ g = d.meth (); // set breakpoint here
+ return 0;
+}
Index: testsuite/gdb.cp/gdb2384.exp
===================================================================
RCS file: testsuite/gdb.cp/gdb2384.exp
diff -N testsuite/gdb.cp/gdb2384.exp
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ testsuite/gdb.cp/gdb2384.exp 13 Dec 2007 23:59:35 -0000
@@ -0,0 +1,99 @@
+# Copyright 2007 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# When gdb resolves type information for class "derived" from objfile
+# gdb2384, it use to fill in the TYPE_VPTR_BASETYPE field with class "base"
+# from objfile gdb2384-base.so. When the program is rerun the type
+# information for base-in-so-base.so is discarded leaving
+# TYPE_VPTR_BASETYPE dangling.
+
+if $tracelevel then {
+ strace $tracelevel
+}
+
+if { [skip_cplus_tests] } { continue }
+
+set prms_id 2384
+set bug_id 0
+
+set testfile "gdb2384"
+set srcfile ${testfile}.cc
+set binfile $objdir/$subdir/$testfile
+
+set libfile "gdb2384-base"
+set libsrcfile ${libfile}.cc
+set sofile $objdir/$subdir/"${libfile}.so"
+
+# Create and source the file that provides information about the compiler
+# used to compile the test case.
+if [get_compiler_info ${binfile} "c++"] {
+ return -1
+}
+
+if { [gdb_compile_shlib $srcdir/$subdir/$libsrcfile $sofile {debug c++}] != ""
+ || [gdb_compile $srcdir/$subdir/$srcfile $binfile executable [list debug "c++" shlib=${sofile}]] != ""} {
+ untested gdb2384.exp
+ return -1
+}
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_load ${binfile}
+#gdb_load_shlibs ${sofile}
+
+set bp_location [gdb_get_line_number "set breakpoint here"]
+
+# Set a breakpoint with multiple locations.
+
+gdb_test "break $srcfile:$bp_location" \
+ "Breakpoint.*at.* file .*$srcfile, line.*" \
+ "set breakpoint"
+
+gdb_run_cmd
+gdb_expect {
+ -re "Breakpoint \[0-9\]+,.*main \\(.*\\).*$gdb_prompt $" {
+ pass "run to breakpoint"
+ }
+ -re "$gdb_prompt $" {
+ fail "run to breakpoint"
+ }
+ timeout {
+ fail "run to breakpoint (timeout)"
+ }
+}
+
+gdb_test "print d.meth ()" \
+ ".*42.*" \
+ "print d.meth ()"
+
+# Now try again. gdb's without the fix will hopefully segv here
+
+gdb_run_cmd
+gdb_expect {
+ -re "Breakpoint \[0-9\]+,.*main \\(.*\\).*$gdb_prompt $" {
+ pass "run to breakpoint #2"
+ }
+ -re "$gdb_prompt $" {
+ fail "run to breakpoint #2"
+ }
+ timeout {
+ fail "run to breakpoint #2 (timeout)"
+ }
+}
+
+gdb_test "print d.meth ()" \
+ ".*42.*" \
+ "gdb2384"
next reply other threads:[~2007-12-14 0:11 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-12-14 0:26 Doug Evans [this message]
2007-12-14 6:23 ` Daniel Jacobowitz
2007-12-14 20:44 ` Doug Evans
2007-12-14 21:27 ` Doug Evans
2007-12-15 13:15 ` Doug Evans
2007-12-20 19:49 ` Doug Evans
2008-01-28 19:05 ` Doug Evans
2008-01-30 1:23 ` Daniel Jacobowitz
2008-02-03 22:19 ` Doug Evans
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e394668d0712131610w432ee506t38cfd4abfbf6ed7a@mail.gmail.com \
--to=dje@google.com \
--cc=gdb-patches@sourceware.org \
--cc=jimb@codesourcery.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox