From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH 2/2] Print command trace to gdb_stdlog
Date: Tue, 02 Jun 2026 11:51:50 -0600 [thread overview]
Message-ID: <20260602-cmd-trace-logging-v1-2-ab7e0fdd476e@adacore.com> (raw)
In-Reply-To: <20260602-cmd-trace-logging-v1-0-ab7e0fdd476e@adacore.com>
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 | 10 ++++------
gdb/testsuite/gdb.base/ui-redirect.exp | 6 ++++++
2 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c
index b8312f431cb..0a1208845b4 100644
--- a/gdb/cli/cli-script.c
+++ b/gdb/cli/cli-script.c
@@ -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. */
diff --git a/gdb/testsuite/gdb.base/ui-redirect.exp b/gdb/testsuite/gdb.base/ui-redirect.exp
index c1cb461496b..64007276b17 100644
--- a/gdb/testsuite/gdb.base/ui-redirect.exp
+++ b/gdb/testsuite/gdb.base/ui-redirect.exp
@@ -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:.*"
}
--
2.54.0
next prev parent reply other threads:[~2026-06-02 17:53 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-02 17:51 [PATCH 0/2] Send trace-commands output " Tom Tromey
2026-06-02 17:51 ` [PATCH 1/2] Boolify suppress_next_print_command_trace Tom Tromey
2026-06-02 17:51 ` Tom Tromey [this message]
2026-06-18 16:48 ` [PATCH 0/2] Send trace-commands output to gdb_stdlog 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=20260602-cmd-trace-logging-v1-2-ab7e0fdd476e@adacore.com \
--to=tromey@adacore.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