2011-02-24 Michael Snyder <msnyder@vmware.com>
authorMichael Snyder <msnyder@vmware.com>
Sun, 27 Feb 2011 20:57:16 +0000 (20:57 +0000)
committerMichael Snyder <msnyder@vmware.com>
Sun, 27 Feb 2011 20:57:16 +0000 (20:57 +0000)
* value.c (value_from_history_ref): New function.
* value.h (value_from_history_ref): Export.
* cli/cli-utils.c (get_number_trailer): Use value_from_history_ref
to parse value history references.
* cli/cli-utils.h (get_number_trailer): Update comment.

2011-02-24  Michael Snyder  <msnyder@vmware.com>

* gdb.base/break.exp: Add tests for delete breakpoints using
convenience variables and value history references.

gdb/ChangeLog
gdb/cli/cli-utils.c
gdb/cli/cli-utils.h
gdb/doc/ChangeLog
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/break.exp
gdb/value.c
gdb/value.h

index f8ccb3331f86c6572231f9a3801f1dd35cd5af21..ab012b22feade96ba16381b233a109ccb404fcb2 100644 (file)
@@ -1,3 +1,19 @@
+2011-02-27  Michael Snyder  <msnyder@vmware.com>
+
+       * value.c (value_from_history_ref): New function.
+       * value.h (value_from_history_ref): Export.
+       * cli/cli-utils.c (get_number_trailer): Use value_from_history_ref
+       to parse value history references.
+       * cli/cli-utils.h (get_number_trailer): Update comment.
+
+2011-02-27  Michael Snyder  <msnyder@vmware.com>
+
+       * inferior.c (detach_inferior_command): Use get_number_or_range.
+       (kill_inferior_command): Ditto.
+       (remove_inferior_command): Ditto.
+       (initialize_inferiors): Make command names plural.
+       Update help strings.
+
 2011-02-27  Michael Snyder  <msnyder@vmware.com>
 
        * darwin-nat-info.c: Fix comment typo.
        * python/py-value.c: Ditto.
        * tui/tui-win.c: Ditto.
 
-2011-02-25  Michael Snyder  <msnyder@vmware.com>
-
-       * inferior.c (detach_inferior_command): Use get_number_or_range.
-       (kill_inferior_command): Ditto.
-       (remove_inferior_command): Ditto.
-       (initialize_inferiors): Make command names plural.
-       Update help strings.
-
 2011-02-25  Michael Snyder  <msnyder@vmware.com>
 
        * inferior.c (print_inferior): Accept a string instead of an int
index 34c368be9c58fe9c7a0a104d5e2dee0327e5351b..133ac538316680fb761f95e49611a9b982784872 100644 (file)
 #include "cli/cli-utils.h"
 #include "gdb_string.h"
 #include "value.h"
+#include "gdb_assert.h"
 
 #include <ctype.h>
 
 /* *PP is a string denoting a number.  Get the number of the.  Advance
    *PP after the string and any trailing whitespace.
 
-   Currently the string can either be a number or "$" followed by the
-   name of a convenience variable.
+   Currently the string can either be a number, or "$" followed by the
+   name of a convenience variable, or ("$" or "$$") followed by digits.
 
    TRAILER is a character which can be found after the number; most
    commonly this is `-'.  If you don't want a trailer, use \0.  */
@@ -41,24 +42,39 @@ get_number_trailer (char **pp, int trailer)
 
   if (*p == '$')
     {
-      /* Make a copy of the name, so we can null-terminate it
-         to pass to lookup_internalvar().  */
-      char *varname;
-      char *start = ++p;
-      LONGEST val;
-
-      while (isalnum (*p) || *p == '_')
-       p++;
-      varname = (char *) alloca (p - start + 1);
-      strncpy (varname, start, p - start);
-      varname[p - start] = '\0';
-      if (get_internalvar_integer (lookup_internalvar (varname), &val))
-       retval = (int) val;
-      else
+      struct value *val = value_from_history_ref (p, &p);
+
+      if (val) /* Value history reference */
        {
-         printf_filtered (_("Convenience variable must "
-                            "have integer value.\n"));
-         retval = 0;
+         if (TYPE_CODE (value_type (val)) == TYPE_CODE_INT)
+           retval = value_as_long (val);
+         else
+           {
+             printf_filtered (_("History value must have integer type."));
+             retval = 0;
+           }
+       }
+      else     /* Convenience variable */
+       {
+         /* Internal variable.  Make a copy of the name, so we can
+            null-terminate it to pass to lookup_internalvar().  */
+         char *varname;
+         char *start = ++p;
+         LONGEST val;
+
+         while (isalnum (*p) || *p == '_')
+           p++;
+         varname = (char *) alloca (p - start + 1);
+         strncpy (varname, start, p - start);
+         varname[p - start] = '\0';
+         if (get_internalvar_integer (lookup_internalvar (varname), &val))
+           retval = (int) val;
+         else
+           {
+             printf_filtered (_("Convenience variable must "
+                                "have integer value.\n"));
+             retval = 0;
+           }
        }
     }
   else
index 6158999860eb55dfe2711ba0f0775d7e8ad4ef94..09240d076449aa3c730b4c2885b26b17cc852d90 100644 (file)
@@ -23,8 +23,8 @@
 /* *PP is a string denoting a number.  Get the number of the.  Advance
    *PP after the string and any trailing whitespace.
 
-   Currently the string can either be a number or "$" followed by the
-   name of a convenience variable.  */
+   Currently the string can either be a number or "$" followed by the
+   name of a convenience variable, or ("$" or "$$") followed by digits.  */
 
 extern int get_number (char **);
 
index e84de14a11dcc73b480ebf323dd0f5d51a97889d..f1939dbcc9666b7be3f933a973ca150dc1ee8eb6 100644 (file)
@@ -1,4 +1,4 @@
-2011-02-25  Michael Snyder  <msnyder@vmware.com>
+2011-02-27  Michael Snyder  <msnyder@vmware.com>
 
        * gdb.texinfo (Inferiors and Programs): Update commands to show 
        that they can accept multiple arguments.
index 27164000a31aaa65612067b8fa59d5f30ee62b91..a92d0c662b87ef53a210292ba00927d9da5d0a05 100644 (file)
@@ -1,12 +1,12 @@
+2011-02-27  Michael Snyder  <msnyder@vmware.com>
+
+       * gdb.multi/base.exp: Add test for remove-inferiors.
+
 2011-02-26  Joel Brobecker  <brobecker@adacore.com>
 
        * gdb.python/py-frame.exp: Simplify the initialization phase
        using prepare_for_testing.
 
-2011-02-25  Michael Snyder  <msnyder@vmware.com>
-
-       * gdb.multi/base.exp: Add test for remove-inferiors.
-
 2011-02-25  Michael Snyder  <msnyder@vmware.com>
 
        * gdb.multi/base.exp: Add tests for info inferiors with args.
        * gdb.dwarf2/dw2-ranges3.S: Rename to ...
        * gdb.dwarf2/dw2-ranges3.c: ... here, convert it to C.
 
+2011-02-24  Michael Snyder  <msnyder@vmware.com>
+
+       * gdb.base/break.exp: Add tests for delete breakpoints using
+       convenience variables and value history references.
+
 2011-02-24  Michael Snyder  <msnyder@vmware.com>
 
        * gdb.base/break.exp: Remove debugging 'printf' accidentally
index 6e14a477c7573123023ea0ea7e38dd303fd55950..15227bc1e39210813adaeb47acdebf7c406fdc1f 100644 (file)
@@ -236,6 +236,129 @@ gdb_test_multiple "info break 3-5" "info break 3-5" {
     }
 }
 
+#
+# Test disable/enable with arguments
+#
+
+# Test with value history
+
+gdb_test "print 1" "" ""
+gdb_test "print 2" "" ""
+gdb_test "print 3" "" ""
+gdb_test "print 4" "" ""
+gdb_test "print 5" "" ""
+gdb_test "print 6" "" ""
+
+# $2 is 2 and $$ is 5
+gdb_test_no_output "disable \$2 \$\$" "disable using history values"
+
+set see1 0
+set see2 0
+set see3 0
+set see4 0
+set see5 0
+set see6 0
+
+gdb_test_multiple "info break" "check disable with history values" {
+    -re "1\[\t \]+breakpoint *keep y.* in main at .*:$main_line\[^\r\n\]*" {
+       set see1 1
+       exp_continue
+    }
+    -re "2\[\t \]+breakpoint *keep n\[^\r\n\]* in marker2 at \[^\r\n\]*" {
+       set see2 1
+       exp_continue
+    }
+    -re "3\[\t \]+breakpoint *keep y\[^\r\n\]*$bp_location7\[^\r\n\]*" {
+       set see3 1
+       exp_continue
+    }
+    -re "4\[\t \]+breakpoint *keep y\[^\r\n\]*$bp_location1\[^\r\n\]*" {
+       set see4 1
+       exp_continue
+    }
+    -re "5\[\t \]+breakpoint *keep n\[^\r\n\]*$bp_location1\[^\r\n\]*" {
+       set see5 1
+       exp_continue
+    }
+    -re "6\[\t \]+breakpoint *keep y\[^\r\n\]*$bp_location2\[^\r\n\]*" {
+       set see6 1
+       exp_continue
+    }
+    -re ".*$gdb_prompt $" {
+       if { $see1 && $see2 && $see3 && $see4 && $see5 && $see6 } then {
+           pass "check disable with history values"
+       } else {
+           fail "check disable with history values"
+       }
+    }
+}
+
+gdb_test "enable" "" ""
+gdb_test "set \$foo = 3" "" ""
+gdb_test "set \$bar = 6" "" ""
+gdb_test_no_output "disable \$foo \$bar" "disable with convenience values"
+
+set see1 0
+set see2 0
+set see3 0
+set see4 0
+set see5 0
+set see6 0
+
+gdb_test_multiple "info break" "check disable with convenience values" {
+    -re "1\[\t \]+breakpoint *keep y.* in main at .*:$main_line\[^\r\n\]*" {
+       set see1 1
+       exp_continue
+    }
+    -re "2\[\t \]+breakpoint *keep y\[^\r\n\]* in marker2 at \[^\r\n\]*" {
+       set see2 1
+       exp_continue
+    }
+    -re "3\[\t \]+breakpoint *keep n\[^\r\n\]*$bp_location7\[^\r\n\]*" {
+       set see3 1
+       exp_continue
+    }
+    -re "4\[\t \]+breakpoint *keep y\[^\r\n\]*$bp_location1\[^\r\n\]*" {
+       set see4 1
+       exp_continue
+    }
+    -re "5\[\t \]+breakpoint *keep y\[^\r\n\]*$bp_location1\[^\r\n\]*" {
+       set see5 1
+       exp_continue
+    }
+    -re "6\[\t \]+breakpoint *keep n\[^\r\n\]*$bp_location2\[^\r\n\]*" {
+       set see6 1
+       exp_continue
+    }
+    -re ".*$gdb_prompt $" {
+       if { $see1 && $see2 && $see3 && $see4 && $see5 && $see6 } then {
+           pass "check disable with convenience values"
+       } else {
+           fail "check disable with convenience values"
+       }
+    }
+}
+
+# test with bad values
+
+gdb_test "enable" "" ""
+gdb_test "disable 10" "No breakpoint number 10." \
+    "disable non-existent breakpoint 10"
+
+gdb_test "set \$baz 1.234"
+gdb_test "disable \$baz" \
+    "Convenience variable must have integer value.*" \
+    "disable with non-integer convenience var"
+gdb_test "disable \$grbx" \
+    "Convenience variable must have integer value.*" \
+    "disable with non-existent convenience var"
+gdb_test "disable \$10" \
+    "History has not yet reached .10." \
+    "disable with non-existent history value"
+gdb_test "disable \$1foo" \
+    "Convenience variable must have integer value.*" \
+    "disable with badly formed history value"
+
 # FIXME: The rest of this test doesn't work with anything that can't
 # handle arguments.
 # Huh? There doesn't *appear* to be anything that passes arguments
index 011b5e75b049e891b0df7bfda170ca1913bcdec5..2acb1df75db986a310fa0d52ccbbf007557574cd 100644 (file)
@@ -41,7 +41,7 @@
 #include "cli/cli-decode.h"
 #include "exceptions.h"
 #include "python/python.h"
-
+#include <ctype.h>
 #include "tracepoint.h"
 
 /* Prototypes for exported functions.  */
@@ -2991,6 +2991,59 @@ value_from_decfloat (struct type *type, const gdb_byte *dec)
   return val;
 }
 
+/* Extract a value from the history file.  Input will be of the form
+   $digits or $$digits.  See block comment above 'write_dollar_variable'
+   for details.  */
+
+struct value *
+value_from_history_ref (char *h, char **endp)
+{
+  int index, len;
+
+  if (h[0] == '$')
+    len = 1;
+  else
+    return NULL;
+
+  if (h[1] == '$')
+    len = 2;
+
+  /* Find length of numeral string.  */
+  for (; isdigit (h[len]); len++)
+    ;
+
+  /* Make sure numeral string is not part of an identifier.  */
+  if (h[len] == '_' || isalpha (h[len]))
+    return NULL;
+
+  /* Now collect the index value.  */
+  if (h[1] == '$')
+    {
+      if (len == 2)
+       {
+         /* For some bizarre reason, "$$" is equivalent to "$$1", 
+            rather than to "$$0" as it ought to be!  */
+         index = -1;
+         *endp += len;
+       }
+      else
+       index = -strtol (&h[2], endp, 10);
+    }
+  else
+    {
+      if (len == 1)
+       {
+         /* "$" is equivalent to "$0".  */
+         index = 0;
+         *endp += len;
+       }
+      else
+       index = strtol (&h[1], endp, 10);
+    }
+
+  return access_value_history (index);
+}
+
 struct value *
 coerce_ref (struct value *arg)
 {
index e019e56676a3861ec136c4a0d406e9e8e47d69d2..ad90a38f5ca6f4bd0765289325c4a187521ace96 100644 (file)
@@ -471,6 +471,7 @@ extern struct value *value_from_pointer (struct type *type, CORE_ADDR addr);
 extern struct value *value_from_double (struct type *type, DOUBLEST num);
 extern struct value *value_from_decfloat (struct type *type,
                                          const gdb_byte *decbytes);
+extern struct value *value_from_history_ref (char *, char **);
 
 extern struct value *value_at (struct type *type, CORE_ADDR addr);
 extern struct value *value_at_lazy (struct type *type, CORE_ADDR addr);