This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[patch] Additional fix for gdb/2384.
- From: ppluzhnikov at google dot com (Paul Pluzhnikov)
- To: gdb-patches at sourceware dot org
- Cc: dje at google dot com
- Date: Fri, 3 Oct 2008 14:37:58 -0700 (PDT)
- Subject: [patch] Additional fix for gdb/2384.
Greetings,
This is rather on the obvious side.
I've discovered that Doug Evans' fix for gdb/2384 was incomplete.
Attached modified testsuite/gdb.cp/gdb2384* demonstrates the problem,
and gdbtypes.c change fixes it.
OK?
--
Paul Pluzhnikov
2008-10-03 Paul Pluzhnikov <ppluzhnikov@google.com>
PR gdb/2384:
* gdbtypes.c (get_vptr_fieldno): baseclass and basetype may have
different lifetimes.
2008-10-03 Paul Pluzhnikov <ppluzhnikov@google.com>
PR gdb/2384:
* gdb.cp/gdb2384.exp: Extended to test more cases.
* gdb.cp/gdb2384.cc: Likewise.
* gdb.cp/gdb2384-base.h: Likewise.
* gdb.cp/gdb2384-base.cc: Likewise.
Index: gdbtypes.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbtypes.c,v
retrieving revision 1.151
diff -u -p -u -r1.151 gdbtypes.c
--- gdbtypes.c 2 Oct 2008 22:06:07 -0000 1.151
+++ gdbtypes.c 3 Oct 2008 21:24:00 -0000
@@ -1324,7 +1324,7 @@ get_vptr_fieldno (struct type *type, str
{
/* If the type comes from a different objfile we can't cache
it, it may have a different lifetime. PR 2384 */
- if (TYPE_OBJFILE (type) == TYPE_OBJFILE (baseclass))
+ if (TYPE_OBJFILE (type) == TYPE_OBJFILE (basetype))
{
TYPE_VPTR_FIELDNO (type) = fieldno;
TYPE_VPTR_BASETYPE (type) = basetype;
Index: testsuite/gdb.cp/gdb2384-base.cc
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.cp/gdb2384-base.cc,v
retrieving revision 1.2
diff -u -p -u -r1.2 gdb2384-base.cc
--- testsuite/gdb.cp/gdb2384-base.cc 3 Feb 2008 22:17:05 -0000 1.2
+++ testsuite/gdb.cp/gdb2384-base.cc 3 Oct 2008 21:24:00 -0000
@@ -28,3 +28,8 @@ base::meth ()
{
return x;
}
+
+derived::derived (int _x)
+ : base (_x)
+{
+}
Index: testsuite/gdb.cp/gdb2384-base.h
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.cp/gdb2384-base.h,v
retrieving revision 1.2
diff -u -p -u -r1.2 gdb2384-base.h
--- testsuite/gdb.cp/gdb2384-base.h 3 Feb 2008 22:17:05 -0000 1.2
+++ testsuite/gdb.cp/gdb2384-base.h 3 Oct 2008 21:24:00 -0000
@@ -23,3 +23,9 @@ class base
int x;
virtual int meth ();
};
+
+class derived : public base
+{
+ public:
+ derived (int _x);
+};
Index: testsuite/gdb.cp/gdb2384.cc
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.cp/gdb2384.cc,v
retrieving revision 1.2
diff -u -p -u -r1.2 gdb2384.cc
--- testsuite/gdb.cp/gdb2384.cc 3 Feb 2008 22:17:05 -0000 1.2
+++ testsuite/gdb.cp/gdb2384.cc 3 Oct 2008 21:24:00 -0000
@@ -18,23 +18,36 @@
#include "gdb2384-base.h"
-class derived : public base
+class derived1 : public base
{
public:
- derived (int);
+ derived1 (int);
};
-derived::derived (int _x)
+derived1::derived1 (int _x)
: base (_x)
{
}
+class derived2 : public derived
+{
+ public:
+ derived2 (int);
+};
+
+derived2::derived2 (int _x)
+ : derived (_x)
+{
+}
+
int g;
int
main ()
{
- derived d (42);
- g = d.meth (); // set breakpoint here
+ derived1 d1 (42);
+ derived2 d2 (24);
+ g = d1.meth (); // set breakpoint here
+ g = d2.meth (); // set breakpoint here (second)
return 0;
}
Index: testsuite/gdb.cp/gdb2384.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.cp/gdb2384.exp,v
retrieving revision 1.1
diff -u -p -u -r1.1 gdb2384.exp
--- testsuite/gdb.cp/gdb2384.exp 3 Feb 2008 22:13:30 -0000 1.1
+++ testsuite/gdb.cp/gdb2384.exp 3 Oct 2008 21:24:00 -0000
@@ -55,46 +55,41 @@ 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)"
- }
+if ![runto_main] then {
+ perror "couldn't run to breakpoint"
+ return -1
}
-gdb_test "print d.meth ()" \
+gdb_breakpoint [gdb_get_line_number "set breakpoint here"]
+gdb_continue_to_breakpoint "set breakpoint here"
+
+gdb_test "print d1.meth ()" \
".*42.*" \
- "print d.meth ()"
+ "print d1.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 ()" \
+runto_main
+gdb_breakpoint [gdb_get_line_number "set breakpoint here"]
+gdb_continue_to_breakpoint "set breakpoint here"
+gdb_test "print d1.meth ()" \
".*42.*" \
"gdb2384"
+
+# second case
+
+runto_main
+gdb_breakpoint [gdb_get_line_number "set breakpoint here (second)"]
+gdb_continue_to_breakpoint "set breakpoint here (second)"
+gdb_test "print d2.meth ()" \
+ ".*24.*" \
+ "print d2.meth()"
+
+runto_main
+gdb_breakpoint [gdb_get_line_number "set breakpoint here (second)"]
+gdb_continue_to_breakpoint "set breakpoint here (second)"
+gdb_test "print d2.meth ()" \
+ ".*24.*" \
+ "gdb2384 (second)"
+