aboutsummaryrefslogtreecommitdiff
path: root/gdb/p-exp.y
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2020-12-11 09:59:15 -0700
committerTom Tromey <tom@tromey.com>2020-12-11 10:10:53 -0700
commit02c727013cc3ae08b86ad360429f9a0dbdc0ec92 (patch)
treea2ab1ef9c1f3d7c441e615f01fd671c135742827 /gdb/p-exp.y
parent14a772212b8e8e19b45a23e2dacb61ceff0d4979 (diff)
downloadgdb-02c727013cc3ae08b86ad360429f9a0dbdc0ec92.zip
gdb-02c727013cc3ae08b86ad360429f9a0dbdc0ec92.tar.gz
gdb-02c727013cc3ae08b86ad360429f9a0dbdc0ec92.tar.bz2
Avoid side effects in expression lexers
I noticed that some of the lexers were calling write_dollar_variable from the lexer. This seems like a bad practice, so this patch moves the side effects into the parsers. I tested this by re-running gdb.fortran and gdb.modula2; the Pascal compiler on my machine seems not to work, so I couldn't test gdb.pascal. I note that the type-tracking in the Pascal is also incorrect, in that a convenience variable's type may change between parsing and evaluation (or even during the course of evaluation). gdb/ChangeLog 2020-12-11 Tom Tromey <tom@tromey.com> * p-exp.y (intvar): Remove global. (DOLLAR_VARIABLE): Change type. (start): Update. (exp): Call write_dollar_variable here... (yylex): ... not here. * m2-exp.y (DOLLAR_VARIABLE): Change type. (variable): Call write_dollar_variable here... (yylex): ... not here. * f-exp.y (DOLLAR_VARIABLE): Change type. (exp): Call write_dollar_variable here... (yylex): ... not here.
Diffstat (limited to 'gdb/p-exp.y')
-rw-r--r--gdb/p-exp.y48
1 files changed, 23 insertions, 25 deletions
diff --git a/gdb/p-exp.y b/gdb/p-exp.y
index 9caf15f..618557c 100644
--- a/gdb/p-exp.y
+++ b/gdb/p-exp.y
@@ -115,7 +115,6 @@ static int parse_number (struct parser_state *,
const char *, int, int, YYSTYPE *);
static struct type *current_type;
-static struct internalvar *intvar;
static int leftdiv_is_integer;
static void push_current_type (void);
static void pop_current_type (void);
@@ -161,7 +160,7 @@ static int search_field;
/* Special type cases, put in to allow the parser to distinguish different
legal basetypes. */
-%token <voidval> DOLLAR_VARIABLE
+%token <sval> DOLLAR_VARIABLE
/* Object pascal */
@@ -192,7 +191,6 @@ static int search_field;
%%
start : { current_type = NULL;
- intvar = NULL;
search_field = 0;
leftdiv_is_integer = 0;
}
@@ -526,17 +524,28 @@ exp : variable
;
exp : DOLLAR_VARIABLE
- /* Already written by write_dollar_variable.
- Handle current_type. */
- { if (intvar) {
- struct value * val, * mark;
-
- mark = value_mark ();
- val = value_of_internalvar (pstate->gdbarch (),
- intvar);
- current_type = value_type (val);
- value_release_to_mark (mark);
- }
+ {
+ write_dollar_variable (pstate, $1);
+
+ /* $ is the normal prefix for pascal
+ hexadecimal values but this conflicts
+ with the GDB use for debugger variables
+ so in expression to enter hexadecimal
+ values we still need to use C syntax with
+ 0xff */
+ std::string tmp ($1.ptr, $1.length);
+ /* Handle current_type. */
+ struct internalvar *intvar
+ = lookup_only_internalvar (tmp.c_str () + 1);
+ if (intvar != nullptr)
+ {
+ scoped_value_mark mark;
+
+ value *val
+ = value_of_internalvar (pstate->gdbarch (),
+ intvar);
+ current_type = value_type (val);
+ }
}
;
@@ -1494,17 +1503,6 @@ yylex (void)
if (*tokstart == '$')
{
- char *tmp;
-
- /* $ is the normal prefix for pascal hexadecimal values
- but this conflicts with the GDB use for debugger variables
- so in expression to enter hexadecimal values
- we still need to use C syntax with 0xff */
- write_dollar_variable (pstate, yylval.sval);
- tmp = (char *) alloca (namelen + 1);
- memcpy (tmp, tokstart, namelen);
- tmp[namelen] = '\0';
- intvar = lookup_only_internalvar (tmp + 1);
free (uptokstart);
return DOLLAR_VARIABLE;
}