From be09caf15d3d57da2173d26abdb0bf92ef90f28f Mon Sep 17 00:00:00 2001 From: Philippe Waroquiers Date: Sun, 8 Sep 2019 21:54:18 +0200 Subject: Allow . character as part of command names. This patch adds . as an allowed character for user defined commands. Combined with 'define-prefix', this allows to e.g. define a set of Valgrind specific user command corresponding to the Valgrind monitor commands (such as check_memory, v.info, v.set, ...). gdb/ChangeLog 2019-11-30 Philippe Waroquiers * command.h (valid_cmd_char_p): Declare. * cli/cli-decode.c (valid_cmd_char_p): New function factorizing the check of valid command char. (find_command_name_length, valid_user_defined_cmd_name_p): Use valid_cmd_char_p. * cli/cli-script.c (validate_comname): Likewise. * completer.c (gdb_completer_command_word_break_characters): Do not remove . from the word break char, update comments. (complete_line_internal_1): Use valid_cmd_char_p. * guile/scm-cmd.c (gdbscm_parse_command_name): Likewise. * python/py-cmd.c (gdbpy_parse_command_name): Likewise. gdb/testsuite/ChangeLog 2019-11-30 Philippe Waroquiers * gdb.base/define.exp: Test . in command names. * gdb.base/setshow.exp: Update test, as . is now part of command name. --- gdb/cli/cli-decode.c | 24 ++++++++++++++---------- gdb/cli/cli-script.c | 2 +- 2 files changed, 15 insertions(+), 11 deletions(-) (limited to 'gdb/cli') diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c index 7ace72f..307fd1e 100644 --- a/gdb/cli/cli-decode.c +++ b/gdb/cli/cli-decode.c @@ -1372,7 +1372,7 @@ find_command_name_length (const char *text) if (*p == '!' || *p == '|') return 1; - while (isalnum (*p) || *p == '-' || *p == '_' + while (valid_cmd_char_p (*p) /* Characters used by TUI specific commands. */ || *p == '+' || *p == '<' || *p == '>' || *p == '$') p++; @@ -1380,9 +1380,18 @@ 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. */ +/* See command.h. */ + +bool +valid_cmd_char_p (int c) +{ + /* Alas "42" is a legitimate user-defined command. + In the interests of not breaking anything we preserve that. */ + + return isalnum (c) || c == '-' || c == '_' || c == '.'; +} + +/* See command.h. */ bool valid_user_defined_cmd_name_p (const char *name) @@ -1392,14 +1401,9 @@ valid_user_defined_cmd_name_p (const char *name) 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 == '_') + if (valid_cmd_char_p (*p)) ; /* Ok. */ else return false; diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c index 55dcb34..10824a3 100644 --- a/gdb/cli/cli-script.c +++ b/gdb/cli/cli-script.c @@ -1342,7 +1342,7 @@ validate_comname (const char **comname) p = *comname; while (*p) { - if (!isalnum (*p) && *p != '-' && *p != '_') + if (!valid_cmd_char_p (*p)) error (_("Junk in argument list: \"%s\""), p); p++; } -- cgit v1.1