From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 92464 invoked by alias); 28 Jan 2019 19:08:17 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 92455 invoked by uid 89); 28 Jan 2019 19:08:17 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=BAYES_00,GIT_PATCH_2,GIT_PATCH_3,KAM_SHORT,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=pedro, Pedro, organized, bot X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 28 Jan 2019 19:08:15 +0000 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 75E622D805; Mon, 28 Jan 2019 19:08:14 +0000 (UTC) Received: from [127.0.0.1] (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 254B861791; Mon, 28 Jan 2019 19:08:12 +0000 (UTC) Subject: Re: [RFC] Sort #includes in gdb To: Tom Tromey , gdb-patches@sourceware.org References: <87fttfmnpq.fsf@tromey.com> From: Pedro Alves Message-ID: Date: Mon, 28 Jan 2019 19:08:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <87fttfmnpq.fsf@tromey.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-SW-Source: 2019-01/txt/msg00586.txt.bz2 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 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 . */ #include "server.h" + +#include #include + #include "tracepoint.h" -#include #ifdef HAVE_GETAUXVAL #include #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 > #include > +#include 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 #include #include #include #include #include ... 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