[binutils-gdb] [gdb] Remove unnecessary defs.h/common-defs.h includes

Tom de Vries via Gdb-cvs <[email protected]>
Newsgroups gmane.comp.gdb.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=eb221802ed0fc9204da49b2ec493c00896687e95

commit eb221802ed0fc9204da49b2ec493c00896687e95
Author: Tom de Vries <[email protected]>
Date:   Tue Apr 21 23:12:13 2026 +0200

    [gdb] Remove unnecessary defs.h/common-defs.h includes
    
    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 <[email protected]>
    
    [1] https://sourceware.org/pipermail/gdb-patches/2026-April/226694.html

Diff:
---
 gdb/amd64-gnu-tdep.c                                 | 1 -
 gdb/break-cond-parse.c                               | 1 -
 gdb/defs.h                                           | 2 ++
 gdb/nat/x86-linux.c                                  | 1 -
 gdb/riscv-linux-canonicalize-syscall-gen.c           | 1 -
 gdb/syscalls/riscv-linux-canonicalize-syscall-gen.py | 1 -
 gdb/unittests/remote-arg-selftests.c                 | 1 -
 gdbserver/linux-microblaze-low.cc                    | 1 -
 gdbserver/server.h                                   | 2 ++
 gdbsupport/common-defs.h                             | 2 ++
 gdbsupport/remote-args.cc                            | 1 -
 11 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/gdb/amd64-gnu-tdep.c b/gdb/amd64-gnu-tdep.c
index 366cc4584ad..8415ce7468a 100644
--- a/gdb/amd64-gnu-tdep.c
+++ b/gdb/amd64-gnu-tdep.c
@@ -16,7 +16,6 @@
    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"
diff --git a/gdb/break-cond-parse.c b/gdb/break-cond-parse.c
index 4fec4dbef94..7cb70df378c 100644
--- a/gdb/break-cond-parse.c
+++ b/gdb/break-cond-parse.c
@@ -15,7 +15,6 @@
    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"
diff --git a/gdb/defs.h b/gdb/defs.h
index 6029a2144d0..90abf0d3432 100644
--- a/gdb/defs.h
+++ b/gdb/defs.h
@@ -397,4 +397,6 @@ DEF_ENUM_FLAGS_TYPE (enum user_selected_what_flag, user_selected_what);
   extern void _initialize_ ## NAME (); \
   void _initialize_ ## NAME ()
 
+#else
+#  error gdb/defs.h should not be included manually
 #endif /* GDB_DEFS_H */
diff --git a/gdb/nat/x86-linux.c b/gdb/nat/x86-linux.c
index 92979ae652d..16391dcde24 100644
--- a/gdb/nat/x86-linux.c
+++ b/gdb/nat/x86-linux.c
@@ -18,7 +18,6 @@
    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"
diff --git a/gdb/riscv-linux-canonicalize-syscall-gen.c b/gdb/riscv-linux-canonicalize-syscall-gen.c
index be1eabcabc0..2d625bdfa8c 100644
--- a/gdb/riscv-linux-canonicalize-syscall-gen.c
+++ b/gdb/riscv-linux-canonicalize-syscall-gen.c
@@ -17,7 +17,6 @@
    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
diff --git a/gdb/syscalls/riscv-linux-canonicalize-syscall-gen.py b/gdb/syscalls/riscv-linux-canonicalize-syscall-gen.py
index ca7dbe0b306..63b359f226b 100755
--- a/gdb/syscalls/riscv-linux-canonicalize-syscall-gen.py
+++ b/gdb/syscalls/riscv-linux-canonicalize-syscall-gen.py
@@ -59,7 +59,6 @@ HEAD = f"""\
    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
diff --git a/gdb/unittests/remote-arg-selftests.c b/gdb/unittests/remote-arg-selftests.c
index e878fefb2ef..7d4e63deefd 100644
--- a/gdb/unittests/remote-arg-selftests.c
+++ b/gdb/unittests/remote-arg-selftests.c
@@ -17,7 +17,6 @@
    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"
diff --git a/gdbserver/linux-microblaze-low.cc b/gdbserver/linux-microblaze-low.cc
index e5bdba12dfc..21793d9a801 100644
--- a/gdbserver/linux-microblaze-low.cc
+++ b/gdbserver/linux-microblaze-low.cc
@@ -17,7 +17,6 @@
    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"
diff --git a/gdbserver/server.h b/gdbserver/server.h
index 284f61821c0..bbba3650de7 100644
--- a/gdbserver/server.h
+++ b/gdbserver/server.h
@@ -214,4 +214,6 @@ client_state &get_client_state ();
 #include "gdbthread.h"
 #include "inferiors.h"
 
+#else
+#  error gdbserver/server.h should not be included manually
 #endif /* GDBSERVER_SERVER_H */
diff --git a/gdbsupport/common-defs.h b/gdbsupport/common-defs.h
index f181044f383..1c0ae0ad9d1 100644
--- a/gdbsupport/common-defs.h
+++ b/gdbsupport/common-defs.h
@@ -237,4 +237,6 @@
 #define HAVE_USEFUL_SBRK 1
 #endif
 
+#else
+#  error gdbsupport/common-defs.h should not be included manually
 #endif /* GDBSUPPORT_COMMON_DEFS_H */
diff --git a/gdbsupport/remote-args.cc b/gdbsupport/remote-args.cc
index 232adbff998..2abf61aa86b 100644
--- a/gdbsupport/remote-args.cc
+++ b/gdbsupport/remote-args.cc
@@ -15,7 +15,6 @@
    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"
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.