mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-11-27 03:51:15 +08:00
ab7daea3ad
The motivation for this change is for analysis tools and IDEs to be better at analyzing header files on their own. There are some definitions and includes we want to occur at the very beginning of all translation units. The way we currently do that is by requiring all source files (.c and .cc files) to include one of defs.h (for gdb), server.h (for gdbserver) of common-defs.h (for gdbsupport and shared source files). These special header files define and include everything that needs to be included at the very beginning. Other header files are written in a way that assume that these special "prologue" header files have already been included. My problem with that is that my editor (clangd-based) provides a very bad experience when editing header files. Since clangd doesn't know that one of defs.h/server.h/common-defs.h was included already, a lot of things are flagged as errors. For instance, CORE_ADDR is not known. It's possible to edit the files in this state, but a lot of the power of the editor is unavailable. My proposal to help with this is to include those things we always want to be there using the compilers' `-include` option. Tom Tromey said that the current approach might exist because not all compilers used to have an option like this. But I believe that it's safe to assume they do today. With this change, clangd picks up the -include option from the compile command, and is able to analyze the header file correctly, as it sees all that stuff included or defined by that -include option. That works because when editing a header file, clangd tries to get the compilation flags from a source file that includes said header file. This change is a bit self-serving, because it addresses one of my frustrations when editing header files, but it might help others too. I'd be curious to know if others encounter the same kinds of problems when editing header files. Also, even if the change is not necessary by any means, I think the solution of using -include for stuff we always want to be there is more elegant than the current solution. Even with this -include flag, many header files currently don't include what they use, but rather depend on files included before them. This will still cause errors when editing them, but it should be easily fixable by adding the appropriate include. There's no rush to do so, as long as the code still compiles, it's just a convenience thing. The changes are: - Add the appropriate `-include` option to the various Makefiles. - There is one particularity for gdbserver's Makefile: we do not want to include server.h when building `gdbreplay.o`, as `gdbreplay.cc` doesn't include it. So we can't simply put the `-include` in `INTERNAL_CFLAGS`. Add the `-include server.h` option to the `COMPILE` and `IPAGENT_COMPILE` variables, and added a special rule to compile `gdbreplay.o` with `-include gdbsupport/common-defs.h`. - Remove the `-include` option from the `check-headers` rule in gdb/Makefile.in, since it is already included in `INTERNAL_CFLAGS`. Change-Id: If3e345d00a9fc42336322f1d8286687d22134340 Approved-By: Pedro Alves <pedro@palves.net>
100 lines
2.4 KiB
Makefile
100 lines
2.4 KiB
Makefile
## Process this file with automake to generate Makefile.in
|
|
#
|
|
# Copyright (C) 2020-2024 Free Software Foundation, Inc.
|
|
#
|
|
# This file is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program; see the file COPYING3. If not see
|
|
# <http://www.gnu.org/licenses/>.
|
|
#
|
|
|
|
AUTOMAKE_OPTIONS = no-dist foreign
|
|
ACLOCAL_AMFLAGS = -I . -I ../config
|
|
|
|
# Suppress 'configure.ac: error: AM_GNU_GETTEXT used but SUBDIRS not defined'
|
|
# from Automake, as gdbsupport uses AM_GNU_GETTEXT through
|
|
# ZW_GNU_GETTEXT_SISTER_DIR, but doesn't have any translations (currently).
|
|
SUBDIRS =
|
|
|
|
AM_CPPFLAGS = \
|
|
-I$(srcdir)/../include \
|
|
-I$(srcdir)/../gdb \
|
|
-I../gnulib/import \
|
|
-I$(srcdir)/../gnulib/import \
|
|
-I.. \
|
|
-I$(srcdir)/.. \
|
|
$(INCINTL) \
|
|
-I../bfd \
|
|
-I$(srcdir)/../bfd \
|
|
-include $(srcdir)/common-defs.h \
|
|
@LARGEFILE_CPPFLAGS@
|
|
|
|
override CXX += $(CXX_DIALECT)
|
|
|
|
AM_CXXFLAGS = $(WARN_CFLAGS) $(WERROR_CFLAGS)
|
|
|
|
noinst_LIBRARIES = libgdbsupport.a
|
|
|
|
if SELFTEST
|
|
selftest = selftest.cc
|
|
endif
|
|
|
|
if HAVE_PIPE_OR_PIPE2
|
|
eventpipe = event-pipe.cc
|
|
endif
|
|
|
|
libgdbsupport_a_SOURCES = \
|
|
agent.cc \
|
|
btrace-common.cc \
|
|
cleanups.cc \
|
|
common-debug.cc \
|
|
common-exceptions.cc \
|
|
common-inferior.cc \
|
|
common-regcache.cc \
|
|
common-utils.cc \
|
|
environ.cc \
|
|
errors.cc \
|
|
event-loop.cc \
|
|
fileio.cc \
|
|
filestuff.cc \
|
|
format.cc \
|
|
gdb-dlfcn.cc \
|
|
gdb-hashtab.cc \
|
|
gdb_obstack.cc \
|
|
gdb_regex.cc \
|
|
gdb_tilde_expand.cc \
|
|
gdb_wait.cc \
|
|
gdb_vecs.cc \
|
|
job-control.cc \
|
|
netstuff.cc \
|
|
new-op.cc \
|
|
pathstuff.cc \
|
|
print-utils.cc \
|
|
ptid.cc \
|
|
rsp-low.cc \
|
|
run-time-clock.cc \
|
|
safe-strerror.cc \
|
|
scoped_mmap.cc \
|
|
search.cc \
|
|
signals.cc \
|
|
signals-state-save-restore.cc \
|
|
task-group.cc \
|
|
tdesc.cc \
|
|
thread-pool.cc \
|
|
xml-utils.cc \
|
|
${eventpipe} \
|
|
$(selftest)
|
|
|
|
# Double-check that no defines are missing from our configury.
|
|
check-defines:
|
|
cd $(srcdir) && emacs --script check-defines.el
|