* [PATCH] [gdb] Remove unnecessary defs.h/common-defs.h includes
@ 2026-04-21 16:24 Tom de Vries
2026-04-21 17:09 ` Simon Marchi
0 siblings, 1 reply; 3+ messages in thread
From: Tom de Vries @ 2026-04-21 16:24 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.
Tested by rebuilding gdb on aarch64-linux.
---
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 -
gdbsupport/common-defs.h | 2 ++
gdbsupport/remote-args.cc | 1 -
9 files changed, 4 insertions(+), 7 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..5070d04adae 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 twice
#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/gdbsupport/common-defs.h b/gdbsupport/common-defs.h
index f181044f383..da94e38c60f 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 twice
#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] [gdb] Remove unnecessary defs.h/common-defs.h includes
2026-04-21 16:24 [PATCH] [gdb] Remove unnecessary defs.h/common-defs.h includes Tom de Vries
@ 2026-04-21 17:09 ` Simon Marchi
2026-04-21 19:44 ` Tom de Vries
0 siblings, 1 reply; 3+ messages in thread
From: Simon Marchi @ 2026-04-21 17:09 UTC (permalink / raw)
To: Tom de Vries, gdb-patches
On 4/21/26 12:24 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.
>
> 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.
>
> Tested by rebuilding gdb on aarch64-linux.
server.h in gdbserver is the same idea. I see one include in
linux-microblaze-low.cc that should be removed.
I would suggest changing the error message to something clearer and more
actionable for those who might not know the backstory of these files,
perhaps:
# error gdb/defs.h should not be included manually
Simon
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] [gdb] Remove unnecessary defs.h/common-defs.h includes
2026-04-21 17:09 ` Simon Marchi
@ 2026-04-21 19:44 ` Tom de Vries
0 siblings, 0 replies; 3+ messages in thread
From: Tom de Vries @ 2026-04-21 19:44 UTC (permalink / raw)
To: Simon Marchi, gdb-patches
On 4/21/26 7:09 PM, Simon Marchi wrote:
> On 4/21/26 12:24 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.
>>
>> 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.
>>
>> Tested by rebuilding gdb on aarch64-linux.
>
> server.h in gdbserver is the same idea. I see one include in
> linux-microblaze-low.cc that should be removed.
>
Ack, added in a v2 (
https://sourceware.org/pipermail/gdb-patches/2026-April/226697.html ).
> I would suggest changing the error message to something clearer and more
> actionable for those who might not know the backstory of these files,
> perhaps:
>
> # error gdb/defs.h should not be included manually
Also done in v2.
Thanks,
- Tom
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-04-21 19:45 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-04-21 16:24 [PATCH] [gdb] Remove unnecessary defs.h/common-defs.h includes Tom de Vries
2026-04-21 17:09 ` Simon Marchi
2026-04-21 19:44 ` 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