Re: [FYI] Sort includes for files gdb/[a-f]*.[chyl].

John Baldwin
2019-04-06T19:29:23Z

On 4/5/19 11:48 PM, Andreas Schwab wrote:
> On Apr 05 2019, Tom Tromey <tom@tromey.com> wrote:
>
>> diff --git a/gdb/aarch64-fbsd-nat.c b/gdb/aarch64-fbsd-nat.c
>> index bb187a600d0..cb4130a2844 100644
>> --- a/gdb/aarch64-fbsd-nat.c
>> +++ b/gdb/aarch64-fbsd-nat.c
>> @@ -18,16 +18,18 @@
>> along with this program. If not, see <http://www.gnu.org/licenses/>. */
>>
>> #include "defs.h"
>> -#include "target.h"
>>
>> -#include <sys/types.h>
>> -#include <sys/ptrace.h>
>> +/* Standard C includes. */
>> #include <machine/reg.h>
>> +#include <sys/ptrace.h>
>> +#include <sys/types.h>
>
> These are not really "Standard C includes".

I agree that these are pretty OS-specific. Also, FreeBSD doesn't make all of its
headers standalone and sys/types.h probably has to come first before any other
sys/*.h, etc. (I had forgotten about this until now). You can think of
<sys/types.h> (or <sys/param.h> if needed) as being like GDB's "defs.h". As it
is, my guess is that this change doesn't compile as <machine/reg.h> almost
certainly uses types defined in <sys/types.h> on all FreeBSD architectures.

The sorting rules that FreeBSD uses in its source tree is something like:

<sys/param.h> or <sys/types.h> (but not both)
<sys/*.h> (sorted)
<machine|net|netinet|*/*.h> (sorted which naturally groups them by subdir)
<*.h> (sorted)

I'm not sure if we want to treat sys/types.h special in your script, but POSIX in
the past did used to require it before other headers (e.g. socket() used to
formally require <sys/types.h> before <sys/socket.h>). I'm also not sure if we want
to sort <sys/*.h> before other groups, but FreeBSD might very well need that at
least. I'm fine with fixing any build breakages post commit (I know there aren't
any functional FreeBSD buildbots currently). I just don't know how much you care
about the script being completely correct. It might also depend on if any of the
non-nat files that include <sys/types.h> end up breaking on FreeBSD (or other OS's)
after the sorting changes. I'm happy to pull down a branch and do a test build if
that would work best for you.

The one use of sys/param.h in the tree is bsd-kvm.c which is effectively a nat file
only used on the BSD's and the natural sort order of the sys/*.h headers in that
file would sort correctly anyway FWIW.

--
John Baldwin