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.
This commit is contained in:
parent
14a772212b
commit
02c727013c
@ -1,3 +1,17 @@
|
|||||||
|
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.
|
||||||
|
|
||||||
2020-12-11 Tom Tromey <tom@tromey.com>
|
2020-12-11 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
* varobj.c (varobj_create): Update.
|
* varobj.c (varobj_create): Update.
|
||||||
|
@ -174,7 +174,7 @@ static int parse_number (struct parser_state *, const char *, int,
|
|||||||
%token SINGLE DOUBLE PRECISION
|
%token SINGLE DOUBLE PRECISION
|
||||||
%token <lval> CHARACTER
|
%token <lval> CHARACTER
|
||||||
|
|
||||||
%token <voidval> DOLLAR_VARIABLE
|
%token <sval> DOLLAR_VARIABLE
|
||||||
|
|
||||||
%token <opcode> ASSIGN_MODIFY
|
%token <opcode> ASSIGN_MODIFY
|
||||||
%token <opcode> UNOP_INTRINSIC BINOP_INTRINSIC
|
%token <opcode> UNOP_INTRINSIC BINOP_INTRINSIC
|
||||||
@ -509,6 +509,7 @@ exp : variable
|
|||||||
;
|
;
|
||||||
|
|
||||||
exp : DOLLAR_VARIABLE
|
exp : DOLLAR_VARIABLE
|
||||||
|
{ write_dollar_variable (pstate, $1); }
|
||||||
;
|
;
|
||||||
|
|
||||||
exp : SIZEOF '(' type ')' %prec UNARY
|
exp : SIZEOF '(' type ')' %prec UNARY
|
||||||
@ -1357,10 +1358,7 @@ yylex (void)
|
|||||||
yylval.sval.length = namelen;
|
yylval.sval.length = namelen;
|
||||||
|
|
||||||
if (*tokstart == '$')
|
if (*tokstart == '$')
|
||||||
{
|
|
||||||
write_dollar_variable (pstate, yylval.sval);
|
|
||||||
return DOLLAR_VARIABLE;
|
return DOLLAR_VARIABLE;
|
||||||
}
|
|
||||||
|
|
||||||
/* Use token-type TYPENAME for symbols that happen to be defined
|
/* Use token-type TYPENAME for symbols that happen to be defined
|
||||||
currently as names of types; NAME for other symbols.
|
currently as names of types; NAME for other symbols.
|
||||||
|
@ -125,7 +125,7 @@ static int number_sign = 1;
|
|||||||
/* The GDB scope operator */
|
/* The GDB scope operator */
|
||||||
%token COLONCOLON
|
%token COLONCOLON
|
||||||
|
|
||||||
%token <voidval> DOLLAR_VARIABLE
|
%token <sval> DOLLAR_VARIABLE
|
||||||
|
|
||||||
/* M2 tokens */
|
/* M2 tokens */
|
||||||
%left ','
|
%left ','
|
||||||
@ -535,6 +535,7 @@ variable: fblock
|
|||||||
|
|
||||||
/* GDB internal ($foo) variable */
|
/* GDB internal ($foo) variable */
|
||||||
variable: DOLLAR_VARIABLE
|
variable: DOLLAR_VARIABLE
|
||||||
|
{ write_dollar_variable (pstate, $1); }
|
||||||
;
|
;
|
||||||
|
|
||||||
/* GDB scope operator */
|
/* GDB scope operator */
|
||||||
@ -952,10 +953,7 @@ yylex (void)
|
|||||||
yylval.sval.length = namelen;
|
yylval.sval.length = namelen;
|
||||||
|
|
||||||
if (*tokstart == '$')
|
if (*tokstart == '$')
|
||||||
{
|
|
||||||
write_dollar_variable (pstate, yylval.sval);
|
|
||||||
return DOLLAR_VARIABLE;
|
return DOLLAR_VARIABLE;
|
||||||
}
|
|
||||||
|
|
||||||
/* Use token-type BLOCKNAME for symbols that happen to be defined as
|
/* Use token-type BLOCKNAME for symbols that happen to be defined as
|
||||||
functions. If this is not so, then ...
|
functions. If this is not so, then ...
|
||||||
|
40
gdb/p-exp.y
40
gdb/p-exp.y
@ -115,7 +115,6 @@ static int parse_number (struct parser_state *,
|
|||||||
const char *, int, int, YYSTYPE *);
|
const char *, int, int, YYSTYPE *);
|
||||||
|
|
||||||
static struct type *current_type;
|
static struct type *current_type;
|
||||||
static struct internalvar *intvar;
|
|
||||||
static int leftdiv_is_integer;
|
static int leftdiv_is_integer;
|
||||||
static void push_current_type (void);
|
static void push_current_type (void);
|
||||||
static void pop_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
|
/* Special type cases, put in to allow the parser to distinguish different
|
||||||
legal basetypes. */
|
legal basetypes. */
|
||||||
|
|
||||||
%token <voidval> DOLLAR_VARIABLE
|
%token <sval> DOLLAR_VARIABLE
|
||||||
|
|
||||||
|
|
||||||
/* Object pascal */
|
/* Object pascal */
|
||||||
@ -192,7 +191,6 @@ static int search_field;
|
|||||||
%%
|
%%
|
||||||
|
|
||||||
start : { current_type = NULL;
|
start : { current_type = NULL;
|
||||||
intvar = NULL;
|
|
||||||
search_field = 0;
|
search_field = 0;
|
||||||
leftdiv_is_integer = 0;
|
leftdiv_is_integer = 0;
|
||||||
}
|
}
|
||||||
@ -526,16 +524,27 @@ exp : variable
|
|||||||
;
|
;
|
||||||
|
|
||||||
exp : DOLLAR_VARIABLE
|
exp : DOLLAR_VARIABLE
|
||||||
/* Already written by write_dollar_variable.
|
{
|
||||||
Handle current_type. */
|
write_dollar_variable (pstate, $1);
|
||||||
{ if (intvar) {
|
|
||||||
struct value * val, * mark;
|
|
||||||
|
|
||||||
mark = value_mark ();
|
/* $ is the normal prefix for pascal
|
||||||
val = value_of_internalvar (pstate->gdbarch (),
|
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);
|
intvar);
|
||||||
current_type = value_type (val);
|
current_type = value_type (val);
|
||||||
value_release_to_mark (mark);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
@ -1494,17 +1503,6 @@ yylex (void)
|
|||||||
|
|
||||||
if (*tokstart == '$')
|
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);
|
free (uptokstart);
|
||||||
return DOLLAR_VARIABLE;
|
return DOLLAR_VARIABLE;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user