This is the mail archive of the
mailing list for the GDB project.
GDB in C++
- From: Michael Eager <eager at eagercon dot com>
- To: gdb at sources dot redhat dot com
- Date: Sat, 30 Jun 2007 07:56:32 -0700
- Subject: GDB in C++
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
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 firstname.lastname@example.org
1960 Park Blvd., Palo Alto, CA 94306 650-325-8077