]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Fix "set debug parser"
authorTom Tromey <tom@tromey.com>
Fri, 25 Apr 2025 23:32:33 +0000 (17:32 -0600)
committerTom Tromey <tom@tromey.com>
Mon, 28 Apr 2025 22:29:50 +0000 (16:29 -0600)
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.

Thanks to Tom de Vries for fixing the test case.

gdb/cp-name-parser.y
gdb/parse.c
gdb/parser-defs.h
gdb/printcmd.c
gdb/testsuite/gdb.base/exprs.exp

index 10f6e2d149170ed6c6080fb25fac7ef1c89926cd..e7317b732cca012eb61f85945e1c26315806df00 100644 (file)
@@ -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)
index 3108017dbb757b2e4ea26013b170acd6be802325..64653c8ae6e8f91186539aaa433a84d4cc094eaf 100644 (file)
@@ -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,
index c13a56e0505e42999eeb465230511b8b1482c312..f5618f3a9ce82210779ff0f9ce88d1557b14457b 100644 (file)
@@ -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 */
index 2be5eaa15a20dc231ad380e7fd07f60fd541a946..6659c5a41e52ed177f3bb218201b7649ae52d367 100644 (file)
@@ -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 ();
     }
index eb2d0e4bd8b5c69f3a2d17a9b91f97de93d272fd..f703c18a8360b69229cde6a249e698dedd4b488c 100644 (file)
@@ -284,3 +284,21 @@ 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
+set saw_val 0
+gdb_test_multiple "print 23" "print with debugging" -lbl {
+    -re "\r\nStarting parse(?=\r\n)" {
+       set saw_start 1
+       exp_continue
+    }
+    -re "\r\n.$decimal = 23(?=\r\n)" {
+       set saw_val 1
+       exp_continue
+    }
+
+    -re -wrap "" {
+       gdb_assert {$saw_start && $saw_val} $gdb_test_name
+    }
+}