[PATCH 2/2] gdb: add warning when no native target is available

Guinevere Larsen
2025-11-06T19:48:56Z

When a user starts GDB, they have no way of knowing if native debugging
will be supported or not. This is most relevant for Mac users, since
GDB hasn't been ported to Apple's CPUs yet.

This patch adds a warning if, after initializing all files, GDB was
unable to find an appropriate native target for the session, informing
the user that they will only be able to debug remotely.
---
gdb/main.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/gdb/main.c b/gdb/main.c
index 58a744bb2b7..1aa6e85d1d7 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -1211,6 +1211,11 @@ captured_main_1 (struct captured_main_args *context)
tmp_warn_preprint.reset ();
warning_pre_print = "\n";

+ if (get_native_target () == nullptr)
+ warning (_("No native target, only remote debugging is supported.\n"
+ "Use \"%ps\" to check which architectures are supported."),
+ styled_string (command_style.style (), "info architecture"));
+
/* Read and execute the system-wide gdbinit file, if it exists.
This is done *before* all the command line arguments are
processed; it sets global parameters, which are independent of
--
2.51.0