Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* GDB in C++
@ 2007-06-30 14:56 Michael Eager
  2007-07-01 20:54 ` Daniel Jacobowitz
  0 siblings, 1 reply; 26+ messages in thread
From: Michael Eager @ 2007-06-30 14:56 UTC (permalink / raw)
  To: gdb

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


^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2007-07-13 21:24 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-06-30 14:56 GDB in C++ Michael Eager
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox