public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 08/11] Add PARSER_LEAVE_BLOCK_ALONE flag
Date: Thu, 04 May 2023 08:21:29 -0600	[thread overview]
Message-ID: <20230504-frameless-v1-8-4191201740b0@adacore.com> (raw)
In-Reply-To: <20230504-frameless-v1-0-4191201740b0@adacore.com>

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.
---
 gdb/expression.h |  6 ++++++
 gdb/parse.c      | 37 +++++++++++++++++++++----------------
 2 files changed, 27 insertions(+), 16 deletions(-)

diff --git a/gdb/expression.h b/gdb/expression.h
index c485b159ef8..d1858776e8e 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 bbe5cf12d37..221733a3f90 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)

-- 
2.39.1


  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 ` [PATCH 03/11] Introduce and use parser flags Tom Tromey
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 ` Tom Tromey [this message]
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-8-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).