Skip to content

Commit e4d214d

Browse files
committed
Print command trace to gdb_stdlog
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.
1 parent b7d1fcd commit e4d214d

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

gdb/cli/cli-script.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -486,8 +486,6 @@ ATTRIBUTE_PRINTF (1, 2)
486486
void
487487
print_command_trace (const char *fmt, ...)
488488
{
489-
int i;
490-
491489
if (suppress_next_print_command_trace)
492490
{
493491
suppress_next_print_command_trace = false;
@@ -497,15 +495,15 @@ print_command_trace (const char *fmt, ...)
497495
if (!source_verbose && !trace_commands)
498496
return;
499497

500-
for (i=0; i < command_nest_depth; i++)
501-
gdb_printf ("+");
498+
for (int i = 0; i < command_nest_depth; ++i)
499+
gdb_printf (gdb_stdlog, "+");
502500

503501
va_list args;
504502

505503
va_start (args, fmt);
506-
gdb_vprintf (fmt, args);
504+
gdb_vprintf (gdb_stdlog, fmt, args);
507505
va_end (args);
508-
gdb_puts ("\n");
506+
gdb_puts ("\n", gdb_stdlog);
509507
}
510508

511509
/* Helper for execute_control_command. */

gdb/testsuite/gdb.base/ui-redirect.exp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ with_test_prefix "redirect debugging" {
135135
"Copying output to /dev/null.*Redirecting debug output to /dev/null\\."
136136
gdb_test "continue" "Continuing.*((?!infrun).).*Breakpoint ${::decimal}, bar.*"
137137
gdb_test "set debug infrun 0"
138+
139+
# The trace should be sent to the log, not stdout.
140+
gdb_test_no_output "set trace-commands on"
141+
gdb_test_no_output {printf ""}
142+
gdb_test_no_output "set trace-commands off"
143+
138144
gdb_test "set logging enabled off" "Done logging to /dev/null\\."
139145
gdb_test "help" "List of classes of commands:.*"
140146
}

0 commit comments

Comments
 (0)