This is the mail archive of the gdb-cvs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] Error out immediatly when using if command without args in command list


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

commit 80a65e9b8fbc93d4a7548ac17b8094ced23f66a7
Author: Simon Marchi <simon.marchi@ericsson.com>
Date:   Mon Sep 4 19:13:08 2017 +0200

    Error out immediatly when using if command without args in command list
    
    When using "if" (or while) without args directly on gdb's command line,
    you get this:
    
      (gdb) if
      if/while commands require arguments
    
    When doing the same when entering a command list, you only get an error
    when the command is executed, when parse_exp_in_context_1 fails to
    evaluate the expression.
    
      (gdb) define foo
      Type commands for definition of "foo".
      End with a line saying just "end".
      >if
       >end
      >end
      (gdb) foo
      Argument required (expression to compute).
    
    I think it would make more sense to error out when inputting the command
    list directly:
    
      (gdb) define foo
      Type commands for definition of "foo".
      End with a line saying just "end".
      >if
      if/while commands require arguments.
    
    The only required change is to check whether args is an empty string in
    build_command_line.
    
    gdb/ChangeLog:
    
    	* cli/cli-script.c (build_command_line): For if/while commands,
    	check whether args is empty.
    
    gdb/testsuite/ChangeLog:
    
    	* gdb.base/commands.exp: Call new procedure.
    	(define_if_without_arg_test): New procedure.

Diff:
---
 gdb/ChangeLog                       |  5 +++++
 gdb/cli/cli-script.c                |  3 ++-
 gdb/testsuite/ChangeLog             |  5 +++++
 gdb/testsuite/gdb.base/commands.exp | 16 ++++++++++++++++
 4 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 0a1171a..39a47ec 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
 2017-09-04  Simon Marchi  <simon.marchi@ericsson.com>
 
+	* cli/cli-script.c (build_command_line): For if/while commands,
+	check whether args is empty.
+
+2017-09-04  Simon Marchi  <simon.marchi@ericsson.com>
+
 	* cli/cli-script.h (enum misc_command_type): Move from defs.h.
 	(enum command_control_type): Likewise.
 	(struct command_line): Likewise.
diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c
index 64b4c2b..1757e4e 100644
--- a/gdb/cli/cli-script.c
+++ b/gdb/cli/cli-script.c
@@ -147,7 +147,8 @@ build_command_line (enum command_control_type type, const char *args)
 {
   struct command_line *cmd;
 
-  if (args == NULL && (type == if_control || type == while_control))
+  if ((args == NULL || *args == '\0')
+      && (type == if_control || type == while_control))
     error (_("if/while commands require arguments."));
   gdb_assert (args != NULL);
 
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 5943b63..cfcb556 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2017-09-04  Simon Marchi  <simon.marchi@ericsson.com>
+
+	* gdb.base/commands.exp: Call new procedure.
+	(define_if_without_arg_test): New procedure.
+
 2017-09-04  Pedro Alves  <palves@redhat.com>
 
 	* gdb.base/list-ambiguous.exp: New file.
diff --git a/gdb/testsuite/gdb.base/commands.exp b/gdb/testsuite/gdb.base/commands.exp
index c934052..677361a 100644
--- a/gdb/testsuite/gdb.base/commands.exp
+++ b/gdb/testsuite/gdb.base/commands.exp
@@ -1011,6 +1011,21 @@ proc_with_prefix redefine_backtrace_test {} {
     gdb_test "bt" "hibob" "execute bt command"
 }
 
+# Test using "if" and "while" without args when building a command list.
+
+proc define_if_without_arg_test {} {
+    foreach cmd {if while} {
+	set test "define some_command_$cmd"
+	gdb_test_multiple $test $test {
+	    -re "End with"  {
+		pass $test
+	    }
+	}
+
+	gdb_test "$cmd" "if/while commands require arguments." "type $cmd without args"
+    }
+}
+
 # Test an input line split with a continuation character (backslash)
 # while entering a multi-line command (in a secondary prompt).
 
@@ -1076,5 +1091,6 @@ if_commands_test
 error_clears_commands_left
 redefine_hook_test
 backslash_in_multi_line_command_test
+define_if_without_arg_test
 # This one should come last, as it redefines "backtrace".
 redefine_backtrace_test


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]