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] gdb: 'list' command, tweak handling of +/- arguments.


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

commit a0def019aaf79adf3add2a0559ab75bb84d72085
Author: Andrew Burgess <andrew.burgess@embecosm.com>
Date:   Mon Nov 16 09:33:32 2015 +0000

    gdb: 'list' command, tweak handling of +/- arguments.
    
    There is an inconsistency with the handling of the special +/- arguments
    to the list command.
    
    For the very first time that list is used (after the inferior has
    changed locations) then only the first character of the argument string
    is checked, so 'list +BLAH' will operate as 'list +' and 'list -----FOO'
    will operate as 'list -'.  This compares to each subsequent use of list,
    where the whole argument string is checked, so 'list +BLAH' will try to
    list lines of code around the function '+BLAH'.
    
    This commit unifies the behaviour so that the whole argument string is
    checked, in order to list the next 10, or previous 10 lines from a file
    only 'list +' and 'list -' are now valid.
    
    gdb/ChangeLog:
    
    	* cli/cli-cmds.c (list_command): Check that the argument string is
    	a single character, either '+' or '-'.
    
    gdb/testsuite/ChangeLog:
    
    	* gdb.base/list.exp (test_list_invalid_args): New function,
    	defined, and called.

Diff:
---
 gdb/ChangeLog                   |  5 +++++
 gdb/cli/cli-cmds.c              |  6 +++---
 gdb/testsuite/ChangeLog         |  5 +++++
 gdb/testsuite/gdb.base/list.exp | 19 +++++++++++++++++++
 4 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 17db0c3..970bea2 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
 2015-12-11  Andrew Burgess  <andrew.burgess@embecosm.com>
 
+	* cli/cli-cmds.c (list_command): Check that the argument string is
+	a single character, either '+' or '-'.
+
+2015-12-11  Andrew Burgess  <andrew.burgess@embecosm.com>
+
 	* cli/cli-cmds.c (list_command): Move all handling of +/-
 	arguments into a single if block.
 
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index 872c844..4557bfd 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -907,7 +907,7 @@ list_command (char *arg, int from_tty)
   cleanup = make_cleanup (null_cleanup, NULL);
 
   /* Pull in the current default source line if necessary.  */
-  if (arg == NULL || arg[0] == '+' || arg[0] == '-')
+  if (arg == NULL || ((arg[0] == '+' || arg[0] == '-') && arg[1] == '\0'))
     {
       set_default_source_symtab_and_line ();
       cursal = get_current_source_symtab_and_line ();
@@ -933,13 +933,13 @@ list_command (char *arg, int from_tty)
 	}
 
       /* "l" or "l +" lists next ten lines.  */
-      else if (arg == NULL || strcmp (arg, "+") == 0)
+      else if (arg == NULL || arg[0] == '+')
 	print_source_lines (cursal.symtab, cursal.line,
 			    cursal.line + get_lines_to_list (), 0);
 
       /* "l -" lists previous ten lines, the ones before the ten just
 	 listed.  */
-      else if (strcmp (arg, "-") == 0)
+      else if (arg[0] == '-')
 	print_source_lines (cursal.symtab,
 			    max (get_first_line_listed ()
 				 - get_lines_to_list (), 1),
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index b1902e0..8c7af55 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,5 +1,10 @@
 2015-12-11  Andrew Burgess  <andrew.burgess@embecosm.com>
 
+	* gdb.base/list.exp (test_list_invalid_args): New function,
+	defined, and called.
+
+2015-12-11  Andrew Burgess  <andrew.burgess@embecosm.com>
+
 	* gdb.base/list.exp (test_list): Make test names unique.
 
 2015-12-11  Yao Qi  <yao.qi@linaro.org>
diff --git a/gdb/testsuite/gdb.base/list.exp b/gdb/testsuite/gdb.base/list.exp
index 84ae251..cac3a62 100644
--- a/gdb/testsuite/gdb.base/list.exp
+++ b/gdb/testsuite/gdb.base/list.exp
@@ -505,6 +505,24 @@ proc test_only_end {} {
     gdb_test "list ,5" "list ,5\r\n4\[ \t\]\[^\r\n\]*\r\n5\[ \t\]\[^\r\n\]*"
 }
 
+proc test_list_invalid_args {} {
+    global binfile
+
+    clean_restart ${binfile}
+    gdb_test "list -INVALID" \
+	"invalid explicit location argument, \"-INVALID\"" \
+	"first use of \"list -INVALID\""
+    gdb_test "list -INVALID" \
+	"invalid explicit location argument, \"-INVALID\"" \
+	"second use of \"list -INVALID\""
+
+    clean_restart ${binfile}
+    gdb_test "list +INVALID" "Function \"\\+INVALID\" not defined." \
+	"first use of \"list +INVALID\""
+    gdb_test "list +INVALID" "Function \"\\+INVALID\" not defined." \
+	"second use of \"list +INVALID\""
+}
+
 # Start with a fresh gdb.
 
 gdb_exit
@@ -527,6 +545,7 @@ if [ set_listsize 10 ] then {
     test_list_filename_and_function
     test_forward_search
     test_only_end
+    test_list_invalid_args
 }
 
 # Follows tests that require execution.


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