public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Fix alias command not detecting non matching prefix & sometimes asserting.
@ 2019-06-25 17:36 Philippe Waroquiers
  0 siblings, 0 replies; only message in thread
From: Philippe Waroquiers @ 2019-06-25 17:36 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=b65b566cdcb577edb57616c5b49a2f245b56325c

commit b65b566cdcb577edb57616c5b49a2f245b56325c
Author: Philippe Waroquiers <philippe.waroquiers@skynet.be>
Date:   Sun Jun 23 15:34:15 2019 +0200

    Fix alias command not detecting non matching prefix & sometimes asserting.
    
    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-25  Philippe Waroquiers  <philippe.waroquiers@skynet.be>
    
    	* cli/cli-cmds.c (alias_command): Compare the alias prefix
    	with the command prefix.
    
    gdb/testsuite/ChangeLog
    2019-06-25  Philippe Waroquiers  <philippe.waroquiers@skynet.be>
    
    	* gdb.base/alias.exp: Test non matching/non existing prefixes.

Diff:
---
 gdb/ChangeLog                    |  5 ++++
 gdb/cli/cli-cmds.c               |  9 ++++----
 gdb/testsuite/ChangeLog          |  4 ++++
 gdb/testsuite/gdb.base/alias.exp | 50 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 64 insertions(+), 4 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index ff05c1c..64656d6 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2019-06-25  Philippe Waroquiers  <philippe.waroquiers@skynet.be>
+
+	* cli/cli-cmds.c (alias_command): Compare the alias prefix
+	with the command prefix.
+
 2019-06-25  Tom Tromey  <tom@tromey.com>
 
 	* tui/tui-wingeneral.c (tui_delete_win): Remove "return".
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index 62f4d7f..5124ab3 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/ChangeLog b/gdb/testsuite/ChangeLog
index f0e05d3..8410a09 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2019-06-23  Philippe Waroquiers  <philippe.waroquiers@skynet.be>
+
+	* gdb.base/alias.exp: Test non matching/non existing prefixes.
+
 2019-06-25  Tom de Vries  <tdevries@suse.de>
 
 	PR testsuite/24727
diff --git a/gdb/testsuite/gdb.base/alias.exp b/gdb/testsuite/gdb.base/alias.exp
index fe4eb44..20722e5 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"


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-06-25 17:36 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-25 17:36 [binutils-gdb] Fix alias command not detecting non matching prefix & sometimes asserting Philippe Waroquiers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).