Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH] Fix "set debug parser"
Date: Sat, 26 Apr 2025 17:12:42 -0600	[thread overview]
Message-ID: <20250426231242.926679-1-tom@tromey.com> (raw)

While debugging my longer series, I discovered that I broken "set
debug parser" a couple years ago.  This patch fixes it and adds a
minimal test case so that it, hopefully, will not break again.

This patch also adds parser debugging to the C++ name canonicalizer.
---
 gdb/cp-name-parser.y             |  3 +++
 gdb/parse.c                      |  4 ++--
 gdb/parser-defs.h                |  3 +++
 gdb/printcmd.c                   |  4 +++-
 gdb/testsuite/gdb.base/exprs.exp | 12 ++++++++++++
 5 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/gdb/cp-name-parser.y b/gdb/cp-name-parser.y
index 10f6e2d1491..e7317b732cc 100644
--- a/gdb/cp-name-parser.y
+++ b/gdb/cp-name-parser.y
@@ -2047,6 +2047,9 @@ cp_demangled_name_to_comp (const char *demangled_name,
   auto result = std::make_unique<demangle_parse_info> ();
   cpname_state state (demangled_name, result.get ());
 
+  scoped_restore restore_yydebug = make_scoped_restore (&yydebug,
+							parser_debug);
+
   if (yyparse (&state))
     {
       if (state.global_errmsg && errmsg)
diff --git a/gdb/parse.c b/gdb/parse.c
index 3108017dbb7..64653c8ae6e 100644
--- a/gdb/parse.c
+++ b/gdb/parse.c
@@ -60,8 +60,8 @@ show_expressiondebug (struct ui_file *file, int from_tty,
 }
 
 
-/* True if an expression parser should set yydebug.  */
-static bool parser_debug;
+/* See parser-defs.h.  */
+bool parser_debug;
 
 static void
 show_parserdebug (struct ui_file *file, int from_tty,
diff --git a/gdb/parser-defs.h b/gdb/parser-defs.h
index c13a56e0505..f5618f3a9ce 100644
--- a/gdb/parser-defs.h
+++ b/gdb/parser-defs.h
@@ -389,4 +389,7 @@ extern bool fits_in_type (int n_sign, const gdb_mpz &n, int type_bits,
 
 extern void parser_fprintf (FILE *, const char *, ...) ATTRIBUTE_PRINTF (2, 3);
 
+/* True if an expression parser should set yydebug.  */
+extern bool parser_debug;
+
 #endif /* GDB_PARSER_DEFS_H */
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index 2be5eaa15a2..6659c5a41e5 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -1320,7 +1320,9 @@ process_print_command_args (const char *args, value_print_options *print_opts,
 	 value, so invert it for parse_expression.  */
       parser_flags flags = 0;
       if (!voidprint)
-	flags = PARSER_VOID_CONTEXT;
+	flags |= PARSER_VOID_CONTEXT;
+      if (parser_debug)
+	flags |= PARSER_DEBUG;
       expression_up expr = parse_expression (exp, nullptr, flags);
       return expr->evaluate ();
     }
diff --git a/gdb/testsuite/gdb.base/exprs.exp b/gdb/testsuite/gdb.base/exprs.exp
index eb2d0e4bd8b..81e78e50e62 100644
--- a/gdb/testsuite/gdb.base/exprs.exp
+++ b/gdb/testsuite/gdb.base/exprs.exp
@@ -284,3 +284,15 @@ gdb_test "print v_short + " \
 # Test for a syntax error in the middle of an expression.
 gdb_test "print v_short =}{= 3" \
     "A syntax error in expression, near `\\}\\{= 3'\\."
+
+gdb_test_no_output "set debug parse 1"
+set saw_start 0
+gdb_test_multiple "print 23" "print with debugging" -lbl {
+    "Starting parse" {
+	set saw_start 1
+	exp_continue
+    }
+    -re ".$decimal = 23" {
+	gdb_assert $saw_start $gdb_test_name
+    }
+}
-- 
2.49.0


             reply	other threads:[~2025-04-26 23:13 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-26 23:12 Tom Tromey [this message]
2025-04-28 10:50 ` Tom de Vries
2025-04-28 22:29   ` Tom Tromey
2025-04-29  7:42     ` Tom de Vries
2025-05-02 20:30 ` Simon Marchi
2025-05-03 14:26   ` Simon Marchi
2025-05-03 17:26     ` Tom Tromey
2025-05-03 17:25   ` 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=20250426231242.926679-1-tom@tromey.com \
    --to=tom@tromey.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