[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 08:18:31 PDT 2024
https://github.com/dzhidzhoev updated https://github.com/llvm/llvm-project/pull/93833
>From 1681c41f4486047239d28d694cb29448b60b12b0 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 ++
.../API/commands/session/save/TestSessionSave.py | 13 +++++++++----
2 files changed, 11 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..496999e613867 100644
--- a/lldb/test/API/commands/session/save/TestSessionSave.py
+++ b/lldb/test/API/commands/session/save/TestSessionSave.py
@@ -1,6 +1,7 @@
"""
Test the session save feature
"""
+
import os
import tempfile
@@ -19,7 +20,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 +61,14 @@ 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 +101,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