From: david carlton <carlton@math.stanford.edu>
To: gdb-patches@sources.redhat.com
Cc: carlton@math.stanford.edu
Subject: patch for PR gdb/574
Date: Mon, 22 Jul 2002 12:02:00 -0000 [thread overview]
Message-ID: <15676.21042.125481.349851@jackfruit.Stanford.EDU> (raw)
For various reasons, I decided to delve into GDB recently, so I picked
bug 574 somewhat at random and decided to try to fix it. Here's a
patch.
The problem: GDB tries to access an improper memory location while
trying to find run time type info on certain code compiled with G++
2.something. In the situation in question, GDB is trying to find the
vptr of an object that is a subclass of a class with virtual functions
and static member data. It looks for the information about the vptr
at a place where information about the static member data is actually
stored. This is a data structure with a useless (and very large)
bitpos field; adding this bitpos to a pointer causes that pointer to
point to the middle of nowhere. Oops.
The solution: Get rid of the check for
if (VALUE_ENCLOSING_TYPE(v) != VALUE_TYPE(v))
and the surrounding code in gnu-v2-abi.c(gnuv2_value_rtti_type).
Some comments:
* gnu-v3-abi.c(gnuv3_rtti_type) doesn't have any such code, so I don't
think this fix is likely to break anything that isn't also broken in
gnu-v3-abi.c.
* It doesn't seem to cause any testsuites to fail that didn't fail
before. (In fact, when I ran it, it turned gdb.base/selftest.exp
from a FAIL into a pass, for what that's worth; I don't know if my
changes are relevant to that, though.) I'm not too used to working
the testsuites; please rerun them to make sure.
* In the test case in question, the only reason why that check matched
was because a call to value_cast earlier in the function set the
enclosing type to differ from the type.
* There are other problems in the surrounding code that are unrelated
to this. When I compiled my test program under g++-3.1, I got an
unrelated bad memory access from inside gnu-v3-abi.c. Also (and
this may be related to that bad memory access), there seems to be a
difference of opinion among various pieces of code as to whose job
it is to demangle symbols that you want to look up in symbol
tables. I'll try to spend some time over the next week or two
sorting this out.
* I'm not convinced that the code I deleted wouldn't be useful in some
circumstances (where we had a pointer to something in the middle of
a class); I'll try to spend some time over the next week or two
coming up with test cases to see cause the code to fail, and to see
if there's a better fix around somewhere. Nonetheless, given that
my patch does fix a known problem and, if there is a problem with
enclosing_type, then the current gnu-v3-abi.c code probably has it
as well, I think it should be committed.
* I haven't contacted the submitter of the bug report, but I'd be
happy to do so if that is appropriate.
I'm including a sample program that demonstrates the bug (though the
submitter of the bug report also submitted a more elaborate test case
that has some other interesting features; hurrah for good bug
reports), a ChangeLog entry, and the patch; all will follow my
signature.
David Carlton
carlton@math.stanford.edu
/*
An attempt to replicate GDB bug 574 with a shorter program.
g++ -g test.cc # no optimization, else we'd need to split into 2 files
gdb a.out
(gdb) b main
(gdb) r
(gdb) n
(gdb) p *theB
*/
class A {
public:
virtual void foo() {}; // Stick in a virtual function.
static const int bar; // Stick in a static data member.
};
class B : public A {
static const int bar = 1;
};
int main()
{
B *theB = new B;
}
2002-07-22 david carlton <carlton@math.stanford.edu>
* gnu-v2-abi.c (gnuv2_value_rtti_type): Eliminate test for being
enclosed. Fix PR gdb/574.
Index: gnu-v2-abi.c
===================================================================
RCS file: /cvs/src/src/gdb/gnu-v2-abi.c,v
retrieving revision 1.6
diff -c -p -r1.6 gnu-v2-abi.c
*** gnu-v2-abi.c 4 Jan 2002 18:20:19 -0000 1.6
--- gnu-v2-abi.c 22 Jul 2002 18:22:05 -0000
*************** gnuv2_value_rtti_type (struct value *v,
*** 189,195 ****
struct type *rtti_type;
CORE_ADDR coreptr;
struct value *vp;
- int using_enclosing = 0;
long top_offset = 0;
char rtti_type_name[256];
CORE_ADDR vtbl;
--- 189,194 ----
*************** gnuv2_value_rtti_type (struct value *v,
*** 244,268 ****
if (VALUE_ADDRESS (value_field (v, TYPE_VPTR_FIELDNO (known_type))) == 0)
return NULL;
! /*
! If we are enclosed by something that isn't us, adjust the
! address properly and set using_enclosing.
! */
! if (VALUE_ENCLOSING_TYPE(v) != VALUE_TYPE(v))
! {
! struct value *tempval;
! int bitpos = TYPE_BASECLASS_BITPOS (known_type,
! TYPE_VPTR_FIELDNO (known_type));
! tempval=value_field (v, TYPE_VPTR_FIELDNO(known_type));
! VALUE_ADDRESS(tempval) += bitpos / 8;
! vtbl=value_as_address (tempval);
! using_enclosing=1;
! }
! else
! {
! vtbl=value_as_address(value_field(v,TYPE_VPTR_FIELDNO(known_type)));
! using_enclosing=0;
! }
/* Try to find a symbol that is the vtable */
minsym=lookup_minimal_symbol_by_pc(vtbl);
--- 243,249 ----
if (VALUE_ADDRESS (value_field (v, TYPE_VPTR_FIELDNO (known_type))) == 0)
return NULL;
! vtbl=value_as_address(value_field(v,TYPE_VPTR_FIELDNO(known_type)));
/* Try to find a symbol that is the vtable */
minsym=lookup_minimal_symbol_by_pc(vtbl);
*************** gnuv2_value_rtti_type (struct value *v,
*** 304,311 ****
if (full)
*full=1;
}
- if (using_enc)
- *using_enc=using_enclosing;
return rtti_type;
}
--- 285,290 ----
next reply other threads:[~2002-07-22 18:43 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-07-22 12:02 david carlton [this message]
2002-07-22 12:16 ` Daniel Jacobowitz
2002-07-22 12:18 ` david carlton
2002-07-23 16:47 ` Jim Blandy
2002-08-15 20:26 ` Daniel Jacobowitz
2002-08-15 20:48 ` David Carlton
2002-08-16 16:10 ` [rfa/c++testsuite] (was Re: patch for PR gdb/574) David Carlton
2002-08-22 10:10 ` David Carlton
2002-09-27 16:20 ` Andrew Cagney
2002-09-27 16:32 ` David Carlton
2002-09-27 16:42 ` Andrew Cagney
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=15676.21042.125481.349851@jackfruit.Stanford.EDU \
--to=carlton@math.stanford.edu \
--cc=gdb-patches@sources.redhat.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