public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Tom Tromey <tromey@redhat.com>
Cc: Jan Kratochvil <jan.kratochvil@redhat.com>, gdb@sourceware.org
Subject: Re: Will therefore GDB utilize C++ or not?
Date: Mon, 09 Apr 2012 18:41:00 -0000	[thread overview]
Message-ID: <4F832D5B.9030308@redhat.com> (raw)
In-Reply-To: <87aa2rjkb8.fsf@fleche.redhat.com>

If you asked me not too long ago, I'd have been strongly in favor
of C++.  However, that is no longer the case.  I'm now pending
towards "no C++".

Indeed, gdbserver would need to remain pure C, and likewise any
code shared between gdbserver and gdb should have to be kept
as such.  This is important, because we want gdbserver to be usable
in #1, resource constrained scenarios where the C++ dependency would
be unacceptable.  We don't want there to need to be other gdbserver-like
programs specialized for such environments, and gdbserver to be usable only
on bigger machines.  We want gdbserver to run everywhere.  And #2, the debugger
is one of the first programs that is desirable to get running on a new
system/board.  Usually you get C going much sooner than C++.

This, above, mainly #1, made me spend the last few days thinking about
the "to C++ or not to C++" dilema, and I ended up concluding that C++
may not be a good idea afterall.

I'm very wary that introducing C++ will make it increasingly
difficult to share between the C++ and C parts.  Currently not
that much is shared between gdb and gdbserver, but it is long desired,
and in actually in this year's plan to merge gdb's and gdbserver's
backends (am I am actively working on this.  See
<http://sourceware.org/gdb/wiki/LocalRemoteFeatureParity>).
Another set of code that could also be shared, and thus would need to
remain C is the ser*.c files.  The ser_ops vector is one of those bits that would
be "obvious" candidates for turning into C++ classes, but given the desire to
reuse, it would need to stay C.  The event-loop.c file is yet another thing.
It is currently duplicated (though a bit simplified) in gdbserver/event-loop.c.
There goes another use for C++ classes.

The "monitor foo" commands are implemented completely by the target.  E.g., try
"monitor help" in gdbserver.  GDBserver's implementation of monitor commands
is ad hoc.  This mechanism isn't transparent to GDB and users.  E.g., completion
can't work with these commands.  I have desired before to rip out
GDB's command registration machinery under cli/, making it more modular, and
reusing it in GDBserver.  There goes another big potential user for C++-fication.

And then, there's the exceptions support.  GDBserver's current error handling
is like GDB's was 10 years ago.  There's a simple setjmp at the top
level, and any error longjmp's there.  The debugging session tends
to gets broken when an "error" happens  This is even more likely to happen
with multi-inferior debugging.  As such, and with the gdb -> gdbserver
backend merging in mind, it'd be desirable to make gdbserver's backends
use GDB's TRY_CATCH and friends too.  GDB's backends already do...
Now, if parts of GDB are written in C++, which will be made to
throw/catch C++ exceptions, we end up with the case that we need to wrap
cross-language calls in both directions, in order to bridge/wrap the
incompatible exceptions mechanisms.  IMO, this is a _worse_ state than having
the whole of the GDB core in C, and having everything and everyone speak
the same language.

The target_ops vector is yet another candidate for sharing between native
gdb and gdbserver.  Currently in gdbserver, linux-low.c calls into thread_db.c
directly, while in the native debugger the flow is reversed.  Even if
the target vector ends up being replaced by some other form of chaining,
it'd be very desirable to use the same mechanism in either the native debugger
or gdbserver.  So this means that the target_ops vector is something else
that is probably not good to consider converting to C++ classes, although
it always shows up high on the list of candidates.

And I'm sure I could come up with other examples of things that would be
nice C++ classes, but, we better not make them so.

We can't really tell at this point what could or not be C++-ified
freely, and I'd hate it to see some code converted to C++, only to
end up needing to fork it and convert it to C down the road.  Or worse,
rewrite it from scratch.

(On a sidenote: I get the impression from some that C++ would be mostly
useful for the stronger static typing, but I can't help finding it in
contrast with the simultaneous push of some of GDB functionality towards
being implemented in python, with duck typing and all, which people
are happy with.  One (uninvestigated) idea I had was to take a look at
Linux's sparse tool for catching issues like the "offsets" case that
led to this thread.)

There's also the issue with in-process code, which is also
desirable to remain as C code.  Latest developments push towards having
debugger code run _within_ the inferior.  Witness gdbserver's current IPA
(in-process agent; libinproctrace.so), which has a lot of coupling in its
implementation (and a lot of code shared), and a bunch of code shared with
gdbserver.  We can't predict which bits of GDB will we want to be able to
reuse in GDBserver or an IPA, but I do believe that we will be considering
it (reuse something more) the future.

So all in all, I believe that in a C++ world, GDB's "C++ in C" wouldn't
really go away; it would end up still being prominent, not as hidden as
libbfd or other dependencies.  Not hidden enough that we could just
tuck it under the carpet.  I worry that this actually makes it _worse_
for new contributers, who will need to learn about GDB's C idiomatic usage,
and whatever new C++ idiomatic usage GDB would end up with.  With that, and
the worry about the new source of trouble and bugs and confusion that
it would be the bridging between the parts written in the different languages,
I do believe we're better off staying in C land, at least for a couple years more.

-- 
Pedro Alves

  parent reply	other threads:[~2012-04-09 18:41 UTC|newest]

Thread overview: 116+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-30 16:14 Jan Kratochvil
2012-04-04 20:48 ` Tom Tromey
2012-04-04 21:55   ` Mark Kettenis
2012-04-05  3:31     ` Sergio Durigan Junior
2012-04-05 11:46     ` Phil Muldoon
2012-04-06  0:35       ` Will therefore GDB utilize C++? Not John Gilmore
2012-04-06  1:35         ` Russell Shaw
2012-04-06 13:16           ` Joel Brobecker
2012-04-06 14:43             ` Russell Shaw
2012-04-06 15:34             ` Michael Eager
2012-04-06 23:32             ` John Gilmore
2012-04-07  1:04               ` Robert Dewar
2012-04-07  1:52                 ` Thomas Dineen
2012-04-07 16:54               ` Michael Eager
2012-04-09 23:59               ` Stan Shebs
2012-04-05  0:22   ` Will therefore GDB utilize C++ or not? asmwarrior
2012-04-09 18:41   ` Pedro Alves [this message]
2012-04-09 19:05     ` Jan Kratochvil
2012-04-09 19:49       ` Pedro Alves
2012-04-09 20:15         ` Paul Smith
2012-04-12 20:06         ` Daniel Jacobowitz
2012-04-12 21:28           ` Paul_Koning
2012-04-13  0:04           ` Doug Evans
2012-04-18 14:10             ` Pedro Alves
2012-04-18 20:27             ` Tom Tromey
2012-04-18 14:08           ` Pedro Alves
2012-04-21 17:24             ` Daniel Jacobowitz
2012-04-16  6:55         ` Jan Kratochvil
2012-04-18 14:11           ` Pedro Alves
2012-04-18 15:16             ` Jan Kratochvil
2012-04-18 15:28               ` Pedro Alves
2012-04-18 15:54                 ` Jan Kratochvil
2012-04-18 16:01                   ` Pedro Alves
2012-04-18 16:07                   ` Joel Brobecker
2012-04-18 16:13                     ` Jan Kratochvil
2012-04-18 16:23                       ` Joel Brobecker
2012-04-18 16:31                         ` Joel Sherrill
2012-04-18 16:50                           ` Pedro Alves
2012-04-18 16:57                             ` Joel Brobecker
2012-04-18 17:28                               ` Joel Sherrill
2012-04-18 17:40                               ` Paul_Koning
2012-04-18 20:37                                 ` Frank Ch. Eigler
2012-04-18 20:38                                   ` Paul_Koning
2012-04-18 20:36                     ` Tom Tromey
2012-04-18 17:48                   ` John Gilmore
2012-04-18 19:07                     ` Tom Tromey
2012-04-18 23:10                       ` John Gilmore
2012-05-18 18:36                         ` Tom Tromey
2012-05-18 18:47                           ` Paul_Koning
2012-05-18 19:36                             ` Tom Tromey
2012-05-18 19:44                               ` Paul_Koning
2012-05-18 20:07                                 ` Tom Tromey
2012-05-18 20:41                                   ` Aurelian Melinte
2012-05-18 18:51                         ` Lazy CU expansion (Was: Will therefore GDB utilize C++ or not?) Tom Tromey
2012-04-18 20:34                   ` Will therefore GDB utilize C++ or not? Tom Tromey
2012-04-18 19:18               ` Will C++ proponents spend 20 minutes to try what they're proposing? John Gilmore
2012-04-18 19:23                 ` Jan Kratochvil
2012-04-18 20:40                 ` Tom Tromey
2012-04-18 20:56                   ` Mike Frysinger
2012-04-18 20:31           ` Will therefore GDB utilize C++ or not? Tom Tromey
2012-04-18 20:25         ` Tom Tromey
2012-05-21 18:11           ` Pedro Alves
2012-05-21 18:36             ` Jan Kratochvil
2012-11-21 20:18             ` Jan Kratochvil
2012-04-10  0:23     ` Yao Qi
2012-04-10  9:47       ` Yao Qi
2012-04-18 20:11     ` Tom Tromey
2012-04-18 20:31       ` Can it really be ok to map GPL'd code into any old process? John Gilmore
2012-04-18 20:36         ` Pedro Alves
2012-04-23 18:03       ` Will therefore GDB utilize C++ or not? Tom Tromey
2012-05-18 19:55     ` Tom Tromey
2012-05-18 21:56       ` Joel Brobecker
2012-05-19  2:17         ` Tom Tromey
2012-05-19 15:21           ` Daniel Jacobowitz
2012-05-19 21:36             ` Joel Brobecker
2012-05-20 12:16         ` Frank Ch. Eigler
2012-05-21 15:56       ` Pedro Alves
2012-05-21 16:15         ` Jan Kratochvil
2012-05-21 17:37           ` Paul_Koning
2012-05-21 17:58             ` Jan Kratochvil
2012-05-22 18:03               ` Paul_Koning
2012-05-21 18:08           ` Pedro Alves
2012-05-21 18:08             ` Tom Tromey
2012-05-21 18:10             ` Jan Kratochvil
2012-05-21 18:54             ` Matt Rice
2012-05-26 15:50         ` Jan Kratochvil
2012-06-02  7:01           ` Russell Shaw
2012-06-02  7:13             ` Jan Kratochvil
2012-06-02 10:47               ` Russell Shaw
2012-06-02 11:10                 ` Jan Kratochvil
2012-06-02 11:15                   ` Jan Kratochvil
2012-06-02 11:15                   ` Russell Shaw
2012-11-22 18:46     ` Jan Kratochvil
2012-11-22 21:42       ` John Gilmore
2012-11-23 15:26         ` Jan Kratochvil
2012-11-27  1:29       ` Stan Shebs
2012-11-27  2:02         ` Paul_Koning
2012-11-27  2:59           ` Stan Shebs
2012-11-27 15:17             ` Paul_Koning
2012-11-27 21:14             ` Tom Tromey
2012-04-09 23:23   ` Stan Shebs
2012-04-18 14:22     ` Pedro Alves
2012-04-18 18:12       ` Stan Shebs
2012-04-18 18:32         ` Paul_Koning
2012-04-18 18:37         ` Pedro Alves
2012-04-19  8:43   ` Yao Qi
2012-12-04 14:17     ` Jan Kratochvil
2012-12-04 14:44       ` Mark Kettenis
2012-12-04 14:52         ` Jan Kratochvil
2012-12-06 20:39           ` Matt Rice
2012-12-07 12:57             ` Jan Kratochvil
2012-12-07 13:25             ` Yao Qi
2012-12-11  6:25               ` Matt Rice
2012-12-13 15:12                 ` Jan Kratochvil
2012-12-14 11:03                   ` Matt Rice
2012-12-14 12:16                     ` Jan Kratochvil

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=4F832D5B.9030308@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb@sourceware.org \
    --cc=jan.kratochvil@redhat.com \
    --cc=tromey@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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).