aboutsummaryrefslogtreecommitdiff
path: root/gdb/cli/cli-decode.c
diff options
context:
space:
mode:
authorDoug Evans <dje@google.com>2011-10-09 22:21:43 +0000
committerDoug Evans <dje@google.com>2011-10-09 22:21:43 +0000
commit5a56e9c5e9a817598264d329c0f7936982683cf3 (patch)
treeb098197d8cf4b75931db58241388806c7ed8be9e /gdb/cli/cli-decode.c
parent509f0fd9410d9394d0a6e2fa4ef80e08de5598b5 (diff)
downloadbinutils-5a56e9c5e9a817598264d329c0f7936982683cf3.zip
binutils-5a56e9c5e9a817598264d329c0f7936982683cf3.tar.gz
binutils-5a56e9c5e9a817598264d329c0f7936982683cf3.tar.bz2
Add new "alias" command.
* NEWS: Mention new command. * command.h (valid_user_defined_cmd_name_p): Declare. * defs.h (make_cleanup_dyn_string_delete): Declare. * utils.c: #include "dyn-string.h". (do_dyn_string_delete, make_cleanup_dyn_string_delete): New functions. * cli/cli-cmds.c: #include "dyn-string.h". (argv_to_dyn_string, valid_command_p, alias_command): New functions. (init_cli_cmds): Add new command. * cli/cli-decode.c (valid_user_defined_cmd_name_p): New function. doc/ * gdb.texinfo (Extending GDB): Document alias command. testsuite/ * gdb.base/alias.exp: Add tests for alias command.
Diffstat (limited to 'gdb/cli/cli-decode.c')
-rw-r--r--gdb/cli/cli-decode.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c
index 95996e8..0870782 100644
--- a/gdb/cli/cli-decode.c
+++ b/gdb/cli/cli-decode.c
@@ -126,7 +126,6 @@ set_cmd_completer (struct cmd_list_element *cmd,
cmd->completer = completer; /* Ok. */
}
-
/* Add element named NAME.
Space for NAME and DOC must be allocated by the caller.
CLASS is the top level category into which commands are broken down
@@ -1138,6 +1137,34 @@ find_command_name_length (const char *text)
return p - text;
}
+/* Return TRUE if NAME is a valid user-defined command name.
+ This is a stricter subset of all gdb commands,
+ see find_command_name_length. */
+
+int
+valid_user_defined_cmd_name_p (const char *name)
+{
+ const char *p;
+
+ if (*name == '\0')
+ return FALSE;
+
+ /* Alas "42" is a legitimate user-defined command.
+ In the interests of not breaking anything we preserve that. */
+
+ for (p = name; *p != '\0'; ++p)
+ {
+ if (isalnum (*p)
+ || *p == '-'
+ || *p == '_')
+ ; /* Ok. */
+ else
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
/* This routine takes a line of TEXT and a CLIST in which to start the
lookup. When it returns it will have incremented the text pointer past
the section of text it matched, set *RESULT_LIST to point to the list in