From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH 1/3] Use string_view in cli-decode.c:find_cmd
Date: Thu, 22 Jan 2026 13:49:11 -0700 [thread overview]
Message-ID: <20260122-command-no-alloca-v1-1-402aa429bbbf@adacore.com> (raw)
In-Reply-To: <20260122-command-no-alloca-v1-0-402aa429bbbf@adacore.com>
This changes cli-decode.c:find_cmd to use std::string_view. I've made
this a separate patch to make the next patch more obvious.
---
gdb/cli/cli-decode.c | 17 ++++++-----------
1 file changed, 6 insertions(+), 11 deletions(-)
diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c
index 04935575b67..c9bd610a3ac 100644
--- a/gdb/cli/cli-decode.c
+++ b/gdb/cli/cli-decode.c
@@ -34,12 +34,6 @@ static cmd_list_element::aliases_list_type delete_cmd
cmd_list_element **prehookee, cmd_list_element **posthook,
cmd_list_element **posthookee);
-static struct cmd_list_element *find_cmd (const char *command,
- int len,
- struct cmd_list_element *clist,
- int ignore_help_classes,
- int *nfound);
-
static void help_cmd_list (struct cmd_list_element *list,
command_classes theclass,
bool recurse,
@@ -2174,7 +2168,7 @@ help_cmd_list (struct cmd_list_element *list, command_classes theclass,
found in nfound. */
static struct cmd_list_element *
-find_cmd (const char *command, int len, struct cmd_list_element *clist,
+find_cmd (std::string_view command, struct cmd_list_element *clist,
int ignore_help_classes, int *nfound)
{
struct cmd_list_element *found, *c;
@@ -2182,12 +2176,12 @@ find_cmd (const char *command, int len, struct cmd_list_element *clist,
found = NULL;
*nfound = 0;
for (c = clist; c; c = c->next)
- if (!strncmp (command, c->name, len)
+ if (startswith (c->name, command)
&& (!ignore_help_classes || !c->is_command_class_help ()))
{
found = c;
(*nfound)++;
- if (c->name[len] == '\0')
+ if (c->name[command.size ()] == '\0')
{
*nfound = 1;
break;
@@ -2290,7 +2284,8 @@ lookup_cmd_1 (const char **text, struct cmd_list_element *clist,
/* Look it up. */
found = 0;
nfound = 0;
- found = find_cmd (command, len, clist, ignore_help_classes, &nfound);
+ found = find_cmd (std::string_view (command, len),
+ clist, ignore_help_classes, &nfound);
/* If nothing matches, we have a simple failure. */
if (nfound == 0)
@@ -2676,7 +2671,7 @@ lookup_cmd_composition_1 (const char *text,
/* Look it up. */
int nfound = 0;
- *cmd = find_cmd (command.c_str (), len, cur_list, 1, &nfound);
+ *cmd = find_cmd (command, cur_list, 1, &nfound);
/* We only handle the case where a single command was found. */
if (nfound > 1)
--
2.52.0
next prev parent reply other threads:[~2026-01-22 20:50 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-22 20:49 [PATCH 0/3] Remove some uses of alloca from cli/ Tom Tromey
2026-01-22 20:49 ` Tom Tromey [this message]
2026-01-22 20:49 ` [PATCH 2/3] Don't make copies when calling find_cmd Tom Tromey
2026-01-22 20:49 ` [PATCH 3/3] Remove alloca from lookup_cmd Tom Tromey
2026-01-29 19:07 ` [PATCH 0/3] Remove some uses of alloca from cli/ Kevin Buettner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260122-command-no-alloca-v1-1-402aa429bbbf@adacore.com \
--to=tromey@adacore.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox