* [PATCH v2] [gdb] Remove unnecessary defs.h/common-defs.h includes
@ 2026-04-21 19:40 Tom de Vries
2026-04-21 19:53 ` Simon Marchi
0 siblings, 1 reply; 3+ messages in thread
From: Tom de Vries @ 2026-04-21 19:40 UTC (permalink / raw)
To: gdb-patches
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"
[1] https://sourceware.org/pipermail/gdb-patches/2026-April/226694.html
---
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"
base-commit: 8927b500532538cd86aae2d777c6452c51a210c6
--
2.51.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] [gdb] Remove unnecessary defs.h/common-defs.h includes
2026-04-21 19:40 [PATCH v2] [gdb] Remove unnecessary defs.h/common-defs.h includes Tom de Vries
@ 2026-04-21 19:53 ` Simon Marchi
2026-04-21 21:28 ` Tom de Vries
0 siblings, 1 reply; 3+ messages in thread
From: Simon Marchi @ 2026-04-21 19:53 UTC (permalink / raw)
To: Tom de Vries, gdb-patches
On 4/21/26 3:40 PM, Tom de Vries wrote:
> 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.
Btw, this is the kind of details that we could put in an AGENTS.md file
(or similar), if it doesn't offend too many people. AIs are much more
efficient if they know the conventions of the project ahead of time.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Simon
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] [gdb] Remove unnecessary defs.h/common-defs.h includes
2026-04-21 19:53 ` Simon Marchi
@ 2026-04-21 21:28 ` Tom de Vries
0 siblings, 0 replies; 3+ messages in thread
From: Tom de Vries @ 2026-04-21 21:28 UTC (permalink / raw)
To: Simon Marchi, gdb-patches
On 4/21/26 9:53 PM, Simon Marchi wrote:
> On 4/21/26 3:40 PM, Tom de Vries wrote:
>> 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.
>
> Btw, this is the kind of details that we could put in an AGENTS.md file
> (or similar), if it doesn't offend too many people. AIs are much more
> efficient if they know the conventions of the project ahead of time.
I've opened a PR ( https://sourceware.org/bugzilla/show_bug.cgi?id=33951
) about adding an AGENTS.md file, with a similar idea.
Kevin added a comment about how that may not necessarily work well.
Thanks,
- Tom
> Approved-By: Simon Marchi <simon.marchi@efficios.com>
>
> Simon
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-04-21 21:29 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-04-21 19:40 [PATCH v2] [gdb] Remove unnecessary defs.h/common-defs.h includes Tom de Vries
2026-04-21 19:53 ` Simon Marchi
2026-04-21 21:28 ` Tom de Vries
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox