From: Michael Eager <eager@eagercon.com>
To: gdb@sources.redhat.com
Subject: GDB in C++
Date: Sat, 30 Jun 2007 14:56:00 -0000 [thread overview]
Message-ID: <46866F20.2010902@eagercon.com> (raw)
I'd like to bring up what I think will be regarded as
heresy: converting GDB to C++.
First, let me say that I'm not a fan of C++. It's an
overly complex language with many faults.
That said, when I read and step through GDB code I see
significant portions which are clearly written in a way
which attempts to emulate classes, objects, and both
data and member encapsulation.
I also see some flaws in this emulation, some of which
affect performance, others which affect logic. There
are also places where the encapsulation is broken. All of
this makes debugging more difficult.
For example, in gdbarch handling, all (or almost all)
routines start with one or more asserts which check that
the routine is passed a pointer to an gdbarch specification.
Actually, they don't validate that this is a gdbarch, only
that the pointer is not NULL. These routines and the asserts
are executed tens of thousands of times when running GDB.
If this were a real class, many of these asserts would be
unnecessary, since by construction, the "this" pointer would
be valid. Inlining would also improve performance, since it
would eliminate many function calls.
I'm repeatedly surprised to step over an assert and find
that either the state has changed or I hit a previously
set breakpoint. There are significant side effects to
executing these asserts, which changes the apparent flow
of the program. While asserts are a "good thing", hidden
side effects and especially side effects in asserts are a
"bad thing". I think that many of these side effects would
disappear or at least become apparent if real classes were
used.
Some additional history: many years ago I participated in
a major re-write of Sun Microsystem's DBX. We converted
it from K&R style C to ANSI C which was compatible with C++.
I then re-wrote about 1/3 of DBX in a constrained subset of
C++, essentially C with Classes. The handling of object files
(a.out and ELF), symbols, stabs, and shared libraries was
all converted to use classes. The rewrite was quite successful
in adding new functionality and eliminating many bugs.
There are vestiges of K&R support in GDB, such as the PARAMS
function, but I believe that this is not universally used and
is out of date. I think that concerns about availability of
C++ on currently supported hosts are also out of date. As
a side effect, if GDB were written in C++, I think that the
support for C++ debugging would be forced to improve.
I'm out of town at the moment, being fitted with asbestos
undergarments and armor, getting ready for the anticipated
flames and brickbats. I may be a bit slow in responding.
--
Michael Eager eager@eagercon.com
1960 Park Blvd., Palo Alto, CA 94306 650-325-8077
next reply other threads:[~2007-06-30 14:56 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-06-30 14:56 Michael Eager [this message]
2007-07-01 20:54 ` Daniel Jacobowitz
2007-07-02 1:33 ` Joel Brobecker
2007-07-03 3:49 ` Michael Eager
2007-07-03 7:55 ` Mark Kettenis
2007-07-11 21:04 ` Jan Kratochvil
2007-07-02 7:21 ` Mark Kettenis
2007-07-03 3:57 ` Michael Eager
2007-07-03 7:03 ` Fabian Cenedese
2007-07-03 12:14 ` Robert Dewar
2007-07-03 19:09 ` Gary Funck
2007-07-11 19:47 ` Thiago Jung Bauermann
2007-07-11 19:59 ` Paul Koning
2007-07-11 20:41 ` Jim Blandy
2007-07-11 21:00 ` Gary Funck
2007-07-11 21:32 ` Daniel Jacobowitz
2007-07-11 21:38 ` Robert Dewar
2007-07-12 3:16 ` Eli Zaretskii
2007-07-12 2:24 ` Michael Eager
2007-07-13 20:21 ` Thiago Jung Bauermann
2007-07-13 20:55 ` Eli Zaretskii
2007-07-13 21:24 ` Thiago Jung Bauermann
2007-07-12 3:11 ` Eli Zaretskii
2007-07-11 21:11 ` Gary Funck
2007-07-02 20:21 ` David Daney
2007-07-02 20:28 ` Daniel Jacobowitz
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=46866F20.2010902@eagercon.com \
--to=eager@eagercon.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