Skip to content

Commit 7ad417d

Browse files
committed
Have parser reset the innermost block tracker
I ran across a comment in symfile.c today: /* Clear globals which might have pointed into a removed objfile. FIXME: It's not clear which of these are supposed to persist between expressions and which ought to be reset each time. */ It seems to me that this can be clarified: the parser entry points ought to reset the innermost block tracker (and the expression context block), and these should not be considered valid for code to use at arbitrary times -- only immediately after an expression has been parsed. This patch implements this idea. This could be further improved by removing the parser globals and changing the parser functions to return this information, but I have not done this. Tested by the buildbot. gdb/ChangeLog 2019-03-23 Tom Tromey <tom@tromey.com> * varobj.c (varobj_create): Update. * symfile.c (clear_symtab_users): Don't reset innermost_block. * printcmd.c (display_command, do_one_display): Don't reset innermost_block. * parser-defs.h (enum innermost_block_tracker_type): Move to expression.h. (innermost_block): Update comment. * parse.c (parse_exp_1): Add tracker_types parameter. (parse_exp_in_context): Rename from parse_exp_in_context_1. Add tracker_types parameter. Reset innermost_block. (parse_exp_in_context): Remove. (parse_expression_for_completion): Update. * objfiles.c (~objfile): Don't reset expression_context_block or innermost_block. * expression.h (enum innermost_block_tracker_type): Move from parser-defs.h. (parse_exp_1): Add tracker_types parameter. * breakpoint.c (set_breakpoint_condition, watch_command_1): Don't reset innermost_block.
1 parent b366c20 commit 7ad417d

File tree

9 files changed

+60
-60
lines changed

9 files changed

+60
-60
lines changed

gdb/ChangeLog

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
2019-03-23 Tom Tromey <tom@tromey.com>
2+
3+
* varobj.c (varobj_create): Update.
4+
* symfile.c (clear_symtab_users): Don't reset innermost_block.
5+
* printcmd.c (display_command, do_one_display): Don't reset
6+
innermost_block.
7+
* parser-defs.h (enum innermost_block_tracker_type): Move to
8+
expression.h.
9+
(innermost_block): Update comment.
10+
* parse.c (parse_exp_1): Add tracker_types parameter.
11+
(parse_exp_in_context): Rename from parse_exp_in_context_1. Add
12+
tracker_types parameter. Reset innermost_block.
13+
(parse_exp_in_context): Remove.
14+
(parse_expression_for_completion): Update.
15+
* objfiles.c (~objfile): Don't reset expression_context_block or
16+
innermost_block.
17+
* expression.h (enum innermost_block_tracker_type): Move from
18+
parser-defs.h.
19+
(parse_exp_1): Add tracker_types parameter.
20+
* breakpoint.c (set_breakpoint_condition, watch_command_1): Don't
21+
reset innermost_block.
22+
123
2019-03-23 Tom Tromey <tom@tromey.com>
224

325
* objfiles.h: Include bcache.h.

gdb/breakpoint.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,6 @@ set_breakpoint_condition (struct breakpoint *b, const char *exp,
880880
{
881881
struct watchpoint *w = (struct watchpoint *) b;
882882

883-
innermost_block.reset ();
884883
arg = exp;
885884
w->cond_exp = parse_exp_1 (&arg, 0, 0, 0);
886885
if (*arg)
@@ -10602,7 +10601,6 @@ watch_command_1 (const char *arg, int accessflag, int from_tty,
1060210601
/* Parse the rest of the arguments. From here on out, everything
1060310602
is in terms of a newly allocated string instead of the original
1060410603
ARG. */
10605-
innermost_block.reset ();
1060610604
std::string expression (arg, exp_end - arg);
1060710605
exp_start = arg = expression.c_str ();
1060810606
expression_up exp = parse_exp_1 (&arg, 0, 0, 0);
@@ -10664,7 +10662,6 @@ watch_command_1 (const char *arg, int accessflag, int from_tty,
1066410662
toklen = end_tok - tok;
1066510663
if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
1066610664
{
10667-
innermost_block.reset ();
1066810665
tok = cond_start = end_tok + 1;
1066910666
parse_exp_1 (&tok, 0, 0, 0);
1067010667

gdb/expression.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,23 @@
2323

2424
#include "symtab.h" /* Needed for "struct block" type. */
2525

26+
/* While parsing expressions we need to track the innermost lexical block
27+
that we encounter. In some situations we need to track the innermost
28+
block just for symbols, and in other situations we want to track the
29+
innermost block for symbols and registers. These flags are used by the
30+
innermost block tracker to control which blocks we consider for the
31+
innermost block. These flags can be combined together as needed. */
32+
33+
enum innermost_block_tracker_type
34+
{
35+
/* Track the innermost block for symbols within an expression. */
36+
INNERMOST_BLOCK_FOR_SYMBOLS = (1 << 0),
37+
38+
/* Track the innermost block for registers within an expression. */
39+
INNERMOST_BLOCK_FOR_REGISTERS = (1 << 1)
40+
};
41+
DEF_ENUM_FLAGS_TYPE (enum innermost_block_tracker_type,
42+
innermost_block_tracker_types);
2643

2744
/* Definitions for saved C expressions. */
2845

@@ -105,7 +122,9 @@ extern struct type *parse_expression_for_completion
105122
(const char *, gdb::unique_xmalloc_ptr<char> *, enum type_code *);
106123

107124
extern expression_up parse_exp_1 (const char **, CORE_ADDR pc,
108-
const struct block *, int);
125+
const struct block *, int,
126+
innermost_block_tracker_types
127+
= INNERMOST_BLOCK_FOR_SYMBOLS);
109128

110129
/* For use by parsers; set if we want to parse an expression and
111130
attempt completion. */

gdb/objfiles.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -670,12 +670,6 @@ objfile::~objfile ()
670670
for example), so we need to call this here. */
671671
clear_pc_function_cache ();
672672

673-
/* Clear globals which might have pointed into a removed objfile.
674-
FIXME: It's not clear which of these are supposed to persist
675-
between expressions and which ought to be reset each time. */
676-
expression_context_block = NULL;
677-
innermost_block.reset ();
678-
679673
/* Check to see if the current_source_symtab belongs to this objfile,
680674
and if so, call clear_current_source_symtab_and_line. */
681675

gdb/parse.c

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,8 @@ static int prefixify_subexp (struct expression *, struct expression *, int,
116116

117117
static expression_up parse_exp_in_context (const char **, CORE_ADDR,
118118
const struct block *, int,
119-
int, int *);
120-
static expression_up parse_exp_in_context_1 (const char **, CORE_ADDR,
121-
const struct block *, int,
122-
int, int *);
119+
int, int *,
120+
innermost_block_tracker_types);
123121

124122
/* Documented at it's declaration. */
125123

@@ -1095,18 +1093,10 @@ prefixify_subexp (struct expression *inexpr,
10951093

10961094
expression_up
10971095
parse_exp_1 (const char **stringptr, CORE_ADDR pc, const struct block *block,
1098-
int comma)
1096+
int comma, innermost_block_tracker_types tracker_types)
10991097
{
1100-
return parse_exp_in_context (stringptr, pc, block, comma, 0, NULL);
1101-
}
1102-
1103-
static expression_up
1104-
parse_exp_in_context (const char **stringptr, CORE_ADDR pc,
1105-
const struct block *block,
1106-
int comma, int void_context_p, int *out_subexp)
1107-
{
1108-
return parse_exp_in_context_1 (stringptr, pc, block, comma,
1109-
void_context_p, out_subexp);
1098+
return parse_exp_in_context (stringptr, pc, block, comma, 0, NULL,
1099+
tracker_types);
11101100
}
11111101

11121102
/* As for parse_exp_1, except that if VOID_CONTEXT_P, then
@@ -1117,9 +1107,10 @@ parse_exp_in_context (const char **stringptr, CORE_ADDR pc,
11171107
is left untouched. */
11181108

11191109
static expression_up
1120-
parse_exp_in_context_1 (const char **stringptr, CORE_ADDR pc,
1121-
const struct block *block,
1122-
int comma, int void_context_p, int *out_subexp)
1110+
parse_exp_in_context (const char **stringptr, CORE_ADDR pc,
1111+
const struct block *block,
1112+
int comma, int void_context_p, int *out_subexp,
1113+
innermost_block_tracker_types tracker_types)
11231114
{
11241115
const struct language_defn *lang = NULL;
11251116
int subexp;
@@ -1132,6 +1123,7 @@ parse_exp_in_context_1 (const char **stringptr, CORE_ADDR pc,
11321123
expout_last_struct = -1;
11331124
expout_tag_completion_type = TYPE_CODE_UNDEF;
11341125
expout_completion_name.reset ();
1126+
innermost_block.reset (tracker_types);
11351127

11361128
comma_terminates = comma;
11371129

@@ -1286,7 +1278,8 @@ parse_expression_for_completion (const char *string,
12861278
TRY
12871279
{
12881280
parse_completion = 1;
1289-
exp = parse_exp_in_context (&string, 0, 0, 0, 0, &subexp);
1281+
exp = parse_exp_in_context (&string, 0, 0, 0, 0, &subexp,
1282+
INNERMOST_BLOCK_FOR_SYMBOLS);
12901283
}
12911284
CATCH (except, RETURN_MASK_ERROR)
12921285
{

gdb/parser-defs.h

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -75,24 +75,6 @@ extern const struct block *expression_context_block;
7575
then look up the macro definitions active at that point. */
7676
extern CORE_ADDR expression_context_pc;
7777

78-
/* While parsing expressions we need to track the innermost lexical block
79-
that we encounter. In some situations we need to track the innermost
80-
block just for symbols, and in other situations we want to track the
81-
innermost block for symbols and registers. These flags are used by the
82-
innermost block tracker to control which blocks we consider for the
83-
innermost block. These flags can be combined together as needed. */
84-
85-
enum innermost_block_tracker_type
86-
{
87-
/* Track the innermost block for symbols within an expression. */
88-
INNERMOST_BLOCK_FOR_SYMBOLS = (1 << 0),
89-
90-
/* Track the innermost block for registers within an expression. */
91-
INNERMOST_BLOCK_FOR_REGISTERS = (1 << 1)
92-
};
93-
DEF_ENUM_FLAGS_TYPE (enum innermost_block_tracker_type,
94-
innermost_block_tracker_types);
95-
9678
/* When parsing expressions we track the innermost block that was
9779
referenced. */
9880

@@ -146,8 +128,9 @@ class innermost_block_tracker
146128
};
147129

148130
/* The innermost context required by the stack and register variables
149-
we've encountered so far. This should be cleared before parsing an
150-
expression, and queried once the parse is complete. */
131+
we've encountered so far. This is cleared by the expression
132+
parsing functions before parsing an expression, and can queried
133+
once the parse is complete. */
151134
extern innermost_block_tracker innermost_block;
152135

153136
/* Number of arguments seen so far in innermost function call. */

gdb/printcmd.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1715,7 +1715,6 @@ display_command (const char *arg, int from_tty)
17151715
fmt.raw = 0;
17161716
}
17171717

1718-
innermost_block.reset ();
17191718
expression_up expr = parse_expression (exp);
17201719

17211720
newobj = new display ();
@@ -1883,7 +1882,6 @@ do_one_display (struct display *d)
18831882

18841883
TRY
18851884
{
1886-
innermost_block.reset ();
18871885
d->exp = parse_expression (d->exp_string);
18881886
d->block = innermost_block.block ();
18891887
}

gdb/symfile.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2901,12 +2901,6 @@ clear_symtab_users (symfile_add_flags add_flags)
29012901
clear_pc_function_cache ();
29022902
gdb::observers::new_objfile.notify (NULL);
29032903

2904-
/* Clear globals which might have pointed into a removed objfile.
2905-
FIXME: It's not clear which of these are supposed to persist
2906-
between expressions and which ought to be reset each time. */
2907-
expression_context_block = NULL;
2908-
innermost_block.reset ();
2909-
29102904
/* Varobj may refer to old symbols, perform a cleanup. */
29112905
varobj_invalidate ();
29122906

gdb/varobj.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,13 +309,13 @@ varobj_create (const char *objname,
309309
}
310310

311311
p = expression;
312-
innermost_block.reset (INNERMOST_BLOCK_FOR_SYMBOLS
313-
| INNERMOST_BLOCK_FOR_REGISTERS);
314312
/* Wrap the call to parse expression, so we can
315313
return a sensible error. */
316314
TRY
317315
{
318-
var->root->exp = parse_exp_1 (&p, pc, block, 0);
316+
var->root->exp = parse_exp_1 (&p, pc, block, 0,
317+
INNERMOST_BLOCK_FOR_SYMBOLS
318+
| INNERMOST_BLOCK_FOR_REGISTERS);
319319
}
320320

321321
CATCH (except, RETURN_MASK_ERROR)

0 commit comments

Comments
 (0)