]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Warn if log file changed while logging
authorTom Tromey <tom@tromey.com>
Wed, 10 Dec 2025 09:24:13 +0000 (02:24 -0700)
committerTom Tromey <tom@tromey.com>
Mon, 9 Feb 2026 15:15:52 +0000 (08:15 -0700)
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>
gdb/cli/cli-logging.c
gdb/testsuite/gdb.base/ui-redirect.exp

index c046e9131bcc6213d7a7146a764c61586d871c47..8d22a62fa02dd1249b0f0e208bb6fd59436e0ad8 100644 (file)
 
 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);
 
index a038289398052efc21ba761cbe65c570443014f1..b128391115f2e9031dfdac86d965f9120a1eb6c5 100644 (file)
@@ -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"