From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 03/11] Introduce and use parser flags
Date: Thu, 04 May 2023 08:21:24 -0600 [thread overview]
Message-ID: <20230504-frameless-v1-3-4191201740b0@adacore.com> (raw)
In-Reply-To: <20230504-frameless-v1-0-4191201740b0@adacore.com>
This patch adds a new parser_flags type and changes the parser APIs to
use it rather than a collection of 'int' and 'bool'. More flags will
be added in subsquent patches.
---
gdb/ax-gdb.c | 3 ++-
gdb/breakpoint.c | 3 ++-
gdb/eval.c | 3 ++-
gdb/expression.h | 21 +++++++++++++++++++--
gdb/parse.c | 29 +++++++++++++----------------
gdb/printcmd.c | 5 ++++-
gdb/tracepoint.c | 10 ++++++----
7 files changed, 48 insertions(+), 26 deletions(-)
diff --git a/gdb/ax-gdb.c b/gdb/ax-gdb.c
index 528f45e19eb..927dfc6337e 100644
--- a/gdb/ax-gdb.c
+++ b/gdb/ax-gdb.c
@@ -2615,7 +2615,8 @@ maint_agent_printf_command (const char *cmdrest, int from_tty)
const char *cmd1;
cmd1 = cmdrest;
- expression_up expr = parse_exp_1 (&cmd1, 0, (struct block *) 0, 1);
+ expression_up expr = parse_exp_1 (&cmd1, 0, (struct block *) 0,
+ PARSER_COMMA_TERMINATES);
argvec.push_back (expr.release ());
cmdrest = cmd1;
if (*cmdrest == ',')
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 30d438d06df..de3a7e9ef9c 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -2526,7 +2526,8 @@ parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd)
const char *cmd1;
cmd1 = cmdrest;
- expression_up expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1);
+ expression_up expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope),
+ PARSER_COMMA_TERMINATES);
argvec.push_back (expr.release ());
cmdrest = cmd1;
if (*cmdrest == ',')
diff --git a/gdb/eval.c b/gdb/eval.c
index 9d5ca0b47de..d8d53c28686 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -81,7 +81,8 @@ parse_and_eval (const char *exp)
struct value *
parse_to_comma_and_eval (const char **expp)
{
- expression_up expr = parse_exp_1 (expp, 0, nullptr, 1);
+ expression_up expr = parse_exp_1 (expp, 0, nullptr,
+ PARSER_COMMA_TERMINATES);
return expr->evaluate ();
}
diff --git a/gdb/expression.h b/gdb/expression.h
index 8d351b30a3a..2e2d2a090f9 100644
--- a/gdb/expression.h
+++ b/gdb/expression.h
@@ -283,11 +283,27 @@ class innermost_block_tracker
const struct block *m_innermost_block;
};
+/* Flags that can affect the parsers. */
+
+enum parser_flag
+{
+ /* This flag is set if the expression is being evaluated in a
+ context where a 'void' result type is expected. Parsers are free
+ to ignore this, or to use it to help with overload resolution
+ decisions. */
+ PARSER_VOID_CONTEXT = (1 << 0),
+
+ /* This flag is set if a top-level comma terminates the
+ expression. */
+ PARSER_COMMA_TERMINATES = (1 << 1),
+};
+DEF_ENUM_FLAGS_TYPE (enum parser_flag, parser_flags);
+
/* From parse.c */
extern expression_up parse_expression (const char *,
innermost_block_tracker * = nullptr,
- bool void_context_p = false);
+ parser_flags flags = 0);
extern expression_up parse_expression_with_language (const char *string,
enum language lang);
@@ -314,7 +330,8 @@ extern expression_up parse_expression_for_completion
(const char *, std::unique_ptr<expr_completion_base> *completer);
extern expression_up parse_exp_1 (const char **, CORE_ADDR pc,
- const struct block *, int,
+ const struct block *,
+ parser_flags flags,
innermost_block_tracker * = nullptr);
/* From eval.c */
diff --git a/gdb/parse.c b/gdb/parse.c
index e4678e9c6e8..ed0d0b8a880 100644
--- a/gdb/parse.c
+++ b/gdb/parse.c
@@ -328,7 +328,7 @@ copy_name (struct stoken token)
static expression_up
parse_exp_in_context (const char **stringptr, CORE_ADDR pc,
const struct block *block,
- int comma, bool void_context_p,
+ parser_flags flags,
innermost_block_tracker *tracker,
std::unique_ptr<expr_completion_base> *completer)
{
@@ -398,8 +398,11 @@ parse_exp_in_context (const char **stringptr, CORE_ADDR pc,
to the value matching SELECTED_FRAME as set by get_current_arch. */
parser_state ps (lang, get_current_arch (), expression_context_block,
- expression_context_pc, comma, *stringptr,
- completer != nullptr, tracker, void_context_p);
+ expression_context_pc,
+ (flags & PARSER_COMMA_TERMINATES) != 0,
+ *stringptr,
+ completer != nullptr, tracker,
+ (flags & PARSER_VOID_CONTEXT) != 0);
scoped_restore_current_language lang_saver;
set_language (lang->la_language);
@@ -435,31 +438,25 @@ parse_exp_in_context (const char **stringptr, CORE_ADDR pc,
if BLOCK is zero, use the block of the selected stack frame.
Meanwhile, advance *STRINGPTR to point after the expression,
at the first nonwhite character that is not part of the expression
- (possibly a null character).
-
- If COMMA is nonzero, stop if a comma is reached. */
+ (possibly a null character). FLAGS are passed to the parser. */
expression_up
parse_exp_1 (const char **stringptr, CORE_ADDR pc, const struct block *block,
- int comma, innermost_block_tracker *tracker)
+ parser_flags flags, innermost_block_tracker *tracker)
{
- return parse_exp_in_context (stringptr, pc, block, comma, false,
+ return parse_exp_in_context (stringptr, pc, block, flags,
tracker, nullptr);
}
/* Parse STRING as an expression, and complain if this fails to use up
all of the contents of STRING. TRACKER, if non-null, will be
- updated by the parser. VOID_CONTEXT_P should be true to indicate
- that the expression may be expected to return a value with void
- type. Parsers are free to ignore this, or to use it to help with
- overload resolution decisions. */
+ updated by the parser. FLAGS are passed to the parser. */
expression_up
parse_expression (const char *string, innermost_block_tracker *tracker,
- bool void_context_p)
+ parser_flags flags)
{
- expression_up exp = parse_exp_in_context (&string, 0, nullptr, 0,
- void_context_p,
+ expression_up exp = parse_exp_in_context (&string, 0, nullptr, flags,
tracker, nullptr);
if (*string)
error (_("Junk after end of expression."));
@@ -495,7 +492,7 @@ parse_expression_for_completion
try
{
- exp = parse_exp_in_context (&string, 0, 0, 0, false, nullptr, completer);
+ exp = parse_exp_in_context (&string, 0, 0, 0, nullptr, completer);
}
catch (const gdb_exception_error &except)
{
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index e903bf48fa5..e04a9c28739 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -1315,7 +1315,10 @@ process_print_command_args (const char *args, value_print_options *print_opts,
/* VOIDPRINT is true to indicate that we do want to print a void
value, so invert it for parse_expression. */
- expression_up expr = parse_expression (exp, nullptr, !voidprint);
+ parser_flags flags = 0;
+ if (!voidprint)
+ flags = PARSER_VOID_CONTEXT;
+ expression_up expr = parse_expression (exp, nullptr, flags);
return expr->evaluate ();
}
diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index ffda4a6439e..9e5ced1893e 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -680,7 +680,8 @@ validate_actionline (const char *line, struct breakpoint *b)
{
p = tmp_p;
expression_up exp = parse_exp_1 (&p, loc->address,
- block_for_pc (loc->address), 1);
+ block_for_pc (loc->address),
+ PARSER_COMMA_TERMINATES);
if (exp->first_opcode () == OP_VAR_VALUE)
{
@@ -732,7 +733,8 @@ validate_actionline (const char *line, struct breakpoint *b)
/* Only expressions are allowed for this action. */
expression_up exp = parse_exp_1 (&p, loc->address,
- block_for_pc (loc->address), 1);
+ block_for_pc (loc->address),
+ PARSER_COMMA_TERMINATES);
/* We have something to evaluate, make sure that the expr to
bytecode translator can handle it and that it's not too
@@ -1349,7 +1351,7 @@ encode_actions_1 (struct command_line *action,
const char *exp_start = action_exp;
expression_up exp = parse_exp_1 (&action_exp, tloc->address,
block_for_pc (tloc->address),
- 1);
+ PARSER_COMMA_TERMINATES);
switch (exp->first_opcode ())
{
@@ -1439,7 +1441,7 @@ encode_actions_1 (struct command_line *action,
{
expression_up exp = parse_exp_1 (&action_exp, tloc->address,
block_for_pc (tloc->address),
- 1);
+ PARSER_COMMA_TERMINATES);
agent_expr_up aexpr = gen_eval_for_expr (tloc->address,
exp.get ());
--
2.39.1
next prev parent reply other threads:[~2023-05-04 14:21 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-04 14:21 [PATCH 00/11] Fix frame-less expression evaluation in DAP Tom Tromey
2023-05-04 14:21 ` [PATCH 01/11] Avoid forward declaration in parse.c Tom Tromey
2023-05-04 14:21 ` [PATCH 02/11] Move innermost_block_tracker to expression.h Tom Tromey
2023-05-04 14:21 ` Tom Tromey [this message]
2023-05-04 14:21 ` [PATCH 04/11] Simplify parser_state constructor Tom Tromey
2023-05-04 14:21 ` [PATCH 05/11] Boolify parser_state::comma_terminates Tom Tromey
2023-05-04 14:21 ` [PATCH 06/11] Rearrange parser_state Tom Tromey
2023-05-04 14:21 ` [PATCH 07/11] Add PARSER_DEBUG flag Tom Tromey
2023-05-04 14:21 ` [PATCH 08/11] Add PARSER_LEAVE_BLOCK_ALONE flag Tom Tromey
2023-05-04 14:21 ` [PATCH 09/11] Add flags to parse_and_eval Tom Tromey
2023-05-04 14:21 ` [PATCH 10/11] Add global_context parameter to gdb.parse_and_eval Tom Tromey
2023-05-04 14:54 ` Eli Zaretskii
2023-05-23 20:17 ` Tom Tromey
2023-05-04 14:21 ` [PATCH 11/11] Handle DAP evaluate request without a frame ID Tom Tromey
2023-05-23 20:17 ` [PATCH 00/11] Fix frame-less expression evaluation in DAP Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230504-frameless-v1-3-4191201740b0@adacore.com \
--to=tromey@adacore.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).