Move GDB to C++ ?

Michael Veksler mveksler@tx.technion.ac.il
Thu Jul 31 04:52:00 GMT 2008


David Carlton wrote:
> Which language will lead to more people enjoying contributing to GDB?
> Which language will lead to more people feeling like they can work at
> full productivity while contributing to GDB? How will the choice of
> language affect GDB's institutional memory? How will the choice of
> language affect whether or not newcomers are likely to join in,
> whether or not they're likely to stay involved?
>
I have never contributed one line of code to GDB, however this could
be different.

The story:
Several years ago I have encountered a crippling bug for AIX+g++
debugging which would make gdb crash on the first breakpoint.
It is possible that there is a PR for this, I don't remember.

The cause for the crash was that some of the stabs debug info got 
reordered by
AIX's /bin/ld and /bin/as (which seems to be within the spec, by the way).
This reordering sometimes confused gdb and an assertion was fired up.
After seeing the mess of gdb code in that area I gave up fixing this bug in
gdb.

What I ended up doing is to hack gcc-3.2 to emit redundant debug 
information,
such that reordering will not make any difference for gdb. Unfortunately,
gcc would not accept my 10 lines patch (because the bug was not in gcc)
and I had to maintain a private gcc (which I ended up sending to several
people who found me through google).

My conclusion:
If GDB had used c++ std containers it would be much easier for
me to *read* the code and then reorganize it. I don't claim that debugging
C++ is any easier, but I do claim that understanding code *intent* is 
easier
(as long as the coders follow the prime guideline - do not surprise the 
reader)

I would have written a 1000 lines patch if I could only figure out what
gdb was doing in a reasonable amount of time. I *believe* that if that 
piece
of code had used std containers then gdb would see more random
contributions than it does today (in that piece of code).
This is only my personal belief. I am biased since I have been writing c++
code for the past 11 years (wrote C for 5 years before that).

Against c++ I would say that writing good c++ code (without shooting 
yourself
through all your limbs) requires self control and experience. Sometimes it
requires deep knowledge of weird corners in the language (which took me 
years
to mostly master). Simply minimize your friction with such corners by 
e.g. defining
templates only in very rare cases when the benefits are huge and several 
experts
are willing to provide nearly 24h/7 support for them (or avoid them 
altogether).

I will never remember the rules for writing a template function which is 
a friend
of a template class - inside the class definition (every compiler has 
different corner
cases and bugs for this kind of stuff), I simply avoid it - not worth 
the trouble.

Michael



More information about the Gdb mailing list