[binutils-gdb] Warn if log file changed while logging
Tom Tromey
tromey@sourceware.org
Mon Feb 9 15:52:08 GMT 2026
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=ea357403139cd0da6bd0a320f75f693939eaf508
commit ea357403139cd0da6bd0a320f75f693939eaf508
Author: Tom Tromey <tom@tromey.com>
Date: Wed Dec 10 02:24:13 2025 -0700
Warn if log file changed while logging
PR gdb/33531 points out that while some "set logging" commands will
warn if you attempt to change settings when logging is already active,
"set logging file" does not. This patch corrects this oversight.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33531
Approved-By: Andrew Burgess <aburgess@redhat.com>
Diff:
---
gdb/cli/cli-logging.c | 26 +++++++++++++++++---------
gdb/testsuite/gdb.base/ui-redirect.exp | 3 +++
2 files changed, 20 insertions(+), 9 deletions(-)
diff --git a/gdb/cli/cli-logging.c b/gdb/cli/cli-logging.c
index c046e9131bc..8d22a62fa02 100644
--- a/gdb/cli/cli-logging.c
+++ b/gdb/cli/cli-logging.c
@@ -26,7 +26,23 @@
static std::string saved_filename;
+static void
+maybe_warn_already_logging ()
+{
+ if (!saved_filename.empty ())
+ warning (_("Currently logging to %s. Turn the logging off and on to "
+ "make the new setting effective."), saved_filename.c_str ());
+}
+
static std::string logging_filename = "gdb.txt";
+
+static void
+set_logging_filename (const char *args,
+ int from_tty, struct cmd_list_element *c)
+{
+ maybe_warn_already_logging ();
+}
+
static void
show_logging_filename (struct ui_file *file, int from_tty,
struct cmd_list_element *c, const char *value)
@@ -37,14 +53,6 @@ show_logging_filename (struct ui_file *file, int from_tty,
static bool logging_overwrite;
-static void
-maybe_warn_already_logging ()
-{
- if (!saved_filename.empty ())
- warning (_("Currently logging to %s. Turn the logging off and on to "
- "make the new setting effective."), saved_filename.c_str ());
-}
-
static void
set_logging_overwrite (const char *args,
int from_tty, struct cmd_list_element *c)
@@ -344,7 +352,7 @@ If debug redirect is on, debug will go only to the log file."),
Set the current logfile."), _("\
Show the current logfile."), _("\
The logfile is used when directing GDB's output."),
- NULL,
+ set_logging_filename,
show_logging_filename,
&set_logging_cmdlist, &show_logging_cmdlist);
diff --git a/gdb/testsuite/gdb.base/ui-redirect.exp b/gdb/testsuite/gdb.base/ui-redirect.exp
index a0382893980..b128391115f 100644
--- a/gdb/testsuite/gdb.base/ui-redirect.exp
+++ b/gdb/testsuite/gdb.base/ui-redirect.exp
@@ -100,6 +100,9 @@ with_test_prefix "redirect while already logging" {
"Copying output to /dev/null.*Copying debug output to /dev/null\\."
gdb_test "set logging redirect on" \
".*warning: Currently logging .*Turn the logging off and on to make the new setting effective.*"
+ gdb_test "set logging file /dev/null" \
+ ".*warning: Currently logging .*Turn the logging off and on to make the new setting effective.*" \
+ "warn when changing log filename"
gdb_test "save breakpoints $cmds_file" "Saved to file '$cmds_file'\\." \
"save breakpoints cmds.txt"
cmp_file_string "$cmds_file" "$cmds" "cmds.txt"
More information about the Gdb-cvs
mailing list