]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Print command trace to gdb_stdlog
authorTom Tromey <tromey@adacore.com>
Tue, 2 Jun 2026 17:27:15 +0000 (11:27 -0600)
committerTom Tromey <tromey@adacore.com>
Thu, 18 Jun 2026 16:48:53 +0000 (10:48 -0600)
I recently wanted to enable some gdb logging when running the internal
AdaCore test suite.  To do this nicely, I enable debug-redirect early
in the test, so that the logging output does not affect the test
results.

I also wanted to the log the commands, to correlate what I see in the
debug log with what I see in the ordinary test suite log file (which
is basically like our own gdb.log).

However, I found that "set trace-commands on" will log to stdout, not
stdlog.  This patch changes this to log to the log file instead.

gdb/cli/cli-script.c
gdb/testsuite/gdb.base/ui-redirect.exp

index b8312f431cb1311ba7b0c5254a487b4d9ca9bfd2..0a1208845b41bcbec9d10b20f7cfbd397e776717 100644 (file)
@@ -486,8 +486,6 @@ ATTRIBUTE_PRINTF (1, 2)
 void
 print_command_trace (const char *fmt, ...)
 {
-  int i;
-
   if (suppress_next_print_command_trace)
     {
       suppress_next_print_command_trace = false;
@@ -497,15 +495,15 @@ print_command_trace (const char *fmt, ...)
   if (!source_verbose && !trace_commands)
     return;
 
-  for (i=0; i < command_nest_depth; i++)
-    gdb_printf ("+");
+  for (int i = 0; i < command_nest_depth; ++i)
+    gdb_printf (gdb_stdlog, "+");
 
   va_list args;
 
   va_start (args, fmt);
-  gdb_vprintf (fmt, args);
+  gdb_vprintf (gdb_stdlog, fmt, args);
   va_end (args);
-  gdb_puts ("\n");
+  gdb_puts ("\n", gdb_stdlog);
 }
 
 /* Helper for execute_control_command.  */
index 313843e3626100d2acdd2c36de51ea428605e62d..bed11bd2e87dc24de3a3dc4bf8e0eebe548b1115 100644 (file)
@@ -135,6 +135,12 @@ with_test_prefix "redirect debugging" {
     "Copying output to /dev/null.*Redirecting debug output to /dev/null\\."
     gdb_test "continue" "Continuing.*((?!infrun).).*Breakpoint ${::decimal}, bar.*"
     gdb_test "set debug infrun 0"
+
+    # The trace should be sent to the log, not stdout.
+    gdb_test_no_output "set trace-commands on"
+    gdb_test_no_output {printf ""}
+    gdb_test_no_output "set trace-commands off"
+
     gdb_test "set logging enabled off" "Done logging to /dev/null\\."
     gdb_test "help" "List of classes of commands:.*"
 }