public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@redhat.com>
To: Jan Kratochvil <jan.kratochvil@redhat.com>
Cc: gdb@sourceware.org
Subject: Re: Will therefore GDB utilize C++ or not?
Date: Wed, 04 Apr 2012 20:48:00 -0000	[thread overview]
Message-ID: <87aa2rjkb8.fsf@fleche.redhat.com> (raw)
In-Reply-To: <20120330161403.GA17891@host2.jankratochvil.net> (Jan	Kratochvil's message of "Fri, 30 Mar 2012 18:14:03 +0200")

>>>>> "Jan" == Jan Kratochvil <jan.kratochvil@redhat.com> writes:

Jan> To C++ or not to C++?  Unfortunately the discussion was here
Jan> already before and I am aware several contributors are not welcome
Jan> with it, I think it does not need to affect readability of C code
Jan> much, there is not enough workforce to rewrite all the GDB code
Jan> into C++ style anyway.  Still C++ would help a lot, some kinds of
Jan> bugs are not solvable without it.

I'm strongly in favor of C++ for reasons I'll lay out below.

I agree with all your points.

But first:

Jan> I am open to suggestions of static analysis tools to use instead
Jan> but at least according to the experience of Tom Tromey it is not so
Jan> easy / safe / foolproof to use, IIUC his words.

Yes, when David Malcolm wrote his Python plugin for GCC, I decided to
see whether we could get the equivalent maintainability benefits of C++
by writing in C and then using static analysis to fill the gaps.

To this end I wrote a few small plugins to do analysis on gdb.

My conclusion is that it is just too much work to iron out all the false
reports from the plugins.  Partly this is due to gdb's unusual
structure, in particular the use of cleanups, which mean that any
analysis requires a lot of hair to ensure its correctness.


Last June (so long ago already?) I sent a draft of a proposal to migrate
gdb to C++ to the Archer list (the thread is
http://sourceware.org/ml/archer/2011-q2/threads.html#00028; the
followups are worth reading, but I've incorporated most of it into the
below).  After some discussion and edits, I chickened out of sending it.
Here it is now:


At the GCC Summit, I once again brought up the perennial idea of
moving GDB to be implemented in C++.  There, we agreed that as a
follow-on to that discussion that I would raise the topic among the
GDB maintainers, and in particular present my migration plan.

My goal for moving to C++ is to make GDB more robust.

My view is that GDB is already written in a poor cousin of C++.
Nearly every feature that people hate about C++ is already in use in
GDB.  This list is not exhaustive, just informational:

* Subclasses.  See general_symbol_info.  struct value and struct type
  would be improved by them.

* Virtual functions.  gdbarch, languages, and values all use these.

* Overloaded functions.  Anywhere you see a _1 suffix.

* Templates.  Both observers and VEC are templates.

* Exceptions.  Used ubiquitously.

* RAII.  Cleanups, but they are dynamic and more error-prone.

* Even global constructors -- init.c.

In most cases, GDB's implementation of these features is inferior to
that of the C++ compiler.  Its exceptions are slower.  Its data
structures have less type-safety.  Both cleanups and TRY_CATCH are
error-prone in practice.  GDB is needlessly verbose due to using
callback-based container iteration and callback-based exception
handling.  We have run into various situations where errors could have
been prevented through the use of better type-safety -- e.g., wrapper
classes for the CU- versus section-offset case.

I think a gradual move to C++ would enable us to fix these problems.
I believe it would also provide us a way to fix the ongoing reference
counting bugs in the Python layer.


I don't believe we should convert all of GDB to C++.  In particular I
think gdbserver should remain as pure C, and likewise any code shared
between gdbserver and gdb should be kept as such.


I also think we should be reasonably conservative in our choices of
C++ constructs to use.  I think this should be a separate thread; I
will be happy to write a draft proposal for this as well.  We can also
see what the GCC community comes up with here -- our needs are a
little different, but probably not drastically so.


My concrete transition proposal is:

1. Modify GDB so it can be compiled with -Wc++-compat.
   This would be the first patch series.  There is already an archer
   branch for this.

2. Then, change GDB to compile with a C++ compiler (-Wc++-compat is
   not complete).  This would be the second patch series.

3. Require C++.

4. Change selected modules to use C++ rather than C.
   I don't think a wholesale change makes sense, but some areas would
   benefit.

   My first target would be to change the exception handling system to
   use C++ exceptions.  This would enable us to begin using RAII in
   some areas, which would help robustness.

   My concrete plan here is:

   * Use the GCC cleanup-checking plugin I already wrote to detect
     cleanup-aware functions.

   * Modify these functions, using a script, to add an RAII-using
     object to manage the local cleanups.  This is important so that
     we run cleanups at the correct time during stack unwinding.

   * Change throw_exception to use 'throw' and all TRY_EXCEPT
     instances to try...catch.

   * Finally, convert functions to static RAII usage when appropriate;
     this will be an ongoing transition.

   I think our second target will be sorting out Python reference
   counting, so we can avoid the many problems we have had there.


Tom

  reply	other threads:[~2012-04-04 20:48 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 [this message]
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
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                   ` Russell Shaw
2012-06-02 11:15                   ` Jan Kratochvil
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=87aa2rjkb8.fsf@fleche.redhat.com \
    --to=tromey@redhat.com \
    --cc=gdb@sourceware.org \
    --cc=jan.kratochvil@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).