[PATCH 1/2] gdb: introduce command "info architecture"

Guinevere Larsen
2025-11-06T19:47:22Z

There is no convenient way to tell a user how to check which
architectures are supported by their build of GDB. This hasn't really
been a problem, but now that GDB isn't ported to Apple's new CPU
architectures, a user could run into a situation where they're trying to
debug an unsupported CPU.

This commit adds a way to list supported architectures, and filter them
using a regular expression. No test is added because I couldn't think
of a good way to verify functionality when we can't control the
configure line.
---
gdb/NEWS | 4 ++++
gdb/arch-utils.c | 28 ++++++++++++++++++++++++++++
gdb/doc/gdb.texinfo | 5 +++++
3 files changed, 37 insertions(+)

diff --git a/gdb/NEWS b/gdb/NEWS
index 64e35f1a438..8d87e2473f7 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -45,6 +45,10 @@ maintenance test-remote-args ARGS
Test splitting and joining of inferior arguments ARGS as they would
be split and joined when being passed to a remote target.

+info architectures [REGEXP]
+ List CPU microarchitectures supported by this build of GDB. If
+ REGEXP is provided, filter to microarchitectures that match it.
+
* Changed commands

maintenance info program-spaces
diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c
index 8e3f79089d4..4367e26c02b 100644
--- a/gdb/arch-utils.c
+++ b/gdb/arch-utils.c
@@ -682,6 +682,28 @@ static enum bfd_endian default_byte_order = BFD_ENDIAN_UNKNOWN;
"set arch" command. */
static std::vector<const char *> arches;

+/* Implementation of "info architectures" command. */
+
+static void
+info_architectures_command (const char *args, int from_tty)
+{
+ bool filtered = false;
+ if (args != nullptr && args[0] != '\0')
+ {
+ char *re_err = re_comp (args);
+ if (re_err != nullptr)
+ error (_("Invalid regexp: %s"), re_err);
+ filtered = true;
+ }
+ for (const char *s : arches)
+ {
+ if (s == nullptr)
+ break;
+ if (!filtered || re_exec (s))
+ gdb_printf ("%s\n", s);
+ }
+}
+
void
initialize_current_architecture (void)
{
@@ -767,6 +789,12 @@ initialize_current_architecture (void)
&setlist, &showlist);
add_alias_cmd ("processor", architecture_cmds.set, class_support, 1,
&setlist);
+ add_info ("architectures", info_architectures_command,
+ _("List supported CPU microarchitectures.\n\
+\n\
+Usage: info architectures [REGEXP]\n\
+If REGEXP is supplied, list supported microarchitectures that match the\n\
+regular expresion. Otherwise list all supported microarchitectures."));
}
}

diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 854f22b612e..a4576ca3703 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -23428,6 +23428,11 @@ Show the current target architecture.
@kindex show processor
These are alias commands for, respectively, @code{set architecture}
and @code{show architecture}.
+
+@item info architectures
+@item info architectures @var{regexp}
+List architectures supported by GDB. If @var{regexp} is provided, filter
+results through the regular expression, otherwise list all architectures.
@end table

@menu
--
2.51.0