public inbox for archer@sourceware.org
 help / color / mirror / Atom feed
From: Gary Benson <gbenson@redhat.com>
To: archer@sourceware.org
Cc: Yao Qi <qiyaoltc@gmail.com>
Subject: Re: C++ draft
Date: Tue, 28 Jun 2011 12:21:00 -0000	[thread overview]
Message-ID: <20110628122135.GB3005@redhat.com> (raw)
In-Reply-To: <BANLkTimpvfyY4hWO_WGxtpXqf8sLiQX6YwfX4fhyJ5Lz8nb3Qw@mail.gmail.com>

Yao Qi wrote:
> Do we plan to move gdbserver to C++?  I think no, because some
> baremental boards have too few memory to hold a C++ application.
> So we are in a state that both C and C++ co-exist in GDB for
> some time. I don't think C and C++ co-existance is a problem,
> or, your plan is> about "make good use of C++ to replace some
> bad and error-prone stuffs in GDB, and keep the rest of GDB as
> it is".  Is it right?

As I understand it, I don't know that there's any reason C++ has to
use more memory than C.  Granted there are things like the STL that
generate vastly more code under the hood than you might expect, but
I don't think anybody is talking about using STL here.

I've spent the past few years working on HotSpot, which is written
using a similar subsection of C++ to what Tom is proposing (with the
exception that HotSpot does not use C++ exceptions).  My experience
has been that the overheads of C++ are as minimal as the can be.  A
data structure in a virtualized class, for example, is larger than
that same data structure in a struct by only a single pointer.  In
cases where GDB is doing what C++ would anyway--for example, replacing
pointers to functions with C++ virtual functions--then we're doing
essentially the same thing, only with better readability and error-
detection.

A concrete example, hello world:

  #include <stdio.h>
  
  int
  main (int argc, char *argv[])
  {
    puts ("Hello world");
    return 0;
  }

Save it as hello.c and compile with gcc, then save it as hello.cc
and compile with g++.  The code for the main function is _exactly_
the same:

  0000000000400514 <main>:
    400514:	55                   	push   %rbp
    400515:	48 89 e5             	mov    %rsp,%rbp
    400518:	48 83 ec 10          	sub    $0x10,%rsp
    40051c:	89 7d fc             	mov    %edi,-0x4(%rbp)
    40051f:	48 89 75 f0          	mov    %rsi,-0x10(%rbp)
    400523:	bf 38 06 40 00       	mov    $0x400638,%edi
    400528:	e8 e3 fe ff ff       	callq  400410 <puts@plt>
    40052d:	b8 00 00 00 00       	mov    $0x0,%eax
    400532:	c9                   	leaveq 
    400533:	c3                   	retq   
    400534:	90                   	nop
    400535:	90                   	nop
    400536:	90                   	nop
    400537:	90                   	nop
    400538:	90                   	nop
    400539:	90                   	nop
    40053a:	90                   	nop
    40053b:	90                   	nop
    40053c:	90                   	nop
    40053d:	90                   	nop
    40053e:	90                   	nop
    40053f:	90                   	nop

The resulting executable is slightly larger (6562 bytes from 6433).
I'm not sure where this comes from or how it would scale from this
trivial example to a project the size of GDB, but the beauty of
Tom's plan is that the first step is to get the basic C code to
compile with a C++ compiler.  Once that's done we can build the
same codebase with the different compilers and see where we're at.

Cheers,
Gary
    
-- 
http://gbenson.net/

  reply	other threads:[~2011-06-28 12:21 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-27 21:08 Tom Tromey
2011-06-27 21:23 ` [Archer] " Joel Brobecker
2011-06-29 19:55   ` Tom Tromey
2011-06-29 21:47     ` [Archer] " Joel Brobecker
2011-06-28  4:33 ` Matt Rice
2011-06-28  8:21 ` Yao Qi
2011-06-28 12:21   ` Gary Benson [this message]
2011-06-28 17:08     ` Matt Rice
2011-06-28 17:36     ` Jan Kratochvil
2011-06-29 20:08     ` Tom Tromey
2011-06-29 20:06   ` Tom Tromey
2011-06-30  6:06     ` Yao Qi
2011-09-26 21:01       ` Jim Blandy
2011-06-29 18:52 ` Stan Shebs
2011-06-29 19:03   ` [Archer] " Joel Brobecker

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=20110628122135.GB3005@redhat.com \
    --to=gbenson@redhat.com \
    --cc=archer@sourceware.org \
    --cc=qiyaoltc@gmail.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).