From patchwork Tue Nov 26 23:34:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Waroquiers X-Patchwork-Id: 36289 Received: (qmail 32134 invoked by alias); 26 Nov 2019 23:34:42 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 32077 invoked by uid 89); 26 Nov 2019 23:34:42 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.1 spammy=supplies, completing X-HELO: mailsec117.isp.belgacom.be Received: from mailsec117.isp.belgacom.be (HELO mailsec117.isp.belgacom.be) (195.238.20.113) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 26 Nov 2019 23:34:39 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skynet.be; i=@skynet.be; q=dns/txt; s=securemail; t=1574811279; x=1606347279; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7zkKoFXk11SwYbvLMJNjfgFzOYLHQAe0peRNLKrl+64=; b=XfKqbQNjIf84UGKb0kVaQfHQhZlqkOfCQxlcvLQ3vFvk7jfRErPAky0z RhzzCMVRYxHtqeN1WeAXD57Cs0Gh+w==; IronPort-SDR: XAF2KZg8kUuiW4ATiwbsQdW1GYcj9B5H4+T6FMTaTEdD0XMIqkcL5cJmxL132jayDQph4R6OWs cn18zyAH0WdtssKddASk2dDxtnjstMhkhqRikfqPh6WEpiej90la6Ytn7bOq9R6ZYmLPy0jOWi RrdKVN/P98wV+QvU+Fsb8f6Yvo8H0mcqqqCk5orgJj+XMUaqFVASdUF+J36uKQUrM7/RnBBwBI /gJauN1hSw1kjos6H9IiN9d60ULq1VK32UO3G6/DMyIxctWEeAfoDD/hLtdTrwmHH/Ym/yXhpL FmA= Received: from 136.173-134-109.adsl-dyn.isp.belgacom.be (HELO md.home) ([109.134.173.136]) by relay.skynet.be with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 27 Nov 2019 00:34:30 +0100 From: Philippe Waroquiers To: gdb-patches@sourceware.org Cc: Philippe Waroquiers Subject: [RFAv2 3/4] Allow . character as part of command names. Date: Wed, 27 Nov 2019 00:34:22 +0100 Message-Id: <20191126233423.14801-4-philippe.waroquiers@skynet.be> In-Reply-To: <20191126233423.14801-1-philippe.waroquiers@skynet.be> References: <20191126233423.14801-1-philippe.waroquiers@skynet.be> MIME-Version: 1.0 X-IsSubscribed: yes 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 YYYY-MM-DD 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 YYYY-MM-DD 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 +- gdb/command.h | 8 ++++++++ gdb/completer.c | 10 +++++----- gdb/guile/scm-cmd.c | 5 +---- gdb/python/py-cmd.c | 5 +---- gdb/testsuite/gdb.base/define.exp | 25 +++++++++++++++++++++++++ gdb/testsuite/gdb.base/setshow.exp | 2 +- 8 files changed, 56 insertions(+), 25 deletions(-) diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c index 7ace72fb7e..307fd1e826 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 e0463cb5b7..79c499a4c2 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++; } diff --git a/gdb/command.h b/gdb/command.h index cf190ef649..5384a0a674 100644 --- a/gdb/command.h +++ b/gdb/command.h @@ -133,8 +133,16 @@ extern struct cli_suppress_notification cli_suppress_notification; /* API to the manipulation of command lists. */ +/* 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. */ + extern bool valid_user_defined_cmd_name_p (const char *name); +/* Return TRUE if C is a valid command character. */ + +extern bool valid_cmd_char_p (int c); + /* Const-correct variant of the above. */ extern struct cmd_list_element *add_cmd (const char *, enum command_class, diff --git a/gdb/completer.c b/gdb/completer.c index b34b7762c6..6658da6d7f 100644 --- a/gdb/completer.c +++ b/gdb/completer.c @@ -102,13 +102,13 @@ enum explicit_location_match_type /* Variables which are necessary for fancy command line editing. */ -/* When completing on command names, we remove '-' from the list of +/* When completing on command names, we remove '-' and '.' from the list of word break characters, since we use it in command names. If the readline library sees one in any of the current completion strings, it thinks that the string needs to be quoted and automatically supplies a leading quote. */ static const char gdb_completer_command_word_break_characters[] = -" \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,"; +" \t\n!@#$%^&*()+=|~`}{[]\"';:?/><,"; /* When completing on file names, we remove from the list of word break characters any characters that are commonly used in file @@ -1284,7 +1284,7 @@ complete_line_internal_1 (completion_tracker &tracker, on command strings (as opposed to strings supplied by the individual command completer functions, which can be any string) then we will switch to the special word break set for command - strings, which leaves out the '-' character used in some + strings, which leaves out the '-' and '.' character used in some commands. */ set_rl_completer_word_break_characters (current_language->la_word_break_characters()); @@ -1347,7 +1347,7 @@ complete_line_internal_1 (completion_tracker &tracker, /* lookup_cmd_1 advances p up to the first ambiguous thing, but doesn't advance over that thing itself. Do so now. */ q = p; - while (*q && (isalnum (*q) || *q == '-' || *q == '_')) + while (valid_cmd_char_p (*q)) ++q; if (q != tmp_command + point) { @@ -1435,7 +1435,7 @@ complete_line_internal_1 (completion_tracker &tracker, q = p; while (q > tmp_command) { - if (isalnum (q[-1]) || q[-1] == '-' || q[-1] == '_') + if (valid_cmd_char_p (q[-1])) --q; else break; diff --git a/gdb/guile/scm-cmd.c b/gdb/guile/scm-cmd.c index f2fa40e453..3b8195b8b4 100644 --- a/gdb/guile/scm-cmd.c +++ b/gdb/guile/scm-cmd.c @@ -492,10 +492,7 @@ gdbscm_parse_command_name (const char *name, lastchar = i; /* Find first character of the final word. */ - for (; i > 0 && (isalnum (name[i - 1]) - || name[i - 1] == '-' - || name[i - 1] == '_'); - --i) + for (; i > 0 && valid_cmd_char_p (name[i - 1]); --i) ; result = (char *) xmalloc (lastchar - i + 2); memcpy (result, &name[i], lastchar - i + 1); diff --git a/gdb/python/py-cmd.c b/gdb/python/py-cmd.c index 38973401a8..8d6f01b78f 100644 --- a/gdb/python/py-cmd.c +++ b/gdb/python/py-cmd.c @@ -372,10 +372,7 @@ gdbpy_parse_command_name (const char *name, lastchar = i; /* Find first character of the final word. */ - for (; i > 0 && (isalnum (name[i - 1]) - || name[i - 1] == '-' - || name[i - 1] == '_'); - --i) + for (; i > 0 && valid_cmd_char_p (name[i - 1]); --i) ; result = (char *) xmalloc (lastchar - i + 2); memcpy (result, &name[i], lastchar - i + 1); diff --git a/gdb/testsuite/gdb.base/define.exp b/gdb/testsuite/gdb.base/define.exp index d7d4fd03ba..b5183eceec 100644 --- a/gdb/testsuite/gdb.base/define.exp +++ b/gdb/testsuite/gdb.base/define.exp @@ -130,6 +130,31 @@ gdb_test "help nextwhere" \ " A next command that first shows you where you're stepping from.*" \ "preserve whitespace in help string" +# Verify that GDB allows a user to use . in a command name. +# +gdb_test_multiple "define dot.command" "define user command: dot.command" { + -re "Type commands for definition of \"dot.command\".\r\nEnd with a line saying just \"end\".\r\n>$" { + gdb_test "echo dot command\\n\nend" "" \ + "define user command: dot.command" + } +} + +# Verify that dot.command works. +# +gdb_test "dot.command" \ + "dot command" \ + "full name dot.command" +gdb_test "dot" \ + "dot command" \ + "partial name dot" +gdb_test "dot." \ + "dot command" \ + "partial name dot." +gdb_test "dot.c" \ + "dot command" \ + "partial name dot.c" + + # Verify that the command parser doesn't require a space after an 'if' # command in a user defined function. # diff --git a/gdb/testsuite/gdb.base/setshow.exp b/gdb/testsuite/gdb.base/setshow.exp index 717bcc3270..394967babf 100644 --- a/gdb/testsuite/gdb.base/setshow.exp +++ b/gdb/testsuite/gdb.base/setshow.exp @@ -355,7 +355,7 @@ gdb_test_no_output "set verbose off" "set verbose off" gdb_test "show verbose" "Verbosity is off..*" "show verbose (off)" #test argument must be preceded by space foreach x {"history file" "solib-search-path" "data-directory"} { - foreach y {"/home/" "." "~/home" "=home"} { + foreach y {"/home/" "~/home" "=home"} { gdb_test "set $x$y" "Argument must be preceded by space." \ "$x is not set to $y" }