From: Tom Tromey Date: Wed, 10 Dec 2025 09:24:13 +0000 (-0700) Subject: Warn if log file changed while logging X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ea357403139cd0da6bd0a320f75f693939eaf508;p=thirdparty%2Fbinutils-gdb.git 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 --- 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"