public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Burgess <andrew.burgess@embecosm.com>
To: gdb-patches@sourceware.org
Cc: Andrew Burgess <andrew.burgess@embecosm.com>
Subject: [PATCH 5/7] gdb: 'list' command, tweak handling of +/- arguments.
Date: Wed, 25 Nov 2015 00:34:00 -0000	[thread overview]
Message-ID: <0af61eb3baed9334e8dc0aae2b572d87e2807fa8.1448411122.git.andrew.burgess@embecosm.com> (raw)
In-Reply-To: <cover.1448411121.git.andrew.burgess@embecosm.com>
In-Reply-To: <cover.1448411121.git.andrew.burgess@embecosm.com>

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.
---
 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 a19ed49..4099267 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
 2015-11-24  Andrew Burgess  <andrew.burgess@embecosm.com>
 
+	* cli/cli-cmds.c (list_command): Check that the argument string is
+	a single character, either '+' or '-'.
+
+2015-11-24  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 c47526f..be84f81 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 ();
@@ -935,7 +935,7 @@ list_command (char *arg, int from_tty)
 
       /* "l" or "l +" lists next ten lines.  */
 
-      if (arg == NULL || strcmp (arg, "+") == 0)
+      if (arg == NULL || arg[0] == '+')
 	{
 	  print_source_lines (cursal.symtab, cursal.line,
 			      cursal.line + get_lines_to_list (), 0);
@@ -944,7 +944,7 @@ list_command (char *arg, int from_tty)
 
       /* "l -" lists previous ten lines, the ones before the ten just
 	 listed.  */
-      if (strcmp (arg, "-") == 0)
+      if (arg[0] == '-')
 	{
 	  print_source_lines (cursal.symtab,
 			      max (get_first_line_listed ()
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 60bd923..009044c 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,5 +1,10 @@
 2015-11-24  Andrew Burgess  <andrew.burgess@embecosm.com>
 
+	* gdb.base/list.exp (test_list_invalid_args): New function,
+	defined, and called.
+
+2015-11-24  Andrew Burgess  <andrew.burgess@embecosm.com>
+
 	* gdb.base/list.exp (test_list): Make test names unique.
 
 2015-11-23  Simon Marchi  <simon.marchi@ericsson.com>
diff --git a/gdb/testsuite/gdb.base/list.exp b/gdb/testsuite/gdb.base/list.exp
index 84ae251..1b9d4e6 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.
-- 
2.5.1

  parent reply	other threads:[~2015-11-25  0:34 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-25  0:34 [PATCH 0/7] Minor changes to 'list' command Andrew Burgess
2015-11-25  0:34 ` [PATCH 2/7] gdb: Use NULL instead of 0 for pointer comparison Andrew Burgess
2015-11-26 12:37   ` Pedro Alves
2015-11-25  0:34 ` [PATCH 6/7] gdb: Add an error when 'list -' reaches the start of a file Andrew Burgess
2015-11-26 12:38   ` Pedro Alves
2015-11-25  0:34 ` [PATCH 7/7] gdb: Extend help text for 'list' command Andrew Burgess
2015-11-26 12:38   ` Pedro Alves
2015-12-10 10:08     ` Andrew Burgess
2015-12-10 16:24       ` Eli Zaretskii
2015-11-25  0:34 ` Andrew Burgess [this message]
2015-11-26 12:38   ` [PATCH 5/7] gdb: 'list' command, tweak handling of +/- arguments Pedro Alves
2015-11-25  0:34 ` [PATCH 3/7] gdb: Small code restructure for list_command Andrew Burgess
2015-11-26 12:37   ` Pedro Alves
2015-11-25  0:34 ` [PATCH 4/7] gdb: Make test names unique in list.exp Andrew Burgess
2015-11-26 12:37   ` Pedro Alves
2015-11-25  0:34 ` [PATCH 1/7] gdb: Make lines_to_list variable static Andrew Burgess
2015-11-26 12:37   ` Pedro Alves
2015-12-11 23:28 ` [PATCH 0/7] Minor changes to 'list' command Andrew Burgess

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0af61eb3baed9334e8dc0aae2b572d87e2807fa8.1448411122.git.andrew.burgess@embecosm.com \
    --to=andrew.burgess@embecosm.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).