diff options
author | Tom Tromey <tromey@adacore.com> | 2023-04-28 08:38:38 -0600 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2023-05-23 13:57:54 -0600 |
commit | 87b647cfb13a47effebe185b7dcc733b45f51789 (patch) | |
tree | 86106e0e6997b679bcf4eebc0c4b3a3509a2c4ab /gdb | |
parent | e360af5af8e0ecb3eb62cf3970e9d1df0289c781 (diff) | |
download | binutils-87b647cfb13a47effebe185b7dcc733b45f51789.zip binutils-87b647cfb13a47effebe185b7dcc733b45f51789.tar.gz binutils-87b647cfb13a47effebe185b7dcc733b45f51789.tar.bz2 |
Add PARSER_LEAVE_BLOCK_ALONE flag
This adds a PARSER_LEAVE_BLOCK_ALONE flag, and changes the parse API
to respect it. This flag lets callers avoid any change to the
passed-in block and expression PC, letting them specify the context
exactly. In particular, now nullptr can be used to indicate that the
parse should not examine any local variables.
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/expression.h | 6 | ||||
-rw-r--r-- | gdb/parse.c | 37 |
2 files changed, 27 insertions, 16 deletions
diff --git a/gdb/expression.h b/gdb/expression.h index c485b15..d185877 100644 --- a/gdb/expression.h +++ b/gdb/expression.h @@ -301,6 +301,12 @@ enum parser_flag it parses. For yacc-based parsers, this translates to setting yydebug. */ PARSER_DEBUG = (1 << 2), + + /* Normally the expression-parsing functions like parse_exp_1 will + attempt to find a context block if one is not passed in. If set, + this flag suppresses this search and uses a null context for the + parse. */ + PARSER_LEAVE_BLOCK_ALONE = (1 << 3), }; DEF_ENUM_FLAGS_TYPE (enum parser_flag, parser_flags); diff --git a/gdb/parse.c b/gdb/parse.c index bbe5cf1..221733a 100644 --- a/gdb/parse.c +++ b/gdb/parse.c @@ -344,26 +344,31 @@ parse_exp_in_context (const char **stringptr, CORE_ADDR pc, if (tracker == nullptr) tracker = &local_tracker; - /* If no context specified, try using the current frame, if any. */ - if (!expression_context_block) - expression_context_block = get_selected_block (&expression_context_pc); - else if (pc == 0) - expression_context_pc = expression_context_block->entry_pc (); - else - expression_context_pc = pc; + if ((flags & PARSER_LEAVE_BLOCK_ALONE) == 0) + { + /* If no context specified, try using the current frame, if any. */ + if (!expression_context_block) + expression_context_block + = get_selected_block (&expression_context_pc); + else if (pc == 0) + expression_context_pc = expression_context_block->entry_pc (); + else + expression_context_pc = pc; - /* Fall back to using the current source static context, if any. */ + /* Fall back to using the current source static context, if any. */ - if (!expression_context_block) - { - struct symtab_and_line cursal = get_current_source_symtab_and_line (); + if (!expression_context_block) + { + struct symtab_and_line cursal + = get_current_source_symtab_and_line (); - if (cursal.symtab) - expression_context_block - = cursal.symtab->compunit ()->blockvector ()->static_block (); + if (cursal.symtab) + expression_context_block + = cursal.symtab->compunit ()->blockvector ()->static_block (); - if (expression_context_block) - expression_context_pc = expression_context_block->entry_pc (); + if (expression_context_block) + expression_context_pc = expression_context_block->entry_pc (); + } } if (language_mode == language_mode_auto && block != NULL) |