I asked an AI to review a patch that added a new file, and it mentioned I
should add an include of defs.h as first include.
That used to be true, but since commit
18d2988e5da ("gdb, gdbserver,
gdbsupport: remove includes of early headers") that's not the case anymore.
Error out when encountering a second include of defs.h, and remove a few of
those.
While we're at it, do the same for gdbsupport/common-defs.h and
gdbserver/server.h.
Tested by rebuilding gdb on x86_64-linux.
V1 submitted here [1].
Changes in v1:
- also handle gdbserver/server.h
- change error message to use "manually" instead of "twice"
Approved-By: Simon Marchi <simon.marchi@efficios.com>
[1] https://sourceware.org/pipermail/gdb-patches/2026-April/226694.html
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
-#include "defs.h"
#include "extract-store-integer.h"
#include "gdbcore.h"
#include "osabi.h"
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
-#include "defs.h"
#include "gdbsupport/gdb_assert.h"
#include "gdbsupport/selftest.h"
#include "test-target.h"
extern void _initialize_ ## NAME (); \
void _initialize_ ## NAME ()
+#else
+# error gdb/defs.h should not be included manually
#endif /* GDB_DEFS_H */
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "elf/common.h"
-#include "gdbsupport/common-defs.h"
#include "nat/gdb_ptrace.h"
#include "nat/linux-ptrace.h"
#include "nat/x86-cpuid.h"
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
-#include "defs.h"
#include "riscv-linux-tdep.h"
/* riscv_linux_canonicalize_syscall maps from the native RISC-V Linux set
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
-#include "defs.h"
#include "riscv-linux-tdep.h"
/* riscv_linux_canonicalize_syscall maps from the native RISC-V Linux set
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
-#include "defs.h"
#include "gdbsupport/selftest.h"
#include "gdbsupport/buildargv.h"
#include "gdbsupport/common-inferior.h"
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
-#include "server.h"
#include "linux-low.h"
#include "elf/common.h"
#include "gdbthread.h"
#include "inferiors.h"
+#else
+# error gdbserver/server.h should not be included manually
#endif /* GDBSERVER_SERVER_H */
#define HAVE_USEFUL_SBRK 1
#endif
+#else
+# error gdbsupport/common-defs.h should not be included manually
#endif /* GDBSUPPORT_COMMON_DEFS_H */
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
-#include "gdbsupport/common-defs.h"
#include "gdbsupport/remote-args.h"
#include "gdbsupport/common-inferior.h"
#include "gdbsupport/buildargv.h"