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

via lldb-commits lldb-commits at lists.llvm.org
Thu May 30 07:47:27 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lldb

Author: Vladislav Dzhidzhoev (dzhidzhoev)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/93833.diff


2 Files Affected:

- (modified) lldb/source/Interpreter/CommandInterpreter.cpp (+2) 
- (modified) lldb/test/API/commands/session/save/TestSessionSave.py (+7-4) 


``````````diff
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 = ""

``````````

</details>


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


More information about the lldb-commits mailing list