number_or_range_parser::get_number, don't treat "1 -" as a range
authorPedro Alves <palves@redhat.com>
Wed, 12 Jun 2019 23:06:53 +0000 (00:06 +0100)
committerPedro Alves <palves@redhat.com>
Wed, 12 Jun 2019 23:18:09 +0000 (00:18 +0100)
While adding -OPT options to "frame apply level", I noticed that:

 (gdb) frame apply level 0 -[TAB]

wasn't completing on the supported options.  This commit fixes it.
We'll get instead:

  (gdb) frame apply level 0 -
  -c           -past-entry  -past-main   -q           -s

I added the isspace check because this case:

  (gdb) frame apply level 0-

can't be an option.

Tests for this will be in a new gdb.base/options.exp file, in a
following patch.  It will exercise all of:

  (gdb) frame apply level 0-
  (gdb) frame apply level 0 -
  (gdb) frame apply level 0 --
  (gdb) frame apply level 0 -- -

gdb/ChangeLog:
2019-06-13  Pedro Alves  <palves@redhat.com>

* cli/cli-utils.c (number_or_range_parser::get_number): Do not
parse a range if "-" is at the end of the string.

gdb/ChangeLog
gdb/cli/cli-utils.c

index 63a3690c52dddcf3aad0f77206f425e2b5bbe2f7..73fd65e9256a290349e0292269a9af102e06925e 100644 (file)
@@ -1,3 +1,8 @@
+2019-06-13  Pedro Alves  <palves@redhat.com>
+
+       * cli/cli-utils.c (number_or_range_parser::get_number): Do not
+       parse a range if "-" is at the end of the string.
+
 2019-06-13  Pedro Alves  <palves@redhat.com>
 
        * cli/cli-setshow.c (parse_auto_binary_operation)
index a24fe9278c745c65024b0c14b06bf1af7e88cb69..23296cee9c33169412674b53d0b049f868d77dda 100644 (file)
@@ -233,10 +233,18 @@ number_or_range_parser::get_number ()
       /* Default case: state->m_cur_tok is pointing either to a solo
         number, or to the first number of a range.  */
       m_last_retval = get_number_trailer (&m_cur_tok, '-');
-      /* If get_number_trailer has found a -, it might be the start
-        of a command option.  So, do not parse a range if the - is
-        followed by an alpha.  */
-      if (*m_cur_tok == '-' && !isalpha (*(m_cur_tok + 1)))
+      /* If get_number_trailer has found a '-' preceded by a space, it
+        might be the start of a command option.  So, do not parse a
+        range if the '-' is followed by an alpha or another '-'.  We
+        might also be completing something like
+        "frame apply level 0 -" and we prefer treating that "-" as an
+        option rather than an incomplete range, so check for end of
+        string as well.  */
+      if (m_cur_tok[0] == '-'
+         && !(isspace (m_cur_tok[-1])
+              && (isalpha (m_cur_tok[1])
+                  || m_cur_tok[1] == '-'
+                  || m_cur_tok[1] == '\0')))
        {
          const char **temp;
 
This page took 0.030053 seconds and 4 git commands to generate.