[Lldb-commits] [lldb] [lldb] Fix 'session save' command on Windows (PR #93833)

Vladislav Dzhidzhoev via lldb-commits lldb-commits at lists.llvm.org
Thu May 30 07:46:56 PDT 2024


https://github.com/dzhidzhoev created https://github.com/llvm/llvm-project/pull/93833

1. Use dashes (-) instead of colons (:) as a time separator in a session log file name since Windows doesn't support saving files with names containing colons.

2. Temporary file creation code is changed in the test:
On Windows, the temporary file should be closed before 'session save' writes the session log to it. NamedTemporaryFile() can preserve the file after closing it with the delete_on_close=False option. However, this option is only available since Python 3.12. Thus mkstemp() is used for temporary file creation as the more compatible option.

>From a11876da55230bd9c5df7cddc3726cef5f5836a1 Mon Sep 17 00:00:00 2001
From: Vladislav Dzhidzhoev <vdzhidzhoev at accesssoftek.com>
Date: Fri, 10 May 2024 22:59:31 +0000
Subject: [PATCH] [lldb] Fix 'session save' command on Windows

1. Use dashes (-) instead of colons (:) as time separator in a session log
file name since Windows doesn't support saving files with names containing
colons.

2. Temporary file creation code is changed in the test:
On Windows, the temporary file should be closed before 'session save'
writes session log to it. NamedTemporaryFile() can preserve the file
after closing it with delete_on_close=False option.
However, this option is only available since Python 3.12. Thus
mkstemp() is used for temporary file creation as the more compatible
option.
---
 lldb/source/Interpreter/CommandInterpreter.cpp        |  2 ++
 .../test/API/commands/session/save/TestSessionSave.py | 11 +++++++----
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp
index 7f21f382adb83..6a61882df093d 100644
--- a/lldb/source/Interpreter/CommandInterpreter.cpp
+++ b/lldb/source/Interpreter/CommandInterpreter.cpp
@@ -3235,6 +3235,8 @@ bool CommandInterpreter::SaveTranscript(
   if (output_file == std::nullopt || output_file->empty()) {
     std::string now = llvm::to_string(std::chrono::system_clock::now());
     std::replace(now.begin(), now.end(), ' ', '_');
+    // Can't have file name with colons on Windows
+    std::replace(now.begin(), now.end(), ':', '-');
     const std::string file_name = "lldb_session_" + now + ".log";
 
     FileSpec save_location = GetSaveSessionDirectory();
diff --git a/lldb/test/API/commands/session/save/TestSessionSave.py b/lldb/test/API/commands/session/save/TestSessionSave.py
index 98985c66010bb..ed7be741ced60 100644
--- a/lldb/test/API/commands/session/save/TestSessionSave.py
+++ b/lldb/test/API/commands/session/save/TestSessionSave.py
@@ -19,7 +19,6 @@ def raw_transcript_builder(self, cmd, res):
             raw += res.GetError()
         return raw
 
-    @skipIfWindows
     @no_debug_info_test
     def test_session_save(self):
         raw = ""
@@ -61,8 +60,13 @@ def test_session_save(self):
         self.assertFalse(res.Succeeded())
         raw += self.raw_transcript_builder(cmd, res)
 
-        tf = tempfile.NamedTemporaryFile()
-        output_file = tf.name
+        fd, output_file = tempfile.mkstemp()
+        os.close(fd)
+
+        def cleanup():
+            if os.path.exists(output_file):
+                os.unlink(output_file)
+        self.addTearDownHook(cleanup)
 
         res = lldb.SBCommandReturnObject()
         interpreter.HandleCommand("session save " + output_file, res)
@@ -95,7 +99,6 @@ def test_session_save(self):
             for line in lines:
                 self.assertIn(line, content)
 
-    @skipIfWindows
     @no_debug_info_test
     def test_session_save_on_quit(self):
         raw = ""



More information about the lldb-commits mailing list