From: Jim Blandy <jimb@zwingli.cygnus.com>
To: Andrew Cagney <ac131313@cygnus.com>
Cc: GDB Discussion <gdb@sources.redhat.com>
Subject: Re: So what is wrong with v3 C++
Date: Fri, 29 Jun 2001 13:40:00 -0000 [thread overview]
Message-ID: <npk81vrpbi.fsf@zwingli.cygnus.com> (raw)
In-Reply-To: <3B3BBD90.8070601@cygnus.com>
When it comes to prioritizing problems, there's some risk in a bunch
of non-C++ programmers like me trying to assess which bugs are most
important to fix, since we don't have daily experience showing us
which bugs interfere with our work the most.
I just talked about this on the phone with Ben Kosnik. He says that
the bug causing him the most trouble is the simple inability to print
his objects. Troubles with virtual base classes and stepping into
virtual functions are insignificant compared to the frustration of
being unable to see his data.
Here's a simple example that illustrates the problem:
$ cat scope-rtti.cc
#include <stdio.h>
namespace N
{
struct A
{
int x, y;
virtual int sum (void);
};
};
int
N::A::sum ()
{
return x + y;
}
main ()
{
N::A a;
a.x = 3;
a.y = 4;
printf ("%d\n", a.sum ());
}
$ $Gcc3B/g++ -g scope-rtti.cc -o scope-rtti
$ $D6/gdb/gdb scope-rtti
GNU gdb 2001-06-28-cvs (MI_OUT)
Copyright 2001 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i686-pc-linux-gnu"...
(gdb) break 25
Breakpoint 1 at 0x8048813: file scope-rtti.cc, line 25.
(gdb) run
Starting program: /home/jimb/c++v3/play/scope-rtti
Breakpoint 1, main () at scope-rtti.cc:25
25 printf ("%d\n", a.sum ());
(gdb) print a
$1 = {_vptr.A = 0x8049908, x = 3, y = 4}
By default, GDB prints `a' using its compile-time type. There's
nothing really ABI-specific going on here, so it works okay.
(gdb) set print object
(gdb) print a
$2 = can't find class named `N::A', as given by C++ RTTI
(gdb)
When we say `set print object', we ask GDB to print using `a''s
run-time type. This is really what you need for debugging, I think:
when the compile-time type is just some base class that defines
nothing but a bunch of virtual functions (as is the case in the bug
report Ben just posted), the compile-time type is practically useless.
Unfortunately, since GDB mishandles the scoping, this feature doesn't
work. If I remove the `namespace N' from the example, so the type's
name is simply `A' instead of `N::A', everything works fine.
What makes it especially urgent is that, for people working on the
standard C++ library implementation, *every* type is in the `std'
namespace. So this problem will affect just about every object they
ever want to print. And of course, ordinary C++ code will use the
standard library pretty frequently, too.
So, if I've understood the situation correctly (all you actual C++
users, please correct me), I think this is probably the first bug we
should fix.
I have no opinion yet on whether we would need to rewrite the dwarf 2
reader to fix this.
next prev parent reply other threads:[~2001-06-29 13:40 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-06-28 16:28 Andrew Cagney
2001-06-28 18:59 ` Daniel Berlin
2001-06-29 13:40 ` Jim Blandy [this message]
2001-06-29 23:15 ` Daniel Berlin
2001-06-30 10:06 ` Jim Blandy
2001-06-30 12:30 ` Daniel Berlin
2001-07-02 9:01 ` Jim Blandy
2001-07-04 9:22 ` Andrew Cagney
2001-06-28 18:12 Michael Elizabeth Chastain
2001-06-28 19:06 ` Daniel Berlin
2001-06-28 20:42 Michael Elizabeth Chastain
2001-06-28 20:44 ` Christopher Faylor
2001-06-28 23:10 ` Daniel Berlin
2001-06-28 23:08 ` Daniel Berlin
2001-06-29 0:29 ` Tom Tromey
2001-06-28 23:31 Michael Elizabeth Chastain
2001-06-29 8:59 ` Daniel Berlin
2001-06-28 23:50 Michael Elizabeth Chastain
2001-06-29 8:59 ` Daniel Berlin
2001-06-29 0:56 Michael Elizabeth Chastain
2001-06-29 10:28 Michael Elizabeth Chastain
2001-06-29 11:40 ` Daniel Berlin
2001-06-29 11:57 Benjamin Kosnik
2001-07-02 20:28 ` Per Bothner
2001-07-02 14:54 Benjamin Kosnik
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=npk81vrpbi.fsf@zwingli.cygnus.com \
--to=jimb@zwingli.cygnus.com \
--cc=ac131313@cygnus.com \
--cc=gdb@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