From patchwork Sun Jun 23 15:41:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Waroquiers X-Patchwork-Id: 33280 Received: (qmail 76536 invoked by alias); 23 Jun 2019 15:41:26 -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 76527 invoked by uid 89); 23 Jun 2019 15:41:26 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.1 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=Define, logic, rfa, Limit X-HELO: mailsec110.isp.belgacom.be Received: from mailsec110.isp.belgacom.be (HELO mailsec110.isp.belgacom.be) (195.238.20.106) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 23 Jun 2019 15:41:23 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skynet.be; i=@skynet.be; q=dns/txt; s=securemail; t=1561304483; x=1592840483; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=L8sa6SNxcklGooz5rMIEP+UxjaTigJdHC0KEy1imaYI=; b=CABQrqv+F/i86w+Ywvq773K6bDrh42288TVi49ZwFa6/gkR1mQVvQihT DIOobqemY6eB8OXmzyF/WJ/it/hnew==; Received: from 96.218-128-109.adsl-dyn.isp.belgacom.be (HELO md.home) ([109.128.218.96]) by relay.skynet.be with ESMTP/TLS/DHE-RSA-AES128-GCM-SHA256; 23 Jun 2019 17:41:12 +0200 From: Philippe Waroquiers To: gdb-patches@sourceware.org Cc: Philippe Waroquiers Subject: [RFA] Fix alias command not detecting non matching prefix & sometimes asserting. Date: Sun, 23 Jun 2019 17:41:06 +0200 Message-Id: <20190623154106.13224-1-philippe.waroquiers@skynet.be> MIME-Version: 1.0 X-IsSubscribed: yes alias_command does not detect that the prefixes of the alias command and the aliased command are not matching: it is comparing the alias prefix with itself, instead of comparing it with the aliased command prefix. This causes either the alias command to silently do nothing, or to have GDB asserting: (gdb) alias assigne imprime limite-elements = set print elements ../../binutils-gdb/gdb/cli/cli-cmds.c:1552: internal-error: void alias_command(const char*, int): Assertion `c_command != NULL && c_command != (struct cmd_list_element *) -1' failed. A problem internal to GDB has been detected, Fix the logic, and update gdb.base/alias.exp to test these cases. gdb/ChangeLog 2019-06-23 Philippe Waroquiers * cli/cli-cmds.c (alias_command): Compare the alias prefix with the command prefix. gdb/testsuite/ChangeLog 2019-06-23 Philippe Waroquiers * gdb.base/alias.exp: Test non matching/non existing prefixes. --- gdb/cli/cli-cmds.c | 9 +++--- gdb/testsuite/gdb.base/alias.exp | 50 ++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 4 deletions(-) diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index 62f4d7f0c5..5124ab3f1b 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -1518,8 +1518,8 @@ alias_command (const char *args, int from_tty) Example: alias spe = set print elements Otherwise ALIAS and COMMAND must have the same number of words, - and every word except the last must match; and the last word of - ALIAS is made an alias of the last word of COMMAND. + and every word except the last must identify the same prefix command; + and the last word of ALIAS is made an alias of the last word of COMMAND. Example: alias set print elms = set pr elem Note that unambiguous abbreviations are allowed. */ @@ -1538,10 +1538,11 @@ alias_command (const char *args, int from_tty) error (_("Mismatched command length between ALIAS and COMMAND.")); /* Create copies of ALIAS and COMMAND without the last word, - and use that to verify the leading elements match. */ + and use that to verify the leading elements give the same + prefix command. */ std::string alias_prefix_string (argv_to_string (alias_argv, alias_argc - 1)); - std::string command_prefix_string (argv_to_string (alias_argv, + std::string command_prefix_string (argv_to_string (command_argv.get (), command_argc - 1)); alias_prefix = alias_prefix_string.c_str (); command_prefix = command_prefix_string.c_str (); diff --git a/gdb/testsuite/gdb.base/alias.exp b/gdb/testsuite/gdb.base/alias.exp index fe4eb44cd0..20722e5dea 100644 --- a/gdb/testsuite/gdb.base/alias.exp +++ b/gdb/testsuite/gdb.base/alias.exp @@ -66,3 +66,53 @@ gdb_test_no_output "alias set pr elms = set p elem" gdb_test_no_output "set pr elms 51" gdb_test "show print elements" "Limit .* is 51\[.\]" "verify set pr elms" gdb_test "help set print" "set print elms .*" + +# Verify alias command detects a non existing prefix. +gdb_test "alias assigne imprime limite-elements = set print elements" \ + "ALIAS and COMMAND prefixes do not match\." \ + "assigne imprime prefix not defined" + +gdb_test "alias set imprime limite-elements = set print elements" \ + "ALIAS and COMMAND prefixes do not match\." \ + "set imprime prefix not defined" + +# Verify alias command detects a non matching prefix. +gdb_test "alias set ada limite-elements = set print elements" \ + "ALIAS and COMMAND prefixes do not match\." \ + "mismatched prefix" + +# Verify alias command detects a non matching prefix due to length. +gdb_test "alias set imprime-limite-elements = set print elements" \ + "Mismatched command length between ALIAS and COMMAND\." \ + "mismatched length" + + +# Gradually define the prefixes and the limite-elements command. +gdb_test_no_output "alias assigne = set" "alias assigne" +gdb_test_no_output "alias assigne imprime = set print" "alias assigne imprime" +gdb_test_no_output "alias assigne imprime limite-elements = set print elements" \ + "alias assigne imprime limite-elements" + +# Define an alias using the command prefix with a command using an alias prefix. +gdb_test_no_output "alias set print max-elements = assigne imprime elements" \ + "alias set print max-elements using assigne imprime" + + +# Tests the resulting prefixes and commands. +gdb_test_no_output "assigne print elements 52" +gdb_test "show print elements" "Limit .* is 52\[.\]" "verify 52" + +gdb_test_no_output "assigne imprime elements 53" +gdb_test "show print elements" "Limit .* is 53\[.\]" "verify 53" + +gdb_test_no_output "assigne imprime limite-elements 54" +gdb_test "show print elements" "Limit .* is 54\[.\]" "verify 54" + +gdb_test_no_output "set imprime elements 55" +gdb_test "show print elements" "Limit .* is 55\[.\]" "verify 55" + +gdb_test_no_output "set print limite-elements 56" +gdb_test "show print elements" "Limit .* is 56\[.\]" "verify 56" + +gdb_test_no_output "set print max-elements 57" +gdb_test "show print elements" "Limit .* is 57\[.\]" "verify 57"