From 3bd0f5efd1910d53733ff9962deee99d7e45d1de Mon Sep 17 00:00:00 2001 From: Michael Snyder Date: Sun, 27 Feb 2011 20:57:16 +0000 Subject: 2011-02-24 Michael Snyder * 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 * gdb.base/break.exp: Add tests for delete breakpoints using convenience variables and value history references. --- gdb/value.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) (limited to 'gdb/value.c') diff --git a/gdb/value.c b/gdb/value.c index 011b5e7..2acb1df 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -41,7 +41,7 @@ #include "cli/cli-decode.h" #include "exceptions.h" #include "python/python.h" - +#include #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) { -- cgit v1.1