Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] Fix "set debug parser"
@ 2025-04-26 23:12 Tom Tromey
  2025-04-28 10:50 ` Tom de Vries
  2025-05-02 20:30 ` Simon Marchi
  0 siblings, 2 replies; 8+ messages in thread
From: Tom Tromey @ 2025-04-26 23:12 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

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


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-05-03 17:27 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-04-26 23:12 [PATCH] Fix "set debug parser" Tom Tromey
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox