Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Tom Tromey <tom@tromey.com>, gdb-patches@sourceware.org
Subject: Re: [RFC] Sort #includes in gdb
Date: Mon, 28 Jan 2019 19:08:00 -0000	[thread overview]
Message-ID: <e132876c-15b3-7c47-f765-5c2db103b38e@redhat.com> (raw)
In-Reply-To: <87fttfmnpq.fsf@tromey.com>

Hi!

On 01/26/2019 03:40 PM, Tom Tromey wrote:

> I did not push this to the buildbot, as I believe it is too large for
> that as well.

ISTR that you could point the bot at some branch instead of a patch?

This would seem particularly useful for this patch, given
the potential for breaking native/host-only code.

> If you want to try building it without running the
> script, it is the branch "submit/sort-includes" in my github.
> 
> I did test that the script produces the same output if run twice.
> (Actually it has a buglet where it still updates the ChangeLog the
> second time, but I didn't feel like fixing this.)
> 
> Let me know what you think.  This does have some possibility of breaking
> the build.

Yeah, there's a likely chance that this will break some native builds -- there are
some headers that are (or used to be) order dependent.  I remember a small number of
patches over the years moving header include order particularly in the
architecture-specific Linux native files, around asm/foo.h, sys/foo.h, headers to
fix the build in some particular kernel/libc version.  ISTR <asm/ptrace.h>
as a particular trouble maker, but I could well be misremembering that one.
I wish I could point at actual code / comments or commits, but I'm not
finding much.  :-/

See this one in gdbserver/linux-arm-low.c at least:

 /* Don't include elf.h if linux/elf.h got included by gdb_proc_service.h.
    On Bionic elf.h and linux/elf.h have conflicting definitions.  */


The fix would be trivial of course, so it doesn't sound very alarming to
me.

BTW, skimming the patch I noticed that the script didn't move
this conditional include (HAVE_GETAUXVAL):

 --- a/gdb/gdbserver/linux-aarch64-ipa.c
 +++ b/gdb/gdbserver/linux-aarch64-ipa.c
 @@ -19,9 +19,11 @@
     along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
  
  #include "server.h"
 +
 +#include <elf.h>
  #include <sys/mman.h>
 +
  #include "tracepoint.h"
 -#include <elf.h>
  #ifdef HAVE_GETAUXVAL
  #include <sys/auxv.h>
  #endif

but seems to have handled the conditional include in many other cases.

> --- a/gdb/ada-lang.c
> +++ b/gdb/ada-lang.c
> 
>  #include "defs.h"
> +#include "ada-lang.h"
> +
> +#include <algorithm>
>  #include <ctype.h>
> +#include <sys/stat.h>

What do you think of having separate stanzas for C and C++ system includes?

So we'd have include sections similar to:

 #include "defs.h"
 #include "ada-lang.h"

 #include <ctype.h>
 #include <sys/stat.h>

 #include <algorithm>
 #include <map>
 #include <string>
 #include <vector>

 ...

C++ headers are easily detectable as those without a file extension (no .h).


A minor one: personally, I think I would prefer that all files from the
same directory were sorted together.  I.e., instead of:

 #include "c-lang.h"
 #include "cli/cli-utils.h"
 #include "common/byte-vector.h"
 #include "common/function-view.h"
 #include "common/gdb_vecs.h"
 #include "common/vec.h"
 #include "completer.h"
 #include "dictionary.h"
 #include "symfile.h"
 #include "symtab.h"

This would look clearer / more organized to me:

 #include "cli/cli-utils.h"
 #include "common/byte-vector.h"
 #include "common/function-view.h"
 #include "common/gdb_vecs.h"
 #include "common/vec.h"

 #include "c-lang.h"
 #include "completer.h"
 #include "dictionary.h"
 #include "symfile.h"
 #include "symtab.h"

The above shows directories before non-directory files, because
it seems like the include order goes along with the 
'more general -> more specific', or 'further away -> closer' order.
Something like:

 system headers
 "external" libraries/utilities (libiberty/BFD)
 "internal" libraries/utilities (common / nat / cli / arch)
 gdb/ headers

No firm opinion on comments vs no comments.

Thanks,
Pedro Alves


  parent reply	other threads:[~2019-01-28 19:08 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-26 15:40 Tom Tromey
2019-01-27  4:58 ` Joel Brobecker
2019-02-15 20:46   ` Tom Tromey
2019-01-28 19:08 ` Pedro Alves [this message]
2019-01-28 22:31   ` Matt Rice
2019-02-15 20:55   ` Tom Tromey
2019-03-15 23:13     ` Tom Tromey
2019-03-20 17:42       ` Pedro Alves
2019-03-29 20:52         ` Tom Tromey
2019-03-29 21:05           ` Simon Marchi
2019-03-30 18:35             ` Tom Tromey
2019-04-03 18:58               ` Pedro Alves
2019-04-03 19:29                 ` Sergio Durigan Junior
2019-04-03 20:34                 ` Sergio Durigan Junior
2019-04-04  2:47                   ` Tom Tromey
2019-04-04  3:40                     ` Sergio Durigan Junior
2019-04-03 19:00             ` Pedro Alves
2019-04-03 20:11               ` Tom Tromey
2019-04-03 21:00                 ` Pedro Alves

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=e132876c-15b3-7c47-f765-5c2db103b38e@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.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